List of usage examples for javax.swing JFileChooser FILES_ONLY
int FILES_ONLY
To view the source code for javax.swing JFileChooser FILES_ONLY.
Click Source Link
From source file:gui.images.ImageHubExplorer.java
/** * Get a screen capture of the kNN graph visualization and save the image to * a file.// w w w .j a v a 2s . co m * * @param evt ActionEvent object. */ private void graphScreenCaptureItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphScreenCaptureItemActionPerformed if (neighborGraphScrollPane != null) { BufferedImage bufImage = ScreenImage .createImage((JComponent) neighborGraphScrollPane.getViewport().getComponent(0)); try { File outFile; JFileChooser jfc = new JFileChooser(currentDirectory); jfc.setDialogTitle("Select file to save the component image: "); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); int rVal = jfc.showOpenDialog(ImageHubExplorer.this); if (rVal == JFileChooser.APPROVE_OPTION) { currentDirectory = jfc.getSelectedFile().getParentFile(); outFile = jfc.getSelectedFile(); ImageIO.write(bufImage, "jpg", outFile); } } catch (Exception e) { System.err.println("problem writing file: " + e.getMessage()); } } }
From source file:gui.images.ImageHubExplorer.java
/** * Get a screen capture of the MDS data visualization and save the image to * a file./*w ww . j a v a 2s . c o m*/ * * @param evt ActionEvent object. */ private void mdsScreenCaptureItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mdsScreenCaptureItemActionPerformed if (mdsCollectionPanel != null) { BufferedImage bufImage = ScreenImage.createImage((JComponent) mdsCollectionPanel); try { File outFile; JFileChooser jfc = new JFileChooser(currentDirectory); jfc.setDialogTitle("Select file to save the component image: "); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); int rVal = jfc.showOpenDialog(ImageHubExplorer.this); if (rVal == JFileChooser.APPROVE_OPTION) { currentDirectory = jfc.getSelectedFile().getParentFile(); outFile = jfc.getSelectedFile(); ImageIO.write(bufImage, "jpg", outFile); } } catch (Exception e) { System.err.println("problem writing file: " + e.getMessage()); } } }
From source file:src.gui.ItSIMPLE.java
/** * @return Returns the planAnalysisFramePanel. *///from w ww . java2 s. co m private ItFramePanel getPlanAnalysisFramePanel() { if (planAnalysisFramePanel == null) { planAnalysisFramePanel = new ItFramePanel(":: Plan Analysis", ItFramePanel.NO_MINIMIZE_MAXIMIZE); // tool bar JToolBar chartsToolBar = new JToolBar(); chartsToolBar.add(new JButton(drawChartAction)); // charts panel chartsPanel = new JPanel(); chartsPanel.setLayout(new BoxLayout(chartsPanel, BoxLayout.Y_AXIS)); ItFramePanel variableSelectionPanel = new ItFramePanel(".: Select variables to be tracked", ItFramePanel.NO_MINIMIZE_MAXIMIZE); //variableSelectionPanel.setBackground(new Color(151,151,157)); JSplitPane split = new JSplitPane(); split.setContinuousLayout(true); split.setOrientation(JSplitPane.HORIZONTAL_SPLIT); split.setDividerLocation(2 * screenSize.height / 3); split.setDividerSize(8); //split.setPreferredSize(new Dimension(screenSize.width/4-20, screenSize.height/2 - 50)); //split.setPreferredSize(new Dimension(screenSize.width/4-20, 120)); split.setLeftComponent(new JScrollPane(variablesPlanTree)); split.setRightComponent(new JScrollPane(selectedVariablesPlanTree)); variableSelectionPanel.setContent(split, false); //variableSelectionPanel.setParentSplitPane() //JPanel variableSelectionPanel = new JPanel(new BorderLayout()); //variableSelectionPanel.add(new JScrollPane(variablesPlanTree), BorderLayout.CENTER); //variableSelectionPanel.add(new JScrollPane(selectedVariablesPlanTree), BorderLayout.EAST); ItFramePanel variableGraphPanel = new ItFramePanel(".: Chart", ItFramePanel.NO_MINIMIZE_MAXIMIZE); variableGraphPanel.setContent(chartsPanel, true); JSplitPane mainvariablesplit = new JSplitPane(); mainvariablesplit.setContinuousLayout(true); mainvariablesplit.setOrientation(JSplitPane.VERTICAL_SPLIT); mainvariablesplit.setDividerLocation(150); mainvariablesplit.setDividerSize(8); //mainvariablesplit.setPreferredSize(new Dimension(screenSize.width/4-20, screenSize.height/2 - 50)); mainvariablesplit.setTopComponent(variableSelectionPanel); mainvariablesplit.setBottomComponent(variableGraphPanel); // main charts panel - used to locate the tool bar above the charts panel JPanel mainChartsPanel = new JPanel(new BorderLayout()); mainChartsPanel.add(chartsToolBar, BorderLayout.NORTH); //mainChartsPanel.add(new JScrollPane(chartsPanel), BorderLayout.CENTER); mainChartsPanel.add(mainvariablesplit, BorderLayout.CENTER); //Results planInfoEditorPane = new JEditorPane(); planInfoEditorPane.setContentType("text/html"); planInfoEditorPane.setEditable(false); planInfoEditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR)); planInfoEditorPane.setBackground(Color.WHITE); JPanel resultsPanel = new JPanel(new BorderLayout()); JToolBar resultsToolBar = new JToolBar(); resultsToolBar.setRollover(true); JButton planReportButton = new JButton("View Full Report", new ImageIcon("resources/images/viewreport.png")); planReportButton.setToolTipText("<html>View full plan report.<br> For multiple plans you will need " + "access to the Internet.<br> The components used in the report require such access (no data is " + "sent through the Internet).</html>"); planReportButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Opens html with defaut browser String path = "resources/report/Report.html"; File report = new File(path); path = report.getAbsolutePath(); try { BrowserLauncher launcher = new BrowserLauncher(); launcher.openURLinBrowser("file://" + path); } catch (BrowserLaunchingInitializingException ex) { Logger.getLogger(ItSIMPLE.class.getName()).log(Level.SEVERE, null, ex); appendOutputPanelText("ERROR. Problem while trying to open the default browser. \n"); } catch (UnsupportedOperatingSystemException ex) { Logger.getLogger(ItSIMPLE.class.getName()).log(Level.SEVERE, null, ex); appendOutputPanelText("ERROR. Problem while trying to open the default browser. \n"); } } }); resultsToolBar.add(planReportButton); resultsToolBar.addSeparator(); JButton planReportDataButton = new JButton("Save Report Data", new ImageIcon("resources/images/savePDDL.png")); planReportDataButton.setToolTipText("<html>Save report data to file</html>"); planReportDataButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Save report data if (solveResult != null) { Element lastOpenFolderElement = itSettings.getChild("generalSettings") .getChild("lastOpenFolder"); JFileChooser fc = new JFileChooser(lastOpenFolderElement.getText()); fc.setDialogTitle("Save Report Data"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new XMLFileFilter()); int returnVal = fc.showSaveDialog(ItSIMPLE.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); String path = selectedFile.getPath(); if (!path.toLowerCase().endsWith(".xml")) { path += ".xml"; } //save file (xml) try { FileWriter file = new FileWriter(path); file.write(XMLUtilities.toString(solveResult)); file.close(); } catch (IOException e1) { e1.printStackTrace(); } //Save as a last open folder String folder = selectedFile.getParent(); //Element lastOpenFolderElement = itSettings.getChild("generalSettings").getChild("lastOpenFolder"); lastOpenFolderElement.setText(folder); XMLUtilities.writeToFile("resources/settings/itSettings.xml", itSettings.getDocument()); //Ask if the user wants to save plans individually too. boolean needToSavePlans = false; int option = JOptionPane.showOptionDialog(instance, "<html><center>Do you also want to save the plans" + "<br>in individual files?</center></html>", "Save plans", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); switch (option) { case JOptionPane.YES_OPTION: { needToSavePlans = true; } break; case JOptionPane.NO_OPTION: { needToSavePlans = false; } break; } if (needToSavePlans) { //Close Open tabs List<?> problems = null; try { XPath ppath = new JDOMXPath("project/domains/domain/problems/problem"); problems = ppath.selectNodes(solveResult); } catch (JaxenException e2) { e2.printStackTrace(); } for (int i = 0; i < problems.size(); i++) { Element problem = (Element) problems.get(i); //create a folder for each problem and put all plans inside as xml files String folderName = problem.getChildText("name"); String folderPath = selectedFile.getAbsolutePath() .replace(selectedFile.getName(), folderName); //System.out.println(folderPath); File planfolder = new File(folderPath); boolean canSavePlan = false; try { if (planfolder.mkdir()) { System.out.println("Directory '" + folderPath + "' created."); canSavePlan = true; } else { System.out.println("Directory '" + folderPath + "' was not created."); } } catch (Exception ep) { ep.printStackTrace(); } if (canSavePlan) { Element plans = problem.getChild("plans"); for (Iterator<Element> it = plans.getChildren("xmlPlan").iterator(); it .hasNext();) { Element eaplan = it.next(); Element theplanner = eaplan.getChild("planner"); //save file (xml) String planFileName = "solution" + theplanner.getChildText("name") + "-" + theplanner.getChildText("version") + "-" + Integer.toString(plans.getChildren().indexOf(eaplan)) + ".xml"; String planPath = folderPath + File.separator + planFileName; /* try { FileWriter planfile = new FileWriter(planPath); planfile.write(XMLUtilities.toString(eaplan)); planfile.close(); System.out.println("File '" + planPath + "' created."); } catch (IOException e1) { e1.printStackTrace(); } * */ if (eaplan.getChild("plan").getChildren().size() > 0) { //TODO: save the plan in PDDL too. It should be done through the XPDDL/PDDL classes String pddlplan = ToXPDDL.XMLtoXPDDLPlan(eaplan); String planFileNamePDDL = "solution" + theplanner.getChildText("name") + "-" + theplanner.getChildText("version") + "-" + Integer.toString(plans.getChildren().indexOf(eaplan)) + ".pddl"; String planPathPDDL = folderPath + File.separator + planFileNamePDDL; //String cfolderPath = selectedFile.getAbsolutePath().replace(selectedFile.getName(), ""); //String planFileNamePDDL = theplanner.getChildText("name")+"-"+theplanner.getChildText("version") + "-" + folderName+"-solution.pddl"; //String planPathPDDL = cfolderPath + File.separator + planFileNamePDDL; //if (!theplanner.getChildText("name").contains("MIPS")){ try { FileWriter planfile = new FileWriter(planPathPDDL); planfile.write(pddlplan); planfile.close(); System.out.println("File '" + planPathPDDL + "' created."); } catch (IOException e1) { e1.printStackTrace(); } } //} } } } } } } else { appendOutputPanelText(">> No report data available to save! \n"); } } }); resultsToolBar.add(planReportDataButton); JButton openPlanReportDataButton = new JButton("Open Report Data", new ImageIcon("resources/images/openreport.png")); openPlanReportDataButton.setToolTipText("<html>Open report data to file</html>"); openPlanReportDataButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { planSimStatusBar.setText("Status: Opening File..."); appendOutputPanelText(">> Opening File... \n"); //Open report data Element lastOpenFolderElement = itSettings.getChild("generalSettings") .getChild("lastOpenFolder"); JFileChooser fc = new JFileChooser(lastOpenFolderElement.getText()); fc.setDialogTitle("Open Report Data"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new XMLFileFilter()); int returnVal = fc.showOpenDialog(ItSIMPLE.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // Get itSIMPLE itSettings from itSettings.xml org.jdom.Document resultsDoc = null; try { resultsDoc = XMLUtilities.readFromFile(file.getPath()); solveResult = resultsDoc.getRootElement(); //XMLUtilities.printXML(solveResult); if (solveResult.getName().equals("projects")) { String report = PlanAnalyzer.generatePlannersComparisonReport(solveResult); String comparisonReport = PlanAnalyzer .generateFullPlannersComparisonReport(solveResult); //Save Comparison Report file saveFile("resources/report/Report.html", comparisonReport); setPlanInfoPanelText(report); setPlanEvaluationInfoPanelText(""); appendOutputPanelText(">> Report data read! \n"); //My experiments PlanAnalyzer.myAnalysis(itPlanners.getChild("planners"), solveResult); } } catch (Exception e1) { e1.printStackTrace(); } //Save as a last open folder String folder = fc.getSelectedFile().getParent(); lastOpenFolderElement.setText(folder); XMLUtilities.writeToFile("resources/settings/itSettings.xml", itSettings.getDocument()); } else { planSimStatusBar.setText("Status:"); appendOutputPanelText(">> Canceled \n"); } } }); resultsToolBar.add(openPlanReportDataButton); JButton compareProjectReportDataButton = new JButton("Compare Project Data", new ImageIcon("resources/images/compare.png")); compareProjectReportDataButton.setToolTipText( "<html>Compare different project report data <br> This is commonly use to compare diferent domain models with different adjustments.<br>" + "One project data must be chosen as a reference; others will be compared to this referencial one.</html>"); compareProjectReportDataButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { final ProjectComparisonDialog dialog = new ProjectComparisonDialog(); dialog.setVisible(true); final List<String> files = dialog.getFiles(); if (files.size() > 1) { new Thread() { public void run() { appendOutputPanelText(">> Project comparison report requested. Processing... \n"); planSimStatusBar.setText("Status: Reading files ..."); appendOutputPanelText(">> Reading files ... \n"); //base project file String baseFileName = files.get(0); appendOutputPanelText(">> Reading file '" + baseFileName + "' \n"); org.jdom.Document baseProjectDoc = null; try { baseProjectDoc = XMLUtilities.readFromFile(baseFileName); } catch (Exception ec) { ec.printStackTrace(); } Element baseProject = null; if (baseProjectDoc != null) { baseProject = baseProjectDoc.getRootElement().getChild("project"); } //The comparible projects List<Element> comparableProjects = new ArrayList<Element>(); for (int i = 1; i < files.size(); i++) { String eafile = files.get(i); appendOutputPanelText(">> Reading file '" + eafile + "' \n"); org.jdom.Document eaProjectDoc = null; try { eaProjectDoc = XMLUtilities.readFromFile(eafile); } catch (Exception ec) { ec.printStackTrace(); } if (eaProjectDoc != null) { comparableProjects.add(eaProjectDoc.getRootElement().getChild("project")); } } appendOutputPanelText(">> Files read. Building report... \n"); String comparisonReport = PlanAnalyzer.generateProjectComparisonReport(baseProject, comparableProjects); saveFile("resources/report/Report.html", comparisonReport); appendOutputPanelText( ">> Project comparison report generated. Press 'View Full Report'\n"); appendOutputPanelText(" \n"); } }.start(); } } }); resultsToolBar.add(compareProjectReportDataButton); resultsPanel.add(resultsToolBar, BorderLayout.NORTH); resultsPanel.add(new JScrollPane(planInfoEditorPane), BorderLayout.CENTER); JTabbedPane planAnalysisTabbedPane = new JTabbedPane(); planAnalysisTabbedPane.addTab("Results", resultsPanel); planAnalysisTabbedPane.addTab("Variable Tracking", mainChartsPanel); planAnalysisTabbedPane.addTab("Movie Maker", getMovieMakerPanel()); planAnalysisTabbedPane.addTab("Plan Evaluation", getPlanEvaluationPanel()); planAnalysisTabbedPane.addTab("Plan Database", getPlanDatabasePanel()); planAnalysisTabbedPane.addTab("Rationale Database", getRationaleDatabasePanel()); JPanel planAnalysisPanel = new JPanel(new BorderLayout()); //planAnalysisPanel.add(chartsToolBar, BorderLayout.NORTH); planAnalysisPanel.add(planAnalysisTabbedPane, BorderLayout.CENTER); planAnalysisFramePanel.setContent(planAnalysisPanel, false); } return planAnalysisFramePanel; }
From source file:nl.fontys.sofa.limo.view.project.actions.ExportChainAction.java
private void openFileChooser() throws HeadlessException, IOException { JFileChooser fc = new ChainSaveFileChooser(); FileNameExtensionFilter chainFilter = new FileNameExtensionFilter("Supply chains (*.lsc)", "lsc"); if (supplyChain.getFilepath() != null) { //This happens if a supply chain is loaded. fc.setCurrentDirectory(new File(supplyChain.getFilepath())); }/*from w ww .j a v a2s. co m*/ fc.setFileFilter(chainFilter); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setSelectedFile(new File(FilenameUtils.removeExtension(supplyChain.getName()))); // This sets the name without the extension int result = fc.showOpenDialog(null); String fileName = fc.getSelectedFile().getName(); //name with extension if (result == JFileChooser.APPROVE_OPTION) { //If folder is selected than save the supply chain. supplyChain.setName(fileName); File file = fc.getSelectedFile(); supplyChain.saveToFile(file.getAbsolutePath() + ".lsc"); } else { //If no folder is selected throw an exception so the saving process is cancelled. throw new IOException("The supply chain " + supplyChain.getName() + " is invalid."); } }
From source file:nl.tudelft.goal.SimpleIDE.FilePanel.java
/** * Renames a file to a new name. THe new name will be asked from the user. * If the selected target file exists we overwrite the existing file with * the given (after user's confirmation). * * @param oldFile/*from ww w. j a v a 2 s . c o m*/ * is the file to be renamed. * @throws GOALException * @throws ParserException */ public void rename(File oldFile) throws GOALException, ParserException, InvalidEmotionConfigFile, FileNotFoundException { // step 1. ask new filename. // use the general getExtension to support unknown extensions properly. String extension = FilenameUtils.getExtension(oldFile.getName()); String oldfilename = FilenameUtils.removeExtension(oldFile.getAbsolutePath()); File newFile = null; try { newFile = SimpleIDE.askFile(this.mainpanel, false, "Save as", //$NON-NLS-1$ JFileChooser.FILES_ONLY, extension, oldfilename, PMPreferences.getAgentBrowsePath(), true); } catch (GOALCommandCancelledException ignore) { return; } if (PMPreferences.getRememberLastUsedAgentDir()) { PMPreferences.setAgentBrowsePath(newFile.getParent()); } Extension ext = Extension.getFileExtension(newFile); // step 1b. disallow renaming to an existing project present in the IDE if (ext == Extension.MAS && containsFile(newFile)) { throw new GOALUserError("Cannot rename a MAS project to " //$NON-NLS-1$ + "another MAS project present in the IDE."); //$NON-NLS-1$ } // this is a bit tricky, as we should try to keep this functionality // separate // from the editor panel functionality... // step 2. close editor(s) boolean isEditingOldFile = EditManager.getInstance().isOpenEditor(oldFile); // mainPanel.getEditPanel().saveAs(newFile.getAbsolutePath()); // edit panel close old editor and open new one. if (isEditingOldFile) { EditManager.getInstance().close(oldFile); } boolean isEditingNewFile = EditManager.getInstance().isOpenEditor(newFile); // mainPanel.getEditPanel().saveAs(newFile.getAbsolutePath()); // edit panel close old editor and open new one. if (isEditingNewFile) { EditManager.getInstance().close(newFile); } // step 3. make copy try { FileInputStream input = new FileInputStream(oldFile); FileOutputStream output = new FileOutputStream(newFile); IOUtils.copy(input, output); input.close(); output.close(); } catch (IOException e) { throw new GOALUserError("Cannot copy " + oldFile + " to " + newFile, e); //$NON-NLS-1$ //$NON-NLS-2$ } // step 4. reload some stuff // HACK, #1061 switch (ext) { case GOAL: KRInterface language = this.platform.getAgentProgram(oldFile).getKRInterface(); this.platform.parseGOALFile(newFile, language); this.platform.removeParsedProgram(oldFile); break; case MAS: // add new file, remove old file this.platform.parseMASFile(newFile); this.platform.removeParsedProgram(oldFile); break; default: // other files are not parsed break; } // step 5. fix file panel. boolean oldFileInUse = !handleFileRename(oldFile, newFile); // step 6. refresh nodes, but only if any of the nodes reference the // new file if (containsFile(newFile)) { if (ext == Extension.MAS) { // refresh the MAS file node. placed here since it is // not part of the #1061 hack refreshMASFile(newFile); } else if (ext == Extension.GOAL) { refreshGOALFile(newFile); } } // step 7. restore editing configuration if possible. if (isEditingOldFile && oldFileInUse) { EditManager.getInstance().editFile(oldFile); } if (isEditingOldFile || isEditingNewFile) { EditManager.getInstance().editFile(newFile); } // step 8. delete old file if not used anymore. if (!oldFileInUse) { try { oldFile.delete(); } catch (SecurityException e) { new Warning(Resources.get(WarningStrings.FAILED_REMOVE_AFTER_RENAME), e); } } }
From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataConfiguratorPresenter.java
private boolean chooseDirectory(String initialDirectory, String title) { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); boolean result = chooseFile(initialDirectory, title, true); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); return result; }
From source file:org.apache.cayenne.modeler.action.ImportDataMapAction.java
protected File selectDataMap(Frame f) { // find start directory in preferences FSPath lastDir = getApplication().getFrameController().getLastDirectory(); // configure dialog JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); lastDir.updateChooser(chooser);//from ww w .j a v a 2 s . c o m chooser.addChoosableFileFilter(FileFilters.getDataMapFilter()); int status = chooser.showDialog(f, "Select DataMap"); if (status == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); // save to preferences... lastDir.updateFromChooser(chooser); return file; } return null; }
From source file:org.apache.cayenne.modeler.action.ProjectOpener.java
/** * Runs a dialog to open Cayenne project. *//* w ww . java2s .c om*/ File openProjectFile(Frame f) { // configure dialog setDialogTitle("Select Project File"); setFileSelectionMode(JFileChooser.FILES_ONLY); setCurrentDirectory(getDefaultStartDir()); // configure filters resetChoosableFileFilters(); addChoosableFileFilter(FileFilters.getApplicationFilter()); // default to App projects setFileFilter(FileFilters.getApplicationFilter()); int status = showOpenDialog(f); if (status != JFileChooser.APPROVE_OPTION) { return null; } return getSelectedFile(); }
From source file:org.apache.cayenne.modeler.dialog.pref.ClasspathPreferences.java
protected void addJarOrZipAction() { chooseClassEntry(FileFilters.getClassArchiveFilter(), "Select JAR or ZIP File.", JFileChooser.FILES_ONLY); }
From source file:org.apache.cayenne.modeler.graph.action.SaveAsImageAction.java
@Override public void performAction(ActionEvent e) { // find start directory in preferences FSPath lastDir = getApplication().getFrameController().getLastDirectory(); // configure dialog JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); lastDir.updateChooser(chooser);// w w w. ja v a 2 s. co m chooser.setAcceptAllFileFilterUsed(false); String ext = "png"; chooser.addChoosableFileFilter(FileFilters.getExtensionFileFilter(ext, "PNG Images")); int status = chooser.showSaveDialog(Application.getFrame()); if (status == JFileChooser.APPROVE_OPTION) { lastDir.updateFromChooser(chooser); String path = chooser.getSelectedFile().getPath(); if (!path.endsWith("." + ext)) { path += "." + ext; } try { JGraph graph = dataDomainGraphTab.getGraph(); BufferedImage img = graph.getImage(null, 0); try (OutputStream out = new FileOutputStream(path);) { ImageIO.write(img, ext, out); out.flush(); } } catch (IOException ex) { logObj.error("Could not save image", ex); JOptionPane.showMessageDialog(Application.getFrame(), "Could not save image.", "Error saving image", JOptionPane.ERROR_MESSAGE); } } }