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:smlm.util.SRutil.java
public static String[][] getFiles(String title, String initialRoot, String initialFile) { if (title == null || title == "") title = "Choose files"; if (initialRoot == null || initialRoot == "") initialRoot = "E:\\Data"; JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); FileNameExtensionFilter filter = new FileNameExtensionFilter("Tiff files", "tif", "tiff"); chooser.setFileFilter(filter); chooser.setDialogTitle(title);// ww w. j a va 2 s .c om chooser.setCurrentDirectory(new File(initialRoot)); chooser.setMultiSelectionEnabled(true); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { String[][] files = new String[chooser.getSelectedFiles().length][2]; for (int i = 0; i < files.length; i++) { files[i][0] = chooser.getSelectedFiles()[i].getParent(); files[i][1] = chooser.getSelectedFiles()[i].getName(); } return files; } else return null; }
From source file:tvbrowser.extras.reminderplugin.ReminderSettingsTab.java
/** * Creates the settings panel for this tab. *//*from ww w .j ava 2 s. c om*/ public JPanel createSettingsPanel() { FormLayout layout = new FormLayout("5dlu,pref,5dlu,pref,pref:grow,3dlu,pref,3dlu,pref,5dlu", "pref,5dlu,pref,1dlu,pref,1dlu,pref,1dlu,pref,10dlu,pref,5dlu," + "pref,10dlu,pref,5dlu,pref,10dlu,pref,5dlu,pref,10dlu," + "pref,5dlu,pref,3dlu,pref,10dlu,pref,5dlu,pref"); layout.setColumnGroups(new int[][] { { 7, 9 } }); PanelBuilder pb = new PanelBuilder(layout, new ScrollableJPanel()); pb.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); final String[] extArr = { ".wav", ".aif", ".rmf", ".au", ".mid" }; String soundFName = mSettings.getProperty("soundfile", "/"); String msg = mLocalizer.msg("soundFileFilter", "Sound file ({0})", "*" + StringUtils.join(extArr, ", *")); mReminderWindowChB = new JCheckBox(mLocalizer.msg("reminderWindow", "Reminder window"), mSettings.getProperty("usemsgbox", "false").equalsIgnoreCase("true")); mShowAlwaysOnTop = new JCheckBox(mLocalizer.msg("alwaysOnTop", "Show always on top"), mSettings.getProperty("alwaysOnTop", "true").equalsIgnoreCase("true")); mShowAlwaysOnTop.setEnabled(mReminderWindowChB.isSelected()); JPanel reminderWindowCfg = new JPanel(new FormLayout("12dlu,default:grow", "pref,1dlu,pref")); reminderWindowCfg.add(mReminderWindowChB, cc.xyw(1, 1, 2)); reminderWindowCfg.add(mShowAlwaysOnTop, cc.xy(2, 3)); mSoundFileChB = new FileCheckBox(mLocalizer.msg("playlingSound", "Play sound"), new File(soundFName), 0, false); JFileChooser soundChooser = new JFileChooser((String) null); soundChooser.setFileFilter(new ExtensionFileFilter(extArr, msg)); mSoundFileChB.setFileChooser(soundChooser); mSoundFileChB.setSelected(mSettings.getProperty("usesound", "false").equals("true")); mBeep = new JCheckBox(mLocalizer.msg("beep", "Speaker sound"), mSettings.getProperty("usebeep", "true").equalsIgnoreCase("true")); mExecFileStr = mSettings.getProperty("execfile", ""); mExecParamStr = mSettings.getProperty("execparam", ""); final JButton soundTestBt = new JButton(mLocalizer.msg("test", "Test")); mExecChB = new JCheckBox(mLocalizer.msg("executeProgram", "Execute program")); mExecChB.setSelected(mSettings.getProperty("useexec", "false").equals("true")); mExecFileDialogBtn = new JButton(mLocalizer.msg("executeConfig", "Configure")); mExecFileDialogBtn.setEnabled(mExecChB.isSelected()); mPluginLabel = new JLabel(); JButton choose = new JButton(mLocalizer.msg("selectPlugins", "Choose Plugins")); mClientPluginTargets = ReminderPlugin.getInstance().getClientPluginsTargets(); handlePluginSelection(); choose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Window parent = UiUtilities.getLastModalChildOf(MainFrame.getInstance()); PluginChooserDlg chooser = null; chooser = new PluginChooserDlg(parent, mClientPluginTargets, null, ReminderPluginProxy.getInstance()); chooser.setLocationRelativeTo(parent); chooser.setVisible(true); if (chooser.getReceiveTargets() != null) { mClientPluginTargets = chooser.getReceiveTargets(); } handlePluginSelection(); } catch (Exception ee) { ee.printStackTrace(); } } }); int autoCloseReminderTime = 10; try { String asString = mSettings.getProperty("autoCloseReminderTime", "10"); autoCloseReminderTime = Integer.parseInt(asString); if (autoCloseReminderTime == 0) { autoCloseReminderTime = 10; } } catch (Exception exc) { // ignore } mCloseOnEnd = new JRadioButton(mLocalizer.msg("autoCloseReminderAtProgramEnd", "Program end"), mSettings.getProperty("autoCloseBehaviour", "onEnd").equals("onEnd")); mCloseOnEnd.setEnabled(mReminderWindowChB.isSelected()); mCloseNever = new JRadioButton(mLocalizer.msg("autoCloseNever", "Never close"), mSettings.getProperty("autoCloseBehaviour", "onEnd").equals("never")); mCloseNever.setEnabled(mReminderWindowChB.isSelected()); mCloseOnTime = new JRadioButton(mLocalizer.ellipsisMsg("autoCloseAfterTime", "After time"), mSettings.getProperty("autoCloseBehaviour", "onEnd").equals("onTime")); mCloseOnTime.setEnabled(mReminderWindowChB.isSelected()); ButtonGroup bg = new ButtonGroup(); bg.add(mCloseOnEnd); bg.add(mCloseNever); bg.add(mCloseOnTime); mAutoCloseReminderTimeSp = new JSpinner( new SpinnerNumberModel(autoCloseReminderTime, autoCloseReminderTime < 5 ? 1 : 5, 600, 1)); mAutoCloseReminderTimeSp.setEnabled(mCloseOnTime.isSelected() && mReminderWindowChB.isSelected()); mShowTimeCounter = new JCheckBox(mLocalizer.msg("showTimeCounter", "Show time counter"), mSettings.getProperty("showTimeCounter", "false").compareTo("true") == 0); mShowTimeCounter.setEnabled(!mCloseNever.isSelected() && mReminderWindowChB.isSelected()); PanelBuilder autoClosePanel = new PanelBuilder( new FormLayout("12dlu,default,2dlu,default:grow", "pref,2dlu,pref,2dlu,pref,2dlu,pref,10dlu,pref")); autoClosePanel.add(mCloseOnEnd, cc.xyw(1, 1, 4)); autoClosePanel.add(mCloseNever, cc.xyw(1, 3, 4)); autoClosePanel.add(mCloseOnTime, cc.xyw(1, 5, 4)); autoClosePanel.add(mAutoCloseReminderTimeSp, cc.xy(2, 7)); final JLabel secondsLabel = autoClosePanel.addLabel(mLocalizer.msg("seconds", "seconds (0 = off)"), cc.xy(4, 7)); autoClosePanel.add(mShowTimeCounter, cc.xyw(1, 9, 4)); secondsLabel.setEnabled(mCloseOnTime.isSelected() && mReminderWindowChB.isSelected()); String defaultReminderEntryStr = (String) mSettings.get("defaultReminderEntry"); mDefaultReminderEntryList = new JComboBox(ReminderDialog.SMALL_REMIND_MSG_ARR); if (defaultReminderEntryStr != null) { try { int inx = Integer.parseInt(defaultReminderEntryStr); if (inx < ReminderDialog.SMALL_REMIND_MSG_ARR.length) { mDefaultReminderEntryList.setSelectedIndex(inx); } } catch (NumberFormatException e) { // ignore } } mShowTimeSelectionDlg = new JCheckBox( mLocalizer.msg("showTimeSelectionDialog", "Show time selection dialog")); mShowTimeSelectionDlg .setSelected(mSettings.getProperty("showTimeSelectionDialog", "true").compareTo("true") == 0); mShowRemovedDlg = new JCheckBox( mLocalizer.msg("showRemovedDialog", "Show removed reminders after data update")); mShowRemovedDlg.setSelected(mSettings.getProperty("showRemovedDialog", "true").compareTo("true") == 0); pb.addSeparator(mLocalizer.msg("remindBy", "Remind me by"), cc.xyw(1, 1, 10)); pb.add(reminderWindowCfg, cc.xyw(2, 3, 4)); pb.add(mSoundFileChB, cc.xyw(2, 5, 4)); pb.add(mSoundFileChB.getButton(), cc.xy(7, 5)); pb.add(soundTestBt, cc.xy(9, 5)); pb.add(mBeep, cc.xy(2, 7)); pb.add(mExecChB, cc.xyw(2, 9, 4)); pb.add(mExecFileDialogBtn, cc.xyw(7, 9, 3)); pb.addSeparator(mLocalizer.msg("sendToPlugin", "Send reminded program to"), cc.xyw(1, 11, 10)); pb.add(mPluginLabel, cc.xyw(2, 13, 4)); pb.add(choose, cc.xyw(7, 13, 3)); final JLabel c = (JLabel) pb .addSeparator(mLocalizer.msg("autoCloseReminder", "Automatically close reminder"), cc.xyw(1, 15, 10)) .getComponent(0); c.setEnabled(mReminderWindowChB.isSelected()); pb.add(autoClosePanel.getPanel(), cc.xyw(2, 17, 5)); JPanel reminderEntry = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); reminderEntry.add(mDefaultReminderEntryList); pb.addSeparator(mLocalizer.msg("defaltReminderEntry", "Default reminder time"), cc.xyw(1, 19, 10)); pb.add(reminderEntry, cc.xyw(2, 21, 4)); pb.addSeparator(mLocalizer.msg("miscSettings", "Misc settings"), cc.xyw(1, 23, 10)); pb.add(mShowTimeSelectionDlg, cc.xyw(2, 25, 7)); pb.add(mShowRemovedDlg, cc.xyw(2, 27, 7)); pb.addSeparator(DefaultMarkingPrioritySelectionPanel.getTitle(), cc.xyw(1, 29, 10)); pb.add(mMarkingsPanel = DefaultMarkingPrioritySelectionPanel .createPanel(ReminderPlugin.getInstance().getMarkPriority(), false, false), cc.xyw(2, 31, 9)); mReminderWindowChB.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { mShowAlwaysOnTop.setEnabled(e.getStateChange() == ItemEvent.SELECTED); c.setEnabled(e.getStateChange() == ItemEvent.SELECTED); secondsLabel.setEnabled(e.getStateChange() == ItemEvent.SELECTED && mCloseOnTime.isSelected()); mCloseOnEnd.setEnabled(e.getStateChange() == ItemEvent.SELECTED); mCloseNever.setEnabled(e.getStateChange() == ItemEvent.SELECTED); mCloseOnTime.setEnabled(e.getStateChange() == ItemEvent.SELECTED); mShowTimeCounter.setEnabled(e.getStateChange() == ItemEvent.SELECTED && !mCloseNever.isSelected()); mAutoCloseReminderTimeSp .setEnabled(e.getStateChange() == ItemEvent.SELECTED && mCloseOnTime.isSelected()); } }); soundTestBt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (evt.getActionCommand().compareTo(mLocalizer.msg("test", "Test")) == 0) { mTestSound = ReminderPlugin.playSound(mSoundFileChB.getTextField().getText()); if (mTestSound != null) { soundTestBt.setText(mLocalizer.msg("stop", "Stop")); } if (mTestSound != null) { if (mTestSound instanceof SourceDataLine) { ((SourceDataLine) mTestSound).addLineListener(new LineListener() { public void update(LineEvent event) { if (event.getType() == Type.CLOSE) { soundTestBt.setText(mLocalizer.msg("test", "Test")); } } }); } else if (mTestSound instanceof Sequencer) { new Thread("Test MIDI sound") { public void run() { setPriority(Thread.MIN_PRIORITY); while (((Sequencer) mTestSound).isRunning()) { try { Thread.sleep(100); } catch (Exception ee) { } } soundTestBt.setText(mLocalizer.msg("test", "Test")); } }.start(); } } } else if (mTestSound != null) { if (mTestSound instanceof SourceDataLine && ((SourceDataLine) mTestSound).isRunning()) { ((SourceDataLine) mTestSound).stop(); } else if (mTestSound instanceof Sequencer && ((Sequencer) mTestSound).isRunning()) { ((Sequencer) mTestSound).stop(); } } } }); mSoundFileChB.getCheckBox().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { soundTestBt.setEnabled(mSoundFileChB.isSelected()); } }); mSoundFileChB.getTextField().addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { String text = mSoundFileChB.getTextField().getText(); if ((new File(text)).isFile()) { boolean notFound = true; for (String extension : extArr) { if (StringUtils.endsWithIgnoreCase(text, extension)) { notFound = false; break; } } if (notFound) { soundTestBt.setEnabled(false); } else { soundTestBt.setEnabled(true); } } else { soundTestBt.setEnabled(false); } } }); mSoundFileChB.getTextField().getKeyListeners()[0].keyReleased(null); mExecChB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mExecFileDialogBtn.setEnabled(mExecChB.isSelected()); if (mExecFileDialogBtn.isEnabled()) { showFileSettingsDialog(); } } }); mExecFileDialogBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showFileSettingsDialog(); } }); ItemListener autoCloseListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { mAutoCloseReminderTimeSp.setEnabled(mCloseOnTime.isSelected()); secondsLabel.setEnabled(mCloseOnTime.isSelected()); mShowTimeCounter.setEnabled(mCloseOnTime.isSelected() || mCloseOnEnd.isSelected()); } }; mCloseOnEnd.addItemListener(autoCloseListener); mCloseOnTime.addItemListener(autoCloseListener); mCloseOnTime.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { mShowTimeCounter.setEnabled(e.getStateChange() == ItemEvent.SELECTED); } }); JScrollPane scrollPane = new JScrollPane(pb.getPanel()); scrollPane.setBorder(null); scrollPane.setViewportBorder(null); JPanel scrollPanel = new JPanel(new FormLayout("default:grow", "default")); scrollPanel.add(scrollPane, cc.xy(1, 1)); return scrollPanel; }
From source file:ui.UI.java
private void jButtonInputFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonInputFileActionPerformed JFileChooser chooser = new JFileChooser(new File(".")); FileFilter filter = new FileNameExtensionFilter("Video Files", "mp4", "mp2"); chooser.addChoosableFileFilter(filter); chooser.setFileFilter(filter); int choice = chooser.showOpenDialog(null); if (choice == JFileChooser.APPROVE_OPTION) { toddler.setInputFile(chooser.getSelectedFile()); }/* www . j av a2 s .c om*/ }
From source file:uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetDisplay.java
public void actionPerformed(ActionEvent ae) { /* if (ae.getActionCommand().equals("plot")) { //w w w .jav a2s . 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.ac.liverpool.narrative.SolutionGraphics.java
@Override public void run() { // set up action cost filter if (actionCostsFilePath != null && (new File(actionCostsFilePath)).exists()) { CharacterActionSolutionFilter tc = new CharacterActionSolutionFilter(); if (actionCostsFilePath != null && (new File(actionCostsFilePath)).exists()) { tc.setActionCosts(BranchingStoryGenerator.readCosts(actionCostsFilePath, BranchingStoryGenerator.actionCostType)); }//from w w w .j a v a2 s . c om if (characterCostsFilePath != null && (new File(characterCostsFilePath)).exists()) { tc.setCharacterCosts(BranchingStoryGenerator.readCosts(characterCostsFilePath, BranchingStoryGenerator.characterCostType)); } if (authorDirection != null && (new File(authorDirection)).exists()) { tc.setAuthorDirection( BranchingStoryGenerator.readCosts(authorDirection, BranchingStoryGenerator.authorCostType) .get(BranchingStoryGenerator.authorCostType)); } sg.filters.add(tc); tc.setThreshold(threshold); } if (character != null) { charFilter = new CharacterFilter(character); } if (fc) { JFileChooser fc = new JFileChooser(BranchingStoryGenerator.DestinationFolder); fc.setAccessory(new SolutionPreview(fc)); FileNameExtensionFilter filter = new FileNameExtensionFilter("Solution files", "sol"); fc.setFileFilter(filter); fc.setMultiSelectionEnabled(true); fc.showOpenDialog(vvv); File[] files = fc.getSelectedFiles(); for (File f : files) { try { sg.readSolutionFile(f); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else { for (File f : BranchingStoryGenerator.DestinationFolder.listFiles()) { if (!f.isFile() || !f.getName().endsWith(".sol")) { continue; } try { sg.readSolutionFile(f); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } System.out.println("done"); }
From source file:uk.chromis.pos.imports.JPanelCSVImport.java
private void jbtnDbDriverLibActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnDbDriverLibActionPerformed resetFields();// w w w .j av a 2 s . c o m setWorker(); // If CSV.last_file is null then use c:\ otherwise use saved dir JFileChooser chooser = new JFileChooser(last_folder == null ? "C:\\" : last_folder); FileNameExtensionFilter filter = new FileNameExtensionFilter("csv files", "csv"); chooser.setFileFilter(filter); chooser.showOpenDialog(null); File csvFile = chooser.getSelectedFile(); // check if a file was selected if (csvFile == null) { return; } File current_folder = chooser.getCurrentDirectory(); // If we have a file lets save the directory for later use if it's different from the old if (last_folder == null || !last_folder.equals(current_folder.getAbsolutePath())) { AppConfig.getInstance().setProperty("CSV.last_folder", current_folder.getAbsolutePath()); last_folder = current_folder.getAbsolutePath(); try { AppConfig.getInstance().save(); } catch (IOException ex) { Logger.getLogger(JPanelCSVImport.class.getName()).log(Level.SEVERE, null, ex); } } String csv = csvFile.getName(); if (!(csv.trim().equals(""))) { csvFileName = csvFile.getAbsolutePath(); jFileName.setText(csvFileName); } }
From source file:uk.co.danielrendall.imagetiler.gui.FileChoosers.java
private JFileChooser createFileChooser(String name, FileFilter filter, ResourceMap appResourceMap) { JFileChooser fc = new JFileChooser(); fc.setName(name);/*from www.java 2 s. c o m*/ fc.setFileFilter(filter); appResourceMap.injectComponents(fc); return fc; }
From source file:updater.UpdaterGUI.java
@SuppressWarnings("resource") public UpdaterGUI() { try {// www .j av a 2 s. c o m URL url1 = new URL( "https://raw.githubusercontent.com/kvsjxd/Droid-PC-Suite/master/.release-version.txt"); ReadableByteChannel obj1 = Channels.newChannel(url1.openStream()); FileOutputStream outputstream1 = new FileOutputStream(".release-version.txt"); outputstream1.getChannel().transferFrom(obj1, 0, Long.MAX_VALUE); URL url2 = new URL( "https://raw.githubusercontent.com/kvsjxd/Droid-PC-Suite/master/.release-changelog.txt"); ReadableByteChannel obj2 = Channels.newChannel(url2.openStream()); FileOutputStream outputstream2 = new FileOutputStream(".release-changelog.txt"); outputstream2.getChannel().transferFrom(obj2, 0, Long.MAX_VALUE); FileReader file = new FileReader(".release-version.txt"); BufferedReader reader = new BufferedReader(file); String DownloadedString = reader.readLine(); File file2 = new File(".release-version.txt"); if (file2.exists() && !file2.isDirectory()) { file2.delete(); } AvailableUpdate = Double.parseDouble(DownloadedString); InputStreamReader reader2 = new InputStreamReader( getClass().getResourceAsStream("/others/app-version.txt")); String tmp = IOUtils.toString(reader2); ApplicationVersion = Double.parseDouble(tmp); } catch (Exception e) { e.printStackTrace(); } setIconImage(Toolkit.getDefaultToolkit().getImage(UpdaterGUI.class.getResource("/graphics/Icon.png"))); setResizable(false); setType(Type.UTILITY); setTitle("Updater"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 430, 415); contentPane = new JPanel(); contentPane.setBackground(Color.WHITE); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblApplicationVersion = new JLabel("App Version: v" + ApplicationVersion); lblApplicationVersion.setBounds(12, 12, 222, 15); contentPane.add(lblApplicationVersion); JLabel lblUpdateVersion = new JLabel("Update Version: v" + AvailableUpdate); lblUpdateVersion.setBounds(12, 30, 222, 15); contentPane.add(lblUpdateVersion); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(0, 51, 422, 281); contentPane.add(scrollPane); JTextArea UpdateChangelogViewer = new JTextArea(); scrollPane.setViewportView(UpdateChangelogViewer); JButton btnDownload = new JButton("Download"); btnDownload.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFrame parentFrame = new JFrame(); JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Zip Files", "zip"); fileChooser.setFileFilter(filter); fileChooser.setDialogTitle("Save as"); int userSelection = fileChooser.showSaveDialog(parentFrame); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); try { URL url = new URL("https://github.com/kvsjxd/Droid-PC-Suite/releases/download/" + AvailableUpdate + "/DPCS.v" + AvailableUpdate + ".Stable.zip"); ReadableByteChannel obj = Channels.newChannel(url.openStream()); FileOutputStream outputstream = new FileOutputStream(fileToSave.getAbsolutePath() + ".zip"); outputstream.getChannel().transferFrom(obj, 0, Long.MAX_VALUE); JOptionPane.showMessageDialog(null, "Download complete!\nPlease delete this version and extract the downloaded zip\nwhich is saved at " + fileToSave.getAbsolutePath() + ".zip"); } catch (Exception e) { e.printStackTrace(); } } } }); btnDownload.setBounds(140, 344, 117, 25); contentPane.add(btnDownload); try { FileReader reader3 = new FileReader(new File(".release-changelog.txt")); UpdateChangelogViewer.read(reader3, ""); File file3 = new File(".release-changelog.txt"); if (file3.exists() && !file3.isDirectory()) { file3.delete(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Open or create a SQL statement file.// w w w. j a v a 2s. c o m */ private void openSQLFile() { JFileChooser fileMenu; FileFilter defaultFileFilter = null; FileFilter preferredFileFilter = null; File chosenSQLFile; int returnVal; chosenSQLFile = null; // Save current information, including SQL Statements saveConfig(); // Allow user to choose/create new file for SQL Statements fileMenu = new JFileChooser(new File(queryFilename)); for (FileFilterDefinition filterDefinition : FileFilterDefinition.values()) { if (filterDefinition.name().startsWith("QUERY")) { final FileFilter fileFilter = new SuffixFileFilter(filterDefinition.description(), filterDefinition.acceptedSuffixes()); if (filterDefinition.isPreferredOption()) { preferredFileFilter = fileFilter; } fileMenu.addChoosableFileFilter(fileFilter); if (filterDefinition.description().equals(latestChosenQueryFileFilterDescription)) { defaultFileFilter = fileFilter; } } } if (defaultFileFilter != null) { fileMenu.setFileFilter(defaultFileFilter); } else if (latestChosenQueryFileFilterDescription != null && latestChosenQueryFileFilterDescription.startsWith("All")) { fileMenu.setFileFilter(fileMenu.getAcceptAllFileFilter()); } else if (preferredFileFilter != null) { fileMenu.setFileFilter(preferredFileFilter); } fileMenu.setSelectedFile(new File(queryFilename)); fileMenu.setDialogTitle(Resources.getString("dlgSQLFileTitle")); fileMenu.setDialogType(JFileChooser.OPEN_DIALOG); fileMenu.setFileSelectionMode(JFileChooser.FILES_ONLY); fileMenu.setMultiSelectionEnabled(false); if (fileMenu.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { chosenSQLFile = fileMenu.getSelectedFile(); // Adjust file suffix if necessary final FileFilter fileFilter = fileMenu.getFileFilter(); if (fileFilter != null && fileFilter instanceof SuffixFileFilter && !fileMenu.getFileFilter().accept(chosenSQLFile)) { chosenSQLFile = ((SuffixFileFilter) fileFilter).makeWithPrimarySuffix(chosenSQLFile); } if (!chosenSQLFile.exists()) { returnVal = JOptionPane.showConfirmDialog(this, Resources.getString("dlgNewSQLFileText", chosenSQLFile.getName()), Resources.getString("dlgNewSQLFileTitle"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (returnVal == JOptionPane.NO_OPTION) { querySelection.removeAllItems(); queryText.setText(""); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } else if (returnVal == JOptionPane.CANCEL_OPTION) { chosenSQLFile = null; } } else { setQueryFilename(chosenSQLFile.getAbsolutePath()); querySelection.removeAllItems(); queryText.setText(""); loadCombo(querySelection, queryFilename); QueryHistory.getInstance().clearAllQueries(); // Update GUI setPrevNextIndication(); } } try { latestChosenQueryFileFilterDescription = fileMenu.getFileFilter().getDescription(); } catch (Throwable throwable) { LOGGER.warn("Unable to determine which ontology file filter was chosen", throwable); } if (chosenSQLFile != null) { setQueryFilename(chosenSQLFile.getAbsolutePath()); saveConfig(); } }
From source file:verdandi.ui.action.ImportPluginAction.java
/** * Ask the import file from the user//from w w w.jav a 2s. 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; }