Changeset 2081 in josm for trunk/src


Ignore:
Timestamp:
2009-09-08T22:56:02+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3393: loooong delay when using presets with a large osm file - further improvement; next step could be to turn UploadHooks into an asynchronous task; ApiPreconditionChecker loops over all keys in all upload primitives!
fixed #3435: Switching the changeset type deletes any changeset tags that have been set
fixed #3430: Entering comment=* manually in the changeset tags dialog gets ignored
fixed #3431: Upload dialog pops up again if no comment is provided
fixed #3429: created_by=* includes the wrong language when uploading from a new layer

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
8 edited

Legend:

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

    r2017 r2081  
    6161                manifest = true;
    6262                u = new URL("jar:" + Main.class.getProtectionDomain().getCodeSource().getLocation().toString()
    63                     + "!/META-INF/MANIFEST.MF");
     63                        + "!/META-INF/MANIFEST.MF");
    6464            } catch (MalformedURLException e) {
    6565                e.printStackTrace();
  • trunk/src/org/openstreetmap/josm/actions/ApiPreconditionChecker.java

    r2035 r2081  
    44
    55import java.util.Collection;
    6 import java.util.LinkedList;
    7 import java.util.List;
     6import java.util.Collections;
    87import java.util.Map.Entry;
    98
     
    1211import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.actions.UploadAction.UploadHook;
     13import org.openstreetmap.josm.data.APIDataSet;
    1414import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1515import org.openstreetmap.josm.data.osm.Way;
     
    2121public class ApiPreconditionChecker implements UploadHook {
    2222
    23     public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update,
    24             Collection<OsmPrimitive> delete) {
     23    public boolean checkUpload(APIDataSet apiData) {
    2524        OsmApi api = OsmApi.getOsmApi();
    2625        try {
     
    3635
    3736            if (maxNodes > 0) {
    38                 if( !checkMaxNodes(add, maxNodes))
     37                if( !checkMaxNodes(apiData.getPrimitivesToAdd(), maxNodes))
    3938                    return false;
    40                 if( !checkMaxNodes(update, maxNodes))
     39                if( !checkMaxNodes(apiData.getPrimitivesToUpdate(), maxNodes))
    4140                    return false;
    42                 if( !checkMaxNodes(delete, maxNodes))
     41                if( !checkMaxNodes(apiData.getPrimitivesToDelete(), maxNodes))
    4342                    return false;
    4443            }
     
    4645            if (maxElements  > 0) {
    4746                int total = 0;
    48                 total = add.size() + update.size() + delete.size();
     47                total = apiData.getPrimitivesToAdd().size() + apiData.getPrimitivesToUpdate().size() + apiData.getPrimitivesToDelete().size();
    4948                if(total > maxElements) {
    5049                    JOptionPane.showMessageDialog(
     
    6766    }
    6867
    69     private boolean checkMaxNodes(Collection<OsmPrimitive> add, long maxNodes) {
    70         for (OsmPrimitive osmPrimitive : add) {
     68    private boolean checkMaxNodes(Collection<OsmPrimitive> primitives, long maxNodes) {
     69        for (OsmPrimitive osmPrimitive : primitives) {
    7170            for (Entry<String,String> e : osmPrimitive.entrySet()) {
    7271                if(e.getValue().length() > 255) {
     
    9089                            JOptionPane.ERROR_MESSAGE
    9190                    );
    92                     List<OsmPrimitive> newNodes = new LinkedList<OsmPrimitive>();
    93                     newNodes.add(osmPrimitive);
    94                     Main.main.getCurrentDataSet().setSelected(newNodes);
     91                    Main.main.getCurrentDataSet().setSelected(Collections.singleton(osmPrimitive));
    9592                    return false;
    9693                }
     
    109106                        JOptionPane.ERROR_MESSAGE
    110107                );
    111                 List<OsmPrimitive> newNodes = new LinkedList<OsmPrimitive>();
    112                 newNodes.add(osmPrimitive);
    113 
    114                 Main.main.getCurrentDataSet().setSelected(newNodes);
     108                Main.main.getCurrentDataSet().setSelected(Collections.singleton(osmPrimitive));
    115109                return false;
    116110            }
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r2077 r2081  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.tools.I18n.trn;
    6 
    7 import java.awt.BorderLayout;
    8 import java.awt.Dimension;
    9 import java.awt.GridBagConstraints;
    10 import java.awt.GridBagLayout;
     5
    116import java.awt.event.ActionEvent;
    12 import java.awt.event.ActionListener;
    137import java.awt.event.KeyEvent;
    148import java.io.IOException;
    159import java.net.HttpURLConnection;
    1610import java.util.Collection;
    17 import java.util.HashMap;
    1811import java.util.LinkedList;
    19 import java.util.List;
    20 import java.util.Map;
    21 import java.util.Properties;
    2212import java.util.logging.Logger;
    2313import java.util.regex.Matcher;
    2414import java.util.regex.Pattern;
    2515
    26 import javax.swing.BoxLayout;
    27 import javax.swing.ButtonGroup;
    28 import javax.swing.JCheckBox;
    29 import javax.swing.JLabel;
    30 import javax.swing.JList;
    3116import javax.swing.JOptionPane;
    32 import javax.swing.JPanel;
    33 import javax.swing.JRadioButton;
    34 import javax.swing.JScrollPane;
    35 import javax.swing.JTabbedPane;
    3617
    3718import org.openstreetmap.josm.Main;
     
    4324import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    4425import org.openstreetmap.josm.gui.ExceptionDialogUtil;
    45 import org.openstreetmap.josm.gui.ExtendedDialog;
    46 import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    4726import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    48 import org.openstreetmap.josm.gui.historycombobox.SuggestingJHistoryComboBox;
     27import org.openstreetmap.josm.gui.io.UploadDialog;
    4928import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5029import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    51 import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
    5230import org.openstreetmap.josm.io.ChangesetProcessingType;
    5331import org.openstreetmap.josm.io.OsmApi;
     
    5634import org.openstreetmap.josm.io.OsmChangesetCloseException;
    5735import org.openstreetmap.josm.io.OsmServerWriter;
    58 import org.openstreetmap.josm.tools.GBC;
    5936import org.openstreetmap.josm.tools.Shortcut;
    60 import org.openstreetmap.josm.tools.WindowGeometry;
    6137import org.xml.sax.SAXException;
    6238
     
    7450public class UploadAction extends JosmAction{
    7551    static private Logger logger = Logger.getLogger(UploadAction.class.getName());
    76 
    77     public static final String HISTORY_KEY = "upload.comment.history";
    78 
    79     /** Upload Hook */
    80     public interface UploadHook {
    81         /**
    82          * Checks the upload.
    83          * @param add The added primitives
    84          * @param update The updated primitives
    85          * @param delete The deleted primitives
    86          * @return true, if the upload can continue
    87          */
    88         public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete);
    89     }
    90 
    9152    /**
    9253     * The list of upload hooks. These hooks will be called one after the other
     
    9960     * however, a plugin might also want to insert something after that.
    10061     */
    101     public final LinkedList<UploadHook> uploadHooks = new LinkedList<UploadHook>();
    102 
    103     public UploadAction() {
    104         super(tr("Upload to OSM..."), "upload", tr("Upload all changes to the OSM server."),
    105                 Shortcut.registerShortcut("file:upload", tr("File: {0}", tr("Upload to OSM...")), KeyEvent.VK_U, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY), true);
    106 
     62    public static final LinkedList<UploadHook> uploadHooks = new LinkedList<UploadHook>();
     63    static {
    10764        /**
    10865         * Checks server capabilities before upload.
     
    11572         */
    11673        uploadHooks.add(new UploadConfirmationHook());
     74    }
     75
     76    /**
     77     * Registers an upload hook. Adds the hook to the end of the list of upload hooks.
     78     *
     79     * @param hook the upload hook. Ignored if null.
     80     */
     81    public static void registerUploadHook(UploadHook hook) {
     82        if(hook == null) return;
     83        if (!uploadHooks.contains(hook)) {
     84            uploadHooks.add(hook);
     85        }
     86    }
     87
     88    /**
     89     * Unregisters an upload hook. Removes the hook from the list of upload hooks.
     90     *
     91     * @param hook the upload hook. Ignored if null.
     92     */
     93    public static void unregisterUploadHook(UploadHook hook) {
     94        if(hook == null) return;
     95        if (uploadHooks.contains(hook)) {
     96            uploadHooks.remove(hook);
     97        }
     98    }
     99
     100    /** Upload Hook */
     101    public interface UploadHook {
     102        /**
     103         * Checks the upload.
     104         * @param apiDataSet the data to upload
     105         */
     106        public boolean checkUpload(APIDataSet apiDataSet);
     107    }
     108
     109
     110    public UploadAction() {
     111        super(tr("Upload to OSM..."), "upload", tr("Upload all changes to the OSM server."),
     112                Shortcut.registerShortcut("file:upload", tr("File: {0}", tr("Upload to OSM...")), KeyEvent.VK_U, Shortcut.GROUPS_ALT1+Shortcut.GROUP_HOTKEY), true);
    117113    }
    118114
     
    145141        // is one of these.
    146142        for(UploadHook hook : uploadHooks)
    147             if(!hook.checkUpload(apiData.getPrimitivesToAdd(), apiData.getPrimitivesToUpdate(), apiData.getPrimitivesToDelete()))
     143            if(!hook.checkUpload(apiData))
    148144                return false;
    149145
     
    180176                        Main.map.mapView.getEditLayer(),
    181177                        apiData.getPrimitives(),
    182                         UploadConfirmationHook.getUploadDialogPanel().getChangeset(),
    183                         UploadConfirmationHook.getUploadDialogPanel().getChangesetProcessingType()
     178                        UploadConfirmationHook.getUploadDialog().getChangeset(),
     179                        UploadConfirmationHook.getUploadDialog().getChangesetProcessingType()
    184180                )
    185181        );
     
    461457
    462458    static public class UploadConfirmationHook implements UploadHook {
    463         static private UploadDialogPanel uploadDialogPanel;
    464 
    465         static public UploadDialogPanel getUploadDialogPanel() {
    466             if (uploadDialogPanel == null) {
    467                 uploadDialogPanel = new UploadDialogPanel();
    468             }
    469             return uploadDialogPanel;
    470         }
    471 
    472         public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) {
    473             final UploadDialogPanel panel = getUploadDialogPanel();
    474             panel.setUploadedPrimitives(add, update, delete);
    475 
    476             ExtendedDialog dialog = new ExtendedDialog(
    477                     Main.parent,
    478                     tr("Upload these changes?"),
    479                     new String[] {tr("Upload Changes"), tr("Cancel")}
    480             ) {
    481                 @Override
    482                 public void setVisible(boolean visible) {
    483                     if (visible) {
    484                         new WindowGeometry(
    485                                 panel.getClass().getName(),
    486                                 WindowGeometry.centerInWindow(
    487                                         JOptionPane.getFrameForComponent(Main.parent),
    488                                         new Dimension(400,600)
    489                                 )
    490                         ).apply(this);
    491                         panel.startUserInput();
    492                     } else {
    493                         new WindowGeometry(this).remember(panel.getClass().getName());
    494                     }
    495                     super.setVisible(visible);
    496                 }
    497             };
    498 
    499             dialog.setButtonIcons(new String[] {"upload.png", "cancel.png"});
    500             dialog.setContent(panel, false /* no scroll pane */);
    501             while(true) {
    502                 dialog.showDialog();
    503                 int result = dialog.getValue();
    504                 // cancel pressed
    505                 if (result != 1) return false;
    506                 // don't allow empty commit message
    507                 if (! panel.hasChangesetComment()) {
    508                     continue;
    509                 }
    510                 panel.rememberUserInput();
    511                 break;
    512             }
     459        static private UploadDialog uploadDialog;
     460
     461        static public UploadDialog getUploadDialog() {
     462            if (uploadDialog == null) {
     463                uploadDialog = new UploadDialog();
     464            }
     465            return uploadDialog;
     466        }
     467
     468        public boolean checkUpload(APIDataSet apiData) {
     469            final UploadDialog dialog = getUploadDialog();
     470            dialog.setUploadedPrimitives(apiData.getPrimitivesToAdd(),apiData.getPrimitivesToUpdate(), apiData.getPrimitivesToDelete());
     471            dialog.setVisible(true);
     472            if (dialog.isCanceled())
     473                return false;
     474            dialog.rememberUserInput();
    513475            return true;
    514476        }
     
    586548        }
    587549    }
    588 
    589     /**
    590      * The panel displaying information about primitives to upload and providing
    591      * UI widgets for entering the changeset comment and other configuration
    592      * settings.
    593      *
    594      */
    595     static public class UploadDialogPanel extends JPanel {
    596 
    597         /** the list with the added primitives */
    598         private JList lstAdd;
    599         private JLabel lblAdd;
    600         private JScrollPane spAdd;
    601         /** the list with the updated primitives */
    602         private JList lstUpdate;
    603         private JLabel lblUpdate;
    604         private JScrollPane spUpdate;
    605         /** the list with the deleted primitives */
    606         private JList lstDelete;
    607         private JLabel lblDelete;
    608         private JScrollPane spDelete;
    609         /** the panel containing the widgets for the lists of primitives */
    610         private JPanel pnlLists;
    611         /** checkbox for selecting whether an atomic upload is to be used  */
    612         private JCheckBox cbUseAtomicUpload;
    613         /** input field for changeset comment */
    614         private SuggestingJHistoryComboBox cmt;
    615         /** ui component for editing changeset tags */
    616         private TagEditorPanel tagEditorPanel;
    617         /** the tabbed pane used below of the list of primitives  */
    618         private JTabbedPane southTabbedPane;
    619         /** the button group with the changeset processing types */
    620         private ButtonGroup bgChangesetHandlingOptions;
    621         /** radio buttons for selecting a changeset processing type */
    622         private Map<ChangesetProcessingType, JRadioButton> rbChangesetHandlingOptions;
    623 
    624         /**
    625          * builds the panel with the lists of primitives
    626          *
    627          * @return the panel with the lists of primitives
    628          */
    629         protected JPanel buildListsPanel() {
    630             pnlLists = new JPanel();
    631             pnlLists.setLayout(new GridBagLayout());
    632             // we don't add the lists yet, see setUploadPrimivies()
    633             //
    634             return pnlLists;
    635         }
    636 
    637         /**
    638          * builds the panel with the ui components for controlling how the changeset
    639          * should be processed (opening/closing a changeset)
    640          *
    641          * @return the panel with the ui components for controlling how the changeset
    642          * should be processed
    643          */
    644         protected JPanel buildChangesetHandlingControlPanel() {
    645             JPanel pnl = new JPanel();
    646             pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS));
    647             bgChangesetHandlingOptions = new ButtonGroup();
    648             rbChangesetHandlingOptions = new HashMap<ChangesetProcessingType, JRadioButton>();
    649             ChangesetProcessingTypeChangedAction a = new ChangesetProcessingTypeChangedAction();
    650             for(ChangesetProcessingType type: ChangesetProcessingType.values()) {
    651                 rbChangesetHandlingOptions.put(type, new JRadioButton());
    652                 rbChangesetHandlingOptions.get(type).addActionListener(a);
    653             }
    654             JRadioButton rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_CLOSE);
    655             rb.setText(tr("Use a new changeset and close it"));
    656             rb.setToolTipText(tr("Select to upload the data using a new changeset and to close the changeset after the upload"));
    657 
    658             rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_LEAVE_OPEN);
    659             rb.setText(tr("Use a new changeset and leave it open"));
    660             rb.setToolTipText(tr("Select to upload the data using a new changeset and to leave the changeset open after the upload"));
    661 
    662             pnl.add(new JLabel(tr("Upload to a new or to an existing changeset?")));
    663             pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_CLOSE));
    664             pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_LEAVE_OPEN));
    665             pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_CLOSE));
    666             pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_LEAVE_OPEN));
    667 
    668             for(ChangesetProcessingType type: ChangesetProcessingType.values()) {
    669                 rbChangesetHandlingOptions.get(type).setVisible(false);
    670                 bgChangesetHandlingOptions.add(rbChangesetHandlingOptions.get(type));
    671             }
    672             return pnl;
    673         }
    674 
    675         /**
    676          * build the panel with the widgets for controlling how the changeset should be processed
    677          * (atomic upload or not, comment, opening/closing changeset)
    678          *
    679          * @return
    680          */
    681         protected JPanel buildChangesetControlPanel() {
    682             JPanel pnl = new JPanel();
    683             pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS));
    684             pnl.add(cbUseAtomicUpload = new JCheckBox(tr("upload all changes in one request")));
    685             cbUseAtomicUpload.setToolTipText(tr("Enable to upload all changes in one request, disable to use one request per changed primitive"));
    686             boolean useAtomicUpload = Main.pref.getBoolean("osm-server.atomic-upload", true);
    687             cbUseAtomicUpload.setSelected(useAtomicUpload);
    688             cbUseAtomicUpload.setEnabled(OsmApi.getOsmApi().hasSupportForDiffUploads());
    689 
    690             pnl.add(buildChangesetHandlingControlPanel());
    691             return pnl;
    692         }
    693 
    694         /**
    695          * builds the upload control panel
    696          *
    697          * @return
    698          */
    699         protected JPanel buildUploadControlPanel() {
    700             JPanel pnl = new JPanel();
    701             pnl.setLayout(new GridBagLayout());
    702             pnl.add(new JLabel(tr("Provide a brief comment for the changes you are uploading:")), GBC.eol().insets(0, 5, 10, 3));
    703             cmt = new SuggestingJHistoryComboBox();
    704             List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(HISTORY_KEY, new LinkedList<String>()));
    705             cmt.setHistory(cmtHistory);
    706             pnl.add(cmt, GBC.eol().fill(GBC.HORIZONTAL));
    707 
    708             // configuration options for atomic upload
    709             //
    710             pnl.add(buildChangesetControlPanel(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    711             return pnl;
    712         }
    713 
    714         /**
    715          * builds the gui
    716          */
    717         protected void build() {
    718             setLayout(new GridBagLayout());
    719             GridBagConstraints gc = new GridBagConstraints();
    720 
    721             // first the panel with the list in the upper half
    722             //
    723             gc.fill = GridBagConstraints.BOTH;
    724             gc.weightx = 1.0;
    725             gc.weighty = 1.0;
    726             add(buildListsPanel(), gc);
    727 
    728             // a tabbed pane with two configuration panels in the
    729             // lower half
    730             //
    731             southTabbedPane = new JTabbedPane();
    732             southTabbedPane.add(buildUploadControlPanel());
    733             tagEditorPanel = new TagEditorPanel();
    734             southTabbedPane.add(tagEditorPanel);
    735             southTabbedPane.setTitleAt(0, tr("Settings"));
    736             southTabbedPane.setTitleAt(1, tr("Tags of new changeset"));
    737             JPanel pnl = new JPanel();
    738             pnl.setLayout(new BorderLayout());
    739             pnl.add(southTabbedPane,BorderLayout.CENTER);
    740             gc.fill = GridBagConstraints.HORIZONTAL;
    741             gc.gridy = 1;
    742             gc.weightx = 1.0;
    743             gc.weighty = 0.0;
    744             add(pnl, gc);
    745         }
    746 
    747         /**
    748          * constructor
    749          */
    750         protected UploadDialogPanel() {
    751             OsmPrimitivRenderer renderer = new OsmPrimitivRenderer();
    752 
    753             // initialize the three lists for primitives
    754             //
    755             lstAdd = new JList();
    756             lstAdd.setCellRenderer(renderer);
    757             lstAdd.setVisibleRowCount(Math.min(lstAdd.getModel().getSize(), 10));
    758             spAdd = new JScrollPane(lstAdd);
    759             lblAdd = new JLabel(tr("Objects to add:"));
    760 
    761             lstUpdate = new JList();
    762             lstUpdate.setCellRenderer(renderer);
    763             lstUpdate.setVisibleRowCount(Math.min(lstUpdate.getModel().getSize(), 10));
    764             spUpdate = new JScrollPane(lstUpdate);
    765             lblUpdate = new JLabel(tr("Objects to modify:"));
    766 
    767             lstDelete = new JList();
    768             lstDelete.setCellRenderer(renderer);
    769             lstDelete.setVisibleRowCount(Math.min(lstDelete.getModel().getSize(), 10));
    770             spDelete = new JScrollPane(lstDelete);
    771             lblDelete = new JLabel(tr("Objects to delete:"));
    772 
    773             // build the GUI
    774             //
    775             build();
    776         }
    777 
    778         /**
    779          * sets the collection of primitives which will be uploaded
    780          *
    781          * @param add  the collection of primitives to add
    782          * @param update the collection of primitives to update
    783          * @param delete the collection of primitives to delete
    784          */
    785         public void setUploadedPrimitives(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) {
    786             lstAdd.setListData(add.toArray());
    787             lstUpdate.setListData(update.toArray());
    788             lstDelete.setListData(delete.toArray());
    789 
    790 
    791             GridBagConstraints gcLabel = new GridBagConstraints();
    792             gcLabel.fill = GridBagConstraints.HORIZONTAL;
    793             gcLabel.weightx = 1.0;
    794             gcLabel.weighty = 0.0;
    795             gcLabel.anchor = GridBagConstraints.FIRST_LINE_START;
    796 
    797             GridBagConstraints gcList = new GridBagConstraints();
    798             gcList.fill = GridBagConstraints.BOTH;
    799             gcList.weightx = 1.0;
    800             gcList.weighty = 1.0;
    801             gcList.anchor = GridBagConstraints.CENTER;
    802             pnlLists.removeAll();
    803             int y = -1;
    804             if (!add.isEmpty()) {
    805                 y++;
    806                 gcLabel.gridy = y;
    807                 lblAdd.setText(trn("{0} object to add:", "{0} objects to add:", add.size(),add.size()));
    808                 pnlLists.add(lblAdd, gcLabel);
    809                 y++;
    810                 gcList.gridy = y;
    811                 pnlLists.add(spAdd, gcList);
    812             }
    813             if (!update.isEmpty()) {
    814                 y++;
    815                 gcLabel.gridy = y;
    816                 lblUpdate.setText(trn("{0} object to modifiy:", "{0} objects to modify:", update.size(),update.size()));
    817                 pnlLists.add(lblUpdate, gcLabel);
    818                 y++;
    819                 gcList.gridy = y;
    820                 pnlLists.add(spUpdate, gcList);
    821             }
    822             if (!delete.isEmpty()) {
    823                 y++;
    824                 gcLabel.gridy = y;
    825                 lblDelete.setText(trn("{0} object to delete:", "{0} objects to delete:", delete.size(),delete.size()));
    826                 pnlLists.add(lblDelete, gcLabel);
    827                 y++;
    828                 gcList.gridy = y;
    829                 pnlLists.add(spDelete, gcList);
    830             }
    831         }
    832 
    833         /**
    834          * Replies true if a valid changeset comment has been entered in this dialog
    835          *
    836          * @return true if a valid changeset comment has been entered in this dialog
    837          */
    838         public boolean hasChangesetComment() {
    839             if (!getChangesetProcessingType().isUseNew())
    840                 return true;
    841             return cmt.getText().trim().length() >= 3;
    842         }
    843 
    844         /**
    845          * Remembers the user input in the preference settings
    846          */
    847         public void rememberUserInput() {
    848             // store the history of comments
    849             cmt.addCurrentItemToHistory();
    850             Main.pref.putCollection(HISTORY_KEY, cmt.getHistory());
    851             Main.pref.put("osm-server.atomic-upload", cbUseAtomicUpload.isSelected());
    852         }
    853 
    854         /**
    855          * Initializes the panel for user input
    856          */
    857         public void startUserInput() {
    858             tagEditorPanel.initAutoCompletion(Main.main.getEditLayer());
    859             initChangesetProcessingType();
    860             cmt.getEditor().selectAll();
    861             cmt.requestFocus();
    862         }
    863 
    864         /**
    865          * Replies the current changeset processing type
    866          *
    867          * @return the current changeset processing type
    868          */
    869         public ChangesetProcessingType getChangesetProcessingType() {
    870             ChangesetProcessingType changesetProcessingType = null;
    871             for (ChangesetProcessingType type: ChangesetProcessingType.values()) {
    872                 if (rbChangesetHandlingOptions.get(type).isSelected()) {
    873                     changesetProcessingType = type;
    874                     break;
    875                 }
    876             }
    877             return changesetProcessingType == null ?
    878                     ChangesetProcessingType.USE_NEW_AND_CLOSE :
    879                         changesetProcessingType;
    880         }
    881 
    882         /**
    883          * Replies the current changeset
    884          *
    885          * @return the current changeset
    886          */
    887         public Changeset getChangeset() {
    888             Changeset changeset = new Changeset();
    889             tagEditorPanel.getModel().applyToPrimitive(changeset);
    890             changeset.put("comment", cmt.getText());
    891             return changeset;
    892         }
    893 
    894         /**
    895          * initializes the panel depending on the possible changeset processing
    896          * types
    897          */
    898         protected void initChangesetProcessingType() {
    899             for (ChangesetProcessingType type: ChangesetProcessingType.values()) {
    900                 // show options for new changeset, disable others
    901                 //
    902                 rbChangesetHandlingOptions.get(type).setVisible(type.isUseNew());
    903             }
    904             if (OsmApi.getOsmApi().getCurrentChangeset() != null) {
    905                 Changeset cs = OsmApi.getOsmApi().getCurrentChangeset();
    906                 for (ChangesetProcessingType type: ChangesetProcessingType.values()) {
    907                     // show options for using existing changeset
    908                     //
    909                     if (!type.isUseNew()) {
    910                         rbChangesetHandlingOptions.get(type).setVisible(true);
    911                     }
    912                 }
    913                 JRadioButton rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_CLOSE);
    914                 rb.setText(tr("Use the existing changeset {0} and close it after upload",cs.getId()));
    915                 rb.setToolTipText(tr("Select to upload to the existing changeset {0} and to close the changeset after this upload",cs.getId()));
    916 
    917                 rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_LEAVE_OPEN);
    918                 rb.setText(tr("Use the existing changeset {0} and leave it open",cs.getId()));
    919                 rb.setToolTipText(tr("Select to upload to the existing changeset {0} and to leave the changeset open for further uploads",cs.getId()));
    920 
    921                 rbChangesetHandlingOptions.get(getChangesetProcessingType()).setSelected(true);
    922 
    923             } else {
    924                 ChangesetProcessingType type = getChangesetProcessingType();
    925                 if (!type.isUseNew()) {
    926                     type = ChangesetProcessingType.USE_NEW_AND_CLOSE;
    927                 }
    928                 rbChangesetHandlingOptions.get(type).setSelected(true);
    929             }
    930             refreshChangesetProcessingType(getChangesetProcessingType());
    931         }
    932 
    933         /**
    934          * refreshes  the panel depending on a changeset processing type
    935          *
    936          * @param type the changeset processing type
    937          */
    938         protected void refreshChangesetProcessingType(ChangesetProcessingType type) {
    939             if (type.isUseNew()) {
    940                 southTabbedPane.setTitleAt(1, tr("Tags of new changeset"));
    941                 Changeset cs = new Changeset();
    942                 Properties sysProp = System.getProperties();
    943                 Object ua = sysProp.get("http.agent");
    944                 cs.put("created_by", (ua == null) ? "JOSM" : ua.toString());
    945                 tagEditorPanel.getModel().initFromPrimitive(cs);
    946             } else {
    947                 Changeset cs = OsmApi.getOsmApi().getCurrentChangeset();
    948                 if (cs != null) {
    949                     southTabbedPane.setTitleAt(1, tr("Tags of changeset {0}", cs.getId()));
    950                     if (cs.get("comment") != null) {
    951                         cmt.setText(cs.get("comment"));
    952                         cs.remove("comment");
    953                     }
    954                     tagEditorPanel.getModel().initFromPrimitive(cs);
    955                 }
    956             }
    957         }
    958 
    959         class ChangesetProcessingTypeChangedAction implements ActionListener {
    960             public void actionPerformed(ActionEvent e) {
    961                 ChangesetProcessingType type = getChangesetProcessingType();
    962                 refreshChangesetProcessingType(type);
    963             }
    964         }
    965     }
    966550}
  • trunk/src/org/openstreetmap/josm/data/osm/Changeset.java

    r2070 r2081  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import javax.print.attribute.standard.MediaSize.Other;
    57
    68import org.openstreetmap.josm.data.osm.visitor.Visitor;
     
    2325     */
    2426    public String start_timestamp = null;
     27
     28    public Changeset() {
     29        super(0);
     30    }
     31
     32    public Changeset(long id) {
     33        super(id);
     34    }
     35
     36    public Changeset(Changeset clone){
     37        super(clone.getId());
     38        cloneFrom(clone);
     39    }
    2540
    2641    @Override
     
    4964        return formatter.format(this);
    5065    }
     66
     67
     68    @Override public void cloneFrom(OsmPrimitive osm) {
     69        super.cloneFrom(osm);
     70    }
    5171}
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r2063 r2081  
    8787        }
    8888
    89         Main.pref.init(args.containsKey("reset-preferences"));
    90 
    9189        // Check if passed as parameter
    9290        if (args.containsKey("language")) {
     
    9593            I18n.set(Main.pref.get("language", null));
    9694        }
     95
     96        Main.pref.init(args.containsKey("reset-preferences"));
     97
    9798
    9899        if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
     
    115116                    "\t-Djosm.home="+tr("/PATH/TO/JOSM/FOLDER/         ")+tr("Change the folder for all user settings")+"\n\n"+
    116117                    tr("note: For some tasks, JOSM needs a lot of memory. It can be necessary to add the following\n" +
    117                        "      Java option to increase the maximum size of allocated memory")+":\n"+
     118                    "      Java option to increase the maximum size of allocated memory")+":\n"+
    118119                    "\t-Xmx...m\n\n"+
    119120                    tr("examples")+":\n"+
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java

    r2040 r2081  
    299299        public void cancel() {
    300300            switch(model.getMode()) {
    301                 case EDITING_DATA: cancelWhenInEditingModel(); break;
    302                 case UPLOADING_AND_SAVING: cancelSafeAndUploadTask(); break;
     301            case EDITING_DATA: cancelWhenInEditingModel(); break;
     302            case UPLOADING_AND_SAVING: cancelSafeAndUploadTask(); break;
    303303            }
    304304        }
     
    334334                Mode mode = (Mode)evt.getNewValue();
    335335                switch(mode) {
    336                     case EDITING_DATA: setEnabled(true); break;
    337                     case UPLOADING_AND_SAVING: setEnabled(false); break;
     336                case EDITING_DATA: setEnabled(true); break;
     337                case UPLOADING_AND_SAVING: setEnabled(false); break;
    338338                }
    339339            }
     
    368368                SaveLayersModel.Mode mode = (SaveLayersModel.Mode)evt.getNewValue();
    369369                switch(mode) {
    370                     case EDITING_DATA: setEnabled(true); break;
    371                     case UPLOADING_AND_SAVING: setEnabled(false); break;
     370                case EDITING_DATA: setEnabled(true); break;
     371                case UPLOADING_AND_SAVING: setEnabled(false); break;
    372372                }
    373373            }
     
    411411                        layerInfo.getLayer(),
    412412                        monitor,
    413                         UploadAction.UploadConfirmationHook.getUploadDialogPanel().getChangeset(),
    414                         UploadAction.UploadConfirmationHook.getUploadDialogPanel().getChangesetProcessingType()
     413                        UploadAction.UploadConfirmationHook.getUploadDialog().getChangeset(),
     414                        UploadAction.UploadConfirmationHook.getUploadDialog().getChangesetProcessingType()
    415415                );
    416416                currentFuture = worker.submit(currentTask);
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r2040 r2081  
    99import java.util.Collection;
    1010import java.util.Comparator;
     11import java.util.Iterator;
    1112import java.util.List;
    1213import java.util.logging.Logger;
     
    216217
    217218    /**
     219     * Deletes all tags with name <code>name</code>
     220     *
     221     * @param name the name. Ignored if null.
     222     */
     223    public void delete(String name) {
     224        if (name == null) return;
     225        Iterator<TagModel> it = tags.iterator();
     226        while(it.hasNext()) {
     227            TagModel tm = it.next();
     228            if (tm.getName().equals(name)) {
     229                it.remove();
     230            }
     231        }
     232        fireTableDataChanged();
     233        setDirty(true);
     234    }
     235    /**
    218236     * deletes the tags given by tagIndices
    219237     *
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r2078 r2081  
    77import java.util.Collection;
    88import java.util.LinkedList;
    9 import java.util.List;
    109import java.util.logging.Logger;
    1110
    1211import org.openstreetmap.josm.Main;
    13 import org.openstreetmap.josm.actions.UploadAction;
    1412import org.openstreetmap.josm.data.osm.Changeset;
    1513import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6159        time_left_str += Integer.toString(seconds_left);
    6260        return time_left_str;
    63     }
    64 
    65     /**
    66      * retrieves the most recent changeset comment from the preferences
    67      *
    68      * @return the most recent changeset comment
    69      */
    70     protected String getChangesetComment() {
    71         String cmt = "";
    72         List<String> history = new LinkedList<String>(
    73                 Main.pref.getCollection(UploadAction.HISTORY_KEY, new LinkedList<String>()));
    74         if(history.size() > 0) {
    75             cmt = history.get(0);
    76         }
    77         return cmt;
    7861    }
    7962
Note: See TracChangeset for help on using the changeset viewer.