Ignore:
Timestamp:
2016-06-01T00:55:28+02:00 (10 years ago)
Author:
donvip
Message:

sonar - fix many issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Address.java

    r32060 r32211  
    1414import java.awt.event.KeyEvent;
    1515import java.awt.event.MouseEvent;
    16 import java.awt.event.MouseListener;
    17 import java.awt.event.MouseMotionListener;
     16import java.awt.event.WindowAdapter;
    1817import java.awt.event.WindowEvent;
    19 import java.awt.event.WindowListener;
    2018import java.util.ArrayList;
    2119import java.util.Collection;
     
    6361import org.openstreetmap.josm.tools.Shortcut;
    6462
    65 public class Address extends MapMode implements MouseListener, MouseMotionListener, ActionListener {
     63public class Address extends MapMode {
    6664
    6765    // perhaps make all these tags configurable in the future
     
    7674    private String relationMemberHouse = "house";
    7775
    78     private JRadioButton plus_one = new JRadioButton("+1", false);
    79     private JRadioButton plus_two = new JRadioButton("+2", true); // enable this by default
    80     private JRadioButton minus_one = new JRadioButton("-1", false);
    81     private JRadioButton minus_two = new JRadioButton("-2", false);
     76    private JRadioButton plusOne = new JRadioButton("+1", false);
     77    private JRadioButton plusTwo = new JRadioButton("+2", true); // enable this by default
     78    private JRadioButton minusOne = new JRadioButton("-1", false);
     79    private JRadioButton minusTwo = new JRadioButton("-2", false);
    8280    final JCheckBox tagPolygon = new JCheckBox(tr("on polygon"));
    8381
    84     JDialog dialog = null;
    85     JButton clearButton = null;
     82    JDialog dialog;
     83    JButton clearButton;
    8684    final JTextField inputNumber = new JTextField();
    8785    final JTextField inputStreet = new JTextField();
    8886    JLabel link = new JLabel();
    89     private Way selectedWay;
     87    private transient Way selectedWay;
    9088    private boolean shift;
    9189    private boolean ctrl;
     
    114112//        dialog.setVisible(false);
    115113        // kill the window completely to fix an issue on some linux distro and full screen mode.
    116         if(dialog != null)
    117         {
     114        if(dialog != null) {
    118115            dialog.dispose();
    119116            dialog = null;
     
    131128        List<Way> mouseOnExistingWays = new ArrayList<>();
    132129        List<Way> mouseOnExistingBuildingWays = new ArrayList<>();
    133         mouseOnExistingWays = new ArrayList<>();
    134130        Node currentMouseNode = mv.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate);
    135131        if (currentMouseNode != null) {
     
    140136                    && currentMouseNode.get(tagHouseStreet) == null
    141137                    && findWayInRelationAddr(currentMouseNode) == null
    142                     && !inputStreet.getText().equals("")) {
     138                    && !inputStreet.getText().isEmpty()) {
    143139                // house number already present but not linked to a street
    144140                Collection<Command> cmds = new LinkedList<>();
     
    199195                inputNumber.setText("");
    200196                setNewSelection(mouseOnExistingWays.get(0));
    201             } else if (mouseOnExistingWays.size() == 0) {
     197            } else if (mouseOnExistingWays.isEmpty()) {
    202198                // clicked a non highway and not a node => add the new address
    203                 if (inputStreet.getText().equals("") || inputNumber.getText().equals("")) {
     199                if (inputStreet.getText().isEmpty() || inputNumber.getText().isEmpty()) {
    204200                    Toolkit.getDefaultToolkit().beep();
    205201                } else {
     
    217213            }
    218214        }
    219 
    220215    }
    221216
     
    297292    }
    298293
    299     private Node createNewNode(MouseEvent e, Collection<Command> cmds) {
     294    private static Node createNewNode(MouseEvent e, Collection<Command> cmds) {
    300295        // DrawAction.mouseReleased() but without key modifiers
    301296        Node n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY()));
     
    398393
    399394    private static void pruneSuccsAndReverse(List<Integer> is) {
    400         //if (is.size() < 2) return;
    401 
    402395        HashSet<Integer> is2 = new HashSet<>();
    403396        for (int i : is) {
     
    415408        try {
    416409            return ImageProvider.getCursor("crosshair", null);
    417         } catch (Exception e) {
     410        } catch (RuntimeException e) {
     411            Main.warn(e);
    418412        }
    419413        return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
     
    422416    private void applyInputNumberChange() {
    423417        Integer num = Integer.parseInt(inputNumber.getText());
    424         if (plus_one.isSelected())
     418        if (plusOne.isSelected())
    425419            num = num + 1;
    426         if (plus_two.isSelected())
     420        if (plusTwo.isSelected())
    427421            num = num + 2;
    428         if (minus_one.isSelected() && num > 1)
     422        if (minusOne.isSelected() && num > 1)
    429423            num = num - 1;
    430         if (minus_two.isSelected() && num > 2)
     424        if (minusTwo.isSelected() && num > 2)
    431425            num = num - 2;
    432426        inputNumber.setText(num.toString());
     
    435429    private void revertInputNumberChange() {
    436430        Integer num = Integer.parseInt(inputNumber.getText());
    437         if (plus_one.isSelected())
     431        if (plusOne.isSelected())
    438432            num = num - 1;
    439         if (plus_two.isSelected())
     433        if (plusTwo.isSelected())
    440434            num = num - 2;
    441         if (minus_one.isSelected() && num > 1)
     435        if (minusOne.isSelected() && num > 1)
    442436            num = num + 1;
    443         if (minus_two.isSelected() && num > 2)
     437        if (minusTwo.isSelected() && num > 2)
    444438            num = num + 2;
    445439        inputNumber.setText(num.toString());
     
    471465        });
    472466        ButtonGroup bgIncremental = new ButtonGroup();
    473         bgIncremental.add(plus_one);
    474         bgIncremental.add(plus_two);
    475         bgIncremental.add(minus_one);
    476         bgIncremental.add(minus_two);
    477         p.add(minus_one, GBC.std().insets(10, 0, 10, 0));
    478 //        p.add(plus_one, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
    479         p.add(plus_one, GBC.std().insets(0, 0, 10, 0));
     467        bgIncremental.add(plusOne);
     468        bgIncremental.add(plusTwo);
     469        bgIncremental.add(minusOne);
     470        bgIncremental.add(minusTwo);
     471        p.add(minusOne, GBC.std().insets(10, 0, 10, 0));
     472        p.add(plusOne, GBC.std().insets(0, 0, 10, 0));
    480473        tagPolygon.setSelected(Main.pref.getBoolean("cadastrewms.addr.onBuilding", false));
    481474        tagPolygon.addChangeListener(new ChangeListener() {
     
    486479        });
    487480        p.add(tagPolygon, GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 0, 0));
    488         p.add(minus_two, GBC.std().insets(10, 0, 10, 0));
    489         p.add(plus_two, GBC.std().insets(0, 0, 10, 0));
     481        p.add(minusTwo, GBC.std().insets(10, 0, 10, 0));
     482        p.add(plusTwo, GBC.std().insets(0, 0, 10, 0));
    490483        p.add(clearButton, GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 0, 0));
    491484
     
    508501            }
    509502        });
    510         dialog.addWindowListener(new WindowListener() {
     503        dialog.addWindowListener(new WindowAdapter() {
    511504            @Override
    512             public void windowClosing(WindowEvent arg0) {
     505            public void windowClosing(WindowEvent arg) {
    513506                exitMode();
    514507                Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction());
    515508            }
    516             @Override
    517             public void windowClosed(WindowEvent e) {}
    518             @Override
    519             public void windowActivated(WindowEvent arg0) {}
    520             @Override
    521             public void windowDeactivated(WindowEvent arg0) {}
    522             @Override
    523             public void windowDeiconified(WindowEvent arg0) {}
    524             @Override
    525             public void windowIconified(WindowEvent arg0) {}
    526             @Override
    527             public void windowOpened(WindowEvent arg0) {}
    528509        });
    529510        String bounds = Main.pref.get("cadastrewms.addr.bounds",null);
     
    544525    }
    545526
    546     private void setNewSelection(OsmPrimitive osm) {
     527    private static void setNewSelection(OsmPrimitive osm) {
    547528        Collection<OsmPrimitive> newSelection = new LinkedList<>(Main.main.getCurrentDataSet().getSelected());
    548529        newSelection.clear();
Note: See TracChangeset for help on using the changeset viewer.