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