(final String prompt,
final String callbackMethod,
final File defaultSelection,
final Object callbackObject,
final Frame parentFrame,
final int mode,
final PApplet sketch)
| 6573 | // Will remove the 'sketch' parameter once we get an upstream JOGL fix |
| 6574 | // https://github.com/processing/processing/issues/3831 |
| 6575 | static protected void selectImpl(final String prompt, |
| 6576 | final String callbackMethod, |
| 6577 | final File defaultSelection, |
| 6578 | final Object callbackObject, |
| 6579 | final Frame parentFrame, |
| 6580 | final int mode, |
| 6581 | final PApplet sketch) { |
| 6582 | EventQueue.invokeLater(new Runnable() { |
| 6583 | public void run() { |
| 6584 | File selectedFile = null; |
| 6585 | |
| 6586 | boolean hide = (sketch != null) && |
| 6587 | (sketch.g instanceof PGraphicsOpenGL) && (platform == WINDOWS); |
| 6588 | if (hide) sketch.surface.setVisible(false); |
| 6589 | |
| 6590 | if (useNativeSelect) { |
| 6591 | FileDialog dialog = new FileDialog(parentFrame, prompt, mode); |
| 6592 | if (defaultSelection != null) { |
| 6593 | dialog.setDirectory(defaultSelection.getParent()); |
| 6594 | dialog.setFile(defaultSelection.getName()); |
| 6595 | } |
| 6596 | |
| 6597 | dialog.setVisible(true); |
| 6598 | String directory = dialog.getDirectory(); |
| 6599 | String filename = dialog.getFile(); |
| 6600 | if (filename != null) { |
| 6601 | selectedFile = new File(directory, filename); |
| 6602 | } |
| 6603 | |
| 6604 | } else { |
| 6605 | JFileChooser chooser = new JFileChooser(); |
| 6606 | chooser.setDialogTitle(prompt); |
| 6607 | if (defaultSelection != null) { |
| 6608 | chooser.setSelectedFile(defaultSelection); |
| 6609 | } |
| 6610 | |
| 6611 | int result = -1; |
| 6612 | if (mode == FileDialog.SAVE) { |
| 6613 | result = chooser.showSaveDialog(parentFrame); |
| 6614 | } else if (mode == FileDialog.LOAD) { |
| 6615 | result = chooser.showOpenDialog(parentFrame); |
| 6616 | } |
| 6617 | if (result == JFileChooser.APPROVE_OPTION) { |
| 6618 | selectedFile = chooser.getSelectedFile(); |
| 6619 | } |
| 6620 | } |
| 6621 | |
| 6622 | if (hide) sketch.surface.setVisible(true); |
| 6623 | selectCallback(selectedFile, callbackMethod, callbackObject); |
| 6624 | } |
| 6625 | }); |
| 6626 | } |
| 6627 | |
| 6628 | |
| 6629 | /** |
no outgoing calls
no test coverage detected