List of usage examples for java.awt FileDialog setVisible
public void setVisible(boolean b)
From source file:de.mycrobase.jcloudapp.Main.java
public void doUploadFile() { FileDialog dlg = new FileDialog((Dialog) null, "Upload File..."); dlg.setVisible(true); if (dlg.getDirectory() == null || dlg.getFile() == null) { return;/*from ww w . j av a 2 s . c o m*/ } File f = new File(dlg.getDirectory() + File.separator + dlg.getFile()); if (f.exists()) { setImageWorking(); JSONObject drop = upload(f); if (drop != null) { String url = getDropUrl(drop); System.out.println("Upload complete, URL:\n" + url); setClipboard(url); icon.displayMessage("Upload finished", String.format("Item: %s", f.getName()), TrayIcon.MessageType.INFO); } setImageNormal(); } }
From source file:de.uka.ilkd.key.dl.gui.initialdialog.gui.ToolInstaller.java
public void install(JComponent parent, Window dialog) { final File installDirectory; switch (OSInfosDefault.INSTANCE.getOs()) { case OSX://from w ww. jav a 2 s.com System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog d = new FileDialog(Frame.getFrames()[0], "Choose directory for installation of " + toolName, FileDialog.LOAD); d.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (d.getFile() != null) { installDirectory = new File(d.getDirectory(), d.getFile()); } else { installDirectory = null; } break; default: final JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Choose directory for installation of " + toolName); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setApproveButtonText("Install " + toolName + " here"); int result = chooser.showDialog(parent, "Install " + toolName + " here"); if (result == JFileChooser.APPROVE_OPTION) { installDirectory = chooser.getSelectedFile(); } else { installDirectory = null; } } if (installDirectory != null) { try { final File tmp = File.createTempFile("keymaeraDownload", "." + ft.toString().toLowerCase()); final FileInfo info = new FileInfo(url, tmp.getName(), false); final DownloadManager dlm = new DownloadManager(); ProgressBarWindow pbw = new ProgressBarWindow(parent, installDirectory, tmp, ft, ps, dialog); dlm.addListener(pbw); Runnable down = new Runnable() { @Override public void run() { dlm.downloadAll(new FileInfo[] { info }, 2000, tmp.getParentFile().getAbsolutePath(), true); } }; Thread thread = new Thread(down); thread.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:Forms.CreateGearForm.java
private GearSpec loadGearSpec() { //Get top level frame JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel); //Create dialog for choosing gearspec file FileDialog fd = new FileDialog(topFrame, "Choose a .gearspec file", FileDialog.LOAD); fd.setDirectory(System.getProperty("user.home")); fd.setFile("*.gearspec"); fd.setVisible(true); //Get file//from w ww. j a v a 2 s. c o m String filename = fd.getFile(); if (filename == null) System.out.println("You cancelled the choice"); else { System.out.println("You chose " + filename); //Get spec file File specFile = new File(fd.getDirectory() + Utils.pathSeparator() + filename); //If it exists, set it as the selected file path if (specFile.exists()) { //Generate spec return Utils.specForFile(specFile); } } return null; }
From source file:de.tbuchloh.kiskis.gui.dialogs.PropertyEditor.java
protected void onImport() { final FileDialog dlg = new FileDialog(this); dlg.setSelectedFile(new File(Settings.getLastFile())); dlg.setVisible(true); final File file = dlg.getSelectedFile(); if (file != null) { final PasswordDialog pdlg = new PasswordDialog(this, false); Toolkit.centerWindow(this, pdlg); pdlg.setVisible(true);/*from w w w.j a v a 2s . com*/ if (pdlg.getButton() != PasswordDialog.CANCEL_BUTTON) { final char[] pwd = pdlg.getPassword(); final ICryptoContext ctx = new PasswordCryptoContext(dlg.getSelectedAlgo(), new SimplePasswordProxy(pwd), file); doImportAccountTypes(ctx); } } }
From source file:jpad.MainEditor.java
public void openFile_OSX_Nix() { isOpen = true;/*from ww w .j a v a 2 s.c om*/ 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: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;/*w w w . j a va2 s .co 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:wsattacker.sso.openid.attacker.gui.MainGui.java
private void loadItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_loadItemActionPerformed FileDialog fd = new FileDialog(this, "Choose a file", FileDialog.LOAD); fd.setFile("*.xml"); fd.setVisible(true); File[] files = fd.getFiles(); if (files.length > 0) { File loadFile = files[0]; try {/* w w w. j a v a 2 s .co m*/ ToolConfiguration currentToolConfig = new ToolConfiguration(); currentToolConfig.setAttackerConfig(controller.getAttackerConfig()); currentToolConfig.setAnalyzerConfig(controller.getAnalyzerConfig()); XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, currentToolConfig); } catch (XmlPersistenceError ex) { Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex); } } /*int returnVal = loadFileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File loadFile = loadFileChooser.getSelectedFile(); try { XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, controller.getConfig()); } catch (XmlPersistenceError ex) { Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex); } }*/ }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaToolsDlg.java
/** * /*from ww w . j a v a 2 s .c o m*/ */ @SuppressWarnings("unchecked") protected void exportSchemaLocales() { FileDialog dlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), getResourceString("Save"), FileDialog.SAVE); dlg.setVisible(true); String fileName = dlg.getFile(); if (fileName != null) { final File outFile = new File(dlg.getDirectory() + File.separator + fileName); //final File outFile = new File("xxx.xml"); final SimpleGlassPane glassPane = new SimpleGlassPane(getResourceString("SL_EXPORT_SCHEMA"), 18); glassPane.setBarHeight(12); glassPane.setFillColor(new Color(0, 0, 0, 85)); setGlassPane(glassPane); glassPane.setVisible(true); SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { @Override protected Integer doInBackground() throws Exception { DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); int dispId = AppContextMgr.getInstance().getClassObject(Discipline.class).getDisciplineId(); String sql = String.format( "FROM SpLocaleContainer WHERE disciplineId = %d AND schemaType = %d", dispId, schemaType); List<SpLocaleContainer> spContainers = (List<SpLocaleContainer>) session.getDataList(sql); try { FileWriter fw = new FileWriter(outFile); //fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<vector>\n"); fw.write("<vector>\n"); BeanWriter beanWriter = new BeanWriter(fw); XMLIntrospector introspector = beanWriter.getXMLIntrospector(); introspector.getConfiguration().setWrapCollectionsInElement(true); beanWriter.getBindingConfiguration().setMapIDs(false); beanWriter.setWriteEmptyElements(false); beanWriter.enablePrettyPrint(); double step = 100.0 / (double) spContainers.size(); double total = 0.0; for (SpLocaleContainer container : spContainers) { // force Load of lazy collections container.getDescs().size(); container.getNames().size(); // Leaving this Code as an example of specifying the bewtixt file. /*InputStream inputStream = Specify.class.getResourceAsStream("datamodel/SpLocaleContainer.betwixt"); //InputStream inputStream = Specify.class.getResourceAsStream("/edu/ku/brc/specify/tools/schemalocale/SpLocaleContainer.betwixt"); InputSource inputSrc = new InputSource(inputStream); beanWriter.write(container, inputSrc); inputStream.close(); */ beanWriter.write(container); total += step; firePropertyChange("progress", 0, (int) total); } fw.write("</vector>\n"); fw.close(); } catch (Exception ex) { ex.printStackTrace(); } } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaLocalizerDlg.class, e); e.printStackTrace(); } finally { if (session != null) { session.close(); } } return null; } @Override protected void done() { super.done(); glassPane.setVisible(false); } }; backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (evt.getPropertyName().equals("progress")) { glassPane.setProgress((Integer) evt.getNewValue()); } } }); backupWorker.execute(); } }
From source file:livecanvas.mesheditor.MeshEditor.java
private void open(File file) { if (file == null) { FileDialog fd = new FileDialog(JOptionPane.getFrameForComponent(MeshEditor.this), "Load"); fd.setVisible(true); String file_str = fd.getFile(); if (file_str == null) { return; }/*from w w w . ja v a 2 s. c o m*/ file = new File(fd.getDirectory() + "/" + file_str); } try { StringWriter out = new StringWriter(); InputStreamReader in = new InputStreamReader(new FileInputStream(file)); Utils.copy(in, out); in.close(); out.close(); clear(); JSONObject doc = new JSONObject(out.toString()); Layer rootLayer = Layer.fromJSON(doc.getJSONObject("rootLayer")); layersView.setRootLayer(rootLayer); rootLayer.setCanvas(canvas); for (Layer layer : rootLayer.getSubLayersRecursively()) { layer.setCanvas(canvas); } JSONObject canvasJSON = doc.optJSONObject("canvas"); if (canvasJSON != null) { canvas.fromJSON(canvasJSON); } canvas.setCurrLayer(rootLayer); } catch (Exception e1) { e1.printStackTrace(); String msg = "An error occurred while trying to load."; JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(MeshEditor.this), msg, "Error", JOptionPane.ERROR_MESSAGE); } repaint(); }
From source file:livecanvas.mesheditor.MeshEditor.java
private void save(File file) { if (!canSave()) { return;/*from w w w .j a v a2 s. c o m*/ } if (file == null) { FileDialog fd = new FileDialog(JOptionPane.getFrameForComponent(MeshEditor.this), "Save"); fd.setVisible(true); String file_str = fd.getFile(); if (file_str == null) { return; } file = new File(fd.getDirectory() + "/" + file_str); } try { Layer rootLayer = layersView.getRootLayer(); for (Layer l : rootLayer.getSubLayersRecursively()) { Path path = l.getPath(); if (path.isFinalized()) { Mesh mesh = path.getMesh(); if (mesh.getControlPointsCount() < 2) { String msg = "At least one mesh has less than 2 control points.\n" + "You may not be able to use it for animation. Do you\n" + "still want to continue?"; if (JOptionPane.showConfirmDialog(this, msg, "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) { return; } else { break; } } } } PrintWriter out = new PrintWriter(new FileOutputStream(file)); JSONObject doc = new JSONObject(); doc.put("rootLayer", rootLayer.toJSON()); doc.put("canvas", canvas.toJSON()); doc.write(out); out.close(); } catch (Exception e1) { e1.printStackTrace(); String msg = "An error occurred while trying to load."; JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(MeshEditor.this), msg, "Error", JOptionPane.ERROR_MESSAGE); } repaint(); }