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/PanelFog.java

    r30738 r32767  
    11package panels;
    22
    3 import javax.swing.*;
    4 
    5 import java.awt.*;
    6 import java.awt.event.*;
     3import java.awt.Rectangle;
     4import java.awt.event.ActionEvent;
     5import java.awt.event.ActionListener;
     6import java.awt.event.FocusAdapter;
     7import java.awt.event.FocusEvent;
     8import java.awt.event.FocusListener;
    79import java.util.EnumMap;
    810
     11import javax.swing.BorderFactory;
     12import javax.swing.ButtonGroup;
     13import javax.swing.ImageIcon;
     14import javax.swing.JLabel;
     15import javax.swing.JPanel;
     16import javax.swing.JRadioButton;
     17import javax.swing.JTextField;
     18import javax.swing.SwingConstants;
     19
    920import messages.Messages;
     21import seamarks.SeaMark.Fog;
    1022import smed.SmedAction;
    11 import seamarks.SeaMark.*;
    1223
    1324public class PanelFog extends JPanel {
    1425
    15         private SmedAction dlg;
    16         private ButtonGroup fogButtons = new ButtonGroup();
    17         public JRadioButton noFogButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/OffButton.png")));
    18         public JRadioButton yesFogButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogYesButton.png")));
    19         public JRadioButton hornButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogHornButton.png")));
    20         public JRadioButton sirenButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogSirenButton.png")));
    21         public JRadioButton diaButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogDiaButton.png")));
    22         public JRadioButton bellButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogBellButton.png")));
    23         public JRadioButton whisButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogWhisButton.png")));
    24         public JRadioButton gongButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogGongButton.png")));
    25         public JRadioButton explosButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogExplosButton.png")));
    26         private EnumMap<Fog, JRadioButton> fogs = new EnumMap<>(Fog.class);
    27         private ActionListener alFog = new ActionListener() {
    28                 public void actionPerformed(java.awt.event.ActionEvent e) {
    29                         for (Fog fog : fogs.keySet()) {
    30                                 JRadioButton button = fogs.get(fog);
    31                                 if (button.isSelected()) {
    32                                         SmedAction.panelMain.mark.setFogSound(fog);
    33                                         button.setBorderPainted(true);
    34                                 } else
    35                                         button.setBorderPainted(false);
    36                         }
    37                 }
    38         };
    39         public JLabel groupLabel;
    40         public JTextField groupBox;
    41         private FocusListener flGroup = new FocusAdapter() {
    42                 public void focusLost(java.awt.event.FocusEvent e) {
    43                         SmedAction.panelMain.mark.setFogGroup(groupBox.getText());
    44                 }
    45         };
    46         public JLabel periodLabel;
    47         public JTextField periodBox;
    48         private FocusListener flPeriod = new FocusAdapter() {
    49                 public void focusLost(java.awt.event.FocusEvent e) {
    50                         SmedAction.panelMain.mark.setFogPeriod(periodBox.getText());
    51                 }
    52         };
    53         public JLabel seqLabel;
    54         public JTextField seqBox;
    55         private FocusListener flSeq = new FocusAdapter() {
    56                 public void focusLost(java.awt.event.FocusEvent e) {
    57                         SmedAction.panelMain.mark.setFogSequence(seqBox.getText());
    58                 }
    59         };
    60         public JLabel rangeLabel;
    61         public JTextField rangeBox;
    62         private FocusListener flRange = new FocusAdapter() {
    63                 public void focusLost(java.awt.event.FocusEvent e) {
    64                         SmedAction.panelMain.mark.setFogRange(rangeBox.getText());
    65                 }
    66         };
     26    private SmedAction dlg;
     27    private ButtonGroup fogButtons = new ButtonGroup();
     28    public JRadioButton noFogButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/OffButton.png")));
     29    public JRadioButton yesFogButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogYesButton.png")));
     30    public JRadioButton hornButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogHornButton.png")));
     31    public JRadioButton sirenButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogSirenButton.png")));
     32    public JRadioButton diaButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogDiaButton.png")));
     33    public JRadioButton bellButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogBellButton.png")));
     34    public JRadioButton whisButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogWhisButton.png")));
     35    public JRadioButton gongButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogGongButton.png")));
     36    public JRadioButton explosButton = new JRadioButton(new ImageIcon(getClass().getResource("/images/FogExplosButton.png")));
     37    private EnumMap<Fog, JRadioButton> fogs = new EnumMap<>(Fog.class);
     38    private ActionListener alFog = new ActionListener() {
     39        @Override
     40        public void actionPerformed(ActionEvent e) {
     41            for (Fog fog : fogs.keySet()) {
     42                JRadioButton button = fogs.get(fog);
     43                if (button.isSelected()) {
     44                    SmedAction.panelMain.mark.setFogSound(fog);
     45                    button.setBorderPainted(true);
     46                } else {
     47                    button.setBorderPainted(false);
     48                }
     49            }
     50        }
     51    };
     52    public JLabel groupLabel;
     53    public JTextField groupBox;
     54    private FocusListener flGroup = new FocusAdapter() {
     55        @Override
     56        public void focusLost(FocusEvent e) {
     57            SmedAction.panelMain.mark.setFogGroup(groupBox.getText());
     58        }
     59    };
     60    public JLabel periodLabel;
     61    public JTextField periodBox;
     62    private FocusListener flPeriod = new FocusAdapter() {
     63        @Override
     64        public void focusLost(FocusEvent e) {
     65            SmedAction.panelMain.mark.setFogPeriod(periodBox.getText());
     66        }
     67    };
     68    public JLabel seqLabel;
     69    public JTextField seqBox;
     70    private FocusListener flSeq = new FocusAdapter() {
     71        @Override
     72        public void focusLost(FocusEvent e) {
     73            SmedAction.panelMain.mark.setFogSequence(seqBox.getText());
     74        }
     75    };
     76    public JLabel rangeLabel;
     77    public JTextField rangeBox;
     78    private FocusListener flRange = new FocusAdapter() {
     79        @Override
     80        public void focusLost(FocusEvent e) {
     81            SmedAction.panelMain.mark.setFogRange(rangeBox.getText());
     82        }
     83    };
    6784
    68         public PanelFog(SmedAction dia) {
    69                 dlg = dia;
    70                 setLayout(null);
    71                 add(getFogButton(noFogButton, 0, 2, 27, 27, "NoFog", Fog.NOFOG));
    72                 add(getFogButton(yesFogButton, 0, 32, 27, 27, "FogSignal", Fog.FOGSIG));
    73                 add(getFogButton(hornButton, 0, 62, 27, 27, "Horn", Fog.HORN));
    74                 add(getFogButton(sirenButton, 0, 92, 27, 27, "Siren", Fog.SIREN));
    75                 add(getFogButton(gongButton, 0, 122, 27, 27, "Gong", Fog.GONG));
    76                 add(getFogButton(diaButton, 30, 2, 27, 27, "Diaphone", Fog.DIA));
    77                 add(getFogButton(bellButton, 30, 32, 27, 27, "Bell", Fog.BELL));
    78                 add(getFogButton(whisButton, 30, 62, 27, 27, "Whistle", Fog.WHIS));
    79                 add(getFogButton(explosButton, 30, 92, 27, 27, "Explosion", Fog.EXPLOS));
     85    public PanelFog(SmedAction dia) {
     86        dlg = dia;
     87        setLayout(null);
     88        add(getFogButton(noFogButton, 0, 2, 27, 27, "NoFog", Fog.NOFOG));
     89        add(getFogButton(yesFogButton, 0, 32, 27, 27, "FogSignal", Fog.FOGSIG));
     90        add(getFogButton(hornButton, 0, 62, 27, 27, "Horn", Fog.HORN));
     91        add(getFogButton(sirenButton, 0, 92, 27, 27, "Siren", Fog.SIREN));
     92        add(getFogButton(gongButton, 0, 122, 27, 27, "Gong", Fog.GONG));
     93        add(getFogButton(diaButton, 30, 2, 27, 27, "Diaphone", Fog.DIA));
     94        add(getFogButton(bellButton, 30, 32, 27, 27, "Bell", Fog.BELL));
     95        add(getFogButton(whisButton, 30, 62, 27, 27, "Whistle", Fog.WHIS));
     96        add(getFogButton(explosButton, 30, 92, 27, 27, "Explosion", Fog.EXPLOS));
    8097
    81                 groupLabel = new JLabel(Messages.getString("Group"), SwingConstants.CENTER);
    82                 groupLabel.setBounds(new Rectangle(75, 0, 100, 20));
    83                 add(groupLabel);
    84                 groupBox = new JTextField();
    85                 groupBox.setBounds(new Rectangle(100, 20, 50, 20));
    86                 groupBox.setHorizontalAlignment(SwingConstants.CENTER);
    87                 add(groupBox);
    88                 groupBox.addFocusListener(flGroup);
     98        groupLabel = new JLabel(Messages.getString("Group"), SwingConstants.CENTER);
     99        groupLabel.setBounds(new Rectangle(75, 0, 100, 20));
     100        add(groupLabel);
     101        groupBox = new JTextField();
     102        groupBox.setBounds(new Rectangle(100, 20, 50, 20));
     103        groupBox.setHorizontalAlignment(SwingConstants.CENTER);
     104        add(groupBox);
     105        groupBox.addFocusListener(flGroup);
    89106
    90                 periodLabel = new JLabel(Messages.getString("Period"), SwingConstants.CENTER);
    91                 periodLabel.setBounds(new Rectangle(75, 40, 100, 20));
    92                 add(periodLabel);
    93                 periodBox = new JTextField();
    94                 periodBox.setBounds(new Rectangle(100, 60, 50, 20));
    95                 periodBox.setHorizontalAlignment(SwingConstants.CENTER);
    96                 add(periodBox);
    97                 periodBox.addFocusListener(flPeriod);
     107        periodLabel = new JLabel(Messages.getString("Period"), SwingConstants.CENTER);
     108        periodLabel.setBounds(new Rectangle(75, 40, 100, 20));
     109        add(periodLabel);
     110        periodBox = new JTextField();
     111        periodBox.setBounds(new Rectangle(100, 60, 50, 20));
     112        periodBox.setHorizontalAlignment(SwingConstants.CENTER);
     113        add(periodBox);
     114        periodBox.addFocusListener(flPeriod);
    98115
    99                 seqLabel = new JLabel(Messages.getString("Sequence"), SwingConstants.CENTER);
    100                 seqLabel.setBounds(new Rectangle(75, 80, 100, 20));
    101                 add(seqLabel);
    102                 seqBox = new JTextField();
    103                 seqBox.setBounds(new Rectangle(100, 100, 50, 20));
    104                 seqBox.setHorizontalAlignment(SwingConstants.CENTER);
    105                 add(seqBox);
    106                 seqBox.addFocusListener(flSeq);
     116        seqLabel = new JLabel(Messages.getString("Sequence"), SwingConstants.CENTER);
     117        seqLabel.setBounds(new Rectangle(75, 80, 100, 20));
     118        add(seqLabel);
     119        seqBox = new JTextField();
     120        seqBox.setBounds(new Rectangle(100, 100, 50, 20));
     121        seqBox.setHorizontalAlignment(SwingConstants.CENTER);
     122        add(seqBox);
     123        seqBox.addFocusListener(flSeq);
    107124
    108                 rangeLabel = new JLabel(Messages.getString("Range"), SwingConstants.CENTER);
    109                 rangeLabel.setBounds(new Rectangle(75, 120, 100, 20));
    110                 add(rangeLabel);
    111                 rangeBox = new JTextField();
    112                 rangeBox.setBounds(new Rectangle(100, 140, 50, 20));
    113                 rangeBox.setHorizontalAlignment(SwingConstants.CENTER);
    114                 add(rangeBox);
    115                 rangeBox.addFocusListener(flRange);
     125        rangeLabel = new JLabel(Messages.getString("Range"), SwingConstants.CENTER);
     126        rangeLabel.setBounds(new Rectangle(75, 120, 100, 20));
     127        add(rangeLabel);
     128        rangeBox = new JTextField();
     129        rangeBox.setBounds(new Rectangle(100, 140, 50, 20));
     130        rangeBox.setHorizontalAlignment(SwingConstants.CENTER);
     131        add(rangeBox);
     132        rangeBox.addFocusListener(flRange);
    116133
    117         }
     134    }
    118135
    119         public void syncPanel() {
    120                 for (Fog fog : fogs.keySet()) {
    121                         JRadioButton button = fogs.get(fog);
    122                         button.setBorderPainted(SmedAction.panelMain.mark.getFogSound() == fog);
    123                 }
    124                 groupBox.setText(SmedAction.panelMain.mark.getFogGroup());
    125                 seqBox.setText(SmedAction.panelMain.mark.getFogSequence());
    126                 periodBox.setText(SmedAction.panelMain.mark.getFogPeriod());
    127                 rangeBox.setText(SmedAction.panelMain.mark.getFogRange());
    128         }
     136    public void syncPanel() {
     137        for (Fog fog : fogs.keySet()) {
     138            JRadioButton button = fogs.get(fog);
     139            button.setBorderPainted(SmedAction.panelMain.mark.getFogSound() == fog);
     140        }
     141        groupBox.setText(SmedAction.panelMain.mark.getFogGroup());
     142        seqBox.setText(SmedAction.panelMain.mark.getFogSequence());
     143        periodBox.setText(SmedAction.panelMain.mark.getFogPeriod());
     144        rangeBox.setText(SmedAction.panelMain.mark.getFogRange());
     145    }
    129146
    130         private JRadioButton getFogButton(JRadioButton button, int x, int y, int w, int h, String tip, Fog fog) {
    131                 button.setBounds(new Rectangle(x, y, w, h));
    132                 button.setBorder(BorderFactory.createLoweredBevelBorder());
    133                 button.setToolTipText(Messages.getString(tip));
    134                 button.addActionListener(alFog);
    135                 fogButtons.add(button);
    136                 fogs.put(fog, button);
    137                 return button;
    138         }
     147    private JRadioButton getFogButton(JRadioButton button, int x, int y, int w, int h, String tip, Fog fog) {
     148        button.setBounds(new Rectangle(x, y, w, h));
     149        button.setBorder(BorderFactory.createLoweredBevelBorder());
     150        button.setToolTipText(Messages.getString(tip));
     151        button.addActionListener(alFog);
     152        fogButtons.add(button);
     153        fogs.put(fog, button);
     154        return button;
     155    }
    139156
    140157}
Note: See TracChangeset for help on using the changeset viewer.