Changeset 1432 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-02-20T17:33:15+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
r1427 r1432 28 28 private Component parent; 29 29 private final String[] bTexts; 30 30 31 31 // For easy access when inherited 32 32 protected Object contentConstraints = GBC.eol().anchor(GBC.CENTER).insets(5,10,5,0); 33 33 protected ArrayList<JButton> buttons = new ArrayList<JButton>(); 34 34 35 35 /** 36 36 * Sets up the dialog. The first button is always the default. … … 40 40 * @param buttonTexts The labels that will be displayed on the buttons 41 41 * @param buttonIcons The path to the icons that will be displayed on the buttons. Path is relative to JOSM's image directory. File extensions need to be included. If a button should not have an icon pass null. 42 */ 42 */ 43 43 public ExtendedDialog(Component parent, String title, Component content, String[] buttonTexts, String[] buttonIcons) { 44 super(JOptionPane.getFrameForComponent(parent), title, true); 44 super(JOptionPane.getFrameForComponent(parent), title, true); 45 45 this.parent = parent; 46 bTexts = buttonTexts; 46 bTexts = buttonTexts; 47 47 setupDialog(content, buttonIcons); 48 48 setVisible(true); 49 49 } 50 50 51 51 public ExtendedDialog(Component parent, String title, Component content, String[] buttonTexts) { 52 52 this(parent, title, content, buttonTexts, null); 53 53 } 54 54 55 55 /** 56 56 * Sets up the dialog and displays the given message in a breakable label … … 58 58 public ExtendedDialog(Component parent, String title, String message, String[] buttonTexts, String[] buttonIcons) { 59 59 super(JOptionPane.getFrameForComponent(parent), title, true); 60 60 61 61 JMultilineLabel lbl = new JMultilineLabel(message); 62 62 // Make it not wider than 2/3 of the screen 63 63 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 64 64 lbl.setMaxWidth(Math.round(screenSize.width*2/3)); 65 66 bTexts = buttonTexts; 65 66 bTexts = buttonTexts; 67 67 setupDialog(lbl, buttonIcons); 68 68 setVisible(true); 69 69 } 70 70 71 71 public ExtendedDialog(Component parent, String title, String message, String[] buttonTexts) { 72 72 this(parent, title, message, buttonTexts, null); 73 73 } 74 74 75 75 /** 76 76 * Constructor that doesn't make the dialog visible immediately. Intended for when inheriting. 77 77 */ 78 78 public ExtendedDialog(Component parent, String title, String[] buttonTexts, boolean modal) { 79 super(JOptionPane.getFrameForComponent(parent), title, modal); 80 bTexts = buttonTexts; 79 super(JOptionPane.getFrameForComponent(parent), title, modal); 80 bTexts = buttonTexts; 81 81 } 82 82 83 83 protected void setupDialog(Component content, String[] buttonIcons) { 84 84 setupEscListener(); 85 85 86 86 JButton button; 87 87 JPanel buttonsPanel = new JPanel(new GridBagLayout()); 88 88 89 89 for(int i=0; i < bTexts.length; i++) { 90 90 Action action = new AbstractAction(bTexts[i]) { 91 91 public void actionPerformed(ActionEvent evt) { 92 String a = evt.getActionCommand(); 93 for(int i=0; i < bTexts.length; i++) 94 if(bTexts[i].equals(a)) { 95 result = i+1; 96 break; 97 } 98 99 setVisible(false); 92 buttonAction(evt); 100 93 } 101 94 }; 102 103 button = new JButton(action); 95 96 button = new JButton(action); 104 97 if(buttonIcons != null && buttonIcons[i] != null) 105 98 button.setIcon(ImageProvider.get(buttonIcons[i])); 106 107 if(i == 0) rootPane.setDefaultButton(button); 99 100 if(i == 0) rootPane.setDefaultButton(button); 108 101 buttonsPanel.add(button, GBC.std().insets(2,2,2,2)); 109 102 buttons.add(button); 110 103 } 111 112 JPanel cp = new JPanel(new GridBagLayout()); 104 105 JPanel cp = new JPanel(new GridBagLayout()); 113 106 cp.add(content, contentConstraints); 114 107 cp.add(buttonsPanel, GBC.eol().anchor(GBC.CENTER).insets(5,5,5,5)); 115 108 116 109 JScrollPane pane = new JScrollPane(cp); 117 pane.setBorder(null); 110 pane.setBorder(null); 118 111 setContentPane(pane); 119 120 pack(); 121 112 113 pack(); 114 122 115 // Try to make it not larger than the parent window or at least not larger than 2/3 of the screen 123 116 Dimension d = getSize(); 124 117 Dimension x = findMaxDialogSize(); 125 118 126 119 boolean limitedInWidth = d.width > x.width; 127 120 boolean limitedInHeight = d.height > x.height; … … 129 122 if(x.width > 0 && d.width > x.width) d.width = x.width; 130 123 if(x.height > 0 && d.height > x.height) d.height = x.height; 131 124 132 125 // We have a vertical scrollbar and enough space to prevent a horizontal one 133 126 if(!limitedInWidth && limitedInHeight) 134 127 d.width += new JScrollBar().getPreferredSize().width; 135 128 136 129 setSize(d); 137 130 setLocationRelativeTo(parent); 138 131 } 139 132 140 133 /** 141 * @return int The selected button. The count starts with 1. 134 * @return int The selected button. The count starts with 1. 142 135 * A return value of 0 means the dialog has been closed otherwise. 143 */ 136 */ 144 137 public int getValue() { 145 138 return result; 146 139 } 147 140 141 /** 142 * This gets performed whenever a button is clicked or activated 143 * @param evt the button event 144 */ 145 protected void buttonAction(ActionEvent evt) { 146 String a = evt.getActionCommand(); 147 for(int i=0; i < bTexts.length; i++) 148 if(bTexts[i].equals(a)) { 149 result = i+1; 150 break; 151 } 152 153 setVisible(false); 154 } 155 148 156 /** 149 157 * Tries to find a good value of how large the dialog should be … … 160 168 return x; 161 169 } 162 170 163 171 /** 164 172 * Makes the dialog listen to ESC keypressed 165 173 */ 166 174 private void setupEscListener() { 167 Action actionListener = new AbstractAction() { 168 public void actionPerformed(ActionEvent actionEvent) { 175 Action actionListener = new AbstractAction() { 176 public void actionPerformed(ActionEvent actionEvent) { 169 177 setVisible(false); 170 } 178 } 171 179 }; 172 180 173 181 rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) 174 182 .put(KeyStroke.getKeyStroke("ESCAPE"), "ESCAPE"); 175 rootPane.getActionMap().put("ESCAPE", actionListener); 183 rootPane.getActionMap().put("ESCAPE", actionListener); 176 184 } 177 185 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationEditor.java
r1431 r1432 175 175 // ... until here, and also get rid of the "Collections.sort..." below. 176 176 177 // We need this twice, so cache result 178 protected final static String applyChangesText = tr("Apply Changes"); 179 177 180 /** 178 181 * Creates a new relation editor for the given relation. The relation … … 206 209 : tr("Edit relation #{0}", relation.id) 207 210 ), 208 new String[] { tr("Apply Changes"), tr("Cancel")},211 new String[] { applyChangesText, tr("Cancel")}, 209 212 false 210 213 ); … … 212 215 this.relation = relation; 213 216 ordered = !Main.pref.get("osm-server.version", "0.5").equals("0.5"); 214 ordered = true; 217 215 218 if (relation == null) { 216 219 // create a new relation … … 235 238 236 239 try { setAlwaysOnTop(true); } catch (SecurityException sx) {} 237 238 240 setVisible(true); 239 240 if(getValue() != 1) 241 return; 242 243 // User clicked "Apply" 244 applyChanges(); 245 } 241 } 242 246 243 247 244 /** … … 425 422 426 423 @Override 424 protected void buttonAction(ActionEvent evt) { 425 String a = evt.getActionCommand(); 426 if(applyChangesText.equals(a)) 427 applyChanges(); 428 429 setVisible(false); 430 } 431 432 @Override 427 433 protected Dimension findMaxDialogSize() { 428 434 // FIXME: Make it remember dialog size
Note:
See TracChangeset
for help on using the changeset viewer.