Example usage for javax.swing.filechooser FileSystemView getHomeDirectory

List of usage examples for javax.swing.filechooser FileSystemView getHomeDirectory

Introduction

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

Prototype

public File getHomeDirectory() 

Source Link

Document

Returns the home directory.

Usage

From source file:MainClass.java

public static void main(String[] args) {

    JFileChooser chooser = new JFileChooser();
    FileSystemView view = chooser.getFileSystemView();

    System.out.println("The home directory is " + view.getHomeDirectory());
}

From source file:com.sunchenbin.store.feilong.core.io.SpecialFolder.java

/**
 * ?<br>/* w  w  w  . j  a va  2  s.  c  o  m*/
 * example:win7:C:\Users\venusdrogon\Desktop.
 * 
 * <br>
 *  ?? USERPROFILE<br>
 * return C:\Users\venusdrogon ? Desktop 
 * 
 * @return ??
 * @see FileSystemView#getHomeDirectory()
 */
public static String getDesktop() {
    FileSystemView fileSystemView = FileSystemView.getFileSystemView();
    File file = fileSystemView.getHomeDirectory();
    //  ?? USERPROFILE======>C:\Users\venusdrogon ? Desktop 
    return file.getPath();
}

From source file:com.feilong.commons.core.io.SpecialFolder.java

/**
 * ?<br>/*ww w .j a  va  2s. c o m*/
 * example:win7:C:\Users\venusdrogon\Desktop.
 * 
 * <br>
 *  ?? USERPROFILE<br>
 * return C:\Users\venusdrogon ? Desktop 
 * 
 * @return ??
 * @see FileSystemView#getHomeDirectory()
 */
public static final String getDesktop() {
    FileSystemView fileSystemView = FileSystemView.getFileSystemView();
    File file = fileSystemView.getHomeDirectory();
    //  ?? USERPROFILE======>C:\Users\venusdrogon ? Desktop 
    return file.getPath();
}

From source file:cn.labthink.ReadAccess060.java

private void jButton_exportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_exportActionPerformed
    JFileChooser jfc = new JFileChooser();
    ExtensionFileFilter filter;//from   w w  w.  ja v  a  2s  .c o m

    if (jTable1.getSelectedRowCount() == 1) {
        // filter
        filter = new ExtensionFileFilter("xls", false, true);
        filter.setDescription("Save Export File");

        jfc.setDialogTitle("Create the Export Excel file");
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    } else if (jTable1.getSelectedRowCount() > 1) {
        // filter
        filter = new ExtensionFileFilter("", false, true);
        filter.setDescription("Save Export Files");
        jfc.setDialogTitle("Choose the Export Directory");
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    } else {
        //?
        jLabel_info.setText("<html><font color='red'>No Record Selected</font></html>");
        return;
    }

    //?
    FileSystemView fsv = FileSystemView.getFileSystemView();
    //?
    jfc.setCurrentDirectory(fsv.getHomeDirectory());

    jfc.setMultiSelectionEnabled(false);
    jfc.setDialogType(JFileChooser.SAVE_DIALOG);

    jfc.setFileFilter(filter);
    int result = jfc.showSaveDialog(this); // ""?

    if (result == JFileChooser.APPROVE_OPTION) {
        if (jTable1.getSelectedRowCount() == 1) {
            //
            String filesrc = jfc.getSelectedFile().getAbsolutePath();
            if (!filesrc.toLowerCase().endsWith(".xls")) {
                filesrc = jfc.getSelectedFile().getAbsolutePath() + ".xls";
            }
            outputfile = new File(filesrc);
            jLabel_info.setText("Exported File:" + outputfile.getAbsolutePath());
        } else if (jTable1.getSelectedRowCount() > 1) {
            //
            outputfile = jfc.getSelectedFile().isDirectory() ? jfc.getSelectedFile()
                    : jfc.getSelectedFile().getParentFile();
            if (outputfile == null) {
                outputfile = fsv.getHomeDirectory();
            }
            jLabel_info.setText("Exported to path:" + outputfile.getAbsolutePath());
        } else {
            //?
            return;
        }

    } else {
        return;
    }

    if (inputfile == null) {
        return;
    }

    int[] rows = jTable1.getSelectedRows();
    if (rows.length == 1) {
        //?
        book = null;
        ExportOneRecord(rows[0]);
    } else {
        File path = outputfile;

        for (int rowindex = 0; rowindex < rows.length; rowindex++) {
            int k = rows[rowindex];
            book = null;
            outputfile = new File(path.getAbsolutePath() + "/" + jTable1.getValueAt(k, 0) + ".xls");
            ExportOneRecord(k);
        }
    }
    //        int k = jTable1.getSelectedRow();
    //        ExportOneRecord(k);

}

From source file:cn.labthink.ReadAccess060.java

private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed

    //filter//w  ww .j a  va2s.  c  om
    ExtensionFileFilter filter = new ExtensionFileFilter("mdb", false, true);
    filter.setDescription("Open DataBase File");
    //?

    JFileChooser jfc = new JFileChooser();

    FileSystemView fsv = FileSystemView.getFileSystemView();
    //?
    jfc.setCurrentDirectory(fsv.getHomeDirectory());

    jfc.setDialogTitle("Choose the mdb file");
    jfc.setMultiSelectionEnabled(false);
    jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    jfc.setFileFilter(filter);
    int result = jfc.showOpenDialog(this); // ""?
    if (result == JFileChooser.APPROVE_OPTION) {
        String filesrc = jfc.getSelectedFile().getAbsolutePath();
        inputfile = jfc.getSelectedFile();
        jLabel_dbpath.setText("DB File Path:" + filesrc);
        maxid = Integer.MIN_VALUE;
        minid = Integer.MAX_VALUE;
    } else {
        return;
    }
    //

    Infodata = new Vector();
    Infocolumns = new Vector();

    try {

        //            String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://b.MDB";
        if (inputfile == null) {
            return;
        }
        initDB();

        sql = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rs = sql.executeQuery("SELECT * FROM test order by testid desc");

        Infocolumns.add("TestID");
        Infocolumns.add("TestType");
        Infocolumns.add("DeviceID");
        Infocolumns.add("CellID");
        Infocolumns.add("Operator");
        Infocolumns.add("StartTime");
        Infocolumns.add("EndTime");
        Infocolumns.add("Comments");
        Infocolumns.add("SetTemp.");
        int columnCount = Infocolumns.size();
        Vector row;
        while (rs.next()) {
            row = new Vector(columnCount);
            int temp = 0;
            int ivalue = rs.getInt("TESTID");
            maxid = maxid < ivalue ? ivalue : maxid;
            minid = minid > ivalue ? ivalue : minid;
            row.add(ivalue);
            temp = rs.getInt("TESTTYPE");
            if (temp == 1) {
                row.add("OTR");
            } else if (temp == 2) {
                row.add("WVTR");
            } else {
                row.add(temp);
            }
            row.add(rs.getInt("DEVICEID"));
            row.add(rs.getString("CELLID"));
            row.add(rs.getString("OPERATOR"));
            row.add(rs.getDate("STARTTIME"));
            row.add(rs.getDate("ENDTIME"));
            row.add(rs.getString("COMMENTS"));
            row.add(rs.getDouble("SETTEMP"));
            //                row.add(rs.getString(11));
            //                row.add(rs.getInt(10));
            Infodata.add(row);
        }

        DefaultTableModel tableModel = new DefaultTableModel(Infodata, Infocolumns);
        jTable1.setModel(tableModel);
        //?  
        // jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);  
        jTable1.setSelectionBackground(Color.orange);
        //?
        TableRowSorter<TableModel> tableRowSorter = new TableRowSorter<TableModel>(tableModel);
        jTable1.setRowSorter(tableRowSorter);
        //            jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //table
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// table
        tcr.setHorizontalAlignment(SwingConstants.CENTER);// ??
        jTable1.setDefaultRenderer(Object.class, tcr);

        //
        ((DefaultTableCellRenderer) jTable1.getTableHeader().getDefaultRenderer())
                .setHorizontalAlignment(SwingConstants.CENTER);
        //            DefaultTableCellRenderer  rh = new DefaultTableCellRenderer();
        //            rh.setHorizontalAlignment(SwingConstants.CENTER);
        //            jTable1.getTableHeader().setDefaultRenderer(rh);

        jTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(28);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(4).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(5).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(6).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(7).setPreferredWidth(100);

    } catch (SQLException ee) {
        System.out.println(ee);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            sql.close();
        } catch (Exception e) {
        }
        try {
            rs.close();
        } catch (Exception e) {
        }
    }

    //        validate();

}

From source file:cn.labthink.ReadAccess330.java

private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed

    //filter/*from   w ww  .  ja  va 2 s. c  om*/
    ExtensionFileFilter filter = new ExtensionFileFilter("mdb", false, true);
    filter.setDescription("Open DataBase File");
    //?

    JFileChooser jfc = new JFileChooser();

    FileSystemView fsv = FileSystemView.getFileSystemView();
    //?
    jfc.setCurrentDirectory(fsv.getHomeDirectory());

    jfc.setDialogTitle("Choose the mdb file");
    jfc.setMultiSelectionEnabled(false);
    jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    jfc.setFileFilter(filter);
    int result = jfc.showOpenDialog(this); // ""?
    if (result == JFileChooser.APPROVE_OPTION) {
        String filesrc = jfc.getSelectedFile().getAbsolutePath();
        inputfile = jfc.getSelectedFile();
        jLabel_dbpath.setText("DB File Path:" + filesrc);
        maxid = Integer.MIN_VALUE;
        minid = Integer.MAX_VALUE;
    } else {
        return;
    }
    //

    Infodata = new Vector();
    Infocolumns = new Vector();

    try {

        //            String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://b.MDB";
        if (inputfile == null) {
            return;
        }
        initDB();

        sql = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rs = sql.executeQuery("SELECT * FROM test order by testid desc");

        Infocolumns.add("TestID");
        Infocolumns.add("TestType");
        Infocolumns.add("DeviceID");
        Infocolumns.add("CellID");
        Infocolumns.add("Operator");
        Infocolumns.add("StartTime");
        Infocolumns.add("EndTime");
        Infocolumns.add("Comments");
        Infocolumns.add("SetTemp.");
        int columnCount = Infocolumns.size();
        Vector row;
        while (rs.next()) {
            row = new Vector(columnCount);
            int temp = 0;
            int ivalue = rs.getInt("TESTID");
            maxid = maxid < ivalue ? ivalue : maxid;
            minid = minid > ivalue ? ivalue : minid;
            row.add(ivalue);
            temp = rs.getInt("TESTTYPE");
            if (temp == 1) {
                row.add("OTR");
            } else if (temp == 2) {
                row.add("WVTR");
            } else {
                row.add(temp);
            }
            row.add(rs.getInt("DEVICEID"));
            row.add(rs.getString("CELLID"));
            row.add(rs.getString("OPERATOR"));
            row.add(rs.getDate("STARTTIME"));
            row.add(rs.getDate("ENDTIME"));
            row.add(rs.getString("COMMENTS"));
            row.add(rs.getDouble("SETTEMP"));
            //                row.add(rs.getString(11));
            //                row.add(rs.getInt(10));
            Infodata.add(row);
        }

        DefaultTableModel tableModel = new DefaultTableModel(Infodata, Infocolumns);
        jTable1.setModel(tableModel);
        //?  
        // jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);  
        jTable1.setSelectionBackground(Color.orange);
        //?
        TableRowSorter<TableModel> tableRowSorter = new TableRowSorter<TableModel>(tableModel);
        jTable1.setRowSorter(tableRowSorter);
        //            jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //table
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// table
        tcr.setHorizontalAlignment(SwingConstants.CENTER);// ??
        jTable1.setDefaultRenderer(Object.class, tcr);

        //
        ((DefaultTableCellRenderer) jTable1.getTableHeader().getDefaultRenderer())
                .setHorizontalAlignment(SwingConstants.CENTER);
        //            DefaultTableCellRenderer  rh = new DefaultTableCellRenderer();
        //            rh.setHorizontalAlignment(SwingConstants.CENTER);
        //            jTable1.getTableHeader().setDefaultRenderer(rh);

        jTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(28);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(4).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(5).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(6).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(7).setPreferredWidth(100);

    } catch (SQLException ee) {
        System.out.println(ee);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            sql.close();
        } catch (Exception e) {
        }
        try {
            rs.close();
        } catch (Exception e) {
        }
    }

    //        validate();

}

From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

protected JFileChooser initFileChooser() {
    ExtensionFileFilter filter = new ExtensionFileFilter("log,txt", true, true);
    filter.setDescription("?");
    JFileChooser jfc = new JFileChooser();
    FileSystemView fsv = FileSystemView.getFileSystemView();
    //?//from   w  w w .  j a  v a 2  s. c o  m
    jfc.setCurrentDirectory(fsv.getHomeDirectory());
    jfc.setDialogTitle("?");
    jfc.setMultiSelectionEnabled(false);
    jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);//JFileChooser.FILES_AND_DIRECTORIES
    jfc.setFileFilter(filter);
    return jfc;
}

From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java

public void openFiletoCurve() throws NumberFormatException {
    String tempstr = jFormattedTextField_temp.getText();
    int tempint = Integer.parseInt(tempstr);
    dropinterval = tempint;/*  w w  w .  java 2 s  . c  om*/

    //??
    //??0?1
    double oldzero = -1000;
    long oldzerotime = -1;
    double oldstatus = -1;

    filterds = new double[dropinterval];
    SimpleDateFormat sdfx = new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss]");
    //        String content;
    List<String> fileContentStringList = null;

    JFileChooser jfc = initFileChooser();

    //?lastpath
    String latestPath = (String) datas.get("lastpath");

    File currentDir = null;
    FileSystemView fsv = FileSystemView.getFileSystemView();
    if (latestPath == null) {
        //?
        currentDir = fsv.getHomeDirectory();
    } else {
        currentDir = new File(latestPath);
        if (currentDir.exists() && currentDir.isDirectory()) {
        } else {
            currentDir = fsv.getHomeDirectory();
        }
    }
    jfc.setCurrentDirectory(currentDir);

    int result = jfc.showOpenDialog(this); // ""?
    if (result == JFileChooser.APPROVE_OPTION) {
        //            String filepath = jfc.getSelectedFile().getAbsolutePath();
        //lastpath
        datas.put("lastpath", jfc.getSelectedFile().isDirectory() ? jfc.getSelectedFile().getAbsolutePath()
                : jfc.getSelectedFile().getParent());

        if (jfc.getSelectedFile() == null) {
            //
            System.out.println("!!");
            return;
        }
        try {
            fileContentStringList = Files.readLines(jfc.getSelectedFile(), Charsets.ISO_8859_1);

        } catch (IOException ex) {
            Logger.getLogger(JIF_DrawChart_w3330.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        System.out.println("!!");
        return;
    }

    //??,dropinterval
    parseFileToDataStructure(fileContentStringList, dropinterval);
    if (metadatas.size() == 0) {
        System.out.println("?");
        return;
    } else {
        chartPanel.getChart().setTitle("" + jfc.getSelectedFile().getName());
        System.out.println("" + jfc.getSelectedFile().getName());
        System.out.println(String.format("?%d", fileContentStringList.size()));
        System.out.println(String.format("?%d", metadatas.size()));
    }

    //?
    KalmanFilterHolder kfh_AmbiTemp = new KalmanFilterHolder(25d);//?
    KalmanFilterHolder kfh_ppm = new KalmanFilterHolder(13d);//?

    //===============kalman?
    clearChart();//?

    tsNotifyFalse();//?

    //??
    for (int i = 0; i < metadatas.size(); i++) {
        W3330MetaData data = metadatas.get(i);

        if (oldzero < -1) {
            oldzero = data.zero;
            oldzerotime = data.time.getTime();
        } else if (oldzero != data.zero) {
            oldzero = data.zero;
            oldzerotime = data.time.getTime();
            //
            Color purple = new Color(139, 0, 255);
            String Labelstr = String.format("%.4f", data.zero);
            chartDrawHerizonLine(data, purple, Labelstr);
        }

        //status 1?? 2 ? 3 4 5?? 6 7?? 8 9? 0 
        if (oldstatus != data.status) {
            oldstatus = data.status;
            //
            Color purple = new Color(139, 0, 255);
            String Labelstr;

            switch ((int) data.status) {
            case 1:
                Labelstr = "??";
                break;
            case 2:
                Labelstr = "?";
                break;
            case 3:
                Labelstr = "";
                break;
            case 4:
                Labelstr = "";
                break;
            case 5:
                Labelstr = "??";
                break;
            case 6:
                Labelstr = "";
                break;
            case 7:
                Labelstr = "??";
                break;
            case 8:
                Labelstr = "";
                break;
            case 9:
                Labelstr = "?";
                break;
            case 0:
                Labelstr = "";
                break;
            default:
                Labelstr = "???status=" + data.status;
                //                        throw new AssertionError();
            }
            //                Labelstr = String.format("%.4f", data.zero);
            chartDrawVerticalLine(data, purple, Labelstr);

            //?ppm
            kfh_ppm = new KalmanFilterHolder(data.wppm);//?
        }

        //
        data.filter1 = kfh_AmbiTemp.getEstimation(data.temp3);
        data.filter2 = kfh_ppm.getEstimation(data.wppm);

        //fitting2 = kalmanfilter2.getStateEstimation()[0]-(fitting-25)*0.78;
        //                        fitting2 = wppm-(fitting-25)*0.7;//ppm
        //                        fitting = kalmanfilter.getStateEstimation()[0];
        // state estimate shouldn't be larger than the measurement noise
        //                        double diff = Math.abs(x.getEntry(0) - kalmanfilter.getStateEstimation()[0]);
        /*
                     //?
                     if (filterpoint < filterds.length) {
                     //?
                     filterds[filterpoint] = temp3;
                     filterpoint++;
                     fitting = wppm;
                     } else {
                
                     //???
                     filterds[filterpoint % filterds.length] = temp3;
                     double[] copy = Arrays.copyOf(filterds, filterds.length);
                     Arrays.sort(copy);
                
                     double total = 0;
                     for (int idx = copy.length / 4; idx < copy.length - copy.length / 4; idx++) {
                     total += copy[idx];
                     }
                     temp3 = total / (copy.length - copy.length / 4 - copy.length / 4);
                     filterpoint++;
                     //0.78?
                     //????
                     //                            fitting = wppm-(filterds[filterpoint%filterds.length]-25)*0.78;
                     fitting = wppm - (temp3 - 25) * 0.78;
                     }
                     */
        ts_wppm.addOrUpdate(new Millisecond(data.time), data.wppm);
        ts_wppm_zero.addOrUpdate(new Millisecond(data.time), data.ppmzero);
        ts_wvtr.addOrUpdate(new Millisecond(data.time), data.wvtr);
        //??100??100
        ts_flux.addOrUpdate(new Millisecond(data.time), data.flux);
        //25????25
        ts_tempambi.addOrUpdate(new Millisecond(data.time), data.temp3);
        //38????38
        ts_tempcell.addOrUpdate(new Millisecond(data.time), data.temp1);
        //?
        //status 1?? 2 ? 3 4 5?? 6 7?? 8 9? 0 
        ts_status.addOrUpdate(new Millisecond(data.time), data.status);
        ts_fitting.addOrUpdate(new Millisecond(data.time), data.filter1);
        data.fitting2 = data.wppm - (data.temp3 - 25) * 1.25;//??
        //data.fitting2 = data.wppm *(273.15+25)/(273.15+data.temp3);//??
        //            data.fitting2= data.wppm+(data.flux-40)*12.4;
        //            ts_fitting2.addOrUpdate(new Millisecond(data.time), data.fitting2);
        ts_fitting2.addOrUpdate(new Millisecond(data.time), data.filter2);
        //fitting2 ?
        /*
         int step = 20;
         step = tempint;
         if (data.zero > 0 && i % step == 0 && i > 2 * step) {
         //??
         double value_wvtr = (data.wppm - data.zero) * 0.02161956;
         double total = 0;
         double value_avg = 0;
         double old1 = (metadatas.get(i - step).wppm - data.zero);
         double old2 = (metadatas.get(i - step * 2).wppm - data.zero);
         total = (old1 + old2 + (data.wppm - data.zero)) * 0.02161956;
         value_avg = total / 3;
         double diff = (value_wvtr - value_avg) / value_avg;
         System.out.println(String.format(":%s?%.4f?%.4f???%.4f%%", sdfx.format(data.time), value_wvtr, value_avg, diff * 100));
         ts_fitting2.addOrUpdate(new Millisecond(data.time), data.wppm - old1 - data.zero);
         }
         */
    }

    tsNotifyTrue();//
}