public void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (frame.isSelected()) {
     g.setColor(UIManager.getColor("activeCaptionText"));
   } else {
     g.setColor(UIManager.getColor("inactiveCaptionText"));
   }
   Dimension d = getSize();
   String frameTitle = frame.getTitle();
   if (frameTitle != null) {
     MotifGraphicsUtils.drawStringInRect(
         frame, g, frameTitle, 0, 0, d.width, d.height, SwingConstants.CENTER);
   }
 }
  /**
   * 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());
  }
 public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) {
   ListCellRenderer renderer = comboBox.getRenderer();
   Component c;
   Dimension d;
   c =
       renderer.getListCellRendererComponent(
           listBox, comboBox.getSelectedItem(), -1, false, false);
   c.setFont(comboBox.getFont());
   if (comboBox.isEnabled()) {
     c.setForeground(comboBox.getForeground());
     c.setBackground(comboBox.getBackground());
   } else {
     c.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
     c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
   }
   d = c.getPreferredSize();
   currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y, bounds.width, d.height);
 }
    Title(String title) {
      super();
      setText(title);
      setHorizontalAlignment(SwingConstants.CENTER);
      setBorder(
          BorderFactory.createBevelBorder(
              BevelBorder.RAISED,
              UIManager.getColor("activeCaptionBorder"),
              UIManager.getColor("inactiveCaptionBorder")));

      // Forward mouse events to titlebar for moves.
      addMouseMotionListener(
          new MouseMotionListener() {
            public void mouseDragged(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mouseMoved(MouseEvent e) {
              forwardEventToParent(e);
            }
          });
      addMouseListener(
          new MouseListener() {
            public void mouseClicked(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mousePressed(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mouseReleased(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mouseEntered(MouseEvent e) {
              forwardEventToParent(e);
            }

            public void mouseExited(MouseEvent e) {
              forwardEventToParent(e);
            }
          });
    }
  public void installUI(JComponent c) {
    super.installUI(c);
    arrowIcon =
        new MotifComboBoxArrowIcon(
            UIManager.getColor("controlHighlight"),
            UIManager.getColor("controlShadow"),
            UIManager.getColor("control"));

    Runnable initCode =
        new Runnable() {
          public void run() {
            if (motifGetEditor() != null) {
              motifGetEditor().setBackground(UIManager.getColor("text"));
            }
          }
        };

    SwingUtilities.invokeLater(initCode);
  }
  public void paint(Graphics g, JComponent c) {
    boolean hasFocus = comboBox.hasFocus();
    Rectangle r;

    if (comboBox.isEnabled()) {
      g.setColor(comboBox.getBackground());
    } else {
      g.setColor(UIManager.getColor("ComboBox.disabledBackground"));
    }
    g.fillRect(0, 0, c.getWidth(), c.getHeight());

    if (!comboBox.isEditable()) {
      r = rectangleForCurrentValue();
      paintCurrentValue(g, r, hasFocus);
    }
    r = rectangleForArrowIcon();
    arrowIcon.paintIcon(c, g, r.x, r.y);
    if (!comboBox.isEditable()) {
      Border border = comboBox.getBorder();
      Insets in;
      if (border != null) {
        in = border.getBorderInsets(comboBox);
      } else {
        in = new Insets(0, 0, 0, 0);
      }
      // Draw the separation
      if (MotifGraphicsUtils.isLeftToRight(comboBox)) {
        r.x -= (HORIZ_MARGIN + 2);
      } else {
        r.x += r.width + HORIZ_MARGIN + 1;
      }
      r.y = in.top;
      r.width = 1;
      r.height = comboBox.getBounds().height - in.bottom - in.top;
      g.setColor(UIManager.getColor("controlShadow"));
      g.fillRect(r.x, r.y, r.width, r.height);
      r.x++;
      g.setColor(UIManager.getColor("controlHighlight"));
      g.fillRect(r.x, r.y, r.width, r.height);
    }
  }
Beispiel #7
0
  /**
   * Create a component that will replace the spinner models value with the object returned by
   * <code>spinner.getNextValue</code>. By default the <code>nextButton</code> is a JButton who's
   * <code>ActionListener</code> updates it's <code>JSpinner</code> ancestors model. If a nextButton
   * isn't needed (in a subclass) then override this method to return null.
   *
   * @return a component that will replace the spinners model with the next value in the sequence,
   *     or null
   * @see #installUI
   * @see #createPreviousButton
   */
  protected Component createNextButton() {
    Component tmpButton = super.createNextButton();

    if (tmpButton instanceof JButton) {
      JButton result = new ArrowButton(SwingConstants.NORTH);
      ((ArrowButton) result).setDrawBottomBorder(false);

      result.setBorder(
          BorderFactory.createMatteBorder(1, 1, 0, 1, UIManager.getColor("Button.borderColor")));
      ActionListener al[] = ((JButton) tmpButton).getActionListeners();
      for (int i = 0; i < al.length; i++) result.addActionListener(al[i]);

      MouseListener ml[] = ((JButton) tmpButton).getMouseListeners();
      for (int i = 0; i < ml.length; i++) result.addMouseListener(ml[i]);

      return result;
    } else return tmpButton;
  }
/**
 * Metal's split pane divider
 *
 * <p><strong>Warning:</strong> Serialized objects of this class will not be compatible with future
 * Swing releases. The current serialization support is appropriate for short term storage or RMI
 * between applications running the same version of Swing. As of 1.4, support for long term storage
 * of all JavaBeans<sup><font size="-2">TM</font></sup> has been added to the <code>java.beans
 * </code> package. Please see {@link java.beans.XMLEncoder}.
 *
 * @author Steve Wilson
 * @author Ralph kar
 */
class MetalSplitPaneDivider extends BasicSplitPaneDivider {
  private MetalBumps bumps =
      new MetalBumps(
          10,
          10,
          MetalLookAndFeel.getControlHighlight(),
          MetalLookAndFeel.getControlDarkShadow(),
          MetalLookAndFeel.getControl());

  private MetalBumps focusBumps =
      new MetalBumps(
          10,
          10,
          MetalLookAndFeel.getPrimaryControlHighlight(),
          MetalLookAndFeel.getPrimaryControlDarkShadow(),
          UIManager.getColor("SplitPane.dividerFocusColor"));

  private int inset = 2;

  private Color controlColor = MetalLookAndFeel.getControl();
  private Color primaryControlColor = UIManager.getColor("SplitPane.dividerFocusColor");

  public MetalSplitPaneDivider(BasicSplitPaneUI ui) {
    super(ui);
  }

  public void paint(Graphics g) {
    MetalBumps usedBumps;
    if (splitPane.hasFocus()) {
      usedBumps = focusBumps;
      g.setColor(primaryControlColor);
    } else {
      usedBumps = bumps;
      g.setColor(controlColor);
    }
    Rectangle clip = g.getClipBounds();
    Insets insets = getInsets();
    g.fillRect(clip.x, clip.y, clip.width, clip.height);
    Dimension size = getSize();
    size.width -= inset * 2;
    size.height -= inset * 2;
    int drawX = inset;
    int drawY = inset;
    if (insets != null) {
      size.width -= (insets.left + insets.right);
      size.height -= (insets.top + insets.bottom);
      drawX += insets.left;
      drawY += insets.top;
    }
    usedBumps.setBumpArea(size);
    usedBumps.paintIcon(this, g, drawX, drawY);
    super.paint(g);
  }

  /**
   * Creates and return an instance of JButton that can be used to collapse the left component in
   * the metal split pane.
   */
  protected JButton createLeftOneTouchButton() {
    JButton b =
        new JButton() {
          // Sprite buffer for the arrow image of the left button
          int[][] buffer = {
            {0, 0, 0, 2, 2, 0, 0, 0, 0},
            {0, 0, 2, 1, 1, 1, 0, 0, 0},
            {0, 2, 1, 1, 1, 1, 1, 0, 0},
            {2, 1, 1, 1, 1, 1, 1, 1, 0},
            {0, 3, 3, 3, 3, 3, 3, 3, 3}
          };

          public void setBorder(Border b) {}

          public void paint(Graphics g) {
            JSplitPane splitPane = getSplitPaneFromSuper();
            if (splitPane != null) {
              int oneTouchSize = getOneTouchSizeFromSuper();
              int orientation = getOrientationFromSuper();
              int blockSize = Math.min(getDividerSize(), oneTouchSize);

              // Initialize the color array
              Color[] colors = {
                this.getBackground(),
                MetalLookAndFeel.getPrimaryControlDarkShadow(),
                MetalLookAndFeel.getPrimaryControlInfo(),
                MetalLookAndFeel.getPrimaryControlHighlight()
              };

              // Fill the background first ...
              g.setColor(this.getBackground());
              if (isOpaque()) {
                g.fillRect(0, 0, this.getWidth(), this.getHeight());
              }

              // ... then draw the arrow.
              if (getModel().isPressed()) {
                // Adjust color mapping for pressed button state
                colors[1] = colors[2];
              }
              if (orientation == JSplitPane.VERTICAL_SPLIT) {
                // Draw the image for a vertical split
                for (int i = 1; i <= buffer[0].length; i++) {
                  for (int j = 1; j < blockSize; j++) {
                    if (buffer[j - 1][i - 1] == 0) {
                      continue;
                    } else {
                      g.setColor(colors[buffer[j - 1][i - 1]]);
                    }
                    g.drawLine(i, j, i, j);
                  }
                }
              } else {
                // Draw the image for a horizontal split
                // by simply swaping the i and j axis.
                // Except the drawLine() call this code is
                // identical to the code block above. This was done
                // in order to remove the additional orientation
                // check for each pixel.
                for (int i = 1; i <= buffer[0].length; i++) {
                  for (int j = 1; j < blockSize; j++) {
                    if (buffer[j - 1][i - 1] == 0) {
                      // Nothing needs
                      // to be drawn
                      continue;
                    } else {
                      // Set the color from the
                      // color map
                      g.setColor(colors[buffer[j - 1][i - 1]]);
                    }
                    // Draw a pixel
                    g.drawLine(j, i, j, i);
                  }
                }
              }
            }
          }

          // Don't want the button to participate in focus traversable.
          public boolean isFocusTraversable() {
            return false;
          }
        };
    b.setRequestFocusEnabled(false);
    b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    b.setFocusPainted(false);
    b.setBorderPainted(false);
    maybeMakeButtonOpaque(b);
    return b;
  }

  /** If necessary <code>c</code> is made opaque. */
  private void maybeMakeButtonOpaque(JComponent c) {
    Object opaque = UIManager.get("SplitPane.oneTouchButtonsOpaque");
    if (opaque != null) {
      c.setOpaque(((Boolean) opaque).booleanValue());
    }
  }

  /**
   * Creates and return an instance of JButton that can be used to collapse the right component in
   * the metal split pane.
   */
  protected JButton createRightOneTouchButton() {
    JButton b =
        new JButton() {
          // Sprite buffer for the arrow image of the right button
          int[][] buffer = {
            {2, 2, 2, 2, 2, 2, 2, 2},
            {0, 1, 1, 1, 1, 1, 1, 3},
            {0, 0, 1, 1, 1, 1, 3, 0},
            {0, 0, 0, 1, 1, 3, 0, 0},
            {0, 0, 0, 0, 3, 0, 0, 0}
          };

          public void setBorder(Border border) {}

          public void paint(Graphics g) {
            JSplitPane splitPane = getSplitPaneFromSuper();
            if (splitPane != null) {
              int oneTouchSize = getOneTouchSizeFromSuper();
              int orientation = getOrientationFromSuper();
              int blockSize = Math.min(getDividerSize(), oneTouchSize);

              // Initialize the color array
              Color[] colors = {
                this.getBackground(),
                MetalLookAndFeel.getPrimaryControlDarkShadow(),
                MetalLookAndFeel.getPrimaryControlInfo(),
                MetalLookAndFeel.getPrimaryControlHighlight()
              };

              // Fill the background first ...
              g.setColor(this.getBackground());
              if (isOpaque()) {
                g.fillRect(0, 0, this.getWidth(), this.getHeight());
              }

              // ... then draw the arrow.
              if (getModel().isPressed()) {
                // Adjust color mapping for pressed button state
                colors[1] = colors[2];
              }
              if (orientation == JSplitPane.VERTICAL_SPLIT) {
                // Draw the image for a vertical split
                for (int i = 1; i <= buffer[0].length; i++) {
                  for (int j = 1; j < blockSize; j++) {
                    if (buffer[j - 1][i - 1] == 0) {
                      continue;
                    } else {
                      g.setColor(colors[buffer[j - 1][i - 1]]);
                    }
                    g.drawLine(i, j, i, j);
                  }
                }
              } else {
                // Draw the image for a horizontal split
                // by simply swaping the i and j axis.
                // Except the drawLine() call this code is
                // identical to the code block above. This was done
                // in order to remove the additional orientation
                // check for each pixel.
                for (int i = 1; i <= buffer[0].length; i++) {
                  for (int j = 1; j < blockSize; j++) {
                    if (buffer[j - 1][i - 1] == 0) {
                      // Nothing needs
                      // to be drawn
                      continue;
                    } else {
                      // Set the color from the
                      // color map
                      g.setColor(colors[buffer[j - 1][i - 1]]);
                    }
                    // Draw a pixel
                    g.drawLine(j, i, j, i);
                  }
                }
              }
            }
          }

          // Don't want the button to participate in focus traversable.
          public boolean isFocusTraversable() {
            return false;
          }
        };
    b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    b.setFocusPainted(false);
    b.setBorderPainted(false);
    b.setRequestFocusEnabled(false);
    maybeMakeButtonOpaque(b);
    return b;
  }

  /**
   * Used to layout a MetalSplitPaneDivider. Layout for the divider involves appropriately moving
   * the left/right buttons around.
   *
   * <p>This class should be treated as a &quot;protected&quot; inner class. Instantiate it only
   * within subclasses of MetalSplitPaneDivider.
   */
  public class MetalDividerLayout implements LayoutManager {

    // NOTE NOTE NOTE NOTE NOTE
    // This class is no longer used, the functionality has
    // been rolled into BasicSplitPaneDivider.DividerLayout as a
    // defaults property

    public void layoutContainer(Container c) {
      JButton leftButton = getLeftButtonFromSuper();
      JButton rightButton = getRightButtonFromSuper();
      JSplitPane splitPane = getSplitPaneFromSuper();
      int orientation = getOrientationFromSuper();
      int oneTouchSize = getOneTouchSizeFromSuper();
      int oneTouchOffset = getOneTouchOffsetFromSuper();
      Insets insets = getInsets();

      // This layout differs from the one used in BasicSplitPaneDivider.
      // It does not center justify the oneTouchExpadable buttons.
      // This was necessary in order to meet the spec of the Metal
      // splitpane divider.
      if (leftButton != null && rightButton != null && c == MetalSplitPaneDivider.this) {
        if (splitPane.isOneTouchExpandable()) {
          if (orientation == JSplitPane.VERTICAL_SPLIT) {
            int extraY = (insets != null) ? insets.top : 0;
            int blockSize = getDividerSize();

            if (insets != null) {
              blockSize -= (insets.top + insets.bottom);
            }
            blockSize = Math.min(blockSize, oneTouchSize);
            leftButton.setBounds(oneTouchOffset, extraY, blockSize * 2, blockSize);
            rightButton.setBounds(
                oneTouchOffset + oneTouchSize * 2, extraY, blockSize * 2, blockSize);
          } else {
            int blockSize = getDividerSize();
            int extraX = (insets != null) ? insets.left : 0;

            if (insets != null) {
              blockSize -= (insets.left + insets.right);
            }
            blockSize = Math.min(blockSize, oneTouchSize);
            leftButton.setBounds(extraX, oneTouchOffset, blockSize, blockSize * 2);
            rightButton.setBounds(
                extraX, oneTouchOffset + oneTouchSize * 2, blockSize, blockSize * 2);
          }
        } else {
          leftButton.setBounds(-5, -5, 1, 1);
          rightButton.setBounds(-5, -5, 1, 1);
        }
      }
    }

    public Dimension minimumLayoutSize(Container c) {
      return new Dimension(0, 0);
    }

    public Dimension preferredLayoutSize(Container c) {
      return new Dimension(0, 0);
    }

    public void removeLayoutComponent(Component c) {}

    public void addLayoutComponent(String string, Component c) {}
  }

  /*
   * The following methods only exist in order to be able to access protected
   * members in the superclass, because these are otherwise not available
   * in any inner class.
   */

  int getOneTouchSizeFromSuper() {
    return super.ONE_TOUCH_SIZE;
  }

  int getOneTouchOffsetFromSuper() {
    return super.ONE_TOUCH_OFFSET;
  }

  int getOrientationFromSuper() {
    return super.orientation;
  }

  JSplitPane getSplitPaneFromSuper() {
    return super.splitPane;
  }

  JButton getLeftButtonFromSuper() {
    return super.leftButton;
  }

  JButton getRightButtonFromSuper() {
    return super.rightButton;
  }
}
Beispiel #9
0
 protected Color getDisabledTextColor() {
   disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText");
   return disabledTextColor;
 }
Beispiel #10
0
 // ********************************
 //         Default Accessors
 // ********************************
 protected Color getSelectColor() {
   selectColor = UIManager.getColor(getPropertyPrefix() + "select");
   return selectColor;
 }
Beispiel #11
0
 protected Color getFocusColor() {
   focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
   return focusColor;
 }
 public void configureEditor() {
   super.configureEditor();
   editor.setBackground(UIManager.getColor("text"));
 }