- Timestamp:
- 2016-09-04T16:32:05+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r10791 r10957 146 146 } 147 147 148 /** 149 * Same as above but lets you define if the dialog should be disposed on close. 150 * @param parent The parent element that will be used for position and maximum size 151 * @param title The text that will be shown in the window titlebar 152 * @param buttonTexts String Array of the text that will appear on the buttons. The first button is the default one. 153 * @param modal Set it to {@code true} if you want the dialog to be modal 154 * @param disposeOnClose whether to call {@link #dispose} when closing the dialog 155 */ 148 156 public ExtendedDialog(Component parent, String title, String[] buttonTexts, boolean modal, boolean disposeOnClose) { 149 157 super(searchRealParent(parent), title, modal ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS); … … 329 337 330 338 for (int i = 0; i < bTexts.length; i++) { 331 final int finalI = i; 332 Action action = new AbstractAction(bTexts[i]) { 333 @Override 334 public void actionPerformed(ActionEvent evt) { 335 buttonAction(finalI, evt); 336 } 337 }; 338 339 button = new JButton(action); 339 button = new JButton(createButtonAction(i)); 340 340 if (i == defaultButtonIdx-1) { 341 341 defaultButton = button; … … 430 430 setSize(d); 431 431 setLocationRelativeTo(parent); 432 } 433 434 protected Action createButtonAction(final int i) { 435 return new AbstractAction(bTexts[i]) { 436 @Override 437 public void actionPerformed(ActionEvent evt) { 438 buttonAction(i, evt); 439 } 440 }; 432 441 } 433 442 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r10853 r10957 222 222 ConflictResolutionDialog dialog = new ConflictResolutionDialog(Main.parent); 223 223 dialog.getConflictResolver().populate(c); 224 dialog.s etVisible(true);224 dialog.showDialog(); 225 225 226 226 lstConflicts.setSelectedIndex(index); -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
r10454 r10957 7 7 import java.awt.BorderLayout; 8 8 import java.awt.Component; 9 import java.awt.Dimension;10 import java.awt.FlowLayout;11 9 import java.awt.event.ActionEvent; 12 10 import java.beans.PropertyChangeEvent; … … 15 13 import javax.swing.AbstractAction; 16 14 import javax.swing.Action; 17 import javax.swing.BorderFactory;18 import javax.swing.JButton;19 import javax.swing.JDialog;20 15 import javax.swing.JLabel; 21 16 import javax.swing.JOptionPane; 22 17 import javax.swing.JPanel; 23 import javax.swing.WindowConstants;24 18 25 19 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.command.Command;27 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 28 21 import org.openstreetmap.josm.gui.DefaultNameFormatter; 22 import org.openstreetmap.josm.gui.ExtendedDialog; 29 23 import org.openstreetmap.josm.gui.conflict.pair.ConflictResolver; 30 24 import org.openstreetmap.josm.gui.help.HelpBrowser; 31 25 import org.openstreetmap.josm.gui.help.HelpUtil; 32 import org.openstreetmap.josm.gui.util.GuiHelper;33 26 import org.openstreetmap.josm.tools.ImageProvider; 34 import org.openstreetmap.josm.tools.WindowGeometry;35 27 36 28 /** … … 38 30 * @since 1622 39 31 */ 40 public class ConflictResolutionDialog extends JDialog implements PropertyChangeListener {32 public class ConflictResolutionDialog extends ExtendedDialog implements PropertyChangeListener { 41 33 /** the conflict resolver component */ 42 private ConflictResolver resolver; 43 private JLabel titleLabel; 44 45 private ApplyResolutionAction applyResolutionAction; 46 47 @Override 48 public void removeNotify() { 49 super.removeNotify(); 50 unregisterListeners(); 51 } 52 53 @Override 54 public void addNotify() { 55 super.addNotify(); 56 registerListeners(); 57 } 58 59 @Override 60 public void setVisible(boolean isVisible) { 61 String geom = getClass().getName() + ".geometry"; 62 if (isVisible) { 63 toFront(); 64 new WindowGeometry(geom, WindowGeometry.centerInWindow(Main.parent, 65 new Dimension(600, 400))).applySafe(this); 66 } else { 67 if (isShowing()) { // Avoid IllegalComponentStateException like in #8775 68 new WindowGeometry(this).remember(geom); 69 } 70 } 71 super.setVisible(isVisible); 72 } 73 74 private void closeDialog() { 75 setVisible(false); 76 dispose(); 77 } 78 79 /** 80 * builds the sub panel with the control buttons 81 * 82 * @return the panel 83 */ 84 protected JPanel buildButtonRow() { 85 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 86 87 applyResolutionAction = new ApplyResolutionAction(); 88 JButton btn = new JButton(applyResolutionAction); 89 btn.setName("button.apply"); 90 pnl.add(btn); 91 92 btn = new JButton(new CancelAction()); 93 btn.setName("button.cancel"); 94 pnl.add(btn); 95 96 btn = new JButton(new HelpAction()); 97 btn.setName("button.help"); 98 pnl.add(btn); 99 100 pnl.setBorder(BorderFactory.createLoweredBevelBorder()); 101 return pnl; 102 } 103 104 private void registerListeners() { 105 resolver.addPropertyChangeListener(applyResolutionAction); 106 resolver.registerListeners(); 107 } 108 109 private void unregisterListeners() { 110 resolver.removePropertyChangeListener(applyResolutionAction); 111 resolver.unregisterListeners(); 112 } 113 114 /** 115 * builds the GUI 116 */ 117 protected void build() { 118 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 119 getContentPane().setLayout(new BorderLayout()); 120 121 titleLabel = new JLabel(); 122 titleLabel.setHorizontalAlignment(JLabel.CENTER); 123 getContentPane().add(titleLabel, BorderLayout.NORTH); 124 125 updateTitle(); 126 127 resolver = new ConflictResolver(); 128 resolver.setName("panel.conflictresolver"); 129 getContentPane().add(resolver, BorderLayout.CENTER); 130 getContentPane().add(buildButtonRow(), BorderLayout.SOUTH); 131 132 resolver.addPropertyChangeListener(this); 133 HelpUtil.setHelpContext(this.getRootPane(), ht("Dialog/Conflict")); 134 } 34 private final ConflictResolver resolver = new ConflictResolver(); 35 private final JLabel titleLabel = new JLabel("", null, JLabel.CENTER); 36 37 private final ApplyResolutionAction applyResolutionAction = new ApplyResolutionAction(); 135 38 136 39 /** … … 139 42 */ 140 43 public ConflictResolutionDialog(Component parent) { 141 super(GuiHelper.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL); 44 // We define our own actions, but need to give a hint about number of buttons 45 super(parent, tr("Resolve conflicts"), new String[] {null, null, null}); 46 setDefaultButton(1); 47 setCancelButton(2); 142 48 build(); 143 49 pack(); 144 50 if (getInsets().top > 0) { 145 51 titleLabel.setVisible(false); 52 } 53 } 54 55 @Override 56 public void removeNotify() { 57 super.removeNotify(); 58 unregisterListeners(); 59 } 60 61 @Override 62 public void addNotify() { 63 super.addNotify(); 64 registerListeners(); 65 } 66 67 private void registerListeners() { 68 resolver.addPropertyChangeListener(applyResolutionAction); 69 resolver.registerListeners(); 70 } 71 72 private void unregisterListeners() { 73 resolver.removePropertyChangeListener(applyResolutionAction); 74 resolver.unregisterListeners(); 75 } 76 77 /** 78 * builds the GUI 79 */ 80 protected void build() { 81 JPanel p = new JPanel(new BorderLayout()); 82 83 p.add(titleLabel, BorderLayout.NORTH); 84 85 updateTitle(); 86 87 resolver.setName("panel.conflictresolver"); 88 p.add(resolver, BorderLayout.CENTER); 89 90 resolver.addPropertyChangeListener(this); 91 HelpUtil.setHelpContext(this.getRootPane(), ht("Dialog/Conflict")); 92 93 setContent(p); 94 } 95 96 @Override 97 protected Action createButtonAction(int i) { 98 switch (i) { 99 case 0: return applyResolutionAction; 100 case 1: return new CancelAction(); 101 case 2: return new HelpAction(); 102 default: return super.createButtonAction(i); 146 103 } 147 104 } … … 167 124 168 125 @Override 169 public void actionPerformed(ActionEvent arg0) {170 closeDialog();126 public void actionPerformed(ActionEvent evt) { 127 buttonAction(2, evt); 171 128 } 172 129 } … … 184 141 185 142 @Override 186 public void actionPerformed(ActionEvent arg0) {143 public void actionPerformed(ActionEvent evt) { 187 144 HelpBrowser.setUrlForHelpTopic(ht("/Dialog/Conflict")); 188 145 } … … 206 163 207 164 @Override 208 public void actionPerformed(ActionEvent arg0) {165 public void actionPerformed(ActionEvent evt) { 209 166 if (!resolver.isResolvedCompletely()) { 210 167 Object[] options = { … … 229 186 switch(ret) { 230 187 case JOptionPane.YES_OPTION: 231 closeDialog();188 buttonAction(1, evt); 232 189 break; 233 190 default: … … 235 192 } 236 193 } 237 Command cmd = resolver.buildResolveCommand(); 238 Main.main.undoRedo.add(cmd); 239 closeDialog(); 194 Main.main.undoRedo.add(resolver.buildResolveCommand()); 195 buttonAction(1, evt); 240 196 } 241 197 -
trunk/test/functional/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialogTestFT.java
r9546 r10957 32 32 33 33 public void showDialog() { 34 dialog.s etVisible(true);34 dialog.showDialog(); 35 35 } 36 36
Note:
See TracChangeset
for help on using the changeset viewer.