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