Changeset 1427 in josm


Ignore:
Timestamp:
Feb 19, 2009 6:04:31 PM (4 years ago)
Author:
stoecker
Message:

fixed 2122. patch by xeen

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java

    r1415 r1427  
    66import java.awt.GridBagLayout; 
    77import java.awt.Toolkit; 
     8import java.util.ArrayList; 
    89 
    910import javax.swing.AbstractAction; 
     
    2526public class ExtendedDialog extends JDialog { 
    2627    private int result = 0; 
     28    private Component parent; 
    2729    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>(); 
    2834     
    2935    /** 
     
    3642     */  
    3743    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; 
    3946        bTexts = buttonTexts;         
    40         setupDialog(parent, title, content, buttonTexts, buttonIcons); 
     47        setupDialog(content, buttonIcons); 
     48        setVisible(true); 
    4149    } 
    4250     
     
    4553    } 
    4654     
    47     // just display a breakable message 
     55    /** 
     56     * Sets up the dialog and displays the given message in a breakable label 
     57     */ 
    4858    public ExtendedDialog(Component parent, String title, String message, String[] buttonTexts, String[] buttonIcons) { 
    4959        super(JOptionPane.getFrameForComponent(parent), title, true); 
     
    5565         
    5666        bTexts = buttonTexts;         
    57         setupDialog(parent, title, lbl, buttonTexts, buttonIcons); 
     67        setupDialog(lbl, buttonIcons); 
     68        setVisible(true); 
    5869    } 
    5970     
     
    6273    } 
    6374     
    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) { 
    6584        setupEscListener(); 
    6685         
     
    88107            if(i == 0) rootPane.setDefaultButton(button);            
    89108            buttonsPanel.add(button, GBC.std().insets(2,2,2,2)); 
     109            buttons.add(button); 
    90110        } 
    91111         
    92112        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); 
    94114        cp.add(buttonsPanel, GBC.eol().anchor(GBC.CENTER).insets(5,5,5,5)); 
    95115         
     
    102122        // Try to make it not larger than the parent window or at least not larger than 2/3 of the screen 
    103123        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(); 
    111125         
    112126        boolean limitedInWidth = d.width > x.width; 
     
    122136        setSize(d); 
    123137        setLocationRelativeTo(parent); 
    124         setVisible(true); 
    125138    } 
    126139     
     
    131144    public int getValue() { 
    132145        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; 
    133161    } 
    134162     
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r1415 r1427  
    66import static org.openstreetmap.josm.tools.I18n.trn; 
    77 
     8import java.awt.Component; 
    89import java.awt.GridBagLayout; 
    910import java.awt.Image; 
    1011import java.awt.event.ActionEvent; 
    1112import java.io.BufferedReader; 
     13import java.io.IOException; 
    1214import java.io.InputStreamReader; 
    13 import java.io.IOException; 
    1415import java.io.Reader; 
    1516import java.io.UnsupportedEncodingException; 
     
    3738import org.openstreetmap.josm.command.Command; 
    3839import org.openstreetmap.josm.command.SequenceCommand; 
     40import org.openstreetmap.josm.data.osm.Node; 
    3941import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    4042import org.openstreetmap.josm.data.osm.OsmUtils; 
    41 import org.openstreetmap.josm.data.osm.Node; 
     43import org.openstreetmap.josm.data.osm.Relation; 
    4244import org.openstreetmap.josm.data.osm.Way; 
    43 import org.openstreetmap.josm.data.osm.Relation; 
     45import org.openstreetmap.josm.gui.ExtendedDialog; 
     46import org.openstreetmap.josm.gui.QuadStateCheckBox; 
    4447import 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; 
    4848import org.openstreetmap.josm.tools.GBC; 
    4949import org.openstreetmap.josm.tools.ImageProvider; 
     
    590590        if (p == null) 
    591591            return; 
    592         int answer = JOptionPane.OK_OPTION; 
     592               
     593        int answer = 1; 
    593594        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             }; 
    604595            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) { 
    615620            Command cmd = createCommand(sel); 
    616621            if (cmd != null) 
     
    619624        Main.ds.setSelected(Main.ds.getSelected()); // force update 
    620625    } 
    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     */ 
    622637    private Collection<OsmPrimitive> createSelection(Collection<OsmPrimitive> participants) { 
     638        originalSelectionEmpty = participants.size() == 0; 
    623639        Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(); 
    624640        for (OsmPrimitive osm : participants) 
Note: See TracChangeset for help on using the changeset viewer.