Example #1
2
 /**
  * Returns a border instance for a Windows ToolBar
  *
  * @return a border used for the toolbar
  * @since 1.4
  */
 public static Border getToolBarBorder() {
   UIDefaults table = UIManager.getLookAndFeelDefaults();
   Border toolBarBorder =
       new WindowsBorders.ToolBarBorder(
           table.getColor("ToolBar.shadow"), table.getColor("ToolBar.highlight"));
   return toolBarBorder;
 }
Example #2
0
  public static class BevelBorder extends AbstractBorder implements UIResource {
    private Color darkShadow = UIManager.getColor("controlShadow");
    private Color lightShadow = UIManager.getColor("controlLtHighlight");
    private boolean isRaised;

    public BevelBorder(boolean isRaised, Color darkShadow, Color lightShadow) {
      this.isRaised = isRaised;
      this.darkShadow = darkShadow;
      this.lightShadow = lightShadow;
    }

    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      g.setColor((isRaised) ? lightShadow : darkShadow);
      g.drawLine(x, y, x + w - 1, y); // top
      g.drawLine(x, y + h - 1, x, y + 1); // left

      g.setColor((isRaised) ? darkShadow : lightShadow);
      g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); // bottom
      g.drawLine(x + w - 1, y + h - 1, x + w - 1, y + 1); // right
    }

    public Insets getBorderInsets(Component c, Insets insets) {
      insets.set(1, 1, 1, 1);
      return insets;
    }

    public boolean isOpaque(Component c) {
      return true;
    }
  }
Example #3
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      g.setColor(UIManager.getColor("InternalFrame.resizeIconHighlight"));
      g.drawLine(0, 11, 11, 0);
      g.drawLine(4, 11, 11, 4);
      g.drawLine(8, 11, 11, 8);

      g.setColor(UIManager.getColor("InternalFrame.resizeIconShadow"));
      g.drawLine(1, 11, 11, 1);
      g.drawLine(2, 11, 11, 2);
      g.drawLine(5, 11, 11, 5);
      g.drawLine(6, 11, 11, 6);
      g.drawLine(9, 11, 11, 9);
      g.drawLine(10, 11, 11, 10);
    }
Example #4
0
    /**
     * Draws the FrameBorder in the given Rect. Calls <b>drawTitleBar</b>, <b>drawLeftBorder</b>,
     * <b>drawRightBorder</b> and <b>drawBottomBorder</b>.
     */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
      if (isActiveFrame()) {
        frameColor = UIManager.getColor("activeCaptionBorder");
      } else {
        frameColor = UIManager.getColor("inactiveCaptionBorder");
      }
      frameHighlight = frameColor.brighter();
      frameShadow = frameColor.darker().darker();

      drawTopBorder(c, g, x, y, width, height);
      drawLeftBorder(c, g, x, y, width, height);
      drawRightBorder(c, g, x, y, width, height);
      drawBottomBorder(c, g, x, y, width, height);
    }
Example #5
0
 Map<String, Object> getDefaultsForPrefix(String prefix) {
   if (compiledDefaults == null) {
     compiledDefaults = new HashMap<String, Map<String, Object>>();
     for (Map.Entry<Object, Object> entry : UIManager.getDefaults().entrySet()) {
       if (entry.getKey() instanceof String) {
         addDefault((String) entry.getKey(), entry.getValue());
       }
     }
     if (!defaultListenerAdded) {
       UIManager.getDefaults().addPropertyChangeListener(defaultsListener);
       defaultListenerAdded = true;
     }
   }
   return compiledDefaults.get(prefix);
 }
Example #6
0
 /**
  * Check if developer changed icon in the UI table.
  *
  * @return the icon to use or {@code null} if the current one is to be used
  */
 private Icon getLaFIcon() {
   // use icon from the UI table if it does not match this one.
   Icon rv = (Icon) UIManager.getDefaults().get(typeToString(type));
   if (rv instanceof VistaMenuItemCheckIcon && ((VistaMenuItemCheckIcon) rv).type == type) {
     rv = null;
   }
   return rv;
 }
Example #7
0
 /** Called by UIManager when this look and feel is uninstalled. */
 @Override
 public void uninitialize() {
   super.uninitialize();
   defaults.uninitialize();
   // clear all cached images to free memory
   ImageCache.getInstance().flush();
   UIManager.getDefaults().removePropertyChangeListener(defaultsListener);
 }
Example #8
0
 /**
  * Returns a border instance for a Windows Progress Bar
  *
  * @since 1.4
  */
 public static Border getProgressBarBorder() {
   UIDefaults table = UIManager.getLookAndFeelDefaults();
   Border progressBarBorder =
       new BorderUIResource.CompoundBorderUIResource(
           new WindowsBorders.ProgressBarBorder(
               table.getColor("ProgressBar.shadow"), table.getColor("ProgressBar.highlight")),
           new EmptyBorder(1, 1, 1, 1));
   return progressBarBorder;
 }
Example #9
0
 public int getIconWidth() {
   int width;
   if (XPStyle.getXP() != null) {
     // Fix for XP bug where sometimes these sizes aren't updated properly
     // Assume for now that height is correct and derive width using the
     // ratio from the uxtheme part
     width = UIManager.getInt("InternalFrame.titleButtonHeight") - 2;
     Dimension d = XPStyle.getPartSize(Part.WP_CLOSEBUTTON, State.NORMAL);
     if (d != null && d.width != 0 && d.height != 0) {
       width = (int) ((float) width * d.width / d.height);
     }
   } else {
     width = UIManager.getInt("InternalFrame.titleButtonWidth") - 2;
   }
   if (XPStyle.getXP() != null) {
     width -= 2;
   }
   return width;
 }
Example #10
0
 /**
  * Implements the standard Icon interface's paintIcon method as the standard synth stub passes
  * null for the context and this will cause us to not paint any thing, so we override here so that
  * we can paint the enabled state if no synth context is available
  */
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Painter painter = (Painter) UIManager.get(prefix + "[Enabled]." + key);
   if (painter != null) {
     JComponent jc = (c instanceof JComponent) ? (JComponent) c : null;
     Graphics2D gfx = (Graphics2D) g;
     gfx.translate(x, y);
     painter.paint(gfx, jc, width, height);
     gfx.translate(-x, -y);
   }
 }
Example #11
0
 public static Border getTableHeaderBorder() {
   UIDefaults table = UIManager.getLookAndFeelDefaults();
   Border tableHeaderBorder =
       new BorderUIResource.CompoundBorderUIResource(
           new BasicBorders.ButtonBorder(
               table.getColor("Table.shadow"),
               table.getColor("Table.darkShadow"),
               table.getColor("Table.light"),
               table.getColor("Table.highlight")),
           new BasicBorders.MarginBorder());
   return tableHeaderBorder;
 }
Example #12
0
  public static Border getInternalFrameBorder() {
    UIDefaults table = UIManager.getLookAndFeelDefaults();
    Border internalFrameBorder =
        new BorderUIResource.CompoundBorderUIResource(
            BorderFactory.createBevelBorder(
                BevelBorder.RAISED,
                table.getColor("InternalFrame.borderColor"),
                table.getColor("InternalFrame.borderHighlight"),
                table.getColor("InternalFrame.borderDarkShadow"),
                table.getColor("InternalFrame.borderShadow")),
            new WindowsBorders.InternalFrameLineBorder(
                table.getColor("InternalFrame.activeBorderColor"),
                table.getColor("InternalFrame.inactiveBorderColor"),
                table.getInt("InternalFrame.borderWidth")));

    return internalFrameBorder;
  }
Example #13
0
  /**
   * This method is not being used to paint menu item since 6.0 This code left for compatibility
   * only. Do not use or override it, this will not cause any visible effect.
   */
  public static void paintMenuItem(
      Graphics g,
      JComponent c,
      Icon checkIcon,
      Icon arrowIcon,
      Color background,
      Color foreground,
      int defaultTextIconGap) {

    JMenuItem b = (JMenuItem) c;
    ButtonModel model = b.getModel();

    Dimension size = b.getSize();
    Insets i = c.getInsets();

    Rectangle viewRect = new Rectangle(size);

    viewRect.x += i.left;
    viewRect.y += i.top;
    viewRect.width -= (i.right + viewRect.x);
    viewRect.height -= (i.bottom + viewRect.y);

    Rectangle iconRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle acceleratorRect = new Rectangle();
    Rectangle checkRect = new Rectangle();
    Rectangle arrowRect = new Rectangle();

    Font holdf = g.getFont();
    Font f = c.getFont();
    g.setFont(f);
    FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
    FontMetrics fmAccel =
        SwingUtilities2.getFontMetrics(c, g, UIManager.getFont("MenuItem.acceleratorFont"));

    if (c.isOpaque()) {
      if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
        g.setColor(background);
      } else {
        g.setColor(c.getBackground());
      }
      g.fillRect(0, 0, size.width, size.height);
    }

    // get Accelerator text
    KeyStroke accelerator = b.getAccelerator();
    String acceleratorText = "";
    if (accelerator != null) {
      int modifiers = accelerator.getModifiers();
      if (modifiers > 0) {
        acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
        acceleratorText += "+";
      }
      acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());
    }

    // layout the text and icon
    String text =
        layoutMenuItem(
            c,
            fm,
            b.getText(),
            fmAccel,
            acceleratorText,
            b.getIcon(),
            checkIcon,
            arrowIcon,
            b.getVerticalAlignment(),
            b.getHorizontalAlignment(),
            b.getVerticalTextPosition(),
            b.getHorizontalTextPosition(),
            viewRect,
            iconRect,
            textRect,
            acceleratorRect,
            checkRect,
            arrowRect,
            b.getText() == null ? 0 : defaultTextIconGap,
            defaultTextIconGap);

    // Paint the Check
    Color holdc = g.getColor();
    if (checkIcon != null) {
      if (model.isArmed() || (c instanceof JMenu && model.isSelected())) g.setColor(foreground);
      checkIcon.paintIcon(c, g, checkRect.x, checkRect.y);
      g.setColor(holdc);
    }

    // Paint the Icon
    if (b.getIcon() != null) {
      Icon icon;
      if (!model.isEnabled()) {
        icon = b.getDisabledIcon();
      } else if (model.isPressed() && model.isArmed()) {
        icon = b.getPressedIcon();
        if (icon == null) {
          // Use default icon
          icon = b.getIcon();
        }
      } else {
        icon = b.getIcon();
      }

      if (icon != null) {
        icon.paintIcon(c, g, iconRect.x, iconRect.y);
      }
    }

    // Draw the Text
    if (text != null && !text.equals("")) {
      // Once BasicHTML becomes public, use BasicHTML.propertyKey
      // instead of the hardcoded string below!
      View v = (View) c.getClientProperty("html");
      if (v != null) {
        v.paint(g, textRect);
      } else {
        int mnemIndex = b.getDisplayedMnemonicIndex();

        if (!model.isEnabled()) {
          // *** paint the text disabled
          g.setColor(b.getBackground().brighter());
          SwingUtilities2.drawStringUnderlineCharAt(
              b, g, text, mnemIndex, textRect.x, textRect.y + fmAccel.getAscent());
          g.setColor(b.getBackground().darker());
          SwingUtilities2.drawStringUnderlineCharAt(
              b, g, text, mnemIndex, textRect.x - 1, textRect.y + fmAccel.getAscent() - 1);

        } else {
          // *** paint the text normally
          if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
            g.setColor(foreground);
          } else {
            g.setColor(b.getForeground());
          }
          SwingUtilities2.drawStringUnderlineCharAt(
              b, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
        }
      }
    }

    // Draw the Accelerator Text
    if (acceleratorText != null && !acceleratorText.equals("")) {

      // Get the maxAccWidth from the parent to calculate the offset.
      int accOffset = 0;
      Container parent = b.getParent();
      if (parent != null && parent instanceof JComponent) {
        JComponent p = (JComponent) parent;
        Integer maxValueInt = (Integer) p.getClientProperty(MotifGraphicsUtils.MAX_ACC_WIDTH);
        int maxValue = maxValueInt != null ? maxValueInt.intValue() : acceleratorRect.width;

        // Calculate the offset, with which the accelerator texts will be drawn with.
        accOffset = maxValue - acceleratorRect.width;
      }

      g.setFont(UIManager.getFont("MenuItem.acceleratorFont"));
      if (!model.isEnabled()) {
        // *** paint the acceleratorText disabled
        g.setColor(b.getBackground().brighter());
        SwingUtilities2.drawString(
            c,
            g,
            acceleratorText,
            acceleratorRect.x - accOffset,
            acceleratorRect.y + fm.getAscent());
        g.setColor(b.getBackground().darker());
        SwingUtilities2.drawString(
            c,
            g,
            acceleratorText,
            acceleratorRect.x - accOffset - 1,
            acceleratorRect.y + fm.getAscent() - 1);
      } else {
        // *** paint the acceleratorText normally
        if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
          g.setColor(foreground);
        } else {
          g.setColor(b.getForeground());
        }
        SwingUtilities2.drawString(
            c,
            g,
            acceleratorText,
            acceleratorRect.x - accOffset,
            acceleratorRect.y + fmAccel.getAscent());
      }
    }

    // Paint the Arrow
    if (arrowIcon != null) {
      if (model.isArmed() || (c instanceof JMenu && model.isSelected())) g.setColor(foreground);
      if (!(b.getParent() instanceof JMenuBar)) arrowIcon.paintIcon(c, g, arrowRect.x, arrowRect.y);
    }

    g.setColor(holdc);
    g.setFont(holdf);
  }
Example #14
0
  @Override
  public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) {
    Painter painter = null;
    if (context != null) {
      painter = (Painter) context.getStyle().get(context, key);
    }
    if (painter == null) {
      painter = (Painter) UIManager.get(prefix + "[Enabled]." + key);
    }

    if (painter != null && context != null) {
      JComponent c = context.getComponent();
      boolean rotate = false;
      boolean flip = false;
      // translatex and translatey are additional translations that
      // must occur on the graphics context when rendering a toolbar
      // icon
      int translatex = 0;
      int translatey = 0;
      if (c instanceof JToolBar) {
        JToolBar toolbar = (JToolBar) c;
        rotate = toolbar.getOrientation() == JToolBar.VERTICAL;
        flip = !toolbar.getComponentOrientation().isLeftToRight();
        Object o = NimbusLookAndFeel.resolveToolbarConstraint(toolbar);
        // we only do the +1 hack for UIResource borders, assuming
        // that the border is probably going to be our border
        if (toolbar.getBorder() instanceof UIResource) {
          if (o == BorderLayout.SOUTH) {
            translatey = 1;
          } else if (o == BorderLayout.EAST) {
            translatex = 1;
          }
        }
      } else if (c instanceof JMenu) {
        flip = !c.getComponentOrientation().isLeftToRight();
      }
      if (g instanceof Graphics2D) {
        Graphics2D gfx = (Graphics2D) g;
        gfx.translate(x, y);
        gfx.translate(translatex, translatey);
        if (rotate) {
          gfx.rotate(Math.toRadians(90));
          gfx.translate(0, -w);
          painter.paint(gfx, context.getComponent(), h, w);
          gfx.translate(0, w);
          gfx.rotate(Math.toRadians(-90));
        } else if (flip) {
          gfx.scale(-1, 1);
          gfx.translate(-w, 0);
          painter.paint(gfx, context.getComponent(), w, h);
          gfx.translate(w, 0);
          gfx.scale(-1, 1);
        } else {
          painter.paint(gfx, context.getComponent(), w, h);
        }
        gfx.translate(-translatex, -translatey);
        gfx.translate(-x, -y);
      } else {
        // use image if we are printing to a Java 1.1 PrintGraphics as
        // it is not a instance of Graphics2D
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D gfx = img.createGraphics();
        if (rotate) {
          gfx.rotate(Math.toRadians(90));
          gfx.translate(0, -w);
          painter.paint(gfx, context.getComponent(), h, w);
        } else if (flip) {
          gfx.scale(-1, 1);
          gfx.translate(-w, 0);
          painter.paint(gfx, context.getComponent(), w, h);
        } else {
          painter.paint(gfx, context.getComponent(), w, h);
        }
        gfx.dispose();
        g.drawImage(img, x, y, null);
        img = null;
      }
    }
  }
Example #15
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      AbstractButton b = (AbstractButton) c;
      ButtonModel model = b.getModel();
      XPStyle xp = XPStyle.getXP();

      if (xp != null) {
        Part part = Part.BP_RADIOBUTTON;
        Skin skin = xp.getSkin(b, part);
        State state;
        int index = 0;
        if (model.isSelected()) {
          state = State.CHECKEDNORMAL;
          if (!model.isEnabled()) {
            state = State.CHECKEDDISABLED;
          } else if (model.isPressed() && model.isArmed()) {
            state = State.CHECKEDPRESSED;
          } else if (model.isRollover()) {
            state = State.CHECKEDHOT;
          }
        } else {
          state = State.UNCHECKEDNORMAL;
          if (!model.isEnabled()) {
            state = State.UNCHECKEDDISABLED;
          } else if (model.isPressed() && model.isArmed()) {
            state = State.UNCHECKEDPRESSED;
          } else if (model.isRollover()) {
            state = State.UNCHECKEDHOT;
          }
        }
        skin.paintSkin(g, x, y, state);
      } else {
        // fill interior
        if ((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
          g.setColor(UIManager.getColor("RadioButton.background"));
        } else {
          g.setColor(UIManager.getColor("RadioButton.interiorBackground"));
        }
        g.fillRect(x + 2, y + 2, 8, 8);

        // outter left arc
        g.setColor(UIManager.getColor("RadioButton.shadow"));
        g.drawLine(x + 4, y + 0, x + 7, y + 0);
        g.drawLine(x + 2, y + 1, x + 3, y + 1);
        g.drawLine(x + 8, y + 1, x + 9, y + 1);
        g.drawLine(x + 1, y + 2, x + 1, y + 3);
        g.drawLine(x + 0, y + 4, x + 0, y + 7);
        g.drawLine(x + 1, y + 8, x + 1, y + 9);

        // outter right arc
        g.setColor(UIManager.getColor("RadioButton.highlight"));
        g.drawLine(x + 2, y + 10, x + 3, y + 10);
        g.drawLine(x + 4, y + 11, x + 7, y + 11);
        g.drawLine(x + 8, y + 10, x + 9, y + 10);
        g.drawLine(x + 10, y + 9, x + 10, y + 8);
        g.drawLine(x + 11, y + 7, x + 11, y + 4);
        g.drawLine(x + 10, y + 3, x + 10, y + 2);

        // inner left arc
        g.setColor(UIManager.getColor("RadioButton.darkShadow"));
        g.drawLine(x + 4, y + 1, x + 7, y + 1);
        g.drawLine(x + 2, y + 2, x + 3, y + 2);
        g.drawLine(x + 8, y + 2, x + 9, y + 2);
        g.drawLine(x + 2, y + 3, x + 2, y + 3);
        g.drawLine(x + 1, y + 4, x + 1, y + 7);
        g.drawLine(x + 2, y + 8, x + 2, y + 8);

        // inner right arc
        g.setColor(UIManager.getColor("RadioButton.light"));
        g.drawLine(x + 2, y + 9, x + 3, y + 9);
        g.drawLine(x + 4, y + 10, x + 7, y + 10);
        g.drawLine(x + 8, y + 9, x + 9, y + 9);
        g.drawLine(x + 9, y + 8, x + 9, y + 8);
        g.drawLine(x + 10, y + 7, x + 10, y + 4);
        g.drawLine(x + 9, y + 3, x + 9, y + 3);

        // indicate whether selected or not
        if (model.isSelected()) {
          if (model.isEnabled()) {
            g.setColor(UIManager.getColor("RadioButton.foreground"));
          } else {
            g.setColor(UIManager.getColor("RadioButton.shadow"));
          }
          g.fillRect(x + 4, y + 5, 4, 2);
          g.fillRect(x + 5, y + 4, 2, 4);
        }
      }
    }
Example #16
0
 public int getIconHeight() {
   int height = UIManager.getInt("InternalFrame.titleButtonHeight") - 4;
   return height;
 }
Example #17
0
 @Override
 public Object createValue(UIDefaults table) {
   return UIManager.get(dstPropName);
 }
Example #18
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      JCheckBox cb = (JCheckBox) c;
      ButtonModel model = cb.getModel();
      XPStyle xp = XPStyle.getXP();

      if (xp != null) {
        State state;
        if (model.isSelected()) {
          state = State.CHECKEDNORMAL;
          if (!model.isEnabled()) {
            state = State.CHECKEDDISABLED;
          } else if (model.isPressed() && model.isArmed()) {
            state = State.CHECKEDPRESSED;
          } else if (model.isRollover()) {
            state = State.CHECKEDHOT;
          }
        } else {
          state = State.UNCHECKEDNORMAL;
          if (!model.isEnabled()) {
            state = State.UNCHECKEDDISABLED;
          } else if (model.isPressed() && model.isArmed()) {
            state = State.UNCHECKEDPRESSED;
          } else if (model.isRollover()) {
            state = State.UNCHECKEDHOT;
          }
        }
        Part part = Part.BP_CHECKBOX;
        xp.getSkin(c, part).paintSkin(g, x, y, state);
      } else {
        // outer bevel
        if (!cb.isBorderPaintedFlat()) {
          // Outer top/left
          g.setColor(UIManager.getColor("CheckBox.shadow"));
          g.drawLine(x, y, x + 11, y);
          g.drawLine(x, y + 1, x, y + 11);

          // Outer bottom/right
          g.setColor(UIManager.getColor("CheckBox.highlight"));
          g.drawLine(x + 12, y, x + 12, y + 12);
          g.drawLine(x, y + 12, x + 11, y + 12);

          // Inner top.left
          g.setColor(UIManager.getColor("CheckBox.darkShadow"));
          g.drawLine(x + 1, y + 1, x + 10, y + 1);
          g.drawLine(x + 1, y + 2, x + 1, y + 10);

          // Inner bottom/right
          g.setColor(UIManager.getColor("CheckBox.light"));
          g.drawLine(x + 1, y + 11, x + 11, y + 11);
          g.drawLine(x + 11, y + 1, x + 11, y + 10);

          // inside box
          if ((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
            g.setColor(UIManager.getColor("CheckBox.background"));
          } else {
            g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
          }
          g.fillRect(x + 2, y + 2, csize - 4, csize - 4);
        } else {
          g.setColor(UIManager.getColor("CheckBox.shadow"));
          g.drawRect(x + 1, y + 1, csize - 3, csize - 3);

          if ((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
            g.setColor(UIManager.getColor("CheckBox.background"));
          } else {
            g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
          }
          g.fillRect(x + 2, y + 2, csize - 4, csize - 4);
        }

        if (model.isEnabled()) {
          g.setColor(UIManager.getColor("CheckBox.foreground"));
        } else {
          g.setColor(UIManager.getColor("CheckBox.shadow"));
        }

        // paint check
        if (model.isSelected()) {
          g.drawLine(x + 9, y + 3, x + 9, y + 3);
          g.drawLine(x + 8, y + 4, x + 9, y + 4);
          g.drawLine(x + 7, y + 5, x + 9, y + 5);
          g.drawLine(x + 6, y + 6, x + 8, y + 6);
          g.drawLine(x + 3, y + 7, x + 7, y + 7);
          g.drawLine(x + 4, y + 8, x + 6, y + 8);
          g.drawLine(x + 5, y + 9, x + 5, y + 9);
          g.drawLine(x + 3, y + 5, x + 3, y + 5);
          g.drawLine(x + 3, y + 6, x + 4, y + 6);
        }
      }
    }
Example #19
0
  public static class ButtonBorder extends AbstractBorder implements UIResource {
    protected Color focus = UIManager.getColor("activeCaptionBorder");
    protected Color shadow = UIManager.getColor("Button.shadow");
    protected Color highlight = UIManager.getColor("Button.light");
    protected Color darkShadow;

    public ButtonBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
      this.shadow = shadow;
      this.highlight = highlight;
      this.darkShadow = darkShadow;
      this.focus = focus;
    }

    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      boolean isPressed = false;
      boolean hasFocus = false;
      boolean canBeDefault = false;
      boolean isDefault = false;

      if (c instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) c;
        ButtonModel model = b.getModel();

        isPressed = (model.isArmed() && model.isPressed());
        hasFocus = (model.isArmed() && isPressed) || (b.isFocusPainted() && b.hasFocus());
        if (b instanceof JButton) {
          canBeDefault = ((JButton) b).isDefaultCapable();
          isDefault = ((JButton) b).isDefaultButton();
        }
      }
      int bx1 = x + 1;
      int by1 = y + 1;
      int bx2 = x + w - 2;
      int by2 = y + h - 2;

      if (canBeDefault) {
        if (isDefault) {
          g.setColor(shadow);
          g.drawLine(x + 3, y + 3, x + 3, y + h - 4);
          g.drawLine(x + 3, y + 3, x + w - 4, y + 3);

          g.setColor(highlight);
          g.drawLine(x + 4, y + h - 4, x + w - 4, y + h - 4);
          g.drawLine(x + w - 4, y + 3, x + w - 4, y + h - 4);
        }
        bx1 += 6;
        by1 += 6;
        bx2 -= 6;
        by2 -= 6;
      }

      if (hasFocus) {
        g.setColor(focus);
        if (isDefault) {
          g.drawRect(x, y, w - 1, h - 1);
        } else {
          g.drawRect(bx1 - 1, by1 - 1, bx2 - bx1 + 2, by2 - by1 + 2);
        }
      }

      g.setColor(isPressed ? shadow : highlight);
      g.drawLine(bx1, by1, bx2, by1);
      g.drawLine(bx1, by1, bx1, by2);

      g.setColor(isPressed ? highlight : shadow);
      g.drawLine(bx2, by1 + 1, bx2, by2);
      g.drawLine(bx1 + 1, by2, bx2, by2);
    }

    public Insets getBorderInsets(Component c, Insets insets) {
      int thickness = (c instanceof JButton && ((JButton) c).isDefaultCapable()) ? 8 : 2;
      insets.set(thickness, thickness, thickness, thickness);
      return insets;
    }
  }