public void jButton1_actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(parent); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); jTextField1.setText(file.toString()); } }
public static void openPlaylist(File sanou) throws Exception { if (logger.isDebugEnabled()) logger.debug("Open playlist."); if (Lecteur.CURRENTPLAYLIST.isEmpty()) { savePlaylist("Current Playlist isn't save ; to save now Enter the Playlist Name"); new File(Lecteur.CURRENTPLAYLIST.NAME + ".dec").delete(); copy(sanou, new File(Lecteur.CURRENTPLAYLIST.NAME)); } else { copy(sanou, new File(Lecteur.CURRENTPLAYLIST.NAME)); } currentNAME = sanou.toString(); }
/** * Use a JFileChooser in Save mode to select files to open. Use a filter for FileFilter subclass * to select for "*.java" files. If a file is selected, then this file will be used as final * output */ boolean saveFile() { File file = null; JFileChooser fc = new JFileChooser(); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(fJavaFilter); // Set to a default name for save. fc.setSelectedFile(fFile); // Open chooser dialog int result = fc.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return true; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); String textFile = fFile.toString(); if (fileNo.equalsIgnoreCase("SAVE")) { UpLoadFile.outputfile.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVE2")) { UpLoadMAGEMLFile.outputfile1.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVE3")) { UpLoadMAGEMLFile.outputfile2.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVEJPAG")) { JPEGFileName = textFile; // System.out.println ("JPG filename OpenFileDir= " +JPEGFileName); File fFile = new File(JPEGFileName); if (fFile.exists()) { int response = JOptionPane.showConfirmDialog( null, "Overwrite existing file " + JPEGFileName + " ??", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) { /* go back to reload the file*/ return false; } } SetUpPlotWindow.saveComponentAsJPEG(SetUpPlotWindow.content, JPEGFileName); } return true; } else { return false; } } // saveFile
/* * This function just finds and loads the file */ private boolean loadFile() { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Load File"); // Choose only files, not directories fc.setFileSelectionMode(JFileChooser.FILES_ONLY); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(fJavaFilter); // Now open chooser int result = fc.showOpenDialog(this); if (result == JFileChooser.CANCEL_OPTION) { // return true; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); String textFile = fFile.toString(); if (fileNo.equalsIgnoreCase("LOAD1")) { UpLoadFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD2")) { UpLoadFile.filePath2.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD3")) { VisualizationInput.originalFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD4")) { VisualizationInput.DWDVecFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD5")) { VisualizationInput.DWDOutputFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD6")) { UpLoadMAGEMLFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD7")) { UpLoadMAGEMLFile.filePath2.setText(textFile); } // Get the absolute path for the file being opened filePath = fFile.getAbsolutePath(); if (filePath == null) { // fTextField.setText (filePath); return false; } } else { return false; } return true; } /*End of loadFile*/
public static void saveAsPlaylist(String message) throws Exception { if (logger.isDebugEnabled()) logger.debug("Save as playlist."); String s = GUI.messageDialog2(message); if (s != null) { String s2 = Lecteur.CURRENTPLAYLIST.NAME.substring(0, Lecteur.CURRENTPLAYLIST.NAME.length() - 19); String sa = s2 + s + ".pl"; File f = new File(sa); copy(new File(Lecteur.CURRENTPLAYLIST.NAME), f); currentNAME = f.toString(); GUI.getInstance().createOpenItem(sa); GUI.getInstance().createdeleteItem(sa); } }
void addChildren(DefaultMutableTreeNode parent, File parentDirFile) { for (File file : parentDirFile.listFiles()) { String[] namesplitStrings = file.toString().split("\\\\"); String filename = namesplitStrings[namesplitStrings.length - 1]; if (file.isDirectory()) { DefaultMutableTreeNode child = new DefaultMutableTreeNode(filename); addChildren(child, file); parent.add(child); } else if (file.isFile()) { parent.add(new DefaultMutableTreeNode(filename)); } } }
public SelectableTree() { super("JTree Selections"); WindowUtilities.setNativeLookAndFeel(); addWindowListener(new ExitListener()); Container content = getContentPane(); String[] namesplitStrings = mainDir.toString().split("\\\\"); String filename = namesplitStrings[namesplitStrings.length - 1]; DefaultMutableTreeNode root = new DefaultMutableTreeNode(filename); addChildren(root, mainDir); tree = new JTree(root); tree.addTreeSelectionListener(this); content.add(new JScrollPane(tree), BorderLayout.CENTER); currentSelectionField = new JTextField("Current Selection: NONE"); content.add(currentSelectionField, BorderLayout.SOUTH); setSize(250, 275); setVisible(true); }