Changeset 32767 in osm for applications/editors/josm/plugins/smed/src/panels/PanelPort.java
- Timestamp:
- 2016-08-04T02:27:43+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed/src/panels/PanelPort.java
r30738 r32767 1 1 package panels; 2 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import javax.swing.*; 3 import java.awt.Rectangle; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.ActionListener; 6 import java.util.EnumMap; 6 7 7 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; 8 13 9 14 import messages.Messages; 15 import seamarks.SeaMark.Cat; 16 import seamarks.SeaMark.Col; 17 import seamarks.SeaMark.Obj; 18 import seamarks.SeaMark.Pat; 19 import seamarks.SeaMark.Shp; 10 20 import smed.SmedAction; 11 import seamarks.SeaMark.*;12 21 13 22 public class PanelPort extends JPanel { 14 23 15 private SmedAction dlg; 16 public ButtonGroup shapeButtons = new ButtonGroup(); 17 public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png"))); 18 public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png"))); 19 public JRadioButton canButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CanButton.png"))); 20 public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png"))); 21 public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png"))); 22 public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png"))); 23 public JRadioButton towerButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TowerButton.png"))); 24 public JRadioButton perchButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PerchPButton.png"))); 25 public JRadioButton stakeButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/StakeButton.png"))); 26 public EnumMap<Shp, JRadioButton> shapes = new EnumMap<>(Shp.class); 27 public EnumMap<Shp, Obj> objects = new EnumMap<>(Shp.class); 28 public ActionListener alShape = new ActionListener() { 29 public void actionPerformed(java.awt.event.ActionEvent e) { 30 for (Shp shp : shapes.keySet()) { 31 JRadioButton button = shapes.get(shp); 32 if (button.isSelected()) { 33 SmedAction.panelMain.mark.setShape(shp); 34 SmedAction.panelMain.mark.setObject(objects.get(shp)); 35 button.setBorderPainted(true); 36 } else 37 button.setBorderPainted(false); 38 } 39 if (SmedAction.panelMain.mark.testValid()) { 40 SmedAction.panelMain.panelChan.topmarkButton.setVisible(true); 41 SmedAction.panelMain.panelChan.lightButton.setVisible(true); 42 if (SmedAction.panelMain.mark.getCategory() == Cat.LAM_PORT) { 43 switch (SmedAction.panelMain.mark.getRegion()) { 44 case A: 45 SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT); 46 SmedAction.panelMain.mark.setObjColour(Col.RED); 47 break; 48 case B: 49 SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT); 50 SmedAction.panelMain.mark.setObjColour(Col.GREEN); 51 break; 52 case C: 53 SmedAction.panelMain.mark.setObjPattern(Pat.HSTRP); 54 SmedAction.panelMain.mark.setObjColour(Col.RED); 55 SmedAction.panelMain.mark.addObjColour(Col.WHITE); 56 SmedAction.panelMain.mark.addObjColour(Col.RED); 57 SmedAction.panelMain.mark.addObjColour(Col.WHITE); 58 break; 59 } 60 } else { 61 SmedAction.panelMain.mark.setObjPattern(Pat.HSTRP); 62 switch (SmedAction.panelMain.mark.getRegion()) { 63 case A: 64 SmedAction.panelMain.mark.setObjColour(Col.RED); 65 SmedAction.panelMain.mark.addObjColour(Col.GREEN); 66 SmedAction.panelMain.mark.addObjColour(Col.RED); 67 break; 68 case B: 69 SmedAction.panelMain.mark.setObjColour(Col.GREEN); 70 SmedAction.panelMain.mark.addObjColour(Col.RED); 71 SmedAction.panelMain.mark.addObjColour(Col.GREEN); 72 break; 73 case C: 74 SmedAction.panelMain.mark.setObjColour(Col.RED); 75 SmedAction.panelMain.mark.addObjColour(Col.GREEN); 76 SmedAction.panelMain.mark.addObjColour(Col.RED); 77 SmedAction.panelMain.mark.addObjColour(Col.GREEN); 78 break; 79 } 80 } 81 SmedAction.panelMain.panelMore.syncPanel(); 82 } else { 83 SmedAction.panelMain.panelChan.topmarkButton.setVisible(false); 84 SmedAction.panelMain.panelChan.lightButton.setVisible(false); 85 } 86 } 87 }; 24 private SmedAction dlg; 25 public ButtonGroup shapeButtons = new ButtonGroup(); 26 public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png"))); 27 public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png"))); 28 public JRadioButton canButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/CanButton.png"))); 29 public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png"))); 30 public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png"))); 31 public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png"))); 32 public JRadioButton towerButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/TowerButton.png"))); 33 public JRadioButton perchButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PerchPButton.png"))); 34 public JRadioButton stakeButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/StakeButton.png"))); 35 public EnumMap<Shp, JRadioButton> shapes = new EnumMap<>(Shp.class); 36 public EnumMap<Shp, Obj> objects = new EnumMap<>(Shp.class); 37 public ActionListener alShape = new ActionListener() { 38 @Override 39 public void actionPerformed(ActionEvent e) { 40 for (Shp shp : shapes.keySet()) { 41 JRadioButton button = shapes.get(shp); 42 if (button.isSelected()) { 43 SmedAction.panelMain.mark.setShape(shp); 44 SmedAction.panelMain.mark.setObject(objects.get(shp)); 45 button.setBorderPainted(true); 46 } else { 47 button.setBorderPainted(false); 48 } 49 } 50 if (SmedAction.panelMain.mark.testValid()) { 51 SmedAction.panelMain.panelChan.topmarkButton.setVisible(true); 52 SmedAction.panelMain.panelChan.lightButton.setVisible(true); 53 if (SmedAction.panelMain.mark.getCategory() == Cat.LAM_PORT) { 54 switch (SmedAction.panelMain.mark.getRegion()) { 55 case A: 56 SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT); 57 SmedAction.panelMain.mark.setObjColour(Col.RED); 58 break; 59 case B: 60 SmedAction.panelMain.mark.setObjPattern(Pat.NOPAT); 61 SmedAction.panelMain.mark.setObjColour(Col.GREEN); 62 break; 63 case C: 64 SmedAction.panelMain.mark.setObjPattern(Pat.HSTRP); 65 SmedAction.panelMain.mark.setObjColour(Col.RED); 66 SmedAction.panelMain.mark.addObjColour(Col.WHITE); 67 SmedAction.panelMain.mark.addObjColour(Col.RED); 68 SmedAction.panelMain.mark.addObjColour(Col.WHITE); 69 break; 70 } 71 } else { 72 SmedAction.panelMain.mark.setObjPattern(Pat.HSTRP); 73 switch (SmedAction.panelMain.mark.getRegion()) { 74 case A: 75 SmedAction.panelMain.mark.setObjColour(Col.RED); 76 SmedAction.panelMain.mark.addObjColour(Col.GREEN); 77 SmedAction.panelMain.mark.addObjColour(Col.RED); 78 break; 79 case B: 80 SmedAction.panelMain.mark.setObjColour(Col.GREEN); 81 SmedAction.panelMain.mark.addObjColour(Col.RED); 82 SmedAction.panelMain.mark.addObjColour(Col.GREEN); 83 break; 84 case C: 85 SmedAction.panelMain.mark.setObjColour(Col.RED); 86 SmedAction.panelMain.mark.addObjColour(Col.GREEN); 87 SmedAction.panelMain.mark.addObjColour(Col.RED); 88 SmedAction.panelMain.mark.addObjColour(Col.GREEN); 89 break; 90 } 91 } 92 SmedAction.panelMain.panelMore.syncPanel(); 93 } else { 94 SmedAction.panelMain.panelChan.topmarkButton.setVisible(false); 95 SmedAction.panelMain.panelChan.lightButton.setVisible(false); 96 } 97 } 98 }; 88 99 89 public PanelPort(SmedAction dia) {90 dlg = dia;91 setLayout(null);92 add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYLAT));93 add(getShapeButton(sparButton, 0, 32, 34, 32, "Spar", Shp.SPAR, Obj.BOYLAT));94 add(getShapeButton(canButton, 0, 64, 34, 32, "Can", Shp.CAN, Obj.BOYLAT));95 add(getShapeButton(sphereButton, 0, 96, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYLAT));96 add(getShapeButton(floatButton, 0, 128, 34, 32, "Float", Shp.FLOAT, Obj.FLTLAT));97 add(getShapeButton(beaconButton, 35, 0, 34, 32, "Beacon", Shp.BEACON, Obj.BCNLAT));98 add(getShapeButton(towerButton, 35, 32, 34, 32, "TowerB", Shp.TOWER, Obj.BCNLAT));99 add(getShapeButton(perchButton, 35, 64, 34, 32, "Perch", Shp.PERCH, Obj.BCNLAT));100 add(getShapeButton(stakeButton, 35, 96, 34, 32, "Stake", Shp.STAKE, Obj.BCNLAT));101 }100 public PanelPort(SmedAction dia) { 101 dlg = dia; 102 setLayout(null); 103 add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYLAT)); 104 add(getShapeButton(sparButton, 0, 32, 34, 32, "Spar", Shp.SPAR, Obj.BOYLAT)); 105 add(getShapeButton(canButton, 0, 64, 34, 32, "Can", Shp.CAN, Obj.BOYLAT)); 106 add(getShapeButton(sphereButton, 0, 96, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYLAT)); 107 add(getShapeButton(floatButton, 0, 128, 34, 32, "Float", Shp.FLOAT, Obj.FLTLAT)); 108 add(getShapeButton(beaconButton, 35, 0, 34, 32, "Beacon", Shp.BEACON, Obj.BCNLAT)); 109 add(getShapeButton(towerButton, 35, 32, 34, 32, "TowerB", Shp.TOWER, Obj.BCNLAT)); 110 add(getShapeButton(perchButton, 35, 64, 34, 32, "Perch", Shp.PERCH, Obj.BCNLAT)); 111 add(getShapeButton(stakeButton, 35, 96, 34, 32, "Stake", Shp.STAKE, Obj.BCNLAT)); 112 } 102 113 103 public void syncPanel() { 104 for (Shp shp : shapes.keySet()) { 105 JRadioButton button = shapes.get(shp); 106 if (SmedAction.panelMain.mark.getShape() == shp) { 107 button.setBorderPainted(true); 108 } else 109 button.setBorderPainted(false); 110 } 111 } 114 public void syncPanel() { 115 for (Shp shp : shapes.keySet()) { 116 JRadioButton button = shapes.get(shp); 117 if (SmedAction.panelMain.mark.getShape() == shp) { 118 button.setBorderPainted(true); 119 } else { 120 button.setBorderPainted(false); 121 } 122 } 123 } 112 124 113 private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {114 button.setBounds(new Rectangle(x, y, w, h));115 button.setBorder(BorderFactory.createLoweredBevelBorder());116 button.setToolTipText(Messages.getString(tip));117 button.addActionListener(alShape);118 shapeButtons.add(button);119 shapes.put(shp, button);120 objects.put(shp, obj);121 return button;122 }125 private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) { 126 button.setBounds(new Rectangle(x, y, w, h)); 127 button.setBorder(BorderFactory.createLoweredBevelBorder()); 128 button.setToolTipText(Messages.getString(tip)); 129 button.addActionListener(alShape); 130 shapeButtons.add(button); 131 shapes.put(shp, button); 132 objects.put(shp, obj); 133 return button; 134 } 123 135 124 136 }
Note:
See TracChangeset
for help on using the changeset viewer.
