List of usage examples for java.awt FileDialog FileDialog
public FileDialog(Dialog parent, String title, int mode)
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);//ww w .ja va2 s .co m fd.setVisible(true); File files[] = fd.getFiles(); for (File file : files) { handleUpload(file, room, type); } }
From source file:org.tinymediamanager.ui.TmmUIHelper.java
private static Path openFileDialog(String title, int mode, String filename) throws Exception, Error { FileDialog chooser = new FileDialog(MainWindow.getFrame(), title, mode); if (lastDir != null) { chooser.setDirectory(lastDir.toFile().getAbsolutePath()); }//from ww w . ja va 2 s . com if (mode == FileDialog.SAVE) { chooser.setFile(filename); } chooser.setVisible(true); if (StringUtils.isNotEmpty(chooser.getFile())) { lastDir = Paths.get(chooser.getDirectory()); return Paths.get(chooser.getDirectory(), chooser.getFile()); } else { return null; } }
From source file:jpad.MainEditor.java
public void openFile_OSX_Nix() { isOpen = true;/*from w w w . j a v a 2s .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, "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"); }// w w w . ja v a 2 s. 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:org.mbs3.juniuploader.gui.pnlWoWDirectories.java
private void btnAddDirectoryActionPerformed(ActionEvent evt) { if (evt.getSource() == this.btnAddDirectory) { boolean failed = false; boolean mac = Util.isMac(); if (mac) { java.awt.Frame f = jUniUploader.inst; FileDialog fd = new FileDialog(f, "Select a World of Warcraft Directory", FileDialog.LOAD); try { fd.show();/* w ww . j av a 2 s . com*/ String fileName = fd.getFile(); String rootDir = fd.getDirectory(); String completePath = (rootDir == null ? "" : rootDir) + (fileName == null ? "" : fileName); log.debug("Adding OS X style " + completePath); if (completePath != null) { File file = new File(completePath); if (file != null && file.exists() && file.isDirectory()) { WDirectory wd = new WDirectory(file); frmMain.wowDirectories.addElement(wd); } } } catch (Exception ex) { failed = true; log.warn("Failed trying to display a FileDialog, falling back to JFileChooser", ex); } } if (!mac || failed) { JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); if (file != null && file.exists() && file.isDirectory()) { WDirectory wd = new WDirectory(file); frmMain.wowDirectories.addElement(wd); } } else { log.trace("Open command cancelled by user."); } } } }
From source file:FileViewer.java
/** * Handle button clicks/*from w w w . j av a2 s . co m*/ */ 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/* www . j a v a 2s. c o m*/ * @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; }
From source file:jpad.MainEditor.java
public void saveAs_OSX_Nix() { String fileToSaveTo = null;/*from w w w .ja v a2s .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, "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: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/* w ww . j a v a2 s . co 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); } }
From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java
/** * * @param columnsFormulasToPrint/*from w w w . ja va2 s .c o m*/ * 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); } }