public void actionPerformed(ActionEvent e) {
      int selIndexBefore = getSelectedIndex();
      myDefaultAction.actionPerformed(e);
      int selIndexCurrent = getSelectedIndex();
      if (selIndexBefore != selIndexCurrent) {
        return;
      }
      if (myFocusNext && selIndexCurrent == 0) {
        return;
      }

      KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
      Container container = kfm.getCurrentFocusCycleRoot();
      FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
      if (policy == null) {
        policy = kfm.getDefaultFocusTraversalPolicy();
      }
      Component next =
          myFocusNext
              ? policy.getComponentAfter(container, PaletteItemsComponent.this)
              : policy.getComponentBefore(container, PaletteItemsComponent.this);
      if (next instanceof PaletteGroupComponent) {
        clearSelection();
        next.requestFocus();
        ((PaletteGroupComponent) next).scrollRectToVisible(next.getBounds());
      }
    }
Ejemplo n.º 2
0
  public CreInvChecker(Component parent) {
    typeButtons = new JCheckBox[CHECKTYPES.length];
    JPanel boxPanel = new JPanel(new GridLayout(0, 1));
    for (int i = 0; i < typeButtons.length; i++) {
      typeButtons[i] = new JCheckBox(CHECKTYPES[i], true);
      boxPanel.add(typeButtons[i]);
    }
    bstart.setMnemonic('s');
    bcancel.setMnemonic('c');
    bstart.addActionListener(this);
    bcancel.addActionListener(this);
    selectframe.getRootPane().setDefaultButton(bstart);
    selectframe.setIconImage(Icons.getIcon("Find16.gif").getImage());
    boxPanel.setBorder(BorderFactory.createTitledBorder("Select test to check:"));

    JPanel bpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    bpanel.add(bstart);
    bpanel.add(bcancel);

    JPanel mainpanel = new JPanel(new BorderLayout());
    mainpanel.add(boxPanel, BorderLayout.CENTER);
    mainpanel.add(bpanel, BorderLayout.SOUTH);
    mainpanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    JPanel pane = (JPanel) selectframe.getContentPane();
    pane.setLayout(new BorderLayout());
    pane.add(mainpanel, BorderLayout.CENTER);

    selectframe.pack();
    Center.center(selectframe, parent.getBounds());
    selectframe.setVisible(true);
  }
Ejemplo n.º 3
0
  private boolean is(boolean first) {
    Container parent = getParent();
    if (parent == null) return false;

    int max = first ? Integer.MAX_VALUE : 0;
    ToolWindowAnchor anchor = getAnchor();
    Component c = null;
    int count = parent.getComponentCount();
    for (int i = 0; i < count; i++) {
      Component component = parent.getComponent(i);
      if (!component.isVisible()) continue;
      Rectangle r = component.getBounds();
      if (anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT) {
        if (first && (max > r.y) || (!first && max < r.y)) {
          max = r.y;
          c = component;
        }
      } else {
        if (first && (max > r.x) || (!first && max < r.x)) {
          max = r.x;
          c = component;
        }
      }
    }

    return c == this;
  }
Ejemplo n.º 4
0
  /**
   * method to negotiate draganddrop when mouse is pressed
   *
   * @param e
   */
  public void mousePressed(MouseEvent e) {
    /** Set up click point and set ActivePanel */
    Point p = e.getPoint();
    System.out.println(p);
    if (!setActivePanel(p)) return;

    /** record where the initial click occurred */
    OriP = activePanel;

    /** Check whether click was over an image label */
    selectedComponent = getImageLabel(p);
    if (selectedComponent == null) return;

    /** Check whether click was over waste box */
    if (selectedComponent.getName().equals("WasteBox")) return;

    /**
     * remove selected component from active panel add it to the glass panel set the offset and
     * original position
     */
    Rectangle labelR = selectedComponent.getBounds();
    Rectangle panelR = activePanel.getBounds();
    //  if(labelR.contains(p.x - panelR.x, p.y - panelR.y))
    //  {
    activePanel.remove(selectedComponent);
    selected = true;
    glassPanel.add(selectedComponent);
    offset.x = p.x - labelR.x - panelR.x;
    offset.y = p.y - labelR.y - panelR.y;
    dragging = true;
    Original = labelR.getLocation();
    //  }
  }
  protected Rectangle getTextComponentBound() {
    Rectangle ownerRec = myOwner == null ? new Rectangle(0, 0, 0, 0) : myOwner.getBounds();

    Dimension size = myComponent.getPreferredSize();
    int x = (ownerRec.width - size.width) / 2;
    int y = (ownerRec.height - size.height) / 3;
    return new Rectangle(x, y, size.width, size.height);
  }
Ejemplo n.º 6
0
 /*
  *  Create a BufferedImage for AWT components.
  *
  *  @param	 component AWT component to create image from
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception AWTException see Robot class constructors
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(Component component, String fileName)
     throws AWTException, IOException {
   Point p = new Point(0, 0);
   SwingUtilities.convertPointToScreen(p, component);
   Rectangle region = component.getBounds();
   region.x = p.x;
   region.y = p.y;
   return ScreenCapture.createImage(region, fileName);
 }
Ejemplo n.º 7
0
 @Override
 public void doLayout() {
   int x = 0;
   for (int i = 0; i < getComponentCount(); i++) {
     final Component each = getComponent(i);
     final Dimension eachSize = each.getPreferredSize();
     each.setBounds(x, 0, eachSize.width, getHeight());
     x += each.getBounds().width;
   }
 }
 @Override
 public void doLayout() {
   super.doLayout();
   Component child = getComponentCount() == 1 ? getComponent(0) : null;
   if (child instanceof JBTabsPresentation) {
     if (!((JBTabsPresentation) child).isHideTabs()) {
       Rectangle bounds = child.getBounds();
       bounds.y--;
       bounds.height++;
       child.setBounds(bounds);
     }
   }
 }
Ejemplo n.º 9
0
  public static void setToplevelLocation(
      Window toplevel, Component component, int relativePosition) {

    Rectangle compBounds = component.getBounds();

    // Convert component location to screen coordinates
    Point p = new Point();
    SwingUtilities.convertPointToScreen(p, component);

    int x;
    int y;

    // Set frame location to be centered on panel
    switch (relativePosition) {
      case SwingConstants.NORTH:
        {
          x = (p.x + (compBounds.width / 2)) - (toplevel.getWidth() / 2);
          y = p.y - toplevel.getHeight();
          break;
        }
      case SwingConstants.EAST:
        {
          x = p.x + compBounds.width;
          y = (p.y + (compBounds.height / 2)) - (toplevel.getHeight() / 2);
          break;
        }
      case SwingConstants.SOUTH:
        {
          x = (p.x + (compBounds.width / 2)) - (toplevel.getWidth() / 2);
          y = p.y + compBounds.height;
          break;
        }
      case SwingConstants.WEST:
        {
          x = p.x - toplevel.getWidth();
          y = (p.y + (compBounds.height / 2)) - (toplevel.getHeight() / 2);
          break;
        }
      case SwingConstants.NORTH_EAST:
        {
          x = p.x + compBounds.width;
          y = p.y - toplevel.getHeight();
          break;
        }
      case SwingConstants.NORTH_WEST:
        {
          x = p.x - toplevel.getWidth();
          y = p.y - toplevel.getHeight();
          break;
        }
      case SwingConstants.SOUTH_EAST:
        {
          x = p.x + compBounds.width;
          y = p.y + compBounds.height;
          break;
        }
      case SwingConstants.SOUTH_WEST:
        {
          x = p.x - toplevel.getWidth();
          y = p.y + compBounds.height;
          break;
        }
      default:
      case SwingConstants.CENTER:
        {
          x = (p.x + (compBounds.width / 2)) - (toplevel.getWidth() / 2);
          y = (p.y + (compBounds.height / 2)) - (toplevel.getHeight() / 2);
        }
    }
    toplevel.setLocation(x, y);
  }
Ejemplo n.º 10
0
 /**
  * A very nice trick is to center dialog with their parent.
  *
  * @param parent The parent <code>Component</code>
  * @param child The <code>Component</code> to center
  */
 public static void centerComponentChild(Component parent, Component child) {
   Rectangle par = parent.getBounds();
   Rectangle chi = child.getBounds();
   child.setLocation(
       new Point(par.x + (par.width - chi.width) / 2, par.y + (par.height - chi.height) / 2));
 }
Ejemplo n.º 11
0
  public void layoutContainer(Container parent) {
    Insets insets = parent.insets();
    int ncomponents = parent.countComponents();
    int nrows = getRows();
    int ncols = getColumns();
    int hgap = getHgap();
    int vgap = getVgap();

    if (nrows > 0) {
      ncols = (ncomponents + nrows - 1) / nrows;
    } else {
      nrows = (ncomponents + ncols - 1) / ncols;
    }

    // Set heights
    int x;
    int y;
    int nFills = 0;
    boolean[] fills = new boolean[nrows];
    int lastFillRow = -1;
    int nComps = parent.getComponentCount();

    y = insets.top;
    for (int row = 0; row < nrows; row++) {
      // Find largest minimum height for this row
      int h = 0;
      for (int col = 0; col < ncols; col++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          h = Math.max(h, c.getMinimumSize().height);
        }
      }
      // Set heights for this row
      x = insets.left;
      for (int col = 0; col < ncols; col++) {
        if (row * ncols + col < nComps) {
          JComponent c = (JComponent) parent.getComponent(row * ncols + col);
          int w = c.getWidth();
          c.setBounds(x, y, w, h);
          x += w + hgap;
          if (col == 0 && getFillRow(c)) {
            fills[row] = true;
          }
        }
      }
      y += h + vgap;
      if (fills[row]) {
        nFills++;
        lastFillRow = row;
      }
    }

    // Fill heights
    if (nFills > 0 && y < parent.getHeight()) {
      // How much height to add
      int hAdd = (parent.getHeight() - y) / nFills;
      int hAdded = 0;
      for (int row = 0; row < nrows; row++) {
        if (fills[row]) {
          if (row == lastFillRow) {
            // Compensate for rounding error
            hAdd = parent.getHeight() - (y + hAdded);
          }
          for (int col = 0; col < ncols; col++) {
            if (row * ncols + col < nComps) {
              Component c = parent.getComponent(row * ncols + col);
              Rectangle b = c.getBounds();
              c.setBounds(b.x, b.y + hAdded, b.width, b.height + hAdd);
            }
          }
          hAdded += hAdd;
        }
      }
    }

    // Set widths
    nFills = 0;
    fills = new boolean[ncols];
    int lastFillCol = -1;

    x = insets.left;
    for (int col = 0; col < ncols; col++) {
      // Find largest minimum width for this column
      int w = 0;
      for (int row = 0; row < nrows; row++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          w = Math.max(w, c.getMinimumSize().width);
        }
      }
      // Set widths for this column
      y = insets.top;
      for (int row = 0; row < nrows; row++) {
        if (row * ncols + col < nComps) {
          JComponent c = (JComponent) parent.getComponent(row * ncols + col);
          int h = c.getHeight();
          c.setBounds(x, y, w, h);
          y += h + vgap;
          if (row == 0 && getFillColumn(c)) {
            fills[col] = true;
          }
        }
      }
      x += w + hgap;
      if (fills[col]) {
        nFills++;
        lastFillCol = col;
      }
    }

    // Fill widths
    if (nFills > 0 && x < parent.getWidth()) {
      // How much width to add
      int wAdd = (parent.getWidth() - x) / nFills;
      int wAdded = 0;
      for (int col = 0; col < ncols; col++) {
        if (fills[col]) {
          if (col == lastFillCol) {
            wAdd = parent.getWidth() - (x + wAdded);
          }
          for (int row = 0; row < nrows; row++) {
            if (row * ncols + col < nComps) {
              Component c = parent.getComponent(row * ncols + col);
              Rectangle b = c.getBounds();
              c.setBounds(b.x + wAdded, b.y, b.width + wAdd, b.height);
            }
          }
          wAdded += wAdd;
        }
      }
    }
  }