/** This method cannot be called directly. */ public void actionPerformed(ActionEvent e) { FileDialog chooser = new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE); chooser.setVisible(true); String filename = chooser.getFile(); if (filename != null) { StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile()); } }
public static File FileSaveDialog(String title) { // Open File Dialog: FileDialog filedialog = new FileDialog((Frame) null, title, FileDialog.SAVE); filedialog.setVisible(true); File fileSelected = null; try { fileSelected = new File(filedialog.getDirectory(), filedialog.getFile()); } catch (Exception e) { } return fileSelected; }
private void openAddressBook() { FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); fileDialog.setFilterExtensions(new String[] {"*.messages;", "*.*"}); fileDialog.setFilterNames( new String[] { resMessages.getString("Book_filter_name") + " (*.messages)", resMessages.getString("All_filter_name") + " (*.*)" }); String name = fileDialog.open(); openAddressBook(name); }
private void openFileMenuItemWidgetSelected(SelectionEvent evt) { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); String filename = dialog.open(); if (filename != null) { getShell().setText(filename); File file = new File(filename); XML.load(file); try { XML.Match(); setStatus(XML.Output); } catch (JDOMException e) { e.printStackTrace(); } } }
// public static final String showElementTreeAction = "showElementTree"; // ------------------------------------------------------------- public void openFile(String currDirStr, String currFileStr) { if (fileDialog == null) { fileDialog = new FileDialog(this); } fileDialog.setMode(FileDialog.LOAD); if (!(currDirStr.equals(""))) { fileDialog.setDirectory(currDirStr); } if (!(currFileStr.equals(""))) { fileDialog.setFile(currFileStr); } fileDialog.show(); String file = fileDialog.getFile(); // cancel pushed if (file == null) { return; } String directory = fileDialog.getDirectory(); File f = new File(directory, file); if (f.exists()) { Document oldDoc = getEditor().getDocument(); if (oldDoc != null) // oldDoc.removeUndoableEditListener(undoHandler); /* if (elementTreePanel != null) { elementTreePanel.setEditor(null); } */ getEditor().setDocument(new PlainDocument()); fileDialog.setTitle(file); Thread loader = new FileLoader(f, editor1.getDocument()); loader.start(); } }
private void doExportTimeTree() { FileDialog dialog = new FileDialog(this, "Export Time Tree File...", FileDialog.SAVE); dialog.setVisible(true); if (dialog.getFile() != null) { File file = new File(dialog.getDirectory(), dialog.getFile()); PrintStream ps = null; try { ps = new PrintStream(file); writeTimeTreeFile(ps); ps.close(); } catch (IOException ioe) { JOptionPane.showMessageDialog( this, "Error writing tree file: " + ioe.getMessage(), "Export Error", JOptionPane.ERROR_MESSAGE); } } }
protected void doExportData() { FileDialog dialog = new FileDialog(this, "Export Data File...", FileDialog.SAVE); dialog.setVisible(true); if (dialog.getFile() != null) { File file = new File(dialog.getDirectory(), dialog.getFile()); Writer writer = null; try { writer = new PrintWriter(file); treesPanel.writeDataFile(writer); writer.close(); } catch (IOException ioe) { JOptionPane.showMessageDialog( this, "Error writing data file: " + ioe.getMessage(), "Export Error", JOptionPane.ERROR_MESSAGE); } } }
private boolean saveAs() { FileDialog saveDialog = new FileDialog(shell, SWT.SAVE); saveDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"}); saveDialog.setFilterNames(new String[] {"Address Books (*.adr)", "All Files "}); saveDialog.open(); String name = saveDialog.getFileName(); if (name.equals("")) return false; if (name.indexOf(".adr") != name.length() - 4) { name += ".adr"; } File file = new File(saveDialog.getFilterPath(), name); if (file.exists()) { MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO); box.setText(resAddressBook.getString("Save_as_title")); box.setMessage( resAddressBook.getString("File") + file.getName() + " " + resAddressBook.getString("Query_overwrite")); if (box.open() != SWT.YES) { return false; } } this.file = file; return save(); }
@Override public void execute() throws Exception { FileDialog fd = new FileDialog((Frame) context.getStage().getNativeWindow()); fd.setMode(FileDialog.LOAD); fd.setTitle("Import Other Graphics File"); fd.setVisible(true); if (fd.getFile() != null) { File file = new File(fd.getDirectory(), fd.getFile()); u.p("opening a file" + file); try { load(file); context.main.recentFiles.add(file); } catch (Exception e) { e.printStackTrace(); } } }
/** * Checks whether the given window is either a FileDialog, or contains a JFileChooser component. * If so, its current directory is stored in the given properties. * * @param aNamespace the name space to use; * @param aProperties the properties to store the found directory in; * @param aWindow the window to check for. */ private static void loadFileDialogState(final Preferences aProperties, final Window aWindow) { final String propKey = "lastDirectory"; if (aWindow instanceof FileDialog) { final String dir = aProperties.get(propKey, null); if (dir != null) { ((FileDialog) aWindow).setDirectory(dir); } } else if (aWindow instanceof JDialog) { final Container contentPane = ((JDialog) aWindow).getContentPane(); final JFileChooser fileChooser = (JFileChooser) findComponent(contentPane, JFileChooser.class); if (fileChooser != null) { final String dir = aProperties.get(propKey, null); if (dir != null) { fileChooser.setCurrentDirectory(new File(dir)); } } } }
/** Handle ItemEvents. */ public void itemStateChanged(ItemEvent e) { final String dialog_title = ResourceHandler.getMessage("template_dialog.title"); Component target = (Component) e.getSource(); if (target == recursiveCheckBox) { converter.setRecurse(recursiveCheckBox.isSelected()); } else if (target == staticVersioningRadioButton || target == dynamicVersioningRadioButton) { converter.setStaticVersioning(staticVersioningRadioButton.isSelected()); } else if (target == templateCh && (e.getStateChange() == e.SELECTED)) { // Process only when item is Selected // Get the current template selection String choiceStr = (String) templateCh.getSelectedItem(); // If the user chooses 'other', display a file dialog to allow // them to select a template file. if (choiceStr.equals(TemplateFileChoice.OTHER_STR)) { String templatePath = null; FileDialog fd = new FileDialog(this, dialog_title, FileDialog.LOAD); fd.show(); // Capture the path entered, if any. if (fd.getDirectory() != null && fd.getFile() != null) { templatePath = fd.getDirectory() + fd.getFile(); } // If the template file is valid add it and select it. if (templatePath != null && setTemplateFile(templatePath)) { if (!templateCh.testIfInList(templatePath)) { templateCh.addItem(templatePath); } templateCh.select(templatePath); } else { templateCh.select(templateCh.getPreviousSelection()); } fd.dispose(); } else { templateCh.select(choiceStr); } } }
/** * Shows a file-open selection dialog for the given working directory. * * @param aOwner the owning window to show the dialog in; * @param aCurrentDirectory the working directory to start the dialog in, can be <code>null</code> * . * @return the selected file, or <code>null</code> if the user aborted the dialog. */ public static final File showFileOpenDialog( final Window aOwner, final String aCurrentDirectory, final javax.swing.filechooser.FileFilter... aFileFilters) { if (HostUtils.isMacOS()) { final FileDialog dialog; if (aOwner instanceof Dialog) { dialog = new FileDialog((Dialog) aOwner, "Open file", FileDialog.LOAD); } else { dialog = new FileDialog((Frame) aOwner, "Open file", FileDialog.LOAD); } dialog.setDirectory(aCurrentDirectory); if ((aFileFilters != null) && (aFileFilters.length > 0)) { dialog.setFilenameFilter(new FilenameFilterAdapter(aFileFilters)); } try { dialog.setVisible(true); final String selectedFile = dialog.getFile(); return selectedFile == null ? null : new File(dialog.getDirectory(), selectedFile); } finally { dialog.dispose(); } } else { final JFileChooser dialog = new JFileChooser(); dialog.setCurrentDirectory((aCurrentDirectory == null) ? null : new File(aCurrentDirectory)); for (javax.swing.filechooser.FileFilter filter : aFileFilters) { dialog.addChoosableFileFilter(filter); } File result = null; if (dialog.showOpenDialog(aOwner) == JFileChooser.APPROVE_OPTION) { result = dialog.getSelectedFile(); } return result; } }
protected boolean browseFile() { File currentFile = new File(fnameField.getText()); FileDialog fd = new FileDialog(this, "Save next session as...", FileDialog.SAVE); fd.setDirectory(currentFile.getParent()); fd.setVisible(true); if (fd.getFile() != null) { String newDir = fd.getDirectory(); String sep = System.getProperty("file.separator"); if (newDir.length() > 0) { if (!sep.equals(newDir.substring(newDir.length() - sep.length()))) newDir += sep; } String newFname = newDir + fd.getFile(); if (newFname.equals(fnameField.getText())) { fnameField.setText(newFname); return true; } } return false; }
public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed"); if (e.getSource() == pen) // 画笔 { System.out.println("pen"); toolFlag = 0; } if (e.getSource() == eraser) // 橡皮 { System.out.println("eraser"); toolFlag = 1; } if (e.getSource() == clear) // 清除 { System.out.println("clear"); toolFlag = 2; paintInfo.removeAllElements(); repaint(); } if (e.getSource() == drLine) // 画线 { System.out.println("drLine"); toolFlag = 3; } if (e.getSource() == drCircle) // 画圆 { System.out.println("drCircle"); toolFlag = 4; } if (e.getSource() == drRect) // 画矩形 { System.out.println("drRect"); toolFlag = 5; } if (e.getSource() == colchooser) // 调色板 { System.out.println("colchooser"); Color newColor = JColorChooser.showDialog(this, "我的调色板", c); c = newColor; } if (e.getSource() == openPic) // 打开图画 { openPicture.setVisible(true); if (openPicture.getFile() != null) { int tempflag; tempflag = toolFlag; toolFlag = 2; repaint(); try { paintInfo.removeAllElements(); File filein = new File(openPicture.getDirectory(), openPicture.getFile()); picIn = new FileInputStream(filein); VIn = new ObjectInputStream(picIn); paintInfo = (Vector) VIn.readObject(); VIn.close(); repaint(); toolFlag = tempflag; } catch (ClassNotFoundException IOe2) { repaint(); toolFlag = tempflag; System.out.println("can not read object"); } catch (IOException IOe) { repaint(); toolFlag = tempflag; System.out.println("can not read file"); } } } if (e.getSource() == savePic) // 保存图画 { savePicture.setVisible(true); try { File fileout = new File(savePicture.getDirectory(), savePicture.getFile()); picOut = new FileOutputStream(fileout); VOut = new ObjectOutputStream(picOut); VOut.writeObject(paintInfo); VOut.close(); } catch (IOException IOe) { System.out.println("can not write object"); } } }
paintboard1(String s) { super(s); addMouseMotionListener(this); addMouseListener(this); paintInfo = new Vector(); /* 各工具按钮及选择项 */ // 颜色选择 ColChoice = new Choice(); ColChoice.add("black"); ColChoice.add("red"); ColChoice.add("blue"); ColChoice.add("green"); ColChoice.addItemListener(this); // 画笔大小选择 SizeChoice = new Choice(); SizeChoice.add("1"); SizeChoice.add("3"); SizeChoice.add("5"); SizeChoice.add("7"); SizeChoice.add("9"); SizeChoice.addItemListener(this); // 橡皮大小选择 EraserChoice = new Choice(); EraserChoice.add("5"); EraserChoice.add("9"); EraserChoice.add("13"); EraserChoice.add("17"); EraserChoice.addItemListener(this); // ////////////////////////////////////////////////// toolPanel = new Panel(); clear = new Button("清除"); eraser = new Button("橡皮"); pen = new Button("画笔"); drLine = new Button("画直线"); drCircle = new Button("画圆形"); drRect = new Button("画矩形"); openPic = new Button("打开图画"); savePic = new Button("保存图画"); colchooser = new Button("显示调色板"); // 各组件事件监听 clear.addActionListener(this); eraser.addActionListener(this); pen.addActionListener(this); drLine.addActionListener(this); drCircle.addActionListener(this); drRect.addActionListener(this); openPic.addActionListener(this); savePic.addActionListener(this); colchooser.addActionListener(this); 颜色 = new Label("画笔颜色", Label.CENTER); 大小B = new Label("画笔大小", Label.CENTER); 大小E = new Label("橡皮大小", Label.CENTER); // 面板添加组件 toolPanel.add(openPic); toolPanel.add(savePic); toolPanel.add(pen); toolPanel.add(drLine); toolPanel.add(drCircle); toolPanel.add(drRect); toolPanel.add(颜色); toolPanel.add(ColChoice); toolPanel.add(大小B); toolPanel.add(SizeChoice); toolPanel.add(colchooser); toolPanel.add(eraser); toolPanel.add(大小E); toolPanel.add(EraserChoice); toolPanel.add(clear); // 工具面板到APPLET面板 add(toolPanel, BorderLayout.NORTH); setBounds(230, 50, 900, 650); setVisible(true); validate(); // dialog for save and load openPicture = new FileDialog(this, "打开图画", FileDialog.LOAD); openPicture.setVisible(false); savePicture = new FileDialog(this, "保存图画", FileDialog.SAVE); savePicture.setVisible(false); openPicture.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { openPicture.setVisible(false); } }); savePicture.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { savePicture.setVisible(false); } }); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
public void actionPerformed(ActionEvent e) { System.out.println("April working"); // Creates the "Open a File" dialog box FileDialog fd = new FileDialog(new Frame(), "Open April hillshade ASCII", FileDialog.LOAD); fd.setVisible(true); // Creates a new File object from the file that is opened File file = new File(fd.getDirectory() + fd.getFile()); if ((fd.getDirectory() == null) || (fd.getFile() == null)) { System.out.println("April hillshade file not uploaded"); return; } else { // Creates a GRIDJava object from the opened file GRIDJava2 gj = new GRIDJava2(file, true, store); // Adds the GRIDJava object to the panel panel.addGRIDJavaMethod(gj); // Creates a 2D array from the GRIDJava object double hillshade_April[][] = gj.getTwoDdoubleArray(); // Converts hillshade values (0-255) to % for (int i = 0; i < hillshade_April.length; i++) { for (int j = 0; j < hillshade_April[i].length; j++) { if ((hillshade_April[i][j] != -9999) && (hillshade_April[i][j] != 0)) { double percentage1 = (hillshade_April[i][j] / 255.0); // half the way.... (* 100) double percentage2 = percentage1 * 100.0; hillshade_April[i][j] = percentage2; } else if (hillshade_April[i][j] == 0) { hillshade_April[i][j] = 0; } else { hillshade_April[i][j] = -9999; } } } store.setHillshade_April(hillshade_April); // ****************** End of hillshade conversion ********************** // Creates a 1D array from the GRIDJava object int data1d[] = gj.getOneDintArray(); // Creates an Image object Image temp = null; // Creates a MemoryImageSource object which uses methods from GRIDJava.java and takes in the // 1D array created above MemoryImageSource mis = new MemoryImageSource( gj.getNumberOfColumns(), gj.getNumberOfRows(), data1d, 0, gj.getNumberOfColumns()); // Using a toolkit, this creates the image and assigns it to the Image object created earlier // (previously set to null) temp = panel.getToolkit().createImage(mis); // Displays the image on the panel panel.displayImage(temp); System.out.println("April hillshade uploaded"); } }
/** Construct the TV object - that is, the main GUI for the program */ public TV(JFrame f, TD mod) { super(); frm = f; theTD = mod; JButton b; // Build the GUI toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.getAccessibleContext().setAccessibleName("File Toolbar"); toolBar.addSeparator(); b = addTool(toolBar, "Cut"); b = addTool(toolBar, "Copy"); b = addTool(toolBar, "Paste"); toolBar.addSeparator(); toolBar.putClientProperty("JToolBar.isRollover", Boolean.FALSE); // The Slider numSlider = new JSlider(JSlider.HORIZONTAL, 1, 40, 1); numSlider.setPaintTicks(true); numSlider.setPaintLabels(false); numSlider.setMajorTickSpacing(10); numSlider.setMinorTickSpacing(2); numSlider.setExtent(1); numSlider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent ce) { // System.out.println("CHANGE: " + ce); setQNumber(((JSlider) (ce.getSource())).getValue()); } }); numSlider.setToolTipText("Slide to select question by number"); toolBar.add(numSlider); // The Question# textfield toolBar.add(numTF = new JTextField("01")); numTF.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String num = ((JTextField) e.getSource()).getText(); int n = Integer.parseInt(num.trim()); setQNumber(n); } }); numTF.setToolTipText("Type number to select question by number"); // The First Button b = addTool(toolBar, "First"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setQNumber(1); } }); // The Previous Button b = addTool(toolBar, "Previous"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (getQNumber() <= 1) return; setQNumber(getQNumber() - 1); } }); // The Next Button b = addTool(toolBar, "Next"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (getQNumber() >= getNumQuestions()) return; setQNumber(getQNumber() + 1); } }); // The "Last" Button b = addTool(toolBar, "Last"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setQNumber(getNumQuestions()); } }); add(BorderLayout.NORTH, toolBar); // Rest is a panel to hold the questions, one at a time. questionsPanel = new JPanel(); questionsPanel.setLayout(myCardLayout = new CardLayout()); add(BorderLayout.SOUTH, questionsPanel); fc = new FileDialog(frm); fc.setFilenameFilter( new FilenameFilter() { public boolean accept(File ff, String fname) { // System.out.println("accept("+fname+")"); // XXX TODO list of extentions, from properties. return fname.endsWith(".xam"); } }); TV.centre(fc); }
public void actionPerformed(ActionEvent e) { System.out.println("November 6pm working"); // Creates the "Open a File" dialog box FileDialog fd = new FileDialog(new Frame(), "Open November 6pm hillshade ASCII", FileDialog.LOAD); fd.setVisible(true); // Creates a new File object from the file that is opened File file = new File(fd.getDirectory() + fd.getFile()); // File file = new File("F:\\Model_Test_Files\\59_hillshade.txt"); if ((fd.getDirectory() == null) || (fd.getFile() == null)) { System.out.println("November 6pm hillshade file not uploaded"); return; } else { // Creates a GRIDJava object from the opened file GRIDJava2 gj = new GRIDJava2(file, true, store); // Adds the GRIDJava object to the panel panel.addGRIDJavaMethod(gj); // Creates a 2D array from the GRIDJava object double hillshade_November_6pm[][] = gj.getTwoDdoubleArray(); store.setHillshade_Nov_6pm(hillshade_November_6pm); // ****************** End of hillshade conversion ********************** // Creates a 1D array from the GRIDJava object int data1d[] = gj.getOneDintArray(); // Creates an Image object Image temp = null; // Creates a MemoryImageSource object which uses methods from GRIDJava.java and takes in the // 1D array created above MemoryImageSource mis = new MemoryImageSource( gj.getNumberOfColumns(), gj.getNumberOfRows(), data1d, 0, gj.getNumberOfColumns()); // Using a toolkit, this creates the image and assigns it to the Image object created earlier // (previously set to null) temp = panel.getToolkit().createImage(mis); // Displays the image on the panel panel.displayImage(temp); System.out.println("November 6pm hillshade uploaded"); } }
private void openAddressBook() { FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); fileDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"}); fileDialog.setFilterNames( new String[] { resAddressBook.getString("Book_filter_name") + " (*.adr)", resAddressBook.getString("All_filter_name") + " (*.*)" }); String name = fileDialog.open(); if (name == null) return; File file = new File(name); if (!file.exists()) { displayError( resAddressBook.getString("File") + file.getName() + " " + resAddressBook.getString("Does_not_exist")); return; } Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT); shell.setCursor(waitCursor); FileReader fileReader = null; BufferedReader bufferedReader = null; String[] data = new String[0]; try { fileReader = new FileReader(file.getAbsolutePath()); bufferedReader = new BufferedReader(fileReader); String nextLine = bufferedReader.readLine(); while (nextLine != null) { String[] newData = new String[data.length + 1]; System.arraycopy(data, 0, newData, 0, data.length); newData[data.length] = nextLine; data = newData; nextLine = bufferedReader.readLine(); } } catch (FileNotFoundException e) { displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName()); return; } catch (IOException e) { displayError(resAddressBook.getString("IO_error_read") + "\n" + file.getName()); return; } finally { shell.setCursor(null); if (fileReader != null) { try { fileReader.close(); } catch (IOException e) { displayError(resAddressBook.getString("IO_error_close") + "\n" + file.getName()); return; } } } String[][] tableInfo = new String[data.length][table.getColumnCount()]; int writeIndex = 0; for (int i = 0; i < data.length; i++) { String[] line = decodeLine(data[i]); if (line != null) tableInfo[writeIndex++] = line; } if (writeIndex != data.length) { String[][] result = new String[writeIndex][table.getColumnCount()]; System.arraycopy(tableInfo, 0, result, 0, writeIndex); tableInfo = result; } Arrays.sort(tableInfo, new RowComparator(0)); for (int i = 0; i < tableInfo.length; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(tableInfo[i]); } shell.setText(resAddressBook.getString("Title_bar") + fileDialog.getFileName()); isModified = false; this.file = file; }