abstractbutton.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 1,946 行 · 第 1/4 页
JAVA
1,946 行
* <code>TOP</code>, or <code>BOTTOM</code>. The default is * <code>CENTER</code>. * * @return The current vertical position */ public int getVerticalTextPosition() { return verticalTextPosition; } /** * Set the vertical position of the button's text relative to its * icon. The alignment is a numeric constant from {@link * SwingConstants}. It must be one of: <code>CENTER</code>, * <code>TOP</code>, or <code>BOTTOM</code>. The default is * <code>CENTER</code>. * * @param t The new vertical position * @throws IllegalArgumentException If position is not one of the legal * constants. */ public void setVerticalTextPosition(int t) { if (verticalTextPosition == t) return; int old = verticalTextPosition; verticalTextPosition = t; firePropertyChange(VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, old, t); revalidate(); repaint(); } /** * Set the value of the "borderPainted" property. If set to * <code>false</code>, the button's look and feel class should not paint * a border for the button. The default is <code>true</code>. * * @return The current value of the property. */ public boolean isBorderPainted() { return borderPainted; } /** * Set the value of the "borderPainted" property. If set to * <code>false</code>, the button's look and feel class should not paint * a border for the button. The default is <code>true</code>. * * @param b The new value of the property. */ public void setBorderPainted(boolean b) { if (borderPainted == b) return; boolean old = borderPainted; borderPainted = b; firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, old, b); revalidate(); repaint(); } /** * Get the value of the "action" property. * * @return The current value of the "action" property */ public Action getAction() { return action; } /** * <p>Set the button's "action" property, subscribing the new action to the * button, as an ActionListener, if it is not already subscribed. The old * Action, if it exists, is unsubscribed, and the button is unsubscribed * from the old Action if it was previously subscribed as a * PropertyChangeListener.</p> * * <p>This method also configures several of the button's properties from * the Action, by calling {@link configurePropertiesFromAction}, and * subscribes the button to the Action as a PropertyChangeListener. * Subsequent changes to the Action will thus reconfigure the button * automatically.</p> * * @param a The new value of the "action" property */ public void setAction(Action a) { if (action != null) { action.removePropertyChangeListener(actionPropertyChangeListener); removeActionListener(action); if (actionPropertyChangeListener != null) { action.removePropertyChangeListener(actionPropertyChangeListener); actionPropertyChangeListener = null; } } Action old = action; action = a; configurePropertiesFromAction(action); if (action != null) { actionPropertyChangeListener = createActionPropertyChangeListener(a); action.addPropertyChangeListener(actionPropertyChangeListener); addActionListener(action); } } /** * Return the button's default "icon" property. * * @return The current default icon */ public Icon getIcon() { return default_icon; } /** * Set the button's default "icon" property. This icon is used as a basis * for the pressed and disabled icons, if none are explicitly set. * * @param i The new default icon */ public void setIcon(Icon i) { if (default_icon == i) return; Icon old = default_icon; default_icon = i; firePropertyChange(ICON_CHANGED_PROPERTY, old, i); revalidate(); repaint(); } /** * Return the button's "text" property. This property is synonymous with * the "label" property. * * @return The current "text" property */ public String getText() { return text; } /** * Set the button's "label" property. This property is synonymous with the * "text" property. * * @param label The new "label" property * * @deprecated use <code>setText(text)</code> */ public void setLabel(String label) { setText(label); } /** * Return the button's "label" property. This property is synonymous with * the "text" property. * * @return The current "label" property * * @deprecated use <code>getText()</code> */ public String getLabel() { return getText(); } /** * Set the button's "text" property. This property is synonymous with the * "label" property. * * @param t The new "text" property */ public void setText(String t) { if (text == t) return; String old = text; text = t; firePropertyChange(TEXT_CHANGED_PROPERTY, old, t); revalidate(); repaint(); } /** * Set the value of the {@link #iconTextGap} property. * * @param i The new value of the property */ public void setIconTextGap(int i) { if (iconTextGap == i) return; int old = iconTextGap; iconTextGap = i; fireStateChanged(); revalidate(); repaint(); } /** * Get the value of the {@link #iconTextGap} property. * * @return The current value of the property */ public int getIconTextGap() { return iconTextGap; } /** * Return the button's "margin" property, which is an {@link Insets} object * describing the distance between the button's border and its text and * icon. * * @return The current "margin" property */ public Insets getMargin() { return margin; } /** * Set the button's "margin" property, which is an {@link Insets} object * describing the distance between the button's border and its text and * icon. * * @param m The new "margin" property */ public void setMargin(Insets m) { if (margin == m) return; Insets old = margin; margin = m; firePropertyChange(MARGIN_CHANGED_PROPERTY, old, m); revalidate(); repaint(); } /** * Return the button's "pressedIcon" property. The look and feel class * should paint this icon when the "pressed" property of the button's * {@link ButtonModel} is <code>true</code>. This property may be * <code>null</code>, in which case the default icon is used. * * @return The current "pressedIcon" property */ public Icon getPressedIcon() { return pressed_icon; } /** * Set the button's "pressedIcon" property. The look and feel class * should paint this icon when the "pressed" property of the button's * {@link ButtonModel} is <code>true</code>. This property may be * <code>null</code>, in which case the default icon is used. * * @param pressedIcon The new "pressedIcon" property */ public void setPressedIcon(Icon pressedIcon) { if (pressed_icon == pressedIcon) return; Icon old = pressed_icon; pressed_icon = pressedIcon; firePropertyChange(PRESSED_ICON_CHANGED_PROPERTY, old, pressed_icon); revalidate(); repaint(); } /** * Return the button's "disabledIcon" property. The look and feel class * should paint this icon when the "enabled" property of the button's * {@link ButtonModel} is <code>false</code>. This property may be * <code>null</code>, in which case an icon is constructed, based on the * default icon. * * @return The current "disabledIcon" property */ public Icon getDisabledIcon() { if (disabeldIcon == null && default_icon instanceof ImageIcon) disabeldIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) default_icon).getImage())); return disabeldIcon; } /** * Set the button's "disabledIcon" property. The look and feel class should * paint this icon when the "enabled" property of the button's {@link * ButtonModel} is <code>false</code>. This property may be * <code>null</code>, in which case an icon is constructed, based on the * default icon. * * @param disabledIcon The new "disabledIcon" property */ public void setDisabledIcon(Icon d) { disabeldIcon = d; revalidate(); repaint(); } /** * Return the button's "paintFocus" property. This property controls * whether or not the look and feel class will paint a special indicator * of focus state for the button. If it is false, the button still paints * when focused, but no special decoration is painted to indicate the * presence of focus. * * @return The current "paintFocus" property */ public boolean isFocusPainted() { return focusPainted; } /** * Set the button's "paintFocus" property. This property controls whether * or not the look and feel class will paint a special indicator of focus * state for the button. If it is false, the button still paints when * focused, but no special decoration is painted to indicate the presence * of focus. * * @param b The new "paintFocus" property */ public void setFocusPainted(boolean p) { if (focusPainted == p) return; boolean old = focusPainted; focusPainted = p; firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, old, p); revalidate(); repaint(); } /** * Return the button's "focusTraversable" property. This property controls * whether or not the button can receive focus when the user attempts to * traverse the focus hierarchy. * * @return The current "focusTraversable" property */ public boolean isFocusTraversable() { return true; } /** * Verifies that a particular key is one of the valid constants used for * describing horizontal alignment and positioning. The valid constants * are the following members of {@link SwingConstants}: * <code>RIGHT</code>, <code>LEFT</code>, <code>CENTER</code>, * <code>LEADING</code> or <code>TRAILING</code>. * * @param key The key to check * @param exception A message to include in an IllegalArgumentException * * @return the value of key * * @throws IllegalArgumentException If key is not one of the valid constants * * @see setHorizontalTextPosition() * @see setHorizontalAlignment() */ protected int checkHorizontalKey(int key, String exception) { switch (key) { case SwingConstants.RIGHT: case SwingConstants.LEFT: case SwingConstants.CENTER: case SwingConstants.LEADING: case SwingConstants.TRAILING: break; default: throw new IllegalArgumentException(exception); } return key; } /** * Verifies that a particular key is one of the valid constants used for * describing vertical alignment and positioning. The valid constants are * the following members of {@link SwingConstants}: <code>TOP</code>, * <code>BOTTOM</code> or <code>CENTER</code>. * * @param key The key to check * @param exception A message to include in an IllegalArgumentException * * @return the value of key * * @throws IllegalArgumentException If key is not one of the valid constants * * @see setVerticalTextPosition() * @see setVerticalAlignment() */ protected int checkVerticalKey(int key, String exception) { switch (key) { case SwingConstants.TOP: case SwingConstants.BOTTOM: case SwingConstants.CENTER: break; default: throw new IllegalArgumentException(exception); } return key; } /** * Configure various properties of the button by reading properties * of an {@link Action}. The mapping of properties is as follows: * * <table> * * <tr><th>Action keyed property</th> <th>AbstractButton property</th></tr> * * <tr><td>NAME </td> <td>text </td></tr> * <tr><td>SMALL_ICON </td> <td>icon </td></tr> * <tr><td>SHORT_DESCRIPTION </td> <td>toolTipText </td></tr> * <tr><td>MNEMONIC_KEY </td> <td>mnemonic </td></tr> * <tr><td>ACTION_COMMAND_KEY </td> <td>actionCommand </td></tr> * * </table> * * <p>In addition, this method always sets the button's "enabled" property to * the value of the Action's "enabled" property.</p> * * <p>If the provided Action is <code>null</code>, the text, icon, and * toolTipText properties of the button are set to <code>null</code>, and * the "enabled" property is set to <code>true</code>; the mnemonic and * actionCommand properties are unchanged.</p> * * @param a An Action to configure the button from */ protected void configurePropertiesFromAction(Action a) { if (a == null) { setText(null); setIcon(null); setEnabled(true); setToolTipText(null); } else { setText((String)(a.getValue(Action.NAME))); setIcon((Icon)(a.getValue(Action.SMALL_ICON))); setEnabled(a.isEnabled()); setToolTipText((String)(a.getValue(Action.SHORT_DESCRIPTION))); if (a.getValue(Action.MNEMONIC_KEY) != null) setMnemonic(((Integer)(a.getValue(Action.MNEMONIC_KEY))).intValue()); String actionCommand = (String)(a.getValue(Action.ACTION_COMMAND_KEY)); // Set actionCommand to button's text by default if it is not specified if (actionCommand != null) setActionCommand((String)(a.getValue(Action.ACTION_COMMAND_KEY))); else setActionCommand(getText()); } } /** * <p>A factory method which should return an {@link ActionListener} that * propagates events from the button's {@link ButtonModel} to any of the
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?