Changeset 32767 in osm for applications/editors/josm/plugins/smed/src/panels/PanelPat.java
- Timestamp:
- 2016-08-04T02:27:43+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed/src/panels/PanelPat.java
r30738 r32767 1 1 package panels; 2 2 3 import java.awt.*; 4 import java.awt.event.*; 3 import java.awt.Rectangle; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.ActionListener; 6 import java.util.EnumMap; 5 7 6 import javax.swing.*; 7 8 import java.util.*; 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; 9 13 10 14 import messages.Messages; 15 import seamarks.SeaMark.Ent; 16 import seamarks.SeaMark.Pat; 11 17 import smed.SmedAction; 12 import seamarks.SeaMark.*;13 18 14 19 public class PanelPat extends JPanel { 15 20 16 17 18 21 private SmedAction dlg; 22 private Ent ent; 23 public PanelCol panelCol; 19 24 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.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 SmedAction.panelMain.mark.setPattern(ent, pat); 34 button.setBorderPainted(true); 35 } else 36 button.setBorderPainted(false); 37 } 38 switch (SmedAction.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 }; 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 }; 56 63 57 58 59 60 61 62 63 64 65 66 67 68 69 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)); 70 77 71 78 } 72 79 73 public void syncPanel() { 74 for (Pat pat : patterns.keySet()) { 75 JRadioButton button = patterns.get(pat); 76 if (SmedAction.panelMain.mark.getPattern(ent) == pat) { 77 button.setBorderPainted(true); 78 } else 79 button.setBorderPainted(false); 80 } 81 panelCol.syncPanel(); 82 } 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 } 83 91 84 85 86 87 88 89 90 91 92 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 } 93 101 94 102 }
Note:
See TracChangeset
for help on using the changeset viewer.