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:generadorqr.jifrNuevoQr.java
void CargarVideo(JLabel label, Integer identificador) { int resultado; // ventana = new CargarFoto(); JFileChooser jfchCargarVideo = new JFileChooser(); FileNameExtensionFilter filtro = new FileNameExtensionFilter("MP4", "mp4"); jfchCargarVideo.setFileFilter(filtro); resultado = jfchCargarVideo.showOpenDialog(null); if (JFileChooser.APPROVE_OPTION == resultado) { fichero = jfchCargarVideo.getSelectedFile(); try {/*from w w w . j a v a 2 s . co m*/ tempVideo = fichero.getPath(); tempNombreMultimedia[identificador] = fichero.getName(); label.setText(tempNombreMultimedia[identificador]); if (label.getText().length() > 10) label.setText(tempNombreMultimedia[identificador].substring(0, 10) + "...mp4"); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex); } } }
From source file:generadorqr.jifrNuevoQr.java
void CargarAudio(JLabel label, Integer identificador) { int resultado; // ventana = new CargarFoto(); JFileChooser jfchCargarVideo = new JFileChooser(); FileNameExtensionFilter filtro = new FileNameExtensionFilter("MP3", "mp3"); jfchCargarVideo.setFileFilter(filtro); resultado = jfchCargarVideo.showOpenDialog(null); if (JFileChooser.APPROVE_OPTION == resultado) { fichero = jfchCargarVideo.getSelectedFile(); try {//from w w w . j a va 2 s. c om tempAudio = fichero.getPath(); tempNombreMultimedia[identificador] = fichero.getName(); label.setText(tempNombreMultimedia[identificador]); if (label.getText().length() > 10) label.setText(tempNombreMultimedia[identificador].substring(0, 10) + "...mp3"); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex); } } }
From source file:generadorqr.jifrNuevoQr.java
void CargarImagen(JLabel label, Integer identificador) { int resultado; // ventana = new CargarFoto(); JFileChooser jfchCargarfoto = new JFileChooser(); FileNameExtensionFilter filtro = new FileNameExtensionFilter("JPG", "jpg"); jfchCargarfoto.setFileFilter(filtro); resultado = jfchCargarfoto.showOpenDialog(null); if (JFileChooser.APPROVE_OPTION == resultado) { fichero = jfchCargarfoto.getSelectedFile(); try {/*from ww w . j av a2 s. c o m*/ tempImagen[identificador] = fichero.getPath(); tempNombreArchivo[identificador] = fichero.getName(); ImageIcon icon = new ImageIcon(fichero.toString()); Icon icono = new ImageIcon(icon.getImage().getScaledInstance(label.getWidth(), label.getHeight(), Image.SCALE_DEFAULT)); label.setText(null); label.setIcon(icono); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex); } } }
From source file:com.sshtools.common.ui.SshToolsApplicationClientPanel.java
/** * *///w w w . j a va 2 s .c o m public void open() { // Create a file chooser with the current directory set to the // application home String prefsDir = super.getApplication().getApplicationPreferencesDirectory().getAbsolutePath(); JFileChooser fileDialog = new JFileChooser(prefsDir); fileDialog.setFileFilter(connectionFileFilter); // Show it int ret = fileDialog.showOpenDialog(this); // If we've approved the selection then process if (ret == fileDialog.APPROVE_OPTION) { PreferencesStore.put(PREF_CONNECTION_FILE_DIRECTORY, fileDialog.getCurrentDirectory().getAbsolutePath()); // Get the file File f = fileDialog.getSelectedFile(); open(f); } }
From source file:jmemorize.gui.swing.frames.MainFrame.java
@Override public File determineLessonFileToOpen() { // from determineLessonFile(file): final File lessonFile; final JFileChooser chooser = new JFileChooser(); try {/*from w w w . jav a2s. co m*/ chooser.setCurrentDirectory(Settings.loadLastDirectory()); } catch (final Exception ioe) { Main.logThrowable("Could not load last directory", ioe); chooser.setCurrentDirectory(null); } chooser.setFileFilter(MainFrame.FILE_FILTER); final int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { lessonFile = chooser.getSelectedFile(); } else { lessonFile = null; } return lessonFile; }
From source file:cn.labthink.ReadAccess060.java
private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed //filter/*from www .j a va 2s.c o m*/ 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// www. ja v a2s.co m 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:de.bfs.radon.omsimulation.gui.OMPanelData.java
/** * Initialises the interface of the data panel. *///from ww w .j ava2 s. co m protected void initialize() { setLayout(null); lblExportChartTo = new JLabel("Export chart to ..."); lblExportChartTo.setBounds(436, 479, 144, 14); lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblExportChartTo.setVisible(false); add(lblExportChartTo); btnCsv = new JButton("CSV"); btnCsv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String csv; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("csv")) { csv = ""; } else { csv = ".csv"; } String csvPath = file.getAbsolutePath() + csv; OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem(); double[] selectedValues = selectedRoom.getValues(); File csvFile = new File(csvPath); try { FileWriter logWriter = new FileWriter(csvFile); BufferedWriter csvOutput = new BufferedWriter(logWriter); csvOutput.write("\"ID\";\"" + selectedRoom.getId() + "\""); csvOutput.newLine(); for (int i = 0; i < selectedValues.length; i++) { csvOutput.write("\"" + i + "\";\"" + (int) selectedValues[i] + "\""); csvOutput.newLine(); } JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success", JOptionPane.INFORMATION_MESSAGE); csvOutput.close(); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnCsv.setBounds(590, 475, 70, 23); btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnCsv.setVisible(false); add(btnCsv); btnPdf = new JButton("PDF"); btnPdf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String pdf; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("pdf")) { pdf = ""; } else { pdf = ".pdf"; } String pdfPath = file.getAbsolutePath() + pdf; OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); String title = building.getName(); OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem(); JFreeChart chart = OMCharts.createRoomChart(title, selectedRoom, false); int height = (int) PageSize.A4.getWidth(); int width = (int) PageSize.A4.getHeight(); try { OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title); JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnPdf.setBounds(670, 475, 70, 23); btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnPdf.setVisible(false); add(btnPdf); lblSelectProject = new JLabel("Select Project"); lblSelectProject.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectProject.setBounds(10, 65, 132, 14); add(lblSelectProject); lblSelectRoom = new JLabel("Select Room"); lblSelectRoom.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectRoom.setBounds(10, 94, 132, 14); add(lblSelectRoom); panelData = new JPanel(); panelData.setBounds(10, 118, 730, 347); add(panelData); btnRefresh = new JButton("Load"); btnRefresh.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("") && !txtOmbFile.getText().equals(" ")) { txtOmbFile.setBackground(Color.WHITE); String ombPath = txtOmbFile.getText(); String omb; String[] tmpFileName = ombPath.split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(ombPath + omb); setOmbFile(ombPath + omb); File ombFile = new File(ombPath + omb); if (ombFile.exists()) { txtOmbFile.setBackground(Color.WHITE); btnRefresh.setEnabled(false); comboBoxProjects.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); btnPdf.setVisible(false); btnCsv.setVisible(false); lblExportChartTo.setVisible(false); progressBar.setVisible(true); progressBar.setStringPainted(true); progressBar.setIndeterminate(true); refreshProjectsTask = new RefreshProjects(); refreshProjectsTask.execute(); } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!", "Error", JOptionPane.ERROR_MESSAGE); } } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning", JOptionPane.WARNING_MESSAGE); } } }); btnRefresh.setBounds(616, 61, 124, 23); add(btnRefresh); btnMaximize = new JButton("Fullscreen"); btnMaximize.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnMaximize.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (comboBoxRooms.isEnabled()) { if (comboBoxRooms.getSelectedItem() != null) { OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); String title = building.getName(); OMRoom room = (OMRoom) comboBoxRooms.getSelectedItem(); panelRoom = createRoomPanel(title, room, false, false); JFrame chartFrame = new JFrame(); JPanel chartPanel = createRoomPanel(title, room, false, true); chartFrame.getContentPane().add(chartPanel); chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight()); chartFrame.setTitle("OM Simulation Tool: " + title + ", Room " + room.getId()); chartFrame.setResizable(true); chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); chartFrame.setVisible(true); } } } }); btnMaximize.setBounds(10, 475, 124, 23); btnMaximize.setVisible(false); add(btnMaximize); comboBoxProjects = new JComboBox<OMBuilding>(); comboBoxProjects.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); comboBoxProjects.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { boolean b = false; Color c = null; if (comboBoxProjects.isEnabled()) { if (comboBoxProjects.getSelectedItem() != null) { b = true; c = Color.WHITE; OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); comboBoxRooms.removeAllItems(); for (int i = 0; i < building.getRooms().length; i++) { comboBoxRooms.addItem(building.getRooms()[i]); } for (int i = 0; i < building.getCellars().length; i++) { comboBoxRooms.addItem(building.getCellars()[i]); } for (int i = 0; i < building.getMiscs().length; i++) { comboBoxRooms.addItem(building.getMiscs()[i]); } } else { b = false; c = null; } } else { b = false; c = null; } lblSelectRoom.setEnabled(b); panelData.setEnabled(b); btnMaximize.setVisible(b); comboBoxRooms.setEnabled(b); panelData.setBackground(c); } }); comboBoxProjects.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { boolean b = false; Color c = null; if (comboBoxProjects.isEnabled()) { if (comboBoxProjects.getSelectedItem() != null) { b = true; c = Color.WHITE; OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); comboBoxRooms.removeAllItems(); for (int i = 0; i < building.getRooms().length; i++) { comboBoxRooms.addItem(building.getRooms()[i]); } for (int i = 0; i < building.getCellars().length; i++) { comboBoxRooms.addItem(building.getCellars()[i]); } for (int i = 0; i < building.getMiscs().length; i++) { comboBoxRooms.addItem(building.getMiscs()[i]); } } else { b = false; c = null; } } else { b = false; c = null; } lblSelectRoom.setEnabled(b); panelData.setEnabled(b); btnMaximize.setVisible(b); comboBoxRooms.setEnabled(b); panelData.setBackground(c); } }); comboBoxProjects.setBounds(152, 61, 454, 22); add(comboBoxProjects); comboBoxRooms = new JComboBox<OMRoom>(); comboBoxRooms.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); comboBoxRooms.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (comboBoxRooms.isEnabled()) { if (comboBoxRooms.getSelectedItem() != null) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); remove(panelData); comboBoxRooms.setEnabled(false); refreshChartsTask = new RefreshCharts(); refreshChartsTask.execute(); } } } }); comboBoxRooms.setBounds(152, 90, 454, 22); add(comboBoxRooms); progressBar = new JProgressBar(); progressBar.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); progressBar.setBounds(10, 475, 730, 23); progressBar.setVisible(false); add(progressBar); lblSelectRoom.setEnabled(false); panelData.setEnabled(false); comboBoxRooms.setEnabled(false); lblHelp = new JLabel( "Select an OMB-Object file to analyse its data. You can inspect radon concentration for each room."); lblHelp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblHelp.setForeground(Color.GRAY); lblHelp.setBounds(10, 10, 730, 14); add(lblHelp); txtOmbFile = new JTextField(); txtOmbFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); txtOmbFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { setOmbFile(txtOmbFile.getText()); } }); txtOmbFile.setBounds(152, 33, 454, 20); add(txtOmbFile); txtOmbFile.setColumns(10); btnBrowse = new JButton("Browse"); btnBrowse.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb")); fileDialog.showOpenDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String omb; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(file.getAbsolutePath() + omb); setOmbFile(file.getAbsolutePath() + omb); } } }); btnBrowse.setBounds(616, 32, 124, 23); add(btnBrowse); lblSelectOmbfile = new JLabel("Select OMB-File"); lblSelectOmbfile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectOmbfile.setBounds(10, 36, 132, 14); add(lblSelectOmbfile); }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveSpj(SpinCADBank bank) { // Create a file chooser String savedPath = prefs.get("MRUSpjFolder", ""); String[] spnFileNames = new String[8]; final JFileChooser fc = new JFileChooser(savedPath); // In response to a button click: FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin Project Files", "spj"); fc.setFileFilter(filter); // XXX debug/*from ww w . j av a 2 s. co m*/ fc.showSaveDialog(new JFrame()); File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spj")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spj"); } int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame1 = new JFrame(); n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); } if (n == JOptionPane.YES_OPTION) { // filePath points at the desired Spj file String filePath = fileToBeSaved.getPath(); String folder = fileToBeSaved.getParent().toString(); // export the individual SPN files for (int i = 0; i < 8; i++) { try { String asmFileNameRoot = FilenameUtils.removeExtension(bank.patch[i].patchFileName); String asmFileName = folder + "\\" + asmFileNameRoot + ".spn"; if (bank.patch[i].patchFileName != "Untitled") { fileSaveAsm(bank.patch[i], asmFileName); spnFileNames[i] = asmFileName; } } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } finally { } } // now create the Spin Project file fileToBeSaved.delete(); BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(fileToBeSaved, true)); } catch (IOException e1) { e1.printStackTrace(); } try { writer.write("NUMDOCS:8"); writer.newLine(); } catch (IOException e1) { e1.printStackTrace(); } for (int i = 0; i < 8; i++) { try { if (bank.patch[i].patchFileName != "Untitled") { writer.write(spnFileNames[i] + ",1"); } else { writer.write(",0"); } writer.newLine(); } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!\n" + filePath, "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } } // write the build flags try { writer.write(",1,1,1"); writer.newLine(); } catch (IOException e1) { e1.printStackTrace(); } try { writer.close(); } catch (IOException e) { e.printStackTrace(); } saveMRUSpjFolder(filePath); } }
From source file:au.org.ala.delta.editor.DeltaEditor.java
public File selectFile(boolean open) { File selectedFile = null;//from w w w . j a v a 2 s .c om JFileChooser chooser = new JFileChooser(); if (_lastDirectory != null) { chooser.setCurrentDirectory(_lastDirectory); } chooser.setFileFilter(new FileNameExtensionFilter("Delta Editor files *.dlt", DELTA_FILE_EXTENSION)); int dialogResult; if (open) { dialogResult = chooser.showOpenDialog(getMainFrame()); } else { dialogResult = chooser.showSaveDialog(getMainFrame()); } if (dialogResult == JFileChooser.APPROVE_OPTION) { selectedFile = chooser.getSelectedFile(); _lastDirectory = chooser.getCurrentDirectory(); } return selectedFile; }