source: osm/applications/editors/josm/plugins/smed/plugs/oseam/src/oseam/panels/PanelChan.java@ 24872

Last change on this file since 24872 was 24872, checked in by malcolmh, 14 years ago

save

File size: 6.4 KB
Line 
1package oseam.panels;
2
3import javax.swing.BorderFactory;
4import javax.swing.JPanel;
5
6import java.awt.Color;
7import java.awt.Rectangle;
8
9import javax.swing.ButtonGroup;
10import javax.swing.ImageIcon;
11import javax.swing.JRadioButton;
12
13import oseam.Messages;
14import oseam.dialogs.OSeaMAction;
15import oseam.panels.PanelPort;
16import oseam.panels.PanelStbd;
17import oseam.panels.PanelPrefPort;
18import oseam.panels.PanelPrefStbd;
19import oseam.seamarks.SeaMark;
20import oseam.seamarks.SeaMark.Cat;
21import oseam.seamarks.SeaMark.Col;
22import oseam.seamarks.MarkLat;
23import oseam.seamarks.MarkSaw;
24
25import java.awt.event.ActionListener;
26
27public class PanelChan extends JPanel {
28
29 private OSeaMAction dlg;
30 private ButtonGroup catButtons = new ButtonGroup();
31 public JRadioButton portButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PortButton.png")));
32 public JRadioButton stbdButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/StbdButton.png")));
33 public JRadioButton prefPortButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PrefPortButton.png")));
34 public JRadioButton prefStbdButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PrefStbdButton.png")));
35 public JRadioButton safeWaterButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SafeWaterButton.png")));
36 private ActionListener alCat = new ActionListener() {
37 public void actionPerformed(java.awt.event.ActionEvent e) {
38 if (portButton.isSelected()) {
39 if (!(dlg.mark instanceof MarkLat) || (dlg.mark.getCategory() != Cat.LAT_PORT))
40 dlg.mark = new MarkLat(dlg);
41 dlg.mark.setCategory(Cat.LAT_PORT);
42 if (dlg.mark.getRegion() == SeaMark.IALA_A) {
43 dlg.mark.setColour(Col.RED);
44 panelPort.regionAButton.doClick();
45 } else {
46 dlg.mark.setColour(Col.GREEN);
47 panelPort.regionBButton.doClick();
48 }
49 portButton.setBorderPainted(true);
50 panelPort.setVisible(true);
51 } else {
52 portButton.setBorderPainted(false);
53 panelPort.setVisible(false);
54 panelPort.clearSelections();
55 }
56 if (stbdButton.isSelected()) {
57 if (!(dlg.mark instanceof MarkLat) || (dlg.mark.getCategory() != Cat.LAT_STBD))
58 dlg.mark = new MarkLat(dlg);
59 dlg.mark.setCategory(Cat.LAT_STBD);
60 if (dlg.mark.getRegion() == SeaMark.IALA_A) {
61 dlg.mark.setColour(Col.GREEN);
62 panelStbd.regionAButton.doClick();
63 } else {
64 dlg.mark.setColour(Col.RED);
65 panelStbd.regionBButton.doClick();
66 }
67 stbdButton.setBorderPainted(true);
68 panelStbd.setVisible(true);
69 } else {
70 stbdButton.setBorderPainted(false);
71 panelStbd.setVisible(false);
72 panelStbd.clearSelections();
73 }
74 if (prefPortButton.isSelected()) {
75 if (!(dlg.mark instanceof MarkLat) || (dlg.mark.getCategory() != Cat.LAT_PREF_PORT))
76 dlg.mark = new MarkLat(dlg);
77 dlg.mark.setCategory(Cat.LAT_PREF_PORT);
78 if (dlg.mark.getRegion() == SeaMark.IALA_A) {
79 dlg.mark.setColour(Col.RED_GREEN_RED);
80 panelPrefPort.regionAButton.doClick();
81 } else {
82 dlg.mark.setColour(Col.GREEN_RED_GREEN);
83 panelPrefPort.regionBButton.doClick();
84 }
85 prefPortButton.setBorderPainted(true);
86 panelPrefPort.setVisible(true);
87 } else {
88 prefPortButton.setBorderPainted(false);
89 panelPrefPort.setVisible(false);
90 panelPrefPort.clearSelections();
91 }
92 if (prefStbdButton.isSelected()) {
93 if (!(dlg.mark instanceof MarkLat) || (dlg.mark.getCategory() != Cat.LAT_PREF_STBD))
94 dlg.mark = new MarkLat(dlg);
95 dlg.mark.setCategory(Cat.LAT_PREF_STBD);
96 if (dlg.mark.getRegion() == SeaMark.IALA_A) {
97 dlg.mark.setColour(Col.GREEN_RED_GREEN);
98 panelPrefStbd.regionAButton.doClick();
99 } else {
100 dlg.mark.setColour(Col.RED_GREEN_RED);
101 panelPrefStbd.regionBButton.doClick();
102 }
103 prefStbdButton.setBorderPainted(true);
104 panelPrefStbd.setVisible(true);
105 } else {
106 prefStbdButton.setBorderPainted(false);
107 panelPrefStbd.setVisible(false);
108 panelPrefStbd.clearSelections();
109 }
110 if (safeWaterButton.isSelected()) {
111 if (!(dlg.mark instanceof MarkSaw))
112 dlg.mark = new MarkSaw(dlg);
113 dlg.mark.setColour(Col.RED_WHITE);
114 safeWaterButton.setBorderPainted(true);
115 panelSafeWater.setVisible(true);
116 } else {
117 safeWaterButton.setBorderPainted(false);
118 panelSafeWater.setVisible(false);
119 panelSafeWater.clearSelections();
120 }
121 if (dlg.mark != null)
122 dlg.mark.paintSign();
123 }
124 };
125
126 public PanelPort panelPort = null;
127 public PanelStbd panelStbd = null;
128 public PanelPrefPort panelPrefPort = null;
129 public PanelPrefStbd panelPrefStbd = null;
130 public PanelSafeWater panelSafeWater = null;
131
132 public PanelChan(OSeaMAction dia) {
133 dlg = dia;
134 panelPort = new PanelPort(dlg);
135 panelPort.setBounds(new Rectangle(55, 0, 225, 160));
136 panelPort.setVisible(false);
137 panelStbd = new PanelStbd(dlg);
138 panelStbd.setBounds(new Rectangle(55, 0, 225, 160));
139 panelStbd.setVisible(false);
140 panelPrefPort = new PanelPrefPort(dlg);
141 panelPrefPort.setBounds(new Rectangle(55, 0, 225, 160));
142 panelPrefPort.setVisible(false);
143 panelPrefStbd = new PanelPrefStbd(dlg);
144 panelPrefStbd.setBounds(new Rectangle(55, 0, 225, 160));
145 panelPrefStbd.setVisible(false);
146 panelSafeWater = new PanelSafeWater(dlg);
147 panelSafeWater.setBounds(new Rectangle(55, 0, 225, 160));
148 panelSafeWater.setVisible(false);
149 this.setLayout(null);
150 this.add(panelPort, null);
151 this.add(panelStbd, null);
152 this.add(panelPrefPort, null);
153 this.add(panelPrefStbd, null);
154 this.add(panelSafeWater, null);
155 this.add(getCatButton(portButton, 0, 0, 52, 32, "PortTip"), null);
156 this.add(getCatButton(stbdButton, 0, 32, 52, 32, "StbdTip"), null);
157 this.add(getCatButton(prefPortButton, 0, 64, 52, 32, "PrefPortTip"), null);
158 this.add(getCatButton(prefStbdButton, 0, 96, 52, 32, "PrefStbdTip"), null);
159 this.add(getCatButton(safeWaterButton, 0, 128, 52, 32, "SafeWaterTip"), null);
160 }
161
162 public void clearSelections() {
163 catButtons.clearSelection();
164 alCat.actionPerformed(null);
165 panelPort.clearSelections();
166 panelStbd.clearSelections();
167 panelPrefPort.clearSelections();
168 panelPrefStbd.clearSelections();
169 panelSafeWater.clearSelections();
170 }
171
172 private JRadioButton getCatButton(JRadioButton button, int x, int y, int w, int h, String tip) {
173 button.setBounds(new Rectangle(x, y, w, h));
174 button.setBorder(BorderFactory.createLineBorder(Color.magenta, 2));
175 button.setToolTipText(Messages.getString(tip));
176 button.addActionListener(alCat);
177 catButtons.add(button);
178 return button;
179 }
180
181}
Note: See TracBrowser for help on using the repository browser.