home *** CD-ROM | disk | FTP | other *** search
- package javax.swing;
-
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.beans.PropertyChangeListener;
- import java.io.IOException;
- import java.io.ObjectOutputStream;
- import java.util.Hashtable;
- import javax.accessibility.Accessible;
- import javax.accessibility.AccessibleContext;
- import javax.swing.plaf.ToolBarUI;
-
- public class JToolBar extends JComponent implements SwingConstants, Accessible {
- private static final String uiClassID = "ToolBarUI";
- private boolean paintBorder;
- private Insets margin;
- private boolean floatable;
- private int orientation;
- private static Hashtable listenerRegistry = null;
-
- public JToolBar() {
- this(0);
- }
-
- public JToolBar(int var1) {
- this.paintBorder = true;
- this.margin = null;
- this.floatable = true;
- this.orientation = 0;
- this.checkOrientation(var1);
- this.orientation = var1;
- if (var1 == 1) {
- ((Container)this).setLayout(new BoxLayout(this, 1));
- } else if (SwingUtilities.isLeftToRight(this)) {
- ((Container)this).setLayout(new BoxLayout(this, 0));
- } else {
- ((Container)this).setLayout(new RightToLeftToolBarLayout((1)null));
- }
-
- ((JComponent)this).addPropertyChangeListener(new PropertyChangeHandler(this));
- this.updateUI();
- }
-
- public JButton add(Action var1) {
- JButton var2 = new JButton((String)var1.getValue("Name"), (Icon)var1.getValue("SmallIcon"));
- ((AbstractButton)var2).setHorizontalTextPosition(0);
- ((AbstractButton)var2).setVerticalTextPosition(3);
- ((AbstractButton)var2).setEnabled(var1.isEnabled());
- ((AbstractButton)var2).addActionListener(var1);
- ((Container)this).add(var2);
- this.registerButtonForAction(var2, var1);
- return var2;
- }
-
- protected void addImpl(Component var1, Object var2, int var3) {
- super.addImpl(var1, var2, var3);
- if (var1 instanceof JButton) {
- ((JButton)var1).setDefaultCapable(false);
- }
-
- }
-
- public void addSeparator() {
- Separator var1 = new Separator();
- ((Container)this).add(var1);
- }
-
- public void addSeparator(Dimension var1) {
- Separator var2 = new Separator(var1);
- ((Container)this).add(var2);
- }
-
- private void checkOrientation(int var1) {
- switch (var1) {
- case 0:
- case 1:
- return;
- default:
- throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
- }
- }
-
- protected PropertyChangeListener createActionChangeListener(JButton var1) {
- return new ActionChangedListener(this, var1);
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJToolBar(this);
- }
-
- return super.accessibleContext;
- }
-
- public Component getComponentAtIndex(int var1) {
- int var2 = ((Container)this).getComponentCount();
- if (var1 >= 0 && var1 < var2) {
- Component[] var3 = ((Container)this).getComponents();
- return var3[var1];
- } else {
- return null;
- }
- }
-
- public int getComponentIndex(Component var1) {
- int var2 = ((Container)this).getComponentCount();
- Component[] var3 = ((Container)this).getComponents();
-
- for(int var4 = 0; var4 < var2; ++var4) {
- Component var5 = var3[var4];
- if (var5 == var1) {
- return var4;
- }
- }
-
- return -1;
- }
-
- public Insets getMargin() {
- return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
- }
-
- public int getOrientation() {
- return this.orientation;
- }
-
- public ToolBarUI getUI() {
- return (ToolBarUI)super.ui;
- }
-
- public String getUIClassID() {
- return "ToolBarUI";
- }
-
- public boolean isBorderPainted() {
- return this.paintBorder;
- }
-
- public boolean isFloatable() {
- return this.floatable;
- }
-
- protected void paintBorder(Graphics var1) {
- if (this.isBorderPainted()) {
- super.paintBorder(var1);
- }
-
- }
-
- protected String paramString() {
- String var1 = this.paintBorder ? "true" : "false";
- String var2 = this.margin != null ? this.margin.toString() : "";
- String var3 = this.floatable ? "true" : "false";
- String var4 = this.orientation == 0 ? "HORIZONTAL" : "VERTICAL";
- return super.paramString() + ",floatable=" + var3 + ",margin=" + var2 + ",orientation=" + var4 + ",paintBorder=" + var1;
- }
-
- private void registerButtonForAction(JButton var1, Action var2) {
- PropertyChangeListener var3 = this.createActionChangeListener(var1);
- if (listenerRegistry == null) {
- listenerRegistry = new Hashtable();
- }
-
- listenerRegistry.put(var1, var3);
- listenerRegistry.put(var3, var2);
- var2.addPropertyChangeListener(var3);
- }
-
- public void remove(Component var1) {
- super.remove(var1);
- if (var1 instanceof JButton) {
- JButton var2 = (JButton)var1;
- this.unregisterButtonForAction(var2);
- }
-
- }
-
- public void setBorderPainted(boolean var1) {
- if (this.paintBorder != var1) {
- boolean var2 = this.paintBorder;
- this.paintBorder = var1;
- ((JComponent)this).firePropertyChange("borderPainted", var2, var1);
- ((JComponent)this).revalidate();
- ((Component)this).repaint();
- }
-
- }
-
- public void setFloatable(boolean var1) {
- if (this.floatable != var1) {
- boolean var2 = this.floatable;
- this.floatable = var1;
- ((JComponent)this).firePropertyChange("floatable", var2, var1);
- ((JComponent)this).revalidate();
- ((Component)this).repaint();
- }
-
- }
-
- public void setMargin(Insets var1) {
- Insets var2 = this.margin;
- this.margin = var1;
- ((JComponent)this).firePropertyChange("margin", var2, var1);
- ((JComponent)this).revalidate();
- ((Component)this).repaint();
- }
-
- public void setOrientation(int var1) {
- this.checkOrientation(var1);
- if (this.orientation != var1) {
- int var2 = this.orientation;
- this.orientation = var1;
- if (var1 == 1) {
- ((Container)this).setLayout(new BoxLayout(this, 1));
- } else if (SwingUtilities.isLeftToRight(this)) {
- ((Container)this).setLayout(new BoxLayout(this, 0));
- } else {
- ((Container)this).setLayout(new RightToLeftToolBarLayout((1)null));
- }
-
- ((JComponent)this).firePropertyChange("orientation", var2, var1);
- ((JComponent)this).revalidate();
- ((Component)this).repaint();
- }
-
- }
-
- public void setUI(ToolBarUI var1) {
- super.setUI(var1);
- }
-
- private void unregisterButtonForAction(JButton var1) {
- if (listenerRegistry != null) {
- ActionChangedListener var2 = (ActionChangedListener)listenerRegistry.remove(var1);
- if (var2 != null) {
- Action var3 = (Action)listenerRegistry.remove(var2);
- if (var3 != null) {
- ((AbstractButton)var1).removeActionListener(var3);
- var3.removePropertyChangeListener(var2);
- }
-
- var2.setTarget((JButton)null);
- }
- }
-
- }
-
- public void updateUI() {
- this.setUI((ToolBarUI)UIManager.getUI(this));
- ((Container)this).invalidate();
- }
-
- private void writeObject(ObjectOutputStream var1) throws IOException {
- var1.defaultWriteObject();
- if (super.ui != null && this.getUIClassID().equals("ToolBarUI")) {
- super.ui.installUI(this);
- }
-
- }
- }
-