/** * Actions-handling method. * * @param e The event. */ public void actionPerformed(ActionEvent e) { // Prepares the file chooser JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(idata.getInstallPath())); fc.setMultiSelectionEnabled(false); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); // fc.setCurrentDirectory(new File(".")); // Shows it try { if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { // We handle the xml data writing File file = fc.getSelectedFile(); FileOutputStream out = new FileOutputStream(file); BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120); parent.writeXMLTree(idata.xmlData, outBuff); outBuff.flush(); outBuff.close(); autoButton.setEnabled(false); } } catch (Exception err) { err.printStackTrace(); JOptionPane.showMessageDialog( this, err.toString(), parent.langpack.getString("installer.error"), JOptionPane.ERROR_MESSAGE); } }
private void openFile() { // opens a single file chooser (can select multiple), does not traverse folders. this.copyList = new ArrayList(); final JFileChooser fc = new JFileChooser(currentPath); fc.setMultiSelectionEnabled(true); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filterhtml = new FileNameExtensionFilter("HTML File (.html)", "html"); fc.addChoosableFileFilter(filterhtml); fc.setFileFilter(filterhtml); int result = fc.showOpenDialog(FrontEnd.this); dir = fc.getCurrentDirectory(); dirImp = dir.toString(); switch (result) { case JFileChooser.APPROVE_OPTION: for (File file1 : fc.getSelectedFiles()) { fileImp = file1.toString(); boolean exists = false; for (int i = 0; i < table.getRowCount(); i++) { dir = fc.getCurrentDirectory(); dirImp = dir.toString(); String copyC = dtm.getValueAt(i, 0).toString(); if (duplC.isSelected()) { if (fileImp.endsWith(copyC)) { exists = true; break; } } } if (!exists) { addRow(); dtm.setValueAt(fileImp.substring(67), curRow, 0); dtm.setValueAt(dirImp.substring(67), curRow, 1); curRow++; if (headC == 1) { if (fileImp.substring(67).endsWith(dirImp.substring(67) + ".html")) { curRow--; dtm.removeRow(curRow); } } } } case JFileChooser.CANCEL_OPTION: break; } }
void doEditFilename() { // create the file open dialog final JFileChooser jf = new JFileChooser(); // cancel multiple selections jf.setMultiSelectionEnabled(false); // set the start directory if (_lastDirectory != null) { jf.setCurrentDirectory(new File(_lastDirectory)); } else { String val = ""; // see if we have an old directory to retrieve val = Application.getThisProperty("RANGE_Directory"); // give it a default value, if we have to if (val == null) val = ""; // try to get the import directory jf.setCurrentDirectory(new File(val)); } // open the dialog final int state = jf.showOpenDialog(null); // do we have a valid file? if (state == JFileChooser.APPROVE_OPTION) { // retrieve the filename final File theFile = jf.getSelectedFile(); _theFilename = theFile.getPath(); // retrieve the directory name _lastDirectory = theFile.getParent(); // trigger a refresh refreshForm(); } else if (state == JFileChooser.CANCEL_OPTION) { _theFilename = null; } }
private ObjectOutputStream getObjectOutputStream() { File f = new File("."); String loadDirectory = f.getAbsolutePath(); JFileChooser chooser = new JFileChooser(loadDirectory); chooser.setDialogTitle("Save Generation File As..."); chooser.setMultiSelectionEnabled(false); int result = chooser.showSaveDialog(this); File selectedFile = chooser.getSelectedFile(); if (result == JFileChooser.APPROVE_OPTION) { try { FileOutputStream fileStream = new FileOutputStream(selectedFile.getPath()); ObjectOutputStream objectStream = new ObjectOutputStream(fileStream); return objectStream; } catch (IOException e) { System.err.println(e); } } return null; }
public void secureImport() { JFileChooser imp = new JFileChooser(); imp.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); imp.setMultiSelectionEnabled(true); int ret = imp.showOpenDialog(frm); if (ret != JFileChooser.APPROVE_OPTION) { return; } File[] fis = imp.getSelectedFiles(); ArrayList<String> impJobs = new ArrayList<String>(); boolean dirs = false; for (File fi : fis) { if (fi.isDirectory()) { dirs = true; File lib = new File(fi, LIBRARY_NAME); if (lib.exists()) { try { Scanner sca = new Scanner(lib); while (sca.hasNextLine()) { String nm = sca.nextLine(); String date = sca.nextLine(); String tags = sca.nextLine(); File addr = new File(fi, nm); if (addr.exists() && !addr.isDirectory()) impJobs.add(impJob(addr, date, tags)); } sca.close(); } catch (IOException exc) { // add nothing? } } else { for (File cont : fi.listFiles()) if (!cont.isDirectory()) impJobs.add(impJob(cont, null, null)); } } else { impJobs.add(impJob(fi, null, null)); } } if (impJobs.size() > 1 || dirs) { // dont bother user if selected single file String shw = "Importing:"; if (impJobs.size() > 30) shw = null; int pcount = 0; for (String jb : impJobs) { String[] prts = jb.split(",", 4); // import jobs have 4 parts, import, name, date, tags if (shw != null) shw = shw + "\n - " + new File(prts[1]).getName(); if (!prts[3].equalsIgnoreCase(Storage.NEW_TAG)) { pcount++; if (shw != null) shw = shw + " []"; } } if (shw == null) shw = "importing "; else shw = shw + "\n"; shw = shw + impJobs.size() + "(" + pcount + ") files"; if (JOptionPane.showConfirmDialog(frm, shw, "Confirm Import", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) return; } synchronized (jobs) { for (String j : impJobs) { if (priorityExport) jobs.addLast(j); else jobs.addFirst(j); } } updateStatus(); }
/** Called for button presses and checkbox toggles. */ public void actionPerformed(ActionEvent e) { Object src = e.getSource(); // the source of the event is the add files button // so we need to let the user add some files! if (src == addFiles) { // create an appropriate file chooser JFileChooser myTempFileChooser = new JFileChooser((new File("")).getAbsolutePath()); myTempFileChooser.setMultiSelectionEnabled(true); myTempFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG); myTempFileChooser.setFileHidingEnabled(true); // open the file chooser and get the user's selctions int returnCode = myTempFileChooser.showOpenDialog(this); // use the return info to add files if the // user selected any in the file chooser if (returnCode == JFileChooser.APPROVE_OPTION) { // grab the files the user selected File[] selectedFiles = myTempFileChooser.getSelectedFiles(); // pull the files into the list changeFilesInList.importFileData(list, selectedFiles); } } // the source of the event was the process button else if (src == process) { if (((DefaultListModel) list.getModel()).size() == 0) return; setComponentsEnabled(false); final ThumbMaker tm = this; Thread t = new Thread( new Runnable() { public void run() { tm.process(); setComponentsEnabled(true); } }); t.start(); // because we can't do it on quit, we are going to save // all the preference values when the user processes a set // of images savePreferences(); } // the source of the event was the remove button else if (src == remove) { DefaultListModel model = (DefaultListModel) list.getModel(); while (true) { int ndx = list.getSelectedIndex(); if (ndx < 0) break; model.removeElementAt(ndx); } } // the source of the event was the preserve aspect check box else if (src == aspect) { boolean b = aspect.isSelected(); colorLabel.setEnabled(b); colorBox.setEnabled(b); redLabel.setEnabled(b); red.setEnabled(b); redValue.setEnabled(b); greenLabel.setEnabled(b); green.setEnabled(b); greenValue.setEnabled(b); blueLabel.setEnabled(b); blue.setEnabled(b); blueValue.setEnabled(b); } // the source of the event is the "..." button, // we need to let the user select a destination file else if (src == dotDotDot) { // create an appropriate file chooser JFileChooser myTempFileChooser = new JFileChooser(new File(output.getText()).getAbsolutePath()); myTempFileChooser.setMultiSelectionEnabled(false); myTempFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); myTempFileChooser.setDialogType(JFileChooser.OPEN_DIALOG); myTempFileChooser.setFileHidingEnabled(true); // open the file chooser and get the user's selctions int returnCode = myTempFileChooser.showOpenDialog(this); // use the return info to set the directory if the // user selected one in the file chooser if (returnCode == JFileChooser.APPROVE_OPTION) { // grab the file the user selected File selectedFile = myTempFileChooser.getSelectedFile(); // stuff the file path into the text field output.setText(selectedFile.getAbsolutePath()); } } }