Example #1
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      if (MetalLookAndFeel.usingOcean()) {
        paintOceanBorder(c, g, x, y, w, h);
        return;
      }
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();

      if (model.isEnabled()) {
        boolean isPressed = model.isPressed() && model.isArmed();
        boolean isDefault = (button instanceof JButton && ((JButton) button).isDefaultButton());

        if (isPressed && isDefault) {
          MetalUtils.drawDefaultButtonPressedBorder(g, x, y, w, h);
        } else if (isPressed) {
          MetalUtils.drawPressed3DBorder(g, x, y, w, h);
        } else if (isDefault) {
          MetalUtils.drawDefaultButtonBorder(g, x, y, w, h, false);
        } else {
          MetalUtils.drawButtonBorder(g, x, y, w, h, false);
        }
      } else { // disabled state
        MetalUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
      }
    }
  /** Returns the current state of the passed in <code>AbstractButton</code>. */
  private int getComponentState(JComponent c) {
    int state = ENABLED;

    if (!c.isEnabled()) {
      state = DISABLED;
    }

    AbstractButton button = (AbstractButton) c;
    ButtonModel model = button.getModel();

    if (model.isPressed()) {
      if (model.isArmed()) {
        state = PRESSED;
      } else {
        state = MOUSE_OVER;
      }
    }
    if (model.isRollover()) {
      state |= MOUSE_OVER;
    }
    if (model.isSelected()) {
      state |= SELECTED;
    }
    if (c.isFocusOwner() && button.isFocusPainted()) {
      state |= FOCUSED;
    }
    if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) {
      state |= DEFAULT;
    }
    return state;
  }
Example #3
0
 public void mouseExited(MouseEvent e) {
   Component component = e.getComponent();
   if (component instanceof AbstractButton) {
     AbstractButton button = (AbstractButton) component;
     button.setBorderPainted(false);
   }
 }
Example #4
0
  protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Icon icon = b.getIcon();
    Icon tmpIcon = null;

    if (icon == null) {
      return;
    }

    Icon selectedIcon = null;

    /* the fallback icon should be based on the selected state */
    if (model.isSelected()) {
      selectedIcon = (Icon) b.getSelectedIcon();
      if (selectedIcon != null) {
        icon = selectedIcon;
      }
    }

    if (!model.isEnabled()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getDisabledSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = selectedIcon;
        }
      }

      if (tmpIcon == null) {
        tmpIcon = (Icon) b.getDisabledIcon();
      }
    } else if (model.isPressed() && model.isArmed()) {
      tmpIcon = (Icon) b.getPressedIcon();
      if (tmpIcon != null) {
        // revert back to 0 offset
        clearTextShiftOffset();
      }
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getRolloverSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = selectedIcon;
        }
      }

      if (tmpIcon == null) {
        tmpIcon = (Icon) b.getRolloverIcon();
      }
    }

    if (tmpIcon != null) {
      icon = tmpIcon;
    }

    if (model.isPressed() && model.isArmed()) {
      icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset());
    } else {
      icon.paintIcon(c, g, iconRect.x, iconRect.y);
    }
  }
Example #5
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);
      }
    }
  }
Example #6
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   AbstractButton b = (AbstractButton) c;
   ButtonModel model = b.getModel();
   if (b.isSelected() == true) {
     g.fillRoundRect(x + 3, y + 3, getIconWidth() - 6, getIconHeight() - 6, 4, 4);
   }
 }
Example #7
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));
  }
  /**
   * Method which renders the text of the current button.
   *
   * <p>
   *
   * @param g Graphics context
   * @param b Current button to render
   * @param textRect Bounding rectangle to render the text.
   * @param text String to render
   * @since 1.4
   */
  @Override
  protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
    ButtonModel model = b.getModel();
    FontMetrics fm = g.getFontMetrics();
    int mnemonicIndex = Methods.invokeGetter(b, "getDisplayedMnemonicIndex", -1);
    boolean borderHasPressedCue = borderHasPressedCue(b);

    /* Draw the Text */
    if (model.isPressed() && model.isArmed() && !borderHasPressedCue) {
      g.setColor(new Color(0xa0000000, true));
      QuaquaUtilities.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset() + 1);
    }

    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(b.getForeground());
    } else {
      Color c = UIManager.getColor(getPropertyPrefix() + "disabledForeground");
      g.setColor((c != null) ? c : b.getForeground());
    }
    QuaquaUtilities.drawStringUnderlineCharAt(
        g,
        text,
        mnemonicIndex,
        textRect.x + getTextShiftOffset(),
        textRect.y + fm.getAscent() + getTextShiftOffset());
  }
 @Override
 public Dimension getMinimumSize(JComponent c) {
   AbstractButton b = (AbstractButton) c;
   String style = (String) c.getClientProperty("Quaqua.Button.style");
   if (style == null) {
     style = "push";
   }
   if (style.equals("help")) {
     return getPreferredSize(c);
   }
   Dimension d = super.getMinimumSize(c);
   if (isFixedHeight(c)) {
     Dimension p = getPreferredSize(c);
     if (d != null && p != null) {
       d.height = Math.max(d.height, p.height);
     }
   }
   if (!QuaquaUtilities.isSmallSizeVariant(c)
       && style.equals("push") //
       && b.getIcon() == null
       && b.getText() != null) {
     if (d != null) {
       d.width = Math.max(d.width, UIManager.getInt("Button.minimumWidth"));
     }
   }
   return d;
 }
  public static PropertyUIDescriptor buildUIDescriptor(
      ToolParameterDescriptor prop,
      String[] columnsMembers,
      ToolAdapterOperatorDescriptor opDescriptor,
      BindingContext context,
      ActionListener deleteActionListener,
      ActionListener editActionListener,
      PropertyMemberUIWrapper.CallBackAfterEdit callback) {
    PropertyUIDescriptor descriptor = new PropertyUIDescriptor();

    AbstractButton delButton =
        ToolButtonFactory.createButton(
            UIUtils.loadImageIcon("/org/esa/snap/resources/images/icons/DeleteShapeTool16.gif"),
            false);
    delButton.addActionListener(deleteActionListener);
    descriptor.setDelButton(delButton);
    AbstractButton editButton = new JButton("...");
    editButton.addActionListener(editActionListener);
    descriptor.setEditButton(editButton);

    HashMap<String, PropertyMemberUIWrapper> UIcomponentsMap = new HashMap<>();
    for (String col : columnsMembers) {
      if (!col.equals("del")) {
        UIcomponentsMap.put(
            col,
            PropertyMemberUIWrapperFactory.buildPropertyWrapper(
                col, prop, opDescriptor, context, callback));
      }
    }
    descriptor.setUIcomponentsMap(UIcomponentsMap);

    return descriptor;
  }
  public Transferable createTransferable(JComponent comp) {

    // Clear

    image = null;

    Icon icon = null;

    if (comp instanceof JLabel) {

      JLabel label = (JLabel) comp;

      icon = label.getIcon();

    } else if (comp instanceof AbstractButton) {

      AbstractButton button = (AbstractButton) comp;

      icon = button.getIcon();
    }

    if (icon instanceof ImageIcon) {

      image = ((ImageIcon) icon).getImage();

      return this;
    }

    return null;
  }
Example #12
0
 public void keyReleased(KeyEvent e) {
   int code = e.getKeyCode();
   if (code == KeyEvent.VK_SPACE) {
     AbstractButton button = (AbstractButton) e.getSource();
     button.putClientProperty(SPACEBAR_PRESSED, Boolean.FALSE);
   }
 }
Example #13
0
 private void addHandlers() {
   startButton.setAction(
       new AbstractAction("Start") {
         public void actionPerformed(ActionEvent e) {
           startService();
         }
       });
   stopButton.setAction(
       new AbstractAction("Stop") {
         public void actionPerformed(ActionEvent e) {
           stopService();
         }
       });
   testMessageButton.setAction(
       new AbstractAction("Send Test Message") {
         public void actionPerformed(ActionEvent e) {
           sendTestMessage();
         }
       });
   this.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           shutdown();
         }
       });
 }
Example #14
0
 protected void paintButtonPressed(Graphics g, AbstractButton b) {
   if (b.isContentAreaFilled()) {
     Dimension size = b.getSize();
     g.setColor(getSelectColor());
     g.fillRect(0, 0, size.width, size.height);
   }
 }
 public void setShdPopupOnBtnClick(boolean shdPopup) {
   this.shdPopup = shdPopup;
   if (shdPopup) {
     main.addActionListener(pl);
   } else {
     main.removeActionListener(pl);
   }
 }
Example #16
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      AbstractButton b = (AbstractButton) c;
      ButtonModel model = b.getModel();

      if (model.isRollover() && !(model.isPressed() && !model.isArmed())) {
        super.paintBorder(c, g, x, y, w, h);
      }
    }
Example #17
0
 private JComponent createControlComponent(BooleanControl control) {
   AbstractButton button;
   String strControlName = control.getType().toString();
   ButtonModel model = new JavaMixer.BooleanControlButtonModel(control);
   button = new JCheckBox(strControlName);
   button.setModel(model);
   return button;
 }
Example #18
0
 // TODO 1.5: Remove in 1.5
 protected void installPreviousButtonListenersFromSuper(Component c) {
   AbstractButton sc = (AbstractButton) super.createPreviousButton();
   ActionListener[] als = sc.getActionListeners();
   MouseListener[] mls = sc.getMouseListeners();
   if (c instanceof AbstractButton) {
     ((AbstractButton) c).addActionListener(als[0]);
   }
   c.addMouseListener(mls[0]);
 }
Example #19
0
  /** Returns the amount to shift the text/icon when painting. */
  private int getTextShiftOffset(SynthContext state) {
    AbstractButton button = (AbstractButton) state.getComponent();
    ButtonModel model = button.getModel();

    if (model.isArmed() && model.isPressed() && button.getPressedIcon() == null) {
      return state.getStyle().getInt(state, getPropertyPrefix() + "textShiftOffset", 0);
    }
    return 0;
  }
Example #20
0
 private void setButtonStatus(boolean status) {
   for (AbstractButton button : commandMap.keySet()) {
     button.setEnabled(status);
   }
   btnQuit.setEnabled(status);
   btnShutdown.setEnabled(status);
   btnReset.setEnabled(status);
   btnConnection.setEnabled(!status);
 }
Example #21
0
  private void syncUI() {
    boolean started = mailService != null && mailService.isRunning();

    pop3PortLabel.setText(POP3_PORT_LABEL_PREFIX + (started ? mailService.getPop3Port() : ""));
    smtpPortLabel.setText(SMTP_PORT_LABEL_PREFIX + (started ? mailService.getSmtpPort() : ""));
    startButton.setEnabled(!started);
    stopButton.setEnabled(started);
    testMessageButton.setEnabled(started);
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent
  * )
  */
 @Override
 public void actionPerformed(ActionEvent e) {
   AbstractButton src = (AbstractButton) e.getSource();
   ButtonModel model = src.getModel();
   model.setArmed(false);
   model.setPressed(false);
   model.setRollover(false);
   model.setSelected(false);
 }
  @Override
  protected void installDefaults(AbstractButton b) {
    super.installDefaults(b);

    String pp = getPropertyPrefix();
    // b.setOpaque(QuaquaManager.getBoolean(pp+"opaque"));
    QuaquaUtilities.installProperty(b, "opaque", UIManager.get(pp + "opaque"));
    b.setRequestFocusEnabled(UIManager.getBoolean(pp + "requestFocusEnabled"));
    b.setFocusable(UIManager.getBoolean(pp + "focusable"));
  }
Example #24
0
  /**
   * This method overrides Container's addImpl method. If a JButton is added, it is disabled.
   *
   * @param component The Component to add.
   * @param constraints The Constraints placed on the component.
   * @param index The index to place the Component at.
   */
  protected void addImpl(Component component, Object constraints, int index) {
    // XXX: Sun says disable button but test cases show otherwise.
    super.addImpl(component, constraints, index);

    // if we added a Swing Button then adjust this a little
    if (component instanceof AbstractButton) {
      AbstractButton b = (AbstractButton) component;
      b.setRolloverEnabled(rollover);
    }
  } // addImpl()
Example #25
0
 protected void uninstallListeners(AbstractButton b) {
   BasicButtonListener listener = getButtonListener(b);
   if (listener != null) {
     b.removeMouseListener(listener);
     b.removeMouseMotionListener(listener);
     b.removeFocusListener(listener);
     b.removeChangeListener(listener);
     b.removePropertyChangeListener(listener);
   }
 }
Example #26
0
 protected void installListeners(AbstractButton b) {
   BasicButtonListener listener = createButtonListener(b);
   if (listener != null) {
     b.addMouseListener(listener);
     b.addMouseMotionListener(listener);
     b.addFocusListener(listener);
     b.addPropertyChangeListener(listener);
     b.addChangeListener(listener);
   }
 }
Example #27
0
 public void mouseEntered(MouseEvent evt) {
   if (evt.getSource() instanceof AbstractButton) {
     AbstractButton button = (AbstractButton) evt.getSource();
     Action action = button.getAction();
     if (action != null) {
       String message = (String) action.getValue("LongDescription");
       setMessage(message);
     }
   }
 }
Example #28
0
    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);
    }
Example #29
0
  private String layout(AbstractButton b, FontMetrics fm, int width, int height) {
    Insets i = b.getInsets();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    textRect.x = textRect.y = textRect.width = textRect.height = 0;
    iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;

    // layout the text and icon
    return SwingUtilities.layoutCompoundLabel(
        b,
        fm,
        b.getText(),
        b.getIcon(),
        b.getVerticalAlignment(),
        b.getHorizontalAlignment(),
        b.getVerticalTextPosition(),
        b.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        b.getText() == null ? 0 : b.getIconTextGap());
  }
Example #30
0
  /** Returns the baseline for buttons. */
  private static int getButtonBaseline(AbstractButton button, int height) {
    FontMetrics fm = button.getFontMetrics(button.getFont());

    resetRects(button, height);

    String text = button.getText();
    if (text != null && text.startsWith("<html>")) {
      return -1;
    }
    // NOTE: that we use "a" here to make sure we get a valid value, if
    // we were to pass in an empty string or null we would not get
    // back the right thing.
    SwingUtilities.layoutCompoundLabel(
        button,
        fm,
        "a",
        button.getIcon(),
        button.getVerticalAlignment(),
        button.getHorizontalAlignment(),
        button.getVerticalTextPosition(),
        button.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        text == null ? 0 : button.getIconTextGap());

    if (isAqua()) {
      return textRect.y + fm.getAscent() + 1;
    }
    return textRect.y + fm.getAscent();
  }