KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > tracing > server > viewer > TrailLabelDialog


1 /*
2  * TrailLabelDialog.java
3  *
4  * Created on March 5, 2003, 12:39 PM
5  */

6
7 package org.coach.tracing.server.viewer;
8
9 import javax.swing.*;
10
11 /**
12  *
13  * @author batteram
14  */

15 public class TrailLabelDialog extends javax.swing.JDialog JavaDoc {
16     private JColorChooser colorChooser = new JColorChooser();
17     private TrailLabelData[] labels;
18     private JCheckBox[] checkBoxes;
19     private JButton[] buttons;
20     
21     /** Creates new form TrailLabelDialog */
22     public TrailLabelDialog(JFrame frame, TrailLabelData[] labels) {
23         super(frame, true);
24         this.labels = labels;
25         checkBoxes = new JCheckBox[labels.length];
26         buttons = new JButton[labels.length];
27
28         getContentPane().setLayout(new java.awt.GridLayout JavaDoc(labels.length, 1));
29
30         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
31             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
32                 closeDialog(evt);
33             }
34         });
35
36         for (int i = 0; i < labels.length; i++) {
37             JPanel panel = new javax.swing.JPanel JavaDoc();
38             checkBoxes[i] = new JCheckBox();
39             checkBoxes[i].setText(labels[i].name);
40             checkBoxes[i].setSelected(labels[i].active);
41             buttons[i] = new JButton();
42             buttons[i].setText("color");
43             buttons[i].setBackground(labels[i].color);
44             buttons[i].addActionListener(new java.awt.event.ActionListener JavaDoc() {
45                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
46                     buttonActionPerformed(evt);
47                 }
48             });
49             panel.add(checkBoxes[i]);
50             panel.add(buttons[i]);
51             getContentPane().add(panel);
52         }
53         setLocationRelativeTo(frame);
54         pack();
55         setVisible(true);
56     }
57     
58     public TrailLabelData[] getTrailLabelData() {
59         for (int i = 0; i < labels.length; i++) {
60             labels[i].active = checkBoxes[i].isSelected();
61             labels[i].color = buttons[i].getBackground();
62         }
63         return labels;
64     }
65
66     private void buttonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
67         JButton button = (JButton)evt.getSource();
68         button.setBackground(colorChooser.showDialog(button, "Select trail color", button.getBackground()));
69     }
70     
71     /** Closes the dialog */
72     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt) {
73         setVisible(false);
74         dispose();
75     }
76 }
77
Popular Tags