Changeset 1631 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
- Timestamp:
- 2009-06-01T22:20:03+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
r1627 r1631 10 10 import java.awt.Point; 11 11 import java.awt.event.ActionEvent; 12 import java.net.URL;13 12 import java.util.logging.Logger; 14 13 … … 16 15 import javax.swing.Action; 17 16 import javax.swing.BorderFactory; 18 import javax.swing.ImageIcon;19 17 import javax.swing.JButton; 20 18 import javax.swing.JDialog; … … 25 23 import org.openstreetmap.josm.command.Command; 26 24 import org.openstreetmap.josm.gui.conflict.ConflictResolver; 25 import org.openstreetmap.josm.tools.ImageProvider; 27 26 27 /** 28 * This is an extended dialog for resolving conflict between {@see OsmPrimitive}. 29 * 30 * 31 */ 28 32 public class ConflictResolutionDialog extends JDialog { 29 33 private static final Logger logger = Logger.getLogger(ConflictResolutionDialog.class.getName()); 30 34 public final static Dimension DEFAULT_SIZE = new Dimension(600,400); 31 35 36 /** the conflict resolver component */ 32 37 private ConflictResolver resolver; 33 38 39 /** 40 * restore position and size on screen from preference settings 41 * 42 */ 34 43 protected void restorePositionAndDimension() { 35 44 Point p = new Point(); … … 39 48 p.x = Math.max(0,p.x); 40 49 } catch(Exception e) { 41 logger.warning("unexpected value for preference conflictresolutiondialog.x, assuming 0"); 50 logger.warning("unexpected value for preference conflictresolutiondialog.x, assuming 0"); 42 51 p.x = 0; 43 52 } … … 46 55 p.y = Math.max(0,p.y); 47 56 } catch(Exception e) { 48 logger.warning("unexpected value for preference conflictresolutiondialog.x, assuming 0"); 57 logger.warning("unexpected value for preference conflictresolutiondialog.x, assuming 0"); 49 58 p.y = 0; 50 59 } … … 53 62 d.width = Math.max(0,d.width); 54 63 } catch(Exception e) { 55 logger.warning("unexpected value for preference conflictresolutiondialog.width, assuming " + DEFAULT_SIZE.width); 64 logger.warning("unexpected value for preference conflictresolutiondialog.width, assuming " + DEFAULT_SIZE.width); 56 65 p.y = 0; 57 66 } … … 60 69 d.height = Math.max(0,d.height); 61 70 } catch(Exception e) { 62 logger.warning("unexpected value for preference conflictresolutiondialog.height, assuming " + + DEFAULT_SIZE.height); 71 logger.warning("unexpected value for preference conflictresolutiondialog.height, assuming " + + DEFAULT_SIZE.height); 63 72 p.y = 0; 64 73 } 65 74 66 75 setLocation(p); 67 76 setSize(d); 68 77 } 69 78 79 /** 80 * remember position and size on screen in the preferences 81 * 82 */ 70 83 protected void rememberPositionAndDimension() { 71 84 Point p = getLocation(); 72 85 Main.pref.put("conflictresolutiondialog.x", Integer.toString(p.x)); 73 86 Main.pref.put("conflictresolutiondialog.y", Integer.toString(p.y)); 74 87 75 88 Dimension d = getSize(); 76 89 Main.pref.put("conflictresolutiondialog.width", Integer.toString(d.width)); 77 90 Main.pref.put("conflictresolutiondialog.height", Integer.toString(d.height)); 78 91 } 79 92 93 94 @Override 80 95 public void setVisible(boolean isVisible) { 81 96 if (isVisible){ … … 86 101 super.setVisible(isVisible); 87 102 } 88 103 104 /** 105 * builds the sub panel with the control buttons 106 * 107 * @return the panel 108 */ 89 109 protected JPanel buildButtonRow() { 90 110 JPanel pnl = new JPanel(); 91 111 pnl.setLayout(new FlowLayout(FlowLayout.RIGHT)); 92 112 93 113 JButton btn = new JButton(new CancelAction()); 94 114 btn.setName("button.cancel"); 95 115 pnl.add(btn); 96 116 97 117 btn = new JButton(new ApplyResolutionAction()); 98 118 btn.setName("button.apply"); 99 119 pnl.add(btn); 100 120 101 121 pnl.setBorder(BorderFactory.createLoweredBevelBorder()); 102 122 return pnl; 103 123 } 104 124 125 /** 126 * builds the GUI 127 */ 105 128 protected void build() { 106 setTitle(tr("Resolve conflicts")); 107 getContentPane().setLayout(new BorderLayout()); 108 109 resolver = new ConflictResolver(); 110 getContentPane().add(resolver, BorderLayout.CENTER); 111 getContentPane().add(buildButtonRow(), BorderLayout.SOUTH); 129 setTitle(tr("Resolve conflicts")); 130 getContentPane().setLayout(new BorderLayout()); 131 132 resolver = new ConflictResolver(); 133 resolver.setName("panel.conflictresolver"); 134 getContentPane().add(resolver, BorderLayout.CENTER); 135 getContentPane().add(buildButtonRow(), BorderLayout.SOUTH); 112 136 } 113 114 137 138 115 139 public ConflictResolutionDialog(Component parent) { 116 140 super(JOptionPane.getFrameForComponent(parent), true /* modal */); 117 141 build(); 118 142 } 119 143 120 144 public ConflictResolver getConflictResolver() { 121 145 return resolver; 122 146 } 123 124 protected ImageIcon getIcon(String iconPath) {125 URL imageURL = this.getClass().getResource(iconPath);126 if (imageURL == null) {127 System.out.println(tr("WARNING: failed to load resource {0}", iconPath));128 return null;129 }130 return new ImageIcon(imageURL);131 }132 147 133 134 148 class CancelAction extends AbstractAction { 135 136 public CancelAction() { 149 public CancelAction() { 137 150 putValue(Action.SHORT_DESCRIPTION, tr("Cancel conflict resolution and close the dialog")); 138 151 putValue(Action.NAME, tr("Cancel")); 139 putValue(Action.SMALL_ICON, getIcon("/images/cancel.png"));152 putValue(Action.SMALL_ICON, ImageProvider.get("", "cancel")); 140 153 setEnabled(true); 141 154 } 142 155 143 156 144 157 public void actionPerformed(ActionEvent arg0) { 145 158 setVisible(false); 146 } 147 } 148 149 class ApplyResolutionAction extends AbstractAction { 159 } 160 } 161 162 class ApplyResolutionAction extends AbstractAction { 150 163 public ApplyResolutionAction() { 151 164 putValue(Action.SHORT_DESCRIPTION, tr("Apply resolved conflicts and close the dialog")); 152 165 putValue(Action.NAME, tr("Apply Resolution")); 153 putValue(Action.SMALL_ICON, getIcon("/images/dialogs/conflict.png"));154 setEnabled(true); 166 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs", "conflict")); 167 setEnabled(true); 155 168 } 156 169 157 158 170 public void actionPerformed(ActionEvent arg0) { 159 171 Command cmd = resolver.buildResolveCommand(); 160 172 Main.main.undoRedo.add(cmd); 161 173 setVisible(false); 162 } 174 } 163 175 } 164 176 }
Note:
See TracChangeset
for help on using the changeset viewer.