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

  1. import com.sun.java.swing.Box;
  2. import com.sun.java.swing.BoxLayout;
  3. import com.sun.java.swing.ButtonGroup;
  4. import com.sun.java.swing.DefaultListModel;
  5. import com.sun.java.swing.ImageIcon;
  6. import com.sun.java.swing.JButton;
  7. import com.sun.java.swing.JCheckBox;
  8. import com.sun.java.swing.JComponent;
  9. import com.sun.java.swing.JLabel;
  10. import com.sun.java.swing.JList;
  11. import com.sun.java.swing.JPanel;
  12. import com.sun.java.swing.JRadioButton;
  13. import com.sun.java.swing.JScrollPane;
  14. import java.awt.Container;
  15.  
  16. public class ListPanel extends JPanel {
  17.    int fastfoodIndex;
  18.    int dessertIndex;
  19.    int fruitIndex;
  20.    int veggieIndex;
  21.    boolean fastfoodShown;
  22.    boolean dessertShown;
  23.    boolean fruitShown;
  24.    boolean veggieShown;
  25.    public ImageIcon burger = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/burger.gif", "burger");
  26.    public ImageIcon fries = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/fries.gif", "fries");
  27.    public ImageIcon softdrink = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/softdrink.gif", "soft drink");
  28.    public ImageIcon hotdog = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/hotdog.gif", "hot dog");
  29.    public ImageIcon pizza = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/pizza.gif", "pizza");
  30.    public ImageIcon icecream = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/icecream.gif", "ice cream");
  31.    public ImageIcon pie = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/pie.gif", "pie");
  32.    public ImageIcon cake = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/cake.gif", "cake");
  33.    public ImageIcon donut = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/donut.gif", "donut");
  34.    public ImageIcon treat = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/treat.gif", "treat");
  35.    public ImageIcon grapes = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/grapes.gif", "grapes");
  36.    public ImageIcon banana = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/banana.gif", "banana");
  37.    public ImageIcon watermelon = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/watermelon.gif", "watermelon");
  38.    public ImageIcon cantaloupe = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/cantaloupe.gif", "cantaloupe");
  39.    public ImageIcon peach = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/peach.gif", "peach");
  40.    public ImageIcon broccoli = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/broccoli.gif", "broccoli");
  41.    public ImageIcon carrot = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/carrot.gif", "carrot");
  42.    public ImageIcon peas = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/peas.gif", "peas");
  43.    public ImageIcon corn = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/corn.gif", "corn");
  44.    public ImageIcon radish = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/food/radish.gif", "radish");
  45.    SwingSet swing;
  46.    JList listBox;
  47.    JScrollPane scrollPane;
  48.    DefaultListModel model = new DefaultListModel();
  49.    JLabel priceLabel;
  50.    int listPrice;
  51.    JButton reset;
  52.    JButton purchase;
  53.    JRadioButton dessertRadioButton;
  54.    JRadioButton veggieRadioButton;
  55.    JRadioButton fruitRadioButton;
  56.    JRadioButton fastfoodRadioButton;
  57.    JCheckBox dessertCheckbox;
  58.    JCheckBox veggieCheckbox;
  59.    JCheckBox fruitCheckbox;
  60.    JCheckBox fastfoodCheckbox;
  61.    static int ITEMS = 20;
  62.    ImageIcon[] images;
  63.    String[] desc;
  64.    int[] price;
  65.  
  66.    public ListPanel(SwingSet var1) {
  67.       this.swing = var1;
  68.       ((JComponent)this).setBorder(SwingSet.emptyBorder5);
  69.       ((Container)this).setLayout(new BoxLayout(this, 0));
  70.  
  71.       for(int var2 = 0; var2 < ITEMS; ++var2) {
  72.          this.model.addElement(new Integer(var2));
  73.       }
  74.  
  75.       this.listBox = new ListPanel$1(this.model);
  76.       this.listBox.setCellRenderer(new ListPanel$TestCellRenderer(this, this.listBox));
  77.       ListPanel$2 var3 = new ListPanel$2();
  78.       ((Container)var3).setLayout(new BoxLayout(var3, 1));
  79.       ((JComponent)var3).setBorder(SwingSet.loweredBorder);
  80.       ((JComponent)var3).setAlignmentY(0.0F);
  81.       JPanel var4 = SwingSet.createHorizontalPanel(false);
  82.       ((JComponent)var4).setAlignmentY(0.0F);
  83.       ((JComponent)var4).setAlignmentX(0.0F);
  84.       ((Container)var3).add(var4);
  85.       this.purchase = new JButton("Purchase");
  86.       this.purchase.setToolTipText("Adds the selected item(s) to your grocery bill.");
  87.       ((Container)var4).add(this.purchase);
  88.       ((Container)var4).add(Box.createRigidArea(SwingSet.hpad10));
  89.       this.priceLabel = new JLabel("Total:                           ");
  90.       ((Container)var4).add(this.priceLabel);
  91.       ((Container)var3).add(Box.createRigidArea(SwingSet.vpad20));
  92.       JLabel var5 = new JLabel("Jump To:");
  93.       var5.setFont(var1.boldFont);
  94.       ((Container)var3).add(var5);
  95.       ButtonGroup var6 = new ButtonGroup();
  96.       this.fastfoodRadioButton = new JRadioButton("Fast Food");
  97.       this.fastfoodRadioButton.setToolTipText("Calls list.ensureVisible() to jump to the items.");
  98.       var6.add(this.fastfoodRadioButton);
  99.       ((Container)var3).add(this.fastfoodRadioButton);
  100.       this.dessertRadioButton = new JRadioButton("Desserts");
  101.       this.dessertRadioButton.setToolTipText("Calls list.ensureVisible() to jump to the items.");
  102.       var6.add(this.dessertRadioButton);
  103.       ((Container)var3).add(this.dessertRadioButton);
  104.       this.fruitRadioButton = new JRadioButton("Fruits");
  105.       this.fruitRadioButton.setToolTipText("Calls list.ensureVisible() to jump to the items.");
  106.       var6.add(this.fruitRadioButton);
  107.       ((Container)var3).add(this.fruitRadioButton);
  108.       this.veggieRadioButton = new JRadioButton("Vegetables");
  109.       this.veggieRadioButton.setToolTipText("Calls list.ensureVisible(index) to jump to the items.");
  110.       var6.add(this.veggieRadioButton);
  111.       ((Container)var3).add(this.veggieRadioButton);
  112.       ((Container)var3).add(Box.createRigidArea(SwingSet.vpad20));
  113.       var5 = new JLabel("Show:");
  114.       var5.setFont(var1.boldFont);
  115.       ((Container)var3).add(var5);
  116.       this.fastfoodCheckbox = new JCheckBox("Fast Food");
  117.       this.fastfoodCheckbox.setToolTipText("Calls list.remove(index1,indexN) to remove items.");
  118.       this.fastfoodCheckbox.setSelected(true);
  119.       ((Container)var3).add(this.fastfoodCheckbox);
  120.       this.dessertCheckbox = new JCheckBox("Desserts");
  121.       this.dessertCheckbox.setToolTipText("Calls list.remove(index1,indexN) to remove items.");
  122.       this.dessertCheckbox.setSelected(true);
  123.       ((Container)var3).add(this.dessertCheckbox);
  124.       this.fruitCheckbox = new JCheckBox("Fruits");
  125.       this.fruitCheckbox.setToolTipText("Calls list.remove(index1,indexN) to remove items.");
  126.       this.fruitCheckbox.setSelected(true);
  127.       ((Container)var3).add(this.fruitCheckbox);
  128.       this.veggieCheckbox = new JCheckBox("Vegetables");
  129.       this.veggieCheckbox.setToolTipText("Calls list.remove(index1,indexN) to remove items.");
  130.       this.veggieCheckbox.setSelected(true);
  131.       ((Container)var3).add(this.veggieCheckbox);
  132.       ((Container)var3).add(Box.createGlue());
  133.       this.reset = new JButton("Reset");
  134.       this.reset.setToolTipText("Resets the state of the demo.");
  135.       ((Container)var3).add(this.reset);
  136.       this.scrollPane = new JScrollPane(this.listBox);
  137.       this.scrollPane.setAlignmentX(0.0F);
  138.       this.scrollPane.setAlignmentY(0.0F);
  139.       ((Container)this).add(this.scrollPane);
  140.       ((Container)this).add(Box.createRigidArea(SwingSet.hpad10));
  141.       ((Container)this).add(var3);
  142.       ListPanel$3 var7 = new ListPanel$3(this);
  143.       this.purchase.addActionListener(var7);
  144.       ListPanel$4 var8 = new ListPanel$4(this);
  145.       this.fruitCheckbox.addActionListener(var8);
  146.       this.veggieCheckbox.addActionListener(var8);
  147.       this.dessertCheckbox.addActionListener(var8);
  148.       this.fastfoodCheckbox.addActionListener(var8);
  149.       ListPanel$5 var9 = new ListPanel$5(this);
  150.       this.fruitRadioButton.addActionListener(var9);
  151.       this.veggieRadioButton.addActionListener(var9);
  152.       this.dessertRadioButton.addActionListener(var9);
  153.       this.fastfoodRadioButton.addActionListener(var9);
  154.       ListPanel$6 var10 = new ListPanel$6(this);
  155.       this.reset.addActionListener(var10);
  156.    }
  157.  
  158.    public void resetAll() {
  159.       this.model.removeAllElements();
  160.       this.fastfoodCheckbox.setSelected(true);
  161.       this.fruitCheckbox.setSelected(true);
  162.       this.veggieCheckbox.setSelected(true);
  163.       this.dessertCheckbox.setSelected(true);
  164.       this.fastfoodRadioButton.setEnabled(true);
  165.       this.fruitRadioButton.setEnabled(true);
  166.       this.veggieRadioButton.setEnabled(true);
  167.       this.dessertRadioButton.setEnabled(true);
  168.       this.fastfoodRadioButton.setSelected(true);
  169.  
  170.       for(int var1 = 0; var1 < ITEMS; ++var1) {
  171.          this.model.addElement(new Integer(var1));
  172.       }
  173.  
  174.       this.fastfoodShown = true;
  175.       this.dessertShown = true;
  176.       this.fruitShown = true;
  177.       this.veggieShown = true;
  178.       this.fastfoodIndex = 0;
  179.       this.dessertIndex = 5;
  180.       this.fruitIndex = 10;
  181.       this.veggieIndex = 15;
  182.       this.listPrice = 0;
  183.       this.priceLabel.setText("Total:  $0.00   ");
  184.       this.listBox.ensureIndexIsVisible(this.fastfoodIndex);
  185.       this.scrollPane.validate();
  186.    }
  187. }
  188.