List of usage examples for java.awt FileDialog FileDialog
public FileDialog(Dialog parent)
From source file:Main.java
static FileDialog getFileDialog(Component parentComponent) { FileDialog dialog;/*from w w w . j av a 2s . c om*/ Window window = getComponentWindow(parentComponent); if (window instanceof Frame) { dialog = new FileDialog((Frame) window); } else { dialog = new FileDialog((Dialog) window); } return dialog; }
From source file:Main.java
/** * @param jFrame/*from w w w.ja v a 2 s . com*/ * @param currentDirectory * @return You can get the filename with fileDialog.getFile(), * and you can get the directory with fileDialog.getDirectory(). * String filename = fileDialog.getDirectory() + System.getProperty("file.separator") + fileDialog.getFile(); * */ public static FileDialog letUserChooseFile(JFrame jFrame, String currentDirectory) { FileDialog fileDialog = new FileDialog(jFrame); fileDialog.setModal(true); fileDialog.setMode(FileDialog.LOAD); fileDialog.setTitle("Open a File"); if (currentDirectory != null && !currentDirectory.trim().equals("")) { fileDialog.setDirectory(currentDirectory); } fileDialog.setVisible(true); return fileDialog; }
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;//ww w . j a va 2 s .c om if (window instanceof Frame) { dialog = new FileDialog((Frame) window); } else if (window instanceof Dialog) { dialog = new FileDialog((Dialog) window); } else { 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:org.neo4j.desktop.ui.BrowseForDatabaseActionListener.java
private File macFileSelection() { System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog fileDialog = new FileDialog(frame); fileDialog.setDirectory(directoryDisplay.getText()); fileDialog.setVisible(true);//w w w .j a va 2s. co m File selectedFile = new File(fileDialog.getDirectory(), fileDialog.getFile()); System.setProperty("apple.awt.fileDialogForDirectories", "false"); return selectedFile; }
From source file:org.cds06.speleograph.actions.OpenAction.java
/** * Invoked when an action occurs.//from www .jav a 2 s .c o 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:net.brtly.monkeyboard.gui.MasterControlPanel.java
private static String createAndShowSdkChooser() { String sdk;/*from w w w . j ava2 s. c o m*/ System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog d = new FileDialog(new JFrame()); d.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); sdk = d.getDirectory(); return sdk; }
From source file:de.freese.base.swing.mac_os_x.MyApp.java
/** * @see//from w w w . j a va2 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); } } } } } }
From source file:Sampler.java
private void createUI() { setFont(new Font("Serif", Font.PLAIN, 12)); setLayout(new BorderLayout()); // Set our location to the left of the image frame. setSize(200, 350);// w w w . j a v a 2s. co m Point pt = mImageFrame.getLocation(); setLocation(pt.x - getSize().width, pt.y); final Checkbox accumulateCheckbox = new Checkbox("Accumulate", false); final Label statusLabel = new Label(""); // Make a sorted list of the operators. Enumeration e = mOps.keys(); Vector names = new Vector(); while (e.hasMoreElements()) names.addElement(e.nextElement()); Collections.sort(names); final java.awt.List list = new java.awt.List(); for (int i = 0; i < names.size(); i++) list.add((String) names.elementAt(i)); add(list, BorderLayout.CENTER); // When an item is selected, do the corresponding transformation. list.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { if (ie.getStateChange() != ItemEvent.SELECTED) return; String key = list.getSelectedItem(); BufferedImageOp op = (BufferedImageOp) mOps.get(key); BufferedImage source = mSplitImageComponent.getSecondImage(); boolean accumulate = accumulateCheckbox.getState(); if (source == null || accumulate == false) source = mSplitImageComponent.getImage(); String previous = mImageFrame.getTitle() + " + "; if (accumulate == false) previous = ""; mImageFrame.setTitle(previous + key); statusLabel.setText("Performing " + key + "..."); list.setEnabled(false); accumulateCheckbox.setEnabled(false); BufferedImage destination = op.filter(source, null); mSplitImageComponent.setSecondImage(destination); mSplitImageComponent.setSize(mSplitImageComponent.getPreferredSize()); mImageFrame.setSize(mImageFrame.getPreferredSize()); list.setEnabled(true); accumulateCheckbox.setEnabled(true); statusLabel.setText("Performing " + key + "...done."); } }); Button loadButton = new Button("Load..."); loadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { FileDialog fd = new FileDialog(Sampler.this); fd.show(); if (fd.getFile() == null) return; String path = fd.getDirectory() + fd.getFile(); mSplitImageComponent.setImage(path); mSplitImageComponent.setSecondImage(null); // Utilities.sizeContainerToComponent(mImageFrame, // mSplitImageComponent); mImageFrame.validate(); mImageFrame.repaint(); } }); Panel bottom = new Panel(new GridLayout(2, 1)); Panel topBottom = new Panel(); topBottom.add(accumulateCheckbox); topBottom.add(loadButton); bottom.add(topBottom); bottom.add(statusLabel); add(bottom, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { mImageFrame.dispose(); dispose(); System.exit(0); } }); }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaToolsDlg.java
/** * /*from w w w. j a va 2 s.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:org.broad.igv.hic.MainWindow.java
private void loadMenuItemActionPerformed(ActionEvent e) { FileDialog dlg = new FileDialog(this); dlg.setMode(FileDialog.LOAD); dlg.setVisible(true);/*from w ww . jav a 2 s . com*/ String file = dlg.getFile(); if (file != null) { try { File f = new File(dlg.getDirectory(), dlg.getFile()); load(f.getAbsolutePath()); } catch (IOException e1) { e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } }