List of usage examples for javax.swing.filechooser FileSystemView getFileSystemView
public static FileSystemView getFileSystemView()
From source file:com.devbury.mkremote.server.QuickLaunchServiceImpl.java
protected FileSystemView getFileSystemView() { return FileSystemView.getFileSystemView(); }
From source file:cn.labthink.ReadAccess060.java
private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed //filter/* ww w . j av a 2s . 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 w w . j a v a 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:ffx.ui.MainPanel.java
/** * <p>/* w ww . j a v a 2 s. c o m*/ * getPWD</p> * * @return a {@link java.io.File} object. */ public static File getPWD() { if (pwd == null) { pwd = new File(System.getProperty("user.dir", FileSystemView.getFileSystemView().getDefaultDirectory().getAbsolutePath())); } return pwd; }
From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java
public static Icon getFileIcon(File f) { if (f.exists()) { return FileSystemView.getFileSystemView().getSystemIcon(f); }// w ww. j a v a 2 s .co m try { return FunctionsX.getSystemIcon(f.getAbsolutePath()); } catch (IOException e) { return null; } }
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 ww w.j a v a 2 s . 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:de.quadrillenschule.azocamsyncd.gui.ConfigurationWizardJFrame.java
private void autoruninstalljButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoruninstalljButton1ActionPerformed boolean success = false; JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setApproveButtonText("Prepare card..."); File startFile = new File(System.getProperty("user.dir")); //Get the current directory // Find System Root while (!FileSystemView.getFileSystemView().isFileSystemRoot(startFile)) { startFile = startFile.getParentFile(); }//from w w w. j ava2s . co m jfc.setCurrentDirectory(startFile); int origDriveChooserRetVal = jfc.showDialog(rootPane, "Open"); if (origDriveChooserRetVal == JFileChooser.APPROVE_OPTION) { try { File myfile = new File(jfc.getSelectedFile().getAbsolutePath(), "autorun.sh"); myfile.createNewFile(); FileOutputStream fos; try { fos = new FileOutputStream(myfile); IOUtils.copy(getClass().getResourceAsStream( "/de/quadrillenschule/azocamsyncd/ftpservice/res/autorun.sh"), fos); fos.close(); success = true; } catch (FileNotFoundException ex) { Logger.getLogger(ConfigurationWizardJFrame.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(ConfigurationWizardJFrame.class.getName()).log(Level.SEVERE, null, ex); } } if (!success) { JOptionPane.showMessageDialog(rootPane, "The WiFi is SD card could not be written to. Please check if you selected the right card and it is not write-protected.", "SD card could not be prepared", JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(rootPane, "The WiFi SD card is prepared for operating an FTP and Telnet server.", "Success!", JOptionPane.INFORMATION_MESSAGE); step0jCheckBox.setSelected(true); step0jCheckBox.setText("Done"); updateSelectedPanel(1); } }
From source file:mendeley2kindle.MainUIFrame.java
private File guessKindleRoot() { String os = System.getProperty("os.name"); if (os.indexOf("Windows") >= 0) { FileSystemView fs = FileSystemView.getFileSystemView(); Pattern pat = Pattern.compile("^Kindle \\(\\w:\\)$"); for (File f : File.listRoots()) { String name = fs.getSystemDisplayName(f); if (pat.matcher(name).matches()) { return f; }/*from w w w.j a va2s .c o m*/ } } else if (os.indexOf("Linux") >= 0) { File f = new File("/media/"); return f.isDirectory() ? f : null; } else if (os.indexOf("Mac") >= 0) { File f = new File("/Volumes/Kindle/"); return f.isDirectory() ? f : new File("/Volumes/"); } return null; }
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;//from w w w . ja va2s . c o m //?? //??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();// }
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 2s .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; }