Esempio n. 1
0
 /**
  * Adds a component to the layout.
  *
  * @param name The name of the component to add.
  * @param component the component to add to the layout.
  */
 public void addLayoutComponent(String name, Component component) {
   if (way == X_AXIS
       || (way == LINE_AXIS && component.getComponentOrientation().isHorizontal())
       || (way == PAGE_AXIS && !component.getComponentOrientation().isHorizontal()))
     grid.setColumns(grid.getColumns() + 1);
   else grid.setRows(grid.getRows() + 1);
 }
Esempio n. 2
0
  /**
   * Removes a component from the layout.
   *
   * @param component The component to remove from the layout.
   */
  public void removeLayoutComponent(Component component) {
    grid.removeLayoutComponent(component);

    if (way == X_AXIS
        || (way == LINE_AXIS && component.getComponentOrientation().isHorizontal())
        || (way == PAGE_AXIS && !component.getComponentOrientation().isHorizontal()))
      grid.setColumns(grid.getColumns() - 1);
    else grid.setRows(grid.getRows() - 1);
  }
  public static JPaymentSelect getDialog(Component parent) {

    Window window = getWindow(parent);

    if (window instanceof Frame) {
      return new JPaymentSelectRefund((Frame) window, true, parent.getComponentOrientation());
    } else {
      return new JPaymentSelectRefund((Dialog) window, true, parent.getComponentOrientation());
    }
  }
Esempio n. 4
0
    public Insets getBorderInsets(Component c, Insets newInsets) {
      if (MetalLookAndFeel.usingOcean()) {
        newInsets.set(1, 2, 3, 2);
      } else {
        newInsets.top = newInsets.left = newInsets.bottom = newInsets.right = 2;
      }

      if (((JToolBar) c).isFloatable()) {
        if (((JToolBar) c).getOrientation() == HORIZONTAL) {
          if (c.getComponentOrientation().isLeftToRight()) {
            newInsets.left = 16;
          } else {
            newInsets.right = 16;
          }
        } else { // vertical
          newInsets.top = 16;
        }
      }

      Insets margin = ((JToolBar) c).getMargin();

      if (margin != null) {
        newInsets.left += margin.left;
        newInsets.top += margin.top;
        newInsets.right += margin.right;
        newInsets.bottom += margin.bottom;
      }

      return newInsets;
    }
Esempio n. 5
0
  public void paintBorder(final Component c, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2d = (Graphics2D) g;
    GradientPaint paint;
    Paint oldPaint = g2d.getPaint();
    int textX;
    Font f = c.getFont();
    g2d.setFont(f);
    x += 2;
    width -= 1;
    if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT) {
      textX = x + width - 4 - g2d.getFontMetrics().stringWidth(title);
      paint = new GradientPaint(x, y, destinationColor, width, height, sourceColor);
    } else {
      y += 2;
      textX = x + 4;
      paint = new GradientPaint(x, y, sourceColor, width, height, destinationColor);
    }

    height = f.getSize() + 6;
    g2d.setPaint(paint);
    g2d.fillRect(x, y, width, height);
    g2d.setPaint(oldPaint);

    g2d.setColor(textColor);
    g2d.drawString(title, textX, y + height - 5);
  }
  /**
   * Draws a simple 3d border for the given component.
   *
   * @param c The component to draw its border.
   * @param g The graphics context.
   * @param x The x coordinate of the top left corner.
   * @param y The y coordinate of the top left corner.
   * @param w The width.
   * @param h The height.
   */
  public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    boolean isHorizontal = ((JToolBar) c).getOrientation() == HORIZONTAL;

    g.setColor(MetouiaLookAndFeel.getControlHighlight());
    if (isHorizontal) {
      g.drawLine(0, 0, w - 1, 0);
    } else {
      g.drawLine(0, 0, 0, h - 1);
    }

    g.setColor(MetouiaLookAndFeel.getControlShadow());
    if (isHorizontal) {
      g.drawLine(0, h - 1, w - 1, h - 1);
    } else {
      g.drawLine(w - 1, 0, w - 1, h - 1);
    }

    g.translate(x, y);

    if (((JToolBar) c).isFloatable()) {
      if (((JToolBar) c).getOrientation() == HORIZONTAL) {
        dots.setDotsArea(5, c.getSize().height - 4);
        if (c.getComponentOrientation().isLeftToRight()) {
          dots.paintIcon(c, g, 2, 2);
        } else {
          dots.paintIcon(c, g, c.getBounds().width - 12, 2);
        }
      } else {
        dots.setDotsArea(c.getSize().width - 4, 5);
        dots.paintIcon(c, g, 2, 2);
      }
    }

    g.translate(-x, -y);
  }
 // region Public Methods
 public void showDialog(Component owner) {
   this.setComponentOrientation(owner.getComponentOrientation());
   this.pack();
   this.setResizable(false);
   this.setLocationRelativeTo(owner);
   this.setVisible(true);
 }
  // region Public Methods
  public boolean showDialog(Component owner) {
    this.setComponentOrientation(owner.getComponentOrientation());
    this.pack();
    this.setResizable(false);
    this.setLocationRelativeTo(owner);
    this.setVisible(true);

    return this.connectionDetails != null;
  }
Esempio n. 9
0
  // PENDING JW: this isn't aware of sorting/filtering - fix!
  private static boolean pointIsInActualBounds(JList list, int index, Point point) {
    ListCellRenderer renderer = list.getCellRenderer();
    ListModel model = list.getModel();
    Object element = model.getElementAt(index);
    Component comp = renderer.getListCellRendererComponent(list, element, index, false, false);

    Dimension prefSize = comp.getPreferredSize();
    Rectangle cellBounds = list.getCellBounds(index, index);
    if (!(comp.getComponentOrientation().isLeftToRight())) {
      cellBounds.x += cellBounds.width - prefSize.width;
    }
    cellBounds.width = prefSize.width;

    return cellBounds.contains(point);
  }
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   if (c.getComponentOrientation().isLeftToRight()) {
     int xoffset = checkBox.getPreferredSize().width;
     int yoffset = (getIconHeight() - icon.getIconHeight()) / 2;
     icon.paintIcon(c, g, x + xoffset, y + yoffset);
     if (state != UNCHECKABLE) {
       paintCheckBox(g, x, y);
     }
   } else {
     int yoffset = (getIconHeight() - icon.getIconHeight()) / 2;
     icon.paintIcon(c, g, x, y + yoffset);
     if (state != UNCHECKABLE) {
       paintCheckBox(g, x + icon.getIconWidth(), y);
     }
   }
 }
 /*
  * Convenience function for determining ComponentOrientation.
  * Helps us avoid having Munge directives throughout the code.
  */
 static boolean isLeftToRight(Component c) {
   return c.getComponentOrientation().isLeftToRight();
 }
 public static boolean isLeftToRight(Component c) {
   if (c == null) {
     return true;
   }
   return c.getComponentOrientation().isLeftToRight();
 }
Esempio n. 13
0
    /**
     * Paints the border for the specified component with the specified position and size.
     *
     * @param c the component for which this border is being painted
     * @param g the paint graphics
     * @param x the x position of the painted border
     * @param y the y position of the painted border
     * @param width the width of the painted border
     * @param height the height of the painted border
     */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

      Border border = getBorder();

      if (label == null) {
        if (border != null) {
          border.paintBorder(c, g, x, y, width, height);
        }
        return;
      }

      Rectangle grooveRect =
          new Rectangle(
              x + EDGE_SPACING,
              y + EDGE_SPACING,
              width - (EDGE_SPACING * 2),
              height - (EDGE_SPACING * 2));

      Dimension labelDim = label.getPreferredSize();
      int baseline = label.getBaseline(labelDim.width, labelDim.height);
      int ascent = Math.max(0, baseline);
      int descent = labelDim.height - ascent;
      int diff;
      Insets insets;

      if (border != null) {
        insets = border.getBorderInsets(c);
      } else {
        insets = new Insets(0, 0, 0, 0);
      }

      diff = Math.max(0, ascent / 2 + TEXT_SPACING - EDGE_SPACING);
      grooveRect.y += diff;
      grooveRect.height -= diff;
      compLoc.y = grooveRect.y + insets.top / 2 - (ascent + descent) / 2 - 1;

      int justification;
      if (c.getComponentOrientation().isLeftToRight()) {
        justification = LEFT;
      } else {
        justification = RIGHT;
      }

      switch (justification) {
        case LEFT:
          compLoc.x = grooveRect.x + TEXT_INSET_H + insets.left;
          break;
        case RIGHT:
          compLoc.x =
              (grooveRect.x + grooveRect.width - (labelDim.width + TEXT_INSET_H + insets.right));
          break;
      }

      // If title is positioned in middle of border AND its fontsize
      // is greater than the border's thickness, we'll need to paint
      // the border in sections to leave space for the component's background
      // to show through the title.
      //
      if (border != null) {
        if (grooveRect.y > compLoc.y - ascent) {
          Rectangle clipRect = new Rectangle();

          // save original clip
          Rectangle saveClip = g.getClipBounds();

          // paint strip left of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(clipRect, x, y, compLoc.x - 1 - x, height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip right of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x + labelDim.width + 1,
              y,
              x + width - (compLoc.x + labelDim.width + 1),
              height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip below text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x - 1,
              compLoc.y + ascent + descent,
              labelDim.width + 2,
              y + height - compLoc.y - ascent - descent)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // restore clip
          g.setClip(saveClip);

        } else {
          border.paintBorder(c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
        }

        label.setLocation(compLoc);
        label.setSize(labelDim);
      }
    }