Ignore:
Timestamp:
2016-08-04T02:27:43+02:00 (9 years ago)
Author:
donvip
Message:

code style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed/src/panels/PanelSaw.java

    r30738 r32767  
    11package panels;
    22
    3 import java.awt.*;
    4 import java.awt.event.*;
    5 import javax.swing.*;
     3import java.awt.Rectangle;
     4import java.awt.event.ActionEvent;
     5import java.awt.event.ActionListener;
     6import java.util.EnumMap;
    67
    7 import java.util.*;
     8import javax.swing.BorderFactory;
     9import javax.swing.ButtonGroup;
     10import javax.swing.ImageIcon;
     11import javax.swing.JPanel;
     12import javax.swing.JRadioButton;
    813
    914import messages.Messages;
     15import seamarks.SeaMark.Col;
     16import seamarks.SeaMark.Obj;
     17import seamarks.SeaMark.Pat;
     18import seamarks.SeaMark.Shp;
    1019import smed.SmedAction;
    11 import seamarks.SeaMark.*;
    1220
    1321public class PanelSaw extends JPanel {
    1422
    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 sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
    20         public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
    21         public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
    22         public EnumMap<Shp, JRadioButton> shapes = new EnumMap<>(Shp.class);
    23         public EnumMap<Shp, Obj> objects = new EnumMap<>(Shp.class);
    24         public ActionListener alShape = new ActionListener() {
    25                 public void actionPerformed(java.awt.event.ActionEvent e) {
    26                         for (Shp shp : shapes.keySet()) {
    27                                 JRadioButton button = shapes.get(shp);
    28                                 if (button.isSelected()) {
    29                                         SmedAction.panelMain.mark.setShape(shp);
    30                                         SmedAction.panelMain.mark.setObject(objects.get(shp));
    31                                         button.setBorderPainted(true);
    32                                 } else
    33                                         button.setBorderPainted(false);
    34                         }
    35                         if (SmedAction.panelMain.mark.testValid()) {
    36                                 SmedAction.panelMain.panelChan.topmarkButton.setVisible(true);
    37                                 SmedAction.panelMain.mark.setObjPattern(Pat.VSTRP);
    38                                 SmedAction.panelMain.mark.setObjColour(Col.RED);
    39                                 SmedAction.panelMain.mark.addObjColour(Col.WHITE);
    40                         } else {
    41                                 SmedAction.panelMain.panelChan.topmarkButton.setVisible(false);
    42                         }
    43                         SmedAction.panelMain.panelMore.syncPanel();
    44                 }
    45         };
     23    private SmedAction dlg;
     24    public ButtonGroup shapeButtons = new ButtonGroup();
     25    public JRadioButton pillarButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/PillarButton.png")));
     26    public JRadioButton sparButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SparButton.png")));
     27    public JRadioButton sphereButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/SphereButton.png")));
     28    public JRadioButton floatButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FloatButton.png")));
     29    public JRadioButton beaconButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/BeaconButton.png")));
     30    public EnumMap<Shp, JRadioButton> shapes = new EnumMap<>(Shp.class);
     31    public EnumMap<Shp, Obj> objects = new EnumMap<>(Shp.class);
     32    public ActionListener alShape = new ActionListener() {
     33        @Override
     34        public void actionPerformed(ActionEvent e) {
     35            for (Shp shp : shapes.keySet()) {
     36                JRadioButton button = shapes.get(shp);
     37                if (button.isSelected()) {
     38                    SmedAction.panelMain.mark.setShape(shp);
     39                    SmedAction.panelMain.mark.setObject(objects.get(shp));
     40                    button.setBorderPainted(true);
     41                } else {
     42                    button.setBorderPainted(false);
     43                }
     44            }
     45            if (SmedAction.panelMain.mark.testValid()) {
     46                SmedAction.panelMain.panelChan.topmarkButton.setVisible(true);
     47                SmedAction.panelMain.mark.setObjPattern(Pat.VSTRP);
     48                SmedAction.panelMain.mark.setObjColour(Col.RED);
     49                SmedAction.panelMain.mark.addObjColour(Col.WHITE);
     50            } else {
     51                SmedAction.panelMain.panelChan.topmarkButton.setVisible(false);
     52            }
     53            SmedAction.panelMain.panelMore.syncPanel();
     54        }
     55    };
    4656
    47         public PanelSaw(SmedAction dia) {
    48                 dlg = dia;
    49                 setLayout(null);
    50                 add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYSAW));
    51                 add(getShapeButton(sparButton, 0, 32, 34, 32, "Spar", Shp.SPAR, Obj.BOYSAW));
    52                 add(getShapeButton(sphereButton, 0, 64, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYSAW));
    53                 add(getShapeButton(floatButton, 0, 96, 34, 32, "Float", Shp.FLOAT, Obj.FLTSAW));
    54                 add(getShapeButton(beaconButton, 0, 128, 34, 32, "Beacon", Shp.BEACON, Obj.BCNSAW));
    55         }
     57    public PanelSaw(SmedAction dia) {
     58        dlg = dia;
     59        setLayout(null);
     60        add(getShapeButton(pillarButton, 0, 0, 34, 32, "Pillar", Shp.PILLAR, Obj.BOYSAW));
     61        add(getShapeButton(sparButton, 0, 32, 34, 32, "Spar", Shp.SPAR, Obj.BOYSAW));
     62        add(getShapeButton(sphereButton, 0, 64, 34, 32, "Sphere", Shp.SPHERI, Obj.BOYSAW));
     63        add(getShapeButton(floatButton, 0, 96, 34, 32, "Float", Shp.FLOAT, Obj.FLTSAW));
     64        add(getShapeButton(beaconButton, 0, 128, 34, 32, "Beacon", Shp.BEACON, Obj.BCNSAW));
     65    }
    5666
    57         public void syncPanel() {
    58                 for (Shp shp : shapes.keySet()) {
    59                         JRadioButton button = shapes.get(shp);
    60                         if (SmedAction.panelMain.mark.getShape() == shp) {
    61                                 button.setBorderPainted(true);
    62                         } else
    63                                 button.setBorderPainted(false);
    64                 }
    65                 SmedAction.panelMain.mark.testValid();
    66         }
    67        
    68         private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
    69                 button.setBounds(new Rectangle(x, y, w, h));
    70                 button.setBorder(BorderFactory.createLoweredBevelBorder());
    71                 button.setToolTipText(Messages.getString(tip));
    72                 button.addActionListener(alShape);
    73                 shapeButtons.add(button);
    74                 shapes.put(shp, button);
    75                 objects.put(shp, obj);
    76                 return button;
    77         }
     67    public void syncPanel() {
     68        for (Shp shp : shapes.keySet()) {
     69            JRadioButton button = shapes.get(shp);
     70            if (SmedAction.panelMain.mark.getShape() == shp) {
     71                button.setBorderPainted(true);
     72            } else {
     73                button.setBorderPainted(false);
     74            }
     75        }
     76        SmedAction.panelMain.mark.testValid();
     77    }
     78
     79    private JRadioButton getShapeButton(JRadioButton button, int x, int y, int w, int h, String tip, Shp shp, Obj obj) {
     80        button.setBounds(new Rectangle(x, y, w, h));
     81        button.setBorder(BorderFactory.createLoweredBevelBorder());
     82        button.setToolTipText(Messages.getString(tip));
     83        button.addActionListener(alShape);
     84        shapeButtons.add(button);
     85        shapes.put(shp, button);
     86        objects.put(shp, obj);
     87        return button;
     88    }
    7889
    7990}
Note: See TracChangeset for help on using the changeset viewer.