/** * Opens a file chooser and gives the user an opportunity to save the chart in PNG format. * * @throws IOException * if there is an I/O error. */ @Override public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs); ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"), ".png"); fileChooser.addChoosableFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight()); } }
/** * Opens a file chooser and gives the user an opportunity to save the chart * in PNG format. * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"), ".png"); fileChooser.addChoosableFileFilter(filter); fileChooser.addChoosableFileFilter(new ExtensionFileFilter("All files", "")); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight()); } }
/** * Opens a file chooser and gives the user an opportunity to save the chart * in PNG format. * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); ExtensionFileFilter filter = new ExtensionFileFilter( localizationResources.getString("PNG_Image_Files"), ".png"); fileChooser.addChoosableFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight()); } }
/** * Opens a file chooser and gives the user an opportunity to save the chart * in PNG format. * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs); ExtensionFileFilter filter = new ExtensionFileFilter( localizationResources.getString("PNG_Image_Files"), ".png"); fileChooser.addChoosableFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight()); } }
private void save() throws IOException { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(super.defaultDirectoryForSaveAs); ExtensionFileFilter filter = new ExtensionFileFilter("BED Binary Files", ".bed"); fileChooser.addChoosableFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".bed")) { filename = filename + ".bed"; } } try { BEDFileWriter bfw = new BEDFileWriter(new File(filename)); } catch (IOException ex) { throw new IOException("Could not write file."); } } }
private void save(String collection, String filename) throws FileNotFoundException, IOException { JFileChooser fileChooser = new JFileChooser(); ExtensionFileFilter filter = new ExtensionFileFilter("BED Binary Files", ".bed"); fileChooser.addChoosableFileFilter(filter); if (filename == null){ int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { filename = fileChooser.getSelectedFile().getAbsolutePath(); }else{ return; } } //TP CHANGED THIS BEDFileChanger bfc = new BEDFileChanger(db.getMarkerData().collectionIndices.get(collection), collection, db.getDisplayName(), db.samplesByCollection.get(collection).inds, db.getMarkerData().snpsPerCollection.get(collection), db.getMarkerData().getMarkerTable(), db.changesByCollection.get(collection), filename, db, saveBedBimFamFiles); }
/** * Creates the file chooser. * * @return the initialized file chooser. */ protected JFileChooser createFileChooser() { final JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter( new ExtensionFileFilter(getFileDescription(), getFileExtension()) ); fc.setMultiSelectionEnabled(false); fc.setCurrentDirectory(getCurrentDirectory()); return fc; }
/** * Método de inicializacao */ private void initialize() { setSize(430, 245); initComponents(); gFFBackup.getFileChooser().setFileFilter(new ExtensionFileFilter("Backup Yap", "byap")); gFFRestore.getFileChooser().setFileFilter(new ExtensionFileFilter("Backup Yap", "byap")); }
@Override public final void doSaveAs() throws IOException { String directory = gui.getPreferences().get("lastSaveDirectory", "./"); String filename = validateSaveFileName(null); File chartFile = new File(directory, filename); GUIFileChooser fileChooser = new GUIFileChooser(gui, "Select Save Location"); fileChooser.setSelectedFile(chartFile); ExtensionFileFilter filter = new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"), ".png"); fileChooser.addChoosableFileFilter(filter); if (fileChooser.showDialog(this, "Save") == JFileChooser.APPROVE_OPTION) { chartFile = fileChooser.getSelectedFile(); if (isEnforceFileExtensions()) { if (!chartFile.getName().endsWith(".png")) { chartFile = new File(chartFile.getAbsolutePath() + ".png"); } } if (chartFile.exists()) { int result = JOptionPane.showConfirmDialog(gui.getMainFrame(), "File '" + chartFile.getName() + "' already exists.\nDo you want to overwrite it?", "Overwrite?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) { return; } } ChartUtilities.saveChartAsPNG(chartFile, getChart(), saveWidth, saveHeight); } // save the last directory whether or not the file is actually saved gui.getPreferences().put("lastSaveDirectory", chartFile.getParentFile().getAbsolutePath()); }
private void createChartPrintPostScriptJob() { // Use the pre-defined flavor for a Printable from an InputStream DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; // Specify the type of the output stream String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType(); // Locate factory which can export a GIF image stream as Postscript StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories( flavor, psMimeType); if (factories.length == 0) { System.err.println("No suitable factories"); System.exit(0); // FIXME too } // Obtain file name from user JFileChooser fileChooser = new JFileChooser(); ExtensionFileFilter filter = new ExtensionFileFilter( localizationResources.getString("PostScript_Files"), ".eps"); fileChooser.addChoosableFileFilter(filter); String filename=""; int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".eps")) { filename = filename + ".eps"; } } else return; } try { // Create a file for the exported postscript FileOutputStream fos = new FileOutputStream(filename); // Create a Stream printer for Postscript StreamPrintService sps = factories[0].getPrintService(fos); // Create and call a Print Job DocPrintJob pj = sps.createPrintJob(); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); Doc doc = new SimpleDoc(this, flavor, null); pj.print(doc, aset); fos.close(); } catch (PrintException pe) { System.err.println(pe); } catch (IOException ie) { System.err.println(ie); } }
/** * Prints the chart on a single page. * * @param g the graphics context. * @param pf the page format to use. * @param pageIndex the index of the page. If not <code>0</code>, nothing * gets print. * * @return The result of printing. */ public int print(Graphics g, PageFormat pf, int pageIndex) { if (pageIndex != 0) { return NO_SUCH_PAGE; } /** this works but the curve is made of little pieces */ Graphics2D g2 = (Graphics2D) g; double x = pf.getImageableX(); double y = pf.getImageableY(); double w = pf.getImageableWidth(); double h = pf.getImageableHeight(); this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null); if (printToPrinter) return PAGE_EXISTS; // The rest should be moved up to the export eps action listener so it's not done per page' // Show export dialog JFileChooser fileChooser = new JFileChooser(); ExtensionFileFilter filter = new ExtensionFileFilter( localizationResources.getString("PostScript_Files"), ".eps"); fileChooser.addChoosableFileFilter(filter); String filename=""; int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".eps") || !filename.endsWith(".ps")) { filename = filename + ".eps"; } } else return NO_SUCH_PAGE; } try { OutputStream out = new java.io.FileOutputStream(new File(filename)); out = new java.io.BufferedOutputStream(out); //Instantiate the EPSDocumentGraphics2D instance EPSDocumentGraphics2D g2dps = new EPSDocumentGraphics2D(false); g2dps.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); //Set up the document size g2dps.setupDocument(out, (int)w, (int)h+200); //Paint a bounding box g2dps.drawRect((int)x, (int)y, (int)w, (int)h); this.chart.draw(g2dps, new Rectangle2D.Double(x, y, w, h), this.anchor, null); //A few rectangles rotated and with different color //Cleanup g2dps.finish(); out.flush(); out.close(); } catch(java.io.IOException e){ return NO_SUCH_PAGE; } return PAGE_EXISTS; }
@Override public void actionPerformed(ActionEvent e) { File projectPath = frame.getPath(); if (projectPath == null) { JOptionPane.showMessageDialog(frame, "Can not open graph before project has been opened."); return; } final File networkPath = new File(projectPath + File.separator + ProjectConstants.networkDirName); JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Select a graphml file to load into your project"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setFileFilter(new ExtensionFileFilter("Graphml File chooser", "graphml")); chooser.setMultiSelectionEnabled(false); int result = chooser.showOpenDialog(frame); if (result == JFileChooser.APPROVE_OPTION) { File fileResult = chooser.getSelectedFile(); if(fileResult.exists()){ System.out.println(fileResult); File version = autolabel(projectPath.getAbsolutePath()); File graphmlDir = new File(version, ProjectConstants.undirectedGraphmlDirName); graphmlDir.mkdir(); try { File outputFile = new File(graphmlDir, ProjectConstants.networkGraphmlFileName); FileCopyUtils.copy(fileResult,outputFile); JOptionPane.showMessageDialog(frame, "Graph file successfully imported in "+ version.getName() + " of your current project!"); frame.doOpenGraph(outputFile); } catch (IOException e1) { e1.printStackTrace(); } } } }