Ignore:
Timestamp:
2016-01-18T00:15:58+01:00 (9 years ago)
Author:
Don-vip
Message:

fix java warnings & sonar issues

Location:
trunk/src/org/openstreetmap/josm/gui/io
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r9514 r9522  
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
    2020
     21/**
     22 * Tag settings panel of upload dialog.
     23 * @since 2599
     24 */
    2125public class TagSettingsPanel extends JPanel implements TableModelListener {
    2226
     
    2630    private final transient ChangesetCommentModel changesetCommentModel;
    2731    private final transient ChangesetCommentModel changesetSourceModel;
    28 
    29     protected void build() {
    30         setLayout(new BorderLayout());
    31         add(pnlTagEditor, BorderLayout.CENTER);
    32     }
    3332
    3433    /**
     
    5049    }
    5150
     51    protected void build() {
     52        setLayout(new BorderLayout());
     53        add(pnlTagEditor, BorderLayout.CENTER);
     54    }
     55
    5256    protected void setProperty(String key, String value) {
    53         if (value == null) {
    54             value = "";
    55         }
    56         value = value.trim();
     57        String val = (value == null ? "" : value).trim();
    5758        String commentInTag = getTagEditorValue(key);
    58         if (value.equals(commentInTag))
     59        if (val.equals(commentInTag))
    5960            return;
    6061
    61         if (value.isEmpty()) {
     62        if (val.isEmpty()) {
    6263            pnlTagEditor.getModel().delete(key);
    6364            return;
     
    6566        TagModel tag = pnlTagEditor.getModel().get(key);
    6667        if (tag == null) {
    67             tag = new TagModel(key, value);
     68            tag = new TagModel(key, val);
    6869            pnlTagEditor.getModel().add(tag);
    6970        } else {
    70             pnlTagEditor.getModel().updateTagValue(tag, value);
     71            pnlTagEditor.getModel().updateTagValue(tag, val);
    7172        }
    7273    }
     
    7475    protected String getTagEditorValue(String key) {
    7576        TagModel tag = pnlTagEditor.getModel().get(key);
    76         if (tag == null) return null;
    77         return tag.getValue();
     77        return tag == null ? null : tag.getValue();
    7878    }
    7979
     
    110110    @Deprecated
    111111    public void setDefaultTags(Map<String, String> tags) {
     112        // Deprecated
    112113    }
    113114
     115    /**
     116     * Initializes the panel for user input
     117     */
    114118    public void startUserInput() {
    115119        pnlTagEditor.initAutoCompletion(Main.main.getEditLayer());
     
    128132     * Observes the changeset comment model and keeps the tag editor in sync
    129133     * with the current changeset comment
    130      *
    131134     */
    132135    class ChangesetCommentObserver implements Observer {
     
    140143        @Override
    141144        public void update(Observable o, Object arg) {
    142             if (!(o instanceof ChangesetCommentModel)) return;
    143             String newValue = (String) arg;
    144             String oldValue = getTagEditorValue(key);
    145             if (oldValue == null) {
    146                 oldValue = "";
    147             }
    148             if (!oldValue.equals(newValue)) {
    149                 setProperty(key, (String) arg);
     145            if (o instanceof ChangesetCommentModel) {
     146                String newValue = (String) arg;
     147                String oldValue = getTagEditorValue(key);
     148                if (oldValue == null) {
     149                    oldValue = "";
     150                }
     151                if (!oldValue.equals(newValue)) {
     152                    setProperty(key, (String) arg);
     153                }
    150154            }
    151155        }
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r9514 r9522  
    6565 */
    6666public class UploadDialog extends AbstractUploadDialog implements PropertyChangeListener, PreferenceChangedListener {
    67     /**  the unique instance of the upload dialog */
     67    /** the unique instance of the upload dialog */
    6868    private static UploadDialog uploadDialog;
    6969
    70     /**
    71      * List of custom components that can be added by plugins at JOSM startup.
    72      */
     70    /** list of custom components that can be added by plugins at JOSM startup */
    7371    private static final Collection<Component> customComponents = new ArrayList<>();
    7472
    75     /**
    76      * Replies the unique instance of the upload dialog
    77      *
    78      * @return the unique instance of the upload dialog
    79      */
    80     public static synchronized UploadDialog getUploadDialog() {
    81         if (uploadDialog == null) {
    82             uploadDialog = new UploadDialog();
    83         }
    84         return uploadDialog;
    85     }
     73    /** the "created_by" changeset OSM key */
     74    private static final String CREATED_BY = "created_by";
    8675
    8776    /** the panel with the objects to upload */
     
    10897
    10998    /**
     99     * Constructs a new {@code UploadDialog}.
     100     */
     101    public UploadDialog() {
     102        super(JOptionPane.getFrameForComponent(Main.parent), ModalityType.DOCUMENT_MODAL);
     103        build();
     104    }
     105
     106    /**
     107     * Replies the unique instance of the upload dialog
     108     *
     109     * @return the unique instance of the upload dialog
     110     */
     111    public static synchronized UploadDialog getUploadDialog() {
     112        if (uploadDialog == null) {
     113            uploadDialog = new UploadDialog();
     114        }
     115        return uploadDialog;
     116    }
     117
     118    /**
    110119     * builds the content panel for the upload dialog
    111120     *
     
    117126
    118127        // the panel with the list of uploaded objects
    119         //
    120         pnl.add(pnlUploadedObjects = new UploadedObjectsSummaryPanel(), GBC.eol().fill(GBC.BOTH));
     128        pnlUploadedObjects = new UploadedObjectsSummaryPanel();
     129        pnl.add(pnlUploadedObjects, GBC.eol().fill(GBC.BOTH));
    121130
    122131        // Custom components
     
    126135
    127136        // a tabbed pane with configuration panels in the lower half
    128         //
    129137        tpConfigPanels = new JTabbedPane() {
    130138            @Override
    131139            public Dimension getPreferredSize() {
    132140                // make sure the tabbed pane never grabs more space than necessary
    133                 //
    134141                return super.getMinimumSize();
    135142            }
    136143        };
    137144
    138         tpConfigPanels.add(pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel, changesetSourceModel));
     145        pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel, changesetSourceModel);
     146        tpConfigPanels.add(pnlBasicUploadSettings);
    139147        tpConfigPanels.setTitleAt(0, tr("Settings"));
    140148        tpConfigPanels.setToolTipTextAt(0, tr("Decide how to upload the data and which changeset to use"));
    141149
    142         tpConfigPanels.add(pnlTagSettings = new TagSettingsPanel(changesetCommentModel, changesetSourceModel));
     150        pnlTagSettings = new TagSettingsPanel(changesetCommentModel, changesetSourceModel);
     151        tpConfigPanels.add(pnlTagSettings);
    143152        tpConfigPanels.setTitleAt(1, tr("Tags of new changeset"));
    144153        tpConfigPanels.setToolTipTextAt(1, tr("Apply tags to the changeset data is uploaded to"));
    145154
    146         tpConfigPanels.add(pnlChangesetManagement = new ChangesetManagementPanel(changesetCommentModel));
     155        pnlChangesetManagement = new ChangesetManagementPanel(changesetCommentModel);
     156        tpConfigPanels.add(pnlChangesetManagement);
    147157        tpConfigPanels.setTitleAt(2, tr("Changesets"));
    148158        tpConfigPanels.setToolTipTextAt(2, tr("Manage open changesets and select a changeset to upload to"));
    149159
    150         tpConfigPanels.add(pnlUploadStrategySelectionPanel = new UploadStrategySelectionPanel());
     160        pnlUploadStrategySelectionPanel = new UploadStrategySelectionPanel();
     161        tpConfigPanels.add(pnlUploadStrategySelectionPanel);
    151162        tpConfigPanels.setTitleAt(3, tr("Advanced"));
    152163        tpConfigPanels.setToolTipTextAt(3, tr("Configure advanced settings"));
     
    167178
    168179        // -- upload button
    169         UploadAction uploadAction = new UploadAction();
    170         pnl.add(btnUpload = new SideButton(uploadAction));
     180        btnUpload = new SideButton(new UploadAction());
     181        pnl.add(btnUpload);
    171182        btnUpload.setFocusable(true);
    172183        InputMapUtils.enableEnter(btnUpload);
     
    247258
    248259    /**
    249      * constructor
    250      */
    251     public UploadDialog() {
    252         super(JOptionPane.getFrameForComponent(Main.parent), ModalityType.DOCUMENT_MODAL);
    253         build();
    254     }
    255 
    256     /**
    257260     * Sets the collection of primitives to upload
    258261     *
     
    288291        final Map<String, String> tags = new HashMap<>();
    289292
    290         // obtain from previos input
     293        // obtain from previous input
    291294        tags.put("source", getLastChangesetSourceFromHistory());
    292295        tags.put("comment", getLastChangesetCommentFromHistory());
     
    305308        // set/adapt created_by
    306309        final String agent = Version.getInstance().getAgentString(false);
    307         final String created_by = tags.get("created_by");
    308         if (created_by == null || created_by.isEmpty()) {
    309             tags.put("created_by", agent);
    310         } else if (!created_by.contains(agent)) {
    311             tags.put("created_by", created_by + ';' + agent);
     310        final String createdBy = tags.get(CREATED_BY);
     311        if (createdBy == null || createdBy.isEmpty()) {
     312            tags.put(CREATED_BY, agent);
     313        } else if (!createdBy.contains(agent)) {
     314            tags.put(CREATED_BY, createdBy + ';' + agent);
    312315        }
    313316
     
    359362    }
    360363
     364    /**
     365     * Sets the changeset to be used in the next upload
     366     *
     367     * @param cs the changeset
     368     */
    361369    public void setSelectedChangesetForNextUpload(Changeset cs) {
    362370        pnlChangesetManagement.setSelectedChangesetForNextUpload(cs);
    363371    }
    364372
     373    /**
     374     * @deprecated No longer supported, does nothing;
     375     * @return empty map
     376     */
     377    @Deprecated
    365378    public Map<String, String> getDefaultChangesetTags() {
    366379        return pnlTagSettings.getDefaultTags();
     
    368381
    369382    /**
     383     * @param tags ignored
    370384     * @deprecated No longer supported, does nothing; use {@link #setChangesetTags(DataSet)} instead!
    371385     */
    372386    @Deprecated
    373387    public void setDefaultChangesetTags(Map<String, String> tags) {
     388        // Deprecated
    374389    }
    375390
     
    545560
    546561            UploadStrategySpecification strategy = getUploadStrategySpecification();
    547             if (strategy.getStrategy().equals(UploadStrategy.CHUNKED_DATASET_STRATEGY)) {
    548                 if (strategy.getChunkSize() == UploadStrategySpecification.UNSPECIFIED_CHUNK_SIZE) {
    549                     warnIllegalChunkSize();
    550                     tpConfigPanels.setSelectedIndex(0);
    551                     return;
    552                 }
     562            if (strategy.getStrategy().equals(UploadStrategy.CHUNKED_DATASET_STRATEGY)
     563                    && strategy.getChunkSize() == UploadStrategySpecification.UNSPECIFIED_CHUNK_SIZE) {
     564                warnIllegalChunkSize();
     565                tpConfigPanels.setSelectedIndex(0);
     566                return;
    553567            }
    554568            setCanceled(false);
     
    637651    }
    638652
     653    /**
     654     * Returns the last changeset comment from history.
     655     * @return the last changeset comment from history
     656     */
    639657    public String getLastChangesetCommentFromHistory() {
    640658        return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.HISTORY_KEY, new ArrayList<String>());
    641659    }
    642660
     661    /**
     662     * Returns the last changeset source from history.
     663     * @return the last changeset source from history
     664     */
    643665    public String getLastChangesetSourceFromHistory() {
    644666        return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.SOURCE_HISTORY_KEY, BasicUploadSettingsPanel.getDefaultSources());
Note: See TracChangeset for help on using the changeset viewer.