Ignore:
Timestamp:
2015-06-20T23:42:21+02:00 (9 years ago)
Author:
Don-vip
Message:

checkstyle: enable relevant whitespace checks and fix them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r8509 r8510  
    113113
    114114        public String getDisplayTooltip() {
    115             if(!name.isEmpty())
     115            if (!name.isEmpty())
    116116                return name;
    117117
     
    124124
    125125        public Icon getDisplayIcon() {
    126             if(ico != null)
     126            if (ico != null)
    127127                return ico;
    128128            Object o = action.getValue(Action.LARGE_ICON_KEY);
    129             if(o == null)
     129            if (o == null)
    130130                o = action.getValue(Action.SMALL_ICON);
    131131            return (Icon) o;
     
    156156            if (!(getAction() instanceof ParameterizedAction)) return false;
    157157            for (Object o: parameters.values()) {
    158                 if (o!=null) return true;
     158                if (o != null) return true;
    159159            }
    160160            return false;
     
    208208                skip('(');
    209209
    210                 ParameterizedAction parametrizedAction = (ParameterizedAction)action;
     210                ParameterizedAction parametrizedAction = (ParameterizedAction) action;
    211211                Map<String, ActionParameter<?>> actionParams = new ConcurrentHashMap<>();
    212212                for (ActionParameter<?> param: parametrizedAction.getActionParameters()) {
     
    217217                    String paramName = readTillChar('=', '=');
    218218                    skip('=');
    219                     String paramValue = readTillChar(',',')');
     219                    String paramValue = readTillChar(',', ')');
    220220                    if (!paramName.isEmpty() && !paramValue.isEmpty()) {
    221221                        ActionParameter<?> actionParam = actionParams.get(paramName);
     
    234234                    String paramName = readTillChar('=', '=');
    235235                    skip('=');
    236                     String paramValue = readTillChar(',','}');
     236                    String paramValue = readTillChar(',', '}');
    237237                    if ("icon".equals(paramName) && !paramValue.isEmpty()) {
    238238                        result.setIcon(paramValue);
    239                     } else if("name".equals(paramName) && !paramValue.isEmpty()) {
     239                    } else if ("name".equals(paramName) && !paramValue.isEmpty()) {
    240240                        result.setName(paramValue);
    241241                    }
     
    249249
    250250        private void escape(String s) {
    251             for (int i=0; i<s.length(); i++) {
     251            for (int i = 0; i < s.length(); i++) {
    252252                char ch = s.charAt(i);
    253253                if (ch == '\\' || ch == '(' || ch == '{' || ch == ',' || ch == ')' || ch == '}' || ch == '=') {
     
    265265
    266266            String val = (String) action.getAction().getValue("toolbar");
    267             if(val == null)
     267            if (val == null)
    268268                return null;
    269269            escape(val);
    270270            if (action.getAction() instanceof ParameterizedAction) {
    271271                result.append('(');
    272                 List<ActionParameter<?>> params = ((ParameterizedAction)action.getAction()).getActionParameters();
    273                 for (int i=0; i<params.size(); i++) {
    274                     ActionParameter<Object> param = (ActionParameter<Object>)params.get(i);
     272                List<ActionParameter<?>> params = ((ParameterizedAction) action.getAction()).getActionParameters();
     273                for (int i = 0; i < params.size(); i++) {
     274                    ActionParameter<Object> param = (ActionParameter<Object>) params.get(i);
    275275                    escape(param.getName());
    276276                    result.append('=');
     
    302302                    first = false;
    303303                }
    304                 if(!first) {
     304                if (!first) {
    305305                    result.append('}');
    306306            }
     
    325325            if (currentAction.isSeparator() || !(currentAction.getAction() instanceof ParameterizedAction))
    326326                return adaptable;
    327             ParameterizedAction pa = (ParameterizedAction)currentAction.getAction();
     327            ParameterizedAction pa = (ParameterizedAction) currentAction.getAction();
    328328            return pa.getActionParameters().size() + adaptable;
    329329        }
     
    331331        @SuppressWarnings("unchecked")
    332332        private ActionParameter<Object> getParam(int index) {
    333             ParameterizedAction pa = (ParameterizedAction)currentAction.getAction();
     333            ParameterizedAction pa = (ParameterizedAction) currentAction.getAction();
    334334            return (ActionParameter<Object>) pa.getActionParameters().get(index);
    335335        }
     
    337337        @Override
    338338        public Object getValueAt(int rowIndex, int columnIndex) {
    339             if(currentAction.getAction() instanceof AdaptableAction) {
     339            if (currentAction.getAction() instanceof AdaptableAction) {
    340340                if (rowIndex < 2) {
    341341                    switch (columnIndex) {
     
    372372            int paramIndex = rowIndex;
    373373
    374             if(currentAction.getAction() instanceof AdaptableAction) {
     374            if (currentAction.getAction() instanceof AdaptableAction) {
    375375                if (rowIndex == 0) {
    376376                     currentAction.setName(val);
     
    386386
    387387            if (param != null && !val.isEmpty()) {
    388                 currentAction.getParameters().put(param.getName(), param.readFromString((String)aValue));
     388                currentAction.getParameters().put(param.getName(), param.readFromString((String) aValue));
    389389            }
    390390        }
     
    402402            this.act = action;
    403403            doNotHide.setSelected(Main.pref.getBoolean("toolbar.always-visible", true));
    404             remove.setVisible(act!=null);
    405             shortcutEdit.setVisible(act!=null);
     404            remove.setVisible(act != null);
     405            shortcutEdit.setVisible(act != null);
    406406        }
    407407
     
    423423            @Override
    424424            public void actionPerformed(ActionEvent e) {
    425                     final PreferenceDialog p =new PreferenceDialog(Main.parent);
    426                     p.selectPreferencesTabByName("toolbar");
    427                     p.setVisible(true);
    428                 }
    429             });
     425                final PreferenceDialog p = new PreferenceDialog(Main.parent);
     426                p.selectPreferencesTabByName("toolbar");
     427                p.setVisible(true);
     428            }
     429        });
    430430
    431431        private JMenuItem shortcutEdit = new JMenuItem(new AbstractAction(tr("Edit shortcut")) {
    432432            @Override
    433433            public void actionPerformed(ActionEvent e) {
    434                     final PreferenceDialog p =new PreferenceDialog(Main.parent);
     434                final PreferenceDialog p = new PreferenceDialog(Main.parent);
    435435                p.getTabbedPane().getShortcutPreference().setDefaultFilter(act.getDisplayName());
    436                     p.selectPreferencesTabByName("shortcuts");
    437                     p.setVisible(true);
     436                p.selectPreferencesTabByName("shortcuts");
     437                p.setVisible(true);
    438438                // refresh toolbar to try using changed shortcuts without restart
    439                     Main.toolbar.refreshToolbarControl();
    440                 }
    441             });
     439                Main.toolbar.refreshToolbarControl();
     440            }
     441        });
    442442
    443443        private JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide toolbar and menu")) {
     
    447447                Main.pref.put("toolbar.always-visible", sel);
    448448                Main.pref.put("menu.always-visible", sel);
    449         }
     449            }
    450450        });
     451
    451452        {
    452453            addPopupMenuListener(new PopupMenuListener() {
     
    454455                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    455456                    setActionAndAdapt(buttonActions.get(
    456                             ((JPopupMenu)e.getSource()).getInvoker()
     457                            ((JPopupMenu) e.getSource()).getInvoker()
    457458                    ));
    458459                }
     460
    459461                @Override
    460462                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
     
    496498            protected Transferable createTransferable(JComponent c) {
    497499                List<ActionDefinition> actions = new ArrayList<>();
    498                 for (ActionDefinition o: ((JList<ActionDefinition>)c).getSelectedValuesList()) {
     500                for (ActionDefinition o: ((JList<ActionDefinition>) c).getSelectedValuesList()) {
    499501                    actions.add(o);
    500502                }
     
    609611                            selected.add(leadItem++, ActionDefinition.getSeparator());
    610612                        } else if (node.getUserObject() instanceof Action) {
    611                             selected.add(leadItem++, new ActionDefinition((Action)node.getUserObject()));
     613                            selected.add(leadItem++, new ActionDefinition((Action) node.getUserObject()));
    612614                        }
    613615                    }
     
    744746                        s = tr("Separator");
    745747                    }
    746                     JLabel l = (JLabel)def.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus);
     748                    JLabel l = (JLabel) def.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus);
    747749                    l.setIcon(i);
    748750                    return l;
     
    750752            };
    751753            selectedList.setCellRenderer(renderer);
    752             selectedList.addListSelectionListener(new ListSelectionListener(){
     754            selectedList.addListSelectionListener(new ListSelectionListener() {
    753755                @Override
    754756                public void valueChanged(ListSelectionEvent e) {
     
    806808            right.add(new JScrollPane(actionsTree), GBC.eol().fill(GBC.BOTH));
    807809
    808             final JPanel buttons = new JPanel(new GridLayout(6,1));
     810            final JPanel buttons = new JPanel(new GridLayout(6, 1));
    809811            buttons.add(upButton = createButton("up"));
    810812            buttons.add(addButton = createButton("<"));
     
    814816
    815817            final JPanel p = new JPanel();
    816             p.setLayout(new LayoutManager(){
     818            p.setLayout(new LayoutManager() {
    817819                @Override
    818820                public void addLayoutComponent(String name, Component comp) {}
     821
    819822                @Override
    820823                public void removeLayoutComponent(Component comp) {}
     824
    821825                @Override
    822826                public Dimension minimumLayoutSize(Container parent) {
     
    824828                    Dimension r = right.getMinimumSize();
    825829                    Dimension b = buttons.getMinimumSize();
    826                     return new Dimension(l.width+b.width+10+r.width,l.height+b.height+10+r.height);
    827                 }
     830                    return new Dimension(l.width+b.width+10+r.width, l.height+b.height+10+r.height);
     831                }
     832
    828833                @Override
    829834                public Dimension preferredLayoutSize(Container parent) {
    830835                    Dimension l = new Dimension(200, 200);
    831836                    Dimension r = new Dimension(200, 200);
    832                     return new Dimension(l.width+r.width+10+buttons.getPreferredSize().width,Math.max(l.height, r.height));
    833                 }
     837                    return new Dimension(l.width+r.width+10+buttons.getPreferredSize().width, Math.max(l.height, r.height));
     838                }
     839
    834840                @Override
    835841                public void layoutContainer(Container parent) {
     
    837843                    Dimension b = buttons.getPreferredSize();
    838844                    int width = (d.width-10-b.width)/2;
    839                     left.setBounds(new Rectangle(0,0,width,d.height));
    840                     right.setBounds(new Rectangle(width+10+b.width,0,width,d.height));
     845                    left.setBounds(new Rectangle(0, 0, width, d.height));
     846                    right.setBounds(new Rectangle(width+10+b.width, 0, width, d.height));
    841847                    buttons.setBounds(new Rectangle(width+5, d.height/2-b.height/2, b.width, b.height));
    842848                }
     
    873879                } else {
    874880                    String res = parser.saveAction(action);
    875                     if(res != null) {
     881                    if (res != null) {
    876882                        t.add(res);
    877883                }
     
    905911        for (MenuElement item : menuElement.getSubElements()) {
    906912            if (item instanceof JMenuItem) {
    907                 JMenuItem menuItem = (JMenuItem)item;
     913                JMenuItem menuItem = (JMenuItem) item;
    908914                if (menuItem.getAction() != null) {
    909915                    Action action = menuItem.getAction();
    910916                    userObject = action;
    911917                    Object tb = action.getValue("toolbar");
    912                     if(tb == null) {
     918                    if (tb == null) {
    913919                        Main.info(tr("Toolbar action without name: {0}",
    914920                        action.getClass().getName()));
    915921                        continue;
    916922                    } else if (!(tb instanceof String)) {
    917                         if(!(tb instanceof Boolean) || (Boolean)tb) {
     923                        if (!(tb instanceof Boolean) || (Boolean) tb) {
    918924                            Main.info(tr("Strange toolbar value: {0}",
    919925                            action.getClass().getName()));
     
    923929                        String toolbar = (String) tb;
    924930                        Action r = actions.get(toolbar);
    925                         if(r != null && r != action && !toolbar.startsWith("imagery_")) {
     931                        if (r != null && r != action && !toolbar.startsWith("imagery_")) {
    926932                            Main.info(tr("Toolbar action {0} overwritten: {1} gets {2}",
    927933                            toolbar, r.getClass().getName(), action.getClass().getName()));
     
    941947    public Action getAction(String s) {
    942948        Action e = actions.get(s);
    943         if(e == null) {
     949        if (e == null) {
    944950            e = regactions.get(s);
    945951        }
     
    990996            } else {
    991997                ActionDefinition a = actionParser.loadAction(s);
    992                 if(a != null) {
     998                if (a != null) {
    993999                    result.add(a);
    9941000                } else {
     
    10311037        control.removeAll();
    10321038        buttonActions.clear();
    1033         boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0)!=null;
     1039        boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null;
    10341040
    10351041        for (ActionDefinition action : getDefinedActions()) {
     
    10771083            t.remove(definitionText);
    10781084        } else {
    1079             if (preferredIndex>=0 && preferredIndex < t.size()) {
     1085            if (preferredIndex >= 0 && preferredIndex < t.size()) {
    10801086                t.add(preferredIndex, definitionText); // add to specified place
    10811087            } else {
     
    11051111
    11061112        String tt = action.getDisplayTooltip();
    1107         if (tt==null) {
    1108             tt="";
     1113        if (tt == null) {
     1114            tt = "";
    11091115        }
    11101116
    11111117        if (sc == null || paramCode != 0) {
    11121118            String name = (String) action.getAction().getValue("toolbar");
    1113             if (name==null) {
    1114                 name=action.getDisplayName();
    1115             }
    1116             if (paramCode!=0) {
     1119            if (name == null) {
     1120                name = action.getDisplayName();
     1121            }
     1122            if (paramCode != 0) {
    11171123                name = name+paramCode;
    11181124            }
    1119             String desc = action.getDisplayName() + ((paramCode==0)?"":action.parameters.toString());
     1125            String desc = action.getDisplayName() + ((paramCode == 0) ? "" : action.parameters.toString());
    11201126            sc = Shortcut.registerShortcut("toolbar:"+name, tr("Toolbar: {0}", desc),
    11211127                KeyEvent.CHAR_UNDEFINED, Shortcut.NONE);
     
    11261132            if (sc.isAssignedUser()) {
    11271133                if (tt.startsWith("<html>") && tt.endsWith("</html>")) {
    1128                     tt = tt.substring(6,tt.length()-6);
     1134                    tt = tt.substring(6, tt.length()-6);
    11291135                }
    11301136                tt = Main.platform.makeTooltip(tt, sc);
Note: See TracChangeset for help on using the changeset viewer.