Changeset 2037 in josm for trunk/src/org
- Timestamp:
- 2009-09-03T14:13:22+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r2035 r2037 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.BorderLayout; 7 import java.awt.Dimension; 6 8 import java.awt.FlowLayout; 7 9 import java.awt.GridBagConstraints; … … 44 46 import org.openstreetmap.josm.tools.GBC; 45 47 import org.openstreetmap.josm.tools.Shortcut; 48 import org.openstreetmap.josm.tools.WindowGeometry; 46 49 import org.xml.sax.SAXException; 47 50 … … 438 441 class UploadConfirmationHook implements UploadHook { 439 442 440 private JCheckBox cbUseAtomicUpload;441 442 protected JPanel buildChangesetControlPanel() {443 JPanel pnl = new JPanel();444 pnl.setLayout(new FlowLayout(FlowLayout.LEFT));445 pnl.add(cbUseAtomicUpload = new JCheckBox(tr("upload all changes in one request")));446 cbUseAtomicUpload.setToolTipText(tr("Enable to upload all changes in one request, disable to use one request per changed primitive"));447 boolean useAtomicUpload = Main.pref.getBoolean("osm-server.atomic-upload", true);448 cbUseAtomicUpload.setSelected(useAtomicUpload);449 cbUseAtomicUpload.setEnabled(OsmApi.getOsmApi().hasChangesetSupport());450 return pnl;451 }452 443 453 444 public boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) { 454 455 JPanel p = new JPanel(new GridBagLayout()); 456 457 OsmPrimitivRenderer renderer = new OsmPrimitivRenderer(); 458 459 if (!add.isEmpty()) { 460 p.add(new JLabel(tr("Objects to add:")), GBC.eol()); 461 JList l = new JList(add.toArray()); 462 l.setCellRenderer(renderer); 463 l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10); 464 p.add(new JScrollPane(l), GBC.eol().fill()); 465 } 466 467 if (!update.isEmpty()) { 468 p.add(new JLabel(tr("Objects to modify:")), GBC.eol()); 469 JList l = new JList(update.toArray()); 470 l.setCellRenderer(renderer); 471 l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10); 472 p.add(new JScrollPane(l), GBC.eol().fill()); 473 } 474 475 if (!delete.isEmpty()) { 476 p.add(new JLabel(tr("Objects to delete:")), GBC.eol()); 477 JList l = new JList(delete.toArray()); 478 l.setCellRenderer(renderer); 479 l.setVisibleRowCount(l.getModel().getSize() < 6 ? l.getModel().getSize() : 10); 480 p.add(new JScrollPane(l), GBC.eol().fill()); 481 } 482 483 p.add(new JLabel(tr("Provide a brief comment for the changes you are uploading:")), GBC.eol().insets(0, 5, 10, 3)); 484 SuggestingJHistoryComboBox cmt = new SuggestingJHistoryComboBox(); 485 List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(HISTORY_KEY, new LinkedList<String>())); 486 cmt.setHistory(cmtHistory); 487 p.add(cmt, GBC.eol().fill(GBC.HORIZONTAL)); 488 //final JTextField cmt = new JTextField(lastCommitComment); 489 490 // configuration options for atomic upload 491 p.add(buildChangesetControlPanel(), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 492 445 final UploadDialogPanel panel = new UploadDialogPanel(add, update, delete); 446 447 ExtendedDialog dialog = new ExtendedDialog( 448 Main.parent, 449 tr("Upload these changes?"), 450 new String[] {tr("Upload Changes"), tr("Cancel")} 451 ) { 452 @Override 453 public void setVisible(boolean visible) { 454 if (visible) { 455 new WindowGeometry( 456 panel.getClass().getName(), 457 WindowGeometry.centerInWindow(JOptionPane.getFrameForComponent(Main.parent), new Dimension(400,400)) 458 ).apply(this); 459 panel.startUserInput(); 460 } else { 461 new WindowGeometry(this).remember(panel.getClass().getName()); 462 } 463 super.setVisible(visible); 464 } 465 }; 466 467 dialog.setButtonIcons(new String[] {"upload.png", "cancel.png"}); 468 dialog.setContent(panel, false /* no scroll pane */); 493 469 while(true) { 494 ExtendedDialog dialog = new ExtendedDialog(495 Main.parent,496 tr("Upload these changes?"),497 new String[] {tr("Upload Changes"), tr("Cancel")}498 );499 dialog.setButtonIcons(new String[] {"upload.png", "cancel.png"});500 dialog.setContent(p, false /* no scroll pane */);501 470 dialog.showDialog(); 502 471 int result = dialog.getValue(); 503 504 505 472 // cancel pressed 506 473 if (result != 1) return false; 507 508 474 // don't allow empty commit message 509 if ( cmt.getText().trim().length() < 3) {475 if (! panel.hasChangesetComment()) { 510 476 continue; 511 477 } 512 513 // store the history of comments 514 cmt.addCurrentItemToHistory(); 515 Main.pref.putCollection(HISTORY_KEY, cmt.getHistory()); 516 Main.pref.put("osm-server.atomic-upload", cbUseAtomicUpload.isSelected()); 517 478 panel.rememberUserInput(); 518 479 break; 519 480 } … … 573 534 uploadCancelled = true; 574 535 if (writer != null) { 575 writer. disconnectActiveConnection();536 writer.cancel(); 576 537 } 577 538 } … … 589 550 } 590 551 } 552 553 /** 554 * The panel displaying information about primitives to upload and providing 555 * UI widgets for entering the changeset comment and other configuration 556 * setttings. 557 * 558 */ 559 static private class UploadDialogPanel extends JPanel { 560 561 private JList lstAdd; 562 private JList lstUpdate; 563 private JList lstDelete; 564 private JCheckBox cbUseAtomicUpload; 565 private SuggestingJHistoryComboBox cmt; 566 567 protected int getNumLists() { 568 int ret = 0; 569 if (lstAdd.getModel().getSize() > 0) { 570 ret++; 571 } 572 if (lstUpdate.getModel().getSize() > 0) { 573 ret++; 574 } 575 if (lstDelete.getModel().getSize() > 0) { 576 ret++; 577 } 578 return ret; 579 } 580 581 protected JPanel buildListsPanel() { 582 JPanel pnl = new JPanel(); 583 pnl.setLayout(new GridBagLayout()); 584 585 GridBagConstraints gcLabel = new GridBagConstraints(); 586 gcLabel.fill = GridBagConstraints.HORIZONTAL; 587 gcLabel.weightx = 1.0; 588 gcLabel.weighty = 0.0; 589 gcLabel.anchor = GridBagConstraints.FIRST_LINE_START; 590 591 GridBagConstraints gcList = new GridBagConstraints(); 592 gcList.fill = GridBagConstraints.BOTH; 593 gcList.weightx = 1.0; 594 gcList.weighty = 1.0 / getNumLists(); 595 gcList.anchor = GridBagConstraints.CENTER; 596 597 int y = -1; 598 599 if (lstAdd.getModel().getSize() >0) { 600 y++; 601 gcLabel.gridy = y; 602 pnl.add(new JLabel(tr("Objects to add:")), gcLabel); 603 y++; 604 gcList.gridy = y; 605 pnl.add(new JScrollPane(lstAdd), gcList); 606 } 607 if (lstUpdate.getModel().getSize() >0) { 608 y++; 609 gcLabel.gridy = y; 610 pnl.add(new JLabel(tr("Objects to modify:")), gcLabel); 611 y++; 612 gcList.gridy = y; 613 pnl.add(new JScrollPane(lstUpdate), gcList); 614 } 615 if (lstDelete.getModel().getSize() >0) { 616 y++; 617 gcLabel.gridy = y; 618 pnl.add(new JLabel(tr("Objects to delete:")), gcLabel); 619 y++; 620 gcList.gridy = y; 621 pnl.add(new JScrollPane(lstDelete), gcList); 622 } 623 return pnl; 624 } 625 626 protected JPanel buildChangesetControlPanel() { 627 JPanel pnl = new JPanel(); 628 pnl.setLayout(new FlowLayout(FlowLayout.LEFT)); 629 pnl.add(cbUseAtomicUpload = new JCheckBox(tr("upload all changes in one request"))); 630 cbUseAtomicUpload.setToolTipText(tr("Enable to upload all changes in one request, disable to use one request per changed primitive")); 631 boolean useAtomicUpload = Main.pref.getBoolean("osm-server.atomic-upload", true); 632 cbUseAtomicUpload.setSelected(useAtomicUpload); 633 cbUseAtomicUpload.setEnabled(OsmApi.getOsmApi().hasChangesetSupport()); 634 return pnl; 635 } 636 637 protected JPanel buildUploadControlPanel() { 638 JPanel pnl = new JPanel(); 639 pnl.setLayout(new GridBagLayout()); 640 pnl.add(new JLabel(tr("Provide a brief comment for the changes you are uploading:")), GBC.eol().insets(0, 5, 10, 3)); 641 cmt = new SuggestingJHistoryComboBox(); 642 List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(HISTORY_KEY, new LinkedList<String>())); 643 cmt.setHistory(cmtHistory); 644 pnl.add(cmt, GBC.eol().fill(GBC.HORIZONTAL)); 645 646 // configuration options for atomic upload 647 // 648 pnl.add(buildChangesetControlPanel(), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 649 return pnl; 650 } 651 652 protected void build() { 653 setLayout(new BorderLayout()); 654 add(buildListsPanel(), BorderLayout.CENTER); 655 add(buildUploadControlPanel(), BorderLayout.SOUTH); 656 } 657 658 public UploadDialogPanel(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) { 659 OsmPrimitivRenderer renderer = new OsmPrimitivRenderer(); 660 661 lstAdd = new JList(add.toArray()); 662 lstAdd.setCellRenderer(renderer); 663 lstAdd.setVisibleRowCount(Math.min(lstAdd.getModel().getSize(), 10)); 664 665 lstUpdate = new JList(update.toArray()); 666 lstUpdate.setCellRenderer(renderer); 667 lstUpdate.setVisibleRowCount(Math.min(lstUpdate.getModel().getSize(), 10)); 668 669 lstDelete = new JList(update.toArray()); 670 lstDelete.setCellRenderer(renderer); 671 lstDelete.setVisibleRowCount(Math.min(lstDelete.getModel().getSize(), 10)); 672 build(); 673 } 674 675 public boolean hasChangesetComment() { 676 return cmt.getText().trim().length() >= 3; 677 } 678 679 public void rememberUserInput() { 680 // store the history of comments 681 cmt.addCurrentItemToHistory(); 682 Main.pref.putCollection(HISTORY_KEY, cmt.getHistory()); 683 Main.pref.put("osm-server.atomic-upload", cbUseAtomicUpload.isSelected()); 684 } 685 686 public void startUserInput() { 687 cmt.getEditor().selectAll(); 688 cmt.requestFocus(); 689 } 690 } 591 691 } -
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r2035 r2037 48 48 49 49 // For easy access when inherited 50 protected Object contentConstraints = GBC.eol().anchor(GBC.CENTER).fill(GBC. HORIZONTAL).insets(5,10,5,0);50 protected Object contentConstraints = GBC.eol().anchor(GBC.CENTER).fill(GBC.BOTH).insets(5,10,5,0); 51 51 protected ArrayList<JButton> buttons = new ArrayList<JButton>(); 52 52 -
trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java
r2025 r2037 83 83 setCancelled(true); 84 84 if (writer != null) { 85 writer. disconnectActiveConnection();85 writer.cancel(); 86 86 } 87 87 } -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r2035 r2037 160 160 if (initialized) 161 161 return; 162 cancel = false; 162 163 initAuthentication(); 163 164 try { -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r2015 r2037 23 23 import org.openstreetmap.josm.Main; 24 24 import org.openstreetmap.josm.gui.ExtendedDialog; 25 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 26 import org.openstreetmap.josm.tools.Base64; 26 27 import org.openstreetmap.josm.tools.GBC; … … 94 95 95 96 public void cancel() { 96 //TODO97 //Main.pleaseWaitDlg.currentAction.setText(tr("Aborting..."));98 97 cancel = true; 99 98 if (activeConnection != null) { … … 112 111 try { 113 112 synchronized (credentialsManager) { 114 auth = credentialsManager.lookup(CredentialsManager.Key.USERNAME) + ":" + 115 113 auth = credentialsManager.lookup(CredentialsManager.Key.USERNAME) + ":" + 114 credentialsManager.lookup(CredentialsManager.Key.PASSWORD); 116 115 } 117 116 } catch (CredentialsManager.CMException e) { … … 139 138 String secret = Main.pref.get("osm-server." + key.toString(), null); 140 139 if (secret == null) throw new CredentialsManager.NoContentException(); 141 return secret; 140 return secret; 142 141 } 143 142 public void store(CredentialsManager.Key key, String secret) { … … 171 170 p.add(warning, GBC.eop()); 172 171 173 JCheckBox savePassword = new JCheckBox(tr("Save user and password (unencrypted)"), 174 172 JCheckBox savePassword = new JCheckBox(tr("Save user and password (unencrypted)"), 173 !username.equals("") && !password.equals("")); 175 174 p.add(savePassword, GBC.eop()); 176 175 177 int choice = new ExtendedDialog( 178 Main.parent, 179 tr("Enter Password"), 180 p, 181 new String[] {tr("Login"), tr("Cancel")}, 182 new String[] {"ok.png", "cancel.png"}).getValue(); 183 184 if (choice != 1) { 176 ExtendedDialog dialog = new ExtendedDialog( 177 Main.parent, 178 tr("Enter Password"), 179 new String[] {tr("Login"), tr("Cancel")} 180 ); 181 dialog.setContent(p); 182 dialog.setButtonIcons( new String[] {"ok.png", "cancel.png"}); 183 dialog.showDialog(); 184 185 if (dialog.getValue() != 1) { 185 186 caller.authCancelled = true; 186 187 return null; … … 223 224 oldServerURL = ""; 224 225 } 225 if (oldServerURL.equals("")) oldServerURL = "http://api.openstreetmap.org/api"; 226 if (oldServerURL.equals("")) { 227 oldServerURL = "http://api.openstreetmap.org/api"; 228 } 226 229 try { 227 230 oldUsername = lookup(Key.USERNAME); … … 258 261 String newPassword = String.valueOf(osmDataPassword.getPassword()); 259 262 if (!oldServerURL.equals(newServerURL)) { 260 store(Key.OSM_SERVER_URL, newServerURL); 263 store(Key.OSM_SERVER_URL, newServerURL); 261 264 } 262 265 if (!oldUsername.equals(newUsername)) { -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r2035 r2037 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.actions.UploadAction; 14 import org.openstreetmap.josm.data.osm.Changeset;15 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 203 202 } 204 203 205 public void disconnectActiveConnection() {206 if (api != null && api.activeConnection != null) {207 api. activeConnection.disconnect();204 public void cancel() { 205 if (api != null) { 206 api.cancel(); 208 207 } 209 208 }
Note:
See TracChangeset
for help on using the changeset viewer.