Ticket #1977: EnhanceExtendedDialog.2.patch
File EnhanceExtendedDialog.2.patch, 4.1 KB (added by , 12 years ago) |
---|
-
src/org/openstreetmap/josm/gui/ExtendedDialog.java
6 6 import java.awt.event.ComponentEvent; 7 7 import java.awt.event.ComponentListener; 8 8 import java.awt.GridBagLayout; 9 import java.awt.Toolkit; 9 10 10 11 import javax.swing.AbstractAction; 11 12 import javax.swing.Action; … … 18 19 import javax.swing.JOptionPane; 19 20 import javax.swing.JPanel; 20 21 import javax.swing.JRootPane; 22 import javax.swing.JScrollBar; 21 23 import javax.swing.JScrollPane; 22 24 import javax.swing.KeyStroke; 23 25 24 26 import org.openstreetmap.josm.Main; 27 import org.openstreetmap.josm.gui.JMultilineLabel; 25 28 import org.openstreetmap.josm.tools.GBC; 26 29 import org.openstreetmap.josm.tools.I18n; 27 30 import org.openstreetmap.josm.tools.ImageProvider; … … 46 49 } 47 50 48 51 public ExtendedDialog(Component parent, String title, Component content, String[] buttonTexts) { 52 this(parent, title, content, buttonTexts, null); 53 } 54 55 // just display a breakable message 56 public ExtendedDialog(Component parent, String title, String message, String[] buttonTexts, String[] buttonIcons) { 49 57 super(JOptionPane.getFrameForComponent(parent), title, true); 50 bTexts = buttonTexts; 51 setupDialog(parent, title, content, buttonTexts, null); 58 59 JMultilineLabel lbl = new JMultilineLabel(message); 60 // Make it not wider than 2/3 of the screen 61 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 62 lbl.setMaxWidth(Math.round(screenSize.width*2/3)); 63 64 bTexts = buttonTexts; 65 setupDialog(parent, title, lbl, buttonTexts, buttonIcons); 52 66 } 53 67 68 public ExtendedDialog(Component parent, String title, String message, String[] buttonTexts) { 69 this(parent, title, message, buttonTexts, null); 70 } 71 54 72 private void setupDialog(Component parent, String title, Component content, String[] buttonTexts, String[] buttonIcons) { 73 setupEscListener(); 74 55 75 JButton button; 56 76 JPanel buttonsPanel = new JPanel(new GridBagLayout()); 57 77 … … 78 98 } 79 99 80 100 JPanel cp = new JPanel(new GridBagLayout()); 81 cp.add(content, GBC.eol().anchor(GBC.CENTER).insets( 0,10,0,0)); //fill(GBC.HORIZONTAL).101 cp.add(content, GBC.eol().anchor(GBC.CENTER).insets(5,10,5,0)); 82 102 cp.add(buttonsPanel, GBC.eol().anchor(GBC.CENTER).insets(5,5,5,5)); 83 103 84 JScrollPane pane = new JScrollPane(cp); 104 JScrollPane pane = new JScrollPane(cp); 85 105 pane.setBorder(null); 86 106 setContentPane(pane); 87 107 88 108 pack(); 89 109 90 // Try to make it not larger than the parent window or at least not larger than a reasonable value110 // Try to make it not larger than the parent window or at least not larger than 2/3 of the screen 91 111 Dimension d = getSize(); 92 Dimension x = new Dimension(700, 500); 112 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 113 Dimension x = new Dimension(Math.round(screenSize.width*2/3), Math.round(screenSize.height*2/3)); 114 93 115 try { 94 95 116 if(parent != null) 96 117 x = JOptionPane.getFrameForComponent(parent).getSize(); 97 118 } catch(NullPointerException e) { } 119 120 boolean limitedInWidth = d.width > x.width; 121 boolean limitedInHeight = d.height > x.height; 98 122 99 123 if(x.width > 0 && d.width > x.width) d.width = x.width; 100 124 if(x.height > 0 && d.height > x.height) d.height = x.height; 101 setSize(d);102 125 103 setLocationRelativeTo(parent); 126 // We have a vertical scrollbar and enough space to prevent a horizontal one 127 if(!limitedInWidth && limitedInHeight) 128 d.width += new JScrollBar().getPreferredSize().width; 104 129 105 setupEscListener(); 130 setSize(d); 131 setLocationRelativeTo(parent); 106 132 setVisible(true); 107 133 } 108 134