List of usage examples for java.awt FileDialog getDirectory
public String getDirectory()
From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java
/** * Method for enabling a user to choose a toolbar icon. * @param appLabel the label used to display the icon. * @param clearIconBtn the button used to clear the icon */// w ww. j a va 2 s . c om protected void chooseToolbarIcon(final JLabel appLabel, final JButton clearIconBtn) { FileDialog fileDialog = new FileDialog((Frame) UIRegistry.get(UIRegistry.FRAME), getResourceString("PREF_CHOOSE_APPICON_TITLE"), FileDialog.LOAD); //$NON-NLS-1$ fileDialog.setFilenameFilter(new ImageFilter()); UIHelper.centerAndShow(fileDialog); fileDialog.dispose(); String path = fileDialog.getDirectory(); if (StringUtils.isNotEmpty(path)) { String fullPath = path + File.separator + fileDialog.getFile(); File imageFile = new File(fullPath); if (imageFile.exists()) { ImageIcon newIcon = null; ImageIcon icon = new ImageIcon(fullPath); if (icon.getIconWidth() != -1 && icon.getIconHeight() != -1) { if (icon.getIconWidth() > 32 || icon.getIconHeight() > 32) { Image img = GraphicsUtils.getScaledImage(icon, 32, 32, false); if (img != null) { newIcon = new ImageIcon(img); } } else { newIcon = icon; } } ImageIcon appIcon; if (newIcon != null) { appLabel.setIcon(newIcon); clearIconBtn.setEnabled(true); String imgBufStr = GraphicsUtils.uuencodeImage(newAppIconName, newIcon); AppPreferences.getRemote().put(iconImagePrefName, imgBufStr); appIcon = newIcon; } else { appIcon = IconManager.getIcon("AppIcon"); appLabel.setIcon(appIcon); //$NON-NLS-1$ clearIconBtn.setEnabled(false); AppPreferences.getRemote().remove(iconImagePrefName); } IconEntry entry = IconManager.getIconEntryByName(INNER_APPICON_NAME); entry.setIcon(appIcon); if (entry.getIcons().get(IconManager.IconSize.Std32) != null) { entry.getIcons().get(IconManager.IconSize.Std32).setImageIcon(appIcon); } //((FormViewObj)form).getMVParent().set form.getValidator().dataChanged(null, null, null); } } }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java
/** * Export data /* w ww.jav a 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: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);/*from w w w .j a v a2s. c o m*/ if (fd.getFile() == null) { setStatus("Export CSV canceled"); //export canceled return; } 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: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 ww . j av a2s . c o m } 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: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);/*from www .j av a 2 s. c om*/ if (fd.getFile() == null) { setStatus("Export PNG canceled"); //export canceled return; } 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:edu.ucla.stat.SOCR.analyses.util.moduls.frm.Panels.Jpan_btn.java
private FitxerDades getFitxerDades(final String sPath) { final FileDialog fd = new FileDialog(fDialog, Language.getLabel(9), FileDialog.LOAD); FitxerDades fitx;/*from w w w. j av a 2 s .com*/ fitx = new FitxerDades(); fd.setDirectory(sPath); fd.setVisible(true); if (fd.getFile() == null) { fitx = null; } else { fitx.setNom(fd.getFile()); fitx.setPath(fd.getDirectory()); } return fitx; }
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 www . j a va 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: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);//from ww w .j a va 2 s .c o m //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:net.chaosserver.timelord.swingui.Timelord.java
/** * Persists out the timelord file and allows the user to choose where * the file should go.//from w ww. j av a 2s .c om * * @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:de.freese.base.swing.mac_os_x.MyApp.java
/** * @see/* www.ja v a2 s . c o m*/ * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @Override public void actionPerformed(final ActionEvent e) { Object source = e.getSource(); if (source == this.quitMI) { quit(); } else { if (source == this.optionsMI) { preferences(); } else { if (source == this.aboutMI) { about(); } else { if (source == this.openMI) { // File:Open action shows a FileDialog for loading displayable images FileDialog openDialog = new FileDialog(this); openDialog.setMode(FileDialog.LOAD); openDialog.setFilenameFilter(new FilenameFilter() { /** * @see java.io.FilenameFilter#accept(java.io.File, * java.lang.String) */ @Override public boolean accept(final File dir, final String name) { String[] supportedFiles = ImageIO.getReaderFormatNames(); for (String supportedFile : supportedFiles) { if (name.endsWith(supportedFile)) { return true; } } return false; } }); openDialog.setVisible(true); String filePath = openDialog.getDirectory() + openDialog.getFile(); if (filePath.length() > 0) { loadImageFile(filePath); } } } } } }