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:com.itd.dbmrgdao.TestTime7.java
@Ignore @org.junit.Test/*from w ww .j a va2 s.co m*/ 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, scdate = null, p1Start = null, p1End = null, p2Start = null, p2End = null, otStart = null, otEnd = null; String scode = "1985"; StringBuilder insertSQL = new StringBuilder( "INSERT INTO scandata(sc_sysid,sc_scode,scdate,p1start,p2end) VALUES "); StringBuilder deleteSQL = new StringBuilder("DELETE FROM scandata WHERE (sc_sysid,scdate) IN ("); // read from select file for (strLine = br.readLine(); strLine != null; strLine = br.readLine()) { System.out.println(strLine); } 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])) { deleteSQL = deleteSQL.append(" ('").append(sysid).append("','").append(scdate).append("'),"); insertSQL = insertSQL.append(" ('").append(sysid).append("','").append(scode).append("','") .append(scdate).append("','").append(p1Start).append("','").append(p2End).append("'),"); p1Start = null; p1End = null; p2Start = null; p2End = null; otStart = null; otEnd = null; } //clear sysid = parts[0]; scdate = new StringBuffer(parts[1]).insert(parts[1].length() - 2, "-").toString(); scdate = new StringBuffer(scdate).insert(scdate.length() - 5, "-").toString(); 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"); } } deleteSQL = deleteSQL.append(" ('").append(sysid).append("','").append(scdate).append("'))"); insertSQL = insertSQL.append(" ('").append(sysid).append("','").append(scode).append("','") .append(scdate).append("','").append(p1Start).append("','").append(p2End).append("')"); scanDao.executeSQL(deleteSQL.toString()); scanDao.executeSQL(insertSQL.toString()); br.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:it.unibo.alchemist.boundary.gui.Perspective.java
private void openFile() { final JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false);/*from w w w . jav a 2 s . c o m*/ fc.setFileFilter(FILE_FILTER); fc.setCurrentDirectory(currentDirectory); final int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { fileToLoad = fc.getSelectedFile(); currentDirectory = fc.getSelectedFile().getParentFile(); if (fileToLoad.exists()) { status.setText(getString("ready_to_process") + " " + fileToLoad.getAbsolutePath()); status.setOK(); if (sim != null) { sim.addCommand(new Engine.StateCommand<T>().stop().build()); } bar.setFileOK(true); } else { status.setText(FILE_NOT_VALID + " " + fileToLoad.getAbsolutePath()); status.setNo(); bar.setFileOK(false); } } }
From source file:com.intuit.tank.proxy.settings.ui.ProxyConfigDialog.java
private void save(int port, boolean followRedirecs, String outputFile, Set<ConfigInclusionExclusionRule> inclusions, Set<ConfigInclusionExclusionRule> exclusions, Set<ConfigInclusionExclusionRule> bodyInclusions, Set<ConfigInclusionExclusionRule> bodyExclusions, String configFileName) {//w ww. j av a2s. c om String fileName = ""; if (StringUtils.isEmpty(configFileName)) { JFileChooser fileChooser = new JFileChooser(); File file = new File("."); fileChooser.setCurrentDirectory(file); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setFileFilter(new XmlFileFilter()); int showSaveDialog = fileChooser.showSaveDialog(this); if (showSaveDialog == JFileChooser.APPROVE_OPTION) { String selectedFile = fileChooser.getSelectedFile().getName(); if (!selectedFile.endsWith(".xml")) { selectedFile = selectedFile + ".xml"; } fileName = fileChooser.getSelectedFile().getParent() + "/" + selectedFile; configHandler.setConfigFile(fileName); } else { return; } } else { fileName = configFileName; } CommonsProxyConfiguration.save(port, followRedirecs, outputFile, inclusions, exclusions, bodyInclusions, bodyExclusions, fileName); getProxyConfigPanel().update(); configHandler.setConfigFile(fileName); }
From source file:com.itd.dbmrgdao.TestTime3.java
@Ignore @org.junit.Test//ww w . j ava 2s .c o m 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:com.view.Main.java
private void filePathBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filePathBrowseButtonActionPerformed final JFileChooser fileChooser = new JFileChooser("."); final FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel files", "xlsx", "xls"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter); int result = fileChooser.showDialog(this, "choose a file"); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); filePathTextField.setText(selectedFile.getAbsolutePath()); }/*from w ww. ja v a 2s . c o m*/ }
From source file:CompareFiles.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter); // folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnvalue = folder.showSaveDialog(this); File myfolder = null;/*w w w . jav a2 s. c o m*/ if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); jLabel1.setText(myfolder.toString()); } }
From source file:ac.kaist.ccs.presentation.CCSHubSelectionCoverage.java
public CCSHubSelectionCoverage(final String title, List<Double> coverSourceNum) { super(title); this.title = title; final XYDataset dataset = createDataset(coverSourceNum); final JFreeChart chart = createChart(dataset); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); JButton buttonExport = new JButton("Export"); buttonPanel.add("East", buttonExport); buttonExport.addActionListener(new ActionListener() { ChartPanel chartPanel;/*from w w w. j a v a2 s .c o m*/ public ActionListener init(ChartPanel chartPanel) { this.chartPanel = chartPanel; return this; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Dimension size = chartPanel.getSize(); try { //String outPath = textFieldSelectPath.getText(); //String filename = "chromatography.png"; //String path = outPath+"/"+filename; JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop")); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg")); int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path"); if (returnVal == JFileChooser.APPROVE_OPTION) { String inputPath = fileChooser.getSelectedFile().getAbsolutePath(); if (!inputPath.endsWith(".jpeg")) inputPath = inputPath + ".jpeg"; OutputStream os = new FileOutputStream(inputPath); System.out.println(inputPath + "///" + size.width + " " + size.height); BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width, size.height, null); ImageIO.write(chartImage, "png", os); os.close(); JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.init(chartPanel)); panel.add("Center", chartPanel); panel.add("South", buttonPanel); chartPanel.setPreferredSize(new java.awt.Dimension(700, 500)); setContentPane(panel); }
From source file:ac.kaist.ccs.presentation.CCSHubSelectionCo2Coverage.java
public CCSHubSelectionCo2Coverage(final String title, List<Double> coverSourceNum) { super(title); this.title = title; final XYDataset dataset = createDataset(coverSourceNum); final JFreeChart chart = createChart(dataset); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); JButton buttonExport = new JButton("Export"); buttonPanel.add("East", buttonExport); buttonExport.addActionListener(new ActionListener() { ChartPanel chartPanel;//from ww w . j a v a2 s .co m public ActionListener init(ChartPanel chartPanel) { this.chartPanel = chartPanel; return this; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Dimension size = chartPanel.getSize(); try { //String outPath = textFieldSelectPath.getText(); //String filename = "chromatography.png"; //String path = outPath+"/"+filename; JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop")); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg")); int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path"); if (returnVal == JFileChooser.APPROVE_OPTION) { String inputPath = fileChooser.getSelectedFile().getAbsolutePath(); if (!inputPath.endsWith(".jpeg")) inputPath = inputPath + ".jpeg"; OutputStream os = new FileOutputStream(inputPath); System.out.println(inputPath + "///" + size.width + " " + size.height); BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width, size.height, null); ImageIO.write(chartImage, "png", os); os.close(); JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.init(chartPanel)); panel.add("Center", chartPanel); panel.add("South", buttonPanel); chartPanel.setPreferredSize(new java.awt.Dimension(700, 500)); setContentPane(panel); }
From source file:edu.clemson.lph.civet.addons.VspsCviFile.java
public void importVspsFile(Window parent) { String sVspsDir = CivetConfig.getVspsDirPath(); File fDir = new File(sVspsDir); JFileChooser open = new JFileChooser(fDir); Action details = open.getActionMap().get("viewTypeDetails"); details.actionPerformed(null);/* w ww . j ava 2 s .co m*/ open.setDialogTitle("Civet: Open PDF File"); open.setFileSelectionMode(JFileChooser.FILES_ONLY); open.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv")); open.setMultiSelectionEnabled(false); int resultOfFileSelect = open.showOpenDialog(parent); if (resultOfFileSelect == JFileChooser.APPROVE_OPTION) { File fIn = open.getSelectedFile(); saveme(parent, fIn); // vsps.printme(); } }
From source file:net.panthema.BispanningGame.MyGraphMLReader.java
MyGraphMLReader(javax.swing.JPanel panel) throws FileNotFoundException, GraphIOException { posMap = new TreeMap<Integer, Point2D>(); // Query user for filename JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Specify GraphML file to read"); chooser.setCurrentDirectory(new File(".")); FileNameExtensionFilter filter = new FileNameExtensionFilter("GraphML File", "graphml"); chooser.setFileFilter(filter); if (chooser.showOpenDialog(panel) != JFileChooser.APPROVE_OPTION) return;//from w w w .jav a 2 s. c o m File infile = chooser.getSelectedFile(); BufferedReader fileReader = new BufferedReader(new FileReader(infile)); newGraph = new MyGraph(); // create the graph transformer Transformer<GraphMetadata, MyGraph> graphTransformer = new Transformer<GraphMetadata, MyGraph>() { public MyGraph transform(GraphMetadata metadata) { assert (metadata.getEdgeDefault().equals(EdgeDefault.UNDIRECTED)); return newGraph; } }; // create the vertex transformer Transformer<NodeMetadata, Integer> vertexTransformer = new Transformer<NodeMetadata, Integer>() { public Integer transform(NodeMetadata metadata) { // create a new vertex Integer v = newGraph.getVertexCount(); // save layout information if (metadata.getProperty("x") != null && metadata.getProperty("y") != null) { double x = Double.parseDouble(metadata.getProperty("x")); double y = Double.parseDouble(metadata.getProperty("y")); posMap.put(v, new Point2D.Double(x, y)); } newGraph.addVertex(v); return v; } }; // create the edge transformer Transformer<EdgeMetadata, MyEdge> edgeTransformer = new Transformer<EdgeMetadata, MyEdge>() { public MyEdge transform(EdgeMetadata metadata) { MyEdge e = new MyEdge(newGraph.getEdgeCount()); if (metadata.getProperty("color") != null) e.color = Integer.parseInt(metadata.getProperty("color")); return e; } }; // create the useless hyperedge transformer Transformer<HyperEdgeMetadata, MyEdge> hyperEdgeTransformer = new Transformer<HyperEdgeMetadata, MyEdge>() { public MyEdge transform(HyperEdgeMetadata metadata) { return null; } }; // create the graphMLReader2 GraphMLReader2<MyGraph, Integer, MyEdge> graphReader = new GraphMLReader2<MyGraph, Integer, MyEdge>( fileReader, graphTransformer, vertexTransformer, edgeTransformer, hyperEdgeTransformer); // Get the new graph object from the GraphML file graphReader.readGraph(); }