Example #1
0
  protected void installDefaults(AbstractButton b) {
    // load shared instance defaults
    String pp = getPropertyPrefix();

    defaultTextShiftOffset = UIManager.getInt(pp + "textShiftOffset");

    // set the following defaults on the button
    if (b.isContentAreaFilled()) {
      LookAndFeel.installProperty(b, "opaque", Boolean.TRUE);
    } else {
      LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
    }

    if (b.getMargin() == null || (b.getMargin() instanceof UIResource)) {
      b.setMargin(UIManager.getInsets(pp + "margin"));
    }

    LookAndFeel.installColorsAndFont(b, pp + "background", pp + "foreground", pp + "font");
    LookAndFeel.installBorder(b, pp + "border");

    Object rollover = UIManager.get(pp + "rollover");
    if (rollover != null) {
      LookAndFeel.installProperty(b, "rolloverEnabled", rollover);
    }

    LookAndFeel.installProperty(b, "iconTextGap", new Integer(4));
  }
Example #2
0
  void updateStyle(AbstractButton b) {
    SynthContext context = getContext(b, SynthConstants.ENABLED);
    SynthStyle oldStyle = style;
    style = SynthLookAndFeel.updateStyle(context, this);
    if (style != oldStyle) {
      if (b.getMargin() == null || (b.getMargin() instanceof UIResource)) {
        Insets margin = (Insets) style.get(context, getPropertyPrefix() + "margin");

        if (margin == null) {
          // Some places assume margins are non-null.
          margin = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS;
        }
        b.setMargin(margin);
      }

      Object value = style.get(context, getPropertyPrefix() + "iconTextGap");
      if (value != null) {
        LookAndFeel.installProperty(b, "iconTextGap", value);
      }

      value = style.get(context, getPropertyPrefix() + "contentAreaFilled");
      LookAndFeel.installProperty(b, "contentAreaFilled", value != null ? value : Boolean.TRUE);

      if (oldStyle != null) {
        uninstallKeyboardActions(b);
        installKeyboardActions(b);
      }
    }
  }
  public void setUseFlatUI(boolean b) {
    main.setContentAreaFilled(!b);
    main.setFocusPainted(!b);
    main.setBorderPainted(!b);
    main.setMargin(new Insets(1, 1, 1, 1));

    popper.setContentAreaFilled(!b);
    popper.setFocusPainted(!b);
    popper.setBorderPainted(!b);
    popper.setMargin(new Insets(1, 1, 1, 1));

    setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    setOpaque(false);

    MouseAdapter ma =
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            main.setContentAreaFilled(true);
            main.setBackground(new Color(216, 240, 254));
            // m.getMainButton().setForeground( Color.black );
            setBorder(new LineBorder(new Color(200, 200, 200), 1));
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

            popper.setBackground(new Color(242, 242, 242));
            popper.setContentAreaFilled(true);
            popper.setBorder(menu.getBorder());
          }

          public void mouseExited(MouseEvent e) {
            main.setContentAreaFilled(false);
            //	c.setForeground( Color.black );
            setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
            setCursor(Cursor.getDefaultCursor());

            popper.setContentAreaFilled(false);
            popper.setBorder(null);
          }
        };

    main.addMouseListener(ma);
    popper.addMouseListener(ma);
  }
  public void createButtons(String text, Icon icon) {
    if (main == null) {
      main = new JButton(text, icon);

      if (text == null) {
        main.setMargin(new Insets(0, 0, 0, 0));
      }
    }

    // main.setFont( new Font("Verdana", Font.PLAIN, 11) );
    ImageIcon img = new ImageIcon("resources/images/popicon.gif");
    popper =
        new JButton(/*img*/ ) {

          public void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2 = (Graphics2D) g;
            int width = getWidth(), height = getHeight();
            int midWidth = width / 2, midHeight = height / 2;

            int[] xpoints = {midWidth - 4, midWidth, midWidth + 4};
            int[] ypoints = {midHeight - 1, midHeight + 3, midHeight - 1};

            if (ARROW_DIRECTION == FORWARD) {
              xpoints = new int[] {midWidth - 3, midWidth - 3, midWidth + 2};
              ypoints = new int[] {midHeight - 4, midHeight + 4, midHeight};
            }

            g2.setColor(getPopperArrowColor());
            g2.fill(new Polygon(xpoints, ypoints, 3));
          }
        };

    // popper.setPreferredSize( new Dimension(img.getImage().getWidth(this) + 10,

    popper.addActionListener(this);

    setBorder(null);
    // setLayout( new BoxLayout(this, BoxLayout.X_AXIS) );
    layoutComponents();
  }