List of usage examples for java.awt FileDialog setVisible
public void setVisible(boolean b)
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); //Get file// w w w . ja v a2s . c o m 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:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java
@Override protected void exportButtonActionPerformed(ActionEvent evt) { String outputDirectory = null; String outputFile = null;//from www . j a va2 s .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:com.declarativa.interprolog.gui.Ini.java
public void GraphAnalysis() { String fileToLoad, folder;/* w w w . j av a 2 s.c o m*/ File filetoreconsult = null; FileDialog d = new FileDialog(this, "Consult file..."); d.setVisible(true); fileToLoad = d.getFile(); folder = d.getDirectory(); if (fileToLoad != null) { ArgBuildManager manag = new ArgBuildManager(); manag.GraphFileRules(folder, fileToLoad);//Call to the ArgBuildManager! /* filetoreconsult = new File(folder, fileToLoad); if (engine.consultAbsolute(filetoreconsult)) { addToReloaders(filetoreconsult, "consult"); } */ //System.out.println("file:"+filetoreconsult.); } }
From source file:JDAC.JDAC.java
public void saveData() { DateFormat df = new SimpleDateFormat("ddmmyy_HHmm"); FileDialog fd = new FileDialog(this, "Export as...", FileDialog.SAVE); fd.setFile("Data_" + df.format(new Date()) + ".csv"); fd.setVisible(true); if (fd.getFile() == null) { setStatus("Export CSV canceled"); //export canceled return;/*from w ww .ja v a2 s .c o m*/ } try { BufferedWriter out = new BufferedWriter(new FileWriter(fd.getDirectory() + fd.getFile())); out.write(dataToCSVstring()); out.close(); setStatus("Export CSV successful"); } catch (IOException e) { JOptionPane.showMessageDialog(this, "" + "Error while exporting data...\n" + "If the error persists please contact the system administrator"); return; } }
From source file:JDAC.JDAC.java
public void exportPNG() { DateFormat df = new SimpleDateFormat("ddmmyy_HHmm"); FileDialog fd = new FileDialog(this, "Export as...", FileDialog.SAVE); fd.setFile("Chart_" + df.format(new Date()) + ".png"); fd.setVisible(true); if (fd.getFile() == null) { setStatus("Export PNG canceled"); //export canceled return;//from ww w. ja v a 2 s. co m } mChart.setTitle(currentSensor); try { ChartUtilities.saveChartAsPNG(new File(fd.getDirectory() + fd.getFile()), mChart, Definitions.exportPNGwidth, Definitions.exportPNGheight); setStatus("Export PNG successful"); } catch (IOException e) { JOptionPane.showMessageDialog(this, "" + "Error while exporting chart...\n" + "If the error persists please contact the system administrator"); mChart.setTitle(mainChartPreviewTitle); return; } mChart.setTitle(mainChartPreviewTitle); }
From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java
/** * * @param columnsFormulasToPrint// www .j a v a 2 s . c om * If null, print all columns * @param stripNewLinesInCells * @param filePath * Full path to save file to; if null, user will be prompted. */ public void saveFilteredRowsToFile(List<Integer> columnsFormulasToPrint, boolean stripNewLinesInCells, String filePath) { String saveTo; if (filePath == null) { FileDialog dialog = new FileDialog(new Frame(), "Save filtered rows to", FileDialog.SAVE); dialog.setVisible(true); saveTo = dialog.getDirectory(); if (saveTo == null) return; saveTo += "/" + dialog.getFile(); } else { saveTo = filePath; } PrintWriter out = null; try { out = new PrintWriter(saveTo); StringBuffer b = new StringBuffer(); if (columnsFormulasToPrint == null) { for (int i = 0; i < this.getColumnCount(); i++) { b.append(getColumnName(i)); if (i < getColumnCount() - 1) b.append("\t"); } } else { int index = 0; for (int i : columnsFormulasToPrint) { b.append(getColumnName(i)); if (index + 1 < columnsFormulasToPrint.size()) b.append("\t"); index++; } } out.println(b); for (int i = 0; i < model.getRowCount(); i++) { int rowIndex = convertRowIndexToView(i); if (rowIndex > -1) { if (columnsFormulasToPrint == null) if (stripNewLinesInCells) out.println(getRowAsString(rowIndex).replaceAll("\n", " ")); else out.println(getRowAsString(rowIndex)); else { boolean first = true; for (int column : columnsFormulasToPrint) { if (!first) { out.print("\t"); } first = false; SpreadsheetCell cell = (SpreadsheetCell) getValueAt(rowIndex, column); if (cell != null) { String formula = cell.getFormula(); if (formula != null) { if (stripNewLinesInCells) out.print(formula.replaceAll("\n", " ")); else out.print(formula); } } } out.println(""); } } } out.close(); } catch (FileNotFoundException e) { Utils.printStack(e); Utils.displayMessage("Could not save table", true, LogLevel.ERROR); } }
From source file:com.moneydance.modules.features.importlist.io.MacOSDirectoryChooser.java
@Override void chooseBaseDirectory() { System.setProperty("apple.awt.fileDialogForDirectories", "true"); final FileDialog fileDialog = new FileDialog((Frame) null, this.getLocalizable().getDirectoryChooserTitle(), FileDialog.LOAD);//from w w w. j av a 2s.com fileDialog.setModal(true); fileDialog.setFilenameFilter(DirectoryValidator.INSTANCE); try { fileDialog.setDirectory(FileUtils.getUserDirectory().getAbsolutePath()); } catch (SecurityException e) { LOG.log(Level.WARNING, e.getMessage(), e); } if (this.getBaseDirectory() != null) { final File parentDirectory = this.getBaseDirectory().getParentFile(); if (parentDirectory != null) { fileDialog.setDirectory(parentDirectory.getAbsolutePath()); } } fileDialog.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (fileDialog.getFile() == null) { return; } this.getPrefs() .setBaseDirectory(new File(fileDialog.getDirectory(), fileDialog.getFile()).getAbsolutePath()); LOG.info(String.format("Base directory is %s", this.getPrefs().getBaseDirectory())); }
From source file:jpad.MainEditor.java
public void saveAs_OSX_Nix() { String fileToSaveTo = null;/*from www .j a va 2 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, "Save Text File", FileDialog.SAVE); fd.setDirectory(System.getProperty("java.home")); if (curFile == null) fd.setFile("Untitled.txt"); else fd.setFile(curFile); fd.setFilenameFilter(awtFilter); fd.setVisible(true); if (fd.getFile() != null) fileToSaveTo = fd.getDirectory() + fd.getFile(); else { fileToSaveTo = fd.getFile(); return; } curFile = fileToSaveTo; JRootPane root = this.getRootPane(); root.putClientProperty("Window.documentFile", new File(curFile)); hasChanges = false; hasSavedToFile = true; }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java
/** * Export data //from ww w .ja va 2 s . c o m */ protected void exportSingleLocale() { statusBar.setText(getResourceString("SchemaLocalizerFrame.EXPORTING")); //$NON-NLS-1$ statusBar.paintImmediately(statusBar.getBounds()); schemaLocPanel.getAllDataFromUI(); if (localizableIO.hasChanged()) { if (UIRegistry.askYesNoLocalized("SAVE", "CANCEL", UIRegistry.getResourceString("SchemaLocalizerFrame.NEEDS_SAVING"), "SAVE") == JOptionPane.YES_NO_OPTION) { localizableIO.save(); } else { return; } } Vector<Locale> stdLocales = SchemaI18NService.getInstance().getStdLocaleList(false); final JList list = new JList(stdLocales); list.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value != null) { setText(((Locale) value).getDisplayName()); } return this; } }); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g")); pb.add(UIHelper.createScrollPane(list), (new CellConstraints()).xy(1, 1)); pb.setDefaultDialogBorder(); final CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(), getResourceString("SchemaLocalizerFrame.CHOOSE_LOCALE"), true, pb.getPanel()); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { dlg.getOkBtn().setEnabled(list.getSelectedValue() != null); } } }); dlg.createUI(); dlg.getOkBtn().setEnabled(false); UIHelper.centerAndShow(dlg); if (!dlg.isCancelled()) { Locale locale = (Locale) list.getSelectedValue(); if (locale != null) { FileDialog fileDlg = new FileDialog((Frame) UIRegistry.getTopWindow(), getResourceString("SchemaLocalizerFrame.SVFILENAME"), FileDialog.SAVE); fileDlg.setVisible(true); String fileName = fileDlg.getFile(); if (StringUtils.isNotEmpty(fileName)) { File outFile = new File(fileDlg.getDirectory() + File.separator + fileName); boolean savedOK = localizableIO.exportSingleLanguageToDirectory(outFile, locale); if (savedOK) { String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTEDTO", locale.getDisplayName(), outFile.getAbsolutePath()); UIRegistry.displayInfoMsgDlg(msg); } else { String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTING_ERR", outFile.getAbsolutePath()); UIRegistry.showError(msg); } } } } }
From source file:br.upe.ecomp.dosa.view.mainwindow.MainWindowActions.java
private void openTestScenario() { FileDialog fileopen = new FileDialog(this, "Open Test Scenario", FileDialog.LOAD); fileopen.setFilenameFilter(new FilenameFilter() { @Override//from w w w . j a v a2 s . c o m public boolean accept(File dir, String name) { return name.toLowerCase().endsWith("xml"); } }); fileopen.setVisible(true); if (fileopen.getFile() != null) { filePath = fileopen.getDirectory(); fileName = fileopen.getFile(); algorithm = AlgorithmXMLParser.read(filePath, fileName); configureTree(); updateToolBarButtonsState(); ((CardLayout) panelTestScenario.getLayout()).last(panelTestScenario); } }