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/actions
Files:
3 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}
Note: See TracChangeset for help on using the changeset viewer.