home *** CD-ROM | disk | FTP | other *** search
/ Australian PC Authority 1999 May / may1999.iso / May / JBUILDER / JSAMPLES.Z / ComboBoxPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-30  |  5.4 KB  |  154 lines

  1. import com.sun.java.swing.BorderFactory;
  2. import com.sun.java.swing.Box;
  3. import com.sun.java.swing.BoxLayout;
  4. import com.sun.java.swing.DefaultListModel;
  5. import com.sun.java.swing.JComboBox;
  6. import com.sun.java.swing.JComponent;
  7. import com.sun.java.swing.JPanel;
  8. import com.sun.java.swing.tree.DefaultMutableTreeNode;
  9. import com.sun.java.swing.tree.DefaultTreeModel;
  10. import java.awt.Container;
  11. import java.awt.Dimension;
  12.  
  13. public class ComboBoxPanel extends JPanel {
  14.    SwingSet swing;
  15.    JComboBox months;
  16.    JComboBox days;
  17.    // $FF: renamed from: cb com.sun.java.swing.JComboBox
  18.    JComboBox field_0;
  19.    JComboBox cb1;
  20.    JComboBox custom;
  21.    JComboBox treeComboBox;
  22.    DefaultListModel model = new DefaultListModel();
  23.  
  24.    public ComboBoxPanel(SwingSet var1) {
  25.       this.swing = var1;
  26.       ((Container)this).setLayout(new BoxLayout(this, 1));
  27.       ((JComponent)this).setBorder(SwingSet.emptyBorder5);
  28.       ((Container)this).add(Box.createRigidArea(new Dimension(1, 50)));
  29.       JPanel var3 = new JPanel(false);
  30.       ((Container)var3).setLayout(new BoxLayout(var3, 0));
  31.       ((Container)this).add(var3);
  32.       JPanel var2 = new JPanel();
  33.       ((JComponent)var2).setMaximumSize(new Dimension(32767, 100));
  34.       ((JComponent)var2).setBorder(BorderFactory.createTitledBorder("Classic ComboBox"));
  35.       ((Container)var2).setLayout(new BoxLayout(var2, 0));
  36.       ((Container)var2).add(Box.createRigidArea(new Dimension(5, 1)));
  37.       this.months = new JComboBox();
  38.       this.months.addItem("January");
  39.       this.months.addItem("February");
  40.       this.months.addItem("March");
  41.       this.months.addItem("April");
  42.       this.months.addItem("May");
  43.       this.months.addItem("June");
  44.       this.months.addItem("July");
  45.       this.months.addItem("August");
  46.       this.months.addItem("September");
  47.       this.months.addItem("October");
  48.       this.months.addItem("November");
  49.       this.months.addItem("December");
  50.       this.months.getAccessibleContext().setAccessibleName("Months");
  51.       this.months.getAccessibleContext().setAccessibleDescription("Choose a month of the year");
  52.       ((Container)var2).add(this.months);
  53.       ((Container)var2).add(Box.createRigidArea(new Dimension(5, 1)));
  54.       this.days = new JComboBox();
  55.       this.days.addItem("Monday");
  56.       this.days.addItem("Tuesday");
  57.       this.days.addItem("Wednesday");
  58.       this.days.addItem("Thursday");
  59.       this.days.addItem("Friday");
  60.       this.days.addItem("Saturday");
  61.       this.days.addItem("Sunday");
  62.       this.days.getAccessibleContext().setAccessibleName("Days");
  63.       this.days.getAccessibleContext().setAccessibleDescription("Choose a day of the week");
  64.       ((Container)var2).add(this.days);
  65.       ((Container)var2).add(Box.createRigidArea(new Dimension(5, 1)));
  66.       ((Container)var3).add(var2);
  67.       ((Container)this).add(var3);
  68.       var2 = new JPanel();
  69.       ((JComponent)var2).setMaximumSize(new Dimension(32767, 100));
  70.       ((JComponent)var2).setBorder(BorderFactory.createTitledBorder("Editable ComboBox"));
  71.       ((Container)var2).setLayout(new BoxLayout(var2, 0));
  72.       ((Container)var2).add(Box.createRigidArea(new Dimension(5, 1)));
  73.       this.field_0 = new JComboBox();
  74.       this.field_0.setEditable(true);
  75.       this.field_0.addItem("0");
  76.       this.field_0.addItem("10");
  77.       this.field_0.addItem("20");
  78.       this.field_0.addItem("30");
  79.       this.field_0.addItem("40");
  80.       this.field_0.addItem("50");
  81.       this.field_0.addItem("60");
  82.       this.field_0.addItem("70");
  83.       this.field_0.addItem("80");
  84.       this.field_0.addItem("90");
  85.       this.field_0.addItem("100");
  86.       this.field_0.addItem("More");
  87.       this.field_0.getAccessibleContext().setAccessibleName("Numbers");
  88.       this.field_0.getAccessibleContext().setAccessibleDescription("Demonstration editable ComboBox with numbers 0-100");
  89.       this.field_0.setSelectedItem("50");
  90.       ((Container)var2).add(this.field_0);
  91.       ((Container)var2).add(Box.createRigidArea(new Dimension(5, 1)));
  92.       this.cb1 = new JComboBox();
  93.       this.cb1.setEditable(true);
  94.       this.cb1.addItem("0");
  95.       this.cb1.addItem(".25");
  96.       this.cb1.addItem(".5");
  97.       this.cb1.addItem(".75");
  98.       this.cb1.addItem("1.0");
  99.       this.cb1.getAccessibleContext().setAccessibleName("Small numbers");
  100.       this.cb1.getAccessibleContext().setAccessibleDescription("Demonstration editable ComboBox with numbers 0-1");
  101.       this.cb1.setSelectedItem(".5");
  102.       ((Container)var2).add(this.cb1);
  103.       ((Container)var2).add(Box.createRigidArea(new Dimension(5, 1)));
  104.       ((Container)var3).add(var2);
  105.       var3 = new JPanel(false);
  106.       ((Container)var3).setLayout(new BoxLayout(var3, 0));
  107.       ((Container)this).add(var3);
  108.       var2 = new JPanel();
  109.       ((JComponent)var2).setMaximumSize(new Dimension(32767, 200));
  110.       ((JComponent)var2).setBorder(BorderFactory.createTitledBorder("Custom ComboBox"));
  111.       ((Container)var2).setLayout(new BoxLayout(var2, 0));
  112.       ((Container)var2).add(Box.createRigidArea(new Dimension(5, 1)));
  113.       this.custom = new ComboBoxPanel$CustomComboBox(new ComboBoxPanel$CustomComboBoxModel(this));
  114.       this.custom.setRenderer(new ComboBoxPanel$TestCellRenderer(this, this.custom));
  115.       ((ComboBoxPanel$CustomComboBox)this.custom).setCanChangeRenderer(false);
  116.       this.custom.setSelectedIndex(0);
  117.       this.custom.setMaximumRowCount(4);
  118.       this.custom.getAccessibleContext().setAccessibleName("Custom ComboBox");
  119.       this.custom.getAccessibleContext().setAccessibleDescription("Sample custom ComboBox with icons in them, one of which changes when selected");
  120.       ((Container)var2).add(this.custom);
  121.       ((Container)var2).add(Box.createRigidArea(new Dimension(5, 1)));
  122.       DefaultMutableTreeNode var4 = new DefaultMutableTreeNode("Swing");
  123.       DefaultMutableTreeNode var5 = new DefaultMutableTreeNode("spec");
  124.       DefaultMutableTreeNode var6 = new DefaultMutableTreeNode("api");
  125.       var4.add(var5);
  126.       var4.add(var6);
  127.       var6.add(new DefaultMutableTreeNode("JComponent"));
  128.       var6.add(new DefaultMutableTreeNode("JTable"));
  129.       var6.add(new DefaultMutableTreeNode("JTree"));
  130.       var6.add(new DefaultMutableTreeNode("JComboBox"));
  131.       var6.add(new DefaultMutableTreeNode("JTextComponent"));
  132.       var5.add(new DefaultMutableTreeNode("JComponent"));
  133.       var5.add(new DefaultMutableTreeNode("JTable"));
  134.       var5.add(new DefaultMutableTreeNode("JTree"));
  135.       var5.add(new DefaultMutableTreeNode("JComboBox"));
  136.       var5.add(new DefaultMutableTreeNode("JTextComponent"));
  137.       this.treeComboBox = new TreeCombo(new DefaultTreeModel(var4));
  138.       this.treeComboBox.getAccessibleContext().setAccessibleName("Swing specs and APIs");
  139.       this.treeComboBox.getAccessibleContext().setAccessibleDescription("Sample custom ComboBox with a tree heirarchy");
  140.       ((Container)var2).add(this.treeComboBox);
  141.       ((Container)var2).add(Box.createRigidArea(new Dimension(5, 1)));
  142.       ((Container)var3).add(var2);
  143.    }
  144.  
  145.    public void hideAllPopups() {
  146.       this.months.getUI().hidePopup();
  147.       this.days.getUI().hidePopup();
  148.       this.field_0.getUI().hidePopup();
  149.       this.cb1.getUI().hidePopup();
  150.       this.custom.getUI().hidePopup();
  151.       this.treeComboBox.getUI().hidePopup();
  152.    }
  153. }
  154.