Ticket #1977: EnhanceExtendedDialog.patch

File EnhanceExtendedDialog.patch, 4.4 KB (added by xeen, 12 years ago)

Adds a method to just pass text to ExtendedDialog instead of JComponent

  • src/org/openstreetmap/josm/gui/ExtendedDialog.java

     
    66import java.awt.event.ComponentEvent;
    77import java.awt.event.ComponentListener;
    88import java.awt.GridBagLayout;
     9import java.awt.Toolkit;
    910
    1011import javax.swing.AbstractAction;
    1112import javax.swing.Action;
     
    2223import javax.swing.KeyStroke;
    2324
    2425import org.openstreetmap.josm.Main;
     26import org.openstreetmap.josm.gui.JMultilineLabel;
    2527import org.openstreetmap.josm.tools.GBC;
    2628import org.openstreetmap.josm.tools.I18n;
    2729import org.openstreetmap.josm.tools.ImageProvider;
     
    4648    }
    4749   
    4850    public ExtendedDialog(Component parent, String title, Component content, String[] buttonTexts) {
     51        this(parent, title, content, buttonTexts, null);
     52    }
     53   
     54    // just display a breakable message
     55    public ExtendedDialog(Component parent, String title, String message, String[] buttonTexts, String[] buttonIcons) {
    4956        super(JOptionPane.getFrameForComponent(parent), title, true);
    50         bTexts = buttonTexts;
    51         setupDialog(parent, title, content, buttonTexts, null);
     57       
     58        JMultilineLabel lbl = new JMultilineLabel(message);
     59        // Make it not wider than 2/3 of the screen
     60        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     61        lbl.setMaxWidth(Math.round(screenSize.width*2/3));
     62       
     63        bTexts = buttonTexts;       
     64        setupDialog(parent, title, lbl, buttonTexts, buttonIcons);
    5265    }
    5366   
     67    public ExtendedDialog(Component parent, String title, String message, String[] buttonTexts) {
     68        this(parent, title, message, buttonTexts, null);
     69    }
     70   
    5471    private void setupDialog(Component parent, String title, Component content, String[] buttonTexts, String[] buttonIcons) {
     72        setupEscListener();
     73       
    5574        JButton button;
    5675        JPanel buttonsPanel = new JPanel(new GridBagLayout());
    5776       
     
    7897        }
    7998       
    8099        JPanel cp = new JPanel(new GridBagLayout());       
    81         cp.add(content, GBC.eol().anchor(GBC.CENTER).insets(0,10,0,0)); //fill(GBC.HORIZONTAL).
     100        cp.add(content, GBC.eol().anchor(GBC.CENTER).insets(5,10,5,0));
    82101        cp.add(buttonsPanel, GBC.eol().anchor(GBC.CENTER).insets(5,5,5,5));
    83102       
    84         JScrollPane pane = new JScrollPane(cp); 
     103        JScrollPane pane = new JScrollPane(cp);
    85104        pane.setBorder(null);       
    86105        setContentPane(pane);
    87106       
    88107        pack();
    89108       
    90         // Try to make it not larger than the parent window or at least not larger than a reasonable value
     109        // Try to make it not larger than the parent window or at least not larger than 2/3 of the screen
    91110        Dimension d = getSize();
    92         Dimension x = new Dimension(700, 500);
     111        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     112        Dimension x = new Dimension(Math.round(screenSize.width*2/3), Math.round(screenSize.height*2/3));
     113       
    93114        try {
    94            
    95115            if(parent != null)
    96116                x = JOptionPane.getFrameForComponent(parent).getSize();
    97117        } catch(NullPointerException e) { }
     
    100120        if(x.height > 0 && d.height > x.height) d.height = x.height;
    101121        setSize(d);
    102122       
    103         setLocationRelativeTo(parent);       
    104        
    105         setupEscListener();
     123        setLocationRelativeTo(parent);
    106124        setVisible(true);
    107125    }
    108126   
  • src/org/openstreetmap/josm/Main.java

     
    344344                final String msg = uploadedModified ? "\n"
    345345                +tr("Hint: Some changes came from uploading new data to the server.") : "";
    346346                int result = new ExtendedDialog(parent, tr("Unsaved Changes"),
    347                 new javax.swing.JLabel(tr("There are unsaved changes. Discard the changes and continue?")+msg),
     347                tr("There are unsaved changes. Discard the changes and continue?") + msg,
    348348                new String[] {tr("Save and Exit"), tr("Discard and Exit"), tr("Cancel")},
    349349                new String[] {"save.png", "exit.png", "cancel.png"}).getValue();
    350350