/[classpath]/classpath/javax/swing/AbstractButton.java
ViewVC logotype

Diff of /classpath/javax/swing/AbstractButton.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17.2.10 by gnu_andrew, Tue Aug 2 20:12:36 2005 UTC revision 1.17.2.11 by gnu_andrew, Wed Nov 2 00:43:42 2005 UTC
# Line 165  public abstract class AbstractButton ext Line 165  public abstract class AbstractButton ext
165       */       */
166      public void stateChanged(ChangeEvent ev)      public void stateChanged(ChangeEvent ev)
167      {      {
168          AbstractButton.this.fireStateChanged();
169          repaint();
170      }      }
171    }    }
172    
# Line 375  public abstract class AbstractButton ext Line 377  public abstract class AbstractButton ext
377            
378      protected AccessibleAbstractButton()      protected AccessibleAbstractButton()
379      {      {
380          // Nothing to do here yet.
381      }      }
382    
383      public AccessibleStateSet getAccessibleStateSet()      public AccessibleStateSet getAccessibleStateSet()
# Line 509  public abstract class AbstractButton ext Line 512  public abstract class AbstractButton ext
512    }    }
513    
514    /**    /**
515     * Creates a new AbstractButton object.     * Creates a new AbstractButton object. Subclasses should call the following
516       * sequence in their constructor in order to initialize the button correctly:
517       * <pre>
518       * super();
519       * init(text, icon);
520       * </pre>
521       *
522       * The {@link #init(String, Icon)} method is not called automatically by this
523       * constructor.
524       *
525       * @see #init(String, Icon)
526     */     */
527    public AbstractButton()    public AbstractButton()
528    {    {
529      init("", null);      actionListener = createActionListener();
530        changeListener = createChangeListener();
531        itemListener = createItemListener();
532    
533        horizontalAlignment = CENTER;
534        horizontalTextPosition = TRAILING;
535        verticalAlignment = CENTER;
536        verticalTextPosition = CENTER;
537        borderPainted = true;
538        contentAreaFilled = true;
539        focusPainted = true;
540        setFocusable(true);
541        setAlignmentX(CENTER_ALIGNMENT);
542        setAlignmentY(CENTER_ALIGNMENT);
543        setDisplayedMnemonicIndex(-1);
544        setOpaque(true);
545        text = "";
546      updateUI();      updateUI();
547    }    }
548    
# Line 524  public abstract class AbstractButton ext Line 553  public abstract class AbstractButton ext
553     */     */
554    public ButtonModel getModel()    public ButtonModel getModel()
555    {    {
556      return model;        return model;
557    }    }
558    
559    /**    /**
# Line 569  public abstract class AbstractButton ext Line 598  public abstract class AbstractButton ext
598    
599      if (icon != null)      if (icon != null)
600        default_icon = icon;        default_icon = icon;
   
     actionListener = createActionListener();  
     changeListener = createChangeListener();  
     itemListener = createItemListener();  
   
     horizontalAlignment = CENTER;  
     horizontalTextPosition = TRAILING;  
     verticalAlignment = CENTER;  
     verticalTextPosition = CENTER;  
     borderPainted = true;  
     contentAreaFilled = true;  
   
     focusPainted = true;  
     setFocusable(true);  
   
     setAlignmentX(LEFT_ALIGNMENT);  
     setAlignmentY(CENTER_ALIGNMENT);  
   
     setDisplayedMnemonicIndex(-1);      
601   }   }
602    
603    /**    /**
# Line 615  public abstract class AbstractButton ext Line 625  public abstract class AbstractButton ext
625     */     */
626    public void setActionCommand(String actionCommand)    public void setActionCommand(String actionCommand)
627    {    {
628      model.setActionCommand(actionCommand);      if (model != null)
629          model.setActionCommand(actionCommand);
630    }    }
631    
632    /**    /**
# Line 782  public abstract class AbstractButton ext Line 793  public abstract class AbstractButton ext
793     */     */
794    public int getMnemonic()    public int getMnemonic()
795    {    {
796      return getModel().getMnemonic();      ButtonModel mod = getModel();
797        if (mod != null)
798          return mod.getMnemonic();
799        return -1;
800    }    }
801    
802    /**    /**
# Line 810  public abstract class AbstractButton ext Line 824  public abstract class AbstractButton ext
824     */     */
825    public void setMnemonic(int mne)    public void setMnemonic(int mne)
826    {    {
827      int old = getModel().getMnemonic();      ButtonModel mod = getModel();
828        int old = -1;
829        if (mod != null)
830          old = mod.getMnemonic();
831    
832      if (old != mne)      if (old != mne)
833        {        {
834          getModel().setMnemonic(mne);          if (mod != null)
835              mod.setMnemonic(mne);
836    
837          if (text != null && !text.equals(""))          if (text != null && !text.equals(""))
838            {            {
# Line 907  public abstract class AbstractButton ext Line 925  public abstract class AbstractButton ext
925     */     */
926    public void setSelected(boolean s)    public void setSelected(boolean s)
927    {    {
928      getModel().setSelected(s);      ButtonModel mod = getModel();
929        if (mod != null)
930          mod.setSelected(s);
931    }    }
932    
933    /**    /**
# Line 918  public abstract class AbstractButton ext Line 938  public abstract class AbstractButton ext
938     */     */
939    public boolean isSelected()    public boolean isSelected()
940    {    {
941      return getModel().isSelected();      ButtonModel mod = getModel();
942        if (mod != null)
943          return mod.isSelected();
944        return false;
945    }    }
946    
947    /**    /**
# Line 929  public abstract class AbstractButton ext Line 952  public abstract class AbstractButton ext
952     */     */
953    public void setEnabled(boolean b)    public void setEnabled(boolean b)
954    {    {
955        // Do nothing if state does not change.
956        if (b == isEnabled())
957          return;
958      super.setEnabled(b);      super.setEnabled(b);
959      getModel().setEnabled(b);      ButtonModel mod = getModel();
960        if (mod != null)
961          mod.setEnabled(b);
962    }    }
963    
964    /**    /**
# Line 1608  public abstract class AbstractButton ext Line 1636  public abstract class AbstractButton ext
1636     *     *
1637     * @return The new ChangeListener     * @return The new ChangeListener
1638     */     */
1639    protected  ChangeListener createChangeListener()    protected ChangeListener createChangeListener()
1640    {    {
1641      return new ChangeListener()      return new ButtonChangeListener();
       {  
         public void stateChanged(ChangeEvent e)  
         {  
           AbstractButton.this.fireStateChanged();  
           AbstractButton.this.repaint();            
         }  
       };  
1642    }    }
1643    
1644    /**    /**
# Line 1669  public abstract class AbstractButton ext Line 1690  public abstract class AbstractButton ext
1690     */     */
1691    public void doClick(int pressTime)    public void doClick(int pressTime)
1692    {    {
1693      getModel().setArmed(true);      ButtonModel mod = getModel();
1694      getModel().setPressed(true);      if (mod != null)
     try  
1695        {        {
1696          java.lang.Thread.sleep(pressTime);          mod.setArmed(true);
1697        }          mod.setPressed(true);
1698      catch (java.lang.InterruptedException e)          try
1699        {            {
1700          // probably harmless              java.lang.Thread.sleep(pressTime);
1701              }
1702            catch (java.lang.InterruptedException e)
1703              {
1704                // probably harmless
1705              }
1706            mod.setPressed(false);
1707            mod.setArmed(false);
1708        }        }
     getModel().setPressed(false);  
     getModel().setArmed(false);  
1709    }    }
1710    
1711    /**    /**
# Line 1979  public abstract class AbstractButton ext Line 2004  public abstract class AbstractButton ext
2004     */     */
2005    public void updateUI()    public void updateUI()
2006    {    {
2007        // TODO: What to do here?
2008    }    }
2009    
2010    /**    /**

Legend:
Removed from v.1.17.2.10  
changed lines
  Added in v.1.17.2.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26