source: osm/applications/editors/josm/plugins/smed/src/panels/PanelTop.java@ 32767

Last change on this file since 32767 was 32767, checked in by donvip, 9 years ago

code style

File size: 5.6 KB
Line 
1package panels;
2
3import java.awt.Rectangle;
4import java.awt.event.ActionEvent;
5import java.awt.event.ActionListener;
6import java.util.EnumMap;
7
8import javax.swing.BorderFactory;
9import javax.swing.ButtonGroup;
10import javax.swing.ImageIcon;
11import javax.swing.JPanel;
12import javax.swing.JRadioButton;
13
14import messages.Messages;
15import seamarks.SeaMark.Ent;
16import seamarks.SeaMark.Top;
17import smed.SmedAction;
18
19public class PanelTop extends JPanel {
20
21 private SmedAction dlg;
22 public PanelPat panelPat = null;
23 private ButtonGroup topButtons = new ButtonGroup();
24 public JRadioButton noTopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/OffButton.png")));
25 public JRadioButton canTopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CanTopButton.png")));
26 public JRadioButton coneTopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/ConeTopButton.png")));
27 public JRadioButton sphereTopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereTopButton.png")));
28 public JRadioButton XTopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/XTopButton.png")));
29 public JRadioButton northTopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/NorthTopButton.png")));
30 public JRadioButton southTopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SouthTopButton.png")));
31 public JRadioButton eastTopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/EastTopButton.png")));
32 public JRadioButton westTopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/WestTopButton.png")));
33 public JRadioButton spheres2TopButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/Spheres2TopButton.png")));
34 public JRadioButton boardDayButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BoardDayButton.png")));
35 public JRadioButton rhombusDayButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/DiamondDayButton.png")));
36 public JRadioButton triangleDayButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TriangleDayButton.png")));
37 public JRadioButton triangleInvDayButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TriangleInvDayButton.png")));
38 public JRadioButton squareDayButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SquareDayButton.png")));
39 public JRadioButton circleDayButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CircleDayButton.png")));
40 private EnumMap<Top, JRadioButton> tops = new EnumMap<>(Top.class);
41 private ActionListener alTop = new ActionListener() {
42 @Override
43 public void actionPerformed(ActionEvent e) {
44 for (Top top : tops.keySet()) {
45 JRadioButton button = tops.get(top);
46 if (button.isSelected()) {
47 SmedAction.panelMain.mark.setTopmark(top);
48 button.setBorderPainted(true);
49 } else {
50 button.setBorderPainted(false);
51 }
52 }
53 }
54 };
55
56 public PanelTop(SmedAction dia) {
57 dlg = dia;
58 setLayout(null);
59 panelPat = new PanelPat(dlg, Ent.TOPMARK);
60 panelPat.setBounds(new Rectangle(160, 0, 110, 160));
61 add(panelPat);
62 add(getTopButton(noTopButton, 0, 5, 27, 27, "NoTop", Top.NOTOP));
63 add(getTopButton(canTopButton, 30, 5, 27, 27, "CanTop", Top.CYL));
64 add(getTopButton(coneTopButton, 60, 5, 27, 27, "ConeTop", Top.CONE));
65 add(getTopButton(sphereTopButton, 90, 5, 27, 27, "SphereTop", Top.SPHERE));
66 add(getTopButton(XTopButton, 120, 5, 27, 27, "XTop", Top.X_SHAPE));
67 add(getTopButton(northTopButton, 0, 35, 27, 27, "NorthTop", Top.NORTH));
68 add(getTopButton(southTopButton, 30, 35, 27, 27, "SouthTop", Top.SOUTH));
69 add(getTopButton(eastTopButton, 60, 35, 27, 27, "EastTop", Top.EAST));
70 add(getTopButton(westTopButton, 90, 35, 27, 27, "WestTop", Top.WEST));
71 add(getTopButton(spheres2TopButton, 120, 35, 27, 27, "Spheres2Top", Top.SPHERES2));
72 add(getTopButton(boardDayButton, 0, 65, 27, 27, "BoardDay", Top.BOARD));
73 add(getTopButton(rhombusDayButton, 30, 65, 27, 27, "DiamondDay", Top.RHOMBUS));
74 add(getTopButton(triangleDayButton, 60, 65, 27, 27, "TriangleDay", Top.TRIANGLE));
75 add(getTopButton(triangleInvDayButton, 90, 65, 27, 27, "TriangleInvDay", Top.TRIANGLE_INV));
76 add(getTopButton(squareDayButton, 120, 65, 27, 27, "SquareDay", Top.SQUARE));
77 add(getTopButton(circleDayButton, 120, 95, 27, 27, "CircleDay", Top.CIRCLE));
78 }
79
80 public void enableAll(boolean state) {
81 for (JRadioButton button : tops.values()) {
82 button.setEnabled(state);
83 }
84 }
85
86 public void syncPanel() {
87 for (Top top : tops.keySet()) {
88 JRadioButton button = tops.get(top);
89 if (SmedAction.panelMain.mark.getTopmark() == top) {
90 button.setBorderPainted(true);
91 } else {
92 button.setBorderPainted(false);
93 }
94 }
95 panelPat.syncPanel();
96 }
97
98 private JRadioButton getTopButton(JRadioButton button, int x, int y, int w, int h, String tip, Top top) {
99 button.setBounds(new Rectangle(x, y, w, h));
100 button.setBorder(BorderFactory.createLoweredBevelBorder());
101 button.setToolTipText(Messages.getString(tip));
102 button.addActionListener(alTop);
103 topButtons.add(button);
104 tops.put(top, button);
105 return button;
106 }
107
108}
Note: See TracBrowser for help on using the repository browser.