List of usage examples for javax.swing JFileChooser setFileFilter
@BeanProperty(preferred = true, description = "Sets the File Filter used to filter out files of type.") public void setFileFilter(FileFilter filter)
From source file:org.biojava.bio.view.MotifAnalyzer.java
public void actionPerformed(ActionEvent e) { final JFileChooser readVoter = new JFileChooser(); readVoter.setFileFilter(new Filter("voter")); readVoter.setDialogTitle("Select Motifs file (in MotifVoter format)"); final JFileChooser reader = new JFileChooser(); reader.setDialogTitle("Select Motifs file"); final JFileChooser readFASTA = new JFileChooser(); readFASTA.setFileFilter(new Filter("fasta")); readFASTA.setDialogTitle("Select Sequence File (in FASTA format)"); final JFileChooser readTompa = new JFileChooser(); readTompa.setFileFilter(new Filter("tompa")); readTompa.setDialogTitle("Select Motifs File (in Tompa's fromat)"); final JFileChooser readDirectory = new JFileChooser(); readDirectory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); readDirectory.setDialogTitle("Select Directory"); final Dataset dataset = (Dataset) datasetComboBox.getSelectedItem(); final DatasetType datasetType = (DatasetType) datasetTypeComboBox.getSelectedItem(); final boolean readReverse = checkReverse.isSelected(); final OrganismCode org = OrganismCode.getOrganism(organismType.getSelectedIndex()); final int minPoints = (Integer) this.minPoints.getSelectedItem(); final double epsilon = Double.parseDouble((String) this.clusteringEpsilon.getSelectedItem()); final int numOfClusters = (Integer) this.numOfClusters.getSelectedItem(); final boolean multipleDataSets = this.multipleDataSets.isSelected(); try {// w w w . j a v a2 s . co m if (((JMenuItem) e.getSource()).getText().equals(convertMotifVoterMenuName)) { if (reader.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { String fileName = reader.getSelectedFile().getCanonicalPath(); if (reader.getSelectedFile().getName().contains(".zip")) // if file is zipped, extract it { fileName = UnZip.unZip(reader.getSelectedFile(), ".txt", ".MVW2"); (new File(fileName)).deleteOnExit(); } if (fileName != null) FileConverterTools.readMotifVoterWeb(new File(fileName), readReverse, true); } } else if (((JMenuItem) e.getSource()).getText().equals(runPatchConverMVMenuName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File[] directories = readDirectory.getSelectedFile().listFiles(); File out2 = new File(readDirectory.getSelectedFile().getParentFile() + "\\MVW2"); File out = new File(readDirectory.getSelectedFile().getParentFile() + "\\MVW"); out.mkdir(); out2.mkdir(); for (int i = 0; i < directories.length; i++) { File[] files2 = directories[i].listFiles(new Filter("zip")); File[] files = directories[i].listFiles(new Filter("MVW.voter")); if (files2.length > 0) { String fileName = UnZip.unZip(files2[0], ".txt", ".MVW2"); if (fileName != null) { fileName = FileConverterTools.readMotifVoterWeb(new File(fileName), readReverse, true); FileConverterTools.copy(new File(fileName), out2); } } if (files.length > 0) { FileConverterTools.copy(files[0], out); } } } } else if (((JMenuItem) e.getSource()).getText().equals(convertAllMenuName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { controller.convertFilesAndMerge(readDirectory.getSelectedFile(), dataset, readReverse); } } else if (((JMenuItem) e.getSource()).getText().equals(runPatchConverAllMenuName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File[] directories = readDirectory.getSelectedFile().listFiles(); for (int i = 0; i < directories.length; i++) { String datasetName = directories[i].getName(); if (datasetName.contains("_")) datasetName = datasetName.substring(0, datasetName.indexOf("_")); datasetName = datasetName.substring(0, datasetName.length() - 1); // remove g,m,r controller.convertFilesAndMerge(directories[i], Dataset.getValue(datasetName), readReverse); } } } else if (((JMenuItem) e.getSource()).getText().equals(copyCleanInputFilesName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File[] directories = readDirectory.getSelectedFile().listFiles(); File out = new File(readDirectory.getSelectedFile().getParentFile() + "\\clean"); out.mkdir(); for (int i = 0; i < directories.length; i++) { File[] files = directories[i].listFiles(new Filter("clean.voter")); if (files.length > 0) { FileConverterTools.copy(files[0], out); } } } } else if (((JMenuItem) e.getSource()).getText().equals(loadMenuName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { loadAnalysis(readDirectory.getSelectedFile()); } } else if (((JMenuItem) e.getSource()).getText().equals(saveMenuName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { saveAnalysis(readDirectory.getSelectedFile()); } } else if (((JMenuItem) e.getSource()).getText().equals(gibbsMenuName)) { readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame); FileConverterTools.createLengthFile(readDirectory.getSelectedFile(), new File(readDirectory.getSelectedFile() + "//len.txt")); /* if (readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { Thread t = new Thread(){ public void run() { SimpleGibbsAlignerDemo demo = new SimpleGibbsAlignerDemo(); int i = Integer.parseInt(numOfTrials.getText()); int w = Integer.parseInt(motifWidth.getText()); demo.runDemo(readFASTA.getSelectedFile(), false, w, i);} }; t.start(); } */ } else if (((JMenuItem) e.getSource()).getText().equals(compareSetsName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File dir = readDirectory.getSelectedFile(); if (multipleDataSets) controller.compareSetsAllDir(dir); else controller.compareSets(dir); } } else if (((JMenuItem) e.getSource()).getText().equals(mergeCompareSetsName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File dir = readDirectory.getSelectedFile(); controller.mergeComputeSets(dir); } } else if (((JMenuItem) e.getSource()).getText().equals(infoContentMenuName)) { if (reader.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { List<String> sequences = null; if (inputTextArea.getText() != null) { String temp = inputTextArea.getText(); sequences = new ArrayList<String>(); while (temp.contains("\n")) { String seq = temp.substring(0, temp.indexOf('\n')); temp = temp.substring(temp.indexOf('\n') + 1, temp.length() - 1); if (seq.contains(">")) continue; sequences.add(seq); } sequences.add(temp); } Double[] score = MotifTools.getsequenceScore(reader.getSelectedFile(), sequences); StringBuffer buff = new StringBuffer(); for (int i = 0; i < score.length; i++) buff.append(score[i].doubleValue() + "\n"); getOutputPane().setText(buff.toString()); LinesSeriesChart linesChart = new LinesSeriesChart(); String[] labels = new String[1]; labels[0] = "label"; String x[] = new String[score.length]; Double[][] values = new Double[1][score.length]; for (int i = 0; i < score.length; i++) { values[0][i] = score[i]; x[i] = i + 1 + ""; } //linesChart.createChartImage("e://images//chart1.jpg", labels, x, values, false); tabs.add("Info Content", new ChartPanel(linesChart.createCategoryChart("", "", "", labels, x, values))); } } else if (((JMenuItem) e.getSource()).getText().equals(removeRedundantSitesName)) { int returnVal = JFileChooser.CANCEL_OPTION; if (datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame); if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { SequenceIterator seqItr; if (returnVal == JFileChooser.APPROVE_OPTION) seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile()); else seqItr = TompaDataset.getDatasetSequences(dataset); List<Motif> m = controller .removeRedundantSites(readVoter.getSelectedFile().getCanonicalPath(), dataset); if (m != null) { showMotifs(seqItr, m); for (int i = 0; i < controller.numOfEvaluations; i++) displayCharts(i); } } } } else if (((JMenuItem) e.getSource()).getText().equals(extractSitesName)) { int returnVal = JFileChooser.CANCEL_OPTION; if (datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame); if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { SequenceIterator seqItr; if (returnVal == JFileChooser.APPROVE_OPTION) seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile()); else seqItr = TompaDataset.getDatasetSequences(dataset); List<Motif> m = controller.extractSites(readVoter.getSelectedFile().getCanonicalPath(), dataset); if (m != null) { showMotifs(seqItr, m); for (int i = 0; i < controller.numOfEvaluations; i++) displayCharts(i); } } } } else if (((JMenuItem) e.getSource()).getText().equals(drawKDistanceGraphName)) { int returnVal = JFileChooser.CANCEL_OPTION; if (datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame); if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { String fileName = controller.drawKDistanceGraph(readVoter.getSelectedFile(), dataset, minPoints); displayCharts(fileName); } } } else if (((JMenuItem) e.getSource()).getText().equals(computeWeightName)) { int returnVal = JFileChooser.CANCEL_OPTION; if (datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame); if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { List<Double> list = controller .computeSimilarity(readVoter.getSelectedFile().getCanonicalPath(), dataset); double sim = list.get(0); double w = list.get(1); String out = String.format("Compactness=%.5f, Weight=%.5f", sim, w); System.out.println(out); JOptionPane.showMessageDialog(mainFrame, out, "Info", JOptionPane.INFORMATION_MESSAGE); } } } else if (((JMenuItem) e.getSource()).getText().equals(evaluateTompaMotifEachName)) { if (readTompa.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { controller.evaluateTompaMotifEach(readTompa.getSelectedFile().getCanonicalPath()); displayCharts(); } } else if (((JMenuItem) e.getSource()).getText().equals(evaluateTompaMotifAccName)) { if (readTompa.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { controller.evaluateTompaMotifAcc(readTompa.getSelectedFile().getCanonicalPath()); displayCharts(); } } else if (((JMenuItem) e.getSource()).getText().equals(evaluateTompaMotifTotalName)) { if (readTompa.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { controller.evaluateTompaMotifTotal(readTompa.getSelectedFile().getCanonicalPath()); displayCharts(); } } else if (((JMenuItem) e.getSource()).getText().equals(evaluateMotifVoterName)) { int returnVal = JFileChooser.CANCEL_OPTION; if (datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame); if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { SequenceIterator seqItr; if (returnVal == JFileChooser.APPROVE_OPTION) seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile()); else seqItr = TompaDataset.getDatasetSequences(dataset); Vector<Motif> motifs = controller.evaluateMotifVoterEach(readVoter.getSelectedFile(), dataset); showMotifs(seqItr, motifs); displayCharts(); } } } else if (((JMenuItem) e.getSource()).getText().equals(evaluateMotifVoterTotalName)) { int returnVal = JFileChooser.CANCEL_OPTION; if (datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame); if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { SequenceIterator seqItr; if (returnVal == JFileChooser.APPROVE_OPTION) seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile()); else seqItr = TompaDataset.getDatasetSequences(dataset); Vector<Motif> motifs = controller.evaluateMotifVoterTotal(readVoter.getSelectedFile(), dataset); showMotifs(seqItr, motifs); displayCharts(); } } } else if (((JMenuItem) e.getSource()).getText().equals(evaluateMVDirFirstEleName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File[] files = readDirectory.getSelectedFile().listFiles(new Filter("voter")); controller.evaluateMotifVoterDirFirstEle(files, org, datasetType, readReverse); displayCharts(); } } else if (((JMenuItem) e.getSource()).getText().equals(evaluateMVDirMergedName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File[] files = readDirectory.getSelectedFile().listFiles(new Filter("voter")); controller.evaluateMotifVoterDirMerged(files, org, datasetType, readReverse); displayCharts(); } } else if (((JMenuItem) e.getSource()).getText().equals(compareMotifVoterFirstName)) { int returnVal = JFileChooser.CANCEL_OPTION; if (datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame); if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File file1 = readVoter.getSelectedFile(); if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { SequenceIterator seqItr; if (returnVal == JFileChooser.APPROVE_OPTION) seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile()); else seqItr = TompaDataset.getDatasetSequences(dataset); Vector<Motif> motifs = new Vector<Motif>(2); motifs.add(FileConverterTools.readMotifVoter(file1, readReverse).firstElement()); motifs.add(FileConverterTools.readMotifVoter(readVoter.getSelectedFile(), readReverse) .firstElement()); EvaluationController.evaluateMotifList(motifs, dataset); motifs.add(TompaDataset.getAnswer(dataset)); showMotifs(seqItr, motifs); displayCharts(); } } } } else if (((JMenuItem) e.getSource()).getText().equals(compareMotifVoterAllName)) { int returnVal = JFileChooser.CANCEL_OPTION; if (datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame); if (!datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File file1 = readVoter.getSelectedFile(); if (readVoter.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { SequenceIterator seqItr; if (returnVal == JFileChooser.APPROVE_OPTION) seqItr = TompaDataset.getSequences(readFASTA.getSelectedFile()); else seqItr = TompaDataset.getDatasetSequences(dataset); Vector<Motif> motifs = new Vector<Motif>(2); Vector<Motif> temp = FileConverterTools.readMotifVoter(file1, readReverse); for (Iterator<Motif> i = temp.iterator(); i.hasNext();) temp.firstElement().merge(i.next()); temp.firstElement().setFinder(MotifFinder.MotifVoter); motifs.add(temp.firstElement()); temp = FileConverterTools.readMotifVoter(readVoter.getSelectedFile(), readReverse); for (Iterator<Motif> i = temp.iterator(); i.hasNext();) temp.firstElement().merge(i.next()); motifs.add(temp.firstElement()); EvaluationController.evaluateMotifList(motifs, dataset); motifs.add(TompaDataset.getAnswer(dataset)); showMotifs(seqItr, motifs); displayCharts(); } } } } else if (((JMenuItem) e.getSource()).getText().equals(evaluateAllResultsName)) { if (readDirectory.showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { File[] files = readDirectory.getSelectedFile().listFiles(new Filter("voter")); controller.evaluateMotifVoterDirAllDataset(files, datasetType, readReverse); displayCharts(); } } else if (((JMenuItem) e.getSource()).getText().equals(runBioProspectorName)) runMethod(MotifFinder.BP); /*else if (((JMenuItem)e.getSource()).getText().equals(runDBScanName) || ((JMenuItem)e.getSource()).getText().equals(runKMeansName) || ((JMenuItem)e.getSource()).getText().equals(runOPTICSName) || ((JMenuItem)e.getSource()).getText().equals(runCliqueName) || ((JMenuItem)e.getSource()).getText().equals(runMotifVoterName)) { int type = -1; if (((JMenuItem)e.getSource()).getText().equals(runMotifVoterName)) type = 0; else if (((JMenuItem)e.getSource()).getText().equals(runKMeansName)) type = 1; else if (((JMenuItem)e.getSource()).getText().equals(runDBScanName)) type = 2; else if (((JMenuItem)e.getSource()).getText().equals(runOPTICSName)) type = 3; else if (((JMenuItem)e.getSource()).getText().equals(runCliqueName)) type = 4; */ else if (Method.valueOf(((JMenuItem) e.getSource()).getText()) != null) { final Method methodType = Method.valueOf(((JMenuItem) e.getSource()).getText()); int returnVal = JFileChooser.CANCEL_OPTION; if (!multipleDataSets && datasetComboBox.getSelectedItem().equals(Dataset.unknown)) returnVal = readFASTA.showOpenDialog(MotifAnalyzer.this.mainFrame); if (multipleDataSets || !datasetComboBox.getSelectedItem().equals(Dataset.unknown) || (returnVal == JFileChooser.APPROVE_OPTION)) { if (!multipleDataSets && readVoter .showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { final SequenceIterator seqItr = (returnVal == JFileChooser.APPROVE_OPTION) ? TompaDataset.getSequences(readFASTA.getSelectedFile()) : TompaDataset.getDatasetSequences(dataset); Thread t = new Thread() { public void run() { try { List<Motif> m = controller.runMotifVoter( readVoter.getSelectedFile().getCanonicalPath(), dataset, multipleDataSets, methodType, minPoints, epsilon, numOfClusters); if (m != null) { showMotifs(seqItr, m); for (int i = 0; i < controller.numOfEvaluations; i++) displayCharts(i); } } catch (Exception e) { e.printStackTrace(); } } }; t.start(); } else if (multipleDataSets && readDirectory .showOpenDialog(MotifAnalyzer.this.mainFrame) == JFileChooser.APPROVE_OPTION) { Thread t2 = new Thread() { public void run() { try { controller.runMotifVoter(readDirectory.getSelectedFile().getCanonicalPath(), dataset, multipleDataSets, methodType, minPoints, epsilon, numOfClusters); } catch (Exception e) { e.printStackTrace(); } } }; t2.start(); } } } } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(mainFrame, "An Error occured", "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:com.g2inc.scap.editor.gui.windows.EditorMainWindow.java
private void initFilemenu() { final EditorMainWindow parentWinRef = this; exitMenuItem.addActionListener(new ActionListener() { @Override/* ww w . j a va2 s.c om*/ public void actionPerformed(ActionEvent e) { parentWinRef.dispose(); } }); openOvalMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { final JFileChooser fc = new JFileChooser(); fc.setDialogType(JFileChooser.OPEN_DIALOG); File lastOpenedFrom = guiProps.getLastOpenedFromFile(); // Set current directory fc.setCurrentDirectory(lastOpenedFrom); FileFilter ff = new OcilOrOvalFilesFilter("OVAL"); fc.setFileFilter(ff); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int ret = fc.showOpenDialog(EditorMainWindow.getInstance()); if (ret == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); File parent = f.getAbsoluteFile().getParentFile(); guiProps.setLastOpenedFrom(parent.getAbsolutePath()); guiProps.save(); openFile(f, SCAPDocumentClassEnum.OVAL); } } }); saveMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { // get the currently open window JInternalFrame selectedWin = desktopPane.getSelectedFrame(); if (selectedWin != null) { SCAPDocument scapDoc = null; Document dom = null; String filename = null; if (selectedWin instanceof OvalEditorForm) { OvalEditorForm oef = (OvalEditorForm) selectedWin; scapDoc = oef.getDocument(); dom = scapDoc.getDoc(); filename = scapDoc.getFilename(); } else if (selectedWin instanceof CPEDictionaryEditorForm) { CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin; scapDoc = cef.getDocument(); dom = scapDoc.getDoc(); filename = scapDoc.getFilename(); } if (dom != null) { // since this is a save operation, not save as, we won't // prompt the user for where to store the file try { scapDoc.save(); ((EditorForm) selectedWin).setDirty(false); } catch (Exception e) { String message = "An error occured trying to save to file " + filename + ": " + e.getMessage(); EditorUtil.showMessageDialog(parentWinRef, message, EditorMessages.SAVE_ERROR_DIALOG_TITLE, JOptionPane.ERROR_MESSAGE); } } } } }); saveAsMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { // get the currently open window JInternalFrame selectedWin = desktopPane.getSelectedFrame(); if (selectedWin != null) { SCAPDocument scapDoc = null; Document dom = null; String filename = null; String windowTitle = null; if (selectedWin instanceof OvalEditorForm) { windowTitle = OvalEditorForm.WINDOW_TITLE_BASE; OvalEditorForm oef = (OvalEditorForm) selectedWin; scapDoc = oef.getDocument(); dom = scapDoc.getDoc(); filename = scapDoc.getFilename(); } else if (selectedWin instanceof CPEDictionaryEditorForm) { windowTitle = CPEDictionaryEditorForm.WINDOW_TITLE_BASE; CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin; scapDoc = cef.getDocument(); dom = scapDoc.getDoc(); filename = scapDoc.getFilename(); } else { return; } if (dom != null) { String newFilename = null; SCAPDocumentTypeEnum docType = scapDoc.getDocumentType(); FileSaveAsWizard saveAsWiz = new FileSaveAsWizard(EditorMainWindow.getInstance(), true, docType); //saveAsWiz.pack(); saveAsWiz.setLocationRelativeTo(EditorMainWindow.getInstance()); saveAsWiz.setVisible(true); if (saveAsWiz.wasCancelled()) { return; } newFilename = saveAsWiz.getFilename(); try { scapDoc.setFilename(newFilename); scapDoc.saveAs(newFilename); EditorUtil.markActiveWindowDirty(EditorMainWindow.getInstance(), false); ((EditorForm) selectedWin).refreshRootNode(); } catch (Exception e) { LOG.error(e.getMessage(), e); EditorUtil.showMessageDialog(parentWinRef, "An error occured trying to save to file " + newFilename + ": " + e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE); return; } SCAPContentManager scm = SCAPContentManager.getInstance(); if (scm != null) { scm.removeDocument(filename); scm.addDocument(newFilename, scapDoc); selectedWin.setTitle(windowTitle + (new File(newFilename)).getAbsolutePath()); } else { LOG.error("SCM instance is null here!"); } } } } }); newXCCDFFromOvalMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { //generateXccdfFromOvalOrOcil("OVAL"); final JFileChooser fc = new JFileChooser(); fc.setDialogType(JFileChooser.OPEN_DIALOG); File lastOpenedFrom = guiProps.getLastOpenedFromFile(); // Set current directory fc.setCurrentDirectory(lastOpenedFrom); FileFilter ff = new OcilOrOvalFilesFilter("OVAL"); fc.setFileFilter(ff); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int ret = fc.showOpenDialog(EditorMainWindow.getInstance()); if (ret == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); File parent = f.getAbsoluteFile().getParentFile(); guiProps.setLastOpenedFrom(parent.getAbsolutePath()); guiProps.save(); try { InputStream is = this.getClass().getClassLoader().getResourceAsStream("oval-to-xccdf.xsl"); File xsltfile = new File("oval-to-xccdf.xsl"); OutputStream outputStream = new FileOutputStream(xsltfile); IOUtils.copy(is, outputStream); outputStream.close(); OvalToXCCDF1.ovalToXccdf(f, xsltfile); xsltfile.delete(); String reverseDNS = JOptionPane.showInputDialog("reverse_DNS:"); if (reverseDNS == null || reverseDNS.length() == 0) { JOptionPane.showMessageDialog(null, "Enter the reverse_DNS", "alert", JOptionPane.ERROR_MESSAGE); } else { JFileChooser fc1 = new JFileChooser(); fc1.setCurrentDirectory(f); int ret1 = fc1.showSaveDialog(EditorMainWindow.getInstance()); if (ret1 == JFileChooser.APPROVE_OPTION) { File savefile = fc1.getSelectedFile(); is = this.getClass().getClassLoader().getResourceAsStream("xccdf_1.1_to_1.2.xsl"); xsltfile = new File("oval-to-xccdf.xsl"); outputStream = new FileOutputStream(xsltfile); IOUtils.copy(is, outputStream); outputStream.close(); File temp = new File("temp.xml"); XCCDF1to2.xccdf12(savefile, reverseDNS, xsltfile, temp); JOptionPane.showMessageDialog(null, "XCCDF File Created: " + savefile.getAbsolutePath(), "XCCDF Created", JOptionPane.PLAIN_MESSAGE); xsltfile.delete(); temp.delete(); temp = null; } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } // openFile(f, SCAPDocumentClassEnum.OVAL); } } }); newOvalMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { CreateOvalWizard wiz = new CreateOvalWizard(true); wiz.setName("create_oval_wizard"); wiz.pack(); wiz.setVisible(true); if (!wiz.wasCancelled()) { // User has been through the wizard to select // 1. an Oval schema version (eg, OVAL55) // 2. one or more platforms (eg, "windows", "solaris", etc) // 3. a file name for the new Oval file // Now we are ready to actually create the file String createdFilename = createNewOvalDocument(wiz); if (createdFilename == null) { LOG.error("newOvalMenuItem.actionlistener: Created filename was null!"); return; } File f = new File(createdFilename); guiProps.setLastOpenedFromFile(f.getParentFile()); guiProps.save(); SCAPContentManager scm = SCAPContentManager.getInstance(); if (scm != null) { OvalDefinitionsDocument dd = (OvalDefinitionsDocument) scm.getDocument(f.getAbsolutePath()); openFile(dd); } } wiz.setVisible(false); wiz.dispose(); } }); /* wizModeMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { WizardModeWindow wizModeWin = new WizardModeWindow(); EditorMainWindow emw = EditorMainWindow.getInstance(); JDesktopPane emwDesktopPane = emw.getDesktopPane(); wizModeWin.setTitle("Wizard Mode"); wizModeWin.pack(); wizModeWin.addInternalFrameListener(new WeakInternalFrameListener(EditorMainWindow.getInstance())); Dimension dpDim = emwDesktopPane.getSize(); int x = (dpDim.width - wizModeWin.getWidth()) / 2; int y = (dpDim.height - wizModeWin.getHeight()) / 2; wizModeWin.setLocation(x, y); emwDesktopPane.add(wizModeWin); wizModeWin.setVisible(true); setWizMode(true); } });*/ ugMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); InputStream resource = this.getClass().getResourceAsStream("/User_Guide.pdf"); try { File userGuideFile = File.createTempFile("UserGuide", ".pdf"); userGuideFile.deleteOnExit(); OutputStream out = new FileOutputStream(userGuideFile); try { // copy contents from resource to out IOUtils.copy(resource, out); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Couldn't copy between streams."); } finally { out.close(); } desktop.open(userGuideFile); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Could not call Open on desktop object."); } finally { try { if (resource != null) { resource.close(); } } catch (IOException ex) { LOG.error("Error displaying user guide", ex); JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide."); } } } else { JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide."); } } }); }
From source file:com.freedomotic.jfrontend.MainWindow.java
private void mnuBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuBackgroundActionPerformed final JFileChooser fc = new JFileChooser(Info.PATHS.PATH_DATA_FOLDER + File.separator + "resources" + File.separator + "system" + File.separator + "map" + File.separator); OpenDialogFileFilter filter = new OpenDialogFileFilter(); filter.addExtension("png"); filter.addExtension("jpeg"); filter.addExtension("jpg"); filter.setDescription("Image files (png, jpeg)"); fc.addChoosableFileFilter(filter);// w ww . j a v a2 s . com fc.setFileFilter(filter); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //This is where a real application would open the file. LOG.info("Opening \"{}\"", file.getAbsolutePath()); file = this.moveBackgroundFile(file); drawer.getCurrEnv().getPojo().setBackgroundImage(file.getAbsolutePath()); drawer.setNeedRepaint(true); frameMap.validate(); } }
From source file:com.jug.MoMA.java
/** * Shows a JFileChooser set up to accept the selection of folders. If * 'cancel' is pressed this method terminates the MotherMachine app. * * @param guiFrame/*from w ww . j av a2 s.c o m*/ * parent frame * @param path * path to the folder to open initially * @return an instance of {@link File} pointing at the selected folder. */ private File showFolderChooser(final JFrame guiFrame, final String path) { File selectedFile = null; if (SystemUtils.IS_OS_MAC) { // --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- System.setProperty("apple.awt.fileDialogForDirectories", "true"); final FileDialog fd = new FileDialog(guiFrame, "Select folder containing image sequence...", FileDialog.LOAD); fd.setDirectory(path); // fd.setLocation(50,50); fd.setVisible(true); selectedFile = new File(fd.getDirectory() + "/" + fd.getFile()); if (fd.getFile() == null) { System.exit(0); return null; } System.setProperty("apple.awt.fileDialogForDirectories", "false"); } else { // --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(path)); chooser.setDialogTitle("Select folder containing image sequence..."); chooser.setFileFilter(new FileFilter() { @Override public final boolean accept(final File file) { return file.isDirectory(); } @Override public String getDescription() { return "We only take directories"; } }); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(guiFrame) == JFileChooser.APPROVE_OPTION) { selectedFile = chooser.getSelectedFile(); } else { System.exit(0); return null; } } return selectedFile; }
From source file:com.dfki.av.sudplan.ui.MainFrame.java
private void miOpenDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miOpenDataActionPerformed try {//from ww w . j a va 2 s . com String cmd = evt.getActionCommand(); final JFileChooser fc = new JFileChooser(); FileFilter fileFilter; // Set file filter.. if (cmd.equalsIgnoreCase(miOpenKMLFile.getActionCommand())) { fileFilter = new FileNameExtensionFilter("KML/KMZ File", "kml", "kmz"); } else if (cmd.equalsIgnoreCase(miAddGeoTiff.getActionCommand())) { fileFilter = new FileNameExtensionFilter("GeoTiff File ( *.tif, *.tiff)", "tif", "tiff"); } else if (cmd.equalsIgnoreCase(miAddShape.getActionCommand())) { fileFilter = new FileNameExtensionFilter("ESRI Shapefile (*.shp)", "shp", "SHP"); } else if (cmd.equalsIgnoreCase(miAddShapeZip.getActionCommand())) { fileFilter = new FileNameExtensionFilter("ESRI Shapefile ZIP (*.zip)", "zip", "ZIP"); } else { log.warn("No valid action command."); fileFilter = null; } fc.setFileFilter(fileFilter); // Set latest working directory... XMLConfiguration xmlConfig = Configuration.getXMLConfiguration(); String path = xmlConfig.getString("sudplan3D.working.dir"); File dir; if (path != null) { dir = new File(path); if (dir.exists()) { fc.setCurrentDirectory(dir); } } // Show dialog... int ret = fc.showOpenDialog(this); // Save currently selected working directory... dir = fc.getCurrentDirectory(); path = dir.getAbsolutePath(); xmlConfig.setProperty("sudplan3D.working.dir", path); if (ret != JFileChooser.APPROVE_OPTION) { return; } if (cmd.equalsIgnoreCase(miOpenKMLFile.getActionCommand())) { wwPanel.addKMLLayer(fc.getSelectedFile()); } else if (cmd.equalsIgnoreCase(miAddGeoTiff.getActionCommand())) { wwPanel.addGeoTiffLayer(fc.getSelectedFile()); } else if (cmd.equalsIgnoreCase(miAddShape.getActionCommand()) || cmd.equalsIgnoreCase(miAddShapeZip.getActionCommand())) { IVisAlgorithm algo = VisAlgorithmFactory.newInstance(VisPointCloud.class.getName()); if (algo != null) { wwPanel.addLayer(fc.getSelectedFile(), algo, null); } else { log.error("VisAlgorithm {} not supported.", VisPointCloud.class.getName()); JOptionPane.showMessageDialog(this, "Algorithm not supported.", "Error", JOptionPane.ERROR_MESSAGE); } } else { log.warn("No valid action command."); } } catch (Exception ex) { log.error(ex.toString()); JOptionPane.showMessageDialog(this, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:io.github.jeremgamer.editor.panels.components.PanelsPanel.java
public PanelsPanel(JFrame frame, final PanelSave ps) { this.ps = ps; this.frame = frame; this.setSize(new Dimension(395, frame.getHeight() - 27 - 23)); this.setLocation(300, 0); this.setBorder(BorderFactory.createTitledBorder("Edition du panneau")); JPanel content = new JPanel(); JScrollPane scroll = new JScrollPane(content); scroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); scroll.setBorder(null);/*from www .j ava2 s.com*/ content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); scroll.setPreferredSize(new Dimension(382, frame.getHeight() - 27 - 46 - 20)); JPanel namePanel = new JPanel(); name.setPreferredSize(new Dimension(this.getWidth() - 280, 30)); name.setEditable(false); namePanel.add(new JLabel("Nom :")); namePanel.add(name); namePanel.add(Box.createRigidArea(new Dimension(10, 1))); layout.addItem("Basique"); layout.addItem("Bordures"); layout.addItem("Ligne"); layout.addItem("Colonne"); layout.addItem("Grille"); layout.addItem("Empil"); layout.setPreferredSize(new Dimension(110, 30)); layout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); cl.show(advanced, listContent[combo.getSelectedIndex()]); ps.set("layout", combo.getSelectedIndex()); ActionPanel.updateLists(); } }); namePanel.add(new JLabel("Disposition :")); namePanel.add(layout); namePanel.setPreferredSize(new Dimension(365, 50)); namePanel.setMaximumSize(new Dimension(365, 50)); content.add(namePanel); advanced.setPreferredSize(new Dimension(365, 300)); advanced.setMaximumSize(new Dimension(365, 300)); advanced.add(ble, listContent[0]); advanced.add(brdle, listContent[1]); advanced.add(lle, listContent[2]); advanced.add(rle, listContent[3]); advanced.add(gle, listContent[4]); advanced.add(cle, listContent[5]); content.add(advanced); topBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.top", combo.getSelectedItem()); } }); leftBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.left", combo.getSelectedItem()); } }); centerBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.center", combo.getSelectedItem()); } }); rightBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.right", combo.getSelectedItem()); } }); bottomBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.bottom", combo.getSelectedItem()); } }); JPanel prefSize = new JPanel(); prefSize.setPreferredSize(new Dimension(365, 110)); prefSize.setMaximumSize(new Dimension(365, 110)); prefSize.setBorder(BorderFactory.createTitledBorder("Taille prfre")); JPanel prefSizePanel = new JPanel(); prefSizePanel.setLayout(new GridLayout(2, 4)); prefSizePanel.setPreferredSize(new Dimension(300, 55)); prefSizePanel.setMaximumSize(new Dimension(300, 55)); prefSizePanel.add(prefSizeEnabled); prefSizePanel.add(new JLabel("")); prefSizePanel.add(new JLabel("")); prefSizePanel.add(new JLabel("(en pixels)")); prefSizePanel.add(new JLabel("Largeur :")); prefSizePanel.add(prefWidth); prefSizePanel.add(new JLabel("Hauteur :")); prefSizePanel.add(prefHeight); prefWidth.setEnabled(false); prefHeight.setEnabled(false); prefSizeEnabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JCheckBox check = (JCheckBox) event.getSource(); ps.set("preferredSize", check.isSelected()); prefWidth.setEnabled(check.isSelected()); prefHeight.setEnabled(check.isSelected()); } }); prefWidth.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("preferredWidth", spinner.getValue()); } }); prefHeight.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("preferredHeight", spinner.getValue()); } }); prefSize.add(prefSizePanel); content.add(prefSize); JPanel insetsPanel = new JPanel(); insetsPanel.setBorder(BorderFactory.createTitledBorder("carts")); insetsPanel.setPreferredSize(new Dimension(365, 100)); insetsPanel.setMaximumSize(new Dimension(365, 100)); JPanel insetsContent = new JPanel(); insetsContent.setLayout(new BoxLayout(insetsContent, BoxLayout.PAGE_AXIS)); JPanel insetInput = new JPanel(); insetInput.setLayout(new GridLayout(2, 4)); insetInput.add(insetsEnabled); insetInput.add(new JLabel("")); insetInput.add(new JLabel("")); insetInput.add(new JLabel("(en pixels)")); insetInput.add(new JLabel("Horizontaux :")); insetInput.add(insetHz); insetInput.add(new JLabel("Verticaux :")); insetInput.add(insetVt); insetsEnabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JCheckBox check = (JCheckBox) event.getSource(); if (check.isSelected()) { insetHz.setEnabled(true); insetVt.setEnabled(true); ps.set("insets", true); } else { insetHz.setEnabled(true); insetVt.setEnabled(true); ps.set("insets", false); } } }); insetHz.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("insets.horizontal", spinner.getValue()); } }); insetVt.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("insets.vertical", spinner.getValue()); } }); insetsContent.add(insetInput); insetsPanel.add(insetsContent); content.add(insetsPanel); JPanel web = new JPanel(); web.setPreferredSize(new Dimension(365, 100)); web.setMaximumSize(new Dimension(365, 100)); web.setBorder(BorderFactory.createTitledBorder("Page Web")); JPanel webContent = new JPanel(); webContent.setLayout(new BorderLayout()); webContent.add(webEnabled, BorderLayout.NORTH); webEnabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox check = (JCheckBox) e.getSource(); ps.set("web", check.isSelected()); if (check.isSelected() == true) { layout.setSelectedIndex(0); layout.setEnabled(false); ble.removeAllComponents(); ble.disableComponents(); adress.setEnabled(true); } else { ble.enableComponents(); layout.setEnabled(true); adress.setEnabled(false); } } }); JPanel webInput = new JPanel(); webInput.add(new JLabel("Adresse :")); adress.setPreferredSize(new Dimension(250, 30)); CaretListener caretUpdate = new CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { JTextField text = (JTextField) e.getSource(); ps.set("web.adress", text.getText()); } }; adress.addCaretListener(caretUpdate); webInput.add(adress); webContent.add(webInput, BorderLayout.CENTER); web.add(webContent); JPanel background = new JPanel(); BorderLayout bLayout = new BorderLayout(); bLayout.setVgap(12); background.setLayout(bLayout); background.setBorder(BorderFactory.createTitledBorder("Couleur de fond")); background.setPreferredSize(new Dimension(365, 210)); background.setMaximumSize(new Dimension(365, 210)); cp.setPreferredSize(new Dimension(347, 145)); cp.setMaximumSize(new Dimension(347, 145)); opaque.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox check = (JCheckBox) e.getSource(); ps.set("background.opaque", check.isSelected()); cp.enableComponents(check.isSelected()); } }); background.add(opaque, BorderLayout.NORTH); background.add(cp, BorderLayout.CENTER); JPanel image = new JPanel(); image.setBorder(BorderFactory.createTitledBorder("Image de fond")); image.setPreferredSize(new Dimension(365, 125)); image.setMaximumSize(new Dimension(365, 125)); image.setLayout(new BorderLayout()); try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.setEnabled(false); remove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { File img = new File( "projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png"); if (img.exists()) { img.delete(); } browseImage.setEnabled(true); } }); JPanel top = new JPanel(); browseImage.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JButton button = (JButton) e.getSource(); String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "background.png"); nameBackground.setText(new File(path).getName()); ps.set("background.image", new File(path).getName()); button.setEnabled(false); size.setEnabled(true); size2.setEnabled(true); remove.setEnabled(true); } } }); bg.add(size); bg.add(size2); JPanel sizePanel = new JPanel(); sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.PAGE_AXIS)); size.setEnabled(false); size2.setEnabled(false); sizePanel.add(size); sizePanel.add(size2); size.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ps.set("background.size", 0); } }); size2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ps.set("background.size", 1); } }); top.add(browseImage); top.add(sizePanel); remove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JButton button = (JButton) event.getSource(); new File("projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png") .delete(); nameBackground.setText(""); ps.set("background.image", ""); button.setEnabled(false); } }); nameBackground.setFont(new Font("Sans Serif", Font.PLAIN, 15)); JPanel center = new JPanel(new BorderLayout()); center.add(nameBackground, BorderLayout.CENTER); center.add(remove, BorderLayout.EAST); image.add(top, BorderLayout.NORTH); image.add(center, BorderLayout.CENTER); content.add(web); content.add(background); content.add(image); this.add(scroll); }
From source file:com.openbravo.pos.util.JRViewer411.java
void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed // Add your handling code here: JFileChooser fileChooser = new JFileChooser(); fileChooser.setLocale(this.getLocale()); fileChooser.updateUI();/*w w w . ja v a 2 s. c o m*/ for (int i = 0; i < saveContributors.size(); i++) { fileChooser.addChoosableFileFilter(saveContributors.get(i)); } if (saveContributors.contains(lastSaveContributor)) { fileChooser.setFileFilter(lastSaveContributor); } else if (saveContributors.size() > 0) { fileChooser.setFileFilter(saveContributors.get(0)); } if (lastFolder != null) { fileChooser.setCurrentDirectory(lastFolder); } int retValue = fileChooser.showSaveDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { FileFilter fileFilter = fileChooser.getFileFilter(); File file = fileChooser.getSelectedFile(); lastFolder = file.getParentFile(); JRSaveContributor contributor = null; if (fileFilter instanceof JRSaveContributor) { contributor = (JRSaveContributor) fileFilter; } else { int i = 0; while (contributor == null && i < saveContributors.size()) { contributor = saveContributors.get(i++); if (!contributor.accept(file)) { contributor = null; } } if (contributor == null) { contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle); } } lastSaveContributor = contributor; try { contributor.save(jasperPrint, file); } catch (JRException e) { if (log.isErrorEnabled()) { log.error("Save error.", e); } JOptionPane.showMessageDialog(this, getBundleString("error.saving")); } } }
From source file:net.rptools.maptool.launcher.MapToolLauncher.java
private JPanel buildBasicPanel() { final JPanel p = new JPanel(); p.setLayout(new BorderLayout()); // BASIC: Top panel final JPanel logoPanel = new JPanel(); logoPanel.setLayout(new FlowLayout()); logoPanel.setBorder(/*from w w w . jav a 2s . c o m*/ new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logoPanel.border"))); //$NON-NLS-1$ jlMTLogo.setIcon(icon); logoPanel.add(jlMTLogo); // BASIC: Middle panel final JPanel memPanel = new JPanel(); memPanel.setLayout(new GridLayout(3, 2)); memPanel.setBorder(new LineBorder(Color.WHITE)); jtfMaxMem.setHorizontalAlignment(SwingConstants.RIGHT); jtfMaxMem.setInfo(CopiedFromOtherJars.getText("msg.info.javaMaxMem", DEFAULT_MAXMEM)); //$NON-NLS-1$ jtfMaxMem.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaMaxMem")); //$NON-NLS-1$ jtfMaxMem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { jtfMaxMemActionPerformed(evt); } }); jtfMaxMem.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent evt) { jtfMaxMemFocusLost(evt); } @Override public void focusGained(FocusEvent evt) { jtfMaxMemFocusLost(evt); } }); jtfMaxMem.addKeyListener(new InputValidator()); jtfMinMem.setHorizontalAlignment(SwingConstants.RIGHT); jtfMinMem.setInfo(CopiedFromOtherJars.getText("msg.info.javaMinMem", DEFAULT_MINMEM)); //$NON-NLS-1$ jtfMinMem.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaMinMem")); //$NON-NLS-1$ jtfMinMem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { jtfMinMemActionPerformed(evt); } }); jtfMinMem.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent evt) { jtfMinMemFocusLost(evt); } @Override public void focusGained(FocusEvent evt) { jtfMinMemFocusLost(evt); } }); jtfMinMem.addKeyListener(new InputValidator()); jtfStackSize.setHorizontalAlignment(SwingConstants.RIGHT); jtfStackSize.setInfo(CopiedFromOtherJars.getText("msg.info.javaStackSize", DEFAULT_STACKSIZE)); //$NON-NLS-1$ jtfStackSize.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaStackSize")); //$NON-NLS-1$ jtfStackSize.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { jtfStackSizeActionPerformed(evt); } }); jtfStackSize.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent evt) { jtfStackSizeFocusLost(evt); } @Override public void focusGained(FocusEvent evt) { jtfStackSizeFocusLost(evt); } }); jtfStackSize.addKeyListener(new InputValidator()); memPanel.add(jtfMaxMem); memPanel.add(jtfMinMem); memPanel.add(jtfStackSize); // BASIC: Bottom panel final JPanel southPanel = new JPanel(); southPanel.setLayout(new BorderLayout()); final JPanel cbPanel = new JPanel(); cbPanel.setLayout(new GridLayout(2, 1)); cbPanel.setBorder(new LineBorder(Color.GRAY)); jcbPromptUser.setSelected(true); jcbPromptUser.setText(CopiedFromOtherJars.getText("msg.info.promptAtNextLaunch")); //$NON-NLS-1$ jcbPromptUser.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.promptAtNextLaunch")); //$NON-NLS-1$ jcbPromptUser.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { promptUser = jcbPromptUser.isSelected(); } }); jbMTJar.setText(jbMTJarText); jbMTJar.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.registerMapToolJar")); //$NON-NLS-1$ jbMTJar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter filter = new FileNameExtensionFilter( CopiedFromOtherJars.getText("msg.chooser.javaExecutable"), "jar"); //$NON-NLS-1$ //$NON-NLS-2$ jfc.addChoosableFileFilter(filter); jfc.setFileFilter(filter); if (IS_MAC) { filter = new FileNameExtensionFilter( CopiedFromOtherJars.getText("msg.chooser.appleApplicationBundle"), "app"); //$NON-NLS-1$ //$NON-NLS-2$ jfc.addChoosableFileFilter(filter); } jfc.setCurrentDirectory(mapToolJarDir); final int returnVal = jfc.showOpenDialog(jbMTJar); if (returnVal == JFileChooser.APPROVE_OPTION) { final File f = jfc.getSelectedFile(); final String fileName = f.getName(); if (IS_MAC && fileName.endsWith(".app")) { //$NON-NLS-1$ File jarDir = new File(f.getParentFile(), fileName); if (jarDir.isDirectory()) { jarDir = new File(jarDir, "Contents/Resources/Java"); //$NON-NLS-1$ if (jarDir.isDirectory()) { mapToolJarDir = jarDir; mapToolJarName = fileName.replace(".app", ".jar"); //$NON-NLS-1$ //$NON-NLS-2$ } else { logMsg(Level.SEVERE, "{0} does not contain 'Contents/Resources/Java' like it should!", //$NON-NLS-1$ "msg.chooser.badAppLocation", jarDir); //$NON-NLS-1$ return; } } else { logMsg(Level.SEVERE, "{0} is not a directory and it should be!", //$NON-NLS-1$ "msg.chooser.badAppLocation", jarDir); //$NON-NLS-1$ return; } } else { mapToolJarName = fileName; mapToolJarDir = f.getParentFile(); } logMsg(Level.INFO, f.toString(), null); jbMTJar.setText(fileName.replace(".jar", EMPTY)); //$NON-NLS-1$ if (fileName.toLowerCase().startsWith("maptool-")) { // We expect the name matches 'maptool-1.3.b89.jar' mapToolVersion = " " + fileName.substring(8, 11); } else { logMsg(Level.SEVERE, "Cannot determine MapTool version number from JAR filename: {0}", //$NON-NLS-1$ "msg.info.noMapToolVersion", fileName); mapToolVersion = EMPTY; } jbLaunch.setEnabled(true); updateCommand(); jbLaunch.requestFocusInWindow(); } } }); cbPanel.add(jcbPromptUser); cbPanel.add(jbMTJar); southPanel.add(cbPanel, BorderLayout.CENTER); p.add(memPanel, BorderLayout.CENTER); p.add(logoPanel, BorderLayout.NORTH); p.add(southPanel, BorderLayout.SOUTH); p.setBorder(new LineBorder(Color.BLACK)); return p; }
From source file:org.fhaes.jsea.JSEAFrame.java
@Override public void actionPerformed(ActionEvent event) { if (event.getActionCommand().equals("SegmentationMode")) { Boolean $success = this.validateDataFiles(); if ($success == null) { log.debug("Files not set yet"); return; } else if ($success == false) { log.debug("Invalid file ranges"); return; }/* ww w .j a v a 2 s . co m*/ if (segmentationPanel.chkSegmentation.isSelected() && chronologyYears.size() > 1) { segmentationPanel.table.setEarliestYear(Integer.parseInt(this.firstPossibleYear.toString())); segmentationPanel.table.setLatestYear(Integer.parseInt(this.lastPossibleYear.toString())); } else { // cannot perform segmentation if there are less than 2 years in the chronology segmentationPanel.chkSegmentation.setSelected(false); } } else if (event.getActionCommand().equals("AllYearsCheckbox")) { setYearRangeGUI(); } else if (event.getActionCommand().equals("TimeSeriesFileBrowse")) { String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_READ_TIME_SERIES_FOLDER, App.prefs.getPref(PrefKey.PREF_LAST_READ_FOLDER, null)); JFileChooser fc; if (lastVisitedFolder != null) { fc = new JFileChooser(lastVisitedFolder); } else { fc = new JFileChooser(); } fc.setMultiSelectionEnabled(false); fc.setDialogTitle("Open file"); fc.addChoosableFileFilter(new TXTFileFilter()); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(new CSVFileFilter()); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { txtTimeSeriesFile.setText(fc.getSelectedFile().getAbsolutePath()); txtwrapper.updatePref(); App.prefs.setPref(PrefKey.PREF_LAST_READ_TIME_SERIES_FOLDER, fc.getSelectedFile().getPath()); if (parseTimeSeriesFile()) { setYearRangeGUI(); } else { txtTimeSeriesFile.setText(""); } validateForm(); } } else if (event.getActionCommand().equals("EventListFileBrowse")) { String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_READ_EVENT_LIST_FOLDER, App.prefs.getPref(PrefKey.PREF_LAST_READ_FOLDER, null)); JFileChooser fc; if (lastVisitedFolder != null) { fc = new JFileChooser(lastVisitedFolder); } else { fc = new JFileChooser(); } fc.setMultiSelectionEnabled(false); fc.setDialogTitle("Open file"); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { txtEventListFile.setText(fc.getSelectedFile().getAbsolutePath()); App.prefs.setPref(PrefKey.PREF_LAST_READ_EVENT_LIST_FOLDER, fc.getSelectedFile().getPath()); parseEventListFile(); validateForm(); } } }
From source file:neg.JRViewer.java
void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed // Add your handling code here: JFileChooser fileChooser = new JFileChooser(); fileChooser.setLocale(this.getLocale()); fileChooser.updateUI();// w w w. j ava 2 s. c o m for (int i = 0; i < saveContributors.size(); i++) { fileChooser.addChoosableFileFilter((JRSaveContributor) saveContributors.get(i)); } if (saveContributors.contains(lastSaveContributor)) { fileChooser.setFileFilter(lastSaveContributor); } else if (saveContributors.size() > 0) { fileChooser.setFileFilter((JRSaveContributor) saveContributors.get(0)); } if (lastFolder != null) { fileChooser.setCurrentDirectory(lastFolder); } int retValue = fileChooser.showSaveDialog(this); if (retValue == JFileChooser.APPROVE_OPTION) { FileFilter fileFilter = fileChooser.getFileFilter(); File file = fileChooser.getSelectedFile(); lastFolder = file.getParentFile(); JRSaveContributor contributor = null; if (fileFilter instanceof JRSaveContributor) { contributor = (JRSaveContributor) fileFilter; } else { int i = 0; while (contributor == null && i < saveContributors.size()) { contributor = (JRSaveContributor) saveContributors.get(i++); if (!contributor.accept(file)) { contributor = null; } } if (contributor == null) { contributor = new JRPrintSaveContributor(getLocale(), this.resourceBundle); } } lastSaveContributor = contributor; try { contributor.save(jasperPrint, file); } catch (JRException e) { if (log.isErrorEnabled()) log.error("Save error.", e); JOptionPane.showMessageDialog(this, getBundleString("error.saving")); } } }