List of usage examples for javax.swing JFileChooser JFileChooser
public JFileChooser(FileSystemView fsv)
JFileChooser
using the given FileSystemView
. From source file:abfab3d.param.editor.URIEditor.java
public URIEditor(Parameter param) { super(param); m_textField = new TextField(EDITOR_SIZE); Object val = m_param.getValue(); String sval = ""; if (val != null) { sval = val.toString(); }/* w w w .j av a2 s .co m*/ m_textField.setText(sval); m_textField.addActionListener(this); m_open = new JButton("Open"); m_open.setToolTipText("Open File"); panel = new JPanel(new FlowLayout()); panel.add(m_open); panel.add(m_textField); String user_dir = System.getProperty("user.dir"); Preferences prefs = Preferences.userNodeForPackage(URIEditor.class); String last_dir = prefs.get(LASTDIR_PROPERTY, null); String dir; if (last_dir != null) dir = last_dir; else dir = user_dir; fc = new JFileChooser(dir); m_open.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int returnVal = fc.showDialog(parent, "Open File"); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String dir = file.getPath(); int idx = dir.lastIndexOf(File.separator); if (idx > 0) { dir = dir.substring(0, idx); Preferences prefs = Preferences.userNodeForPackage(URIEditor.class); prefs.put(LASTDIR_PROPERTY, dir); } m_param.setValue(file.getAbsolutePath()); informParamChangedListeners(); } } }); }
From source file:org.pmedv.jake.commands.AddFilesCommand.java
@Override public void execute() { final ApplicationContext ctx = AppContext.getApplicationContext(); final ApplicationWindow win = (ApplicationWindow) ctx.getBean(BeanDirectory.WINDOW_APPLICATION); /**/*from w w w. ja v a 2 s .c o m*/ * Get last selected folder to simplify file browsing */ if (AppContext.getLastSelectedFolder() == null) AppContext.setLastSelectedFolder(System.getProperty("user.home")); JFileChooser fc = new JFileChooser(AppContext.getLastSelectedFolder()); fc.setDialogTitle("Add files"); fc.setMultiSelectionEnabled(true); fc.setFileFilter(new MP3Filter()); int result = fc.showOpenDialog(win); if (result == JFileChooser.CANCEL_OPTION) return; File[] files = fc.getSelectedFiles(); PlayerView view = JakeUtil.getCurrentActivePlayer(); if (view == null) { ArrayList<File> fileList = new ArrayList<File>(); for (int i = 0; i < files.length; i++) fileList.add(files[i]); final PlayerController controller = new PlayerController(fileList); JakeUtil.updateRecentFiles(fc.getSelectedFile().getAbsolutePath()); AppContext.setLastSelectedFolder(fc.getSelectedFiles()[0].getParentFile().getAbsolutePath()); View v = new View(fc.getSelectedFile().getAbsolutePath(), null, controller.getPlayerView()); v.addListener(new DockingWindowAdapter() { @Override public void windowClosing(DockingWindow arg0) throws OperationAbortedException { controller.getPlayer().close(); controller.getPlayFileCommand().setPlaying(false); } }); openEditor(v); } else { if (files.length >= 1) { AppContext.setLastSelectedFolder(fc.getSelectedFiles()[0].getParentFile().getAbsolutePath()); JakeUtil.updateRecentFiles(fc.getSelectedFiles()[0].getParentFile().getAbsolutePath()); FileTableModel model = (FileTableModel) view.getFileTable().getModel(); for (int i = 0; i < files.length; i++) { model.addObject(files[i]); } } } }
From source file:ja.lingo.application.gui.main.export.ExportGui.java
public ExportGui(IEngine engine, Model model, JFrame parentFrame) { this.engine = engine; this.parentFrame = parentFrame; chooser = new JFileChooser("."); model.addApplicationModelListener(new ModelAdapter() { public void export(IArticle article) { saveAs(article);//from www .j a v a2 s . com } public void export(IArticleList articleList) { showAll(articleList); } }); }
From source file:com.ibm.watson.WatsonVRTraining.util.images.PhotoCaptureFrame.java
PhotoCaptureFrame() { jp = new JPanel(); jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(jp); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); scrollPane.setPreferredSize(new Dimension(dim.width / 2 - 40, dim.height - 117)); JButton btn = new JButton("Upload Image"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(System.getenv("user.home")); fc.setFileFilter(new JPEGImageFileFilter()); int res = fc.showOpenDialog(null); // We have an image! try { if (res == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //SharedResources.sharedCache.getCapturedImageList().add(file); File tmpf_name = File.createTempFile("tmp", "." + FilenameUtils.getExtension(file.getName())); System.out.println("cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); new CommandsUtils().executeCommand("bash", "-c", "cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); }//from w ww. j a va 2s . co m } catch (Exception iOException) { } } }); ImageRemainingProcessingLabel = new JLabel("REMAINIG IMAGES:0"); ImageRemainingProcessingLabel.setHorizontalAlignment(SwingConstants.LEFT); ImageRemainingProcessingLabel.setFont(new Font("Arial", Font.BOLD, 13)); ImagebeingProcessedLabel = new JLabel(" PROCESSING IMAGES:0"); ImagebeingProcessedLabel.setHorizontalAlignment(SwingConstants.LEFT); ImagebeingProcessedLabel.setFont(new Font("Arial", Font.BOLD, 13)); appIDLabel = new JLabel("APP-ID:" + AppConstants.unique_app_id); appIDLabel.setHorizontalAlignment(SwingConstants.LEFT); appIDLabel.setFont(new Font("Arial", Font.BOLD, 13)); headerPanel = new JPanel(new FlowLayout()); headerPanel.add(ImageRemainingProcessingLabel); headerPanel.add(ImagebeingProcessedLabel); headerPanel.add(btn); headerPanel.add(appIDLabel); headerPanel.setSize(new Dimension(getWidth(), 10)); JPanel contentPane = new JPanel(); contentPane.add(headerPanel); contentPane.add(scrollPane); f = new JFrame("IBM Watson Visual Prediction Window"); f.setContentPane(contentPane); f.setSize(dim.width / 2 - 30, dim.height - 40); f.setLocation(dim.width / 2, 0); f.setResizable(false); f.setPreferredSize(new Dimension(dim.width / 2 - 30, dim.height - 60)); f.setVisible(true); }
From source file:TextFileHandler.java
public File _saveAs() { File result = null;//from www . jav a 2 s. co m if (chooser == null) chooser = new JFileChooser(new File(".")); int retVal = chooser.showSaveDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); } return result; }
From source file:com.willwinder.universalgcodesender.MainWindow.java
/** * @param args the command line arguments *//*w w w . ja v a2s . c o m*/ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> // Fix look and feel to use CMD+C/X/V/A instead of CTRL if (SystemUtils.IS_OS_MAC) { Collection<InputMap> ims = new ArrayList<>(); ims.add((InputMap) UIManager.get("TextField.focusInputMap")); ims.add((InputMap) UIManager.get("TextArea.focusInputMap")); ims.add((InputMap) UIManager.get("EditorPane.focusInputMap")); ims.add((InputMap) UIManager.get("FormattedTextField.focusInputMap")); ims.add((InputMap) UIManager.get("PasswordField.focusInputMap")); ims.add((InputMap) UIManager.get("TextPane.focusInputMap")); int c = KeyEvent.VK_C; int v = KeyEvent.VK_V; int x = KeyEvent.VK_X; int a = KeyEvent.VK_A; int meta = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); for (InputMap im : ims) { im.put(KeyStroke.getKeyStroke(c, meta), DefaultEditorKit.copyAction); im.put(KeyStroke.getKeyStroke(v, meta), DefaultEditorKit.pasteAction); im.put(KeyStroke.getKeyStroke(x, meta), DefaultEditorKit.cutAction); im.put(KeyStroke.getKeyStroke(a, meta), DefaultEditorKit.selectAllAction); } } /* Create the form */ GUIBackend backend = new GUIBackend(); final MainWindow mw = new MainWindow(backend); /* Apply the settings to the MainWindow bofore showing it */ mw.arrowMovementEnabled.setSelected(mw.settings.isManualModeEnabled()); mw.stepSizeSpinner.setValue(mw.settings.getManualModeStepSize()); boolean unitsAreMM = mw.settings.getDefaultUnits().equals("mm"); mw.mmRadioButton.setSelected(unitsAreMM); mw.inchRadioButton.setSelected(!unitsAreMM); mw.fileChooser = new JFileChooser(mw.settings.getLastOpenedFilename()); mw.commPortComboBox.setSelectedItem(mw.settings.getPort()); mw.baudrateSelectionComboBox.setSelectedItem(mw.settings.getPortRate()); mw.scrollWindowCheckBox.setSelected(mw.settings.isScrollWindowEnabled()); mw.showVerboseOutputCheckBox.setSelected(mw.settings.isVerboseOutputEnabled()); mw.showCommandTableCheckBox.setSelected(mw.settings.isCommandTableEnabled()); mw.showCommandTableCheckBoxActionPerformed(null); mw.firmwareComboBox.setSelectedItem(mw.settings.getFirmwareVersion()); mw.setSize(mw.settings.getMainWindowSettings().width, mw.settings.getMainWindowSettings().height); mw.setLocation(mw.settings.getMainWindowSettings().xLocation, mw.settings.getMainWindowSettings().yLocation); mw.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent ce) { mw.settings.getMainWindowSettings().height = ce.getComponent().getSize().height; mw.settings.getMainWindowSettings().width = ce.getComponent().getSize().width; } @Override public void componentMoved(ComponentEvent ce) { mw.settings.getMainWindowSettings().xLocation = ce.getComponent().getLocation().x; mw.settings.getMainWindowSettings().yLocation = ce.getComponent().getLocation().y; } @Override public void componentShown(ComponentEvent ce) { } @Override public void componentHidden(ComponentEvent ce) { } }); /* Display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { mw.setVisible(true); } }); mw.initFileChooser(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if (mw.fileChooser.getSelectedFile() != null) { mw.settings.setLastOpenedFilename(mw.fileChooser.getSelectedFile().getAbsolutePath()); } mw.settings.setDefaultUnits(mw.inchRadioButton.isSelected() ? "inch" : "mm"); mw.settings.setManualModeStepSize(mw.getStepSize()); mw.settings.setManualModeEnabled(mw.arrowMovementEnabled.isSelected()); mw.settings.setPort(mw.commPortComboBox.getSelectedItem().toString()); mw.settings.setPortRate(mw.baudrateSelectionComboBox.getSelectedItem().toString()); mw.settings.setScrollWindowEnabled(mw.scrollWindowCheckBox.isSelected()); mw.settings.setVerboseOutputEnabled(mw.showVerboseOutputCheckBox.isSelected()); mw.settings.setCommandTableEnabled(mw.showCommandTableCheckBox.isSelected()); mw.settings.setFirmwareVersion(mw.firmwareComboBox.getSelectedItem().toString()); SettingsFactory.saveSettings(mw.settings); if (mw.pendantUI != null) { mw.pendantUI.stop(); } } }); // Check command line for a file to open. boolean open = false; for (String arg : args) { if (open) { try { backend.setGcodeFile(new File(arg)); } catch (Exception ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); System.exit(1); } } if (arg.equals("--open") || arg.equals("-o")) { open = true; } } }
From source file:org.vimarsha.ui.DataLoaderForm.java
public DataLoaderForm() { for (String str : UIHandler.getInstance().getArchitectureList()) { architectureComboBox.addItem(str); architectureComboBox.setSelectedItem(null); }/*from www . ja va 2 s . c o m*/ architectureComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { UIHandler.getInstance().setArchitecture((String) architectureComboBox.getSelectedItem()); trainingModelTextBox.setText(UIHandler.getInstance().getTrainingModel()); } }); openRAWFileButton.addActionListener(new ActionListener() { File file = null; @Override public void actionPerformed(ActionEvent actionEvent) { JFileChooser fc = new JFileChooser("."); int returnVal = fc.showOpenDialog(Tab0); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); } if ((UIHandler.getInstance().setRawFile(file) == 100) && (UIHandler.getInstance().convertRawToArff() == 100)) { saveToARFFFileButton.setEnabled(true); attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray()); testDataTextField.setText(UIHandler.getInstance().getTestDataName()); } } }); openARFFFileButton.addActionListener(new ActionListener() { File file = null; @Override public void actionPerformed(ActionEvent actionEvent) { JFileChooser fc = new JFileChooser("."); int returnVal = fc.showOpenDialog(Tab0); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); UIHandler.getInstance().setArffFile(file); attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray()); saveToARFFFileButton.setEnabled(true); testDataTextField.setText(UIHandler.getInstance().getTestDataName()); } } }); saveToARFFFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { File file = null; JFileChooser fc = new JFileChooser("."); int returnVal = fc.showSaveDialog(Tab0); if (returnVal == JFileChooser.APPROVE_OPTION) { System.out.println(fc.getSelectedFile()); UIHandler.getInstance().saveAsArff(fc.getSelectedFile()); } } }); attributeList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent listSelectionEvent) { int selectedEvent = attributeList.getSelectedIndex(); attributesSummaryTable .setModel(UIHandler.getInstance().getArffAttributeInfo(attributeList.getSelectedIndex())); DefaultCategoryDataset data = UIHandler.getInstance().getBarChartDataSet(selectedEvent); drawBarChart(data); } }); }
From source file:edu.umich.robot.ViewerApplication.java
private Config promptForConfig() { JFileChooser fc = new JFileChooser("config"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter filter = new FileNameExtensionFilter("Text Config File", "txt"); fc.setFileFilter(filter);/*from w w w . j a v a 2s . c o m*/ fc.setMultiSelectionEnabled(false); int ret = fc.showOpenDialog(frame); if (ret == JFileChooser.APPROVE_OPTION) { try { return new ConfigFile(fc.getSelectedFile().getAbsolutePath()); } catch (IOException e) { logger.error(e.getMessage()); } } return null; }
From source file:de.hstsoft.sdeep.view.MainWindow.java
private void openFileChooser() { final JFileChooser fileChooser = new JFileChooser(new File(".")); int retVal = fileChooser.showOpenDialog(this); if (retVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); openFile(selectedFile);/*www . j a v a 2s . c om*/ } }
From source file:TextFileHandler.java
public File openFile(String title) { File result = null;/* w w w . j ava 2 s .c o m*/ JFileChooser chooser = new JFileChooser(new File(".")); if (title != null) chooser.setDialogTitle(title); int retVal = chooser.showOpenDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); } return result; }