/**
  * Computes and returns the layout's grid origins.
  *
  * @param container the layout container to inspect
  * @return an object that comprises the cell origins and extents
  * @throws IllegalArgumentException if the layout is not FormLayout
  */
 public static FormLayout.LayoutInfo getLayoutInfo(Container container) {
   if (!(container.getLayout() instanceof FormLayout)) {
     throw new IllegalArgumentException("The container must use an instance of FormLayout.");
   }
   FormLayout layout = (FormLayout) container.getLayout();
   return layout.getLayoutInfo(container);
 }
 /**
  * Dumps the component constraints to the console.
  *
  * @param container the layout container to inspect
  */
 public static void dumpConstraints(Container container) {
   System.out.println("COMPONENT CONSTRAINTS");
   if (!(container.getLayout() instanceof FormLayout)) {
     System.out.println("The container's layout is not a FormLayout.");
     return;
   }
   FormLayout layout = (FormLayout) container.getLayout();
   int childCount = container.getComponentCount();
   for (int i = 0; i < childCount; i++) {
     Component child = container.getComponent(i);
     CellConstraints cc = layout.getConstraints(child);
     String ccString = cc == null ? "no constraints" : cc.toShortString(layout);
     System.out.print(ccString);
     System.out.print("; ");
     String childType = child.getClass().getName();
     System.out.print(childType);
     if (child instanceof JLabel) {
       JLabel label = (JLabel) child;
       System.out.print("      \"" + label.getText() + "\"");
     }
     if (child.getName() != null) {
       System.out.print("; name=");
       System.out.print(child.getName());
     }
     System.out.println();
   }
   System.out.println();
 }
예제 #3
0
  private int checkSetSizesFromParent(Container container, Insets insets) {
    int skipLayout = 0;
    GridLayoutManager parentGridLayout = null;
    GridConstraints parentGridConstraints = null;
    Container parent = container.getParent();
    if (parent != null) {
      if (parent.getLayout() instanceof GridLayoutManager) {
        parentGridLayout = (GridLayoutManager) parent.getLayout();
        parentGridConstraints = parentGridLayout.getConstraintsForComponent(container);
      } else {
        Container col = parent.getParent();
        if (col != null && col.getLayout() instanceof GridLayoutManager) {
          parentGridLayout = (GridLayoutManager) col.getLayout();
          parentGridConstraints = parentGridLayout.getConstraintsForComponent(parent);
        }
      }
    }

    if (parentGridLayout != null && parentGridConstraints.isUseParentLayout()) {
      int i;
      if (this.myRowStretches.length == parentGridConstraints.getRowSpan()) {
        int row = parentGridConstraints.getRow();
        this.myYs[0] = insets.top + this.myMargin.top;
        this.myHeights[0] = parentGridLayout.myHeights[row] - this.myYs[0];

        for (i = 1; i < this.myRowStretches.length; ++i) {
          this.myYs[i] = parentGridLayout.myYs[i + row] - parentGridLayout.myYs[row];
          this.myHeights[i] = parentGridLayout.myHeights[i + row];
        }

        this.myHeights[this.myRowStretches.length - 1] -= insets.bottom + this.myMargin.bottom;
        skipLayout |= 1;
      }

      if (this.myColumnStretches.length == parentGridConstraints.getColSpan()) {
        int column = parentGridConstraints.getColumn();
        this.myXs[0] = insets.left + this.myMargin.left;
        this.myWidths[0] = parentGridLayout.myWidths[column] - this.myXs[0];

        for (i = 1; i < this.myColumnStretches.length; ++i) {
          this.myXs[i] = parentGridLayout.myXs[i + column] - parentGridLayout.myXs[column];
          this.myWidths[i] = parentGridLayout.myWidths[i + column];
        }

        this.myWidths[this.myColumnStretches.length - 1] -= insets.right + this.myMargin.right;
        skipLayout |= 2;
      }
    }

    return skipLayout;
  }
 /**
  * Dumps all layout state to the console: column and row specifications, column and row groups,
  * grid bounds and cell constraints.
  *
  * @param container the layout container
  */
 public static void dumpAll(Container container) {
   if (!(container.getLayout() instanceof FormLayout)) {
     System.out.println("The container's layout is not a FormLayout.");
     return;
   }
   FormLayout layout = (FormLayout) container.getLayout();
   dumpColumnSpecs(layout);
   dumpRowSpecs(layout);
   System.out.println();
   dumpColumnGroups(layout);
   dumpRowGroups(layout);
   System.out.println();
   dumpConstraints(container);
   dumpGridBounds(container);
 }
예제 #5
0
파일: Utilities.java 프로젝트: bily/fsxp
 public static void addComponent(
     Container container,
     Component component,
     int gridx,
     int gridy,
     int gridwidth,
     int gridheight,
     int fill,
     int anchor,
     Insets insets,
     int ipadx,
     int ipady,
     double weightx,
     double weighty) {
   java.awt.LayoutManager lm = container.getLayout();
   GridBagConstraints gbc = new GridBagConstraints();
   gbc.gridx = gridx;
   gbc.gridy = gridy;
   gbc.gridwidth = gridwidth;
   gbc.gridheight = gridheight;
   gbc.fill = fill;
   gbc.anchor = anchor;
   gbc.insets = insets;
   gbc.ipadx = ipadx;
   gbc.ipady = ipady;
   gbc.weightx = weightx;
   gbc.weighty = weighty;
   ((GridBagLayout) lm).setConstraints(component, gbc);
   container.add(component);
 }
예제 #6
0
 public static void addComponent(
     Container container,
     Component component,
     int gridx,
     int gridy,
     int gridwidth,
     int gridheight,
     int fill,
     int anchor)
     throws AWTException {
   LayoutManager lm = container.getLayout();
   if (!(lm instanceof GridBagLayout)) {
     throw new AWTException("Invalid layout" + lm);
   } else {
     GridBagConstraints gbc = new GridBagConstraints();
     gbc.gridx = gridx;
     gbc.gridy = gridy;
     gbc.gridwidth = gridwidth;
     gbc.gridheight = gridheight;
     gbc.fill = fill;
     gbc.anchor = anchor;
     ((GridBagLayout) lm).setConstraints(component, gbc);
     container.add(component);
   }
 }
예제 #7
0
 // --------------------------------------------------------------------------
 // add `component` to `container` using gridbag layout; see `Visualizer`
 // --------------------------------------------------------------------------
 public void add(
     Container container,
     Component component,
     int gridx,
     int gridy,
     int gridwidth,
     int gridheight,
     int fill,
     int anchor,
     double weightx,
     double weighty,
     int top,
     int left,
     int bottom,
     int right) {
   GridBagConstraints c = new GridBagConstraints();
   c.gridx = gridx;
   c.gridy = gridy;
   c.gridwidth = gridwidth;
   c.gridheight = gridheight;
   c.fill = fill;
   c.anchor = anchor;
   c.weightx = weightx;
   c.weighty = weighty;
   if (top + left + bottom + right > 0) c.insets = new Insets(top, left, bottom, right);
   ((GridBagLayout) container.getLayout()).setConstraints(component, c);
   container.add(component);
 }
 private void resetLastInvalidOnParent(Container paramContainer) {
   while (paramContainer != null) {
     LayoutManager localLayoutManager = paramContainer.getLayout();
     if ((localLayoutManager instanceof MigLayout))
       ((MigLayout) localLayoutManager).lastWasInvalid = false;
     paramContainer = paramContainer.getParent();
   }
 }
예제 #9
0
  public static void makeGrid(
      Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad) {
    SpringLayout layout;
    try {
      layout = (SpringLayout) parent.getLayout();
    } catch (ClassCastException exc) {
      System.err.println("The first argument to makeGrid must use SpringLayout.");
      return;
    }

    Spring xPadSpring = Spring.constant(xPad);
    Spring yPadSpring = Spring.constant(yPad);
    Spring initialXSpring = Spring.constant(initialX);
    Spring initialYSpring = Spring.constant(initialY);
    int max = rows * cols;

    Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    for (int i = 1; i < max; i++) {
      SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
      maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
      maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
    }

    for (int i = 0; i < max; i++) {
      SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
      cons.setWidth(maxWidthSpring);
      cons.setHeight(maxHeightSpring);
    }

    SpringLayout.Constraints lastCons = null;
    SpringLayout.Constraints lastRowCons = null;
    for (int i = 0; i < max; i++) {
      SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
      if (i % cols == 0) {
        lastRowCons = lastCons;
        cons.setX(initialXSpring);
      } else {
        cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), xPadSpring));
      }

      if (i / cols == 0) {
        cons.setY(initialYSpring);
      } else {
        cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), yPadSpring));
      }
      lastCons = cons;
    }

    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(
        SpringLayout.SOUTH,
        Spring.sum(Spring.constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
    pCons.setConstraint(
        SpringLayout.EAST,
        Spring.sum(Spring.constant(xPad), lastCons.getConstraint(SpringLayout.EAST)));
  }
예제 #10
0
 private static void updateSizesFromChildren(DimensionInfo info, boolean min, int[] widths) {
   for (int i = info.getComponentCount() - 1; i >= 0; --i) {
     Component child = info.getComponent(i);
     GridConstraints c = info.getConstraints(i);
     if (c.isUseParentLayout() && child instanceof Container) {
       Container container = (Container) child;
       if (container.getLayout() instanceof GridLayoutManager) {
         updateSizesFromChild(info, min, widths, container, i);
       } else if (container.getComponentCount() == 1
           && container.getComponent(0) instanceof Container) {
         Container childContainer = (Container) container.getComponent(0);
         if (childContainer.getLayout() instanceof GridLayoutManager) {
           updateSizesFromChild(info, min, widths, childContainer, i);
         }
       }
     }
   }
 }
예제 #11
0
  public synchronized void hostGame(String table_name) {
    if (game_gui != null) return;

    TableUI game_ui = new TableUI();
    this.games.put(table_name, game_ui);
    Container cp = main_frame.getContentPane();
    cp.add(game_ui, table_name);
    ((CardLayout) cp.getLayout()).show(cp, table_name);
    game_ui.this_game = new GUIRummy(this, table_name);
    return;
  }
예제 #12
0
  /**
   * Aligns the first <code>rows</code> * <code>cols</code> components of <code>parent</code> in a
   * grid. Each component in a column is as wide as the maximum preferred width of the components in
   * that column; height is similarly determined for each row. The parent is made just big enough to
   * fit them all.
   *
   * @param rows number of rows
   * @param cols number of columns
   * @param initialX x location to start the grid at
   * @param initialY y location to start the grid at
   * @param xPad x padding between cells
   * @param yPad y padding between cells
   */
  public static void makeCompactGrid(
      Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad) {
    SpringLayout layout;
    try {
      layout = (SpringLayout) parent.getLayout();
    } catch (ClassCastException exc) {
      System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
      return;
    }

    // Align all cells in each column and make them the same width.
    Spring x = Spring.constant(initialX);
    for (int c = 0; c < cols; c++) {
      Spring width = Spring.constant(0);
      for (int r = 0; r < rows; r++) {
        width =
            Spring.max(width, SpringUtilities.getConstraintsForCell(r, c, parent, cols).getWidth());
      }
      for (int r = 0; r < rows; r++) {
        SpringLayout.Constraints constraints =
            SpringUtilities.getConstraintsForCell(r, c, parent, cols);
        constraints.setX(x);
        constraints.setWidth(width);
      }
      x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
    }

    // Align all cells in each row and make them the same height.
    Spring y = Spring.constant(initialY);
    for (int r = 0; r < rows; r++) {
      Spring height = Spring.constant(0);
      for (int c = 0; c < cols; c++) {
        height =
            Spring.max(
                height, SpringUtilities.getConstraintsForCell(r, c, parent, cols).getHeight());
      }
      for (int c = 0; c < cols; c++) {
        SpringLayout.Constraints constraints =
            SpringUtilities.getConstraintsForCell(r, c, parent, cols);
        constraints.setY(y);
        constraints.setHeight(height);
      }
      y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
    }

    // Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(SpringLayout.SOUTH, y);
    pCons.setConstraint(SpringLayout.EAST, x);
  }
예제 #13
0
  /**
   * Creation and initialization of a layout delegate for a new container.
   *
   * @param initialize
   * @return false if suitable layout delegate is not found
   * @throws java.lang.Exception
   * @throw IllegalArgumentException if the container instance is not empty
   */
  public boolean prepareLayoutDelegate(boolean initialize) throws Exception {
    LayoutSupportDelegate delegate = null;
    LayoutManager lmInstance = null;

    // first try to find a dedicated layout delegate (for the container)
    Class<?> layoutDelegateClass =
        LayoutSupportRegistry.getSupportClassForContainer(radContainer.getBeanClass());

    if (layoutDelegateClass != null) {
      delegate = (LayoutSupportDelegate) layoutDelegateClass.newInstance();
      /*
      if (!delegate.checkEmptyContainer(getPrimaryContainer())) {
          RuntimeException ex = new IllegalArgumentException();
          org.openide.ErrorManager.getDefault().annotate(
                  ex, AbstractLayoutSupport.getBundle().getString(
                          "MSG_ERR_NonEmptyContainer")); // NOI18N
          throw ex;
      }
      */
    } else {
      Container contDel = getPrimaryContainerDelegate();
      // if (contDel.getComponentCount() == 0) {
      // we can still handle only empty containers ...
      lmInstance = contDel.getLayout();
      delegate = LayoutSupportRegistry.createSupportForLayout(lmInstance.getClass());
      /*
      } else {
          RuntimeException ex = new IllegalArgumentException();
          org.openide.ErrorManager.getDefault().annotate(
                  ex, AbstractLayoutSupport.getBundle().getString(
                          "MSG_ERR_NonEmptyContainer")); // NOI18N
          throw ex;
      }
          */
    }

    if (delegate != null) {
      if (initialize) {
        setLayoutDelegate(delegate);
      } else {
        layoutDelegate = delegate;
        needInit = true;
        initializeFromInstance = lmInstance != null;
      }
      return true;
    } else {
      return false;
    }
  }
예제 #14
0
  private static void updateSizesFromChild(
      DimensionInfo info, boolean min, int[] widths, Container container, int childIndex) {
    GridLayoutManager childLayout = (GridLayoutManager) container.getLayout();
    if (info.getSpan(childIndex) == info.getChildLayoutCellCount(childLayout)) {
      childLayout.validateInfos(container);
      DimensionInfo childInfo =
          info instanceof HorizontalInfo
              ? childLayout.myHorizontalInfo
              : childLayout.myVerticalInfo;
      int[] sizes = childLayout.getMinOrPrefSizes(childInfo, min);
      int cell = info.getCell(childIndex);

      for (int j = 0; j < sizes.length; ++j) {
        widths[cell + j] = Math.max(widths[cell + j], sizes[j]);
      }
    }
  }
예제 #15
0
  private static void addComponentsToPane(JFrame mainframe) {

    Container pane = mainFrame.getContentPane();

    // Ensure the layout manager is a BorderLayout
    if (!(pane.getLayout() instanceof BorderLayout)) {
      pane.setLayout(new BorderLayout());
    }

    // Create a panel to contain the search dialog and accounts listview
    JPanel centralPanel = new JPanel();
    SpringLayout layout = new SpringLayout();
    centralPanel.setLayout(layout);
    centralPanel.setBackground(Color.BLUE);

    // The search field
    JTextField searchField = new JTextField("Search", 20);
    centralPanel.add(searchField);

    // The Accounts listview
    JList accounts = new JList();
    accounts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    accounts.setSelectedIndex(0);
    // accounts.setVisibleRowCount(10);
    populateListView(accounts);
    JScrollPane accountsScrollList =
        new JScrollPane(
            accounts,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    centralPanel.add(accountsScrollList);

    layout.putConstraint(SpringLayout.NORTH, searchField, 5, SpringLayout.NORTH, centralPanel);
    layout.putConstraint(
        SpringLayout.NORTH, accountsScrollList, 5, SpringLayout.SOUTH, searchField);
    layout.putConstraint(SpringLayout.EAST, accountsScrollList, 0, SpringLayout.EAST, centralPanel);
    layout.putConstraint(SpringLayout.WEST, accountsScrollList, 0, SpringLayout.WEST, centralPanel);
    // layout.putConstraint(SpringLayout.SOUTH, accountsScrollList, 0, SpringLayout.SOUTH,
    // centralPanel);

    pane.add(centralPanel, BorderLayout.CENTER);
  }
예제 #16
0
 /**
  * Package private method which returns either BorderLayout.NORTH, BorderLayout.SOUTH,
  * BorderLayout.EAST, or BorderLayout.WEST depending on the location of the toolbar in its parent.
  * The toolbar might be in PAGE_START, PAGE_END, CENTER, or some other position, but will be
  * resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar actually IS, with
  * CENTER being NORTH.
  *
  * <p>This code is used to determine where the border line should be drawn by the custom toolbar
  * states, and also used by NimbusIcon to determine whether the handle icon needs to be shifted to
  * look correct.
  *
  * <p>Toollbars are unfortunately odd in the way these things are handled, and so this code exists
  * to unify the logic related to toolbars so it can be shared among the static files such as
  * NimbusIcon and generated files such as the ToolBar state classes.
  */
 public static Object resolveToolbarConstraint(JToolBar toolbar) {
   // NOTE: we don't worry about component orientation or PAGE_END etc
   // because the BasicToolBarUI always uses an absolute position of
   // NORTH/SOUTH/EAST/WEST.
   if (toolbar != null) {
     Container parent = toolbar.getParent();
     if (parent != null) {
       LayoutManager m = parent.getLayout();
       if (m instanceof BorderLayout) {
         BorderLayout b = (BorderLayout) m;
         Object con = b.getConstraints(toolbar);
         if (con == SOUTH || con == EAST || con == WEST) {
           return con;
         }
         return NORTH;
       }
     }
   }
   return NORTH;
 }
예제 #17
0
        @Override
        public void componentResized(java.awt.event.ComponentEvent event) {
          final boolean SQUARE = getWidth() == getHeight() ? true : false;
          final int SIZE = getWidth() <= getHeight() ? getWidth() : getHeight();
          java.awt.Container parent = getParent();
          if ((parent != null) && (parent.getLayout() == null)) {
            if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) {
              setSize(getMinimumSize().width, getMinimumSize().height);
            } else {
              if (SQUARE) {
                setSize(SIZE, SIZE);
              } else {
                setSize(getWidth(), getHeight());
              }
            }
          } else {
            if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) {
              setPreferredSize(getMinimumSize());
            } else {
              if (SQUARE) {
                setPreferredSize(new java.awt.Dimension(SIZE, SIZE));
              } else {
                setPreferredSize(new java.awt.Dimension(getWidth(), getHeight()));
              }
            }
          }
          calcInnerBounds();
          if (SQUARE) {
            init(INNER_BOUNDS.width, INNER_BOUNDS.width);
          } else {
            init(INNER_BOUNDS.width, INNER_BOUNDS.height);
          }

          FlipImages.INSTANCE.recreateImages(getWidth(), getHeight());

          revalidate();
          repaint(INNER_BOUNDS);
        }
  /**
   * Aligns the first <code>rows</code> * <code>cols</code> components of <code>parent</code> in a
   * grid. Each component is as big as the maximum preferred width and height of the components. The
   * parent is made just big enough to fit them all.
   *
   * @param rows number of rows
   * @param cols number of columns
   * @param initialX x location to start the grid at
   * @param initialY y location to start the grid at
   * @param xPad x padding between cells
   * @param yPad y padding between cells
   */
  public static void makeGrid(
      Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad) {
    SpringLayout layout;
    try {
      layout = (SpringLayout) parent.getLayout();
    } catch (ClassCastException exc) {
      System.err.println("The first argument to makeGrid must use SpringLayout.");
      return;
    }

    Spring xPadSpring = Spring.constant(xPad);
    Spring yPadSpring = Spring.constant(yPad);
    Spring initialXSpring = Spring.constant(initialX);
    Spring initialYSpring = Spring.constant(initialY);
    int max = rows * cols;

    // Calculate Springs that are the max of the width/height so that all
    // cells have the same size.
    Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    for (int i = 1; i < max; i++) {
      SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));

      maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
      maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
    }

    // Apply the new width/height Spring. This forces all the
    // components to have the same size.
    for (int i = 0; i < max; i++) {
      SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));

      cons.setWidth(maxWidthSpring);
      cons.setHeight(maxHeightSpring);
    }

    // Then adjust the x/y constraints of all the cells so that they
    // are aligned in a grid.
    SpringLayout.Constraints lastCons = null;
    SpringLayout.Constraints lastRowCons = null;
    for (int i = 0; i < max; i++) {
      SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
      if (i % cols == 0) { // start of new row
        lastRowCons = lastCons;
        cons.setX(initialXSpring);
      } else { // x position depends on previous component
        cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), xPadSpring));
      }

      if (i / cols == 0) { // first row
        cons.setY(initialYSpring);
      } else { // y position depends on previous row
        cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), yPadSpring));
      }
      lastCons = cons;
    }

    // Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(
        SpringLayout.SOUTH,
        Spring.sum(Spring.constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
    pCons.setConstraint(
        SpringLayout.EAST,
        Spring.sum(Spring.constant(xPad), lastCons.getConstraint(SpringLayout.EAST)));
  }
 /* Used by makeCompactGrid. */
 private static SpringLayout.Constraints getConstraintsForCell(
     int row, int col, Container parent, int cols) {
   SpringLayout layout = (SpringLayout) parent.getLayout();
   Component c = parent.getComponent(row * cols + col);
   return layout.getConstraints(c);
 }
예제 #20
0
  /**
   * Creates the appropriate object to represent each of the objects in <code>buttons</code> and
   * adds it to <code>container</code>. This differs from addMessageComponents in that it will
   * recurse on <code>buttons</code> and that if button is not a Component it will create an
   * instance of JButton.
   */
  protected void addButtonComponents(Container container, Object[] buttons, int initialIndex) {
    if (buttons != null && buttons.length > 0) {
      boolean sizeButtonsToSame = getSizeButtonsToSameWidth();
      boolean createdAll = true;
      int numButtons = buttons.length;
      JButton[] createdButtons = null;
      int maxWidth = 0;

      if (sizeButtonsToSame) {
        createdButtons = new JButton[numButtons];
      }

      for (int counter = 0; counter < numButtons; counter++) {
        Object button = buttons[counter];
        Component newComponent;

        if (button instanceof Component) {
          createdAll = false;
          newComponent = (Component) button;
          container.add(newComponent);
          hasCustomComponents = true;

        } else {
          JButton aButton;

          if (button instanceof ButtonFactory) {
            aButton = ((ButtonFactory) button).createButton();
          } else if (button instanceof Icon) aButton = new JButton((Icon) button);
          else aButton = new JButton(button.toString());

          aButton.setName("OptionPane.button");
          aButton.setMultiClickThreshhold(
              DefaultLookup.getInt(optionPane, this, "OptionPane.buttonClickThreshhold", 0));
          configureButton(aButton);

          container.add(aButton);

          ActionListener buttonListener = createButtonActionListener(counter);
          if (buttonListener != null) {
            aButton.addActionListener(buttonListener);
          }
          newComponent = aButton;
        }
        if (sizeButtonsToSame && createdAll && (newComponent instanceof JButton)) {
          createdButtons[counter] = (JButton) newComponent;
          maxWidth = Math.max(maxWidth, newComponent.getMinimumSize().width);
        }
        if (counter == initialIndex) {
          initialFocusComponent = newComponent;
          if (initialFocusComponent instanceof JButton) {
            JButton defaultB = (JButton) initialFocusComponent;
            defaultB.addHierarchyListener(
                new HierarchyListener() {
                  public void hierarchyChanged(HierarchyEvent e) {
                    if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
                      JButton defaultButton = (JButton) e.getComponent();
                      JRootPane root = SwingUtilities.getRootPane(defaultButton);
                      if (root != null) {
                        root.setDefaultButton(defaultButton);
                      }
                    }
                  }
                });
          }
        }
      }
      ((ButtonAreaLayout) container.getLayout())
          .setSyncAllWidths((sizeButtonsToSame && createdAll));
      /* Set the padding, windows seems to use 8 if <= 2 components,
      otherwise 4 is used. It may actually just be the size of the
      buttons is always the same, not sure. */
      if (DefaultLookup.getBoolean(optionPane, this, "OptionPane.setButtonMargin", true)
          && sizeButtonsToSame
          && createdAll) {
        JButton aButton;
        int padSize;

        padSize = (numButtons <= 2 ? 8 : 4);

        for (int counter = 0; counter < numButtons; counter++) {
          aButton = createdButtons[counter];
          aButton.setMargin(new Insets(2, padSize, 2, padSize));
        }
      }
    }
  }
예제 #21
0
  private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Darya Koreneva
    scrollPane1 = new JScrollPane();
    userTable = new JTable();
    newUserNameLabel = new JLabel();
    newUserNameTextField = new JTextField();
    addButton = new JButton();
    cancelButton = new JButton();
    addUserButton = new JButton();
    deleteUserButton = new JButton();
    blockButton = new JButton();
    unblockButton = new JButton();

    // ======== this ========
    Container contentPane = getContentPane();
    contentPane.setLayout(new GridBagLayout());
    ((GridBagLayout) contentPane.getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0, 0};
    ((GridBagLayout) contentPane.getLayout()).rowHeights = new int[] {0, 0, 0, 0};
    ((GridBagLayout) contentPane.getLayout()).columnWeights =
        new double[] {1.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
    ((GridBagLayout) contentPane.getLayout()).rowWeights = new double[] {1.0, 0.0, 0.0, 1.0E-4};

    // ======== scrollPane1 ========
    {
      scrollPane1.setViewportView(userTable);
    }
    contentPane.add(
        scrollPane1,
        new GridBagConstraints(
            0,
            0,
            5,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 0),
            0,
            0));

    // ---- newUserNameLabel ----
    newUserNameLabel.setText("New user name:");
    newUserNameLabel.setVisible(false);
    newUserNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPane.add(
        newUserNameLabel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5),
            0,
            0));

    // ---- newUserNameTextField ----
    newUserNameTextField.setVisible(false);
    contentPane.add(
        newUserNameTextField,
        new GridBagConstraints(
            1,
            1,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5),
            0,
            0));

    // ---- addButton ----
    addButton.setText("Add");
    addButton.setVisible(false);
    contentPane.add(
        addButton,
        new GridBagConstraints(
            3,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 5),
            0,
            0));

    // ---- cancelButton ----
    cancelButton.setText("Cancel");
    cancelButton.setVisible(false);
    contentPane.add(
        cancelButton,
        new GridBagConstraints(
            4,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 5, 0),
            0,
            0));

    // ---- addUserButton ----
    addUserButton.setText("Add user");
    contentPane.add(
        addUserButton,
        new GridBagConstraints(
            1,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 5),
            0,
            0));

    // ---- deleteUserButton ----
    deleteUserButton.setText("Delete user");
    contentPane.add(
        deleteUserButton,
        new GridBagConstraints(
            2,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 5),
            0,
            0));

    // ---- blockButton ----
    blockButton.setText("Block");
    contentPane.add(
        blockButton,
        new GridBagConstraints(
            3,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 5),
            0,
            0));

    // ---- unblockButton ----
    unblockButton.setText("Unblock");
    contentPane.add(
        unblockButton,
        new GridBagConstraints(
            4,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    setSize(560, 335);
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents

    setData(sys.userMap);
    addUserButton.addActionListener(
        (v) -> {
          newUserNameLabel.setVisible(true);
          newUserNameTextField.setVisible(true);
          addButton.setVisible(true);
          cancelButton.setVisible(true);
        });
    addButton.addActionListener(
        (v) -> {
          String newUserName = newUserNameTextField.getText();
          sys.userMap.put(newUserName, new User(newUserName, ""));
          setData(sys.userMap);
          newUserNameLabel.setVisible(false);
          newUserNameTextField.setVisible(false);
          addButton.setVisible(false);
          cancelButton.setVisible(false);
        });
    cancelButton.addActionListener(
        (v) -> {
          newUserNameLabel.setVisible(false);
          newUserNameTextField.setVisible(false);
          addButton.setVisible(false);
          cancelButton.setVisible(false);
        });
    deleteUserButton.addActionListener(
        (v) -> {
          Object valueAt =
              userTable.getValueAt(userTable.getSelectedRow(), userTable.getSelectedColumn());
          sys.userMap.remove(valueAt);
          setData(sys.userMap);
        });
    blockButton.addActionListener(
        (v) -> {
          Object valueAt =
              userTable.getValueAt(userTable.getSelectedRow(), userTable.getSelectedColumn());
          User user = sys.getUserByName(valueAt.toString());
          user.setBlocked(true);
          setData(sys.userMap);
        });
    unblockButton.addActionListener(
        (v) -> {
          Object valueAt =
              userTable.getValueAt(userTable.getSelectedRow(), userTable.getSelectedColumn());
          User user = sys.getUserByName(valueAt.toString());
          user.setBlocked(false);
          setData(sys.userMap);
        });
  }
예제 #22
0
 public TaskGridView() {
   // default look and feel
   try {
     // UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
     // UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
     // UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticLookAndFeel");
     // UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
     // UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
     // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
     // UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");	//10
     // UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.aero.AeroLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.fast.FastLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.graphite.GraphiteLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");	//8
     // UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.mint.MintLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.noire.NoireLookAndFeel");	//8
     // UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
     UIManager.setLookAndFeel("com.jtattoo.plaf.texture.TextureLookAndFeel"); // 10
     // UIManager.setLookAndFeel("com.pagosoft.plaf.PgsLookAndFeel");
     JFrame.setDefaultLookAndFeelDecorated(false);
   } catch (Exception e) {
     e.printStackTrace();
     JFrame.setDefaultLookAndFeelDecorated(true);
   }
   // Colors
   Palette palette = new Palette();
   super.getContentPane().setBackground(Color.GRAY.darker());
   // On close
   super.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   super.addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowClosing(WindowEvent event) {
           dispose();
         }
       });
   // axis divisions
   int maxx = 64;
   int maxy = 48;
   // Screen size
   Dimension dim =
       GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getSize();
   // Dimension dim = super.getToolkit().getScreenSize();
   // Dimension dim = new Dimension(1024, 768);
   super.setSize(dim);
   super.setUndecorated(true);
   // Dimensions
   int[] x = new int[maxx];
   int[] y = new int[maxy];
   int long_x = (int) (dim.getWidth() / x.length);
   int long_y = (int) (dim.getHeight() / y.length);
   // Grid for controls
   Container frameContentPane = super.getContentPane();
   frameContentPane.setLayout(new GridBagLayout());
   for (int i = 0; i < x.length; i++) x[i] = long_x;
   for (int i = 0; i < y.length; i++) y[i] = long_y;
   ((GridBagLayout) frameContentPane.getLayout()).columnWidths = x;
   ((GridBagLayout) frameContentPane.getLayout()).rowHeights = y;
   // Panels
   PzrPanel _A = new PzrPanel(palette.getColor("#447744"));
   PzrPanel _B = new PzrPanel(palette.getColor("#FFFFFF"));
   PzrPanel _C = new PzrPanel(palette.getColor("#000000"));
   PzrPanel _D = new PzrPanel(palette.getColor("#FFFFFF"));
   _A.setBorder(BorderFactory.createLineBorder(Color.white));
   //
   frameContentPane.add(
       _A,
       new GridBagConstraints(
           0,
           0,
           maxx,
           3,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(0, 0, 0, 0),
           0,
           0));
   frameContentPane.add(
       _B,
       new GridBagConstraints(
           0,
           3,
           maxx,
           3,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(0, 0, 0, 0),
           0,
           0));
   frameContentPane.add(
       _C,
       new GridBagConstraints(
           0,
           6,
           maxx,
           maxy - 9,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(0, 0, 0, 0),
           0,
           0));
   frameContentPane.add(
       _D,
       new GridBagConstraints(
           0,
           maxy - 3,
           maxx,
           3,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(0, 0, 0, 0),
           0,
           0));
   // Title
   lblCaption =
       new PzrLabel(
           0,
           0,
           long_x * maxx,
           long_y * 3,
           "Tests",
           palette.getColor("#FFFFFF"),
           new Font("Verdana", Font.BOLD, 18));
   lblCaption.setHorizontalAlignment(SwingConstants.CENTER);
   _A.add(lblCaption);
   _A.add(
       new PzrImage(
           (long_x * 0) + 5,
           (int) (long_y * 1),
           long_x * 9,
           (int) (long_y * 1),
           "/gui/image/logo_small.png"));
   // Close
   this.btnClose =
       new PzrButton(
           (long_x * (maxx - 8)) - 1,
           (long_y * 0) + 1,
           long_x * 8,
           (long_y * 3) - 2,
           "btnClose",
           "Close",
           palette.getColor("#A20025"),
           "");
   this.btnClose.setOpaque(false);
   this.btnClose.setForeground(palette.getColor("#FFFFFF"));
   this.btnClose.repaint("/gui/image/grid_close_1.png", 32, 32);
   this.btnClose.setHorizontalTextPosition(SwingConstants.RIGHT);
   _A.add(this.btnClose);
   // Buttons top menu
   this.btnNew =
       new PzrButton(
           long_x * 0,
           long_y * 0,
           long_x * 8,
           long_y * 3,
           "btnNew",
           "New",
           palette.getColor("#DFF2BF"),
           "");
   this.btnNew.setOpaque(false);
   this.btnNew.setForeground(palette.getColor("#000000"));
   this.btnNew.repaint("/gui/image/grid_new_0.png", 32, 32);
   this.btnNew.setHorizontalTextPosition(SwingConstants.RIGHT);
   this.btnModify =
       new PzrButton(
           long_x * 8,
           long_y * 0,
           long_x * 8,
           long_y * 3,
           "btnModify",
           "Modify",
           palette.getColor("#BDE5F8"),
           "");
   this.btnModify.setOpaque(false);
   this.btnModify.setForeground(palette.getColor("#000000"));
   this.btnModify.repaint("/gui/image/grid_edit_0.png", 32, 32);
   this.btnModify.setHorizontalTextPosition(SwingConstants.RIGHT);
   this.btnDelete =
       new PzrButton(
           long_x * 16,
           long_y * 0,
           long_x * 8,
           long_y * 3,
           "btnDelete",
           "Delete",
           palette.getColor("#FFBABA"),
           "");
   this.btnDelete.setOpaque(false);
   this.btnDelete.setForeground(palette.getColor("#000000"));
   this.btnDelete.repaint("/gui/image/grid_delete_0.png", 32, 32);
   this.btnDelete.setHorizontalTextPosition(SwingConstants.RIGHT);
   this.btnPrint =
       new PzrButton(
           long_x * 24,
           long_y * 0,
           long_x * 8,
           long_y * 3,
           "btnPrint",
           "Print",
           palette.getColor("#FEEFB3"),
           "");
   this.btnPrint.setOpaque(false);
   this.btnPrint.setForeground(palette.getColor("#000000"));
   this.btnPrint.repaint("/gui/image/grid_print_0.png", 32, 32);
   this.btnPrint.setHorizontalTextPosition(SwingConstants.RIGHT);
   this.btnDetail1 =
       new PzrButton(
           long_x * 32,
           long_y * 0,
           long_x * 8,
           long_y * 3,
           "btnDetail1",
           "",
           palette.getColor(255, 153, 255),
           "");
   this.btnDetail1.setOpaque(false);
   this.btnDetail1.setForeground(palette.getColor("#000000"));
   this.btnDetail1.repaint("/gui/image/grid_roles_0.png", 32, 32);
   this.btnDetail1.setHorizontalTextPosition(SwingConstants.RIGHT);
   this.btnDetail2 =
       new PzrButton(
           long_x * 40,
           long_y * 0,
           long_x * 8,
           long_y * 3,
           "btnDetail2",
           "",
           palette.getColor(204, 153, 255),
           "");
   this.btnDetail2.setOpaque(false);
   this.btnDetail2.setForeground(palette.getColor("#000000"));
   this.btnDetail2.repaint("/gui/image/grid_users_0.png", 32, 32);
   this.btnDetail2.setHorizontalTextPosition(SwingConstants.RIGHT);
   _B.add(this.btnNew);
   _B.add(this.btnModify);
   _B.add(this.btnDelete);
   _B.add(this.btnPrint);
   _B.add(this.btnDetail1);
   _B.add(this.btnDetail2);
   // Grid
   this.grdData =
       new PzrGrid(0, 0, long_x * maxx, long_y * (maxy - 9), new Font("Verdana", Font.PLAIN, 16));
   _C.add(this.grdData);
   // Buttons bottom menu
   this.btnGridFirst =
       new PzrButton(
           long_x * 0,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridFirst",
           "",
           palette.getColor("#FFFFFF"),
           "");
   this.btnGridFirst.setOpaque(false);
   this.btnGridFirst.setForeground(palette.getColor("#000000"));
   this.btnGridFirst.repaint("/gui/image/grid_first.png", 32, 32);
   this.btnGridPrevious =
       new PzrButton(
           long_x * 3,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridPrevious",
           "",
           palette.getColor("#FFFFFF"),
           "");
   this.btnGridPrevious.setOpaque(false);
   this.btnGridPrevious.setForeground(palette.getColor("#000000"));
   this.btnGridPrevious.repaint("/gui/image/grid_previous.png", 32, 32);
   this.btnGridSet1 =
       new PzrButton(
           long_x * 6,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridSet1",
           "1",
           palette.getColor("#FFFFFF"),
           "");
   this.btnGridSet1.setOpaque(false);
   this.btnGridSet1.setForeground(palette.getColor("#000000"));
   this.btnGridSet1.setFont(new Font("Verdana", Font.PLAIN, 18));
   this.btnGridSet2 =
       new PzrButton(
           long_x * 9,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridSet2",
           "2",
           palette.getColor("#FFFFFF"),
           "");
   this.btnGridSet2.setOpaque(false);
   this.btnGridSet2.setForeground(palette.getColor("#000000"));
   this.btnGridSet2.setFont(new Font("Verdana", Font.PLAIN, 18));
   this.btnGridSet3 =
       new PzrButton(
           long_x * 12,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridSet3",
           "3",
           palette.getColor("#FFFFFF"),
           "");
   this.btnGridSet3.setOpaque(false);
   this.btnGridSet3.setForeground(palette.getColor("#000000"));
   this.btnGridSet3.setFont(new Font("Verdana", Font.PLAIN, 18));
   this.btnGridSet4 =
       new PzrButton(
           long_x * 15,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridSet4",
           "4",
           palette.getColor("#DFF2BF"),
           "");
   this.btnGridSet4.setOpaque(false);
   this.btnGridSet4.setForeground(palette.getColor("#000000"));
   this.btnGridSet4.setFont(new Font("Verdana", Font.PLAIN, 18));
   this.btnGridSet5 =
       new PzrButton(
           long_x * 18,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridSet5",
           "5",
           palette.getColor("#DFF2BF"),
           "");
   this.btnGridSet5.setOpaque(false);
   this.btnGridSet5.setForeground(palette.getColor("#000000"));
   this.btnGridSet5.setFont(new Font("Verdana", Font.PLAIN, 18));
   this.btnGridNext =
       new PzrButton(
           long_x * 21,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridNext",
           "",
           palette.getColor("#DFF2BF"),
           "");
   this.btnGridNext.setOpaque(false);
   this.btnGridNext.setForeground(palette.getColor("#000000"));
   this.btnGridNext.repaint("/gui/image/grid_next.png", 32, 32);
   this.btnGridLast =
       new PzrButton(
           long_x * 24,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridLast",
           "",
           palette.getColor("#DFF2BF"),
           "");
   this.btnGridLast.setOpaque(false);
   this.btnGridLast.setForeground(palette.getColor("#000000"));
   this.btnGridLast.repaint("/gui/image/grid_last.png", 32, 32);
   this.btnGridRefresh =
       new PzrButton(
           long_x * 27,
           long_y * 0,
           long_x * 3,
           long_y * 3,
           "btnGridRefresh",
           "",
           palette.getColor("#DFF2BF"),
           "");
   this.btnGridRefresh.setOpaque(false);
   this.btnGridRefresh.setForeground(palette.getColor("#000000"));
   this.btnGridRefresh.repaint("/gui/image/grid_refresh.png", 32, 32);
   this.lblSearch =
       new PzrLabel(
           long_x * (maxx - 30),
           (int) (long_y * 0.5),
           long_x * 7,
           long_y * 2,
           "Search",
           palette.getColor("#000000"),
           new Font("Verdana", Font.BOLD, 12));
   this.lblSearch.setHorizontalAlignment(SwingConstants.RIGHT);
   this.cboSearch =
       new PzrComboBox(
           long_x * (maxx - 23), (int) (long_y * 0.5), long_x * 10, long_y * 2, "cboSearch");
   this.txtSearch =
       new PzrText(
           long_x * (maxx - 13),
           (int) (long_y * 0.5),
           long_x * 10,
           long_y * 2,
           "txtSearch",
           "",
           false);
   this.lblSearch.setFont(new Font("Verdana", Font.PLAIN, 14));
   this.cboSearch.setFont(new Font("Verdana", Font.PLAIN, 14));
   this.txtSearch.setFont(new Font("Verdana", Font.PLAIN, 14));
   this.btnSearchClear =
       new PzrButton(
           long_x * (maxx - 3),
           (int) (long_y * 0.5),
           long_x * 3,
           long_y * 2,
           "btnSearchClear",
           "",
           palette.getColor("#DFF2BF"),
           "");
   this.btnSearchClear.setOpaque(false);
   this.btnSearchClear.setForeground(palette.getColor("#000000"));
   this.btnSearchClear.repaint("/gui/image/grid_search_clear.png", 32, 32);
   _D.add(btnGridFirst);
   _D.add(btnGridPrevious);
   _D.add(btnGridSet1);
   _D.add(btnGridSet2);
   _D.add(btnGridSet3);
   _D.add(btnGridSet4);
   _D.add(btnGridSet5);
   _D.add(btnGridNext);
   _D.add(btnGridLast);
   _D.add(btnGridRefresh);
   _D.add(lblSearch);
   _D.add(cboSearch);
   _D.add(txtSearch);
   _D.add(btnSearchClear);
   // Show
   this.setUndecorated(true);
   this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
   this.setLocationRelativeTo(null);
   this.setModal(true);
 }
예제 #23
0
 public ConfigTestsView() {
   // default look and feel
   try {
     // UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
     // UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
     // UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticLookAndFeel");
     // UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
     // UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
     // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
     // UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
     // //10
     // UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.aero.AeroLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.fast.FastLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.graphite.GraphiteLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
     // //8
     // UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.mint.MintLookAndFeel");
     // UIManager.setLookAndFeel("com.jtattoo.plaf.noire.NoireLookAndFeel");
     // //8
     // UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
     UIManager.setLookAndFeel("com.jtattoo.plaf.texture.TextureLookAndFeel"); // 10
     // UIManager.setLookAndFeel("com.pagosoft.plaf.PgsLookAndFeel");
     JFrame.setDefaultLookAndFeelDecorated(false);
   } catch (Exception e) {
     e.printStackTrace();
     JFrame.setDefaultLookAndFeelDecorated(true);
   }
   // Colors
   Palette palette = new Palette();
   super.getContentPane().setBackground(Color.GRAY.darker());
   // On close
   super.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   super.addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowClosing(WindowEvent event) {
           dispose();
         }
       });
   // axis divisions
   int maxx = 32;
   int maxy = 24;
   // Screen size
   Dimension dim = new Dimension(800, 600);
   super.setSize(dim);
   super.setUndecorated(true);
   // Dimensions
   int[] x = new int[maxx];
   int[] y = new int[maxy];
   int long_x = (int) (dim.getWidth() / x.length);
   int long_y = (int) (dim.getHeight() / y.length);
   // Grid for controls
   Container frameContentPane = super.getContentPane();
   frameContentPane.setLayout(new GridBagLayout());
   for (int i = 0; i < x.length; i++) x[i] = long_x;
   for (int i = 0; i < y.length; i++) y[i] = long_y;
   ((GridBagLayout) frameContentPane.getLayout()).columnWidths = x;
   ((GridBagLayout) frameContentPane.getLayout()).rowHeights = y;
   // Add controls
   PzrPanel _A = new PzrPanel(palette.getColor(Palette.COLOR_CAPTION));
   PzrPanel _B = new PzrPanel(palette.getColor(Palette.COLOR_BACKGROUND));
   PzrPanel _C = new PzrPanel(palette.getColor("#FFFFFF"));
   _A.setBorder(BorderFactory.createLineBorder(palette.getColor(Palette.COLOR_BORDER)));
   // Add controls
   frameContentPane.add(
       _A,
       new GridBagConstraints(
           0,
           0,
           maxx,
           2,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(0, 0, 0, 0),
           0,
           0));
   frameContentPane.add(
       _B,
       new GridBagConstraints(
           0,
           2,
           maxx,
           maxy - 5,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(0, 0, 0, 0),
           0,
           0));
   frameContentPane.add(
       _C,
       new GridBagConstraints(
           0,
           maxy - 3,
           maxx,
           3,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(0, 0, 0, 0),
           0,
           0));
   // title
   lblCaption =
       new PzrLabel(
           0,
           (int) (long_y * 0.5),
           long_x * maxx,
           long_y * 1,
           "",
           palette.getColor("#FFFFFF"),
           new Font("Verdana", Font.BOLD, 16));
   lblCaption.setHorizontalAlignment(SwingConstants.LEFT);
   lblCaption.setVerticalTextPosition(SwingConstants.CENTER);
   _A.add(lblCaption);
   _A.add(
       new PzrImage(
           (long_x * (maxx - 9)) - 5,
           (int) (long_y * 0.5),
           long_x * 9,
           long_y * 1,
           "/gui/image/logo_small.png"));
   // Controls
   int height = (int) (long_y * 1.4);
   int top = long_y * 1;
   int left = long_x * 1;
   int width = long_x * 9;
   Font font = new Font("Verdana", Font.BOLD, 16);
   lblName =
       new PzrLabel(
           left,
           top * 3,
           width,
           height,
           "Name",
           Color.BLACK,
           font,
           SwingConstants.RIGHT,
           SwingConstants.CENTER);
   lblDescription =
       new PzrLabel(
           left,
           top * 5,
           width,
           height,
           "Description",
           Color.BLACK,
           font,
           SwingConstants.RIGHT,
           SwingConstants.CENTER);
   //
   height = (int) (long_y * 1.4);
   top = long_y * 1;
   left = long_x * 11;
   width = long_x * 18;
   font = new Font("Verdana", Font.PLAIN, 16);
   txtName = new PzrText(left, top * 3, width, height, "txtName", font, true);
   txtDescription = new PzrTextArea("txtDescription", font, false);
   PzrScrollPane scrollPane = new PzrScrollPane(left, top * 5, width, height * 5, txtDescription);
   _B.add(lblName);
   _B.add(lblDescription);
   _B.add(txtName);
   _B.add(scrollPane);
   // OK button
   this.btnOK =
       new PzrButton(
           long_x * 0,
           long_y * 0,
           long_x * maxx / 2,
           long_y * 3,
           "btnOK",
           "OK",
           palette.getColor(Palette.COLOR_OK),
           BorderFactory.createLineBorder(Color.white));
   this.btnOK.setForeground(palette.getColor("#FFFFFF"));
   this.btnOK.repaint("/gui/image/form_ok.png", 32, 32);
   this.btnOK.setHorizontalTextPosition(SwingConstants.RIGHT);
   this.btnOK.setVerifyInputWhenFocusTarget(false);
   // Cancel button
   this.btnCancel =
       new PzrButton(
           long_x * maxx / 2,
           long_y * 0,
           long_x * maxx / 2,
           long_y * 3,
           "btnCancel",
           "Cancel",
           palette.getColor(Palette.COLOR_CANCEL),
           BorderFactory.createLineBorder(Color.white));
   this.btnCancel.setForeground(palette.getColor("#FFFFFF"));
   this.btnCancel.repaint("/gui/image/form_cancel.png", 32, 32);
   this.btnCancel.setHorizontalTextPosition(SwingConstants.RIGHT);
   this.btnCancel.setVerifyInputWhenFocusTarget(false);
   // Add buttons
   _C.add(this.btnOK);
   _C.add(this.btnCancel);
   // Show
   this.setUndecorated(true);
   this.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
   this.setLocationRelativeTo(null);
   this.setModal(true);
 }
예제 #24
0
  /**
   * Inizialize frame components
   *
   * @throws CMSException
   * @throws FileNotFoundException
   * @throws IOException
   * @throws GeneralSecurityException
   */
  private void initComponents()
      throws CMSException, FileNotFoundException, IOException, GeneralSecurityException {

    // *********************************

    panel4 = new JPanel();
    label2 = new JLabel();
    textPane1 = new JTextPane();
    panel5 = new JPanel();
    textArea1 = new JTextArea();
    textArea2 = new JTextArea();

    progressBar = new JProgressBar();

    textPane2 = new JTextPane();
    textField1 = new JTextField();
    button1 = new JButton();
    panel6 = new JPanel();
    button2 = new JButton();
    button3 = new JButton();
    button4 = new JButton();
    GridBagConstraints gbc;
    // ======== this ========
    Container contentPane = getContentPane();
    contentPane.setLayout(new GridBagLayout());
    ((GridBagLayout) contentPane.getLayout()).columnWidths = new int[] {165, 0, 0};
    ((GridBagLayout) contentPane.getLayout()).rowHeights = new int[] {105, 50, 0};
    ((GridBagLayout) contentPane.getLayout()).columnWeights = new double[] {0.0, 1.0, 1.0E-4};
    ((GridBagLayout) contentPane.getLayout()).rowWeights = new double[] {1.0, 0.0, 1.0E-4};

    // ======== panel4 ========
    {
      panel4.setBackground(Color.white);
      panel4.setLayout(new GridBagLayout());
      ((GridBagLayout) panel4.getLayout()).columnWidths = new int[] {160, 0};
      ((GridBagLayout) panel4.getLayout()).rowHeights = new int[] {0, 0, 0};
      ((GridBagLayout) panel4.getLayout()).columnWeights = new double[] {0.0, 1.0E-4};
      ((GridBagLayout) panel4.getLayout()).rowWeights = new double[] {1.0, 1.0, 1.0E-4};

      // ---- label2 ----
      label2.setIcon(
          new ImageIcon(
              "images" + System.getProperty("file.separator") + "logo-freesigner-piccolo.png"));
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbc.insets.bottom = 5;
      panel4.add(label2, gbc);

      // ---- textPane1 ----
      textPane1.setFont(new Font("Verdana", Font.BOLD, 12));
      textPane1.setText("Lettura\ncertificati\nda token");
      textPane1.setEditable(false);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 1;
      gbc.anchor = GridBagConstraints.NORTHWEST;
      panel4.add(textPane1, gbc);
    }
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets.bottom = 5;
    gbc.insets.right = 5;
    contentPane.add(panel4, gbc);

    // ======== panel5 ========
    {
      panel5.setBackground(Color.white);
      panel5.setLayout(new GridBagLayout());
      ((GridBagLayout) panel5.getLayout()).columnWidths = new int[] {0, 205, 0, 0};
      ((GridBagLayout) panel5.getLayout()).rowHeights = new int[] {100, 0, 30, 30, 0};
      ((GridBagLayout) panel5.getLayout()).columnWeights = new double[] {1.0, 0.0, 1.0, 1.0E-4};
      ((GridBagLayout) panel5.getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0, 1.0, 1.0E-4};

      // ---- textArea1 ----
      textArea1.setFont(new Font("Verdana", Font.BOLD, 14));
      textArea1.setText("Lettura certificati da token");
      textArea1.setEditable(false);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.gridwidth = 3;
      gbc.fill = GridBagConstraints.VERTICAL;
      gbc.insets.bottom = 5;
      panel5.add(textArea1, gbc);

      // ---- textArea2 ----
      textArea2.setFont(new Font("Verdana", Font.PLAIN, 12));
      textArea2.setText("Ricerca certificati...\n");
      textArea2.setEditable(false);
      textArea2.setColumns(30);
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 1;
      gbc.gridwidth = 3;
      gbc.fill = GridBagConstraints.BOTH;
      panel5.add(textArea2, gbc);
      progressBar.setValue(0);
      progressBar.setMaximum(1);
      progressBar.setStringPainted(true);
      progressBar.setBounds(0, 0, 300, 150);

      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 2;
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbc.insets.bottom = 5;
      gbc.insets.right = 5;
      gbc.gridwidth = 3;
      panel5.add(progressBar, gbc);
    }
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets.bottom = 5;
    contentPane.add(panel5, gbc);

    // ======== panel6 ========
    {
      panel6.setBackground(Color.white);
      panel6.setLayout(new GridBagLayout());
      ((GridBagLayout) panel6.getLayout()).columnWidths = new int[] {0, 0, 0, 0};
      ((GridBagLayout) panel6.getLayout()).rowHeights = new int[] {0, 0};
      ((GridBagLayout) panel6.getLayout()).columnWeights = new double[] {1.0, 1.0, 1.0, 1.0E-4};
      ((GridBagLayout) panel6.getLayout()).rowWeights = new double[] {1.0, 1.0E-4};

      // ---- button2 ----
      button2.setText("Indietro");
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.insets.right = 5;
      button2.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {

              frame.hide();

              FreeSignerSignApplet nuovo = new FreeSignerSignApplet();
            }
          });

      // panel6.add(button2, gbc);

      // ---- button4 ----
      button4.setText("Annulla");
      gbc = new GridBagConstraints();
      gbc.gridx = 2;
      gbc.gridy = 0;
      // panel6.add(button4, gbc);
    }
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.BOTH;
    contentPane.add(panel6, gbc);
    contentPane.setBackground(Color.white);
    frame = new JFrame();
    frame.setContentPane(contentPane);
    frame.setTitle("Freesigner");
    frame.setSize(300, 150);
    frame.setResizable(false);
    frame.pack();
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getWidth()) / 2, (d.height - frame.getHeight()) / 2);

    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    timer =
        new Timer(
            10,
            new ActionListener() {

              public void actionPerformed(ActionEvent evt) {
                frame.show();
                if (task.getMessage() != null) {
                  String s = new String();
                  s = task.getMessage();
                  s = s.substring(0, Math.min(60, s.length()));

                  textArea2.setText(s + " ");
                  progressBar.setValue(task.getStatus());
                }
                if (task.isDone()) {
                  timer.stop();

                  // Finalizzo la cryptoki, onde evitare
                  // successivi errori PKCS11 "cryptoki alreadi initialized"

                  if ((task != null)) task.libFinalize();

                  ArrayList slotInfos = task.getSlotInfos();
                  if ((slotInfos == null) || slotInfos.isEmpty()) {

                    frame.show();

                    JOptionPane.showMessageDialog(
                        frame,
                        "Controllare la presenza sul sistema\n"
                            + "della libreria PKCS11 impostata.",
                        "Nessun lettore rilevato",
                        JOptionPane.WARNING_MESSAGE);

                    frame.hide();

                  } else {
                    String st = task.getCRLerror();

                    if (st.length() > 0) {
                      timer.stop();

                      JOptionPane.showMessageDialog(
                          frame,
                          "C'è stato un errore nella verifica CRL.\n" + st,
                          "Errore verifica CRL",
                          JOptionPane.ERROR_MESSAGE);
                      frame.hide();
                      FreeSignerSignApplet nuovo = new FreeSignerSignApplet();
                    }
                    if (task.getDifferentCerts() == 0) {
                      if (task.getCIr() != null) {
                        JOptionPane.showMessageDialog(
                            frame,
                            "La carta "
                                + task.getCardDescription()
                                + " nel lettore "
                                + conf.getReader()
                                + " non contiene certificati",
                            "Attenzione",
                            JOptionPane.WARNING_MESSAGE);

                      } else
                        JOptionPane.showMessageDialog(
                            frame, task.getMessage(), "Errore:", JOptionPane.ERROR_MESSAGE);
                    }

                    frame.hide();

                    // confFrame.createTreeAndTokenNodes(task.getSlotInfos());

                  }
                }
              }
            });
  }