< prev index next >

src/demo/share/jfc/SwingSet2/DirectionPanel.java

Print this page




  75         b.setEnabled(enable);
  76         b = (DirectionButton) secondThree.add(new DirectionButton( mr_dot, mrdn_dot, "E", "Sets the orientation to the East", l, group, selection.equals("E")));
  77         b.setEnabled(enable);
  78         b = (DirectionButton) thirdThree.add(new DirectionButton(  bl_dot, bldn_dot, "SW", "Sets the orientation to the South-West", l, group, selection.equals("SW")));
  79         b.setEnabled(enable);
  80         b = (DirectionButton) thirdThree.add(new DirectionButton(  bm_dot, bmdn_dot, "S", "Sets the orientation to the South", l, group, selection.equals("S")));
  81         b.setEnabled(enable);
  82         b = (DirectionButton) thirdThree.add(new DirectionButton(  br_dot, brdn_dot, "SE", "Sets the orientation to the South-East", l, group, selection.equals("SE")));
  83         b.setEnabled(enable);
  84 
  85         add(firstThree);
  86         add(secondThree);
  87         add(thirdThree);
  88     }
  89 
  90     public String getSelection() {
  91         return group.getSelection().getActionCommand();
  92     }
  93 
  94     public void setSelection( String selection  ) {
  95         Enumeration e = group.getElements();
  96         while( e.hasMoreElements() ) {
  97             JRadioButton b = (JRadioButton)e.nextElement();
  98             if( b.getActionCommand().equals(selection) ) {
  99                b.setSelected(true);
 100             }
 101         }
 102     }
 103 
 104     // Chester's way cool layout buttons
 105     public ImageIcon bl_dot   = loadImageIcon("bl.gif","bottom left layout button");
 106     public ImageIcon bldn_dot = loadImageIcon("bldn.gif","selected bottom left layout button");
 107     public ImageIcon bm_dot   = loadImageIcon("bm.gif","bottom middle layout button");
 108     public ImageIcon bmdn_dot = loadImageIcon("bmdn.gif","selected bottom middle layout button");
 109     public ImageIcon br_dot   = loadImageIcon("br.gif","bottom right layout button");
 110     public ImageIcon brdn_dot = loadImageIcon("brdn.gif","selected bottom right layout button");
 111     public ImageIcon c_dot    = loadImageIcon("c.gif","center layout button");
 112     public ImageIcon cdn_dot  = loadImageIcon("cdn.gif","selected center layout button");
 113     public ImageIcon ml_dot   = loadImageIcon("ml.gif","middle left layout button");
 114     public ImageIcon mldn_dot = loadImageIcon("mldn.gif","selected middle left layout button");
 115     public ImageIcon mr_dot   = loadImageIcon("mr.gif","middle right layout button");
 116     public ImageIcon mrdn_dot = loadImageIcon("mrdn.gif","selected middle right layout button");
 117     public ImageIcon tl_dot   = loadImageIcon("tl.gif","top left layout button");


 130     public class DirectionButton extends JRadioButton {
 131 
 132         /**
 133          * A layout direction button
 134          */
 135         public DirectionButton(Icon icon, Icon downIcon, String direction,
 136                                String description, ActionListener l,
 137                                ButtonGroup group, boolean selected)
 138         {
 139             super();
 140             this.addActionListener(l);
 141             setFocusPainted(false);
 142             setHorizontalTextPosition(CENTER);
 143             group.add(this);
 144             setIcon(icon);
 145             setSelectedIcon(downIcon);
 146             setActionCommand(direction);
 147             getAccessibleContext().setAccessibleName(direction);
 148             getAccessibleContext().setAccessibleDescription(description);
 149             setSelected(selected);
 150         }
 151 
 152         public boolean isFocusTraversable() {
 153             return false;
 154         }
 155 
 156         public void setBorder(Border b) {
 157         }
 158     }
 159 }


  75         b.setEnabled(enable);
  76         b = (DirectionButton) secondThree.add(new DirectionButton( mr_dot, mrdn_dot, "E", "Sets the orientation to the East", l, group, selection.equals("E")));
  77         b.setEnabled(enable);
  78         b = (DirectionButton) thirdThree.add(new DirectionButton(  bl_dot, bldn_dot, "SW", "Sets the orientation to the South-West", l, group, selection.equals("SW")));
  79         b.setEnabled(enable);
  80         b = (DirectionButton) thirdThree.add(new DirectionButton(  bm_dot, bmdn_dot, "S", "Sets the orientation to the South", l, group, selection.equals("S")));
  81         b.setEnabled(enable);
  82         b = (DirectionButton) thirdThree.add(new DirectionButton(  br_dot, brdn_dot, "SE", "Sets the orientation to the South-East", l, group, selection.equals("SE")));
  83         b.setEnabled(enable);
  84 
  85         add(firstThree);
  86         add(secondThree);
  87         add(thirdThree);
  88     }
  89 
  90     public String getSelection() {
  91         return group.getSelection().getActionCommand();
  92     }
  93 
  94     public void setSelection( String selection  ) {
  95         Enumeration<AbstractButton> e = group.getElements();
  96         while( e.hasMoreElements() ) {
  97                 AbstractButton b = e.nextElement();
  98             if( b.getActionCommand().equals(selection) ) {
  99                b.setSelected(true);
 100             }
 101         }
 102     }
 103 
 104     // Chester's way cool layout buttons
 105     public ImageIcon bl_dot   = loadImageIcon("bl.gif","bottom left layout button");
 106     public ImageIcon bldn_dot = loadImageIcon("bldn.gif","selected bottom left layout button");
 107     public ImageIcon bm_dot   = loadImageIcon("bm.gif","bottom middle layout button");
 108     public ImageIcon bmdn_dot = loadImageIcon("bmdn.gif","selected bottom middle layout button");
 109     public ImageIcon br_dot   = loadImageIcon("br.gif","bottom right layout button");
 110     public ImageIcon brdn_dot = loadImageIcon("brdn.gif","selected bottom right layout button");
 111     public ImageIcon c_dot    = loadImageIcon("c.gif","center layout button");
 112     public ImageIcon cdn_dot  = loadImageIcon("cdn.gif","selected center layout button");
 113     public ImageIcon ml_dot   = loadImageIcon("ml.gif","middle left layout button");
 114     public ImageIcon mldn_dot = loadImageIcon("mldn.gif","selected middle left layout button");
 115     public ImageIcon mr_dot   = loadImageIcon("mr.gif","middle right layout button");
 116     public ImageIcon mrdn_dot = loadImageIcon("mrdn.gif","selected middle right layout button");
 117     public ImageIcon tl_dot   = loadImageIcon("tl.gif","top left layout button");


 130     public class DirectionButton extends JRadioButton {
 131 
 132         /**
 133          * A layout direction button
 134          */
 135         public DirectionButton(Icon icon, Icon downIcon, String direction,
 136                                String description, ActionListener l,
 137                                ButtonGroup group, boolean selected)
 138         {
 139             super();
 140             this.addActionListener(l);
 141             setFocusPainted(false);
 142             setHorizontalTextPosition(CENTER);
 143             group.add(this);
 144             setIcon(icon);
 145             setSelectedIcon(downIcon);
 146             setActionCommand(direction);
 147             getAccessibleContext().setAccessibleName(direction);
 148             getAccessibleContext().setAccessibleDescription(description);
 149             setSelected(selected);
 150             setFocusable(false);



 151         }
 152 
 153         public void setBorder(Border b) {
 154         }
 155     }
 156 }
< prev index next >