List of usage examples for java.awt FileDialog FileDialog
public FileDialog(Dialog parent, String title, int mode)
From source file:PlayerOfMedia.java
/*************************************************************************** * React to menu selections (quit or open) or one of the the buttons on the * dialog boxes./*from w w w . ja va2 s.co m*/ **************************************************************************/ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof MenuItem) { ////////////////////////////////////////////////// // Quit and free up any player acquired resources. ////////////////////////////////////////////////// if (e.getActionCommand().equalsIgnoreCase("QUIT")) { if (player != null) { player.stop(); player.close(); } System.exit(0); } ///////////////////////////////////////////////////////// // User to open/play media. Show the selection dialog box. ///////////////////////////////////////////////////////// else if (e.getActionCommand().equalsIgnoreCase("OPEN")) { selectionDialog.show(); } } ////////////////////// // One of the Buttons. ////////////////////// else { ///////////////////////////////////////////////////////////// // User to browse the local file system. Popup a file dialog. ///////////////////////////////////////////////////////////// if (e.getSource() == choose) { FileDialog choice = new FileDialog(this, "Media File Choice", FileDialog.LOAD); if (lastDirectory != null) choice.setDirectory(lastDirectory); choice.show(); String selection = choice.getFile(); if (selection != null) { lastDirectory = choice.getDirectory(); mediaName.setText("file://" + choice.getDirectory() + selection); } } /////////////////////////////////////////////// // User chooses to cancel opening of new media. /////////////////////////////////////////////// else if (e.getSource() == cancel) { selectionDialog.hide(); } /////////////////////////////////////////////////////// // User has selected the name of the media. Attempt to // create a Player. /////////////////////////////////////////////////////// else if (e.getSource() == open) { selectionDialog.hide(); createAPlayer(mediaName.getText()); } //////////////////////////////////////////// // User has seen error message. Now hide it. //////////////////////////////////////////// else if (e.getSource() == ok) errorDialog.hide(); } }
From source file:uk.nhs.cfh.dsp.srth.desktop.modules.resultexplanationpanel.QueryStatisticsCollectionPanel.java
/** * Creates the statements panel./* w w w.j a v a 2s . c om*/ * * @param textArea the text area * @param title the title * * @return the j panel */ private synchronized JPanel createStatementsPanel(final JTextArea textArea, String title) { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(), BorderFactory.createTitledBorder(title))); // create buttons for copy and export JButton copyButton = new JButton(new AbstractAction("Copy") { public void actionPerformed(ActionEvent event) { StringSelection selection = new StringSelection(textArea.getSelectedText()); // get contents of text area and copy to system clipboard Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, QueryStatisticsCollectionPanel.this); } }); JButton exportButton = new JButton(new AbstractAction("Export") { public void actionPerformed(ActionEvent event) { // open a file dialog and export the contents FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(), "Select file to export to", FileDialog.SAVE); fd.setVisible(true); String fileName = fd.getFile(); String fileDirectory = fd.getDirectory(); if (fileDirectory != null && fileName != null) { File file = new File(fileDirectory, fileName); try { String contents = textArea.getText(); FileWriter fw = new FileWriter(file); fw.flush(); fw.write(contents); fw.close(); // inform user // manager.getStatusMessageLabel().setText("Successfully saved contents to file "+fileName); logger.info("Successfully saved contents to file " + fileName); } catch (IOException e) { logger.warn(e.fillInStackTrace()); // manager.getStatusMessageLabel().setText("Errors saving contents to file "+fileName); } } } }); // create buttons panel JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS)); buttonsPanel.add(Box.createHorizontalStrut(200)); buttonsPanel.add(copyButton); buttonsPanel.add(exportButton); panel.add(buttonsPanel, BorderLayout.SOUTH); panel.add(new JScrollPane(textArea), BorderLayout.CENTER); return panel; }
From source file:utybo.branchingstorytree.swing.editor.StoryEditor.java
public boolean saveAs() { FileDialog fd = new FileDialog(OpenBSTGUI.getInstance(), Lang.get("editor.saveloc"), FileDialog.SAVE); fd.setLocationRelativeTo(OpenBSTGUI.getInstance()); fd.setVisible(true);/*www . j av a 2 s . co m*/ if (fd.getFile() != null) { final File file = new File(fd.getFile().endsWith(".bst") ? fd.getDirectory() + fd.getFile() : fd.getDirectory() + fd.getFile() + ".bst"); try { doSave(file); lastFileLocation = file; return true; } catch (IOException | BSTException e1) { OpenBST.LOG.error("Failed saving a file", e1); Messagers.showException(OpenBSTGUI.getInstance(), Lang.get("editor.savefail"), e1); } } return false; }
From source file:de.uka.ilkd.key.dl.gui.initialdialog.gui.ToolInstaller.java
public void install(JComponent parent, Window dialog) { final File installDirectory; switch (OSInfosDefault.INSTANCE.getOs()) { case OSX:/* w ww . j a v a 2 s.co m*/ System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog d = new FileDialog(Frame.getFrames()[0], "Choose directory for installation of " + toolName, FileDialog.LOAD); d.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (d.getFile() != null) { installDirectory = new File(d.getDirectory(), d.getFile()); } else { installDirectory = null; } break; default: final JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Choose directory for installation of " + toolName); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setApproveButtonText("Install " + toolName + " here"); int result = chooser.showDialog(parent, "Install " + toolName + " here"); if (result == JFileChooser.APPROVE_OPTION) { installDirectory = chooser.getSelectedFile(); } else { installDirectory = null; } } if (installDirectory != null) { try { final File tmp = File.createTempFile("keymaeraDownload", "." + ft.toString().toLowerCase()); final FileInfo info = new FileInfo(url, tmp.getName(), false); final DownloadManager dlm = new DownloadManager(); ProgressBarWindow pbw = new ProgressBarWindow(parent, installDirectory, tmp, ft, ps, dialog); dlm.addListener(pbw); Runnable down = new Runnable() { @Override public void run() { dlm.downloadAll(new FileInfo[] { info }, 2000, tmp.getParentFile().getAbsolutePath(), true); } }; Thread thread = new Thread(down); thread.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:net.chaosserver.timelord.swingui.Timelord.java
/** * Persists out the timelord file and allows the user to choose where * the file should go.// w w w . j av a 2 s. c o m * * @param rwClassName the name of the RW class * (e.g. "net.chaosserver.timelord.data.ExcelDataReaderWriter") * @param userSelect allows the user to select where the file should * be persisted. */ public void writeTimeTrackData(String rwClassName, boolean userSelect) { try { Class<?> rwClass = Class.forName(rwClassName); TimelordDataReaderWriter timelordDataRW = (TimelordDataReaderWriter) rwClass.newInstance(); int result = JFileChooser.APPROVE_OPTION; File outputFile = timelordDataRW.getDefaultOutputFile(); if (timelordDataRW instanceof TimelordDataReaderWriterUI) { TimelordDataReaderWriterUI timelordDataReaderWriterUI = (TimelordDataReaderWriterUI) timelordDataRW; timelordDataReaderWriterUI.setParentFrame(applicationFrame); JDialog configDialog = timelordDataReaderWriterUI.getConfigDialog(); configDialog.pack(); configDialog.setLocationRelativeTo(applicationFrame); configDialog.setVisible(true); } if (userSelect) { if (OsUtil.isMac()) { FileDialog fileDialog = new FileDialog(applicationFrame, "Select File", FileDialog.SAVE); fileDialog.setDirectory(outputFile.getParent()); fileDialog.setFile(outputFile.getName()); fileDialog.setVisible(true); if (fileDialog.getFile() != null) { outputFile = new File(fileDialog.getDirectory(), fileDialog.getFile()); } } else { JFileChooser fileChooser = new JFileChooser(outputFile.getParentFile()); fileChooser.setSelectedFile(outputFile); fileChooser.setFileFilter(timelordDataRW.getFileFilter()); result = fileChooser.showSaveDialog(applicationFrame); if (result == JFileChooser.APPROVE_OPTION) { outputFile = fileChooser.getSelectedFile(); } } } if (result == JFileChooser.APPROVE_OPTION) { timelordDataRW.writeTimelordData(getTimelordData(), outputFile); } } catch (Exception e) { JOptionPane.showMessageDialog(applicationFrame, "Error writing to file.\n" + "Do you have the output file open?", "Save Error", JOptionPane.ERROR_MESSAGE, applicationIcon); if (log.isErrorEnabled()) { log.error("Error persisting file", e); } } }
From source file:edu.ku.brc.specify.tools.l10nios.StrLocalizerAppForiOS.java
/** * /* w ww .jav a2s. c o m*/ */ public void startUp() { //AskForDirectory afd = new AskForDirectory(frame); //currentPath = afd.getDirectory(); FileDialog dlg = new FileDialog(frame, "Select a Directory", FileDialog.LOAD); UIHelper.centerAndShow(dlg); String currentPath = dlg.getDirectory(); if (StringUtils.isNotEmpty(currentPath)) { if (doSrcParsing) { File rootDir = new File("/Users/rods/Documents/SVN/SpecifyInsightL10N"); srcIndexer = new L10NSrcIndexer(rootDir); doScanSources(); } boolean isDirOK = true; rootDir = new File(currentPath); if (!rootDir.exists()) { String dirPath = getFullPath(currentPath); rootDir = new File(dirPath); isDirOK = rootDir.exists(); } if (isDirOK) { createUI(); register(MAINPANE, mainPane); frame.setGlassPane(glassPane = GhostGlassPane.getInstance()); frame.setLocationRelativeTo(null); Toolkit.getDefaultToolkit().setDynamicLayout(true); register(GLASSPANE, glassPane); if (setupSrcFiles(rootDir) > 0) { frame.pack(); UIHelper.centerAndShow(frame); destLanguage = doChooseLangLocale(Locale.ENGLISH); if (destLanguage != null) { destLbl.setText(destLanguage.getDisplayName() + ":"); return; } } else { UIRegistry.showError("The are no localizable files in the directory you selected."); System.exit(0); } } } UIRegistry.showError("StrLocalizer will exit."); System.exit(0); }
From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java
@Override protected void exportButtonActionPerformed(ActionEvent evt) { String outputDirectory = null; String outputFile = null;//from w w w .j a v a 2s . c o m String measurement = (String) measurementLineResultComboBox.getSelectedItem(); Integer step = Integer.parseInt(stepLineResultTextField.getText()); FileDialog fileopen = new FileDialog(new Frame(), "Open Results Directory", FileDialog.SAVE); fileopen.setModalityType(ModalityType.DOCUMENT_MODAL); fileopen.setVisible(true); if (fileopen.getFile() != null) { outputDirectory = fileopen.getDirectory(); outputFile = fileopen.getFile(); } if (outputDirectory != null && outputFile != null) { new CSVParser().parse(outputDirectory, outputFile, resultFiles, measurement, step); } }
From source file:Forms.CreateGearForm.java
private Boolean saveSpec(GearSpec spec) { //Get top level frame JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel); //Create dialog for choosing gearspec file FileDialog fd = new FileDialog(topFrame, "Save .gearspec file", FileDialog.SAVE); fd.setDirectory(System.getProperty("user.home")); // Gets the name that is specified for the spec in the beginning fd.setFile(spec.getName() + ".gearspec"); fd.setVisible(true);/* w w w .jav a 2 s . com*/ //Get file String filename = fd.getFile(); if (filename == null) { System.out.println("You cancelled the choice"); return false; } else { System.out.println("You chose " + filename); //Get spec file File specFile = new File(fd.getDirectory() + Utils.pathSeparator() + filename); //Serialize spec to string String gearString = gson.toJson(spec); try { //If it exists, set it as the selected file path if (specFile.exists()) { FileUtils.forceDelete(specFile); } //Write new spec FileUtils.write(specFile, gearString); } catch (IOException e) { e.printStackTrace(); showSaveErrorDialog(); return false; } return true; } }
From source file:com.awesheet.models.Workbook.java
@Override public void onMessage(final UIMessage message) { switch (message.getType()) { case UIMessageType.CREATE_SHEET: { addSheet(new Sheet(this, "Sheet " + (newSheetID + 1))); break;//from w w w .j a va2 s.c om } case UIMessageType.SELECT_SHEET: { SelectSheetMessage uiMessage = (SelectSheetMessage) message; selectSheet(uiMessage.getSheet()); break; } case UIMessageType.DELETE_SHEET: { DeleteSheetMessage uiMessage = (DeleteSheetMessage) message; removeSheet(uiMessage.getSheet()); break; } case UIMessageType.CREATE_BAR_CHART: { CreateBarChartMessage uiMessage = (CreateBarChartMessage) message; // Get selected cells. Cell selectedCells[] = getSelectedSheet().collectSelectedCells(); BarChart chart = new BarChart(selectedCells); chart.setNameX(uiMessage.getXaxis()); chart.setNameY(uiMessage.getYaxis()); chart.setTitle(uiMessage.getTitle()); if (!chart.generateImageData()) { UIMessageManager.getInstance().dispatchAction( new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error", "Could not create a chart. Please make sure the cells you selected are in the correct format."))); break; } UIMessageManager.getInstance() .dispatchAction(new ShowPopupAction<ChartPopup>(UIPopupType.VIEW_CHART_POPUP, new ChartPopup(new Base64().encodeAsString(chart.getImageData())))); break; } case UIMessageType.CREATE_LINE_CHART: { CreateLineChartMessage uiMessage = (CreateLineChartMessage) message; // Get selected cells. Cell selectedCells[] = getSelectedSheet().collectSelectedCells(); LineChart chart = new LineChart(selectedCells); chart.setNameX(uiMessage.getXaxis()); chart.setNameY(uiMessage.getYaxis()); chart.setTitle(uiMessage.getTitle()); if (!chart.generateImageData()) { UIMessageManager.getInstance().dispatchAction( new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error", "Could not create a chart. Please make sure the cells you selected are in the correct format."))); break; } UIMessageManager.getInstance() .dispatchAction(new ShowPopupAction<ChartPopup>(UIPopupType.VIEW_CHART_POPUP, new ChartPopup(new Base64().encodeAsString(chart.getImageData())))); break; } case UIMessageType.SAVE_CHART_IMAGE: { final SaveChartImageMessage uiMessage = (SaveChartImageMessage) message; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { byte imageData[] = new Base64().decode(uiMessage.getImageData()); FileDialog dialog = new FileDialog(MainFrame.getInstance(), "Save Chart Image", FileDialog.SAVE); dialog.setFile("*.png"); dialog.setVisible(true); dialog.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return (dir.isFile() && name.endsWith(".png")); } }); String filePath = dialog.getFile(); String directory = dialog.getDirectory(); dialog.dispose(); if (directory != null && filePath != null) { String absolutePath = new File(directory + filePath).getAbsolutePath(); if (!FileManager.getInstance().saveFile(absolutePath, imageData)) { UIMessageManager.getInstance() .dispatchAction(new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error", "Could not save chart image."))); } } } }); break; } } }
From source file:Forms.CreateGearForm.java
private GearSpec loadGearSpec() { //Get top level frame JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel); //Create dialog for choosing gearspec file FileDialog fd = new FileDialog(topFrame, "Choose a .gearspec file", FileDialog.LOAD); fd.setDirectory(System.getProperty("user.home")); fd.setFile("*.gearspec"); fd.setVisible(true);// w ww.ja v a 2 s .c o m //Get file String filename = fd.getFile(); if (filename == null) System.out.println("You cancelled the choice"); else { System.out.println("You chose " + filename); //Get spec file File specFile = new File(fd.getDirectory() + Utils.pathSeparator() + filename); //If it exists, set it as the selected file path if (specFile.exists()) { //Generate spec return Utils.specForFile(specFile); } } return null; }