1 package org.xpilot.jxpmap; 2 3 import java.awt.Color; 4 import java.awt.GridLayout; 5 import java.awt.event.ActionEvent; 6 import java.awt.event.ActionListener; 7 8 import javax.swing.JButton; 9 import javax.swing.JCheckBox; 10 import javax.swing.JColorChooser; 11 import javax.swing.JComboBox; 12 import javax.swing.JLabel; 13 import javax.swing.JOptionPane; 14 import javax.swing.JTextField; 15 16 public class EdgeStyleEditor extends EditorPanel implements ActionListener { 17 18 private JComboBox cmbStyle; 19 private JComboBox cmbWidth; 20 private JButton bColor; 21 private JCheckBox cbVisible; 22 private JCheckBox cbVisibleInRadar; 23 private JTextField tfName; 24 25 private LineStyle style; 26 private MapCanvas canvas; 27 private MapModel model; 28 private boolean isNew; 29 30 EdgeStyleEditor(LineStyle style, MapCanvas canvas, boolean isNew)31 public EdgeStyleEditor (LineStyle style, 32 MapCanvas canvas, 33 boolean isNew) { 34 35 this.style = style; 36 this.canvas = canvas; 37 this.isNew = isNew; 38 this.model = canvas.getModel(); 39 40 setTitle("Edge Style"); 41 setLayout(new GridLayout(4, 2)); 42 43 add(new JLabel("Name:")); 44 tfName = new JTextField(); 45 if (style.getId() != null) tfName.setText(style.getId()); 46 add(tfName); 47 48 add(new JLabel("Style:")); 49 cmbStyle = new JComboBox(); 50 cmbStyle.addItem("Solid"); 51 cmbStyle.addItem("Dashed"); 52 cmbStyle.addItem("Double Dashed"); 53 cmbStyle.addItem("Hidden"); 54 cmbStyle.setSelectedIndex(style.getStyle()); 55 add(cmbStyle); 56 57 add(new JLabel("Width:")); 58 cmbWidth = new JComboBox(); 59 for (int i = 0; i < 6; i++) 60 cmbWidth.addItem(String.valueOf(i)); 61 cmbWidth.setSelectedIndex(style.getWidth()); 62 add(cmbWidth); 63 64 add(new JLabel("Color:")); 65 bColor = new JButton(); 66 bColor.addActionListener(this); 67 Color c = style.getColor(); 68 if (c == null) c = Color.black; 69 bColor.setBackground(c); 70 add(bColor); 71 } 72 73 apply()74 public boolean apply () { 75 76 if (tfName.getText() == null || tfName.getText().length() == 0) { 77 JOptionPane.showMessageDialog 78 (this, "First specify a name for this style.", 79 "Information", JOptionPane.INFORMATION_MESSAGE); 80 return false; 81 } 82 if (isNew) { 83 style.setId(tfName.getText()); 84 style.setStyle(cmbStyle.getSelectedIndex()); 85 style.setWidth(cmbWidth.getSelectedIndex()); 86 style.setColor(bColor.getBackground()); 87 } else { 88 canvas.setEdgeStyleProperties 89 (style, 90 tfName.getText(), 91 cmbStyle.getSelectedIndex(), 92 cmbWidth.getSelectedIndex(), 93 bColor.getBackground()); 94 } 95 return true; 96 } 97 98 actionPerformed(ActionEvent evt)99 public void actionPerformed (ActionEvent evt) { 100 if (evt.getSource() == bColor) { 101 Color c = JColorChooser.showDialog 102 (this, "Pick a color", Color.black); 103 if (c != null) bColor.setBackground(c); 104 } 105 } 106 } 107