List of usage examples for java.awt FileDialog LOAD
int LOAD
To view the source code for java.awt FileDialog LOAD.
Click Source Link
From source file:Main.java
/** * Select the file path via {@linkplain FileDialog}. * //w w w .java 2 s .c o m * @param parent * the parent of {@linkplain FileDialog} * @param title * the title of {@linkplain FileDialog} * @return the selected path */ public static String selectPath(Frame parent, String title) { FileDialog dialog = new FileDialog(parent, title, FileDialog.LOAD); dialog.setVisible(true); String dir = dialog.getDirectory(); dialog.dispose(); return dir; }
From source file:Main.java
/** * @param jFrame//from www. ja v a2s.c om * @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:MainClass.java
MainClass() { super("MainClass"); setSize(200, 200);/*from ww w. j a va 2s . c om*/ fc = new FileDialog(this, "Choose a file", FileDialog.LOAD); fc.setDirectory("C:\\"); Button b; add(b = new Button("Browse...")); // Create and add a Button b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fc.setVisible(true); String fn = fc.getFile(); if (fn == null) System.out.println("You cancelled the choice"); else System.out.println("You chose " + fn); } }); }
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); fileDialog.setModal(true);// w w w .j a v a 2s.c om 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:com.vilt.minium.app.controller.FileController.java
@RequestMapping("/open") @ResponseBody//from w w w .j a v a 2s.c o m public TextFileResult openFile() throws IOException { fileDialog.setTitle("Open Javascript File"); fileDialog.setMode(FileDialog.LOAD); fileDialog.setFile("*.js"); fileDialog.setVisible(true); if (fileDialog.getFile() != null) { File file = new File(fileDialog.getDirectory(), fileDialog.getFile()); return new TextFileResult(file); } else { throw new CanceledException("Open file operation was cancelled"); } }
From source file:GUIMediaStatistics.java
/************************************************************************ * Respond to user button presses - either browsing for a file or * gathering format info on the current file. ************************************************************************/ public void actionPerformed(ActionEvent e) { ///////////////////////////////// // Browse - use FileDialog class. ///////////////////////////////// if (e.getSource() == browseButton) { FileDialog choice = new FileDialog(this, "Media File Choice", FileDialog.LOAD); if (lastDirectory != null) choice.setDirectory(lastDirectory); choice.show();/*w ww . j ava2 s. c om*/ String selection = choice.getFile(); if (selection != null) { lastDirectory = choice.getDirectory(); mediaField.setText("file://" + choice.getDirectory() + selection); } } //////////////////////////////////////////////////////// // Get statistics - create a MediaStatistics object and // monitor its progress. /////////////////////////////////////////////////////// else { stats = new MediaStatistics(mediaField.getText()); monitorAndReport(); } }
From source file:jpad.MainEditor.java
public void openFile_OSX_Nix() { isOpen = true;/* www . jav a2 s . c o 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:MDIApp.java
private MenuBar createMenuBar() { ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { String command = ae.getActionCommand(); if (command.equals("Open")) { if (fd == null) { fd = new FileDialog(MDIApp.this, "Open File", FileDialog.LOAD); fd.setDirectory("/movies"); }//from w w w . j av a2s . c o m fd.show(); if (fd.getFile() != null) { String filename = fd.getDirectory() + fd.getFile(); openFile("file:" + filename); } } else if (command.equals("Exit")) { dispose(); System.exit(0); } } }; MenuItem item; MenuBar mb = new MenuBar(); // File Menu Menu mnFile = new Menu("File"); mnFile.add(item = new MenuItem("Open")); item.addActionListener(al); mnFile.add(item = new MenuItem("Exit")); item.addActionListener(al); // Options Menu Menu mnOptions = new Menu("Options"); cbAutoLoop = new CheckboxMenuItem("Auto replay"); cbAutoLoop.setState(true); mnOptions.add(cbAutoLoop); mb.add(mnFile); mb.add(mnOptions); return mb; }
From source file:FileViewer.java
/** * Handle button clicks/*from ww w . j av a2s. c om*/ */ public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("open")) { // If user clicked "Open" button // Create a file dialog box to prompt for a new file to display FileDialog f = new FileDialog(this, "Open File", FileDialog.LOAD); f.setDirectory(directory); // Set the default directory // Display the dialog and wait for the user's response f.show(); directory = f.getDirectory(); // Remember new default directory setFile(directory, f.getFile()); // Load and display selection f.dispose(); // Get rid of the dialog box } else if (cmd.equals("close")) // If user clicked "Close" button this.dispose(); // then close the window }
From source file:edu.ku.brc.specify.tasks.services.PickListUtils.java
/** * @param localizableIO/*from ww w .j a v a 2 s . c om*/ * @param collection * @return */ public static boolean importPickLists(final LocalizableIOIFace localizableIO, final Collection collection) { // Apply is Import All PickLists FileDialog dlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), getResourceString(getI18n("PL_IMPORT")), FileDialog.LOAD); dlg.setDirectory(UIRegistry.getUserHomeDir()); dlg.setFile(getPickListXMLName()); UIHelper.centerAndShow(dlg); String dirStr = dlg.getDirectory(); String fileName = dlg.getFile(); if (StringUtils.isEmpty(dirStr) || StringUtils.isEmpty(fileName)) { return false; } final String path = dirStr + fileName; File file = new File(path); if (!file.exists()) { UIRegistry.showLocalizedError(getI18n("PL_FILE_NOT_EXIST"), file.getAbsoluteFile()); return false; } List<BldrPickList> bldrPickLists = DataBuilder.getBldrPickLists(null, file); Integer cnt = null; boolean wasErr = false; DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); session.beginTransaction(); HashMap<String, PickList> plHash = new HashMap<String, PickList>(); List<PickList> items = getPickLists(localizableIO, true, false); for (PickList pl : items) { plHash.put(pl.getName(), pl); //System.out.println("["+pl.getName()+"]"); } for (BldrPickList bpl : bldrPickLists) { PickList pickList = plHash.get(bpl.getName()); //System.out.println("["+bpl.getName()+"]["+(pickList != null ? pickList.getName() : "null") + "]"); if (pickList == null) { // External PickList is new pickList = createPickList(bpl, collection); session.saveOrUpdate(pickList); if (cnt == null) cnt = 0; cnt++; } else if (!pickListsEqual(pickList, bpl)) { session.delete(pickList); collection.getPickLists().remove(pickList); pickList = createPickList(bpl, collection); session.saveOrUpdate(pickList); collection.getPickLists().add(pickList); if (cnt == null) cnt = 0; cnt++; } } session.commit(); } catch (Exception ex) { wasErr = true; if (session != null) session.rollback(); ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PickListEditorDlg.class, ex); } finally { if (session != null) { session.close(); } } String key = wasErr ? "PL_ERR_IMP" : cnt != null ? "PL_WASIMPORT" : "PL_MATCHIMP"; UIRegistry.displayInfoMsgDlgLocalized(getI18n(key), cnt); return true; }