List of usage examples for java.awt FileDialog getFile
public String getFile()
From source file:org.sbml.bargraph.MainWindow.java
/** * Handles the "Open" menu item in the File menu. * @param evt//from w w w.ja va2 s . c om */ public void openFileHandler(java.awt.event.ActionEvent evt) { Log.note("'Open' menu item invoked."); FileDialog dialog = new FileDialog(this, "Choose file to graph"); dialog.setVisible(true); if (dialog.getFile() == null) { Log.note("User cancelled file selection"); return; } VerifiableFile theFile = new VerifiableFile(dialog.getDirectory() + dialog.getFile()); if (theFile.isVerifiedFile()) { Log.note("User selected file '" + theFile.getPath() + "'"); try { updatePanelForSBMLFile(theFile); } catch (Exception e) { Log.error(e.getMessage()); } } else { Log.note("Invalid file selected: '" + theFile.getPath() + "'"); Dialog.error(this, "Invalid file selected: " + theFile.getName(), "File error"); } }
From source file:uk.nhs.cfh.dsp.srth.desktop.modules.resultexplanationpanel.QueryStatisticsCollectionPanel.java
/** * Creates the statements panel./*from ww w . ja va 2 s. c o m*/ * * @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:PlayerOfMedia.java
/*************************************************************************** * React to menu selections (quit or open) or one of the the buttons on the * dialog boxes.// w w w. j a va 2 s .c om **************************************************************************/ 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:jpad.MainEditor.java
public void openFile_OSX_Nix() { isOpen = true;/*from w w w . j a v a2 s . co m*/ FilenameFilter awtFilter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { String lowercaseName = name.toLowerCase(); if (lowercaseName.endsWith(".txt")) return true; else return false; } }; FileDialog fd = new FileDialog(this, "Open Text File", FileDialog.LOAD); fd.setFilenameFilter(awtFilter); fd.setVisible(true); if (fd.getFile() == null) return; else curFile = fd.getDirectory() + fd.getFile(); //TODO: actually open the file try (FileInputStream inputStream = new FileInputStream(curFile)) { String allText = org.apache.commons.io.IOUtils.toString(inputStream); mainTextArea.setText(allText); } catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Error While Reading", JOptionPane.ERROR_MESSAGE); } JRootPane root = this.getRootPane(); root.putClientProperty("Window.documentFile", new File(curFile)); root.putClientProperty("Window.documentModified", Boolean.FALSE); hasChanges = false; hasSavedToFile = true; this.setTitle(String.format("JPad - %s", curFile)); isOpen = false; }
From source file:de.mycrobase.jcloudapp.Main.java
public void doUploadFile() { FileDialog dlg = new FileDialog((Dialog) null, "Upload File..."); dlg.setVisible(true);/*w w w .j a va 2 s.c o m*/ if (dlg.getDirectory() == null || dlg.getFile() == null) { return; } File f = new File(dlg.getDirectory() + File.separator + dlg.getFile()); if (f.exists()) { setImageWorking(); JSONObject drop = upload(f); if (drop != null) { String url = getDropUrl(drop); System.out.println("Upload complete, URL:\n" + url); setClipboard(url); icon.displayMessage("Upload finished", String.format("Item: %s", f.getName()), TrayIcon.MessageType.INFO); } setImageNormal(); } }
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);/*from w w w .j a v a2s . co 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; }
From source file:no.java.swing.SingleSelectionFileDialog.java
private Result showNativeDialog(Component target, boolean open) { Window window = target == null ? null : (Frame) SwingUtilities.getWindowAncestor(target); FileDialog dialog; if (window instanceof Frame) { dialog = new FileDialog((Frame) window); } else if (window instanceof Dialog) { dialog = new FileDialog((Dialog) window); } else {//from w w w . j a v a 2s. com throw new IllegalStateException("Unknown window type"); } dialog.setDirectory(previousDirectory.getAbsolutePath()); dialog.setMode(open ? FileDialog.LOAD : FileDialog.SAVE); dialog.setVisible(true); if (rememberPreviousLocation) { previousDirectory = new File(dialog.getDirectory()); } if (dialog.getFile() == null) { return Result.CANCEL; } selected = new File(dialog.getFile()); return Result.APPROVE; }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaToolsDlg.java
/** * /*from ww w.j ava 2s.c o m*/ */ private void importSchema(final boolean doLocalization) { FileDialog fileDlg = new FileDialog((Dialog) null); fileDlg.setTitle(getResourceString(doLocalization ? SL_CHS_LOC : SL_CHS_IMP)); UIHelper.centerAndShow(fileDlg); String fileName = fileDlg.getFile(); if (StringUtils.isNotEmpty(fileName)) { String title = getResourceString(doLocalization ? "SL_L10N_SCHEMA" : "SL_IMPORT_SCHEMA"); final File file = new File(fileDlg.getDirectory() + File.separator + fileName); final SimpleGlassPane glassPane = new SimpleGlassPane(title, 18); glassPane.setBarHeight(12); glassPane.setFillColor(new Color(0, 0, 0, 85)); setGlassPane(glassPane); glassPane.setVisible(true); SwingWorker<Integer, Integer> importWorker = new SwingWorker<Integer, Integer>() { private boolean isOK = false; @Override protected Integer doInBackground() throws Exception { DataProviderSessionIFace localSession = null; try { localSession = DataProviderFactory.getInstance().createSession(); localSession.beginTransaction(); BuildSampleDatabase bsd = new BuildSampleDatabase(); Discipline discipline = localSession.get(Discipline.class, AppContextMgr.getInstance().getClassObject(Discipline.class).getId()); isOK = bsd.loadSchemaLocalization(discipline, schemaType, DBTableIdMgr.getInstance(), null, //catFmtName, null, //accFmtName, doLocalization ? UpdateType.eLocalize : UpdateType.eImport, // isDoingUpdate file, // external file glassPane, localSession); if (isOK) { localSession.commit(); } else { localSession.rollback(); } } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BuildSampleDatabase.class, ex); } finally { if (localSession != null) { localSession.close(); } } return null; } @Override protected void done() { super.done(); glassPane.setVisible(false); if (isOK) { UIRegistry.showLocalizedMsg("Specify.ABT_EXIT"); CommandDispatcher.dispatch(new CommandAction("App", "AppReqExit")); } } }; importWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (evt.getPropertyName().equals("progress")) { glassPane.setProgress((Integer) evt.getNewValue()); } } }); importWorker.execute(); } }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaToolsDlg.java
/** * // w ww . j a va 2s . c o m */ @SuppressWarnings("unchecked") protected void exportSchemaLocales() { FileDialog dlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), getResourceString("Save"), FileDialog.SAVE); dlg.setVisible(true); String fileName = dlg.getFile(); if (fileName != null) { final File outFile = new File(dlg.getDirectory() + File.separator + fileName); //final File outFile = new File("xxx.xml"); final SimpleGlassPane glassPane = new SimpleGlassPane(getResourceString("SL_EXPORT_SCHEMA"), 18); glassPane.setBarHeight(12); glassPane.setFillColor(new Color(0, 0, 0, 85)); setGlassPane(glassPane); glassPane.setVisible(true); SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { @Override protected Integer doInBackground() throws Exception { DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); int dispId = AppContextMgr.getInstance().getClassObject(Discipline.class).getDisciplineId(); String sql = String.format( "FROM SpLocaleContainer WHERE disciplineId = %d AND schemaType = %d", dispId, schemaType); List<SpLocaleContainer> spContainers = (List<SpLocaleContainer>) session.getDataList(sql); try { FileWriter fw = new FileWriter(outFile); //fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<vector>\n"); fw.write("<vector>\n"); BeanWriter beanWriter = new BeanWriter(fw); XMLIntrospector introspector = beanWriter.getXMLIntrospector(); introspector.getConfiguration().setWrapCollectionsInElement(true); beanWriter.getBindingConfiguration().setMapIDs(false); beanWriter.setWriteEmptyElements(false); beanWriter.enablePrettyPrint(); double step = 100.0 / (double) spContainers.size(); double total = 0.0; for (SpLocaleContainer container : spContainers) { // force Load of lazy collections container.getDescs().size(); container.getNames().size(); // Leaving this Code as an example of specifying the bewtixt file. /*InputStream inputStream = Specify.class.getResourceAsStream("datamodel/SpLocaleContainer.betwixt"); //InputStream inputStream = Specify.class.getResourceAsStream("/edu/ku/brc/specify/tools/schemalocale/SpLocaleContainer.betwixt"); InputSource inputSrc = new InputSource(inputStream); beanWriter.write(container, inputSrc); inputStream.close(); */ beanWriter.write(container); total += step; firePropertyChange("progress", 0, (int) total); } fw.write("</vector>\n"); fw.close(); } catch (Exception ex) { ex.printStackTrace(); } } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaLocalizerDlg.class, e); e.printStackTrace(); } finally { if (session != null) { session.close(); } } return null; } @Override protected void done() { super.done(); glassPane.setVisible(false); } }; backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (evt.getPropertyName().equals("progress")) { glassPane.setProgress((Integer) evt.getNewValue()); } } }); backupWorker.execute(); } }
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://from w w w. ja v a 2 s .com 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(); } } }