Changeset 1865 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2009-07-28T19:48:39+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java
r1685 r1865 15 15 16 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.gui.OptionPaneUtil; 17 18 18 19 /** … … 68 69 interrupt(); 69 70 while (result == Result.WAITING) { sleep(10); /* yield(); */ } 70 if (result == Result.FAILED) { throw exception; } 71 if (result == Result.FAILED) 72 throw exception; 71 73 } 72 74 private void possiblyInterrupt() throws InterruptedException { … … 229 231 try { 230 232 switch (state) { 231 case INITIALIZING: 232 // we're ready to take interrupts 233 state = State.NOTPLAYING; 234 break; 235 case NOTPLAYING: 236 case PAUSED: 237 sleep(200); 238 break; 239 case PLAYING: 240 command.possiblyInterrupt(); 241 for(;;) { 242 int nBytesRead = 0; 243 nBytesRead = audioInputStream.read(abData, 0, abData.length); 244 position += nBytesRead / bytesPerSecond; 233 case INITIALIZING: 234 // we're ready to take interrupts 235 state = State.NOTPLAYING; 236 break; 237 case NOTPLAYING: 238 case PAUSED: 239 sleep(200); 240 break; 241 case PLAYING: 245 242 command.possiblyInterrupt(); 246 if (nBytesRead < 0) { break; } 247 audioOutputLine.write(abData, 0, nBytesRead); // => int nBytesWritten 243 for(;;) { 244 int nBytesRead = 0; 245 nBytesRead = audioInputStream.read(abData, 0, abData.length); 246 position += nBytesRead / bytesPerSecond; 247 command.possiblyInterrupt(); 248 if (nBytesRead < 0) { break; } 249 audioOutputLine.write(abData, 0, nBytesRead); // => int nBytesWritten 250 command.possiblyInterrupt(); 251 } 252 // end of audio, clean up 253 audioOutputLine.drain(); 254 audioOutputLine.close(); 255 audioOutputLine = null; 256 audioInputStream.close(); 257 audioInputStream = null; 258 playingUrl = null; 259 state = State.NOTPLAYING; 248 260 command.possiblyInterrupt(); 249 } 250 // end of audio, clean up 251 audioOutputLine.drain(); 252 audioOutputLine.close(); 253 audioOutputLine = null; 254 audioInputStream.close(); 255 audioInputStream = null; 256 playingUrl = null; 257 state = State.NOTPLAYING; 258 command.possiblyInterrupt(); 259 break; 261 break; 260 262 } 261 263 } catch (InterruptedException e) { … … 265 267 try { 266 268 switch (command.command()) { 267 case PLAY:268 double offset = command.offset();269 speed = command.speed();270 if (playingUrl != command.url() ||271 stateChange != State.PAUSED ||272 offset != 0.0)273 {274 if (audioInputStream != null) {275 audioInputStream.close();276 audioInputStream = null;277 }278 playingUrl = command.url();279 audioInputStream = AudioSystem.getAudioInputStream(playingUrl);280 audioFormat = audioInputStream.getFormat();281 long nBytesRead = 0;282 position = 0.0;283 offset -= leadIn;284 double calibratedOffset = offset * calibration;285 bytesPerSecond = audioFormat.getFrameRate() /* frames per second */269 case PLAY: 270 double offset = command.offset(); 271 speed = command.speed(); 272 if (playingUrl != command.url() || 273 stateChange != State.PAUSED || 274 offset != 0.0) 275 { 276 if (audioInputStream != null) { 277 audioInputStream.close(); 278 audioInputStream = null; 279 } 280 playingUrl = command.url(); 281 audioInputStream = AudioSystem.getAudioInputStream(playingUrl); 282 audioFormat = audioInputStream.getFormat(); 283 long nBytesRead = 0; 284 position = 0.0; 285 offset -= leadIn; 286 double calibratedOffset = offset * calibration; 287 bytesPerSecond = audioFormat.getFrameRate() /* frames per second */ 286 288 * audioFormat.getFrameSize() /* bytes per frame */; 287 if (speed * bytesPerSecond > 256000.0) 288 speed = 256000 / bytesPerSecond; 289 if (calibratedOffset > 0.0) { 290 long bytesToSkip = (long)( 291 calibratedOffset /* seconds (double) */ * bytesPerSecond); 292 /* skip doesn't seem to want to skip big chunks, so 293 * reduce it to smaller ones 294 */ 295 // audioInputStream.skip(bytesToSkip); 296 while (bytesToSkip > chunk) { 297 nBytesRead = audioInputStream.skip(chunk); 298 if (nBytesRead <= 0) 299 throw new IOException(tr("This is after the end of the recording")); 300 bytesToSkip -= nBytesRead; 289 if (speed * bytesPerSecond > 256000.0) { 290 speed = 256000 / bytesPerSecond; 301 291 } 302 if (bytesToSkip > 0) 303 audioInputStream.skip(bytesToSkip); 304 position = offset; 305 } 306 if (audioOutputLine != null) 307 audioOutputLine.close(); 308 audioFormat = new AudioFormat(audioFormat.getEncoding(), 292 if (calibratedOffset > 0.0) { 293 long bytesToSkip = (long)( 294 calibratedOffset /* seconds (double) */ * bytesPerSecond); 295 /* skip doesn't seem to want to skip big chunks, so 296 * reduce it to smaller ones 297 */ 298 // audioInputStream.skip(bytesToSkip); 299 while (bytesToSkip > chunk) { 300 nBytesRead = audioInputStream.skip(chunk); 301 if (nBytesRead <= 0) 302 throw new IOException(tr("This is after the end of the recording")); 303 bytesToSkip -= nBytesRead; 304 } 305 if (bytesToSkip > 0) { 306 audioInputStream.skip(bytesToSkip); 307 } 308 position = offset; 309 } 310 if (audioOutputLine != null) { 311 audioOutputLine.close(); 312 } 313 audioFormat = new AudioFormat(audioFormat.getEncoding(), 309 314 audioFormat.getSampleRate() * (float) (speed * calibration), 310 315 audioFormat.getSampleSizeInBits(), … … 313 318 audioFormat.getFrameRate() * (float) (speed * calibration), 314 319 audioFormat.isBigEndian()); 315 DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);316 audioOutputLine = (SourceDataLine) AudioSystem.getLine(info);317 audioOutputLine.open(audioFormat);318 audioOutputLine.start();319 }320 stateChange = State.PLAYING;321 break;322 case PAUSE:323 stateChange = State.PAUSED;324 break;320 DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); 321 audioOutputLine = (SourceDataLine) AudioSystem.getLine(info); 322 audioOutputLine.open(audioFormat); 323 audioOutputLine.start(); 324 } 325 stateChange = State.PLAYING; 326 break; 327 case PAUSE: 328 stateChange = State.PAUSED; 329 break; 325 330 } 326 331 command.ok(stateChange); … … 335 340 336 341 public static void audioMalfunction(Exception ex) { 337 JOptionPane.showMessageDialog(Main.parent,342 OptionPaneUtil.showMessageDialog(Main.parent, 338 343 "<html><p>" + tr(ex.getMessage()) + "</p></html>", 339 344 tr("Error playing sound"), JOptionPane.ERROR_MESSAGE); -
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r1674 r1865 20 20 21 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.actions.AboutAction;23 22 import org.openstreetmap.josm.actions.ShowStatusReportAction; 23 import org.openstreetmap.josm.gui.OptionPaneUtil; 24 24 import org.openstreetmap.josm.plugins.PluginHandler; 25 25 … … 39 39 if (e instanceof OutOfMemoryError) { 40 40 // do not translate the string, as translation may raise an exception 41 JOptionPane.showMessageDialog(Main.parent, "JOSM is out of memory. " +41 OptionPaneUtil.showMessageDialog(Main.parent, "JOSM is out of memory. " + 42 42 "Strange things may happen.\nPlease restart JOSM with the -Xmx###M option,\n" + 43 43 "where ### is the the number of MB assigned to JOSM (e.g. 256).\n" + 44 "Currently, " + Runtime.getRuntime().maxMemory()/1024/1024 + " MB are available to JOSM."); 44 "Currently, " + Runtime.getRuntime().maxMemory()/1024/1024 + " MB are available to JOSM.", 45 tr("Error"), 46 JOptionPane.ERROR_MESSAGE 47 ); 45 48 return; 46 49 } … … 50 53 51 54 Object[] options = new String[]{tr("Do nothing"), tr("Report Bug")}; 52 int answer = JOptionPane.showOptionDialog(Main.parent, tr("An unexpected exception occurred.\n\n" +53 "This is always a coding error. If you are running the latest\n" +55 int answer = OptionPaneUtil.showOptionDialog(Main.parent, tr("An unexpected exception occurred.\n\n" + 56 "This is always a coding error. If you are running the latest\n" + 54 57 "version of JOSM, please consider being kind and file a bug report."), 55 58 tr("Unexpected Exception"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, 56 null,options, options[0]);57 if (answer == 1) {59 options, options[0]); 60 if (answer == JOptionPane.YES_OPTION) { 58 61 try { 59 62 StringWriter stack = new StringWriter(); … … 65 68 JPanel p = new JPanel(new GridBagLayout()); 66 69 p.add(new JLabel("<html>" + tr("Please report a ticket at {0}","http://josm.openstreetmap.de/newticket") + 67 "<br>" + tr("Include your steps to get to the error (as detailed as possible)!") +68 "<br>" + tr("Try updating to the newest version of JOSM and all plugins before reporting a bug.") +69 "<br>" + tr("Be sure to include the following information:") + "</html>"), GBC.eol());70 "<br>" + tr("Include your steps to get to the error (as detailed as possible)!") + 71 "<br>" + tr("Try updating to the newest version of JOSM and all plugins before reporting a bug.") + 72 "<br>" + tr("Be sure to include the following information:") + "</html>"), GBC.eol()); 70 73 try { 71 74 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), new ClipboardOwner(){ … … 81 84 p.add(new JScrollPane(info), GBC.eop()); 82 85 83 JOptionPane.showMessageDialog(Main.parent, p);86 OptionPaneUtil.showMessageDialog(Main.parent, p, tr("Warning"), JOptionPane.WARNING_MESSAGE); 84 87 } catch (Exception e1) { 85 88 e1.printStackTrace(); -
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r1415 r1865 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 import org.openstreetmap.josm.Main; 6 import org.openstreetmap.josm.gui.OptionPaneUtil; 6 7 7 8 import java.awt.event.KeyEvent; … … 30 31 */ 31 32 public class Shortcut { 32 // public static final int SHIFT = KeyEvent.SHIFT_DOWN_MASK;33 // public static final int CTRL = KeyEvent.CTRL_DOWN_MASK;34 // public static final int SHIFT_CTRL = KeyEvent.SHIFT_DOWN_MASK|KeyEvent.CTRL_DOWN_MASK;33 // public static final int SHIFT = KeyEvent.SHIFT_DOWN_MASK; 34 // public static final int CTRL = KeyEvent.CTRL_DOWN_MASK; 35 // public static final int SHIFT_CTRL = KeyEvent.SHIFT_DOWN_MASK|KeyEvent.CTRL_DOWN_MASK; 35 36 public static final int SHIFT_DEFAULT = 1; 36 37 private String shortText; // the unique ID of the shortcut … … 135 136 public void setAssignedUser(boolean assignedUser) { 136 137 this.reset = (!this.assignedUser && assignedUser); 137 if (assignedUser) assignedDefault = false; 138 if (assignedUser) { 139 assignedDefault = false; 140 } 138 141 this.assignedUser = assignedUser; 139 142 } … … 215 218 // check if something collides with an existing shortcut 216 219 private static Shortcut findShortcut(int requestedKey, int modifier) { 217 if (modifier == groups.get(GROUP_NONE)) {220 if (modifier == groups.get(GROUP_NONE)) 218 221 return null; 219 }220 222 for (Shortcut sc : shortcuts.values()) { 221 if (sc.isSame(requestedKey, modifier)) {223 if (sc.isSame(requestedKey, modifier)) 222 224 return sc; 223 }224 225 } 225 226 return null; … … 238 239 for (int m : mods) { 239 240 for (int k = KeyEvent.VK_A; k < KeyEvent.VK_Z; k++) { // we'll limit ourself to 100% safe keys 240 if ( findShortcut(k, m) == null ) {241 if ( findShortcut(k, m) == null ) 241 242 return new Shortcut(shortText, longText, requestedKey, requestedGroup, k, m, false, false); 242 }243 243 } 244 244 } … … 281 281 while (p != null) { 282 282 Shortcut sc = new Shortcut(p); 283 if (sc.getAssignedUser()) registerShortcut(sc); 283 if (sc.getAssignedUser()) { 284 registerShortcut(sc); 285 } 284 286 i++; 285 287 p = Main.pref.get("shortcut.shortcut."+i, null); … … 290 292 while (p != null) { 291 293 Shortcut sc = new Shortcut(p); 292 if (!sc.getAssignedUser() && sc.getAssignedDefault()) registerShortcut(sc); 294 if (!sc.getAssignedUser() && sc.getAssignedDefault()) { 295 registerShortcut(sc); 296 } 293 297 i++; 294 298 p = Main.pref.get("shortcut.shortcut."+i, null); … … 299 303 while (p != null) { 300 304 Shortcut sc = new Shortcut(p); 301 if (!sc.getAssignedUser() && !sc.getAssignedDefault()) registerShortcut(sc); 305 if (!sc.getAssignedUser() && !sc.getAssignedDefault()) { 306 registerShortcut(sc); 307 } 302 308 i++; 303 309 p = Main.pref.get("shortcut.shortcut."+i, null); … … 307 313 // shutdown handling 308 314 public static void savePrefs() { 309 // we save this directly from the preferences pane, so don't overwrite these values here310 // for (int i = GROUP_NONE; i < GROUP__MAX+GROUPS_ALT2; i++) {311 // Main.pref.put("shortcut.groups."+i, Groups.get(i).toString());312 // }315 // we save this directly from the preferences pane, so don't overwrite these values here 316 // for (int i = GROUP_NONE; i < GROUP__MAX+GROUPS_ALT2; i++) { 317 // Main.pref.put("shortcut.groups."+i, Groups.get(i).toString()); 318 // } 313 319 int i = 0; 314 320 for (Shortcut sc : shortcuts.values()) { 315 // TODO: Remove sc.getAssignedUser() when we fixed all internal conflicts321 // TODO: Remove sc.getAssignedUser() when we fixed all internal conflicts 316 322 if (!sc.getAutomatic() && !sc.getReset() && sc.getAssignedUser()) { 317 323 Main.pref.put("shortcut.shortcut."+i, sc.asPrefString()); … … 326 332 // put a user configured shortcut in as-is -- unless there's a conflict 327 333 if(sc.getAssignedUser() && findShortcut(sc.getAssignedKey(), 328 sc.getAssignedModifier()) == null)334 sc.getAssignedModifier()) == null) { 329 335 shortcuts.put(sc.getShortText(), sc); 330 else336 } else { 331 337 registerShortcut(sc.getShortText(), sc.getLongText(), sc.getRequestedKey(), 332 sc.getRequestedGroup(), sc.getAssignedModifier(), sc); 338 sc.getRequestedGroup(), sc.getAssignedModifier(), sc); 339 } 333 340 } 334 341 … … 339 346 */ 340 347 public static Shortcut registerSystemShortcut(String shortText, String longText, int key, int modifier) { 341 if (shortcuts.containsKey(shortText)) {348 if (shortcuts.containsKey(shortText)) 342 349 return shortcuts.get(shortText); 343 }344 350 Shortcut potentialShortcut = findShortcut(key, modifier); 345 351 if (potentialShortcut != null) { … … 391 397 Integer defaultModifier = groups.get(requestedGroup + GROUPS_DEFAULT); 392 398 if(modifier != null) { 393 if(modifier == SHIFT_DEFAULT) 399 if(modifier == SHIFT_DEFAULT) { 394 400 defaultModifier |= KeyEvent.SHIFT_DOWN_MASK; 395 else401 } else { 396 402 defaultModifier = modifier; 403 } 397 404 } 398 405 else if (defaultModifier == null) { // garbage in, no shortcut out … … 437 444 // a lengthy warning message 438 445 private static void displayWarning(Shortcut conflictsWith, Shortcut potentialShortcut, String shortText, String longText) { 439 JOptionPane.showMessageDialog(Main.parent,446 OptionPaneUtil.showMessageDialog(Main.parent, 440 447 tr("Setting the keyboard shortcut ''{0}'' for the action ''{1}'' ({2}) failed\n"+ 441 448 "because the shortcut is already taken by the action ''{3}'' ({4}).\n\n", … … 447 454 tr("Using the shortcut ''{0}'' instead.\n\n", potentialShortcut.getKeyText()) 448 455 )+ 449 tr("(Hint: You can edit the shortcuts in the preferences.)") 456 tr("(Hint: You can edit the shortcuts in the preferences.)"), 457 tr("Error"), 458 JOptionPane.ERROR_MESSAGE 450 459 ); 451 460 }
Note:
See TracChangeset
for help on using the changeset viewer.