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.Pat;
|
---|
18 | import smed.SmedAction;
|
---|
19 |
|
---|
20 | public class PanelPat extends JPanel {
|
---|
21 |
|
---|
22 | private SmedAction dlg;
|
---|
23 | private Ent ent;
|
---|
24 | public PanelCol panelCol;
|
---|
25 |
|
---|
26 | private ButtonGroup patButtons = new ButtonGroup();
|
---|
27 | public JRadioButton noneButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/NoneButton.png")));
|
---|
28 | public JRadioButton horizButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/HorizontalButton.png")));
|
---|
29 | public JRadioButton vertButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/VerticalButton.png")));
|
---|
30 | public JRadioButton diagButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/DiagonalButton.png")));
|
---|
31 | public JRadioButton squareButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SquaredButton.png")));
|
---|
32 | public JRadioButton borderButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BorderButton.png")));
|
---|
33 | public EnumMap<Pat, JRadioButton> patterns = new EnumMap<>(Pat.class);
|
---|
34 | private ActionListener alPat = new ActionListener() {
|
---|
35 | @Override
|
---|
36 | public void actionPerformed(ActionEvent e) {
|
---|
37 | for (Pat pat : patterns.keySet()) {
|
---|
38 | JRadioButton button = patterns.get(pat);
|
---|
39 | if (button.isSelected()) {
|
---|
40 | SmedAction.panelMain.mark.setPattern(ent, pat);
|
---|
41 | button.setBorderPainted(true);
|
---|
42 | } else {
|
---|
43 | button.setBorderPainted(false);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | switch (SmedAction.panelMain.mark.getPattern(ent)) {
|
---|
47 | case NOPAT:
|
---|
48 | panelCol.trimStack(1);
|
---|
49 | break;
|
---|
50 | case HSTRP:
|
---|
51 | case VSTRP:
|
---|
52 | case DIAG:
|
---|
53 | break;
|
---|
54 | case SQUARED:
|
---|
55 | panelCol.trimStack(4);
|
---|
56 | break;
|
---|
57 | case BORDER:
|
---|
58 | case CROSS:
|
---|
59 | panelCol.trimStack(2);
|
---|
60 | break;
|
---|
61 | default:
|
---|
62 | break;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | };
|
---|
66 |
|
---|
67 | public PanelPat(SmedAction dia, Ent entity) {
|
---|
68 | dlg = dia;
|
---|
69 | ent = entity;
|
---|
70 | setLayout(null);
|
---|
71 | panelCol = new PanelCol(dlg, ent);
|
---|
72 | panelCol.setBounds(new Rectangle(0, 0, 72, 160));
|
---|
73 | add(panelCol);
|
---|
74 | add(getPatButton(noneButton, 76, 0, 27, 27, "NoPat", Pat.NOPAT));
|
---|
75 | add(getPatButton(horizButton, 76, 26, 27, 27, "HorizPat", Pat.HSTRP));
|
---|
76 | add(getPatButton(vertButton, 76, 52, 27, 27, "VertPat", Pat.VSTRP));
|
---|
77 | add(getPatButton(diagButton, 76, 78, 27, 27, "DiagPat", Pat.DIAG));
|
---|
78 | add(getPatButton(squareButton, 76, 104, 27, 27, "SquarePat", Pat.SQUARED));
|
---|
79 | add(getPatButton(borderButton, 76, 130, 27, 27, "BorderPat", Pat.BORDER));
|
---|
80 |
|
---|
81 | }
|
---|
82 |
|
---|
83 | public void syncPanel() {
|
---|
84 | for (Pat pat : patterns.keySet()) {
|
---|
85 | JRadioButton button = patterns.get(pat);
|
---|
86 | if (SmedAction.panelMain.mark.getPattern(ent) == pat) {
|
---|
87 | button.setBorderPainted(true);
|
---|
88 | } else {
|
---|
89 | button.setBorderPainted(false);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | panelCol.syncPanel();
|
---|
93 | }
|
---|
94 |
|
---|
95 | private JRadioButton getPatButton(JRadioButton button, int x, int y, int w, int h, String tip, Pat pat) {
|
---|
96 | button.setBounds(new Rectangle(x, y, w, h));
|
---|
97 | button.setBorder(BorderFactory.createLoweredBevelBorder());
|
---|
98 | button.setToolTipText(Messages.getString(tip));
|
---|
99 | button.addActionListener(alPat);
|
---|
100 | patButtons.add(button);
|
---|
101 | patterns.put(pat, button);
|
---|
102 | return button;
|
---|
103 | }
|
---|
104 |
|
---|
105 | }
|
---|