Changeset 11343 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2016-11-29T02:22:12+01:00 (8 years ago)
Author:
Don-vip
Message:

findbugs - disable SE_TRANSIENT_FIELD_NOT_RESTORED, fix some SIC_INNER_SHOULD_BE_STATIC_ANON

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    r11257 r11343  
    4545public class AddImageryLayerAction extends JosmAction implements AdaptableAction {
    4646    private final transient ImageryInfo info;
     47
     48    static class SelectWmsLayersDialog extends ExtendedDialog {
     49        SelectWmsLayersDialog(WMSLayerTree tree, JComboBox<String> formats) {
     50            super(Main.parent, tr("Select WMS layers"), new String[]{tr("Add layers"), tr("Cancel")});
     51            final JScrollPane scrollPane = new JScrollPane(tree.getLayerTree());
     52            scrollPane.setPreferredSize(new Dimension(400, 400));
     53            final JPanel panel = new JPanel(new GridBagLayout());
     54            panel.add(scrollPane, GBC.eol().fill());
     55            panel.add(formats, GBC.eol().fill(GBC.HORIZONTAL));
     56            setContent(panel);
     57        }
     58    }
    4759
    4860    /**
     
    151163        formats.setToolTipText(tr("Select image format for WMS layer"));
    152164
    153         if (!GraphicsEnvironment.isHeadless()) {
    154             if (1 != new ExtendedDialog(Main.parent, tr("Select WMS layers"), new String[]{tr("Add layers"), tr("Cancel")}) { {
    155                 final JScrollPane scrollPane = new JScrollPane(tree.getLayerTree());
    156                 scrollPane.setPreferredSize(new Dimension(400, 400));
    157                 final JPanel panel = new JPanel(new GridBagLayout());
    158                 panel.add(scrollPane, GBC.eol().fill());
    159                 panel.add(formats, GBC.eol().fill(GBC.HORIZONTAL));
    160                 setContent(panel);
    161             } }.showDialog().getValue()) {
    162                 return null;
    163             }
     165        if (!GraphicsEnvironment.isHeadless() && 1 != new SelectWmsLayersDialog(tree, formats).showDialog().getValue()) {
     166            return null;
    164167        }
    165168
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r11301 r11343  
    3636public class JumpToAction extends JosmAction {
    3737
     38    private final JosmTextField url = new JosmTextField();
     39    private final JosmTextField lat = new JosmTextField();
     40    private final JosmTextField lon = new JosmTextField();
     41    private final JosmTextField zm = new JosmTextField();
     42
    3843    /**
    3944     * Constructs a new {@code JumpToAction}.
     
    4651    }
    4752
    48     private final JosmTextField url = new JosmTextField();
    49     private final JosmTextField lat = new JosmTextField();
    50     private final JosmTextField lon = new JosmTextField();
    51     private final JosmTextField zm = new JosmTextField();
     53    static class JumpToPositionDialog extends ExtendedDialog {
     54        JumpToPositionDialog(String[] buttons, JPanel panel) {
     55            super(Main.parent, tr("Jump to Position"), buttons);
     56            setContent(panel);
     57            setCancelButton(2);
     58        }
     59    }
    5260
    5361    class OsmURLListener implements DocumentListener {
     
    143151        double zoomLvl = 100;
    144152        while (ll == null) {
    145             final int option = new ExtendedDialog(Main.parent, tr("Jump to Position"), buttons) {{
    146                 setContent(panel);
    147                 setCancelButton(2);
    148             }}.showDialog().getValue();
     153            final int option = new JumpToPositionDialog(buttons, panel).showDialog().getValue();
    149154
    150155            if (option != 1) return;
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r11329 r11343  
    5959    protected final transient List<Class<? extends DownloadTask>> downloadTasks;
    6060
     61    static class WhichTasksToPerformDialog extends ExtendedDialog {
     62        WhichTasksToPerformDialog(JList<DownloadTask> list) {
     63            super(Main.parent, tr("Which tasks to perform?"), new String[]{tr("Ok"), tr("Cancel")}, true);
     64            setButtonIcons(new String[]{"ok", "cancel"});
     65            final JPanel pane = new JPanel(new GridLayout(2, 1));
     66            pane.add(new JLabel(tr("Which tasks to perform?")));
     67            pane.add(list);
     68            setContent(pane);
     69        }
     70    }
     71
    6172    /**
    6273     * Create an open action. The name is "Open a file".
     
    237248        final JList<DownloadTask> list = new JList<>(tasks.toArray(new DownloadTask[tasks.size()]));
    238249        list.addSelectionInterval(0, tasks.size() - 1);
    239         final ExtendedDialog dialog = new ExtendedDialog(Main.parent,
    240                 tr("Which tasks to perform?"), new String[]{tr("Ok"), tr("Cancel")}, true) { {
    241             setButtonIcons(new String[]{"ok", "cancel"});
    242             final JPanel pane = new JPanel(new GridLayout(2, 1));
    243             pane.add(new JLabel(tr("Which tasks to perform?")));
    244             pane.add(list);
    245             setContent(pane);
    246         } };
     250        final ExtendedDialog dialog = new WhichTasksToPerformDialog(list);
    247251        dialog.showDialog();
    248252        return dialog.getValue() == 1 ? list.getSelectedValuesList() : Collections.<DownloadTask>emptyList();
  • trunk/src/org/openstreetmap/josm/actions/PurgeAction.java

    r11277 r11343  
    8989    }
    9090
     91    /** force selection to be active for all entries */
     92    static class SelectionForcedOsmPrimitivRenderer extends OsmPrimitivRenderer {
     93        @Override
     94        public Component getListCellRendererComponent(JList<? extends OsmPrimitive> list,
     95                OsmPrimitive value, int index, boolean isSelected, boolean cellHasFocus) {
     96            return super.getListCellRendererComponent(list, value, index, true, false);
     97        }
     98    }
     99
    91100    @Override
    92101    public void actionPerformed(ActionEvent e) {
     
    128137        toPurgeChecked = new HashSet<>();
    129138
    130         // Add referrer, unless the object to purge is not new
    131         // and the parent is a relation
     139        // Add referrer, unless the object to purge is not new and the parent is a relation
    132140        Set<OsmPrimitive> toPurgeRecursive = new HashSet<>();
    133141        while (!toPurge.isEmpty()) {
     
    169177            }
    170178
    171         // Add untagged way nodes. Do not add nodes that have other
    172         // referrers not yet to-be-purged.
     179        // Add untagged way nodes. Do not add nodes that have other referrers not yet to-be-purged.
    173180        if (Main.pref.getBoolean("purge.add_untagged_waynodes", true)) {
    174181            Set<OsmPrimitive> wayNodes = new HashSet<>();
     
    206213            }
    207214
    208             /**
    209              * Add higher level relations (list gets extended while looping over it)
    210              */
     215            // Add higher level relations (list gets extended while looping over it)
    211216            List<Relation> relLst = new ArrayList<>(relSet);
    212217            for (int i = 0; i < relLst.size(); ++i) { // foreach loop not applicable since list gets extended while looping over it
     
    262267            JList<OsmPrimitive> list = new JList<>(toPurgeAdditionally.toArray(new OsmPrimitive[toPurgeAdditionally.size()]));
    263268            /* force selection to be active for all entries */
    264             list.setCellRenderer(new OsmPrimitivRenderer() {
    265                 @Override
    266                 public Component getListCellRendererComponent(JList<? extends OsmPrimitive> list,
    267                         OsmPrimitive value,
    268                         int index,
    269                         boolean isSelected,
    270                         boolean cellHasFocus) {
    271                     return super.getListCellRendererComponent(list, value, index, true, false);
    272                 }
    273             });
     269            list.setCellRenderer(new SelectionForcedOsmPrimitivRenderer());
    274270            JScrollPane scroll = new JScrollPane(list);
    275271            scroll.setPreferredSize(new Dimension(250, 300));
  • trunk/src/org/openstreetmap/josm/actions/RenameLayerAction.java

    r9591 r11343  
    4444    }
    4545
     46    static class InitialValueOptionPane extends JOptionPane {
     47        InitialValueOptionPane(Box panel, JosmTextField initial) {
     48            super(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, initial);
     49        }
     50
     51        @Override
     52        public void selectInitialValue() {
     53            JosmTextField initial = (JosmTextField) getInitialValue();
     54            initial.requestFocusInWindow();
     55            initial.selectAll();
     56        }
     57    }
     58
    4659    @Override
    4760    public void actionPerformed(ActionEvent e) {
     
    5669        }
    5770
    58         final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION) {
    59             @Override public void selectInitialValue() {
    60                 name.requestFocusInWindow();
    61                 name.selectAll();
    62             }
    63         };
     71        final JOptionPane optionPane = new InitialValueOptionPane(panel, name);
    6472        final JDialog dlg = optionPane.createDialog(Main.parent, tr("Rename layer"));
    6573        dlg.setModalityType(ModalityType.DOCUMENT_MODAL);
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r11240 r11343  
    264264                }
    265265            });
    266             list.setCellRenderer(new DefaultListCellRenderer() {
    267                 @Override
    268                 public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    269                     final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    270                     final String name = DefaultNameFormatter.getInstance().format((Way) value);
    271                     // get rid of id from DefaultNameFormatter.decorateNameWithId()
    272                     final String nameWithoutId = name
    273                             .replace(tr(" [id: {0}]", ((Way) value).getId()), "")
    274                             .replace(tr(" [id: {0}]", ((Way) value).getUniqueId()), "");
    275                     ((JLabel) c).setText(tr("Segment {0}: {1}", index + 1, nameWithoutId));
    276                     return c;
    277                 }
    278             });
     266            list.setCellRenderer(new SegmentListCellRenderer());
    279267        }
    280268
     
    306294                Main.getLayerManager().getEditDataSet().setSelected(result.getNewSelection());
    307295            }
     296        }
     297    }
     298
     299    static class SegmentListCellRenderer extends DefaultListCellRenderer {
     300        @Override
     301        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
     302            final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
     303            final String name = DefaultNameFormatter.getInstance().format((Way) value);
     304            // get rid of id from DefaultNameFormatter.decorateNameWithId()
     305            final String nameWithoutId = name
     306                    .replace(tr(" [id: {0}]", ((Way) value).getId()), "")
     307                    .replace(tr(" [id: {0}]", ((Way) value).getUniqueId()), "");
     308            ((JLabel) c).setText(tr("Segment {0}: {1}", index + 1, nameWithoutId));
     309            return c;
    308310        }
    309311    }
Note: See TracChangeset for help on using the changeset viewer.