List of usage examples for javax.swing JFileChooser DIRECTORIES_ONLY
int DIRECTORIES_ONLY
To view the source code for javax.swing JFileChooser DIRECTORIES_ONLY.
Click Source Link
From source file:com.antelink.sourcesquare.gui.controller.SourceSquareController.java
public void bind() { this.view.getSelectButtonLabel().addMouseListener(new MouseListener() { @Override//from w ww . java 2 s . c o m public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int showDialog = fileChooser.showDialog(SourceSquareController.this.view, "Select directory"); if (showDialog == JFileChooser.APPROVE_OPTION) { SourceSquareController.this.view.getTextField() .setText(fileChooser.getSelectedFile().getAbsolutePath()); } } }); this.view.getScanButtonLabel().addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseClicked(MouseEvent arg0) { File toScan = new File(SourceSquareController.this.view.getTextField().getText()); if (!toScan.exists() || toScan.list().length == 0) { JOptionPane.showMessageDialog(SourceSquareController.this.view, "Choose a valid and not empty directory", null, JOptionPane.ERROR_MESSAGE); return; } SourceSquareController.this.view.setVisible(false); SourceSquareController.this.eventBus.fireEvent(new StartScanEvent(toScan)); } }); }
From source file:AST.DesignPatternDetection.java
private void btProgramPathActionPerformed(ActionEvent e) { // TODO add your code here JFileChooser f2 = new JFileChooser(); f2.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); f2.showDialog(null, null);//from w ww . j a v a 2 s . co m tfProgramPath.setText(f2.getSelectedFile().toString()); //System.out.println(f.getCurrentDirectory()); //System.out.println(f.getSelectedFile()); }
From source file:org.mahasen.client.gui.MahasenClient.java
/** * @param loginData//w ww.j a v a2 s . c o m */ public MahasenClient(ClientLoginData loginData) { initComponents(); downloadFC.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); userNameLabel.setText(loginData.getUserName()); this.clientLoginData = loginData; propertryBasedPanel.setVisible(true); tagBasedPanel.setVisible(false); rangeBasedPanel.setVisible(false); customPropertyPanel1.setVisible(false); customPropertyPanel2.setVisible(false); SearchResult.setVisible(false); SearchResult.setEditable(false); List<NameValuePair> updatePropertyList = new ArrayList<NameValuePair>(); updateProperty = new Property(updatePropertyList); List<NameValuePair> uploadPropertyList = new ArrayList<NameValuePair>(); uploadProperty = new Property(uploadPropertyList); }
From source file:com.stam.batchmove.BatchMoveUtils.java
public static void showFilesFrame(Object[][] data, String[] columnNames, final JFrame callerFrame) { final FilesFrame filesFrame = new FilesFrame(); DefaultTableModel model = new DefaultTableModel(data, columnNames) { private static final long serialVersionUID = 1L; @Override/* ww w.j a v a2s .c o m*/ public Class<?> getColumnClass(int column) { return getValueAt(0, column).getClass(); } @Override public boolean isCellEditable(int row, int column) { return column == 0; } }; DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(JLabel.CENTER); final JTable table = new JTable(model); for (int i = 1; i < table.getColumnCount(); i++) { table.setDefaultRenderer(table.getColumnClass(i), renderer); } // table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); table.getTableHeader().setFont(new Font("Serif", Font.BOLD, 14)); table.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); table.setRowSelectionAllowed(false); table.getColumnModel().getColumn(0).setMaxWidth(35); table.getColumnModel().getColumn(1).setPreferredWidth(350); table.getColumnModel().getColumn(2).setPreferredWidth(90); table.getColumnModel().getColumn(2).setMaxWidth(140); table.getColumnModel().getColumn(3).setMaxWidth(90); JPanel tblPanel = new JPanel(); JPanel btnPanel = new JPanel(); tblPanel.setLayout(new BorderLayout()); if (table.getRowCount() > 15) { JScrollPane scrollPane = new JScrollPane(table); tblPanel.add(scrollPane, BorderLayout.CENTER); } else { tblPanel.add(table.getTableHeader(), BorderLayout.NORTH); tblPanel.add(table, BorderLayout.CENTER); } btnPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); filesFrame.setMinimumSize(new Dimension(800, 600)); filesFrame.setLayout(new BorderLayout()); filesFrame.add(tblPanel, BorderLayout.NORTH); filesFrame.add(btnPanel, BorderLayout.SOUTH); final JLabel resultsLabel = new JLabel(); JButton cancelBtn = new JButton("Cancel"); cancelBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { filesFrame.setVisible(false); callerFrame.setVisible(true); } }); JButton moveBtn = new JButton("Copy"); moveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setDialogTitle("Choose target directory"); int selVal = fileChooser.showOpenDialog(null); if (selVal == JFileChooser.APPROVE_OPTION) { File selection = fileChooser.getSelectedFile(); String targetPath = selection.getAbsolutePath(); DefaultTableModel dtm = (DefaultTableModel) table.getModel(); int nRow = dtm.getRowCount(); int copied = 0; for (int i = 0; i < nRow; i++) { Boolean selected = (Boolean) dtm.getValueAt(i, 0); String filePath = dtm.getValueAt(i, 1).toString(); if (selected) { try { FileUtils.copyFileToDirectory(new File(filePath), new File(targetPath)); dtm.setValueAt("Copied", i, 3); copied++; } catch (Exception ex) { Logger.getLogger(SelectionFrame.class.getName()).log(Level.SEVERE, null, ex); dtm.setValueAt("Failed", i, 3); } } } resultsLabel.setText(copied + " files copied. Finished!"); } } }); btnPanel.add(cancelBtn); btnPanel.add(moveBtn); btnPanel.add(resultsLabel); filesFrame.revalidate(); filesFrame.setVisible(true); callerFrame.setVisible(false); }
From source file:eu.delving.sip.actions.MediaImportAction.java
private void prepareChooser() { File directory = new File(sipModel.getPreferences().get(RECENT_DIR, System.getProperty("user.home"))); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setCurrentDirectory(directory.getParentFile()); chooser.setFileFilter(new FileFilter() { @Override/*from ww w . ja va2s.c o m*/ public boolean accept(File file) { return file.isDirectory(); } @Override public String getDescription() { return "Directories"; } }); chooser.setMultiSelectionEnabled(false); }
From source file:aurelienribon.gdxsetupui.ui.panels.ConfigUpdatePanel.java
private void browse() { String path = Ctx.cfgUpdate.destinationPath; JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this); JFileChooser chooser = new JFileChooser(new File(path)); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Select the core project folder"); if (chooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { pathField.setText(chooser.getSelectedFile().getPath()); updateConfig(chooser.getSelectedFile()); updatePanel();/* w w w. j av a 2 s .c om*/ } }
From source file:TextFileHandler.java
public File openDirectory(String title) { File result = null;/*w ww .ja v a2 s. co m*/ JFileChooser chooser = new JFileChooser(new File(".")); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (title != null) chooser.setDialogTitle(title); int retVal = chooser.showOpenDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); } return result; }
From source file:com.bwc.ora.OraUtils.java
public static File selectFile(boolean openDialog, Component parent, int selectorType, String selectDescription, String extensionDescription, String... extentions) { File prevLocation = fc.getSelectedFile() != null ? fc.getSelectedFile().getParentFile() : null; fc = new JFileChooser(prevLocation); fc.setMultiSelectionEnabled(false);// w w w .j a va 2 s .c o m fc.setFileSelectionMode(selectorType); if (selectorType == JFileChooser.FILES_ONLY) { fc.setFileFilter(new FileNameExtensionFilter(extensionDescription, extentions)); } fc.setAcceptAllFileFilterUsed(false); fc.setApproveButtonText("Select"); fc.setDialogTitle("Select " + selectDescription + "..."); int returnVal = openDialog ? fc.showOpenDialog(parent) : fc.showSaveDialog(parent); if (returnVal == JFileChooser.APPROVE_OPTION) { if (selectorType == JFileChooser.FILES_ONLY) { System.out.println("pwd: " + fc.getCurrentDirectory()); return openDialog ? loadFile(fc.getSelectedFile()) : fc.getSelectedFile(); } else if (selectorType == JFileChooser.DIRECTORIES_ONLY) { return loadDir(fc.getSelectedFile()); } else { throw new IllegalArgumentException( "Can't handle loading of files or directories at the same time!"); } } else { return null; } }
From source file:ca.canucksoftware.ipkpackager.IpkPackagerView.java
private File loadFileChooser(boolean dir, FileFilter filter, String text) { File result = null;// w ww . ja va 2 s . c o m JFileChooser fc = new JFileChooser(); //Create a file chooser disableNewFolderButton(fc); if (text != null) { fc.setSelectedFile(new File(text)); } if (dir) { fc.setDialogTitle(""); File lastDir = new File( Preferences.userRoot().get("lastDir", fc.getCurrentDirectory().getAbsolutePath())); fc.setCurrentDirectory(lastDir); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fc.showDialog(null, "Select") == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); jTextField1.setText(result.getAbsolutePath()); Preferences.userRoot().put("lastDir", result.getParentFile().getAbsolutePath()); } } else { File lastSaved = null; File lastSelected = null; if (filter != null) { fc.setDialogTitle("Save As..."); lastSaved = new File( Preferences.userRoot().get("lastSaved", fc.getCurrentDirectory().getAbsolutePath())); fc.setCurrentDirectory(lastSaved); fc.setFileFilter(filter); } else { fc.setDialogTitle(""); lastSelected = new File( Preferences.userRoot().get("lastSelected", fc.getCurrentDirectory().getAbsolutePath())); fc.setCurrentDirectory(lastSelected); fc.setAcceptAllFileFilterUsed(true); } if (fc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { result = fc.getSelectedFile(); if (lastSaved != null) { Preferences.userRoot().put("lastSaved", result.getParentFile().getAbsolutePath()); } if (lastSelected != null) { Preferences.userRoot().put("lastSelected", result.getParentFile().getAbsolutePath()); } } } return result; }
From source file:com.adito.upgrade.GUIUpgrader.java
public GUIUpgrader() { super(new BorderLayout()); JPanel info = new JPanel(new BorderLayout(2, 2)); // info.setBackground(Color.white); // info.setForeground(Color.black); // info.setOpaque(true); info.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); JLabel l = new JLabel("<html><p>This utility upgrades configuration from " + "one version 0.1.16 installation to another " + "0.2.5+ installation. You may choose which resources you " + "wish to be copied. If resources with the same name already " + "exist they will be left as is."); l.setIcon(new ImageIcon(GUIUpgrader.class.getResource("upgrader-48x48.png"))); info.add(l, BorderLayout.CENTER); info.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH); mainPanel = new JPanel(new BorderLayout()); add(info, BorderLayout.NORTH); add(mainPanel, BorderLayout.CENTER); // Installations panel JPanel installations = new JPanel(new GridBagLayout()); installations.setBorder(BorderFactory.createTitledBorder("Installations")); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.WEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(2, 2, 2, 2); gbc.weightx = 2.0;/*from w w w . j a v a 2s . c om*/ UIUtil.jGridBagAdd(installations, new JLabel("Source"), gbc, GridBagConstraints.REMAINDER); gbc.weightx = 1.0; source = new JTextField(); source.getDocument().addDocumentListener(this); UIUtil.jGridBagAdd(installations, source, gbc, GridBagConstraints.RELATIVE); browseSource = new JButton("Browse"); browseSource.setMnemonic('b'); browseSource.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(source.getText()); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Select source installation directory (0.16.1)"); if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) { source.setText(chooser.getSelectedFile().getAbsolutePath()); } } }); gbc.weightx = 0.0; UIUtil.jGridBagAdd(installations, browseSource, gbc, GridBagConstraints.REMAINDER); gbc.weightx = 2.0; UIUtil.jGridBagAdd(installations, new JLabel("Target"), gbc, GridBagConstraints.REMAINDER); gbc.weightx = 1.0; target = new JTextField(System.getProperty("user.dir")); target.getDocument().addDocumentListener(this); UIUtil.jGridBagAdd(installations, target, gbc, GridBagConstraints.RELATIVE); browseTarget = new JButton("Browse"); browseTarget.setMnemonic('r'); browseTarget.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(target.getText()); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Select target installation directory (0.2.5+)"); if (chooser.showOpenDialog(GUIUpgrader.this) == JFileChooser.APPROVE_OPTION) { target.setText(chooser.getSelectedFile().getAbsolutePath()); } } }); gbc.weightx = 0.0; UIUtil.jGridBagAdd(installations, browseTarget, gbc, GridBagConstraints.REMAINDER); mainPanel.add(installations, BorderLayout.NORTH); // Upgrade selection upgradeSelectionPanel = new JPanel(); upgradeSelectionPanel.setBorder(BorderFactory.createTitledBorder("Upgrades")); upgradeSelectionPanel.setLayout(new BoxLayout(upgradeSelectionPanel, BoxLayout.Y_AXIS)); mainPanel.add(upgradeSelectionPanel, BorderLayout.CENTER); }