1 6 7 package org.coach.tracing.server.viewer; 8 9 import javax.swing.*; 10 11 15 public class TrailLabelDialog extends javax.swing.JDialog { 16 private JColorChooser colorChooser = new JColorChooser(); 17 private TrailLabelData[] labels; 18 private JCheckBox[] checkBoxes; 19 private JButton[] buttons; 20 21 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 (labels.length, 1)); 29 30 addWindowListener(new java.awt.event.WindowAdapter () { 31 public void windowClosing(java.awt.event.WindowEvent evt) { 32 closeDialog(evt); 33 } 34 }); 35 36 for (int i = 0; i < labels.length; i++) { 37 JPanel panel = new javax.swing.JPanel (); 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 () { 45 public void actionPerformed(java.awt.event.ActionEvent 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 evt) { 67 JButton button = (JButton)evt.getSource(); 68 button.setBackground(colorChooser.showDialog(button, "Select trail color", button.getBackground())); 69 } 70 71 72 private void closeDialog(java.awt.event.WindowEvent evt) { 73 setVisible(false); 74 dispose(); 75 } 76 } 77 | Popular Tags |