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.smart.aqimonitor.client.AqiSettingDialog.java
/** * Create the dialog./* w ww . j a v a2 s . c om*/ */ public AqiSettingDialog(Frame owner, final AbstractAqiParser aqiParser) { super(owner); this.aqiParser = aqiParser; setTitle("\u8BBE\u7F6E"); setResizable(false); setBounds(100, 100, 450, 135); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); GridBagLayout gbl_contentPanel = new GridBagLayout(); gbl_contentPanel.columnWidths = new int[] { 33, 48, 66, 41, 48, 66, 0, 0 }; gbl_contentPanel.rowHeights = new int[] { 21, 0, 0 }; gbl_contentPanel.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; gbl_contentPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; contentPanel.setLayout(gbl_contentPanel); { JLabel lblRetryTimes = new JLabel("\u91CD\u8BD5\u6B21\u6570\uFF1A"); GridBagConstraints gbc_lblRetryTimes = new GridBagConstraints(); gbc_lblRetryTimes.anchor = GridBagConstraints.WEST; gbc_lblRetryTimes.insets = new Insets(0, 0, 5, 5); gbc_lblRetryTimes.gridx = 1; gbc_lblRetryTimes.gridy = 0; contentPanel.add(lblRetryTimes, gbc_lblRetryTimes); } { tfRetryTimes = new JTextField(); tfRetryTimes.setPreferredSize(new Dimension(6, 29)); tfRetryTimes.setMinimumSize(new Dimension(60, 29)); GridBagConstraints gbc_tfRetryTimes = new GridBagConstraints(); gbc_tfRetryTimes.anchor = GridBagConstraints.NORTHWEST; gbc_tfRetryTimes.insets = new Insets(0, 0, 5, 5); gbc_tfRetryTimes.gridx = 2; gbc_tfRetryTimes.gridy = 0; contentPanel.add(tfRetryTimes, gbc_tfRetryTimes); tfRetryTimes.setColumns(10); } { JLabel lblRetryGap = new JLabel("\u91CD\u8BD5\u95F4\u9694\uFF1A"); GridBagConstraints gbc_lblRetryGap = new GridBagConstraints(); gbc_lblRetryGap.anchor = GridBagConstraints.WEST; gbc_lblRetryGap.insets = new Insets(0, 0, 5, 5); gbc_lblRetryGap.gridx = 4; gbc_lblRetryGap.gridy = 0; contentPanel.add(lblRetryGap, gbc_lblRetryGap); } { tfRetryGap = new JTextField(); tfRetryGap.setMinimumSize(new Dimension(60, 29)); tfRetryGap.setPreferredSize(new Dimension(60, 29)); GridBagConstraints gbc_tfRetryGap = new GridBagConstraints(); gbc_tfRetryGap.insets = new Insets(0, 0, 5, 5); gbc_tfRetryGap.anchor = GridBagConstraints.NORTHWEST; gbc_tfRetryGap.gridx = 5; gbc_tfRetryGap.gridy = 0; contentPanel.add(tfRetryGap, gbc_tfRetryGap); tfRetryGap.setColumns(10); } { JLabel label = new JLabel("\u5206\u949F"); GridBagConstraints gbc_label = new GridBagConstraints(); gbc_label.insets = new Insets(0, 0, 5, 0); gbc_label.gridx = 6; gbc_label.gridy = 0; contentPanel.add(label, gbc_label); } { JLabel lblExportPath = new JLabel("\u8F93\u51FA\u8DEF\u5F84\uFF1A"); GridBagConstraints gbc_lblExportPath = new GridBagConstraints(); gbc_lblExportPath.anchor = GridBagConstraints.EAST; gbc_lblExportPath.insets = new Insets(0, 0, 0, 5); gbc_lblExportPath.gridx = 1; gbc_lblExportPath.gridy = 1; contentPanel.add(lblExportPath, gbc_lblExportPath); } { tfExportPath = new JTextField(); tfExportPath.setEditable(false); tfExportPath.setPreferredSize(new Dimension(180, 29)); tfExportPath.setMinimumSize(new Dimension(180, 29)); GridBagConstraints gbc_tfExportPath = new GridBagConstraints(); gbc_tfExportPath.gridwidth = 4; gbc_tfExportPath.insets = new Insets(0, 0, 0, 5); gbc_tfExportPath.fill = GridBagConstraints.HORIZONTAL; gbc_tfExportPath.gridx = 2; gbc_tfExportPath.gridy = 1; contentPanel.add(tfExportPath, gbc_tfExportPath); tfExportPath.setColumns(10); } { JButton button = new JButton("..."); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fDialog = new JFileChooser(); // fDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int result = fDialog.showOpenDialog(contentPanel); if (result == JFileChooser.APPROVE_OPTION) { tfExportPath.setText(fDialog.getSelectedFile().getAbsolutePath()); } } }); GridBagConstraints gbc_button = new GridBagConstraints(); gbc_button.gridx = 6; gbc_button.gridy = 1; contentPanel.add(button, gbc_button); } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton okButton = new JButton("\u786E\u5B9A"); okButton.setName("settingOk"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String retryTimes = tfRetryTimes.getText(); if (StringUtils.isEmpty(retryTimes) || !isNumeric(retryTimes)) { JOptionPane.showMessageDialog(contentPanel, "", "", JOptionPane.ERROR_MESSAGE); return; } String retryGap = tfRetryGap.getText(); if (StringUtils.isEmpty(retryGap) || !isNumeric(retryGap)) { JOptionPane.showMessageDialog(contentPanel, "", "", JOptionPane.ERROR_MESSAGE); return; } String exportPath = tfExportPath.getText(); if (StringUtils.isEmpty(exportPath)) { JOptionPane.showMessageDialog(contentPanel, "", "", JOptionPane.ERROR_MESSAGE); return; } File testFile = new File(exportPath); if (!testFile.exists()) { JOptionPane.showMessageDialog(contentPanel, "", "", JOptionPane.ERROR_MESSAGE); return; } props.put("query.retryTimes", retryTimes); props.put("query.retryGap", retryGap); props.put("result.path", exportPath); try { props.store(new FileOutputStream(propertiesResource.getFile()), ""); aqiParser.setRetryTimes(Integer.parseInt(retryTimes)); aqiParser.setRetryGap(Integer.parseInt(retryGap)); aqiParser.setFilePath(exportPath); } catch (IOException e1) { e1.printStackTrace(); } finally { dispose(); } } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton("\u53D6\u6D88"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } }
From source file:edu.harvard.mcz.imagecapture.jobs.JobCleanDirectory.java
private List<File> getFileList() { ArrayList<File> files = new ArrayList<File>(); String pathToCheck = ""; // Find the path in which to include files. File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL File startPoint = null;/*w w w.ja v a 2s . c om*/ // If it isn't null, retrieve the image base directory from properties, and test for read access. if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Don't know where images are stored. Set imagbase property.", "Can't Scan.", JOptionPane.ERROR_MESSAGE); } else { imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); if (imagebase != null) { if (imagebase.canRead()) { startPoint = imagebase; } else { // If it can't be read, null out imagebase imagebase = null; } } if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) { // A scan start point has been provided, don't launch a dialog. startPoint = startPointSpecific; } if (imagebase == null || scan == SCAN_SELECT) { // launch a file chooser dialog to select the directory to scan final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) { fileChooser.setCurrentDirectory(startPointSpecific); } else { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser.setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } } int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); log.debug("Selected base directory: " + file.getName() + "."); startPoint = file; } else { //TODO: handle error condition log.error("Directory selection cancelled by user."); } } // Check that startPoint is or is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory (" + base + ")"); String message = "Can't scan and cleanup files outside of base image directory (" + base + ")"; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION); } else if (ImageCaptureProperties.getPathBelowBase(startPoint).trim().length() == 0) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") which is the base image directory."); String message = "Can only scan and cleanup files in a selected directory within the base directory (" + base + ").\nYou must select some subdirectory within the base directory to cleanup."; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Cleanup image base directory.", JOptionPane.YES_NO_OPTION); } else { if (!startPoint.canRead()) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Unable to read selected directory: " + startPoint.getPath(), "Can't Scan.", JOptionPane.YES_NO_OPTION); } else { pathToCheck = ImageCaptureProperties.getPathBelowBase(startPoint); // retrieve a list of image records in the selected directory ICImageLifeCycle ils = new ICImageLifeCycle(); List<ICImage> images = ils.findAllInDir(pathToCheck); Iterator<ICImage> iter = images.iterator(); while (iter.hasNext()) { ICImage image = iter.next(); File imageFile = new File( ImageCaptureProperties.assemblePathWithBase(image.getPath(), image.getFilename())); files.add(imageFile); counter.incrementFilesSeen(); } } } } log.debug("Found " + files.size() + " Image files in directory to check."); return files; }
From source file:filesscanner.MainWindow.java
private JFileChooser ShowChooser(File f) { JFileChooser chooser = new JFileChooser(f); chooser.setMultiSelectionEnabled(true); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); return chooser; }
From source file:Display.java
@SuppressWarnings("unchecked") Display() {/* w w w . j av a 2s. c o m*/ super(Reference.NAME); cardLayout = new CardLayout(); panel.setLayout(cardLayout); final int java7Update = Utils.Validators.java7Update.check(); final int java8Update = Utils.Validators.java8Update.check(); try { URL host = new URL(Reference.PROTOCOL, Reference.SOURCE_HOST, Reference.PORT, Reference.JSON_ARRAY); JSONParser parser = new JSONParser(); Object json = parser.parse(new URLReader(host)); final JSONArray array = (JSONArray) json; JSONObject nameObject1 = (JSONObject) array.get(0); XPackInstaller.selected_url = nameObject1.get("url").toString(); XPackInstaller.javaVersion = Integer.parseInt(nameObject1.get("version").toString()); XPackInstaller.profile = nameObject1.get("profile").toString(); XPackInstaller.canAcceptOptional = Boolean .parseBoolean(nameObject1.get("canAcceptOptional").toString()); if (!XPackInstaller.canAcceptOptional) { checkOptifine.setEnabled(false); checkOptifine.setSelected(false); zainstalujMoCreaturesCheckBox.setEnabled(false); zainstalujMoCreaturesCheckBox.setSelected(false); optionalText.setEnabled(false); } else { checkOptifine.setEnabled(true); zainstalujMoCreaturesCheckBox.setEnabled(true); optionalText.setEnabled(true); } for (Object anArray : array) { comboBox1.addItem(new JSONObject((JSONObject) anArray).get("name")); } comboBox1.addActionListener(e -> { int i = 0; while (true) { JSONObject nameObject = (JSONObject) array.get(i); String name1 = nameObject.get("name").toString(); if (name1 == comboBox1.getSelectedItem()) { XPackInstaller.canAcceptOptional = Boolean .parseBoolean(nameObject.get("canAcceptOptional").toString()); XPackInstaller.selected_url = nameObject.get("url").toString(); XPackInstaller.javaVersion = Integer.parseInt(nameObject.get("version").toString()); XPackInstaller.profile = nameObject.get("profile").toString(); if (!XPackInstaller.canAcceptOptional) { checkOptifine.setEnabled(false); checkOptifine.setSelected(false); zainstalujMoCreaturesCheckBox.setEnabled(false); zainstalujMoCreaturesCheckBox.setSelected(false); optionalText.setEnabled(false); } else { checkOptifine.setEnabled(true); zainstalujMoCreaturesCheckBox.setEnabled(true); optionalText.setEnabled(true); } break; } i++; } int javaStatus; if (XPackInstaller.javaVersion == 8) { javaStatus = java8Update; } else { javaStatus = java7Update; } if (javaStatus == 0) { javaversion.setText("TAK"); javaversion.setForeground(Reference.COLOR_DARK_GREEN); } else if (javaStatus == 1) { javaversion.setText("NIE"); javaversion.setForeground(Reference.COLOR_DARK_ORANGE); } else if (javaStatus == 2) { if (XPackInstaller.javaVersion == 8) { javaversion.setText("Nie posiadasz JRE8 w wersji 25 lub nowszej!"); } else { javaversion.setText("Nie posiadasz najnowszej wersji JRE7!"); } javaversion.setForeground(Color.RED); } if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = true; button2.setText("Dalej"); } else { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); } }); } catch (FileNotFoundException | ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd", JOptionPane.ERROR_MESSAGE); System.exit(0); } pobierzOryginalnyLauncherMCCheckBox.addActionListener(e -> { if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) { PathLauncherLabel.setEnabled(true); textField1.setEnabled(true); button3.setEnabled(true); XPackInstaller.installLauncher = true; labelLauncher.setEnabled(true); progressBar3.setEnabled(true); } else { PathLauncherLabel.setEnabled(false); textField1.setEnabled(false); button3.setEnabled(false); XPackInstaller.installLauncher = false; labelLauncher.setEnabled(false); progressBar3.setEnabled(false); } }); button3.addActionListener(e -> { JFileChooser chooser = new JFileChooser(System.getProperty("user.home")); chooser.setApproveButtonText("Wybierz"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle("Wybierz ciek"); int returnValue = chooser.showOpenDialog(getContentPane()); if (returnValue == JFileChooser.APPROVE_OPTION) { try { XPackInstaller.launcher_path = chooser.getSelectedFile().getCanonicalPath(); } catch (IOException x) { x.printStackTrace(); } textField1.setText(XPackInstaller.launcher_path); } }); slider1.setMaximum(Utils.Utils.humanReadableRAM() - 2); slider1.addChangeListener(e -> XPackInstaller.allocatedRAM = slider1.getValue()); button1.addActionListener(e -> { if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) { File launcher = new File(XPackInstaller.launcher_path + File.separator + "Minecraft.exe"); if (textField1.getText().equals("")) { JOptionPane.showMessageDialog(panel, "Nie wybrae cieki instalacji Launcher'a!", "Bd", JOptionPane.ERROR_MESSAGE); } else if (launcher.exists()) { JOptionPane.showMessageDialog(panel, "W podanym katalogu istanieje ju plik o nazwie 'Minecraft.exe'!", "Bad", JOptionPane.ERROR_MESSAGE); } else { cardLayout.next(panel); } } else { cardLayout.next(panel); if (osarch.getText().equals("NIE") && Ram.getText().equals("TAK") && javaarch.getText().equals("NIE") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); JOptionPane.showMessageDialog(gui, "Prosimy sprawdzi\u0107 czy na komputerze nie ma zainstalowanych dw\u00f3ch \u015brodowisk Java: w wersji 32-bitowej i 64-bitowej.\nJe\u015bli zainstalowane s\u0105 obie wersje prosimy o odinstalowanie wersji 32-bitowej. To rozwi\u0105\u017ce problem.", "B\u0142\u0105d konfiguracji Javy", JOptionPane.ERROR_MESSAGE); } } }); if (Utils.Validators.systemArchitecture.check()) { osarch.setText("TAK"); osarch.setForeground(Reference.COLOR_DARK_GREEN); } else { osarch.setText("NIE"); osarch.setForeground(Color.RED); } if (Utils.Validators.ramAmount.check()) { Ram.setText("TAK"); Ram.setForeground(Reference.COLOR_DARK_GREEN); } else { Ram.setText("NIE"); Ram.setForeground(Color.RED); } if (Utils.Validators.javaArchitecture.check()) { javaarch.setText("TAK"); javaarch.setForeground(Reference.COLOR_DARK_GREEN); } else { javaarch.setText("NIE"); javaarch.setForeground(Color.RED); } int javaStatus; if (XPackInstaller.javaVersion == 8) { javaStatus = java8Update; } else { javaStatus = java7Update; } if (javaStatus == 0) { javaversion.setText("TAK"); javaversion.setForeground(Reference.COLOR_DARK_GREEN); } else if (javaStatus == 1) { javaversion.setText("NIE"); javaversion.setForeground(Reference.COLOR_DARK_ORANGE); } else if (javaStatus == 2) { javaversion.setText("Nie posiadasz najnowszej wersji JRE!"); javaversion.setForeground(Color.RED); } if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = true; button2.setText("Dalej"); } else { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); } button2.addActionListener(e -> { if (XPackInstaller.canGoForward) { cardLayout.next(panel); } else { System.exit(1); } }); wsteczButton.addActionListener(e -> cardLayout.previous(panel)); try { editorPane1.setPage("http://xpack.pl/licencja.html"); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd", JOptionPane.ERROR_MESSAGE); System.exit(0); } licenseC.addActionListener(e -> { if (licenseC.isSelected()) { dalejButton.setEnabled(true); } else { dalejButton.setEnabled(false); } }); try { File mainDir = new File(System.getenv("appdata") + File.separator + "XPackInstaller"); if (mainDir.exists()) { FileUtils.deleteDirectory(mainDir); if (!mainDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } } else { if (!mainDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } } File optionalDir = new File(mainDir.getAbsolutePath() + File.separator + "OptionalMods"); if (!optionalDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } dalejButton.addActionListener(e -> { cardLayout.next(panel); try { progressBar1.setValue(0); if (checkOptifine.isSelected() && zainstalujMoCreaturesCheckBox.isSelected()) { DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine, optionalDir.getAbsolutePath()); task2.addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("progress")) { labelmodpack.setText("Pobieranie Optifine HD w toku..."); if (task2.isDone()) { task3(); } optifineProgress = (Integer) evt.getNewValue(); progressBar1.setValue(optifineProgress); } }); task2.execute(); } else if (checkOptifine.isSelected()) { DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine, optionalDir.getAbsolutePath()); task2.addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("progress")) { labelmodpack.setText("Pobieranie Optifine HD w toku..."); if (task2.isDone()) { task(); } optifineProgress = (Integer) evt.getNewValue(); progressBar1.setValue(optifineProgress); } }); task2.execute(); } else if (zainstalujMoCreaturesCheckBox.isSelected()) { task3(); } else { task(); } } catch (Exception exx) { exx.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } final JScrollBar bar = scrollPane1.getVerticalScrollBar(); bar.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); bar.addMouseWheelListener(e -> { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } }); scrollPane1.setWheelScrollingEnabled(true); scrollPane1.addMouseWheelListener(e -> { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } }); panel.add(panel3); panel.add(panel1); panel.add(panel2); panel.add(panel4); add(panel); }
From source file:edu.harvard.mcz.imagecapture.jobs.JobRecheckForTemplates.java
private List<ICImage> getFileList() { List<ICImage> files = new ArrayList<ICImage>(); if (scan != SCAN_ALL) { String pathToCheck = ""; // Find the path in which to include files. File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL File startPoint = null;//from w ww . j a v a 2s. co m // If it isn't null, retrieve the image base directory from properties, and test for read access. if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Don't know where images are stored. Set imagbase property.", "Can't Scan.", JOptionPane.ERROR_MESSAGE); } else { imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); if (imagebase != null) { if (imagebase.canRead()) { startPoint = imagebase; } else { // If it can't be read, null out imagebase imagebase = null; } } if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) { // A scan start point has been provided, don't launch a dialog. startPoint = startPointSpecific; } if (imagebase == null || scan == SCAN_SELECT) { // launch a file chooser dialog to select the directory to scan final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) { fileChooser.setCurrentDirectory(startPointSpecific); } else { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser .setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } } int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); log.debug("Selected base directory: " + file.getName() + "."); startPoint = file; } else { //TODO: handle error condition log.error("Directory selection cancelled by user."); } } // Check that startPoint is or is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory (" + base + ")"); String message = "Can't scan and database files outside of base image directory (" + base + ")"; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION); } else { if (!startPoint.canRead()) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Unable to read selected directory: " + startPoint.getPath(), "Can't Scan.", JOptionPane.YES_NO_OPTION); } else { pathToCheck = ImageCaptureProperties.getPathBelowBase(startPoint); // retrieve a list of image records in the selected directory ICImageLifeCycle ils = new ICImageLifeCycle(); ICImage pattern = new ICImage(); pattern.setPath(pathToCheck); pattern.setTemplateId(PositionTemplate.TEMPLATE_NO_COMPONENT_PARTS); files = ils.findByExample(pattern); if (files != null) { log.debug(files.size()); } } } } } else { try { // retrieve a list of all image records with no template ICImageLifeCycle ils = new ICImageLifeCycle(); files = ils.findNotDrawerNoTemplateImages(); if (files != null) { log.debug(files.size()); } } catch (HibernateException e) { log.error(e.getMessage()); runStatus = RunStatus.STATUS_FAILED; String message = "Error loading the list of images with no templates. " + e.getMessage(); JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Error loading image records.", JOptionPane.YES_NO_OPTION); } } log.debug("Found " + files.size() + " Image files without templates in directory to check."); return files; }
From source file:Compare.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter);/*from ww w .j a v a 2 s.com*/ int returnvalue = folder.showSaveDialog(this); File myfolder = null; if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); } listofFiles(myfolder); sortByName(); DefaultTableModel model = (DefaultTableModel) FileDetails.getModel(); int count = 1; for (Files filename : filenames1) { String size = Long.toString(filename.Filesize) + "Bytes"; model.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation }); } }
From source file:de.uka.ilkd.key.dl.gui.initialdialog.gui.ToolInstaller.java
public void install(JComponent parent, Window dialog) { final File installDirectory; switch (OSInfosDefault.INSTANCE.getOs()) { case OSX:// ww w.ja v a 2s . co m System.setProperty("apple.awt.fileDialogForDirectories", "true"); FileDialog d = new FileDialog(Frame.getFrames()[0], "Choose directory for installation of " + toolName, FileDialog.LOAD); d.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (d.getFile() != null) { installDirectory = new File(d.getDirectory(), d.getFile()); } else { installDirectory = null; } break; default: final JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle("Choose directory for installation of " + toolName); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setApproveButtonText("Install " + toolName + " here"); int result = chooser.showDialog(parent, "Install " + toolName + " here"); if (result == JFileChooser.APPROVE_OPTION) { installDirectory = chooser.getSelectedFile(); } else { installDirectory = null; } } if (installDirectory != null) { try { final File tmp = File.createTempFile("keymaeraDownload", "." + ft.toString().toLowerCase()); final FileInfo info = new FileInfo(url, tmp.getName(), false); final DownloadManager dlm = new DownloadManager(); ProgressBarWindow pbw = new ProgressBarWindow(parent, installDirectory, tmp, ft, ps, dialog); dlm.addListener(pbw); Runnable down = new Runnable() { @Override public void run() { dlm.downloadAll(new FileInfo[] { info }, 2000, tmp.getParentFile().getAbsolutePath(), true); } }; Thread thread = new Thread(down); thread.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:edu.harvard.mcz.imagecapture.jobs.JobRepeatOCR.java
private List<File> getFileList() { String pathToCheck = ""; if (scan != SCAN_ALL) { // Find the path in which to include files. File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL File startPoint = null;/*from w w w. jav a 2s .c om*/ // If it isn't null, retrieve the image base directory from properties, and test for read access. if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Don't know where images are stored. Set imagbase property.", "Can't Scan.", JOptionPane.ERROR_MESSAGE); } else { imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); if (imagebase != null) { if (imagebase.canRead()) { startPoint = imagebase; } else { // If it can't be read, null out imagebase imagebase = null; } } if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) { // A scan start point has been provided, don't launch a dialog. startPoint = startPointSpecific; } if (imagebase == null || scan == SCAN_SELECT) { // launch a file chooser dialog to select the directory to scan final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) { fileChooser.setCurrentDirectory(startPointSpecific); } else { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser .setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } } int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); log.debug("Selected base directory: " + file.getName() + "."); startPoint = file; } else { //TODO: handle error condition log.error("Directory selection cancelled by user."); } //TODO: Filechooser to pick path, then save (if SCAN_ALL) imagebase property. //Perhaps. Might be undesirable behavior. //Probably better to warn that imagebase is null; } // Check that startPoint is or is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory (" + base + ")"); String message = "Can't scan and database files outside of base image directory (" + base + ")"; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION); } else { // run in separate thread and allow cancellation and status reporting // walk through directory tree if (!startPoint.canRead()) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Unable to read selected directory: " + startPoint.getPath(), "Can't Scan.", JOptionPane.YES_NO_OPTION); } else { pathToCheck = ImageCaptureProperties.getPathBelowBase(startPoint); } } } } // Retrieve a list of all specimens in state OCR SpecimenLifeCycle sls = new SpecimenLifeCycle(); Specimen pattern = new Specimen(); pattern.setWorkFlowStatus(WorkFlowStatus.STAGE_0); List<Specimen> specimens = sls.findByExample(pattern); ArrayList<File> files = new ArrayList<File>(); for (int i = 0; i < specimens.size(); i++) { Specimen s = specimens.get(i); Set<ICImage> images = s.getICImages(); Iterator<ICImage> iter = images.iterator(); while (iter.hasNext() && runStatus != RunStatus.STATUS_TERMINATED) { ICImage image = (ICImage) iter.next(); if (scan == SCAN_ALL || image.getPath().startsWith(pathToCheck)) { // Add image for specimen to list to check File imageFile = new File( ImageCaptureProperties.assemblePathWithBase(image.getPath(), image.getFilename())); files.add(imageFile); counter.incrementFilesSeen(); } } } String message = "Found " + files.size() + " Specimen records on which to repeat OCR."; log.debug(message); Singleton.getSingletonInstance().getMainFrame().setStatusMessage(message); return files; }
From source file:model.settings.ReadSettings.java
/** * checks whether program information on current workspace exist. * @return if workspace is now set./*from w ww. ja va 2 s . co m*/ */ public static String install() { boolean installed = false; String wsLocation = ""; /* * does program root directory exist? */ if (new File(PROGRAM_LOCATION).exists()) { //try to read try { wsLocation = readFromFile(PROGRAM_SETTINGS_LOCATION); installed = new File(wsLocation).exists(); if (!installed) { wsLocation = ""; } } catch (FileNotFoundException e) { System.out.println("file not found " + e); showErrorMessage(); } catch (IOException e) { System.out.println("io" + e); showErrorMessage(); } } //if settings not found. if (!installed) { new File(PROGRAM_LOCATION).mkdir(); try { //create new file chooser JFileChooser jc = new JFileChooser(); //sets the text and language of all the components in JFileChooser UIManager.put("FileChooser.openDialogTitleText", "Open"); UIManager.put("FileChooser.lookInLabelText", "LookIn"); UIManager.put("FileChooser.openButtonText", "Open"); UIManager.put("FileChooser.cancelButtonText", "Cancel"); UIManager.put("FileChooser.fileNameLabelText", "FileName"); UIManager.put("FileChooser.filesOfTypeLabelText", "TypeFiles"); UIManager.put("FileChooser.openButtonToolTipText", "OpenSelectedFile"); UIManager.put("FileChooser.cancelButtonToolTipText", "Cancel"); UIManager.put("FileChooser.fileNameHeaderText", "FileName"); UIManager.put("FileChooser.upFolderToolTipText", "UpOneLevel"); UIManager.put("FileChooser.homeFolderToolTipText", "Desktop"); UIManager.put("FileChooser.newFolderToolTipText", "CreateNewFolder"); UIManager.put("FileChooser.listViewButtonToolTipText", "List"); UIManager.put("FileChooser.newFolderButtonText", "CreateNewFolder"); UIManager.put("FileChooser.renameFileButtonText", "RenameFile"); UIManager.put("FileChooser.deleteFileButtonText", "DeleteFile"); UIManager.put("FileChooser.filterLabelText", "TypeFiles"); UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details"); UIManager.put("FileChooser.fileSizeHeaderText", "Size"); UIManager.put("FileChooser.fileDateHeaderText", "DateModified"); SwingUtilities.updateComponentTreeUI(jc); jc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jc.setMultiSelectionEnabled(false); final String informationMsg = "Please select the workspace folder. \n" + "By default, the new files are saved in there. \n\n" + "Is changed simply by using the Save-As option.\n" + "If no folder is specified, the default worspace folder \n" + "is the home directory of the current user."; final int response = JOptionPane.showConfirmDialog(jc, informationMsg, "Select workspace folder", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE); final String defaultSaveLocation = System.getProperty("user.home") + System.getProperty("file.separator"); File f; if (response != JOptionPane.NO_OPTION) { //fetch selected file f = jc.getSelectedFile(); jc.showDialog(null, "select"); } else { f = new File(defaultSaveLocation); } printInformation(); if (f == null) { f = new File(defaultSaveLocation); } //if file selected if (f != null) { //if the file exists if (f.exists()) { writeToFile(PROGRAM_SETTINGS_LOCATION, ID_PROGRAM_LOCATION + "\n" + f.getAbsolutePath()); } else { //open message dialog JOptionPane.showConfirmDialog(null, "Folder does " + "not exist", "Error creating workspace", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null); } //recall install return install(); } } catch (IOException e) { System.out.println(e); JOptionPane.showConfirmDialog(null, "An exception occured." + " Try again later.", "Error creating workspace", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null); } } if (System.getProperty("os.name").equals("Mac OS X")) { installOSX(); } else if (System.getProperty("os.name").equals("Linux")) { installLinux(); } else if (System.getProperty("os.name").equals("Windows")) { installWindows(); } return wsLocation; }
From source file:com.stam.batchmove.SelectionFrame.java
private void selectSourceDirBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectSourceDirBtnActionPerformed fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setDialogTitle("Choose source directory"); int retVal = fileChooser.showOpenDialog(this); if (retVal == JFileChooser.APPROVE_OPTION) { File selection = fileChooser.getSelectedFile(); String selectedFolder = selection.getAbsolutePath(); sourceDir.setText(selectedFolder); }// w w w . java 2 s . c o m }