List of usage examples for javax.swing.filechooser FileFilter FileFilter
FileFilter
From source file:org.zeromeaner.gui.reskin.StandaloneFrame.java
private void createCards() { introPanel = new StandaloneLicensePanel(); content.add(introPanel, CARD_INTRO); playCard = new JPanel(new BorderLayout()); content.add(playCard, CARD_PLAY);//from w w w . java2 s.com JPanel confirm = new JPanel(new GridBagLayout()); JOptionPane option = new JOptionPane("A game is in open. End this game?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); option.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!CARD_PLAY_END.equals(currentCard)) return; if (evt.getNewValue().equals(JOptionPane.YES_OPTION)) { gamePanel.shutdown(); try { gamePanel.shutdownWait(); } catch (InterruptedException ie) { } contentCards.show(content, nextCard); currentCard = nextCard; } if (evt.getNewValue().equals(JOptionPane.NO_OPTION)) { contentCards.show(content, CARD_PLAY); currentCard = CARD_PLAY; playButton.setSelected(true); } ((JOptionPane) evt.getSource()).setValue(-1); } }); GridBagConstraints cx = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0); confirm.add(option, cx); content.add(confirm, CARD_PLAY_END); content.add(new StandaloneModeselectPanel(), CARD_MODESELECT); netplayCard = new JPanel(new BorderLayout()); netplayCard.add(netLobby, BorderLayout.SOUTH); content.add(netplayCard, CARD_NETPLAY); confirm = new JPanel(new GridBagLayout()); option = new JOptionPane("A netplay game is open. End this game and disconnect?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); option.addPropertyChangeListener(JOptionPane.VALUE_PROPERTY, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!CARD_NETPLAY_END.equals(currentCard)) return; if (evt.getNewValue().equals(JOptionPane.YES_OPTION)) { gamePanel.shutdown(); try { gamePanel.shutdownWait(); } catch (InterruptedException ie) { } netLobby.disconnect(); contentCards.show(content, nextCard); currentCard = nextCard; } if (evt.getNewValue().equals(JOptionPane.NO_OPTION)) { contentCards.show(content, CARD_NETPLAY); currentCard = CARD_NETPLAY; netplayButton.setSelected(true); } ((JOptionPane) evt.getSource()).setValue(-1); } }); cx = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0); confirm.add(option, cx); content.add(confirm, CARD_NETPLAY_END); StandaloneKeyConfig kc = new StandaloneKeyConfig(this); kc.load(0); content.add(kc, CARD_KEYS_1P); kc = new StandaloneKeyConfig(this); kc.load(1); content.add(kc, CARD_KEYS_2P); StandaloneGameTuningPanel gt = new StandaloneGameTuningPanel(); gt.load(0); content.add(gt, CARD_TUNING_1P); gt = new StandaloneGameTuningPanel(); gt.load(1); content.add(gt, CARD_TUNING_2P); StandaloneAISelectPanel ai = new StandaloneAISelectPanel(); ai.load(0); content.add(ai, CARD_AI_1P); ai = new StandaloneAISelectPanel(); ai.load(1); content.add(ai, CARD_AI_2P); StandaloneGeneralConfigPanel gc = new StandaloneGeneralConfigPanel(); gc.load(); content.add(gc, CARD_GENERAL); final JFileChooser fc = FileSystemViews.get().fileChooser("replay/"); fc.setFileFilter(new FileFilter() { @Override public String getDescription() { return "Zeromeaner Replay Files"; } @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".zrep"); } }); fc.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!e.getActionCommand().equals(JFileChooser.APPROVE_SELECTION)) return; JFileChooser fc = (JFileChooser) e.getSource(); String path = fc.getSelectedFile().getPath(); if (!path.contains("replay/")) path = "replay/" + path; startReplayGame(path); } }); fc.addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { fc.rescanCurrentDirectory(); } }); content.add(fc, CARD_OPEN); content.add(new StandaloneFeedbackPanel(), CARD_FEEDBACK); }
From source file:pcgui.SetupParametersPanel.java
/** * Create the frame.//from ww w . ja v a 2 s. co m * * @param switcher * * @param rootFrame */ public SetupParametersPanel(final PanelSwitcher switcher, JFrame rootFrame) { this.rootFrame = rootFrame; setLayout(new BorderLayout()); JLabel headingLabel = new JLabel("Setup Parameters"); headingLabel.setFont(new Font("Tahoma", Font.BOLD, 16)); add(headingLabel, BorderLayout.NORTH); JButton saveBtn = new JButton("Save"); final JButton runModifiedBtn = new JButton("Run"); runModifiedBtn.setEnabled(false); runModifiedBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { runModel(); } }); saveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //creating separate copy of model so that changes in one doesn't effect other ArrayList<ArrayList<Object>> mod = new ArrayList<ArrayList<Object>>(model.getData()); //call save model of modelsaver //TODO add visualization list and save to excel using similar method as below //TODO add modelname, should contain .xls/.xlsx extension SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss"); outputFile = importedFile.toString().replace(".mos", "") + "_" + sdf.format(new Date()) + "_FEORA_solution.xlsx"; ModelSaver.saveInputModel(mod, outputFile); runModifiedBtn.setEnabled(true); } }); JLabel label = new JLabel("Enter count of random value runs"); repeatCount = new JTextField(); repeatCount.setToolTipText("Enter count for which each combination of step variables is run "); repeatCount.setText("1"); repeatCount.setPreferredSize(new Dimension(100, 20)); JPanel runConfig = new JPanel(); runConfig.setLayout(new GridLayout(2, 2)); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.CENTER; JPanel configCount = new JPanel(new FlowLayout()); JPanel configButtons = new JPanel(new FlowLayout()); configCount.add(label); configCount.add(repeatCount); JButton btnLoadSavedConfiguration = new JButton("Load Saved Configuration"); btnLoadSavedConfiguration.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser jFileChooser = new JFileChooser(); File workingDirectory = new File(System.getProperty("user.dir")); jFileChooser.setCurrentDirectory(workingDirectory); jFileChooser.setFileFilter(new FileFilter() { @Override public String getDescription() { // TODO Auto-generated method stub return "Excel solution files"; } @Override public boolean accept(File f) { // TODO Auto-generated method stub return f.isDirectory() || f.getName().endsWith(".xls") || f.getName().endsWith(".xlsx"); } }); int returnVal = jFileChooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = jFileChooser.getSelectedFile(); // This is where a real application would open the file. if (file.getName().endsWith(".xls") || file.getName().endsWith(".xlsx")) { String fileName = file.getAbsolutePath(); List<List<String>> savedConfig = ModelSaver.loadInputConfigFromExcel(fileName); ArrayList<Symbol> symList = new ArrayList<Symbol>(); int i = 0; for (List<String> list : savedConfig) { //ignore the header row if (i > 0) { System.out.println("VariableName=" + list.get(0)); System.out.println("Datatype=" + list.get(1)); System.out.println("Type=" + list.get(2)); System.out.println("Value=" + list.get(3)); System.out.println("ExternalFile=" + list.get(4)); System.out.println("ExcelRange=" + list.get(5)); System.out.println("DistributionFunction=" + list.get(6)); System.out.println("OutputTracket=" + list.get(7)); Symbol sym = new Symbol<>(); sym.name = list.get(0); sym.typeString = list.get(1); sym.mode = list.get(2); sym.set(list.get(3)); sym.externalFile = list.get(4); sym.excelFileRange = list.get(5); sym.distFunction = list.get(6); sym.trackingEnabled = Boolean.parseBoolean(list.get(7)); symList.add(sym); } i++; } initParamList(symList, parser); } } else { // System.out.println("Open command cancelled by user."); } } }); configButtons.add(btnLoadSavedConfiguration); configButtons.add(saveBtn); configButtons.add(runModifiedBtn); runConfig.add(configCount); runConfig.add(configButtons); add(runConfig, BorderLayout.SOUTH); setVisible(true); }
From source file:pl.otros.logview.gui.Log4jPatternParserEditor.java
protected void saveParser() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(AllPluginables.USER_LOG_IMPORTERS); chooser.addChoosableFileFilter(new FileFilter() { @Override// w w w. j av a 2s . c om public String getDescription() { return "*.pattern files"; } @Override public boolean accept(File f) { return f.getName().endsWith(".pattern") || f.isDirectory(); } }); int showSaveDialog = chooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); if (!selectedFile.getName().endsWith(".pattern")) { selectedFile = new File(selectedFile.getAbsolutePath() + ".pattern"); } if (selectedFile.exists() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(this, "Do you want to overwrite file " + selectedFile.getName() + "?", "Save parser", JOptionPane.YES_NO_OPTION)) { return; } String text = propertyEditor.getText(); FileOutputStream output = null; try { output = new FileOutputStream(selectedFile); IOUtils.write(text, output); LogImporterUsingParser log4jImporter = createLog4jImporter(text); otrosApplication.getAllPluginables().getLogImportersContainer().addElement(log4jImporter); } catch (Exception e) { LOGGER.severe("Can't save parser: " + e.getMessage()); JOptionPane.showMessageDialog(this, "Can't save parser: " + e.getMessage(), "Error saving parser", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } finally { IOUtils.closeQuietly(output); } } }
From source file:pl.otros.logview.gui.markers.editor.NewMarkerAction.java
public NewMarkerAction() { super();//from w w w .ja v a 2 s.c o m putValue(NAME, "New marker"); if (!markersFolder.exists()) { markersFolder.mkdirs(); } chooser = new JFileChooser(markersFolder); chooser.setFileFilter(new FileFilter() { @Override public String getDescription() { return "*.marker"; } @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".marker"); } }); }
From source file:pl.otros.logview.gui.message.editor.MessageColorizerBrowser.java
private void initFileChooser() { File rootDirectory = AllPluginables.USER_MESSAGE_FORMATTER_COLORZIERS; DirectoryRestrictedFileSystemView view = new DirectoryRestrictedFileSystemView(rootDirectory); chooser = new JFileChooser(rootDirectory, view); chooser.setFileFilter(new FileFilter() { @Override//from ww w. j a va 2 s. co m public String getDescription() { return "*.pattern"; } @Override public boolean accept(File f) { return f.isFile() && f.getName().endsWith("pattern"); } }); }
From source file:uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetDisplay.java
public void actionPerformed(ActionEvent ae) { /* if (ae.getActionCommand().equals("plot")) { /*w w w . j a v a 2s .c o m*/ drawScatterPlot(); } */ if (ae.getActionCommand().equals("save_image")) { ImageSaver.saveImage(scatterPlotPanel); } else if (ae.getActionCommand().equals("swap_plot")) { if (storesQuantitated()) { plotPanel.remove(scatterPlotPanel); if (scatterPlotPanel instanceof GeneSetScatterPlotPanel) { scatterPlotPanel = new ZScoreScatterPlotPanel(fromStore, toStore, probes, currentSelectedProbeList, dotSizeSlider.getValue(), zScoreLookupTable); plotPanel.add(scatterPlotPanel, BorderLayout.CENTER); swapPlotButton.setText("Display standard scatterplot"); } else if (scatterPlotPanel instanceof ZScoreScatterPlotPanel) { scatterPlotPanel = new GeneSetScatterPlotPanel(fromStore, toStore, startingProbeList, currentSelectedProbeList, true, dotSizeSlider.getValue(), customRegressionValues, simpleRegression); plotPanel.add(scatterPlotPanel, BorderLayout.CENTER); swapPlotButton.setText("Display z-score plot"); } } } else if (ae.getActionCommand().equals("close")) { /* if(currentSelectedProbeList != null){ currentSelectedProbeList[0].delete(); //currentSelectedProbeList = null; } */ this.dispose(); } else if (ae.getActionCommand().equals("select_all")) { if (selectAllButton.isSelected()) { for (int i = 0; i < tableModel.selected.length; i++) { tableModel.selected[i] = true; tableModel.fireTableCellUpdated(i, 0); } selectAllButton.setText("deselect all"); } else { for (int i = 0; i < tableModel.selected.length; i++) { tableModel.selected[i] = false; tableModel.fireTableCellUpdated(i, 0); } selectAllButton.setText("select all"); } } else if (ae.getActionCommand().equals("save_selected_probelists")) { boolean[] selectedListsBoolean = tableModel.selected; if (selectedListsBoolean.length != filterResultsPVals.length) { System.err.println("not adding up here"); } else { ArrayList<MappedGeneSetTTestValue> selectedListsArrayList = new ArrayList<MappedGeneSetTTestValue>(); for (int i = 0; i < selectedListsBoolean.length; i++) { if (selectedListsBoolean[i] == true) { selectedListsArrayList.add(filterResultsPVals[i]); } } MappedGeneSetTTestValue[] selectedLists = selectedListsArrayList .toArray(new MappedGeneSetTTestValue[0]); if (selectedLists.length == 0) { JOptionPane.showMessageDialog(SeqMonkApplication.getInstance(), "No probe lists were selected", "No probe lists selected", JOptionPane.INFORMATION_MESSAGE); return; } saveProbeLists(selectedLists); if (currentSelectedProbeList != null) { currentSelectedProbeList[0].delete(); currentSelectedProbeList = null; } } } else if (ae.getActionCommand().equals("save_table")) { JFileChooser chooser = new JFileChooser(SeqMonkPreferences.getInstance().getSaveLocation()); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new FileFilter() { public String getDescription() { return "Text files"; } public boolean accept(File f) { if (f.isDirectory() || f.getName().toLowerCase().endsWith(".txt")) { return true; } else { return false; } } }); int result = chooser.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) return; File file = chooser.getSelectedFile(); if (!file.getPath().toLowerCase().endsWith(".txt")) { file = new File(file.getPath() + ".txt"); } SeqMonkPreferences.getInstance().setLastUsedSaveLocation(file); // Check if we're stepping on anyone's toes... if (file.exists()) { int answer = JOptionPane.showOptionDialog(this, file.getName() + " exists. Do you want to overwrite the existing file?", "Overwrite file?", 0, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Overwrite and Save", "Cancel" }, "Overwrite and Save"); if (answer > 0) { return; } } try { PrintWriter p = new PrintWriter(new FileWriter(file)); TableModel model = table.getModel(); int rowCount = model.getRowCount(); int colCount = model.getColumnCount(); // Do the headers first StringBuffer b = new StringBuffer(); for (int c = 1; c < colCount; c++) { b.append(model.getColumnName(c)); if (c + 1 != colCount) { b.append("\t"); } } p.println(b); for (int r = 0; r < rowCount; r++) { b = new StringBuffer(); for (int c = 1; c < colCount; c++) { b.append(model.getValueAt(r, c)); if (c + 1 != colCount) { b.append("\t"); } } p.println(b); } p.close(); } catch (FileNotFoundException e) { new CrashReporter(e); } catch (IOException e) { new CrashReporter(e); } } else { throw new IllegalArgumentException("Unknown command " + ae.getActionCommand()); } }
From source file:uk.co.danielrendall.imagetiler.gui.FileChoosers.java
public FileChoosers(ResourceMap appResourceMap) { openFileChooser = createFileChooser("openFileChooser", new FileFilter() { private final java.io.FileFilter delegate = new OrFileFilter(new SuffixFileFilter("bmp"), DirectoryFileFilter.INSTANCE); @Override//ww w .j a v a2 s. c o m public boolean accept(File f) { return delegate.accept(f); } @Override public String getDescription() { return "BMP Files"; } }, appResourceMap); saveFileChooser = createFileChooser("saveFileChooser", new FileFilter() { private final java.io.FileFilter delegate = new SuffixFileFilter("svg"); @Override public boolean accept(File f) { return delegate.accept(f); } @Override public String getDescription() { return "SVG Files"; } }, appResourceMap); }
From source file:unikn.dbis.univis.explorer.VExplorer.java
License:asdf
private void initMenuBar() { JMenuBar menuBar = new JMenuBar(); VMenu program = new VMenu(Constants.PROGRAM); VMenuItem schemaImport = new VMenuItem(Constants.SCHEMA_IMPORT, VIcons.SCHEMA_IMPORT); schemaImport.setAccelerator(KeyStroke.getKeyStroke('I', Event.CTRL_MASK)); schemaImport.addActionListener(new ActionListener() { /**/*ww w.j a va 2 s . co m*/ * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.addChoosableFileFilter(new FileFilter() { /** * Whether the given file is accepted by this filter. */ public boolean accept(File f) { return f.getName().endsWith(".vs.xml") || f.isDirectory(); } /** * The description of this filter. For example: "JPG and GIF Images" * * @see javax.swing.filechooser.FileView#getName */ public String getDescription() { return "UniVis Schema (*.vs.xml)"; } }); int option = fileChooser.showOpenDialog(VExplorer.this); if (option == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); new SchemaImport(file); refreshTree(); JOptionPane.showMessageDialog(VExplorer.this, "Schema Import erfolgreich beendet.", "Schema Import", JOptionPane.INFORMATION_MESSAGE); } } }); program.add(schemaImport); program.addSeparator(); VMenuItem exit = new VMenuItem(Constants.EXIT, VIcons.EXIT); exit.setAccelerator(KeyStroke.getKeyStroke('Q', Event.ALT_MASK)); exit.addActionListener(new ActionListener() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { System.exit(0); } }); program.add(exit); VMenu lafMenu = new VMenu(Constants.LOOK_AND_FEEL); ButtonGroup lafGroup = new ButtonGroup(); for (final UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) { JRadioButtonMenuItem lafMenuItem = new JRadioButtonMenuItem(laf.getName()); // Set the current Look And Feel as selected. if (UIManager.getLookAndFeel().getName().equals(laf.getName())) { lafMenuItem.setSelected(true); } lafMenuItem.addActionListener(new ActionListener() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { updateLookAndFeel(laf.getClassName()); } }); lafGroup.add(lafMenuItem); lafMenu.add(lafMenuItem); } JMenu questionMark = new JMenu("?"); VMenuItem license = new VMenuItem(Constants.LICENSE); license.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { new LicenseDialog(VExplorer.this); } }); questionMark.add(license); final VMenuItem about = new VMenuItem(Constants.ABOUT, VIcons.INFORMATION); about.addActionListener(new ActionListener() { /** * {@inheritDoc} */ public void actionPerformed(ActionEvent e) { new AboutPanel(VExplorer.this); } }); questionMark.add(about); menuBar.add(program); menuBar.add(lafMenu); menuBar.add(questionMark); setJMenuBar(menuBar); }
From source file:verdandi.ui.action.ImportPluginAction.java
/** * Ask the import file from the user//from w ww . j a va2 s . c o m */ private File getFile() { File res = null; Preferences prefs = Preferences.userNodeForPackage(getClass()); File importDir = new File(prefs.get(KEY_CWD, System.getProperty("user.home"))); JFileChooser chooser = new JFileChooser(importDir); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".jar") || f.isDirectory(); } @Override public String getDescription() { return RC.getString("pluginimportaction.filechooser.jarfilter.description"); } }); chooser.setDialogTitle(RC.getString("pluginimportaction.filechooser.title")); chooser.setMultiSelectionEnabled(false); if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION) { LOG.debug("User cancelled"); return null; } res = chooser.getSelectedFile(); prefs.put("import.dir", res.getParent()); try { prefs.flush(); } catch (BackingStoreException e) { LOG.error("Cannot write export file preference", e); } return res; }
From source file:visolate.Visolate.java
private File browse() { try {/*from w w w .j a va2 s. c om*/ File input = null; String[] zenity = { "zenity", "--file-selection", "--title=Open", "--file-filter=Gerber file | *.gbr", "--file-filter=All | * " }; //FIXME: dirty workaround to get a fully functional and native file dialog on linux String filestring; try { Process p = Runtime.getRuntime().exec(zenity); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuffer sb = new StringBuffer(); sb.append(br.readLine()); filestring = sb.toString(); if (filestring.equals("null")) { return null; } input = new File(filestring); } catch (IOException e1) { //fallback if zenity is not installed final JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new FileFilter() { @Override public String getDescription() { return "Gerber file"; } @Override public boolean accept(File f) { return f.getName().endsWith(".gbr"); } }); int returnVal = -1; returnVal = fc.showOpenDialog(fc); if (returnVal == JFileChooser.APPROVE_OPTION) { input = fc.getSelectedFile(); } } return input; } catch (AccessControlException e1) { accessControlError(); return null; } }