List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:de.ist.clonto.Ontogui.java
private void loadOntology(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_loadOntology if (null != dataset) { dataset.end();//from w w w .j ava 2s . co m } JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { dataset = TDBFactory.createDataset(fc.getSelectedFile().toString()); ontologyNameField.setText(fc.getSelectedFile().getName()); ontoPath = fc.getSelectedFile().toPath(); } else { JOptionPane.showMessageDialog(this, "Loading ontology failed"); } }
From source file:io.github.jeremgamer.editor.panels.IconFrame.java
public IconFrame(JFrame parent) { this.setModal(true); this.setResizable(false); ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>(); try {/*from w w w . java 2s . c om*/ icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png"))); } catch (IOException e1) { e1.printStackTrace(); } this.setIconImages((List<? extends Image>) icons); this.setTitle("Icnes"); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.LINE_AXIS)); content.setBorder(BorderFactory.createTitledBorder("")); try { remove128.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); remove64.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); remove32.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); remove16.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } browse128.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "128.png"); try { x128.repaint(); x128.getGraphics().drawImage(ImageIO.read(new File(path)), 0 + 10, 0 + 20, 128, 128, null); } catch (IOException e) { e.printStackTrace(); } } } }); remove128.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File("projects/" + Editor.getProjectName() + "/128.png"); file.delete(); x128.repaint(); } }); browse64.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "64.png"); try { x64.repaint(); x64.getGraphics().drawImage(ImageIO.read(new File(path)), 32 + 10, 32 + 20, 64, 64, null); } catch (IOException e) { e.printStackTrace(); } } } }); remove64.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File("projects/" + Editor.getProjectName() + "/64.png"); file.delete(); x64.repaint(); } }); browse32.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "32.png"); try { x32.repaint(); x32.getGraphics().drawImage(ImageIO.read(new File(path)), 48 + 10, 48 + 20, 32, 32, null); } catch (IOException e) { e.printStackTrace(); } } } }); remove32.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File("projects/" + Editor.getProjectName() + "/32.png"); file.delete(); x32.repaint(); } }); browse16.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "16.png"); try { x16.repaint(); x16.getGraphics().drawImage(ImageIO.read(new File(path)), 56 + 10, 56 + 20, 16, 16, null); } catch (IOException e) { e.printStackTrace(); } } } }); remove16.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File("projects/" + Editor.getProjectName() + "/16.png"); file.delete(); x16.repaint(); } }); content.add(x128); content.add(x64); content.add(x32); content.add(x16); this.setContentPane(content); this.pack(); this.setLocationRelativeTo(parent); this.setVisible(true); }
From source file:de.ist.clonto.Ontogui.java
private void backupOntologyButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_backupOntologyButtonActionPerformed JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try {// ww w .j a v a 2 s .c o m FileUtils.cleanDirectory(fc.getSelectedFile()); FileUtils.copyDirectory(ontoPath.toFile(), fc.getSelectedFile()); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Loading ontology failed"); } JOptionPane.showMessageDialog(this, "Created Backup files!"); } else { JOptionPane.showMessageDialog(this, "Loading ontology failed"); } }
From source file:coreferenceresolver.gui.MainGUI.java
private void applyClassifierBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyClassifierBtnActionPerformed JFileChooser inputFileChooser = new JFileChooser(defaulPath); inputFileChooser.setDialogTitle("Choose where your classified result file saved"); inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { resultFilePathTF1.setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "classified_result.txt"); noteTF.setText("Create classified result file waiting ..."); new Thread(new Runnable() { @Override//from w ww. ja v a 2 s . com public void run() { try { WekaMain.run(inputFilePathTF.getText(), markupFilePathTF.getText(), trainingFilePathTF.getText(), testingFilePathTF.getText(), resultFilePathTF1.getText()); noteTF.setText("Create result file done!"); String folderPathOpen = resultFilePathTF1.getText().substring(0, resultFilePathTF1.getText().lastIndexOf(File.separatorChar)); Desktop.getDesktop().open(new File(folderPathOpen)); //Open the window for predicted chains ClassifiedResultGUI.render(true); //Open the window for actual chains ClassifiedResultGUI.render(false); } catch (Exception ex) { Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex); } } }).start(); } else { noteTF.setText("No classified result file location selected"); } }
From source file:com.sf.energy.transfer.form.DataConfiguration.java
/** * ??//from w ww. j a v a 2 s.c om * @param evt ? */ private void scanActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser fc = new JFileChooser(); File directory = new File(dir); // ?? fc.setCurrentDirectory(directory); fc.setDialogTitle(""); // FileNameExtensionFilter filter1 = new FileNameExtensionFilter(".xls", "xls"); fc.addChoosableFileFilter(filter1); FileNameExtensionFilter filter2 = new FileNameExtensionFilter(".dmp", "dmp"); fc.addChoosableFileFilter(filter1); // fc.setFileFilter(fc.getAcceptAllFileFilter()); int intRetVal = fc.showOpenDialog(new JFrame()); // ? if (intRetVal == JFileChooser.APPROVE_OPTION) { // ? dir = fc.getSelectedFile().getPath(); // filePath.setText(dir); } }
From source file:com.mycompany.zad1.MainWindow.java
private void chooseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseButtonActionPerformed JFileChooser chooser = new JFileChooser(); int dialogResult = chooser.showOpenDialog(this); if (dialogResult == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try {/*from w w w. j a v a2 s . c o m*/ imageOrginal = new ImageInOut().readImageFromFile(file); imageBuff = new ImageInOut().readImageFromFile(file); } catch (Exception ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } if (imageOrginal != null) { // imageBuff = new ImageModel(imageOrginal); // try { // imageBuff = (ImageModel) imageOrginal.clone(); // } catch (CloneNotSupportedException ex) { // Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); // } imageOrginalLabel.setIcon(new ImageIcon(imageOrginal.getImage())); imageMoiffayLabel.setIcon(new ImageIcon(imageBuff.getImage())); addBrightnessButton.setEnabled(true); addContrastButton.setEnabled(true); minusBrightnessButton.setEnabled(true); minusContrastButton.setEnabled(true); reverseColorButton.setEnabled(true); saveButton.setEnabled(true); laplasjanButton.setEnabled(true); kirshButton.setEnabled(true); averegeilterButton.setEnabled(true); medianFilterButton.setEnabled(true); calculateHistogramButton.setEnabled(true); histogramModifyButton.setEnabled(false); fourierButton.setEnabled(true); regionGrowingButton.setEnabled(true); } }
From source file:userInterface.EnergySourceBoardSupervisor.ManageEnergyConsumptionsJPanel.java
private void uplaodBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uplaodBtnActionPerformed JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(null); File f = chooser.getSelectedFile(); if (f != null) { path = f.getAbsolutePath();//w w w. j av a2 s . c om if (path != null) { attachmentpath_Txt.setText(path); } } else { JOptionPane.showMessageDialog(null, "File not selected", "WARNING", JOptionPane.WARNING_MESSAGE); } }
From source file:uk.ac.ox.cbrg.cpfp.uploadapp.UploadApplet.java
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed // Create & show file chooser with extension filter as per applet param JFileChooser fc = new JFileChooser(); fc.setFileFilter(new CustomFileFilter(fileExtensions)); fc.setMultiSelectionEnabled(true);/*from ww w . j a va 2s .co m*/ fc.showOpenDialog(UploadApplet.this); // Add selected files to upload queue File[] selFiles = fc.getSelectedFiles(); addFiles(selFiles); }
From source file:coreferenceresolver.gui.MarkupGUI.java
public MarkupGUI() throws IOException { highlightPainters = new ArrayList<>(); for (int i = 0; i < COLORS.length; ++i) { DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter( COLORS[i]);//ww w . j a v a 2s .co m highlightPainters.add(highlightPainter); } defaulPath = FileUtils.readFileToString(new File(".\\src\\coreferenceresolver\\gui\\defaultpath")); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new BorderLayout()); this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); //create menu items JMenuItem importMenuItem = new JMenuItem("Import"); JMenuItem exportMenuItem = new JMenuItem("Export"); fileMenu.add(importMenuItem); fileMenu.add(exportMenuItem); menuBar.add(fileMenu); this.setJMenuBar(menuBar); ScrollablePanel mainPanel = new ScrollablePanel(); mainPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.NONE); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); //IMPORT BUTTON importMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // MarkupGUI.reviewElements.clear(); // MarkupGUI.markupReviews.clear(); JFileChooser markupFileChooser = new JFileChooser(defaulPath); markupFileChooser.setDialogTitle("Choose your markup file"); markupFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { final JDialog d = new JDialog(); JPanel p1 = new JPanel(new GridBagLayout()); p1.add(new JLabel("Please Wait..."), new GridBagConstraints()); d.getContentPane().add(p1); d.setSize(100, 100); d.setLocationRelativeTo(null); d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); d.setModal(true); SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws IOException, BadLocationException { readMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath()); for (int i = 0; i < markupReviews.size(); ++i) { mainPanel.add(newReviewPanel(markupReviews.get(i), i)); } return null; } protected void done() { MarkupGUI.this.revalidate(); d.dispose(); } }; worker.execute(); d.setVisible(true); } else { return; } } }); //EXPORT BUTTON: GET NEW VALUE (REF, TYPE) OF NPs exportMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser markupFileChooser = new JFileChooser(defaulPath); markupFileChooser.setDialogTitle("Choose where your markup file saved"); markupFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { final JDialog d = new JDialog(); JPanel p1 = new JPanel(new GridBagLayout()); p1.add(new JLabel("Please Wait..."), new GridBagConstraints()); d.getContentPane().add(p1); d.setSize(100, 100); d.setLocationRelativeTo(null); d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); d.setModal(true); SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws IOException { for (Review review : markupReviews) { generateNPsRef(review); } int i = 0; for (ReviewElement reviewElement : reviewElements) { int j = 0; for (Element element : reviewElement.elements) { String newType = element.typeSpinner.getValue().toString(); if (newType.equals("Object")) { markupReviews.get(i).getNounPhrases().get(j).setType(0); } else if (newType.equals("Attribute")) { markupReviews.get(i).getNounPhrases().get(j).setType(3); } else if (newType.equals("Other")) { markupReviews.get(i).getNounPhrases().get(j).setType(1); } else if (newType.equals("Candidate")) { markupReviews.get(i).getNounPhrases().get(j).setType(2); } ++j; } ++i; } initMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "markup.out.txt"); return null; } protected void done() { d.dispose(); try { Desktop.getDesktop() .open(new File(markupFileChooser.getSelectedFile().getAbsolutePath())); } catch (IOException ex) { Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex); } } }; worker.execute(); d.setVisible(true); } else { return; } } }); JScrollPane scrollMainPane = new JScrollPane(mainPanel); scrollMainPane.getVerticalScrollBar().setUnitIncrement(16); scrollMainPane.setPreferredSize(new Dimension(this.getWidth(), this.getHeight())); scrollMainPane.setSize(this.getWidth(), this.getHeight()); this.setResizable(false); this.add(scrollMainPane, BorderLayout.CENTER); this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.pack(); }
From source file:net.sf.maltcms.chromaui.project.spi.wizard.DBProjectVisualPanel1.java
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed String command = evt.getActionCommand(); if ("BROWSE".equals(command)) { FileChooserBuilder fcb = new FileChooserBuilder(DBProjectVisualPanel1.class); fcb.setTitle("Select Project Location"); fcb.setDirectoriesOnly(true);/*from w ww . ja v a 2 s. c o m*/ String path = this.projectLocationTextField.getText(); JFileChooser jfc = fcb.createFileChooser(); if (path.length() > 0) { File f = new File(path); if (f.exists()) { jfc.setSelectedFile(f); } } if (JFileChooser.APPROVE_OPTION == jfc.showOpenDialog(this)) { File projectDir = jfc.getSelectedFile(); projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); } firePropertyChange("VALIDATE", null, null); } }