Changeset 50 in josm for src/org/openstreetmap
- Timestamp:
- 2006-02-12T12:05:34+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r46 r50 7 7 import java.awt.Point; 8 8 import java.awt.Toolkit; 9 import java.awt.event.WindowAdapter; 10 import java.awt.event.WindowEvent; 9 11 import java.util.Arrays; 10 12 import java.util.Collection; … … 35 37 import org.openstreetmap.josm.gui.MapFrame; 36 38 import org.openstreetmap.josm.gui.ShowModifiers; 39 import org.openstreetmap.josm.gui.layer.Layer; 40 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 37 41 38 42 /** … … 140 144 141 145 getContentPane().add(toolBar, BorderLayout.NORTH); 146 147 addWindowListener(new WindowAdapter(){ 148 @Override 149 public void windowClosing(WindowEvent arg0) { 150 if (mapFrame != null) { 151 boolean changed = false; 152 for (Layer l : mapFrame.mapView.getAllLayers()) { 153 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) { 154 changed = true; 155 break; 156 } 157 } 158 if (changed) { 159 int answer = JOptionPane.showConfirmDialog( 160 Main.this, "There are unsaved changes. Really quit?", 161 "Unsaved Changes", JOptionPane.YES_NO_OPTION); 162 if (answer != JOptionPane.YES_OPTION) 163 return; 164 } 165 } 166 System.exit(0); 167 } 168 }); 169 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 142 170 } 143 171 … … 174 202 175 203 main = new Main(); 176 main.setDefaultCloseOperation(EXIT_ON_CLOSE);177 204 main.setVisible(true); 178 205 -
src/org/openstreetmap/josm/actions/DownloadAction.java
r44 r50 14 14 import javax.swing.JButton; 15 15 import javax.swing.JCheckBox; 16 import javax.swing.JDialog;17 16 import javax.swing.JLabel; 18 17 import javax.swing.JOptionPane; … … 163 162 final OsmServerReader osmReader = new OsmServerReader(b.latlon[0], b.latlon[1], b.latlon[2], b.latlon[3]); 164 163 165 final JDialog pleaseWaitDlg = createPleaseWaitDialog("Downloading data"); 166 167 new Thread(){ 164 new Thread(new PleaseWaitRunnable("Downloading data"){ 168 165 @Override 169 public void r un() {166 public void realRun() { 170 167 try { 171 168 String name = latlon[0].getText() + " " … … 181 178 return; // user cancelled download 182 179 if (dataSet.nodes.isEmpty()) { 183 pleaseWaitDlg.setVisible(false); 184 pleaseWaitDlg.dispose(); 180 closeDialog(); 185 181 JOptionPane.showMessageDialog(Main.main, 186 182 "No data imported."); … … 194 190 else 195 191 Main.main.getMapFrame().mapView.addLayer(layer); 196 pleaseWaitDlg.setVisible(false);197 192 } catch (JDOMException x) { 198 pleaseWaitDlg.setVisible(false); 199 pleaseWaitDlg.dispose(); 193 closeDialog(); 200 194 x.printStackTrace(); 201 195 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 202 196 } catch (FileNotFoundException x) { 203 pleaseWaitDlg.setVisible(false); 204 pleaseWaitDlg.dispose(); 197 closeDialog(); 205 198 x.printStackTrace(); 206 199 JOptionPane.showMessageDialog(Main.main, 207 200 "URL nicht gefunden: " + x.getMessage()); 208 201 } catch (IOException x) { 209 pleaseWaitDlg.setVisible(false); 210 pleaseWaitDlg.dispose(); 202 closeDialog(); 211 203 x.printStackTrace(); 212 204 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 213 } finally { 214 if (pleaseWaitDlg.isVisible()) { 215 pleaseWaitDlg.setVisible(false); 216 pleaseWaitDlg.dispose(); 217 } 218 } 219 } 220 }.start(); 221 222 pleaseWaitDlg.setVisible(true); 205 } 206 } 207 }).start(); 223 208 } 224 209 -
src/org/openstreetmap/josm/actions/JosmAction.java
r44 r50 7 7 import javax.swing.JDialog; 8 8 import javax.swing.JLabel; 9 import javax.swing.SwingUtilities; 9 10 10 11 import org.openstreetmap.josm.Main; … … 17 18 abstract public class JosmAction extends AbstractAction { 18 19 20 /** 21 * Instanced of this thread will display a "Please Wait" message in middle of JOSM 22 * to indicate a progress beeing executed. 23 * 24 * @author Imi 25 */ 26 protected abstract class PleaseWaitRunnable implements Runnable { 27 private String msg; 28 private JDialog pleaseWaitDlg; 29 /** 30 * Create the runnable object with a given message for the user. 31 */ 32 PleaseWaitRunnable(String msg) { 33 this.msg = msg; 34 } 35 public final void run() { 36 pleaseWaitDlg = new JDialog(Main.main, true); 37 pleaseWaitDlg.setUndecorated(true); 38 JLabel l = new JLabel(msg+". Please Wait."); 39 l.setBorder(BorderFactory.createCompoundBorder( 40 BorderFactory.createEtchedBorder(), 41 BorderFactory.createEmptyBorder(20,20,20,20))); 42 pleaseWaitDlg.getContentPane().add(l); 43 pleaseWaitDlg.pack(); 44 pleaseWaitDlg.setLocation(Main.main.getX()+Main.main.getWidth()/2-pleaseWaitDlg.getWidth()/2, 45 Main.main.getY()+Main.main.getHeight()/2-pleaseWaitDlg.getHeight()/2); 46 pleaseWaitDlg.setResizable(false); 47 SwingUtilities.invokeLater(new Runnable(){ 48 public void run() { 49 pleaseWaitDlg.setVisible(true); 50 } 51 }); 52 try { 53 realRun(); 54 } finally { 55 closeDialog(); 56 } 57 } 58 public abstract void realRun(); 59 public void closeDialog() { 60 pleaseWaitDlg.setVisible(false); 61 pleaseWaitDlg.dispose(); 62 } 63 } 64 19 65 /** 20 66 * Construct the action. … … 34 80 putValue(ACCELERATOR_KEY, shortCut); 35 81 } 36 37 /**38 * @return A dialog labeled "... Please Wait." where ... is the message parameter.39 */40 protected JDialog createPleaseWaitDialog(String msg) {41 final JDialog pleaseWaitDlg = new JDialog(Main.main, true);42 pleaseWaitDlg.setUndecorated(true);43 JLabel l = new JLabel(msg+". Please Wait.");44 l.setBorder(BorderFactory.createCompoundBorder(45 BorderFactory.createEtchedBorder(),46 BorderFactory.createEmptyBorder(20,20,20,20)));47 pleaseWaitDlg.getContentPane().add(l);48 pleaseWaitDlg.pack();49 pleaseWaitDlg.setLocation(Main.main.getX()+Main.main.getWidth()/2-pleaseWaitDlg.getWidth()/2,50 Main.main.getY()+Main.main.getHeight()/2-pleaseWaitDlg.getHeight()/2);51 pleaseWaitDlg.setResizable(false);52 return pleaseWaitDlg;53 }54 82 } -
src/org/openstreetmap/josm/actions/UploadAction.java
r44 r50 8 8 import java.util.LinkedList; 9 9 10 import javax.swing.JDialog;11 10 import javax.swing.JLabel; 12 11 import javax.swing.JList; … … 75 74 all.addAll(delete); 76 75 77 final JDialog dlg = createPleaseWaitDialog("Uploading data"); 78 new Thread(){ 76 new Thread(new PleaseWaitRunnable("Uploading data"){ 79 77 @Override 80 public void r un() {78 public void realRun() { 81 79 try { 82 80 server.uploadOsm(all); 83 81 } catch (JDOMException x) { 84 dlg.setVisible(false); 85 dlg.dispose(); 82 closeDialog(); 86 83 x.printStackTrace(); 87 84 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 88 } finally {89 if (dlg.isVisible()) {90 dlg.setVisible(false);91 dlg.dispose();92 }93 85 } 94 86 } 95 }.start(); 96 97 dlg.setVisible(true); 87 }).start(); 98 88 99 89 // finished without errors -> clean dataset -
src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r35 r50 166 166 if (myOsm.keys == null) 167 167 myOsm.keys = otherOsm.keys; 168 else 168 else if (otherOsm.keys != null) 169 169 myOsm.keys.putAll(otherOsm.keys); 170 170 myOsm.modifiedProperties = true; -
src/org/openstreetmap/josm/gui/MapView.java
r43 r50 23 23 import org.openstreetmap.josm.gui.layer.Layer; 24 24 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 25 import org.openstreetmap.josm.gui.layer.OsmDataLayer.ModifiedChangedListener; 25 26 26 27 /** … … 100 101 101 102 if (layer instanceof OsmDataLayer) { 103 final OsmDataLayer dataLayer = (OsmDataLayer)layer; 102 104 if (editLayer != null) { 103 105 // merge the layer into the existing one … … 108 110 return; 109 111 } 110 editLayer = (OsmDataLayer)layer; 112 editLayer = dataLayer; 113 dataLayer.addModifiedListener(new ModifiedChangedListener(){ 114 public void modifiedChanged(boolean value, OsmDataLayer source) { 115 Main.main.setTitle((value?"*":"")+"Java Open Street Map - Editor"); 116 } 117 }); 111 118 } 112 119 -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r41 r50 34 34 public class OsmDataLayer extends Layer { 35 35 36 public interface ModifiedChangedListener { 37 void modifiedChanged(boolean value, OsmDataLayer source); 38 } 39 36 40 private static Icon icon; 37 41 … … 42 46 43 47 /** 48 * Whether the data of this layer was modified during the session. 49 */ 50 private boolean modified = false; 51 /** 44 52 * All commands that were made on the dataset. 45 53 */ … … 50 58 private Stack<Command> redoCommands = new Stack<Command>(); 51 59 60 /** 61 * List of all listeners for changes of modified flag. 62 */ 63 LinkedList<ModifiedChangedListener> listener; 64 52 65 /** 53 66 * Construct a OsmDataLayer. … … 157 170 Main.main.undoAction.setEnabled(true); 158 171 Main.main.redoAction.setEnabled(false); 172 setModified(true); 159 173 } 160 174 … … 171 185 Main.main.undoAction.setEnabled(!commands.isEmpty()); 172 186 Main.main.redoAction.setEnabled(true); 187 if (commands.isEmpty()) 188 setModified(false); 173 189 } 174 190 /** … … 200 216 for (Iterator<Track> it = data.tracks.iterator(); it.hasNext();) 201 217 cleanIterator(it); 218 219 // not modified anymore, since either everything reverted to file state or 220 // everything uploaded properly. 221 setModified(false); 222 223 } 224 225 public boolean isModified() { 226 return modified; 227 } 228 229 public void setModified(boolean modified) { 230 if (modified == this.modified) 231 return; 232 this.modified = modified; 233 if (listener != null) 234 for (ModifiedChangedListener l : listener) 235 l.modifiedChanged(modified, this); 236 } 237 238 /** 239 * Add the parameter to the intern list of listener for modified state. 240 * @param l Listener to add to the list. Must not be null. 241 */ 242 public void addModifiedListener(ModifiedChangedListener l) { 243 if (listener == null) 244 listener = new LinkedList<ModifiedChangedListener>(); 245 listener.add(l); 202 246 } 203 247
Note:
See TracChangeset
for help on using the changeset viewer.