/** * Saves the current chart as an image in png format. The user can select the filename, and is * asked to confirm the overwrite of an existing file. */ public void saveImage() { JFileChooser fc = new JFileChooser(); if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); if (f.exists()) { int ok = JOptionPane.showConfirmDialog( this, KstatResources.getString("SAVEAS.OVERWRITE.TEXT") + " " + f.toString(), KstatResources.getString("SAVEAS.CONFIRM.TEXT"), JOptionPane.YES_NO_OPTION); if (ok != JOptionPane.YES_OPTION) { return; } } BufferedImage bi = kbc.getChart().createBufferedImage(500, 300); try { ImageIO.write(bi, "png", f); /* * According to the API docs this should throw an IOException * on error, but this doesn't seem to be the case. As a result * it's necessary to catch exceptions more generally. Even this * doesn't work properly, but at least we manage to convey the * message to the user that the write failed, even if the * error itself isn't handled. */ } catch (Exception ioe) { JOptionPane.showMessageDialog( this, ioe.toString(), KstatResources.getString("SAVEAS.ERROR.TEXT"), JOptionPane.ERROR_MESSAGE); } } }
public static void main(String args[]) { // TODO: Use args if (false) { Parser p = new Parser(); run(p.parse(ConfigFile)); } // TODO: Use args if (true) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.showSaveDialog(null); String filepath = fileChooser.getSelectedFile().toString().replace("\\", "\\\\"); // String filepath = "X:\\#inbox"; List<Extension> text = new ArrayList<>(); text.add(new ExtensionCaseInsensitive("doc")); text.add(new ExtensionCaseInsensitive("docx")); text.add(new ExtensionCaseInsensitive("pdf")); text.add(new ExtensionCaseInsensitive("txt")); run(new Folder(filepath, text)); } }
/** Call this to browse for a custom gradle executor. */ private void browseForCustomGradleExecutor() { File startingDirectory = new File(SystemProperties.getInstance().getUserHome()); File currentFile = gradlePluginLord.getCustomGradleExecutor(); if (currentFile != null) { startingDirectory = currentFile.getAbsoluteFile(); } else { if (gradlePluginLord.getCurrentDirectory() != null) { startingDirectory = gradlePluginLord.getCurrentDirectory(); } } JFileChooser chooser = new JFileChooser(startingDirectory); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); File file = null; if (chooser.showOpenDialog(mainPanel) == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } if (file != null) { setCustomGradleExecutor(file); } else { // if they canceled, and they have no custom gradle executor specified, then we must // clear things // This will reset the UI back to 'not using a custom executor'. We can't have them check the // field and not have a value here. if (gradlePluginLord.getCustomGradleExecutor() == null) { setCustomGradleExecutor(null); } } }
private static void assertChooser() { if (fc == null) { fc = new JFileChooser(); Box ab = new Box(BoxLayout.Y_AXIS); ab.add(afap = new AudioFormatAccessoryPanel("Sample format")); ab.add(sap = new SaveAccessoryPanel(null)); fc.setAccessory(ab); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileFilter( new FileFilter() { public boolean accept(File f) { return f.isDirectory() && !f.equals(Zoeos.getZoeosLocalDir()); } public String getDescription() { return "Directories"; } }); fc.setAcceptAllFileFilterUsed(false); } try { fc.setCurrentDirectory(new File(ZPREF_lastDir.getValue())); } catch (Exception e) { } }
public void actionPerformed(ActionEvent e) { saveOld(); if (dialog.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { readInFile(dialog.getSelectedFile().getAbsolutePath()); } SaveAs.setEnabled(true); }
/** * The ActionListener implementation * * @param event the event. */ public void actionPerformed(ActionEvent event) { String searchText = textField.getText().trim(); if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) { textPane.setText("Blank search text is not allowed for large IdTables."); } else { File outputFile = null; if (saveAs.isSelected()) { outputFile = chooser.getSelectedFile(); if (outputFile != null) { String name = outputFile.getName(); int k = name.lastIndexOf("."); if (k != -1) name = name.substring(0, k); name += ".txt"; File parent = outputFile.getAbsoluteFile().getParentFile(); outputFile = new File(parent, name); chooser.setSelectedFile(outputFile); } if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0); outputFile = chooser.getSelectedFile(); } textPane.setText(""); Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile); searcher.start(); } }
private boolean checkForSave() { // build warning message String message; if (file == null) { message = "File has been modified. Save changes?"; } else { message = "File \"" + file.getName() + "\" has been modified. Save changes?"; } // show confirm dialog int r = JOptionPane.showConfirmDialog( this, new JLabel(message), "Warning!", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (r == JOptionPane.YES_OPTION) { // Save File if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { // write the file physWriteTextFile(fileChooser.getSelectedFile(), textView.getText()); } else { // user cancelled save after all return false; } } return r != JOptionPane.CANCEL_OPTION; }
public void initGame() { String cfgname = null; if (isApplet()) { cfgname = getParameter("configfile"); } else { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(System.getProperty("user.dir"))); chooser.setDialogTitle("Choose a config file"); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { cfgname = chooser.getSelectedFile().getAbsolutePath(); } else { System.exit(0); } // XXX read this as resource! // cfgname = "mygeneratedgame.appconfig"; } gamecfg = new AppConfig("Game parameters", this, cfgname); gamecfg.loadFromFile(); gamecfg.defineFields("gp_", "", "", ""); gamecfg.saveToObject(); initMotionPars(); // unpause and copy settingswhen config window is closed gamecfg.setListener( new ActionListener() { public void actionPerformed(ActionEvent e) { start(); requestGameFocus(); initMotionPars(); } }); defineMedia("simplegeneratedgame.tbl"); setFrameRate(35, 1); }
private void loadTopicsFromFile() throws IOException { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("ExtempFiller2"); chooser.setFileFilter( new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".txt"); } @Override public String getDescription() { return "Text Files"; } }); int response = chooser.showOpenDialog(this); if (response == JFileChooser.APPROVE_OPTION) { // get everything currently researched java.util.List<String> researched = managerPanel.getTopics(); // load everything from file File file = chooser.getSelectedFile(); Scanner readScanner = new Scanner(file); while (readScanner.hasNext()) { String topic = readScanner.nextLine(); if (!researched.contains(topic)) { Topic t = new Topic(topic); managerPanel.addTopic(t); inQueue.add(new InMessage(InMessage.Type.RESEARCH, t)); } } } }
/** * Method performed when button clicked. * * @param event event that triggers action, here clicking of the button. */ public void actionPerformed(ActionEvent event) { if (choiceBox.getSelectedItem().equals(CUSTOM)) { JFileChooser chooser = new JFileChooser(System.getProperty("user.home")); int returnVal = chooser.showOpenDialog(settingsPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { specifiedOntology = CUSTOM; openFile = chooser.getSelectedFile(); choiceBox.setEditable(true); choiceBox.setSelectedItem(openFile.toString()); choiceBox.setEditable(false); def = false; if (((String) choiceBox.getSelectedItem()).endsWith(".obo")) { settingsPanel.getNamespacePanel().choiceBox.setEnabled(true); } else { settingsPanel.getNamespacePanel().choiceBox.setEnabled(false); } } if (returnVal == JFileChooser.CANCEL_OPTION) { choiceBox.setSelectedItem(NONE); specifiedOntology = NONE; def = true; settingsPanel.getNamespacePanel().choiceBox.setEnabled(false); } } else if (choiceBox.getSelectedItem().equals(NONE)) { specifiedOntology = NONE; def = true; settingsPanel.getNamespacePanel().choiceBox.setEnabled(false); } else { specifiedOntology = (String) choiceBox.getSelectedItem(); def = true; settingsPanel.getNamespacePanel().choiceBox.setEnabled(false); } }
private void cmdLoadActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_cmdLoadActionPerformed // Confirm save before open another file if (this.isContentChanged()) { int ans = JOptionPane.showConfirmDialog( this, "The contents of " + CurrentFileName + " has been modified. Would you like to save the changes first?", "Confirm saving ...", JOptionPane.YES_NO_OPTION); if (ans == JOptionPane.YES_OPTION) { saveFileContent(this.CurrentFileName, rsTextArea.getText()); } } // Select a file to open if (FC.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { CurrentFileName = FC.getSelectedFile().getPath(); String name = FC.getSelectedFile().getName(); // Open idf/imf file rsTextArea.setText(getFileContent(CurrentFileName)); setContentChanged(false); this.Title = name; notifyContentChange(false); } } // GEN-LAST:event_cmdLoadActionPerformed
void onOpenFileClicked() { if (!maybeSave()) { return; } try { JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter1 = new FileNameExtensionFilter(strings.getString("filetype." + EXTENSION), EXTENSION); fc.setFileFilter(filter1); int rv = fc.showOpenDialog(this); if (rv == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); Tournament t = new Tournament(); t.loadFile(file); setTournament(file, t); } } catch (Exception e) { JOptionPane.showMessageDialog( this, e, strings.getString("main.error_caption"), JOptionPane.ERROR_MESSAGE); } }
private boolean setServiceParameter( GlobalEnvironment.PropertyType type, JLabel label, JTextField textField) { String name = String.valueOf(type).toLowerCase(); String startDirectory = StringUtil.isEmptyOrSpaces(textField.getText()) ? System.getProperty("user.home") : textField.getText(); JFileChooser fileChooser = new JFileChooser(startDirectory); fileChooser.setDialogTitle("Select Emacs " + name + " directory"); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { String dir = fileChooser.getSelectedFile().getAbsolutePath(); textField.setText(dir); if (GlobalEnvironment.testProperty(type, dir)) { infoLabel.setText("Emacs " + name + " directory successfully set"); label.setForeground(Color.black); return true; } else { onWrongProperty(label, type); return false; } } else { if (GlobalEnvironment.isEmacsPropertyOk(type)) return true; onWrongProperty(label, type); return false; } }
public void actionPerformed(ActionEvent ae) { String cmd = ae.getActionCommand(); if (JOkCancelPanel.OK.equals(cmd)) { // update evaluator evaluator.name = tfName.getText(); evaluator.type = (byte) cbType.getSelectedIndex(); evaluator.ignoreDiagonals = cbDiagonals.isSelected(); evaluator.investments = (byte) cbInvestment.getSelectedIndex(); evaluator.orgFile = orgFile; setVisible(false); } else if (JOkCancelPanel.CANCEL.equals(cmd)) { // don't update evaluator setVisible(false); } else if (CMD_CHOOSE_FILE.equals(cmd)) { // get a file dialog JFrame f = new JFrame(); JFileChooser jfc = Application.getFileChooser(); int res = jfc.showOpenDialog(f); Application.setWorkingDirectory(jfc.getCurrentDirectory()); if (res == JFileChooser.CANCEL_OPTION) { return; } orgFile = jfc.getSelectedFile(); lOrgFileName.setText("File: " + orgFile.getName()); } }
private void setupFileChooser() { fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Select directory to output ISArchive to..."); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); fileChooser.setApproveButtonText("Output to selected directory"); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); }
/** Process the action event from the open button */ public void actionPerformed(ActionEvent evt) { if (openDialog == null) openDialog = new JFileChooser(); int ret_val = openDialog.showOpenDialog(this); if (ret_val != JFileChooser.APPROVE_OPTION) return; File file = openDialog.getSelectedFile(); try { System.out.println("Loading external file: " + file); FileInputStream is = new FileInputStream(file); BufferedInputStream stream = new BufferedInputStream(is); BufferedImage img = ImageIO.read(stream); if (img == null) { System.out.println("Image load barfed"); return; } srcIcon.setImage(img); srcLabel.setIcon(srcIcon); BufferedImage map_img = textureUtils.createNormalMap(img, null); mapIcon.setImage(map_img); mapLabel.setIcon(mapIcon); } catch (IOException ioe) { System.out.println("crashed " + ioe.getMessage()); ioe.printStackTrace(); } }
private void changeDirectory(File dir) { JFileChooser fc = getFileChooser(); // Traverse shortcuts on Windows if (dir != null && FilePane.usesShellFolder(fc)) { try { ShellFolder shellFolder = ShellFolder.getShellFolder(dir); if (shellFolder.isLink()) { File linkedTo = shellFolder.getLinkLocation(); // If linkedTo is null we try to use dir if (linkedTo != null) { if (fc.isTraversable(linkedTo)) { dir = linkedTo; } else { return; } } else { dir = shellFolder; } } } catch (FileNotFoundException ex) { return; } } fc.setCurrentDirectory(dir); if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES && fc.getFileSystemView().isFileSystem(dir)) { setFileName(dir.getAbsolutePath()); } }
@Override public void actionPerformed(ActionEvent e) { JFileChooser f = new JFileChooser(); f.setFileFilter(new MyFileFilter()); // 設定檔案選擇器 int choose = f.showOpenDialog(getContentPane()); // 顯示檔案選取 if (choose == JFileChooser.OPEN_DIALOG) { // 有開啟檔案的話,開始讀檔 BufferedReader br = null; try { File file = f.getSelectedFile(); br = new BufferedReader(new FileReader(file)); TextDocument ta = new TextDocument(file.getName(), file); ta.addKeyListener(new SystemTrackSave()); ta.read(br, null); td.add(ta); td.setTitleAt(docCount++, file.getName()); } catch (Exception exc) { exc.printStackTrace(); } finally { try { br.close(); } catch (Exception ecx) { ecx.printStackTrace(); } } } }
protected void uninstallDefaults(JFileChooser fc) { uninstallIcons(fc); uninstallStrings(fc); if (fc.getTransferHandler() instanceof UIResource) { fc.setTransferHandler(null); } }
@Override public void actionPerformed(ActionEvent e) { if (td.getTabCount() > 0) { JFileChooser f = new JFileChooser(); f.setFileFilter(new MyFileFilter()); int choose = f.showSaveDialog(getContentPane()); if (choose == JFileChooser.APPROVE_OPTION) { BufferedWriter brw = null; try { File file = f.getSelectedFile(); brw = new BufferedWriter(new FileWriter(file)); int i = td.getSelectedIndex(); TextDocument ta = (TextDocument) td.getComponentAt(i); ta.write(brw); ta.fileName = file.getName(); // 將檔案名稱更新為存檔的名稱 td.setTitleAt(td.getSelectedIndex(), ta.fileName); ta.file = file; ta.save = true; // 設定已儲存 System.out.println("Save as pass!"); td.setTitleAt(i, ta.fileName); // 更新標題名稱 } catch (Exception exc) { exc.printStackTrace(); } finally { try { brw.close(); } catch (Exception ecx) { ecx.printStackTrace(); } } } } else { JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!"); } }
@Override public void actionPerformed(ActionEvent e) { Frame frame = getFrame(); JFileChooser chooser = new JFileChooser(); int ret = chooser.showOpenDialog(frame); if (ret != JFileChooser.APPROVE_OPTION) { return; } File f = chooser.getSelectedFile(); if (f.isFile() && f.canRead()) { Document oldDoc = getEditor().getDocument(); if (oldDoc != null) { oldDoc.removeUndoableEditListener(undoHandler); } if (elementTreePanel != null) { elementTreePanel.setEditor(null); } getEditor().setDocument(new PlainDocument()); frame.setTitle(f.getName()); Thread loader = new FileLoader(f, editor.getDocument()); loader.start(); } else { JOptionPane.showMessageDialog( getFrame(), "Could not open file: " + f, "Error opening file", JOptionPane.ERROR_MESSAGE); } }
private void onTransferFileClicked() { if (transferingFile) return; int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); showInfoMessage("Se selecciono el archivo " + file.getName()); try { lineCount = getFileLineCount(file); fileReader = new FileReader(file); linesTransfered = 0; headerSent = false; lineCountSent = false; transferingFile = true; transmitMessage("$save"); } catch (IOException e) { e.printStackTrace(); } } else { showInfoMessage("Se cancelo la transferencia de archivo"); } }
public void readXMLData() { energy = new double[0]; magnetization = new double[0]; numberOfPoints = 0; String filename = "ising_data.xml"; JFileChooser chooser = OSPFrame.getChooser(); int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { filename = chooser.getSelectedFile().getAbsolutePath(); } else { return; } XMLControlElement xmlControl = new XMLControlElement(filename); if (xmlControl.failedToRead()) { control.println("failed to read: " + filename); } else { // gets the datasets in the xml file Iterator it = xmlControl.getObjects(Dataset.class, false).iterator(); while (it.hasNext()) { Dataset dataset = (Dataset) it.next(); if (dataset.getName().equals("magnetization")) { magnetization = dataset.getYPoints(); } if (dataset.getName().equals("energy")) { energy = dataset.getYPoints(); } } numberOfPoints = magnetization.length; control.println("Reading: " + filename); control.println("Number of points = " + numberOfPoints); } calculate(); plotFrame.repaint(); }
public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) fc.setSelectedFile(new File(name)); else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop) && !fc.getSelectedFile().isDirectory()) name = fc.getSelectedFile().getName(); }
public void actionPerformed(ActionEvent e) { // Handle open button action. if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(FileChooserDemo.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // This is where a real application would open the file. log.append("Opening: " + file.getName() + "." + newline); } else { log.append("Open command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); // Handle save button action. } else if (e.getSource() == saveButton) { int returnVal = fc.showSaveDialog(FileChooserDemo.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // This is where a real application would save the file. log.append("Saving: " + file.getName() + "." + newline); } else { log.append("Save command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); } }
private void selFolder() { // selects a single folder, then makes table uneditable other than launch, sel res folder and // cancel, gui table different, just shows folder final JFileChooser fc = new JFileChooser(currentPath); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fc.showOpenDialog(FrontEnd.this); dir = fc.getSelectedFile(); switch (result) { case JFileChooser.APPROVE_OPTION: dirImp = dir.toString(); dtm.getDataVector().removeAllElements(); dtm.fireTableDataChanged(); curRow = 0; addRow(); dtm.setValueAt( "You have chosen the folder '" + dirImp.substring(67) + "' and all of its subfolders.", 0, 0); dtm.setValueAt(dirImp.substring(67), 0, 1); if (table.getRowCount() > 0) { openF.setEnabled(false); openFo.setEnabled(false); selFo.setEnabled(false); canF.setEnabled(true); } selFoFl = 1; case JFileChooser.CANCEL_OPTION: break; } }
// Add a test case to testBox and tests array. private void addTest() { // Set up the frame for the file chooser. final JFrame appframe = new JFrame("Select Application"); appframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Container contentPane = appframe.getContentPane(); JFileChooser fileChooser = new JFileChooser("."); // Only let you select directories and add chooser to pane. fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); contentPane.add(fileChooser, BorderLayout.CENTER); // Make a new action listener for the file chooser. ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { // Get the information to check if the file chosen is valid. JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource(); String command = actionEvent.getActionCommand(); // If the user cancels selecting a program. if (command.equals(JFileChooser.CANCEL_SELECTION)) { appframe.setVisible(false); appframe.dispose(); return; } // If the file chosen is valid. if (command.equals(JFileChooser.APPROVE_SELECTION)) { // Retrieve the selected file and ask for the main class name. File f = theFileChooser.getSelectedFile(); // Obtain the file URL. String fileURL = null; fileURL = f.getAbsolutePath(); // Add a checkbox to the testing check pane. JCheckBox newTest = new JCheckBox(fileURL, true); testBox.setEditable(true); testBox.add(newTest); testBox.repaint(); testBox.setEditable(false); // Add the test to the list of tests. tests.add(newTest); // Make the file chooser disappear. appframe.setVisible(false); appframe.dispose(); } } }; // Add the action listener created above to file chooser, display it. fileChooser.addActionListener(actionListener); appframe.pack(); appframe.setVisible(true); }
public void doIt(Project project) { JFileChooser fileChooser = project.getOpenChooser(); if (fileChooser.showOpenDialog(project.getComponent()) == JFileChooser.APPROVE_OPTION) { openFile(project, fileChooser); } else { project.setEnabled(true); } }
/** Method to load the excel file into memory */ private void loadExcelFileButtonActionPerformed() { int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); excelTextField.setText(file.getAbsolutePath()); } }
// called when the load script button is pressed. private void scriptPressed() { int returnVal = fileChooser.showDialog(this, "Load Script"); if (returnVal == JFileChooser.APPROVE_OPTION) { notifyControllerListeners( ControllerEvent.SCRIPT_CHANGE, fileChooser.getSelectedFile().getAbsoluteFile()); scriptComponent.setContents(fileChooser.getSelectedFile().getAbsolutePath()); } }