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