- Timestamp:
- 2009-09-04T07:54:40+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r2045 r2046 9 9 import java.awt.GridBagLayout; 10 10 import java.awt.event.ActionEvent; 11 import java.awt.event.ActionListener; 11 12 import java.awt.event.KeyEvent; 12 13 import java.io.IOException; 13 14 import java.net.HttpURLConnection; 14 15 import java.util.Collection; 16 import java.util.HashMap; 15 17 import java.util.LinkedList; 16 18 import java.util.List; 19 import java.util.Map; 17 20 import java.util.logging.Logger; 18 21 import java.util.regex.Matcher; … … 54 57 import org.openstreetmap.josm.tools.WindowGeometry; 55 58 import org.xml.sax.SAXException; 59 60 import com.sun.corba.se.spi.orbutil.fsm.Action; 56 61 57 62 … … 596 601 private JTabbedPane southTabbedPane; 597 602 private ButtonGroup bgChangesetHandlingOptions; 598 private JRadioButton rbUseNewAndClose; 599 private JRadioButton rbUseNewAndLeaveOpen; 600 private JRadioButton rbUseExistingAndClose; 601 private JRadioButton rbUseExistingAndLeaveOpen; 602 private ChangesetProcessingType changesetProcessingType; 603 private Map<ChangesetProcessingType, JRadioButton> rbChangesetHandlingOptions; 603 604 604 605 protected JPanel buildListsPanel() { … … 613 614 pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS)); 614 615 bgChangesetHandlingOptions = new ButtonGroup(); 615 616 rbUseNewAndClose = new JRadioButton(tr("Use a new changeset and close it")); 617 rbUseNewAndClose.setToolTipText(tr("Select to upload the data using a new changeset and to close the changeset after the upload")); 618 619 rbUseNewAndLeaveOpen = new JRadioButton(tr("Use a new changeset and leave it open")); 620 rbUseNewAndLeaveOpen.setToolTipText(tr("Select to upload the data using a new changeset and to leave the changeset open after the upload")); 621 622 rbUseExistingAndClose = new JRadioButton(); 623 rbUseExistingAndLeaveOpen = new JRadioButton(); 616 rbChangesetHandlingOptions = new HashMap<ChangesetProcessingType, JRadioButton>(); 617 ChangesetProcessingTypeChangedAction a = new ChangesetProcessingTypeChangedAction(); 618 for(ChangesetProcessingType type: ChangesetProcessingType.values()) { 619 rbChangesetHandlingOptions.put(type, new JRadioButton()); 620 rbChangesetHandlingOptions.get(type).addActionListener(a); 621 } 622 JRadioButton rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_CLOSE); 623 rb.setText(tr("Use a new changeset and close it")); 624 rb.setToolTipText(tr("Select to upload the data using a new changeset and to close the changeset after the upload")); 625 626 rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_LEAVE_OPEN); 627 rb.setText(tr("Use a new changeset and leave it open")); 628 rb.setToolTipText(tr("Select to upload the data using a new changeset and to leave the changeset open after the upload")); 624 629 625 630 pnl.add(new JLabel(tr("Upload to a new or to an existing changeset?"))); 626 pnl.add(rbUseNewAndClose); 627 pnl.add(rbUseNewAndLeaveOpen); 628 pnl.add(rbUseExistingAndClose); 629 pnl.add(rbUseExistingAndLeaveOpen); 630 631 rbUseNewAndClose.setVisible(false); 632 rbUseNewAndLeaveOpen.setVisible(false); 633 rbUseExistingAndClose.setVisible(false); 634 rbUseExistingAndLeaveOpen.setVisible(false); 635 636 bgChangesetHandlingOptions.add(rbUseNewAndClose); 637 bgChangesetHandlingOptions.add(rbUseNewAndLeaveOpen); 638 bgChangesetHandlingOptions.add(rbUseExistingAndClose); 639 bgChangesetHandlingOptions.add(rbUseExistingAndLeaveOpen); 631 pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_CLOSE)); 632 pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_NEW_AND_LEAVE_OPEN)); 633 pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_CLOSE)); 634 pnl.add(rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_LEAVE_OPEN)); 635 636 for(ChangesetProcessingType type: ChangesetProcessingType.values()) { 637 rbChangesetHandlingOptions.get(type).setVisible(false); 638 bgChangesetHandlingOptions.add(rbChangesetHandlingOptions.get(type)); 639 } 640 640 return pnl; 641 641 } … … 682 682 southTabbedPane.add(tagEditorPanel); 683 683 southTabbedPane.setTitleAt(0, tr("Settings")); 684 southTabbedPane.setTitleAt(1, tr(" Changeset Tags"));684 southTabbedPane.setTitleAt(1, tr("Tags of new changeset")); 685 685 JPanel pnl = new JPanel(); 686 686 pnl.setLayout(new BorderLayout()); … … 765 765 Main.pref.putCollection(HISTORY_KEY, cmt.getHistory()); 766 766 Main.pref.put("osm-server.atomic-upload", cbUseAtomicUpload.isSelected()); 767 768 if (rbUseNewAndClose.isSelected()) {769 changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE;770 } else if (rbUseNewAndLeaveOpen.isSelected()) {771 changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_LEAVE_OPEN;772 } else if (rbUseExistingAndClose.isSelected()) {773 changesetProcessingType = ChangesetProcessingType.USE_EXISTING_AND_CLOSE;774 } else if (rbUseExistingAndLeaveOpen.isSelected()) {775 changesetProcessingType = ChangesetProcessingType.USE_EXISTING_AND_LEAVE_OPEN;776 }777 767 } 778 768 779 769 public void startUserInput() { 780 rbUseNewAndClose.setVisible(true); 781 rbUseNewAndLeaveOpen.setVisible(true); 782 if (OsmApi.getOsmApi().getCurrentChangeset() != null) { 783 Changeset cs = OsmApi.getOsmApi().getCurrentChangeset(); 784 rbUseExistingAndClose.setVisible(true); 785 rbUseExistingAndLeaveOpen.setVisible(true); 786 787 rbUseExistingAndClose.setText(tr("Use the existing changeset {0} and close it after upload",cs.getId())); 788 rbUseExistingAndClose.setToolTipText(tr("Select to upload to the existing changeset {0} and to close the changeset after this upload",cs.getId())); 789 790 rbUseExistingAndLeaveOpen.setText(tr("Use the existing changeset {0} and leave it open",cs.getId())); 791 rbUseExistingAndLeaveOpen.setToolTipText(tr("Select to upload to the existing changeset {0} and to leave the changeset open for further uploads",cs.getId())); 792 793 if (changesetProcessingType == null) { 794 rbUseNewAndClose.setSelected(true); 795 } else { 796 switch(changesetProcessingType) { 797 case USE_NEW_AND_CLOSE: rbUseNewAndClose.setSelected(true); break; 798 case USE_NEW_AND_LEAVE_OPEN: rbUseNewAndLeaveOpen.setSelected(true); break; 799 case USE_EXISTING_AND_CLOSE: rbUseExistingAndClose.setSelected(true); break; 800 case USE_EXISTING_AND_LEAVE_OPEN: rbUseExistingAndLeaveOpen.setSelected(true); break; 801 } 802 } 803 } else { 804 if (changesetProcessingType == null) { 805 changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE; 806 } 807 rbUseExistingAndClose.setVisible(false); 808 rbUseExistingAndLeaveOpen.setVisible(false); 809 switch(changesetProcessingType) { 810 case USE_NEW_AND_CLOSE: rbUseNewAndClose.setSelected(true); break; 811 case USE_NEW_AND_LEAVE_OPEN: rbUseNewAndLeaveOpen.setSelected(true); break; 812 default: rbUseNewAndClose.setSelected(true); break; 813 } 814 } 770 tagEditorPanel.initAutoCompletion(Main.main.getEditLayer()); 771 initChangesetProcessingType(); 815 772 cmt.getEditor().selectAll(); 816 773 cmt.requestFocus(); … … 818 775 819 776 public ChangesetProcessingType getChangesetProcessingType() { 820 if (changesetProcessingType == null) return ChangesetProcessingType.USE_NEW_AND_CLOSE; 821 return changesetProcessingType; 777 ChangesetProcessingType changesetProcessingType = null; 778 for (ChangesetProcessingType type: ChangesetProcessingType.values()) { 779 if (rbChangesetHandlingOptions.get(type).isSelected()) { 780 changesetProcessingType = type; 781 break; 782 } 783 } 784 return changesetProcessingType == null ? 785 ChangesetProcessingType.USE_NEW_AND_CLOSE : 786 changesetProcessingType; 822 787 } 823 788 … … 828 793 return changeset; 829 794 } 795 796 protected void initChangesetProcessingType() { 797 for (ChangesetProcessingType type: ChangesetProcessingType.values()) { 798 // show options for new changeset, disable others 799 // 800 rbChangesetHandlingOptions.get(type).setVisible(type.isUseNew()); 801 } 802 if (OsmApi.getOsmApi().getCurrentChangeset() != null) { 803 Changeset cs = OsmApi.getOsmApi().getCurrentChangeset(); 804 for (ChangesetProcessingType type: ChangesetProcessingType.values()) { 805 // show options for using existing changeset 806 // 807 if (!type.isUseNew()) { 808 rbChangesetHandlingOptions.get(type).setVisible(true); 809 } 810 } 811 JRadioButton rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_CLOSE); 812 rb.setText(tr("Use the existing changeset {0} and close it after upload",cs.getId())); 813 rb.setToolTipText(tr("Select to upload to the existing changeset {0} and to close the changeset after this upload",cs.getId())); 814 815 rb = rbChangesetHandlingOptions.get(ChangesetProcessingType.USE_EXISTING_AND_LEAVE_OPEN); 816 rb.setText(tr("Use the existing changeset {0} and leave it open",cs.getId())); 817 rb.setToolTipText(tr("Select to upload to the existing changeset {0} and to leave the changeset open for further uploads",cs.getId())); 818 819 rbChangesetHandlingOptions.get(getChangesetProcessingType()).setSelected(true); 820 821 } else { 822 ChangesetProcessingType type = getChangesetProcessingType(); 823 if (!type.isUseNew()) { 824 type = ChangesetProcessingType.USE_NEW_AND_CLOSE; 825 } 826 rbChangesetHandlingOptions.get(type).setSelected(true); 827 } 828 } 829 830 class ChangesetProcessingTypeChangedAction implements ActionListener { 831 public void actionPerformed(ActionEvent e) { 832 ChangesetProcessingType type = getChangesetProcessingType(); 833 if (type.isUseNew()) { 834 tagEditorPanel.setEnabled(true); 835 southTabbedPane.setTitleAt(1, tr("Tags of new changeset")); 836 cmt.setEnabled(true); 837 } else { 838 tagEditorPanel.setEnabled(false); 839 cmt.setEnabled(false); 840 Changeset cs = OsmApi.getOsmApi().getCurrentChangeset(); 841 if (cs != null) { 842 tagEditorPanel.getModel().initFromPrimitive(cs); 843 southTabbedPane.setTitleAt(1, tr("Tags of changeset {0} (read-only)", cs.getId())); 844 cmt.setText(cs.get("comment" == null ? "" : cs.get("comment"))); 845 } 846 } 847 } 848 } 830 849 } 831 850 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java
r2040 r2046 5 5 6 6 import java.awt.BorderLayout; 7 import java.awt.Component; 7 8 import java.awt.GridBagConstraints; 8 9 import java.awt.GridBagLayout; 9 10 import java.awt.event.ActionEvent; 11 import java.beans.PropertyChangeEvent; 12 import java.beans.PropertyChangeListener; 10 13 11 14 import javax.swing.AbstractAction; … … 17 20 import javax.swing.event.ListSelectionListener; 18 21 22 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionCache; 23 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList; 24 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 19 25 import org.openstreetmap.josm.tools.ImageProvider; 20 26 27 /** 28 * TagEditorPanel is a {@see JPanel} which can be embedded as UI component in 29 * UIs. It provides a spreadsheet like tabular control for editing tag names 30 * and tag values. Two action buttons are placed on the left, one for additing 31 * a new tag and one for deleting the currently selected tags. 32 * 33 * 34 */ 21 35 public class TagEditorPanel extends JPanel { 36 /** the tag editor model */ 22 37 private TagEditorModel model; 38 /** the tag table */ 23 39 private TagTable tagTable; 24 40 41 private AutoCompletionCache acCache; 42 private AutoCompletionList acList; 43 44 45 /** 46 * builds the panel with the table for editing tags 47 * 48 * @return the panel 49 */ 25 50 protected JPanel buildTagTableEditorPanel() { 51 26 52 JPanel pnl = new JPanel(); 27 53 model = new TagEditorModel(); … … 33 59 } 34 60 61 /** 62 * builds the panel with the button row 63 * 64 * @return the panel 65 */ 35 66 protected JPanel buildButtonsPanel() { 36 67 JPanel pnl = new JPanel(); … … 41 72 AddAction addAction = new AddAction(); 42 73 pnl.add(new JButton(addAction)); 74 tagTable.addPropertyChangeListener(addAction); 43 75 44 76 // delete action … … 46 78 DeleteAction deleteAction = new DeleteAction(); 47 79 tagTable.getSelectionModel().addListSelectionListener(deleteAction); 80 tagTable.addPropertyChangeListener(deleteAction); 48 81 pnl.add(new JButton(deleteAction)); 49 82 return pnl; 50 83 } 51 84 85 /** 86 * builds the GUI 87 */ 52 88 protected void build() { 53 89 setLayout(new GridBagLayout()); … … 74 110 add(tablePanel,gc); 75 111 } 112 113 /** 114 * constructor 115 */ 76 116 public TagEditorPanel() { 77 117 build(); 78 118 } 79 119 120 /** 121 * Replies the tag editor model used by this panel. 122 * 123 * @return the tag editor model used by this panel 124 */ 80 125 public TagEditorModel getModel() { 81 126 return model; 82 127 } 83 128 84 class AddAction extends AbstractAction { 129 /** 130 * The action for adding a tag 131 * 132 */ 133 class AddAction extends AbstractAction implements PropertyChangeListener { 85 134 public AddAction() { 86 135 putValue(SMALL_ICON, ImageProvider.get("dialogs", "add")); 87 136 putValue(SHORT_DESCRIPTION, tr("Add a new tag")); 88 } 137 updateEnabledState(); 138 } 139 89 140 public void actionPerformed(ActionEvent e) { 90 141 model.appendNewTag(); 91 142 } 92 } 93 94 class DeleteAction extends AbstractAction implements ListSelectionListener { 143 144 protected void updateEnabledState() { 145 setEnabled(tagTable.isEnabled()); 146 } 147 148 public void propertyChange(PropertyChangeEvent evt) { 149 updateEnabledState(); 150 } 151 } 152 153 /** 154 * The action for deleting the currently selected tags 155 * 156 * 157 */ 158 class DeleteAction extends AbstractAction implements ListSelectionListener, PropertyChangeListener { 95 159 public DeleteAction() { 96 160 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); … … 137 201 // should not happen 138 202 // 139 throw new IllegalStateException("unexpected selected c lolumn: getSelectedColumn() is "203 throw new IllegalStateException("unexpected selected column: getSelectedColumn() is " 140 204 + tagTable.getSelectedColumn()); 141 205 } else if (tagTable.getSelectedColumnCount() == 2) { … … 148 212 149 213 public void updateEnabledState() { 150 setEnabled(tagTable.getSelectedRowCount() > 0 || tagTable.getSelectedColumnCount() >0); 214 setEnabled(tagTable.isEnabled() && 215 (tagTable.getSelectedRowCount() > 0 || tagTable.getSelectedColumnCount() >0)); 151 216 } 152 217 public void valueChanged(ListSelectionEvent e) { 153 218 updateEnabledState(); 154 219 } 220 221 public void propertyChange(PropertyChangeEvent evt) { 222 updateEnabledState(); 223 } 224 } 225 226 public void initAutoCompletion(OsmDataLayer layer) { 227 // initialize the autocompletion infrastructure 228 // 229 acCache = AutoCompletionCache.getCacheForLayer(layer); 230 acCache.initFromJOSMDataset(); 231 acList = new AutoCompletionList(); 232 233 TagCellEditor editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(0).getCellEditor()); 234 editor.setAutoCompletionCache(acCache); 235 editor.setAutoCompletionList(acList); 236 editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(1).getCellEditor()); 237 editor.setAutoCompletionCache(acCache); 238 editor.setAutoCompletionList(acList); 239 } 240 241 @Override 242 public void setEnabled(boolean enabled) { 243 tagTable.setEnabled(enabled); 244 super.setEnabled(enabled); 155 245 } 156 246 }
Note:
See TracChangeset
for help on using the changeset viewer.