List of usage examples for javax.swing JFileChooser addChoosableFileFilter
@BeanProperty(preferred = true, description = "Adds a filter to the list of user choosable file filters.") public void addChoosableFileFilter(FileFilter filter)
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Opens a file chooser and gives the user an opportunity to save the chart in PNG format. * /* ww w . j av a2 s.c o m*/ * @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()); } }
From source file:com.att.aro.diagnostics.GraphPanel.java
/** * Implements the saving of the graph snapshot. *//*from w ww .j a v a 2 s. co m*/ private void saveAs() throws IOException { // Determine save directory File saveDir = traceData.getTraceDir(); if (graphPanelSaveDirectory != null) { saveDir = new File(graphPanelSaveDirectory); } JFileChooser fc = new JFileChooser(saveDir); // Set up file types String[] fileTypesJPG = new String[2]; String fileDisplayTypeJPG = rb.getString("fileChooser.contentDisplayType.jpeg"); fileTypesJPG[0] = rb.getString("fileChooser.contentType.jpeg"); fileTypesJPG[1] = rb.getString("fileChooser.contentType.jpg"); FileFilter filterJPG = new ExtensionFileFilter(fileDisplayTypeJPG, fileTypesJPG); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); String[] fileTypesPng = new String[1]; String fileDisplayTypePng = rb.getString("fileChooser.contentDisplayType.png"); fileTypesPng[0] = rb.getString("fileChooser.contentType.png"); FileFilter filterPng = new ExtensionFileFilter(fileDisplayTypePng, fileTypesPng); fc.addChoosableFileFilter(filterPng); fc.setFileFilter(filterJPG); File plotImageFile = null; boolean bSavedOrCancelled = false; while (!bSavedOrCancelled) { if (fc.showSaveDialog(this.getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) { String strFile = fc.getSelectedFile().toString(); String strFileLowerCase = strFile.toLowerCase(); String fileDesc = fc.getFileFilter().getDescription(); String fileType = rb.getString("fileChooser.contentType.jpg"); if ((fileDesc.equalsIgnoreCase(rb.getString("fileChooser.contentDisplayType.png")) || strFileLowerCase .endsWith(rb.getString("fileType.filters.dot") + fileTypesPng[0].toLowerCase()))) { fileType = fileTypesPng[0]; } if (strFile.length() > 0) { // Save current directory graphPanelSaveDirectory = fc.getCurrentDirectory().getPath(); if ((fileType != null) && (fileType.length() > 0)) { String fileTypeLowerCaseWithDot = rb.getString("fileType.filters.dot") + fileType.toLowerCase(); if (!strFileLowerCase.endsWith(fileTypeLowerCaseWithDot)) { strFile += rb.getString("fileType.filters.dot") + fileType; } } plotImageFile = new File(strFile); boolean bAttemptToWriteToFile = true; if (plotImageFile.exists()) { if (MessageDialogFactory.showConfirmDialog(this, MessageFormat.format(rb.getString("fileChooser.fileExists"), plotImageFile.getAbsolutePath()), rb.getString("fileChooser.confirm"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { bAttemptToWriteToFile = false; } } if (bAttemptToWriteToFile) { try { if (fileType.equalsIgnoreCase(fileTypesPng[0])) { BufferedImage bufImage = createImage(pane); ImageIO.write(bufImage, "png", plotImageFile); } else { BufferedImage bufImage = createImage(pane); ImageIO.write(bufImage, "jpg", plotImageFile); } bSavedOrCancelled = true; } catch (IOException e) { MessageDialogFactory.showMessageDialog(this, rb.getString("fileChooser.errorWritingToFile" + plotImageFile.toString())); } } } } else { bSavedOrCancelled = true; } } }
From source file:Form.Principal.java
private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked // TODO add your handling code here: if (editando == false) { File Ruta = new File("Imagenes/Fotos Perfil/"); JFileChooser Examinar = new JFileChooser(); FileNameExtensionFilter Filtro = new FileNameExtensionFilter("Image", "png", "jpg"); Examinar.addChoosableFileFilter(Filtro); Examinar.setAcceptAllFileFilterUsed(false); Examinar.setFileFilter(Filtro);/*from w w w .j av a 2 s . c om*/ int Estatus = Examinar.showOpenDialog(this); if (Estatus == JFileChooser.APPROVE_OPTION) { File Origen = Examinar.getSelectedFile(); String Extension = FilenameUtils.getExtension(Origen.getPath()); File Copia = new File(Variables.getIdUsuario() + "." + Extension); try { FileUtils.copyFile(Origen, Copia); FileUtils.copyFileToDirectory(Copia, Ruta); if (Extension.equals("png")) { File jpg = new File("Imagenes/Fotos Perfil/" + Variables.idUsuario + ".jpg"); if (jpg.exists()) { jpg.delete(); } } if (Extension.equals("jpg")) { File png = new File("Imagenes/Fotos Perfil/" + Variables.idUsuario + ".png"); if (png.exists()) { png.delete(); } } Copia.delete(); } catch (IOException e) { e.printStackTrace(); } } else if (Estatus == JFileChooser.CANCEL_OPTION) { System.out.println("Cancelar"); } PerfilUsuario(Variables.idUsuario); } }
From source file:course_generator.frmMain.java
/** * Display a dialog box to open a GPX file *///from w w w. ja va 2s . c o m private void OpenGPXDialog() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter gpxFilter = new FileTypeFilter(".gpx", "GPX file"); fileChooser.addChoosableFileFilter(gpxFilter); fileChooser.setFileFilter(gpxFilter); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); LoadGPX(selectedFile.getAbsolutePath()); } }
From source file:course_generator.frmMain.java
/** * Display a dialog box to open a CGX file *///from ww w .j a va 2s . c o m private void OpenCGXDialog() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter cgxFilter = new FileTypeFilter(".cgx", "CGX file"); fileChooser.addChoosableFileFilter(cgxFilter); fileChooser.setFileFilter(cgxFilter); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); LoadCGX(selectedFile.getAbsolutePath()); } }
From source file:in.gov.uidai.auth.sampleapp.SampleClientMainFrame.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed String biometricPosition = (String) jComboBiometricPosition.getSelectedItem(); if (biometricPosition.equals("Select") || biometricPosition.startsWith("-")) { JOptionPane.showMessageDialog(this, "Please select biometric position before capturing biometrics.", "UID Authentication Demo Client", JOptionPane.ERROR_MESSAGE); return;// ww w . j av a2s. c o m } JFileChooser fc = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("Biometric Image Record (.fmr or .fir or .iir)", "fmr", "fir", "iir"); fc.addChoosableFileFilter(filter); int returnVal = fc.showOpenDialog(this.jPanel1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); System.out.println(file.getAbsolutePath()); try { String fileName = file.getAbsolutePath(); File f = new File(fileName); String fileExtension = fileName.substring(fileName.length() - 3, fileName.length()); CaptureDetails c = new CaptureDetails(null, FileUtils.readFileToByteArray(f), 1); this.addToCaptures(BiometricPosition.valueOf(biometricPosition), BioMetricType.valueOf(fileExtension.toUpperCase()), c); jLabelBiometricFile.setText(bioCaptures.toString()); } catch (IOException ex) { Logger.getLogger(SampleClientMainFrame.class.getName()).log(Level.SEVERE, null, ex); jLabelBiometricFile.setText("ERROR: unable to read the specified file!!"); } } }
From source file:org.nuclos.client.ui.collect.Chart.java
private void actionCommandSave() { try {/* ww w .j a va 2 s.c o m*/ JFileChooser fileChooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter( SpringLocaleDelegate.getInstance().getMessage("filenameextensionfilter.1", "Bildformate") + " (*.svg, *.png, *.jpg, *.jpeg)", "svg", "png", "jpg", "jpeg"); // @todo i18n fileChooser.addChoosableFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (fileChooser.getSelectedFile().getName().lastIndexOf(".") == -1) { filename = filename + ".png"; } if (filename.toLowerCase().endsWith(".png")) ChartUtilities.saveChartAsPNG(new File(filename), getChartPanel().getChart(), getChartPanel().getWidth(), getChartPanel().getHeight()); else if (filename.toLowerCase().endsWith(".jpg") || filename.toLowerCase().endsWith(".jpeg")) ChartUtilities.saveChartAsJPEG(new File(filename), getChartPanel().getChart(), getChartPanel().getWidth(), getChartPanel().getHeight()); else if (filename.toLowerCase().endsWith(".svg")) { // Get a DOMImplementation and create an XML document DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); Document document = domImpl.createDocument(null, "svg", null); // Create an instance of the SVG Generator SVGGraphics2D svgGenerator = new SVGGraphics2D(document); // draw the chart in the SVG generator JFreeChart chart = getChartPanel().getChart(); chart.draw(svgGenerator, getChartPanel().getBounds()); // Write svg file OutputStream outputStream = new FileOutputStream(filename); Writer out = new OutputStreamWriter(outputStream, "UTF-8"); svgGenerator.stream(out, true /* use css */); outputStream.flush(); outputStream.close(); } } } catch (Exception e) { throw new NuclosFatalException(e.getMessage()); } }
From source file:org.fhaes.jsea.JSEAFrame.java
/** * Initialize the menu/toolbar actions.//w w w. j av a2 s . co m */ private void initActions() { final JFrame glue = this; actionFileExit = new FHAESAction("Close", "close.png") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { dispose(); } }; actionChartProperties = new FHAESAction("Chart properties", "properties.png") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { ChartEditor editor = ChartEditorManager .getChartEditor(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart()); int result = JOptionPane.showConfirmDialog(glue, editor, "Properties", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { editor.updateChart(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart()); } } }; actionReset = new FHAESAction("Reset", "filenew.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { Object[] options = { "Yes", "No", "Cancel" }; int n = JOptionPane.showOptionDialog(glue, "Are you sure you want to start a new analysis?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setToDefault(); } } }; actionRun = new FHAESAction("Run analysis", "run.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { runAnalysis(); } }; actionSaveAll = new FHAESAction("Save all results", "save_all.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } File f; try { f = new File(file.getAbsolutePath() + File.separator + "report.txt"); saveReportTXT(f); f = new File(file.getAbsolutePath() + File.separator + "report.pdf"); saveReportPDF(f); f = new File(file.getAbsolutePath() + File.separator + "chart.png"); saveChartPNG(f); f = new File(file.getAbsolutePath() + File.separator + "chart.pdf"); saveChartPDF(f); f = new File(file.getAbsolutePath() + File.separator + "data.xls"); saveDataXLS(f); f = new File(file.getAbsolutePath()); saveDataCSV(f); } catch (IOException e) { e.printStackTrace(); } } }; actionSaveData = new FHAESAction("Save data tables", "table.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } try { saveDataCSV(file); } catch (IOException e) { e.printStackTrace(); } } }; actionSaveReport = new FHAESAction("Save report", "report.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } // Set file filters fc.setAcceptAllFileFilterUsed(false); TXTFileFilter txtfilter = new TXTFileFilter(); PDFFilter pdffilter = new PDFFilter(); fc.addChoosableFileFilter(txtfilter); fc.addChoosableFileFilter(pdffilter); fc.setFileFilter(txtfilter); FileFilter chosenFilter; // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); chosenFilter = fc.getFileFilter(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } // Handle file type and extensions nicely if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) { if (chosenFilter.equals(txtfilter)) { file = new File(file.getAbsoluteFile() + ".txt"); } else if (chosenFilter.equals(pdffilter)) { file = new File(file.getAbsoluteFile() + ".pdf"); } } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("txt") && chosenFilter.equals("pdf")) { chosenFilter = txtfilter; } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf") && chosenFilter.equals("txt")) { chosenFilter = pdffilter; } // If file already exists confirm overwrite if (file.exists()) { // Check we have write access to this file if (!file.canWrite()) { JOptionPane.showMessageDialog(glue, "You do not have write permission to this file", "Error", JOptionPane.ERROR_MESSAGE); return; } int n = JOptionPane.showConfirmDialog(glue, "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?", "Overwrite file?", JOptionPane.YES_NO_OPTION); if (n != JOptionPane.YES_OPTION) { return; } } // Do save try { if (chosenFilter.equals(txtfilter)) { saveReportTXT(file); } else if (chosenFilter.equals(pdffilter)) { saveReportPDF(file); } else { log.error("No export file format chosen. Shouldn't be able to get here!"); } } catch (IOException e) { JOptionPane.showMessageDialog(glue, "Unable to save report. Check log file.", "Warning", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }; actionSaveChart = new FHAESAction("Save chart", "barchart.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } // Set file filters fc.setAcceptAllFileFilterUsed(false); PNGFilter pngfilter = new PNGFilter(); PDFFilter pdffilter = new PDFFilter(); fc.addChoosableFileFilter(pngfilter); fc.addChoosableFileFilter(pdffilter); fc.setFileFilter(pngfilter); FileFilter chosenFilter; // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); chosenFilter = fc.getFileFilter(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } // Handle file type and extensions nicely if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) { if (chosenFilter.equals(pngfilter)) { file = new File(file.getAbsoluteFile() + ".png"); } else if (chosenFilter.equals(pdffilter)) { file = new File(file.getAbsoluteFile() + ".pdf"); } } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("png") && chosenFilter.equals("pdf")) { chosenFilter = pngfilter; } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf") && chosenFilter.equals("png")) { chosenFilter = pdffilter; } // If file already exists confirm overwrite if (file.exists()) { // Check we have write access to this file if (!file.canWrite()) { JOptionPane.showMessageDialog(glue, "You do not have write permission to this file", "Error", JOptionPane.ERROR_MESSAGE); return; } int n = JOptionPane.showConfirmDialog(glue, "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?", "Overwrite file?", JOptionPane.YES_NO_OPTION); if (n != JOptionPane.YES_OPTION) { return; } } // Do save try { if (chosenFilter.equals(pngfilter)) { saveChartPNG(file); } else if (chosenFilter.equals(pdffilter)) { saveChartPDF(file); } else { log.error("No export file format chosen. Shouldn't be able to get here!"); } } catch (IOException e) { JOptionPane.showMessageDialog(glue, "Unable to save chart. Check log file.", "Warning", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }; actionCopy = new FHAESAction("Copy", "edit_copy.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { copyCurrentSelectionToClipboard(); } }; actionLagMap = new FHAESAction("LagMap", "lagmap22.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { launchLagMap(); } }; }
From source file:lu.fisch.unimozer.Diagram.java
public void exportPNG() { selectClass(null);//from www. ja v a 2s . com JFileChooser dlgSave = new JFileChooser("Export diagram as PNG ..."); // propose name String uniName = directoryName.substring(directoryName.lastIndexOf('/') + 1).trim(); dlgSave.setSelectedFile(new File(uniName)); dlgSave.addChoosableFileFilter(new PNGFilter()); int result = dlgSave.showSaveDialog(frame); if (result == JFileChooser.APPROVE_OPTION) { String filename = dlgSave.getSelectedFile().getAbsoluteFile().toString(); if (!filename.substring(filename.length() - 4, filename.length()).toLowerCase().equals(".png")) { filename += ".png"; } File file = new File(filename); BufferedImage bi = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); paint(bi.getGraphics()); try { ImageIO.write(bi, "png", file); } catch (Exception e) { JOptionPane.showOptionDialog(frame, "Error while saving the image!", "Error", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null); } } }
From source file:base.BasePlayer.Main.java
public void actionPerformed(ActionEvent e) { //Logo.frame.setVisible(false); if (e.getSource() == pleiadesButton) { gotoURL("http://kaptah.local.lab.helsinki.fi/pleiades/"); } else if (e.getSource() == manage) { if (VariantHandler.frame == null) { VariantHandler.main(argsit); }//ww w . j a va 2 s . co m VariantHandler.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantHandler.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); VariantHandler.frame.setState(JFrame.NORMAL); VariantHandler.frame.setVisible(true); Draw.calculateVars = true; Draw.updatevars = true; drawCanvas.repaint(); } else if (e.getSource() == tbrowser) { tablebrowser.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); tablebrowser.frame.setState(JFrame.NORMAL); tablebrowser.frame.setVisible(true); } else if (e.getSource() == bconvert) { bedconverter.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); bedconverter.frame.setState(JFrame.NORMAL); bedconverter.frame.setVisible(true); } else if (e.getSource() == peakCaller) { if (PeakCaller.frame == null) { PeakCaller.main(argsit); } PeakCaller.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); PeakCaller.frame.setState(JFrame.NORMAL); PeakCaller.frame.setVisible(true); } else if (e.getSource() == variantCaller) { //FileRead.checkSamples(); if (VariantCaller.frame == null) { VariantCaller.main(argsit); } VariantCaller.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); VariantCaller.frame.setState(JFrame.NORMAL); VariantCaller.frame.setVisible(true); } else if (e.getSource() == average) { if (Average.frame == null) { Average.createAndShowGUI(); } Average.setSamples(); Average.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - Average.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); Average.frame.setState(JFrame.NORMAL); Average.frame.setVisible(true); } else if (e.getSource() == errorlog) { ErrorLog.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - ErrorLog.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); // VariantHandler.frame.setAlwaysOnTop(true); ErrorLog.frame.setState(JFrame.NORMAL); ErrorLog.frame.setVisible(true); } /* else if(e.getSource() == help) { JOptionPane.showMessageDialog(Main.chromDraw, "This is pre-release version of BasePlayer\nContact: help@baseplayer.fi\nUniversity of Helsinki", "Help", JOptionPane.INFORMATION_MESSAGE); }*/ else if (e.getSource() == settings) { Settings.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - Settings.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); Settings.frame.setState(JFrame.NORMAL); Settings.frame.setVisible(true); } else if (e.getSource() == update) { try { Updater update = new Updater(); update.execute(); } catch (Exception ex) { ex.printStackTrace(); } } else if (e.getSource() == clearMemory) { FileRead.nullifyVarNodes(); //FileRead.removeNonListVariants();f System.gc(); chromDraw.repaint(); } else if (e.getSource() == zoomout) { zoomout(); } else if (e.getSource() == dosomething) { BedNode currentbed = bedCanvas.bedTrack.get(0).getHead().getNext(); VarNode currentvar = FileRead.head.getNext(); while (currentbed != null) { while (currentvar != null && currentvar.getPosition() < currentbed.getPosition()) { currentvar = currentvar.getNext(); } while (currentbed != null && currentvar.getPosition() > currentbed.getPosition() + currentbed.getLength()) { currentbed = currentbed.getNext(); } if (currentvar != null && currentvar.getPosition() >= currentbed.getPosition() && currentvar.getPosition() < currentbed.getPosition() + currentbed.getLength()) { currentvar.setBedhit(true); currentvar = currentvar.getNext(); } if (currentvar == null) { break; } currentbed = currentbed.getNext(); } } else if (e.getSource() == clear) { clearData(); } else if (e.getSource() == exit) { System.exit(0); } else if (e.getSource() == openbams) { try { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } FileDialog fc = new FileDialog(frame, "Choose BAM file(s)", FileDialog.LOAD); fc.setDirectory(path); fc.setFile("*.bam;*.cram;*.link"); fc.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".bam") || name.toLowerCase().endsWith(".cram") || name.toLowerCase().endsWith(".link"); } }); fc.setMultipleMode(true); fc.setVisible(true); File[] openfiles = fc.getFiles(); if (openfiles != null && openfiles.length > 0) { path = openfiles[0].getParent(); writeToConfig("DefaultDir=" + path); FileRead filereader = new FileRead(openfiles); filereader.start = (int) drawCanvas.selectedSplit.start; filereader.end = (int) drawCanvas.selectedSplit.end; filereader.readBAM = true; filereader.execute(); } else { //Main.showError("File(s) does not exist.", "Error"); } } catch (Exception ex) { Main.showError(ex.getMessage(), "Error"); } } else if (e.getSource() == openvcfs) { try { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } FileDialog fc = new FileDialog(frame, "Choose VCF file(s)", FileDialog.LOAD); fc.setDirectory(path); fc.setFile("*.vcf"); fc.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".vcf") || name.toLowerCase().endsWith(".vcf.gz"); } }); fc.setMultipleMode(true); fc.setVisible(true); File[] openfiles = fc.getFiles(); if (openfiles != null && openfiles.length > 0) { path = openfiles[0].getParent(); writeToConfig("DefaultDir=" + path); FileRead filereader = new FileRead(openfiles); filereader.start = (int) drawCanvas.selectedSplit.start; filereader.end = (int) drawCanvas.selectedSplit.end; filereader.readVCF = true; filereader.execute(); } else { //Main.showError("File(s) does not exist.", "Error"); } if (1 == 1) { return; } JFileChooser chooser = new JFileChooser(path); getText(chooser.getComponents()); chooser.setMultiSelectionEnabled(true); //chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); chooser.addChoosableFileFilter(vcfFilter); chooser.addChoosableFileFilter(bamFilter); chooser.addChoosableFileFilter(linkFilter); if (defaultSelectType == "vcf") { chooser.setFileFilter(vcfFilter); } else if (defaultSelectType == "bam") { chooser.setFileFilter(bamFilter); } else { chooser.setFileFilter(linkFilter); } chooser.setDialogTitle("Add samples"); chooser.setPreferredSize( new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3)); int returnVal = chooser.showOpenDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { File vcffiles[] = chooser.getSelectedFiles(); if (vcffiles.length == 1 && !vcffiles[0].exists() && pleiades) { if (Main.chooserText.contains("`")) { Main.chooserText.replace("`", "?"); } if (Main.chooserText.contains(" ")) { Main.chooserText.replace(" ", "%20"); } if (Main.chooserText.contains("pleiades")) { try { URL url = new URL(Main.chooserText); //System.out.println(Main.chooserText); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); httpConn.connect(); int responseCode = httpConn.getResponseCode(); if (responseCode == HttpsURLConnection.HTTP_OK) { String loading = drawCanvas.loadingtext; InputStream inputStream = httpConn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); Main.drawCanvas.loadingtext = loading + " 0MB"; String line; StringBuffer buffer = new StringBuffer(""); while ((line = reader.readLine()) != null) { buffer.append(line); } inputStream.close(); reader.close(); String split2; String[] split = buffer.toString().split("dataUnit"); String location; ArrayList<File> array = new ArrayList<File>(); File[] paths; FileSystemView fsv = FileSystemView.getFileSystemView(); paths = File.listRoots(); String loc = "/mnt"; boolean missingfiles = false; for (File path : paths) { if (fsv.getSystemDisplayName(path).contains("merit")) { loc = path.getCanonicalPath(); } } for (int i = 0; i < split.length; i++) { if (!split[i].contains("lastLocation")) { continue; } split2 = split[i].split("\"lastLocation\":\"")[1]; location = split2.substring(0, split2.indexOf("\"}")); String filename = ""; String testloc = location.replace("/mnt", loc) + "/wgspipeline/"; File testDir = new File(testloc); if (testDir.exists() && testDir.isDirectory()) { if (chooser.getFileFilter() .equals(chooser.getChoosableFileFilters()[1])) { File[] addDir = testDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".bam") || name.toLowerCase().endsWith(".cram"); } }); if (addDir.length > 0) { filename = addDir[0].getName(); } } else { File[] addDir = testDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".vcf.gz"); } }); if (addDir.length > 0) { filename = addDir[0].getName(); } } } location = testloc + "/" + filename; if (!new File(location).exists()) { if (!new File(location).exists()) { missingfiles = true; ErrorLog.addError("No sample files found in " + testloc); } else { array.add(new File(location)); } } else { array.add(new File(location)); } } File[] files = new File[array.size()]; for (int i = 0; i < files.length; i++) { files[i] = array.get(i); } FileRead filereader = new FileRead(files); filereader.start = (int) drawCanvas.selectedSplit.start; filereader.end = (int) drawCanvas.selectedSplit.end; if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[1])) { filereader.readBAM = true; } else { filereader.readVCF = true; } filereader.execute(); if (missingfiles) { JOptionPane.showMessageDialog(Main.drawScroll, "Missing files. Check Tools->View log", "Note", JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception ex) { ex.printStackTrace(); } } return; } if (vcffiles.length > 0) { path = vcffiles[0].getParent(); writeToConfig("DefaultDir=" + path); FileRead filereader = new FileRead(vcffiles); if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[0])) { defaultSelectType = "vcf"; filereader.start = (int) drawCanvas.selectedSplit.start; filereader.end = (int) drawCanvas.selectedSplit.end; filereader.readVCF = true; filereader.execute(); } else if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[1])) { defaultSelectType = "bam"; filereader.readBAM = true; filereader.execute(); } else if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[2])) { defaultSelectType = "link"; filereader.readBAM = true; filereader.execute(); } } else { JOptionPane.showMessageDialog(Main.drawScroll, "The file does not exist. The file link may be broken.\nThe problem may also be the Java run time version in Linux.", "Note", JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception ex) { ex.printStackTrace(); } } else if (e.getSource() == addcontrols) { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } FileDialog fc = new FileDialog(frame, "Choose control file(s)", FileDialog.LOAD); fc.setDirectory(Main.controlDir); fc.setFile("*.vcf.gz"); fc.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".vcf.gz"); } }); fc.setMultipleMode(true); fc.setVisible(true); File[] openfiles = fc.getFiles(); if (openfiles != null && openfiles.length > 0) { controlDir = openfiles[0].getParent(); writeToConfig("DefaultControlDir=" + controlDir); Control.addFiles(openfiles); } if (1 == 1) { return; } JFileChooser chooser = new JFileChooser(controlDir); // JFileChooser chooser = new JFileChooser(path); chooser.setMultiSelectionEnabled(true); chooser.setAcceptAllFileFilterUsed(false); Control.MyFilter vcfFilter = new Control.MyFilter(); chooser.addChoosableFileFilter(vcfFilter); chooser.setDialogTitle("Add controls"); chooser.setPreferredSize( new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3)); int returnVal = chooser.showOpenDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { File vcffiles[] = chooser.getSelectedFiles(); controlDir = vcffiles[0].getParent(); writeToConfig("DefaultControlDir=" + controlDir); if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[0])) { Control.addFiles(vcffiles); } } } else if (e.getSource() == addtracks) { if (!checkGenome()) return; try { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } FileDialog fc = new FileDialog(frame, "Choose track file(s)", FileDialog.LOAD); fc.setDirectory(Main.trackDir); fc.setFile( "*.bed;*.bedgraph.gz;*.gff.gz;*.gff3.gz;*.bigwig;*.bw;*.bigbed;*.bb;*.tsv.gz;*.tsv.bgz;*.txt"); fc.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".bed") || name.toLowerCase().endsWith(".bed.gz") || name.toLowerCase().endsWith(".bedgraph.gz") || name.toLowerCase().endsWith(".bedgraph.gz") || name.toLowerCase().endsWith(".bedgraph.gz") || name.toLowerCase().endsWith(".gff.gz") || name.toLowerCase().endsWith(".gff3.gz") || name.toLowerCase().endsWith(".bigwig") || name.toLowerCase().endsWith(".bw") || name.toLowerCase().endsWith(".bigbed") || name.toLowerCase().endsWith(".bb") || name.toLowerCase().endsWith(".tsv.gz") || name.toLowerCase().endsWith(".tsv.bgz") || name.toLowerCase().endsWith(".txt"); } }); fc.setMultipleMode(true); fc.setVisible(true); File[] openfiles = fc.getFiles(); if (openfiles != null && openfiles.length > 0) { trackDir = openfiles[0].getParent(); writeToConfig("DefaultTrackDir=" + trackDir); FileRead filereader = new FileRead(openfiles); filereader.readBED = true; filereader.execute(); } else { //Main.showError("File(s) does not exist.", "Error"); } } catch (Exception ex) { Main.showError(ex.getMessage(), "Error"); } if (1 == 1) { return; } if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } JFileChooser chooser = new JFileChooser(Main.trackDir); getText(chooser.getComponents()); chooser.setMultiSelectionEnabled(true); chooser.setAcceptAllFileFilterUsed(false); MyFilterBED bedFilter = new MyFilterBED(); MyFilterTXT txtFilter = new MyFilterTXT(); chooser.addChoosableFileFilter(bedFilter); chooser.addChoosableFileFilter(txtFilter); chooser.setDialogTitle("Add tracks"); chooser.setPreferredSize( new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3)); int returnVal = chooser.showOpenDialog((Component) this.getParent()); try { if (returnVal == JFileChooser.APPROVE_OPTION) { File bedfiles[] = chooser.getSelectedFiles(); if (bedfiles[0].exists()) { trackDir = bedfiles[0].getParent(); writeToConfig("DefaultTrackDir=" + trackDir); FileRead filereader = new FileRead(bedfiles); filereader.readBED(bedfiles); } else { if (Main.chooserText.length() > 5 && Main.chooserText.endsWith(".bed.gz") || Main.chooserText.endsWith(".gff.gz") || Main.chooserText.endsWith(".gff3.gz") || Main.chooserText.endsWith(".bedgraph.gz")) { if (Main.chooserText.startsWith("http://") || Main.chooserText.startsWith("ftp://")) { URL url = new URL(Main.chooserText); SeekableStream stream = SeekableStreamFactory.getInstance().getStreamFor(url); TabixReader tabixReader = null; String index = null; try { tabixReader = new TabixReader(Main.chooserText, Main.chooserText + ".tbi", stream); index = Main.chooserText + ".tbi"; } catch (Exception ex) { try { tabixReader = new TabixReader(Main.chooserText, Main.chooserText.substring(0, Main.chooserText.indexOf(".gz")) + ".tbi", stream); index = Main.chooserText.substring(0, Main.chooserText.indexOf(".gz")) + ".tbi"; } catch (Exception exc) { exc.printStackTrace(); } } if (tabixReader != null && index != null) { FileRead filereader = new FileRead(bedfiles); filereader.readBED(Main.chooserText, index, false); tabixReader.close(); } } } else { if (Main.chooserText.contains("://")) { try { // bbreader = new BBFileReader(Main.chooserText, stream); } catch (Exception ex) { ex.printStackTrace(); } // if(bbreader != null) { FileRead filereader = new FileRead(bedfiles); filereader.readBED(Main.chooserText, "nan", false); // } // stream.close(); } } } } } catch (Exception ex) { ex.printStackTrace(); } } else if (e.getSource() == openProject) { if (!checkGenome()) return; if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } openProject(); } else if (e.getSource() == saveProjectAs) { if (VariantHandler.frame != null) { VariantHandler.frame.setState(Frame.ICONIFIED); } try { File savefile = null; FileDialog fs = new FileDialog(frame, "Save project as...", FileDialog.SAVE); fs.setDirectory(projectDir); fs.setFile("*.ses"); fs.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".ses"); } }); fs.setVisible(true); while (true) { String filename = fs.getFile(); if (filename != null) { savefile = new File(fs.getDirectory() + "/" + filename); projectDir = fs.getDirectory(); writeToConfig("DefaultProjectDir=" + projectDir); /* if(!Files.isWritable(Paths.get(savefile.getParent()))) { Main.showError("No permission to write.", "Error"); continue; }*/ if (!savefile.getAbsolutePath().endsWith(".ses")) { savefile = new File(savefile.getAbsolutePath() + ".ses"); } Serializer ser = new Serializer(); ser.serialize(savefile); break; } else { break; } } if (1 == 1) { return; } JFileChooser chooser = new JFileChooser(); chooser.setAcceptAllFileFilterUsed(false); MyFilterSES sesFilter = new MyFilterSES(); chooser.addChoosableFileFilter(sesFilter); chooser.setDialogTitle("Save project as..."); int returnVal = chooser.showSaveDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { File outfile = chooser.getSelectedFile(); if (!outfile.getAbsolutePath().endsWith(".ses")) { outfile = new File(outfile.getAbsolutePath() + ".ses"); } Serializer ser = new Serializer(); ser.serialize(outfile); } } catch (Exception ex) { ex.printStackTrace(); } } else if (e.getSource() == saveProject) { if (drawCanvas.drawVariables.projectName.equals("Untitled")) { saveProjectAs.doClick(); } else { Serializer ser = new Serializer(); ser.serialize(drawCanvas.drawVariables.projectFile); } } /* else if(e.getSource() == welcome) { WelcomeScreen.main(args); WelcomeScreen.frame.setVisible(true); WelcomeScreen.frame.setLocation(frame.getLocationOnScreen().x+frame.getWidth()/2 - WelcomeScreen.frame.getWidth()/2, frame.getLocationOnScreen().y+frame.getHeight()/6); }*/ }