home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / JToolBar.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  6.5 KB  |  250 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.Insets;
  8. import java.beans.PropertyChangeListener;
  9. import java.io.IOException;
  10. import java.io.ObjectOutputStream;
  11. import java.util.Hashtable;
  12. import javax.accessibility.Accessible;
  13. import javax.accessibility.AccessibleContext;
  14. import javax.swing.plaf.ToolBarUI;
  15.  
  16. public class JToolBar extends JComponent implements SwingConstants, Accessible {
  17.    private static final String uiClassID = "ToolBarUI";
  18.    private boolean paintBorder;
  19.    private Insets margin;
  20.    private boolean floatable;
  21.    private int orientation;
  22.    private static Hashtable listenerRegistry = null;
  23.  
  24.    public JToolBar() {
  25.       this(0);
  26.    }
  27.  
  28.    public JToolBar(int var1) {
  29.       this.paintBorder = true;
  30.       this.margin = null;
  31.       this.floatable = true;
  32.       this.orientation = 0;
  33.       this.checkOrientation(var1);
  34.       this.orientation = var1;
  35.       if (var1 == 1) {
  36.          ((Container)this).setLayout(new BoxLayout(this, 1));
  37.       } else {
  38.          ((Container)this).setLayout(new BoxLayout(this, 0));
  39.       }
  40.  
  41.       this.updateUI();
  42.    }
  43.  
  44.    public JButton add(Action var1) {
  45.       JButton var2 = new JButton((String)var1.getValue("Name"), (Icon)var1.getValue("SmallIcon"));
  46.       ((AbstractButton)var2).setHorizontalTextPosition(0);
  47.       ((AbstractButton)var2).setVerticalTextPosition(3);
  48.       ((AbstractButton)var2).setEnabled(var1.isEnabled());
  49.       ((AbstractButton)var2).addActionListener(var1);
  50.       ((Container)this).add(var2);
  51.       PropertyChangeListener var3 = this.createActionChangeListener(var2);
  52.       if (listenerRegistry == null) {
  53.          listenerRegistry = new Hashtable();
  54.       }
  55.  
  56.       listenerRegistry.put(var2, var3);
  57.       listenerRegistry.put(var3, var1);
  58.       var1.addPropertyChangeListener(var3);
  59.       return var2;
  60.    }
  61.  
  62.    protected void addImpl(Component var1, Object var2, int var3) {
  63.       super.addImpl(var1, var2, var3);
  64.       if (var1 instanceof JButton) {
  65.          ((JButton)var1).setDefaultCapable(false);
  66.       }
  67.  
  68.    }
  69.  
  70.    public void addSeparator() {
  71.       Separator var1 = new Separator();
  72.       ((Container)this).add(var1);
  73.    }
  74.  
  75.    public void addSeparator(Dimension var1) {
  76.       Separator var2 = new Separator(var1);
  77.       ((Container)this).add(var2);
  78.    }
  79.  
  80.    private void checkOrientation(int var1) {
  81.       switch (var1) {
  82.          case 0:
  83.          case 1:
  84.             return;
  85.          default:
  86.             throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
  87.       }
  88.    }
  89.  
  90.    protected PropertyChangeListener createActionChangeListener(JButton var1) {
  91.       return new ActionChangedListener(this, var1);
  92.    }
  93.  
  94.    public AccessibleContext getAccessibleContext() {
  95.       if (super.accessibleContext == null) {
  96.          super.accessibleContext = new AccessibleJToolBar(this);
  97.       }
  98.  
  99.       return super.accessibleContext;
  100.    }
  101.  
  102.    public Component getComponentAtIndex(int var1) {
  103.       int var2 = ((Container)this).getComponentCount();
  104.       if (var1 >= 0 && var1 < var2) {
  105.          Component[] var3 = ((Container)this).getComponents();
  106.          return var3[var1];
  107.       } else {
  108.          return null;
  109.       }
  110.    }
  111.  
  112.    public int getComponentIndex(Component var1) {
  113.       int var2 = ((Container)this).getComponentCount();
  114.       Component[] var3 = ((Container)this).getComponents();
  115.  
  116.       for(int var4 = 0; var4 < var2; ++var4) {
  117.          Component var5 = var3[var4];
  118.          if (var5 == var1) {
  119.             return var4;
  120.          }
  121.       }
  122.  
  123.       return -1;
  124.    }
  125.  
  126.    public Insets getMargin() {
  127.       return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
  128.    }
  129.  
  130.    public int getOrientation() {
  131.       return this.orientation;
  132.    }
  133.  
  134.    public ToolBarUI getUI() {
  135.       return (ToolBarUI)super.ui;
  136.    }
  137.  
  138.    public String getUIClassID() {
  139.       return "ToolBarUI";
  140.    }
  141.  
  142.    public boolean isBorderPainted() {
  143.       return this.paintBorder;
  144.    }
  145.  
  146.    public boolean isFloatable() {
  147.       return this.floatable;
  148.    }
  149.  
  150.    protected void paintBorder(Graphics var1) {
  151.       if (this.isBorderPainted()) {
  152.          super.paintBorder(var1);
  153.       }
  154.  
  155.    }
  156.  
  157.    protected String paramString() {
  158.       String var1 = this.paintBorder ? "true" : "false";
  159.       String var2 = this.margin != null ? this.margin.toString() : "";
  160.       String var3 = this.floatable ? "true" : "false";
  161.       String var4 = this.orientation == 0 ? "HORIZONTAL" : "VERTICAL";
  162.       return super.paramString() + ",floatable=" + var3 + ",margin=" + var2 + ",orientation=" + var4 + ",paintBorder=" + var1;
  163.    }
  164.  
  165.    public void remove(Component var1) {
  166.       super.remove(var1);
  167.       if (var1 instanceof JButton) {
  168.          JButton var2 = (JButton)var1;
  169.          if (listenerRegistry != null) {
  170.             ActionChangedListener var3 = (ActionChangedListener)listenerRegistry.remove(var2);
  171.             Action var4 = (Action)listenerRegistry.remove(var3);
  172.             ((AbstractButton)var2).removeActionListener(var4);
  173.             if (var3 != null) {
  174.                var3.setTarget((JButton)null);
  175.             }
  176.  
  177.             if (var4 != null) {
  178.                var4.removePropertyChangeListener(var3);
  179.             }
  180.          }
  181.       }
  182.  
  183.    }
  184.  
  185.    public void setBorderPainted(boolean var1) {
  186.       if (this.paintBorder != var1) {
  187.          boolean var2 = this.paintBorder;
  188.          this.paintBorder = var1;
  189.          ((JComponent)this).firePropertyChange("borderpainted", var2, var1);
  190.          ((JComponent)this).revalidate();
  191.          ((Component)this).repaint();
  192.       }
  193.  
  194.    }
  195.  
  196.    public void setFloatable(boolean var1) {
  197.       if (this.floatable != var1) {
  198.          boolean var2 = this.floatable;
  199.          this.floatable = var1;
  200.          ((JComponent)this).firePropertyChange("floatable", var2, var1);
  201.          ((JComponent)this).revalidate();
  202.          ((Component)this).repaint();
  203.       }
  204.  
  205.    }
  206.  
  207.    public void setMargin(Insets var1) {
  208.       Insets var2 = this.margin;
  209.       this.margin = var1;
  210.       ((JComponent)this).firePropertyChange("margin", var2, var1);
  211.       ((JComponent)this).revalidate();
  212.       ((Component)this).repaint();
  213.    }
  214.  
  215.    public void setOrientation(int var1) {
  216.       this.checkOrientation(var1);
  217.       if (this.orientation != var1) {
  218.          int var2 = this.orientation;
  219.          this.orientation = var1;
  220.          if (var1 == 1) {
  221.             ((Container)this).setLayout(new BoxLayout(this, 1));
  222.          } else {
  223.             ((Container)this).setLayout(new BoxLayout(this, 0));
  224.          }
  225.  
  226.          ((JComponent)this).firePropertyChange("orientation", var2, var1);
  227.          ((JComponent)this).revalidate();
  228.          ((Component)this).repaint();
  229.       }
  230.  
  231.    }
  232.  
  233.    public void setUI(ToolBarUI var1) {
  234.       super.setUI(var1);
  235.    }
  236.  
  237.    public void updateUI() {
  238.       this.setUI((ToolBarUI)UIManager.getUI(this));
  239.       ((Container)this).invalidate();
  240.    }
  241.  
  242.    private void writeObject(ObjectOutputStream var1) throws IOException {
  243.       var1.defaultWriteObject();
  244.       if (super.ui != null && this.getUIClassID().equals("ToolBarUI")) {
  245.          super.ui.installUI(this);
  246.       }
  247.  
  248.    }
  249. }
  250.