Changeset 1427 in josm for trunk/src/org
- Timestamp:
- 2009-02-19T18:04:31+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r1415 r1427 6 6 import java.awt.GridBagLayout; 7 7 import java.awt.Toolkit; 8 import java.util.ArrayList; 8 9 9 10 import javax.swing.AbstractAction; … … 25 26 public class ExtendedDialog extends JDialog { 26 27 private int result = 0; 28 private Component parent; 27 29 private final String[] bTexts; 30 31 // For easy access when inherited 32 protected Object contentConstraints = GBC.eol().anchor(GBC.CENTER).insets(5,10,5,0); 33 protected ArrayList<JButton> buttons = new ArrayList<JButton>(); 28 34 29 35 /** … … 36 42 */ 37 43 public ExtendedDialog(Component parent, String title, Component content, String[] buttonTexts, String[] buttonIcons) { 38 super(JOptionPane.getFrameForComponent(parent), title, true); 44 super(JOptionPane.getFrameForComponent(parent), title, true); 45 this.parent = parent; 39 46 bTexts = buttonTexts; 40 setupDialog(parent, title, content, buttonTexts, buttonIcons); 47 setupDialog(content, buttonIcons); 48 setVisible(true); 41 49 } 42 50 … … 45 53 } 46 54 47 // just display a breakable message 55 /** 56 * Sets up the dialog and displays the given message in a breakable label 57 */ 48 58 public ExtendedDialog(Component parent, String title, String message, String[] buttonTexts, String[] buttonIcons) { 49 59 super(JOptionPane.getFrameForComponent(parent), title, true); … … 55 65 56 66 bTexts = buttonTexts; 57 setupDialog(parent, title, lbl, buttonTexts, buttonIcons); 67 setupDialog(lbl, buttonIcons); 68 setVisible(true); 58 69 } 59 70 … … 62 73 } 63 74 64 private void setupDialog(Component parent, String title, Component content, String[] buttonTexts, String[] buttonIcons) { 75 /** 76 * Constructor that doesn't make the dialog visible immediately. Intended for when inheriting. 77 */ 78 public ExtendedDialog(Component parent, String title, String[] buttonTexts, boolean modal) { 79 super(JOptionPane.getFrameForComponent(parent), title, modal); 80 bTexts = buttonTexts; 81 } 82 83 protected void setupDialog(Component content, String[] buttonIcons) { 65 84 setupEscListener(); 66 85 … … 88 107 if(i == 0) rootPane.setDefaultButton(button); 89 108 buttonsPanel.add(button, GBC.std().insets(2,2,2,2)); 109 buttons.add(button); 90 110 } 91 111 92 112 JPanel cp = new JPanel(new GridBagLayout()); 93 cp.add(content, GBC.eol().anchor(GBC.CENTER).insets(5,10,5,0));113 cp.add(content, contentConstraints); 94 114 cp.add(buttonsPanel, GBC.eol().anchor(GBC.CENTER).insets(5,5,5,5)); 95 115 … … 102 122 // Try to make it not larger than the parent window or at least not larger than 2/3 of the screen 103 123 Dimension d = getSize(); 104 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 105 Dimension x = new Dimension(Math.round(screenSize.width*2/3), Math.round(screenSize.height*2/3)); 106 107 try { 108 if(parent != null) 109 x = JOptionPane.getFrameForComponent(parent).getSize(); 110 } catch(NullPointerException e) { } 124 Dimension x = findMaxDialogSize(); 111 125 112 126 boolean limitedInWidth = d.width > x.width; … … 122 136 setSize(d); 123 137 setLocationRelativeTo(parent); 124 setVisible(true);125 138 } 126 139 … … 131 144 public int getValue() { 132 145 return result; 146 } 147 148 /** 149 * Tries to find a good value of how large the dialog should be 150 * @return Dimension Size of the parent Component or 2/3 of screen size if not available 151 */ 152 protected Dimension findMaxDialogSize() { 153 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 154 Dimension x = new Dimension(Math.round(screenSize.width*2/3), 155 Math.round(screenSize.height*2/3)); 156 try { 157 if(parent != null) 158 x = JOptionPane.getFrameForComponent(parent).getSize(); 159 } catch(NullPointerException e) { } 160 return x; 133 161 } 134 162 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r1415 r1427 6 6 import static org.openstreetmap.josm.tools.I18n.trn; 7 7 8 import java.awt.Component; 8 9 import java.awt.GridBagLayout; 9 10 import java.awt.Image; 10 11 import java.awt.event.ActionEvent; 11 12 import java.io.BufferedReader; 13 import java.io.IOException; 12 14 import java.io.InputStreamReader; 13 import java.io.IOException;14 15 import java.io.Reader; 15 16 import java.io.UnsupportedEncodingException; … … 37 38 import org.openstreetmap.josm.command.Command; 38 39 import org.openstreetmap.josm.command.SequenceCommand; 40 import org.openstreetmap.josm.data.osm.Node; 39 41 import org.openstreetmap.josm.data.osm.OsmPrimitive; 40 42 import org.openstreetmap.josm.data.osm.OsmUtils; 41 import org.openstreetmap.josm.data.osm. Node;43 import org.openstreetmap.josm.data.osm.Relation; 42 44 import org.openstreetmap.josm.data.osm.Way; 43 import org.openstreetmap.josm.data.osm.Relation; 45 import org.openstreetmap.josm.gui.ExtendedDialog; 46 import org.openstreetmap.josm.gui.QuadStateCheckBox; 44 47 import org.openstreetmap.josm.io.MirroredInputStream; 45 import org.openstreetmap.josm.gui.QuadStateCheckBox;46 import org.openstreetmap.josm.gui.tagging.TaggingPresetMenu;47 import org.openstreetmap.josm.gui.tagging.TaggingPresetSeparator;48 48 import org.openstreetmap.josm.tools.GBC; 49 49 import org.openstreetmap.josm.tools.ImageProvider; … … 590 590 if (p == null) 591 591 return; 592 int answer = JOptionPane.OK_OPTION; 592 593 int answer = 1; 593 594 if (p.getComponentCount() != 0) { 594 final JOptionPane optionPane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){595 @Override public void selectInitialValue() {596 for (Item i : data) {597 if (i.focus) {598 i.requestFocusInWindow();599 return;600 }601 }602 }603 };604 595 String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size()); 605 if(sel.size() == 0) 606 title = tr("Nothing selected!"); 607 608 optionPane.createDialog(Main.parent, title).setVisible(true); 609 Object answerObj = optionPane.getValue(); 610 if (answerObj == null || answerObj == JOptionPane.UNINITIALIZED_VALUE || 611 (answerObj instanceof Integer && (Integer)answerObj != JOptionPane.OK_OPTION)) 612 answer = JOptionPane.CANCEL_OPTION; 613 } 614 if (sel.size() != 0 && answer == JOptionPane.OK_OPTION) { 596 if(sel.size() == 0) { 597 if(originalSelectionEmpty) 598 title = tr("Nothing selected!"); 599 else 600 title = tr("Selection unsuitable!"); 601 } 602 603 class PresetDialog extends ExtendedDialog { 604 public PresetDialog(Component content, String title, boolean disableApply) { 605 super(Main.parent, 606 title, 607 new String[] { tr("Apply Preset"), tr("Cancel") }, 608 true); 609 contentConstraints = GBC.eol().fill().insets(5,10,5,0); 610 setupDialog(content, new String[] {"ok.png", "cancel.png" }); 611 buttons.get(0).setEnabled(!disableApply); 612 buttons.get(0).setToolTipText(title); 613 setVisible(true); 614 } 615 } 616 617 answer = new PresetDialog(p, title, (sel.size() == 0)).getValue(); 618 } 619 if (sel.size() != 0 && answer == 1) { 615 620 Command cmd = createCommand(sel); 616 621 if (cmd != null) … … 619 624 Main.ds.setSelected(Main.ds.getSelected()); // force update 620 625 } 621 626 627 /** 628 * True whenever the original selection given into createSelection was empty 629 */ 630 private boolean originalSelectionEmpty = false; 631 632 /** 633 * Removes all unsuitable OsmPrimitives from the given list 634 * @param participants List of possibile OsmPrimitives to tag 635 * @return Cleaned list with suitable OsmPrimitives only 636 */ 622 637 private Collection<OsmPrimitive> createSelection(Collection<OsmPrimitive> participants) { 638 originalSelectionEmpty = participants.size() == 0; 623 639 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(); 624 640 for (OsmPrimitive osm : participants)
Note:
See TracChangeset
for help on using the changeset viewer.