Example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter

Introduction

In this page you can find the example usage for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter.

Prototype

public FileNameExtensionFilter(String description, String... extensions) 

Source Link

Document

Creates a FileNameExtensionFilter with the specified description and file name extensions.

Usage

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);/*  ww w.j a  va 2 s.co  m*/

    if (chooser.showOpenDialog(panel) != JFileChooser.APPROVE_OPTION)
        return;

    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();
}

From source file:analysers.ExportValidated.java

@Override
public void analyze(Cell currentCell) {
    JFileChooser fc = new JFileChooser();
    fc.addChoosableFileFilter(new FileNameExtensionFilter("Comma Separated Values", "csv"));
    fc.addChoosableFileFilter(new FileNameExtensionFilter("JSON file", "json"));
    int rv = fc.showSaveDialog(null);
    if (rv == JFileChooser.APPROVE_OPTION) {
        int b = Prefs.getInt(".TrackApp.FilterValidatedDialog.exportMean", 1);
        if (b != 0) {
            IJ.log("Exporting mean intensity values.");
        } else {/*from  w  w w .  jav a 2  s  .c o  m*/
            IJ.log("Exporting sum of intensity values.");
        }

        File ff = fc.getSelectedFile();
        String fn = fc.getSelectedFile().getAbsolutePath();

        if (fc.getFileFilter().getDescription().contains("JSON")) {
            if (!fn.toLowerCase().endsWith(".json")) {
                fn = fn + ".json";
                ff = new File(ff + ".json");
            }
            IJ.log("Writing a JSON file.");
        } else {
            if (!fn.toLowerCase().endsWith(".csv")) {
                fn = fn + ".csv";
                ff = new File(ff + ".csv");
            }
            IJ.log("Writing a CSV file.");
        }
        IJ.log("Writing to " + fn);

        if (fn.endsWith(".csv")) {
            writeCSV(ff);
        } else if (fn.endsWith(".json")) {
            writeJSON(ff);
        } else {
            IJ.log("Unknown output format for file name " + fn);
        }

    }
}

From source file:com.itd.dbmrgdao.TestTime_newscanner.java

@Ignore
@org.junit.Test//from   w  w w. j  av  a 2s.co m
public void test() throws ParseException {

    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;

        Boolean result = updateScanFileRoundUp2(br);

        br.close();

    } catch (IOException ex) {

    }

}

From source file:gr.aueb.mipmapgui.controller.file.ActionOpenMappingTask.java

public Scenario openCompositionFile(String fileAbsoluteFile, File file) {
    Scenario scenario = null;/*from  www.j  av  a2s .  com*/
    try {
        FileNameExtensionFilter xmlFilter = new FileNameExtensionFilter("XML", "xml");
        MappingTask mappingTask = null;
        DAOMappingTask daoMappingTask = new DAOMappingTask();
        if (xmlFilter.accept(file)) {
            mappingTask = daoMappingTask.loadMappingTask(scenarioNo, fileAbsoluteFile, true);
            //
            scenario = gestioneScenario(file, mappingTask, false);
        } else {
            ///throw new Exception
        }
    } catch (Exception ex) {
        logger.error(ex);
        ////Scenarios.releaseNumber();
    }
    return scenario;

}

From source file:com.itd.dbmrgdao.TestTime3.java

@Ignore
@org.junit.Test//  w w  w  .  j a v a  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:com.itd.dbmrgdao.TestTime6.java

@Ignore
@org.junit.Test/* w  w w  .ja v  a 2  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 mySql = new StringBuilder(
                "INSERT INTO scandata(sc_sysid,sc_scode,scdate,p1start,p2end) VALUES ");

        //             StringBuilder mySql = new StringBuilder(
        //                    "INSERT INTO scandata(sc_sysid,sc_scode,scdate,p1start,p1end,p2start,p2end,otstart,otend) VALUES ");

        // 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])) {
                mySql = mySql.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");
            }
        }

        mySql = mySql.append(" ('").append(sysid).append("','").append(scode).append("','").append(scdate)
                .append("','").append(p1Start).append("','").append(p2End).append("')");

        scanDao.executeSQL(mySql.toString());

        br.close();

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}

From source file:com.itd.dbmrgdao.TestTime5.java

@Ignore
@org.junit.Test//  www . jav a 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, scdate = null, p1Start = null, p1End = null, p2Start = null, p2End = null,
                otStart = null, otEnd = 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])) {

                List<Object> lst = new ArrayList<Object>();

                scanDao.deleteScanDataBySysId_Sdate(sysid, scdate);
                scanDao.insertScanData(sysid, "1985", scdate, p1Start, p1End, p2Start, p2End, otStart, otEnd);

                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");
            }

        }

        scanDao.deleteScanDataBySysId_Sdate(sysid, scdate);
        scanDao.insertScanData(sysid, "1985", scdate, p1Start, p1End, p2Start, p2End, otStart, otEnd);

        br.close();

        //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);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}

From source file:com.itd.dbmrgdao.TestTime7.java

@Ignore
@org.junit.Test/* w  ww .  ja va2  s  .  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, 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:com.opendoorlogistics.studio.components.map.plugins.snapshot.ExportImagePanel.java

private ExportImagePanel(ExportImageConfig inputConfig, Dimension defaultSize) {
    super(inputConfig, defaultSize);
    this.config = inputConfig;

    addCheckBox("Save to clipboard", config.isToClipboard(), new CheckChangedListener() {
        @Override//from w w  w.jav a 2s  .  com
        public void checkChanged(boolean isChecked) {
            ExportImagePanel.this.config.setToClipboard(isChecked);
        }
    });

    addCheckBox("Save to file", config.isToFile(), new CheckChangedListener() {
        @Override
        public void checkChanged(boolean isChecked) {
            ExportImagePanel.this.config.setToFile(isChecked);
            //   updateAppearance();
        }
    });

    addCheckBox("Show viewer", config.isToViewer(), new CheckChangedListener() {
        @Override
        public void checkChanged(boolean isChecked) {
            ExportImagePanel.this.config.setToViewer(isChecked);
            //   updateAppearance();
        }
    });

    FileNameExtensionFilter[] filters = new FileNameExtensionFilter[ImageType.values().length];
    for (int i = 0; i < filters.length; i++) {
        ImageType type = ImageType.values()[i];
        filters[i] = new FileNameExtensionFilter("Image file (" + type.name().toLowerCase() + ")",
                type.name().toLowerCase());
    }
    fileBrowser = new FileBrowserPanel(this.config.getFilename(), new FilenameChangeListener() {

        @Override
        public void filenameChanged(String newFilename) {
            ExportImagePanel.this.config.setFilename(newFilename);
            String ext = FilenameUtils.getExtension(newFilename);
            for (ImageType type : ImageType.values()) {
                if (Strings.equalsStd(ext, type.name())) {
                    imageTypeCombo.getComboBox().setSelectedItem(type);
                    config.setImageType(type);
                    break;
                }
            }
        }
    }, false, "Select file", filters);
    add(fileBrowser);

    validateFilename();
}

From source file:de.ep3.ftpc.controller.portal.CrawlerDownloadController.java

@Override
public void mouseClicked(MouseEvent e) {
    CrawlerResultsItem.PreviewPanel previewPanel = (CrawlerResultsItem.PreviewPanel) e.getSource();
    CrawlerResult crawlerResult = previewPanel.getCrawlerResult();
    CrawlerFile crawlerFile = crawlerResult.getFile();

    FTPClient ftpClient = crawlerResult.getFtpClient();

    if (ftpClient.isConnected()) {
        JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadWhileConnected"), null,
                JOptionPane.ERROR_MESSAGE);
        return;/*from  ww w .j a v  a  2 s.co  m*/
    }

    String fileExtension = crawlerFile.getExtension();

    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter chooserFilter = new FileNameExtensionFilter(
            i18n.translate("fileType", fileExtension.toUpperCase()), crawlerFile.getExtension());

    chooser.setApproveButtonText(i18n.translate("buttonSave"));
    chooser.setDialogTitle(i18n.translate("fileDownloadTo"));
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setFileFilter(chooserFilter);
    chooser.setSelectedFile(new File(crawlerFile.getName()));

    int selection = chooser.showSaveDialog(portalFrame);

    if (selection == JFileChooser.APPROVE_OPTION) {
        File fileToSave = chooser.getSelectedFile();

        Server relatedServer = crawlerResult.getServer();

        try {
            ftpClient.connect(relatedServer.need("server.ip"),
                    Integer.parseInt(relatedServer.need("server.port")));

            int replyCode = ftpClient.getReplyCode();

            if (!FTPReply.isPositiveCompletion(replyCode)) {
                throw new IOException(i18n.translate("crawlerServerRefused"));
            }

            if (relatedServer.has("user.name")) {
                String userName = relatedServer.get("user.name");
                String userPassword = "";

                if (relatedServer.hasTemporary("user.password")) {
                    userPassword = relatedServer.getTemporary("user.password");
                }

                boolean loggedIn = ftpClient.login(userName, userPassword);

                if (!loggedIn) {
                    throw new IOException(i18n.translate("crawlerServerAuthFail"));
                }
            }

            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

            /* Download file */

            InputStream is = ftpClient.retrieveFileStream(crawlerFile.getFullName());

            if (is != null) {

                byte[] rawFile = new byte[(int) crawlerFile.getSize()];

                int i = 0;

                while (true) {
                    int b = is.read();

                    if (b == -1) {
                        break;
                    }

                    rawFile[i] = (byte) b;
                    i++;

                    /* Occasionally update the download progress */

                    if (i % 1024 == 0) {
                        int progress = Math.round((((float) i) / crawlerFile.getSize()) * 100);

                        status.add(i18n.translate("crawlerDownloadProgress", progress));
                    }
                }

                is.close();
                is = null;

                if (!ftpClient.completePendingCommand()) {
                    throw new IOException();
                }

                Files.write(fileToSave.toPath(), rawFile);
            }

            /* Logout and disconnect */

            ftpClient.logout();

            tryDisconnect(ftpClient);

            status.add(i18n.translate("crawlerDownloadDone"));
        } catch (IOException ex) {
            tryDisconnect(ftpClient);

            JOptionPane.showMessageDialog(portalFrame, i18n.translate("crawlerDownloadFailed", ex.getMessage()),
                    null, JOptionPane.ERROR_MESSAGE);
        }
    }
}