List of usage examples for javax.swing JFileChooser setMultiSelectionEnabled
@BeanProperty(description = "Sets multiple file selection mode.") public void setMultiSelectionEnabled(boolean b)
From source file:edu.ku.brc.specify.tasks.WorkbenchTask.java
/** * Asks for the type of export and the file name. * @param props the properties object to be filled in. * @return true if everything was asked for and received. *//* ww w . j a v a 2s. c om*/ public static boolean getExportInfo(final Properties props, final String defaultFileName) { String extension = ""; //String fileTypeCaption = ""; if (true) { for (ExportFileConfigurationFactory.ExportableType type : ExportFileConfigurationFactory .getExportList()) { if (type.getMimeType() == ExportFileConfigurationFactory.XLS_MIME_TYPE) { props.setProperty("mimetype", type.getMimeType()); extension = type.getExtension(); //fileTypeCaption = type.getCaption(); break; } } } else { ChooseFromListDlg<ExportFileConfigurationFactory.ExportableType> dlg = new ChooseFromListDlg<ExportFileConfigurationFactory.ExportableType>( (Frame) UIRegistry.get(UIRegistry.FRAME), getResourceString("WB_FILE_FORMAT"), null, ChooseFromListDlg.OKCANCELHELP, ExportFileConfigurationFactory.getExportList(), "WorkbenchImportCvs"); dlg.setModal(true); UIHelper.centerAndShow(dlg); if (!dlg.isCancelled()) { props.setProperty("mimetype", dlg.getSelectedObject().getMimeType()); } else { return false; } extension = dlg.getSelectedObject().getExtension(); dlg.dispose(); } // FileDialog fileDialog = new FileDialog((Frame) UIRegistry.get(UIRegistry.FRAME), // String.format(getResourceString("CHOOSE_WORKBENCH_EXPORT_FILE"), fileTypeCaption), FileDialog.SAVE); // fileDialog.setDirectory(getDefaultDirPath(EXPORT_FILE_PATH)); // UIHelper.centerAndShow(fileDialog); // fileDialog.dispose(); JFileChooser chooser = new JFileChooser(getDefaultDirPath(EXPORT_FILE_PATH)); chooser.setDialogTitle(getResourceString("CHOOSE_WORKBENCH_EXPORT_FILE")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new UIFileFilter("xls", getResourceString("WB_EXCELFILES"))); if (defaultFileName != null) { chooser.setSelectedFile( new File(chooser.getCurrentDirectory().getPath() + File.separator + defaultFileName + ".xls")); } if (chooser.showSaveDialog(UIRegistry.get(UIRegistry.FRAME)) != JFileChooser.APPROVE_OPTION) { UIRegistry.getStatusBar().setText(""); return false; } File file = chooser.getSelectedFile(); if (file == null) { UIRegistry.getStatusBar().setText(getResourceString("WB_EXPORT_NOFILENAME")); return false; } String path = chooser.getCurrentDirectory().getPath(); //String path = FilenameUtils.getPath(file.getPath()); if (StringUtils.isNotEmpty(path)) { AppPreferences localPrefs = AppPreferences.getLocalPrefs(); localPrefs.put(EXPORT_FILE_PATH, path); } // String fileName = fileDialog.getFile(); String fileName = file.getName(); // if (StringUtils.isEmpty(fileName)) // { // UIRegistry.getStatusBar().setText(getResourceString("WB_EXPORT_NOFILENAME")); // return false; // } if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) { fileName += (fileName.endsWith(".") ? "" : ".") + extension; } if (StringUtils.isEmpty(fileName)) { return false; } if (file.exists()) { PanelBuilder builder = new PanelBuilder(new FormLayout("p:g", "c:p:g")); CellConstraints cc = new CellConstraints(); String msg = String.format("<html><p>%s<br><br>%s<br></p></html>", getResourceString("WB_FILE_EXISTS"), getResourceString("WB_OK_TO_OVERWRITE")); builder.add(createLabel(msg), cc.xy(1, 1)); builder.setDefaultDialogBorder(); CustomDialog confirmer = new CustomDialog((Frame) UIRegistry.get(UIRegistry.FRAME), getResourceString("WB_FILE_EXISTS_TITLE"), true, CustomDialog.OKCANCEL, builder.getPanel(), CustomDialog.CANCEL_BTN); UIHelper.centerAndShow(confirmer); confirmer.dispose(); if (confirmer.isCancelled()) { return false; } } props.setProperty("fileName", path + File.separator + fileName); return true; }
From source file:edu.ku.brc.specify.tasks.WorkbenchTask.java
/** * Imports a set of image files, creating a new row per file, to the provided {@link Workbench} parameter. If the * given {@link Workbench} is <code>null</code>, a new {@link Workbench} is created. * /*from w w w . j ava 2s. c om*/ * @param workbenchArg the {@link Workbench} to append rows to, or <code>null</code> if a new {@link Workbench} should be created * @param doOneImagePerRow indicates whether the images are assign to a single row or not. */ public void importCardImages(Workbench workbench, final boolean doOneImagePerRow) { // ask the user to select the files to import final ImageFilter imageFilter = new ImageFilter(); JFileChooser chooser = new JFileChooser(getDefaultDirPath(IMAGES_FILE_PATH)); chooser.setDialogTitle(getResourceString("WB_CHOOSE_IMAGES")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(true); chooser.setFileFilter(imageFilter); if (chooser.showOpenDialog(UIRegistry.get(UIRegistry.FRAME)) != JFileChooser.APPROVE_OPTION) { UIRegistry.getStatusBar().setText(""); return; } AppPreferences localPrefs = AppPreferences.getLocalPrefs(); localPrefs.put(IMAGES_FILE_PATH, chooser.getCurrentDirectory().getAbsolutePath()); // Start by looping through the files and checking for image file extensions // weed out the bad files. final Vector<File> fileList = new Vector<File>(); if (!filterSelectedFileNames(chooser.getSelectedFiles(), fileList, imageFilter)) { return; } for (File f : fileList) { if (!ImageFrame.testImageFile(f.getAbsolutePath())) { JOptionPane.showMessageDialog(UIRegistry.getMostRecentWindow(), String.format(getResourceString("WB_WRONG_IMAGE_TYPE_OR_CORRUPTED_IMAGE"), new Object[] { f.getAbsolutePath() }), UIRegistry.getResourceString("WARNING"), JOptionPane.ERROR_MESSAGE); return; } } boolean creatingNewWb = workbench == null; if (creatingNewWb) // create a new Workbench { List<?> selection = selectExistingTemplate(null, "WorkbenchImportImages"); //Pair<Boolean, WorkbenchTemplate> selection = selectExistingTemplate(null, "WorkbenchImportImages"); if (selection.size() == 0 || !(Boolean) selection.get(0)) { return; //cancelled } WorkbenchTemplate workbenchTemplate = selection.size() > 1 ? (WorkbenchTemplate) selection.get(1) : null; if (workbenchTemplate == null) { // create a new WorkbenchTemplate TemplateEditor dlg = null; try { dlg = showColumnMapperDlg(null, null, "WB_MAPPING_EDITOR"); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(WorkbenchTask.class, ex); log.error(ex); } if (dlg != null && !dlg.isCancelled()) { workbenchTemplate = createTemplate(dlg, null); } if (dlg != null) { dlg.dispose(); } } else { workbenchTemplate = cloneWorkbenchTemplate(workbenchTemplate); } if (workbenchTemplate != null) { workbench = createNewWorkbenchDataObj("", workbenchTemplate); } } if (workbench != null) // this should always hold, but whatev { UIRegistry.writeGlassPaneMsg(String.format(getResourceString("WB_LOADING_IMGS_DATASET"), new Object[] { workbench.getName() }), GLASSPANE_FONT_SIZE); doImageImport(workbench, fileList, creatingNewWb, doOneImagePerRow); } }
From source file:edu.ku.brc.specify.tasks.WorkbenchTask.java
/** * Creates a new WorkBench from the Column Headers and the Data in a file. * @return the new Workbench/*from w w w. j av a2 s. co m*/ */ protected Workbench createNewWorkbenchFromFile() { // For ease of testing File file = null; // FileDialog fileDialog = new FileDialog(/*(Frame)UIRegistry.get(UIRegistry.FRAME),*/ // (Frame )UIRegistry.getTopWindow(), // getResourceString("CHOOSE_WORKBENCH_IMPORT_FILE"), // FileDialog.LOAD); // fileDialog.setDirectory(getDefaultDirPath(IMPORT_FILE_PATH)); // fileDialog.setFilenameFilter(new java.io.FilenameFilter() // { // public boolean accept(File dir, String filename) // { // for (ExportFileConfigurationFactory.ExportableType exportType : ExportFileConfigurationFactory.getExportList()) // { // String ext = FilenameUtils.getExtension(filename); // if (StringUtils.isNotEmpty(ext) && exportType.getExtension().toLowerCase().equals(ext)) // { // return true; // } // } // return false; // } // // }); // UIHelper.centerAndShow(fileDialog); // fileDialog.dispose(); JFileChooser chooser = new JFileChooser(getDefaultDirPath(IMPORT_FILE_PATH)); chooser.setDialogTitle(getResourceString("CHOOSE_WORKBENCH_IMPORT_FILE")); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); String[] exts = { "xls", "csv" }; chooser.setFileFilter(new UIFileFilter(exts, getResourceString("WB_EXCELANDCSVFILES"))); String currDirPath = AppPreferences.getLocalPrefs().get(IMPORT_FILE_PATH, null); if (currDirPath != null) { File currDir = new File(currDirPath); if (currDir.isDirectory() && currDir.exists()) { chooser.setCurrentDirectory(currDir); } } if (chooser.showOpenDialog(UIRegistry.get(UIRegistry.FRAME)) != JFileChooser.APPROVE_OPTION) { UIRegistry.getStatusBar().setText(""); return null; } // String fileName = fileDialog.getFile(); // String path = fileDialog.getDirectory(); // if (StringUtils.isNotEmpty(path)) // { // AppPreferences localPrefs = AppPreferences.getLocalPrefs(); // localPrefs.put(IMPORT_FILE_PATH, path); // } // // if (StringUtils.isNotEmpty(fileName) && StringUtils.isNotEmpty(path)) // { // file = new File(path + File.separator + fileName); // } else // { // return null; // } file = chooser.getSelectedFile(); if (file.exists()) { if (StringUtils.isNotEmpty(file.getPath())) { AppPreferences localPrefs = AppPreferences.getLocalPrefs(); localPrefs.put(IMPORT_FILE_PATH, file.getParent()); } ImportDataFileInfo dataFileInfo = new ImportDataFileInfo(); if (dataFileInfo.load(file)) { Workbench workbench = createNewWorkbench(dataFileInfo, file); // This means correct usage count for ImportXLS will actually be getUsageCount(ImportXLS) - getUsageCount(ImportCSV)... //if (dataFileInfo.getConfig().getProperties().getProperty("mimetype","").equals(ExportFileConfigurationFactory.CSV_MIME_TYPE)) //{ // UsageTracker.incrUsageCount("WB.ImportCSV"); //} return workbench; } else if (dataFileInfo.getConfig() == null || dataFileInfo.getConfig().getStatus() != ConfigureExternalDataIFace.Status.Cancel) { JStatusBar statusBar = UIRegistry.getStatusBar(); statusBar.setErrorMessage( String.format(getResourceString("WB_PARSE_FILE_ERROR"), new Object[] { file.getName() })); } } return null; }
From source file:com.pianobakery.complsa.MainGui.java
public File chooseAddCorpusFolder() { try {//from w w w.j av a 2s . c o m JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(System.getProperty("user.home"))); chooser.setDialogTitle("Create Working Folder"); chooser.setFileHidingEnabled(Boolean.TRUE); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); int whatChoose = chooser.showOpenDialog(null); File selected; if (whatChoose == JFileChooser.APPROVE_OPTION) { selected = chooser.getSelectedFile(); logger.debug("AddCorpDir is: " + selected.toString()); logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory()); logger.debug("getSelectedFile() : " + chooser.getSelectedFile()); enableUIElements(true); return selected; } } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Falsche Eingabe"); } return null; }
From source file:com.pianobakery.complsa.MainGui.java
public void importSearchFile() { searchDocValue.setText("loading..."); try {//from ww w .java2s . c o m File selected; searchFileString = ""; JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(System.getProperty("user.home"))); chooser.setDialogTitle("Choose Search File"); chooser.setFileHidingEnabled(Boolean.TRUE); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); int whatChoose = chooser.showOpenDialog(null); if (whatChoose == JFileChooser.APPROVE_OPTION) { selected = chooser.getSelectedFile(); logger.debug("AddCorpDir is: " + selected.toString()); logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory()); logger.debug("getSelectedFile() : " + chooser.getSelectedFile()); enableUIElements(true); if (selected.exists()) { Parser parser = new Parser(selected); try { parser.parseDocToPlainText(); searchFileString = Utilities.removeQuoteFromString(parser.getPlainText()); logger.debug("The Search File: " + searchFileString); searchDocValue .setText(selected.getParentFile().getName() + File.separator + selected.getName()); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (TikaException e) { e.printStackTrace(); } } } } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Falsche Eingabe"); } }
From source file:com.pianobakery.complsa.MainGui.java
public void chooseNewProjectFolder() { try {/* w ww . j ava 2 s . c om*/ JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(openFolder); //chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home"))); chooser.setDialogTitle("Choose Folder"); chooser.setFileHidingEnabled(Boolean.TRUE); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); chooser.setApproveButtonText("Choose"); int whatChoose = chooser.showOpenDialog(null); if (whatChoose == JFileChooser.APPROVE_OPTION) { String text = chooser.getSelectedFile().toString(); wDirText.setText(text); wDir = chooser.getSelectedFile(); logger.debug("WDir is: " + wDir.toString()); logger.debug("getCurrentDirectory(): " + chooser.getCurrentDirectory()); logger.debug("getSelectedFile() : " + chooser.getSelectedFile()); enableUIElements(true); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Falsche Eingabe"); } }
From source file:com.pianobakery.complsa.MainGui.java
public void createNewProjectFolder() { try {/* ww w.j ava 2s . c om*/ JFrame frame = new JFrame(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(openFolder); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home"))); chooser.setDialogTitle("Create Folder"); chooser.setFileHidingEnabled(Boolean.TRUE); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setSelectedFile(new File("Workingfile")); frame.getContentPane().add(chooser); chooser.setApproveButtonText("Choose"); //Disable Save as ArrayList<JPanel> jpanels = new ArrayList<JPanel>(); for (Component c : chooser.getComponents()) { if (c instanceof JPanel) { jpanels.add((JPanel) c); } } jpanels.get(0).getComponent(0).setVisible(false); frame.pack(); frame.setLocationRelativeTo(null); int whatChoose = chooser.showSaveDialog(null); if (whatChoose == JFileChooser.APPROVE_OPTION) { File selFile = chooser.getSelectedFile(); File currDir = chooser.getCurrentDirectory(); Path parentDir = Paths.get(chooser.getCurrentDirectory().getParent()); String parentDirName = parentDir.getFileName().toString(); logger.debug("Chooser SelectedFile: " + selFile.toString()); logger.debug("getCurrentDirectory(): " + currDir.toString()); logger.debug("Chooser parentdir: " + parentDir); logger.debug("Parentdirname: " + parentDirName); if (selFile.getName().equals(parentDirName)) { wDir = currDir; } else { wDir = chooser.getSelectedFile(); } logger.debug("WDIR is: " + wDir.toString()); wDirText.setText(wDir.toString()); enableUIElements(true); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Falsche Eingabe"); logger.debug("Exeption: " + ex.toString()); } }
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); }//w w w . j a va2 s . c o 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); }*/ }
From source file:app.RunApp.java
/** * Action of Add button in Multiple datasets tab * /* w w w. j av a2 s.c o m*/ * @param evt Event */ private void buttonAddMultipleDatasetsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddMultipleDatasetsActionPerformed //Choose dataset final JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); FileNameExtensionFilter fname = new FileNameExtensionFilter(".arff", "arff"); chooser.setFileFilter(fname); final int returnVal = chooser.showOpenDialog(this); progressBar.setIndeterminate(true); progressFrame.setVisible(true); progressFrame.repaint(); new Thread(new Runnable() { @Override public void run() { // do the long-running work here loadMultiDataset(returnVal, chooser); // at the end: SwingUtilities.invokeLater(new Runnable() { @Override public void run() { progressBar.setIndeterminate(false); progressFrame.setVisible(false); progressFrame.repaint(); }//run }); //invokeLater } }).start(); }
From source file:no.java.swing.SingleSelectionFileDialog.java
private Result showJFileChooser(Component target, boolean open) { JFileChooser chooser = new JFileChooser(previousDirectory); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(filter);// w w w . ja v a 2 s. co m chooser.setAcceptAllFileFilterUsed(filter == null); chooser.setDialogType(open ? JFileChooser.OPEN_DIALOG : JFileChooser.SAVE_DIALOG); int selection = chooser.showDialog(target, null); switch (selection) { case JFileChooser.APPROVE_OPTION: this.selected = chooser.getSelectedFile(); if (rememberPreviousLocation) { previousDirectory = chooser.getCurrentDirectory(); } return Result.APPROVE; case JFileChooser.CANCEL_OPTION: case JFileChooser.ERROR_OPTION: default: this.selected = null; return Result.ERROR; } }