List of usage examples for java.awt FileDialog setVisible
public void setVisible(boolean b)
From source file:uk.nhs.cfh.dsp.srth.desktop.actions.querycrud.core.actions.LoadSavedQueryTask.java
/** * Do in background.//from w w w . j av a 2 s .c o m * * @return the query statement * * @throws Exception the exception */ @Override protected Void doInBackground() throws Exception { // open file dialog FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(), "Select file to load", FileDialog.LOAD); fd.setVisible(true); fileSelected = fd.getFile(); String directorySelected = fd.getDirectory(); if (fileSelected != null && directorySelected != null) { File physicalFile = new File(directorySelected, fileSelected); // use file name load file from XMLLoader loader = new XMLLoader(); Document doc = loader.getXMLDoc(physicalFile); query = queryExpressionXMLConverter.getQueryStatementFromElement(doc.getRootElement()); if (query != null) { // assign physical location to query query.setPhysicalLocation(physicalFile.toURI()); // register query and set to active query queryService.registerQuery(query); queryService.queryChanged(query, this); } } return null; }
From source file:org.jivesoftware.spark.plugin.fileupload.ChatRoomDecorator.java
private void getUploadUrl(ChatRoom room, Message.Type type) { FileDialog fd = new FileDialog((Frame) null, "Choose a file to upload", FileDialog.LOAD); fd.setMultipleMode(true);/*from w w w . j ava2 s. com*/ fd.setVisible(true); File files[] = fd.getFiles(); for (File file : files) { handleUpload(file, room, type); } }
From source file:uk.nhs.cfh.dsp.srth.desktop.modules.queryresultspanel.actions.ExportResultTask.java
@Override protected Void doInBackground() throws Exception { // open file dialog to get save location FileDialog fd = new FileDialog(applicationService.getFrameView().getActiveFrame(), "Select location to save", FileDialog.SAVE); fd.setVisible(true); String selectedFile = fd.getFile(); String selectedDirectory = fd.getDirectory(); if (selectedDirectory != null && selectedFile != null && resultSet != null) { try {/*ww w . ja v a2 s . c o m*/ // save to selected location File file = new File(selectedDirectory, selectedFile); // export to flat file FileWriter fw = new FileWriter(file); fw.flush(); // add column names to data String cols = ""; int colNum = resultSet.getMetaData().getColumnCount(); for (int c = 0; c < colNum; c++) { cols = cols + "\t" + resultSet.getMetaData().getColumnName(c + 1); } // trim line and add new line character cols = cols.trim(); cols = cols + "\n"; // write to file fw.write(cols); float totalRows = resultSetCount; float percent = 0; int counter = 0; // reset resultSet to first row in case its been iterated over before resultSet.beforeFirst(); while (resultSet.next()) { String line = ""; for (int l = 0; l < colNum; l++) { Object o = resultSet.getObject(l + 1); if (o instanceof Date) { o = sdf.format((Date) o); } else if (o instanceof byte[]) { byte[] bytes = (byte[]) o; o = UUID.nameUUIDFromBytes(bytes).toString(); } line = line + "\t" + o.toString(); } // trim line line = line.trim(); // append new line character to line line = line + "\n"; // write to file fw.write(line); // update progress bar percent = (counter / totalRows) * 100; setProgress((int) percent); setMessage("Exported " + counter + " of " + totalRows + " rows"); counter++; } // close file writer fw.close(); } catch (IOException e) { logger.warn("Nested exception is : " + e.fillInStackTrace()); } } return null; }
From source file:org.cds06.speleograph.actions.OpenAction.java
/** * Invoked when an action occurs./* w w w .ja v a2 s . co m*/ */ @Override public void actionPerformed(ActionEvent e) { chooser.setCurrentDirectory(SpeleoGraphApp.getWorkingDirectory()); File file = null; if (SpeleoGraphApp.isMac()) { do { if (file != null && !fileFilter.accept(file)) { JOptionPane.showMessageDialog(SpeleoGraphApp.getInstance(), I18nSupport.translate("actions.open.formaterror"), I18nSupport.translate("error"), JOptionPane.ERROR_MESSAGE); } FileDialog chooserMac = new FileDialog(SpeleoGraphApp.getInstance()); chooserMac.setDirectory(SpeleoGraphApp.getWorkingDirectory().getAbsolutePath()); chooserMac.setVisible(true); if (chooserMac.getFile() == null) return; file = FileUtils.getFile(chooserMac.getDirectory(), chooserMac.getFile()); if (file.isDirectory()) return; } while (!fileFilter.accept(file)); } else { int result = chooser.showOpenDialog(parent); switch (result) { case JFileChooser.APPROVE_OPTION: file = chooser.getSelectedFile(); if (file.isDirectory()) return; break; case JFileChooser.CANCEL_OPTION: default: SpeleoGraphApp.setWorkingDirectory(chooser.getCurrentDirectory()); return; } } try { SpeleoGraphApp.setWorkingDirectory(file.getParentFile()); reader.readFile(file); } catch (FileReadingError e1) { log.error("Error when try to read a SpeleoGraph File", e1); } }
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); if (fd.getFile() != null) { final File file = new File(fd.getFile().endsWith(".bst") ? fd.getDirectory() + fd.getFile() : fd.getDirectory() + fd.getFile() + ".bst"); try {/*from ww w .j av a 2 s . c o m*/ 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:processing.app.tools.Archiver.java
public void run() { SketchController sketch = editor.getSketchController(); // first save the sketch so that things don't archive strangely boolean success = false; try {/*from w w w . ja v a2s .c o m*/ success = sketch.save(); } catch (Exception e) { e.printStackTrace(); } if (!success) { Base.showWarning(tr("Couldn't archive sketch"), tr("Archiving the sketch has been canceled because\nthe sketch couldn't save properly."), null); return; } File location = sketch.getSketch().getFolder(); String name = location.getName(); File parent = new File(location.getParent()); //System.out.println("loc " + location); //System.out.println("par " + parent); File newbie = null; String namely = null; int index = 0; do { // only use the date if the sketch name isn't the default name useDate = !name.startsWith("sketch_"); if (useDate) { String purty = dateFormat.format(new Date()); String stamp = purty + ((char) ('a' + index)); namely = name + "-" + stamp; newbie = new File(parent, namely + ".zip"); } else { String diggie = numberFormat.format(index + 1); namely = name + "-" + diggie; newbie = new File(parent, namely + ".zip"); } index++; } while (newbie.exists()); // open up a prompt for where to save this fella FileDialog fd = new FileDialog(editor, tr("Archive sketch as:"), FileDialog.SAVE); fd.setDirectory(parent.getAbsolutePath()); fd.setFile(newbie.getName()); fd.setVisible(true); String directory = fd.getDirectory(); String filename = fd.getFile(); // only write the file if not canceled if (filename != null) { newbie = new File(directory, filename); ZipOutputStream zos = null; try { //System.out.println(newbie); zos = new ZipOutputStream(new FileOutputStream(newbie)); // recursively fill the zip file buildZip(location, name, zos); // close up the jar file zos.flush(); editor.statusNotice("Created archive " + newbie.getName() + "."); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(zos); } } else { editor.statusNotice(tr("Archive sketch canceled.")); } }
From source file:ec.display.chart.StatisticsChartPaneTab.java
/** * This method initializes jButton /*from ww w . j a va 2 s.com*/ * * @return javax.swing.JButton */ private JButton getPrintButton() { if (printButton == null) { printButton = new JButton(); printButton.setText("Export to PDF..."); final JFreeChart chart = chartPane.getChart(); printButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { int width = chartPane.getWidth(); int height = chartPane.getHeight(); FileDialog fileDialog = new FileDialog(new Frame(), "Export...", FileDialog.SAVE); fileDialog.setDirectory(System.getProperty("user.dir")); fileDialog.setFile("*.pdf"); fileDialog.setVisible(true); String fileName = fileDialog.getFile(); if (fileName != null) { if (!fileName.endsWith(".pdf")) { fileName = fileName + ".pdf"; } File f = new File(fileDialog.getDirectory(), fileName); Document document = new Document(new com.lowagie.text.Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(f)); document.addAuthor("ECJ Console"); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2, rectangle2D); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); } } catch (Exception ex) { ex.printStackTrace(); } } }); } return printButton; }
From source file:org.sbml.bargraph.MainWindow.java
/** * Handles the "Open" menu item in the File menu. * @param evt//from w ww .ja v a 2 s. co m */ 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.//w ww .jav a 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: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 .ja v a 2 s. co m*/ 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; }