List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:com.itd.dbmrgdao.TestTime3.java
@Ignore @org.junit.Test/*w w w.ja va 2 s . c om*/ public void test() throws ParseException { String newTab = "\t"; String[] sysidLine; JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt"); chooser.setFileFilter(filter); chooser.showOpenDialog(null); File f = chooser.getSelectedFile(); String fileName = f.getAbsolutePath(); try { FileReader reader = new FileReader(fileName); BufferedReader br = new BufferedReader(reader); String strLine; String sysid = null, p1Start = null, p1End = null, p2Start = null, p2End = null, otStart = null, otEnd = null; Date scdate = null; // read from select file while ((strLine = br.readLine()) != null) { String[] parts = strLine.split(" "); // check if not first record or sysid change will save in table scandata if (sysid != null && !sysid.equals(parts[0])) { // rule if whatever employee register will get standard hour 8 hrs // if (p1Start != null || p2End != null) { // ScanRule scanRule = scanDao.findScanRuleBySysId(sysid); // p1Start = scanRule.getP1start(); // p2End = scanRule.getP2end(); // } // set up data in entity ScanDataKey scanDataKey = new ScanDataKey(sysid, scdate); ScanData scanData = new ScanData(scanDataKey, "1985", p1Start, p1End, p2Start, p2End, otStart, otEnd); // remove old record (key is sysid and scdate) gennericDao.remove(scanData); gennericDao.create(scanData); //clear p1Start = null; p1End = null; p2Start = null; p2End = null; otStart = null; otEnd = null; } sysid = parts[0]; scdate = new SimpleDateFormat("yyyyMMdd", Locale.US).parse(parts[1]); String timeString = new StringBuffer(parts[5]).insert(parts[5].length() - 2, ":").toString(); if (parts[6].equals("01")) { p1Start = CompareTime(p1Start, timeString, "01"); } else { p2End = CompareTime(p2End, timeString, "04"); } } //last line // if (p1Start != null || p2End != null) { // ScanRule scanRule = scanDao.findScanRuleBySysId(sysid); // p1Start = scanRule.getP1start(); // p2End = scanRule.getP2end(); // } ScanDataKey scanDataKey = new ScanDataKey(sysid, scdate); ScanData scanData = new ScanData(scanDataKey, "1985", p1Start, p1End, p2Start, p2End, otStart, otEnd); gennericDao.remove(scanData); gennericDao.create(scanData); br.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:MyFilterChooser.java
public MyFilterChooser() { super("Filter Test Frame"); setSize(350, 200);//from w ww.j av a2 s .c o m setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); JButton openButton = new JButton("Open"); final JLabel statusbar = new JLabel("Output of your selection will go here"); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String[] pics = new String[] { "gif", "jpg", "tif" }; String[] audios = new String[] { "au", "aiff", "wav" }; JFileChooser chooser = new JFileChooser(); chooser.addChoosableFileFilter(new SimpleFileFilter(pics, "Images (*.gif, *.jpg, *.tif)")); chooser.addChoosableFileFilter(new SimpleFileFilter(".MOV")); chooser.addChoosableFileFilter(new SimpleFileFilter(audios, "Sounds (*.aiff, *.au, *.wav)")); int option = chooser.showOpenDialog(MyFilterChooser.this); if (option == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) statusbar.setText("You chose " + chooser.getSelectedFile().getName()); } else { statusbar.setText("You canceled."); } } }); c.add(openButton); c.add(statusbar); setVisible(true); }
From source file:com.intuit.tank.proxy.settings.ui.ProxyConfigDialog.java
protected void openConfig() { JFileChooser fileChooser = new JFileChooser(); File file = new File("."); fileChooser.setCurrentDirectory(file); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(new XmlFileFilter()); int showOpenDialog = fileChooser.showOpenDialog(this); if (showOpenDialog == JFileChooser.APPROVE_OPTION) { configHandler.setConfigFile(fileChooser.getSelectedFile().getAbsolutePath()); getProxyConfigPanel().update();//from w ww . jav a2s.co m } }
From source file:task5.deneme.java
private void btn_chooseImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_chooseImageActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser fileChooser = new JFileChooser(userDir + "/Desktop"); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); try {//from w w w.j av a 2 s .c o m img = ImageIO.read(selectedFile); getRGBs(); } catch (IOException ex) { Logger.getLogger(deneme.class.getName()).log(Level.SEVERE, null, ex); } } r = red.toArray(); g = green.toArray(); b = blue.toArray(); // // if(red.indexOf(0)==-1 || red.indexOf(255)==-1){ // red.sort(null); // System.out.println("Before Streching... Min and Max Value..." ); // System.out.println(red.get(0)+" "+red.get(red.size()-1)); // contrastR= red.get(red.size()-1)- red.get(0); // int fmin=red.get(0); // int fmax=red.get(red.size()-1); // for (int i = 0; i < red.size(); i++) { // int temp2=0; // if(((int)r[i])<=fmin) // temp2=0; // else if(fmin<=((int)r[i]) && ((int)r[i])<= fmax){ // double temp=((((int)r[i])- fmin)/(contrastR)); // temp2=(int) Math.round((temp*255)); // } // else if(((int)r[i])>=fmax){ // temp2=255; // } // r[i]=temp2; // } // ArrayList<Integer> tempp = new ArrayList<>(); // for (Object r1 : r) { // tempp.add((int) r1); // } // tempp.sort(null); // System.out.println("After Stretching... Min and Max Value..."); // System.out.println(tempp.get(0) + " " + tempp.get(tempp.size() - 1)); // } // // // // // // if(green.indexOf(0)==-1 || green.indexOf(255)==-1){ // green.sort(null); // contrastG= green.get(green.size()-1)- green.get(0); // int fmin=green.get(0); // int fmax=green.get(green.size()-1); // for (int i = 0; i < green.size(); i++) { // int temp2=0; // if(((int)g[i])<=fmin) // temp2=0; // else if(fmin<=((int)g[i]) && ((int)g[i])<= fmax){ // double temp=((((int)g[i])- fmin)/(contrastG)); // temp2=(int) Math.round((temp*255)); // } // else if(((int)g[i])>=fmax){ // temp2=255; // } // g[i]=temp2; // } // } // if(blue.indexOf(0)==-1 || blue.indexOf(255)==-1){ // blue.sort(null); // contrastB= blue.get(blue.size()-1)- blue.get(0); // int fmin=blue.get(0); // int fmax=blue.get(blue.size()-1); // for (int i = 0; i < blue.size(); i++) { // int temp2=0; // if(((int)b[i])<=fmin) // temp2=0; // else if(fmin<=((int)b[i]) && ((int)b[i])<= fmax){ // double temp=((((int)b[i])- fmin)/(contrastB)); // temp2=(int) Math.round((temp*255)); // } // else if(((int)b[i])>=fmax){ // temp2=255; // } // b[i]=temp2; // } // } display(); }
From source file:TextFileHandler.java
public File openFile(String title) { File result = null;/*from www .j av a 2 s . c o m*/ JFileChooser chooser = new JFileChooser(new File(".")); if (title != null) chooser.setDialogTitle(title); int retVal = chooser.showOpenDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { result = chooser.getSelectedFile(); } return result; }
From source file:org.spf4j.ui.TSDBViewJInternalFrame.java
@edu.umd.cs.findbugs.annotations.SuppressWarnings("UP_UNUSED_PARAMETER") private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed TreePath[] selectionPaths = measurementTree.getSelectionPaths(); List<String> selectedTables = getSelectedTables(selectionPaths); if (!selectedTables.isEmpty()) { JFileChooser chooser = new JFileChooser(); chooser.setDialogType(JFileChooser.SAVE_DIALOG); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { tsDb.writeCsvTables(selectedTables, file); } catch (IOException ex) { throw new RuntimeException(ex); }//from w ww.jav a2 s . c om } } }
From source file:view.MainFrame.java
private void menuItemOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemOpenActionPerformed // TODO add your handling code here: JFileChooser filech = new JFileChooser(); filech.setFileSelectionMode(JFileChooser.FILES_ONLY); filech.setFileFilter(new FileNameExtensionFilter("WAV Files", "wav")); int ret = filech.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { try {//from ww w . j a va 2 s . c om wavFile = WavFile.openWavFile(filech.getSelectedFile()); textArea.append(wavFile.getInfoString()); samples = new double[wavFile.getNumChannels() * (int) wavFile.getSampleRate()]; int nFrames = wavFile.readFrames(samples, (int) wavFile.getSampleRate()); textArea.append(nFrames + " frames lidos.\n"); double valuesX[] = new double[samples.length]; for (int i = 0; i < samples.length; i++) { valuesX[i] = i; } showChart(wavFile.getNumChannels() * (int) wavFile.getSampleRate(), samples, valuesX, "Amostra", "Amplitude", "Amplitude das Amostras do ?udio", "Audio"); } catch (IOException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (WavFileException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:cool.pandora.modeller.ui.handlers.base.AddDataHandler.java
/** * addData.//from w ww. j av a2s .c o m */ void addData() { final File selectFile = new File(File.separator + "."); final JFrame frame = new JFrame(); final JFileChooser fc = new JFileChooser(selectFile); fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setMultiSelectionEnabled(true); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fc.setDialogTitle("Add File or Directory"); final int option = fc.showOpenDialog(frame); if (option == JFileChooser.APPROVE_OPTION) { final File[] files = fc.getSelectedFiles(); final String message = ApplicationContextUtil.getMessage("bag.message.filesadded"); if (files != null && files.length > 0) { addBagData(files); ApplicationContextUtil.addConsoleMessage(message + " " + getFileNames(files)); } else { final File file = fc.getSelectedFile(); addBagData(file); ApplicationContextUtil.addConsoleMessage(message + " " + file.getAbsolutePath()); } bagView.bagPayloadTreePanel.refresh(bagView.bagPayloadTree); bagView.updateAddData(); } }
From source file:Main.java
public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == openItem) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".zip") || f.isDirectory(); }//www .j av a 2 s . com public String getDescription() { return "ZIP Files"; } }); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { String zipname = chooser.getSelectedFile().getPath(); System.out.println(zipname); } } else if (source == exitItem) System.exit(0); }
From source file:wsattacker.plugin.intelligentdos.ui.dialog.Result_NB.java
private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_saveBtnActionPerformed try {/*from w w w .j av a 2 s . c om*/ JFileChooser fileChooser = new JFileChooser(); int checker = fileChooser.showOpenDialog(null); if (checker == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); String message = "The selected file already exists.\nOverwrite?"; if (!selectedFile.exists() || JOptionPane.showConfirmDialog(this, message, "Save result", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { if (!FilenameUtils.getExtension(selectedFile.getName()).equalsIgnoreCase(FILE_EXT_ZIP)) { selectedFile = new File(selectedFile.getAbsoluteFile() + "." + FILE_EXT_ZIP); } btnController.save(selectedFile); // default title and icon JOptionPane.showMessageDialog(this, "Result has been saved to filesystem."); } } } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Fehler beim Schreiben", JOptionPane.ERROR_MESSAGE); logger.warn(e, e); } catch (Exception e) { e.printStackTrace(); } }