예제 #1
0
  public static int getRoundedInteriorCorner(JComponent c) {
    if (!(c.getBorder() instanceof PBorder) && !(c.getBorder() instanceof PRoundBorder)) {
      return 0;
    }

    int h = c.getHeight() - (getBorderSize(c) * 2);
    int roundCorner = h;

    String ctype = (String) c.getClientProperty("JComponent.type");
    if (ctype != null) {
      if (ctype.equals("roundRect")) {
        return roundCorner;
      } else if (ctype.equals("square")) {
        return 0;
      } else if (ctype.equals("normal")) {
        return DEFAULT_ROUND_CORNER;
      }
    }

    Integer maxRoundCorner = (Integer) c.getClientProperty("maxRoundCorner");
    if (maxRoundCorner != null && maxRoundCorner >= 0) {
      roundCorner = Math.min(roundCorner, maxRoundCorner);
    }
    return roundCorner;
  }
  public static void componenteError(JComponent componente, String sms) {
    if (componente == null) {
      return;
    }

    cache.put(componente, componente.getBorder());

    Border bIn = componente.getBorder();
    Border bOut = BorderFactory.createLineBorder(Color.RED);
    Border bComp = BorderFactory.createCompoundBorder(bOut, bIn);
    componente.setBorder(bComp);

    ToolTipManager.sharedInstance().setInitialDelay(500);
    setToolTipText(componente, sms);
  }
예제 #3
0
 /**
  * Returns an enum indicating how the baseline of the component changes as the size changes.
  *
  * @throws NullPointerException {@inheritDoc}
  * @see javax.swing.JComponent#getBaseline(int, int)
  * @since 1.6
  */
 public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) {
   super.getBaselineResizeBehavior(c);
   Border border = c.getBorder();
   if (border instanceof AbstractBorder) {
     return ((AbstractBorder) border).getBaselineResizeBehavior(c);
   }
   return Component.BaselineResizeBehavior.OTHER;
 }
예제 #4
0
 /**
  * Returns the baseline.
  *
  * @throws NullPointerException {@inheritDoc}
  * @throws IllegalArgumentException {@inheritDoc}
  * @see javax.swing.JComponent#getBaseline(int, int)
  * @since 1.6
  */
 public int getBaseline(JComponent c, int width, int height) {
   super.getBaseline(c, width, height);
   Border border = c.getBorder();
   if (border instanceof AbstractBorder) {
     return ((AbstractBorder) border).getBaseline(c, width, height);
   }
   return -1;
 }
예제 #5
0
 public PercentEditor(JComboBox comboBox) {
   super(NumberFormat.getPercentInstance());
   addPropertyChangeListener("value", this);
   // We steal the border from the LAF's editor
   // Note: this doesn't work for Nimbus
   JComponent oldEditor = (JComponent) comboBox.getEditor().getEditorComponent();
   setBorder(oldEditor.getBorder());
 }
 @Override
 public Dimension getPreferredSize(JComponent c) {
   Dimension size = super.getPreferredSize(c);
   if (c.getBorder() instanceof MacIntelliJButtonBorder || isComboButton(c)) {
     return new Dimension(size.width + (isComboButton(c) ? 8 : 16), 27);
   }
   return size;
 }
예제 #7
0
 /**
  * Removes the previous content border from the specified component, and sets an empty border if
  * there has been no border or an UIResource instance before.
  */
 private void stripContentBorder(Object c) {
   if (c instanceof JComponent) {
     JComponent contentComp = (JComponent) c;
     Border contentBorder = contentComp.getBorder();
     if (contentBorder == null || contentBorder instanceof UIResource) {
       contentComp.setBorder(handyEmptyBorder);
     }
   }
 }
예제 #8
0
 private Insets getVisualMargin(JComponent component) {
   String uid = component.getUIClassID();
   String style = null;
   if (uid == "ButtonUI" || uid == "ToggleButtonUI") {
     style = (String) component.getClientProperty("JButton.buttonType");
   } else if (uid == "ProgressBarUI") {
     style =
         (((JProgressBar) component).getOrientation() == JProgressBar.HORIZONTAL)
             ? "horizontal"
             : "vertical";
   } else if (uid == "SliderUI") {
     style =
         (((JSlider) component).getOrientation() == JProgressBar.HORIZONTAL)
             ? "horizontal"
             : "vertical";
   } else if (uid == "TabbedPaneUI") {
     switch (((JTabbedPane) component).getTabPlacement()) {
       case JTabbedPane.TOP:
         style = "top";
         break;
       case JTabbedPane.LEFT:
         style = "left";
         break;
       case JTabbedPane.BOTTOM:
         style = "bottom";
         break;
       case JTabbedPane.RIGHT:
         style = "right";
         break;
     }
   }
   Insets gap = getInsets(VISUAL_MARGINS, uid, style, 0);
   // Take into account different positions of the button icon
   if (uid == "RadioButtonUI" || uid == "CheckBoxUI") {
     switch (((AbstractButton) component).getHorizontalTextPosition()) {
       case SwingConstants.RIGHT:
         gap = new Insets(gap.top, gap.right, gap.bottom, gap.left);
         break;
       case SwingConstants.CENTER:
         gap = new Insets(gap.top, gap.right, gap.bottom, gap.right);
         break;
         /*
         case SwingConstants.LEFT :
             break;
              */
       default:
         gap = new Insets(gap.top, gap.left, gap.bottom, gap.right);
     }
     if (component.getBorder() instanceof EmptyBorder) {
       gap.left -= 2;
       gap.right -= 2;
       gap.top -= 2;
       gap.bottom -= 2;
     }
   }
   return gap;
 }
 private boolean isFixedHeight(JComponent c) {
   Border b = c.getBorder();
   if (b != null && b instanceof BackgroundBorder) {
     b = ((BackgroundBorder) b).getBackgroundBorder();
     if (b != null && b instanceof QuaquaButtonBorder) {
       return ((QuaquaButtonBorder) b).isFixedHeight(c);
     }
   }
   return false;
 }
 private void applyFocus(boolean hasFocus, JComponent c) {
   if (hasFocus) {
     c.setBorder(
         BorderFactory.createMatteBorder(1, 1, 1, 1, table.getSelectionBackground().darker()));
   } else {
     if (c.getBorder() != null) {
       c.setBorder(null);
     }
   }
 }
예제 #11
0
  /**
   * Initializes the layout of this <code>GroupBox</code>.
   *
   * @param buttons The buttons to be shown at the top-left section of the group box
   * @param panes The panes to be shown as a group where a button is shown as a pane's title
   */
  protected void initializeLayout(AbstractButton[] buttons, JComponent[] panes) {
    checkIntegrity(buttons, panes);

    GridBagConstraints constraints = new GridBagConstraints();

    for (int index = 0; index < buttons.length; index++) {
      boolean paneWasAddedBefore = ((index > 0) && (panes[index - 1] != NO_PANE));

      // First add the button
      AbstractButton button = buttons[index];
      button.setOpaque(false); // Requires to paint the titled border properly
      button.setBorder(
          BorderFactory.createCompoundBorder(
              BorderFactory.createEmptyBorder(0, 5, 0, 0), button.getBorder()));

      if (panes[index] != NO_PANE) {
        button.addItemListener(buildRepainterHandler());
      }

      constraints.gridx = 0;
      constraints.gridy = index;
      constraints.gridwidth = 1;
      constraints.gridheight = 1;
      constraints.weightx = 0;
      constraints.weighty = 0;
      constraints.fill = GridBagConstraints.NONE;
      constraints.anchor = GridBagConstraints.FIRST_LINE_START;
      constraints.insets = new Insets(paneWasAddedBefore ? 5 : 0, 0, 0, 0);

      add(button, constraints);

      // Now add the pane if one is associated with the button
      JComponent pane = panes[index];

      if (pane != NO_PANE) {
        boolean fillVertical = shouldFillVertical(pane);
        int top = button.getPreferredSize().height / 2 - 6;

        pane.setBorder(
            BorderFactory.createCompoundBorder(createPaneBorder(button, pane), pane.getBorder()));

        constraints.gridx = 0;
        constraints.gridy = index;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.weightx = 1;
        constraints.weighty = fillVertical ? 1 : 0;
        constraints.fill = fillVertical ? GridBagConstraints.BOTH : GridBagConstraints.HORIZONTAL;
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.insets = new Insets(paneWasAddedBefore ? top + 5 : top, 0, 0, 0);

        add(pane, constraints);
      }
    }
  }
예제 #12
0
  /** Uninstalls the UI delegate for the specified component */
  public void uninstallUI(JComponent c) {
    frame = (JInternalFrame) c;

    Container cont = ((JInternalFrame) (c)).getContentPane();
    if (cont instanceof JComponent) {
      JComponent content = (JComponent) cont;
      if (content.getBorder() == handyEmptyBorder) {
        content.setBorder(null);
      }
    }
    super.uninstallUI(c);
  }
예제 #13
0
 /** Sets an empty border with consistent insets. */
 private void configureEditorBorder(JComponent editor) {
   if ((editor instanceof JSpinner.DefaultEditor)) {
     JSpinner.DefaultEditor defaultEditor = (JSpinner.DefaultEditor) editor;
     JTextField editorField = defaultEditor.getTextField();
     Insets insets = UIManager.getInsets("Spinner.defaultEditorInsets");
     editorField.setBorder(new EmptyBorder(insets));
   } else if ((editor instanceof JPanel)
       && (editor.getBorder() == null)
       && (editor.getComponentCount() > 0)) {
     JComponent editorField = (JComponent) editor.getComponent(0);
     Insets insets = UIManager.getInsets("Spinner.defaultEditorInsets");
     editorField.setBorder(new EmptyBorder(insets));
   }
 }
  public void uninstallUI(JComponent c) {
    frame = (JInternalFrame) c;

    c.removePropertyChangeListener(paletteListener);
    c.removePropertyChangeListener(contentPaneListener);

    Container cont = ((JInternalFrame) (c)).getContentPane();
    if (cont instanceof JComponent) {
      JComponent content = (JComponent) cont;
      if (content.getBorder() == EMPTY_BORDER) {
        content.setBorder(null);
      }
    }
    super.uninstallUI(c);
  }
 private void loadImage(Editor editor) {
   JComponent contentComponent = editor.getContentComponent();
   Border border = contentComponent.getBorder();
   if (border instanceof BackgroundImageBorder) {
     BackgroundImageBorder backgroundImageBorder = (BackgroundImageBorder) border;
     if (imagesList.size() > 1) {
       int i = random.nextInt(imagesList.size());
       ImageHolder imageHolder = imagesList.get(i);
       backgroundImageBorder.setImageHolder(imageHolder);
     } else if (imagesList.size() == 1) {
       backgroundImageBorder.setImageHolder(imagesList.get(0));
     } else {
       backgroundImageBorder.setImageHolder(null);
     }
     contentComponent.repaint();
   }
 }
예제 #16
0
 @Override
 public int getIconWidth(SynthContext context) {
   if (context == null) {
     return width;
   }
   JComponent c = context.getComponent();
   if (c instanceof JToolBar && ((JToolBar) c).getOrientation() == JToolBar.VERTICAL) {
     // we only do the -1 hack for UIResource borders, assuming
     // that the border is probably going to be our border
     if (c.getBorder() instanceof UIResource) {
       return c.getWidth() - 1;
     } else {
       return c.getWidth();
     }
   } else {
     return scale(context, width);
   }
 }
  @Override
  public void paint(Graphics g, JComponent c) {

    String style = (String) c.getClientProperty("Quaqua.Button.style");
    if (style != null && style.equals("help")) {
      Insets insets = c.getInsets();
      UIManager.getIcon("Button.helpIcon").paintIcon(c, g, insets.left, insets.top);
      return;
    }

    Object oldHints = QuaquaUtilities.beginGraphics((Graphics2D) g);
    if (((AbstractButton) c).isBorderPainted()) {
      Border b = c.getBorder();
      if (b != null && b instanceof BackgroundBorder) {
        ((BackgroundBorder) b)
            .getBackgroundBorder()
            .paintBorder(c, g, 0, 0, c.getWidth(), c.getHeight());
      }
    }
    super.paint(g, c);
    QuaquaUtilities.endGraphics((Graphics2D) g, oldHints);
    Debug.paint(g, c, this);
  }
예제 #18
0
 @Override
 public void paint(Graphics g, JComponent c) {
   final Border border = c.getBorder();
   final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
   final boolean square = isSquare(c);
   if (c.isEnabled() && border != null) {
     final Insets ins = border.getBorderInsets(c);
     final int yOff = (ins.top + ins.bottom) / 4;
     if (!square) {
       if (((JButton) c).isDefaultButton()) {
         ((Graphics2D) g)
             .setPaint(
                 UIUtil.getGradientPaint(
                     0,
                     0,
                     getSelectedButtonColor1(),
                     0,
                     c.getHeight(),
                     getSelectedButtonColor2()));
       } else {
         ((Graphics2D) g)
             .setPaint(
                 UIUtil.getGradientPaint(
                     0, 0, getButtonColor1(), 0, c.getHeight(), getButtonColor2()));
       }
     }
     g.fillRoundRect(
         square ? 2 : 4,
         yOff,
         c.getWidth() - 2 * 4,
         c.getHeight() - 2 * yOff,
         square ? 3 : 5,
         square ? 3 : 5);
   }
   config.restore();
   super.paint(g, c);
 }
예제 #19
0
// ----------------------------------------------------------------------------
예제 #20
0
  /**
   * Paint xp button background.
   *
   * @param nomalColor the nomal color
   * @param g the g
   * @param c the c
   */
  public static void paintXPButtonBackground(NormalColor nomalColor, Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;

    //		BEXPStyle xp = BEXPStyle.getXP();

    boolean toolbar = (b.getParent() instanceof JToolBar);
    //		Part part = getXPButtonType(b);

    if (b.isContentAreaFilled()) // && xp != null)
    {
      ButtonModel model = b.getModel();
      //			Skin skin = xp.getSkin(b, part);

      // normal, rollover/activated/focus, pressed, disabled, default
      //			State state = State.NORMAL;
      if (toolbar) {
        //				if (model.isArmed() && model.isPressed())
        //				{
        //					state = State.PRESSED;
        //				}
        //				else if (!model.isEnabled())
        //				{
        //					state = State.DISABLED;
        //				}
        //				else if (model.isSelected() && model.isRollover())
        //				{
        //					state = State.HOTCHECKED;
        //				}
        //				else if (model.isSelected())
        //				{
        //					state = State.CHECKED;
        //				}
        //				else if (model.isRollover())
        //				{
        //					state = State.HOT;
        //				}
      } else {
        //				if (model.isArmed() && model.isPressed() || model.isSelected())
        //				{
        //					state = State.PRESSED;
        //				}
        //				else if (!model.isEnabled())
        //				{
        //					state = State.DISABLED;
        //				}
        //				else if (model.isRollover() || model.isPressed())
        //				{
        //					state = State.HOT;
        //				}
        //				else if (b instanceof JButton
        //						&& ((JButton) b).isDefaultButton())
        //				{
        //					state = State.DEFAULTED;
        //				}
        //				else if (c.hasFocus())
        //				{
        //					state = State.HOT;
        //				}
      }
      Dimension d = c.getSize();
      int dx = 0;
      int dy = 0;
      int dw = d.width;
      int dh = d.height;

      Border border = c.getBorder();
      Insets insets;
      if (border != null) {
        // Note: The border may be compound, containing an outer
        // opaque border (supplied by the application), plus an
        // inner transparent margin border. We want to size the
        // background to fill the transparent part, but stay
        // inside the opaque part.
        insets = BEButtonUI.getOpaqueInsets(border, c);
      } else {
        insets = c.getInsets();
      }
      if (insets != null) {
        dx += insets.left;
        dy += insets.top;
        dw -= (insets.left + insets.right);
        dh -= (insets.top + insets.bottom);
      }

      /** ************************* 以下代码由jb2011改造自WindowsButtonUI START ******************* */
      if (toolbar) {
        // 此状态下JToggleButton和JButton使用各自的背景实现,2012-10-16前无论是不是JToggleButton都是使用该种实是不太合理的
        if (model.isRollover() || model.isPressed()) {
          if (c instanceof JToggleButton)
            __Icon9Factory__.getInstance()
                .getToggleButtonIcon_RoverGreen()
                .draw((Graphics2D) g, dx, dy, dw, dh);
          else
            __Icon9Factory__.getInstance()
                .getButtonIcon_PressedOrange()
                .draw((Graphics2D) g, dx, dy, dw, dh);
        } else if (model.isSelected()) // state == State.CHECKED)//||state == State.HOTCHECKED)
        {
          __Icon9Factory__.getInstance()
              .getToggleButtonIcon_CheckedGreen()
              .draw((Graphics2D) g, dx, dy, dw, dh);
        } else {
          // TODO 其它状态下的按钮背景样式需要完善,要不然看起来太硬!
          //					skin.paintSkin(g, dx, dy, dw, dh, state);
        }
      } else {
        try {
          // TODO 其它状态下的按钮背景样式需要完善,要不然看起来太硬!

          //					if(state == State.PRESSED)
          if (model.isArmed() && model.isPressed() || model.isSelected())
            __Icon9Factory__.getInstance()
                .getButtonIcon_PressedOrange()
                .draw((Graphics2D) g, dx, dy, dw, dh);
          //					else if(state == State.DISABLED)
          else if (!model.isEnabled())
            __Icon9Factory__.getInstance()
                .getButtonIcon_DisableGray()
                .draw((Graphics2D) g, dx, dy, dw, dh);
          else if (model.isRollover())
            __Icon9Factory__.getInstance()
                .getButtonIcon_rover()
                .draw((Graphics2D) g, dx, dy, dw, dh);
          else {
            if (nomalColor == NormalColor.green) {
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalGreen()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
            } else if (nomalColor == NormalColor.red) {
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalRed()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
            } else if (nomalColor == NormalColor.blue) {
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalBlue()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
            } else if (nomalColor == NormalColor.lightBlue) {
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalLightBlue()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
            }
            //						else if(nomalColor==NormalColor.red)
            //						{
            //							//红色按钮禁用状态时为更好地突出禁用状态,用深灰按钮
            //							if(state == State.DISABLED)
            //								__Icon9Factory__.getInstance().getButtonIcon_NormalGray().draw((Graphics2D)g,
            // dx, dy, dw, dh);
            //							else
            //								__Icon9Factory__.getInstance().getButtonIcon_NormalRed().draw((Graphics2D)g,
            // dx, dy, dw, dh);
            //						}
            else
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalGray()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      /** ************************* 以下代码由JS改造自WindowsButtonUI END ******************* */
    }
  }
  protected void paintBackground(
      Graphics g, int x, int y, int w, int h, boolean horizontal, JComponent component) {
    Graphics2D g2d = (Graphics2D) g.create();
    CEclipseBorder ec = null;
    Insets ins = getOutsideInsets();

    x = ins.left;
    y = ins.top;
    if (getOrientation().isHorizontal()) {
      w -= ins.left + ins.right;
      h -= ins.top + ins.bottom;
    } else {
      w -= ins.top + ins.bottom;
      h -= ins.left + ins.right;
    }

    if (component.getBorder() instanceof CompoundBorder) {
      CompoundBorder cb = (CompoundBorder) component.getBorder();
      CompoundBorder bb = (CompoundBorder) cb.getInsideBorder();

      ec = (CEclipseBorder) bb.getOutsideBorder();
    }

    if (w > 0 && h > 0) {
      if (glassStrip != null) {
        BufferedImage im = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

        Graphics2D gg = im.createGraphics();
        gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        gg.setColor(component.getBackground());
        if (ec != null) {
          gg.fill(ec.createShape(0, 0, w, h, ec.getCornerRadius()));

        } else {
          gg.fillRect(0, 0, w, h);
        }

        if (!isSelected()) {
          gg.setComposite(AlphaComposite.SrcIn);
        } else {
          gg.setComposite(AlphaComposite.SrcAtop);
        }

        try {
          glass.Render2Graphics(new Dimension(w, h), gg, glassStrip, true);
        } catch (Exception e) {
          glass.Render2Graphics(new Dimension(w, h), gg, CGlassFactory.VALUE_STEEL, true);
        }

        gg.dispose();

        if (!getOrientation().isHorizontal()) {
          AffineTransform atTrans = AffineTransform.getTranslateInstance(x /* + h */, y + w);
          atTrans.concatenate(COutlineHelper.tRot90CCW);
          g2d.drawImage(im, atTrans, null);
        } else {
          g2d.drawImage(im, x, y, null);
        }
      }

      g2d.dispose();
    }
  }
  @Override
  public void paint(Graphics g, JComponent c) {
    if (!(c.getBorder() instanceof MacIntelliJButtonBorder) && !isComboButton(c)) {
      super.paint(g, c);
      return;
    }
    int w = c.getWidth();
    int h = c.getHeight();
    if (isHelpButton(c)) {
      Icon icon = MacIntelliJIconCache.getIcon("helpButton", false, c.hasFocus());
      int x = (w - icon.getIconWidth()) / 2;
      int y = (h - icon.getIconHeight()) / 2;
      icon.paintIcon(c, g, x, y);
    } else {
      AbstractButton b = (AbstractButton) c;
      String text = layout(b, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight());

      boolean isFocused = c.hasFocus();
      if (isSquare(c)) {
        Icon icon = MacIntelliJIconCache.getIcon("browseButton");
        int x = (c.getWidth() - icon.getIconWidth()) / 2;
        int y = (c.getHeight() - icon.getIconHeight()) / 2;
        icon.paintIcon(c, g, x, y);
        return;
      } else {
        int x = isFocused ? 0 : 2;
        int y = isFocused ? 0 : (h - viewRect.height) / 2;
        Icon icon;
        icon = getLeftIcon(b);
        icon.paintIcon(b, g, x, y);
        x += icon.getIconWidth();
        int stop = w - (isFocused ? 0 : 2) - (getRightIcon(b).getIconWidth());
        Graphics gg = g.create(0, 0, w, h);
        gg.setClip(x, y, stop - x, h);
        icon = getMiddleIcon(b);
        while (x < stop) {
          icon.paintIcon(b, gg, x, y);
          x += icon.getIconWidth();
        }
        gg.dispose();
        icon = getRightIcon(b);
        icon.paintIcon(b, g, stop, y);

        clearTextShiftOffset();
      }

      // Paint the Icon
      if (b.getIcon() != null) {
        paintIcon(g, c, iconRect);
      }

      if (text != null && !text.isEmpty()) {
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (v != null) {
          v.paint(g, textRect);
        } else {
          UISettings.setupAntialiasing(g);
          paintText(g, b, textRect, text);
        }
      }
    }
  }