home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / inprise / JSAMPLES.Z / DirectionButton.java < prev    next >
Text File  |  1998-05-08  |  6KB  |  125 lines

  1.  /*
  2.  * @(#)DirectionButton.java    1.4 98/01/31
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. import com.sun.java.swing.*;
  22. import com.sun.java.swing.border.*;
  23.  
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import java.util.*;
  27.  
  28.  
  29. /**
  30.  * @version 1.4 01/31/98
  31.  * @author Jeff Dinkins
  32.  */ 
  33. public class DirectionButton extends JRadioButton {
  34.  
  35.     // Chester's way cool layout buttons 
  36.     public static ImageIcon bl_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/bl.gif","bottom left layout button");
  37.     public static ImageIcon bldn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/bldn.gif","selected bottom left layout button");
  38.     public static ImageIcon bm_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/bm.gif","bottom middle layout button");
  39.     public static ImageIcon bmdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/bmdn.gif","selected bottom middle layout button");
  40.     public static ImageIcon br_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/br.gif","bottom right layout button");
  41.     public static ImageIcon brdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/brdn.gif","selected bottom right layout button");
  42.     public static ImageIcon c_dot    = SwingSet.sharedInstance().loadImageIcon("images/layout/c.gif","center layout button");
  43.     public static ImageIcon cdn_dot  = SwingSet.sharedInstance().loadImageIcon("images/layout/cdn.gif","selected center layout button");
  44.     public static ImageIcon ml_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/ml.gif","middle left layout button");
  45.     public static ImageIcon mldn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/mldn.gif","selected middle left layout button");
  46.     public static ImageIcon mr_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/mr.gif","middle right layout button");
  47.     public static ImageIcon mrdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/mrdn.gif","selected middle right layout button");
  48.     public static ImageIcon tl_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/tl.gif","top left layout button");
  49.     public static ImageIcon tldn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/tldn.gif","selected top left layout button");
  50.     public static ImageIcon tm_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/tm.gif","top middle layout button");
  51.     public static ImageIcon tmdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/tmdn.gif","selected top middle layout button");
  52.     public static ImageIcon tr_dot   = SwingSet.sharedInstance().loadImageIcon("images/layout/tr.gif","top right layout button");
  53.     public static ImageIcon trdn_dot = SwingSet.sharedInstance().loadImageIcon("images/layout/trdn.gif","selected top right layout button");
  54.  
  55.     
  56.     /**
  57.      * A layout direction button
  58.      */
  59.     public DirectionButton(Icon icon, Icon downIcon, String direction,
  60.                String description, ActionListener l, 
  61.                ButtonGroup group, boolean selected)
  62.     {
  63.     super();
  64.     setSelected(selected);
  65.     this.addActionListener(l);
  66.     setFocusPainted(false);
  67.     setHorizontalTextPosition(CENTER);
  68.     group.add(this);
  69.     setIcon(icon);
  70.     setSelectedIcon(downIcon);
  71.     setActionCommand(direction);
  72.     getAccessibleContext().setAccessibleName(direction);
  73.     getAccessibleContext().setAccessibleDescription(description);
  74.     }
  75.  
  76.     public boolean isFocusTraversable() {
  77.         return false;
  78.     }
  79.  
  80.     public void setBorder(Border b) {
  81.     }
  82.  
  83.  
  84.     public static JPanel createDirectionPanel(boolean enable, String selected, ActionListener l) {
  85.     JPanel p = SwingSet.createVerticalPanel(false);
  86.     p.setAlignmentY(TOP_ALIGNMENT);
  87.     p.setAlignmentX(LEFT_ALIGNMENT);
  88.  
  89.     Box firstThree = Box.createHorizontalBox();
  90.     Box secondThree = Box.createHorizontalBox();
  91.     Box thirdThree = Box.createHorizontalBox();
  92.  
  93.     if(!enable) {
  94.         selected = "None";
  95.     }
  96.  
  97.     ButtonGroup group = new ButtonGroup();
  98.     DirectionButton b;
  99.     b = (DirectionButton) firstThree.add(new DirectionButton(  tl_dot, tldn_dot, "NW", "Sets the orientation to the North-West", l, group, selected.equals("NW")));
  100.     b.setEnabled(enable);
  101.     b = (DirectionButton) firstThree.add(new DirectionButton(  tm_dot, tmdn_dot, "N",  "Sets the orientation to the North", l, group, selected.equals("N")));
  102.     b.setEnabled(enable);
  103.     b = (DirectionButton) firstThree.add(new DirectionButton(  tr_dot, trdn_dot, "NE", "Sets the orientation to the North-East", l, group, selected.equals("NE")));
  104.     b.setEnabled(enable);
  105.     b = (DirectionButton) secondThree.add(new DirectionButton( ml_dot, mldn_dot, "W", "Sets the orientation to the West", l, group, selected.equals("W")));
  106.     b.setEnabled(enable);
  107.     b = (DirectionButton) secondThree.add(new DirectionButton( c_dot,  cdn_dot,  "C", "Sets the orientation to the Center", l, group, selected.equals("C")));
  108.     b.setEnabled(enable);
  109.     b = (DirectionButton) secondThree.add(new DirectionButton( mr_dot, mrdn_dot, "E", "Sets the orientation to the East", l, group, selected.equals("E")));
  110.     b.setEnabled(enable);
  111.     b = (DirectionButton) thirdThree.add(new DirectionButton(  bl_dot, bldn_dot, "SW", "Sets the orientation to the South-West", l, group, selected.equals("SW")));
  112.     b.setEnabled(enable);
  113.     b = (DirectionButton) thirdThree.add(new DirectionButton(  bm_dot, bmdn_dot, "S", "Sets the orientation to the South", l, group, selected.equals("S")));
  114.     b.setEnabled(enable);
  115.     b = (DirectionButton) thirdThree.add(new DirectionButton(  br_dot, brdn_dot, "SE", "Sets the orientation to the South-East", l, group, selected.equals("SE")));
  116.     b.setEnabled(enable);
  117.  
  118.     p.add(firstThree);
  119.     p.add(secondThree);
  120.     p.add(thirdThree);
  121.     
  122.     return p;
  123.     }
  124. }
  125.