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:ar.edu.uns.cs.vyglab.arq.rockar.gui.JFrameControlPanel.java
protected void exportOverview() { File currentDir = new File(System.getProperty("user.dir")); JFileChooser saveDialog = new JFileChooser(currentDir); FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG File", "png", "ong"); saveDialog.setFileFilter(filter); int response = saveDialog.showSaveDialog(this); if (response == saveDialog.APPROVE_OPTION) { File outputfile = saveDialog.getSelectedFile(); if (outputfile.getName().lastIndexOf(".") == -1) { outputfile = new File(outputfile.getName() + ".png"); }/*from w w w . j a v a 2 s . c o m*/ try { //ImageIO.write(this.overview, "jpg", outputfile); BufferedImage bi = new BufferedImage(this.jLabelOverview.getIcon().getIconWidth(), this.jLabelOverview.getIcon().getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); // paint the Icon to the BufferedImage. this.jLabelOverview.getIcon().paintIcon(null, g, 0, 0); g.dispose(); ImageIO.write(bi, "png", outputfile); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveHex(SpinCADBank bank) { // Create a file chooser String savedPath = prefs.get("MRUHexFolder", ""); final JFileChooser fc = new JFileChooser(savedPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Hex Files", "hex"); fc.setFileFilter(filter); fc.showSaveDialog(new JFrame()); File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".hex")) { fileToBeSaved = new File(fc.getSelectedFile() + ".hex"); }/*from w ww .j a va 2s.com*/ 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) { String filePath; try { filePath = fileToBeSaved.getPath(); fileToBeSaved.delete(); } finally { } for (int i = 0; i < 8; i++) { try { if (bank.patch[i].isHexFile) { fileSaveHex(i, bank.patch[i].hexFile, filePath); } else { fileSaveHex(i, bank.patch[i].patchModel.getRenderBlock().generateHex(), filePath); } } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } } saveMRUHexFolder(filePath); } }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSavePatchAs(SpinCADPatch p) { // Create a file chooser String savedPath = prefs.get("MRUPatchFolder", ""); final JFileChooser fc = new JFileChooser(savedPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("SpinCAD Files", "spcd"); fc.setFileFilter(filter); fc.setSelectedFile(new File(p.patchFileName)); int returnVal = fc.showSaveDialog(new JFrame()); // need to process user canceling box right here if (returnVal == JFileChooser.APPROVE_OPTION) { // In response to a button click: File fileToBeSaved = fc.getSelectedFile(); if (!fileToBeSaved.getAbsolutePath().endsWith(".spcd")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spcd"); }/*from w w w. java2s.com*/ int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame = new JFrame(); n = JOptionPane.showConfirmDialog(frame, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); } if (n == JOptionPane.YES_OPTION) { try { String filePath = fileToBeSaved.getPath(); String fileName = fileToBeSaved.getName(); p.patchFileName = fileName; fileSavePatch(p); recentPatchFileList.add(fileToBeSaved); saveMRUPatchFolder(filePath); } catch (Exception e) { // thrown over in SpinCADFile.java e.printStackTrace(); SpinCADDialogs.MessageBox("File save failed!", "look at stack trace for info"); } finally { p.setChanged(false); } } } }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveBankAs(SpinCADBank b) { // Create a file chooser String savedPath = prefs.get("MRUBankFolder", ""); final JFileChooser fc = new JFileChooser(savedPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("SpinCAD Bank Files", "spbk"); fc.setFileFilter(filter); fc.setSelectedFile(new File(b.bankFileName)); int returnVal = fc.showSaveDialog(new JFrame()); // need to process user canceling box right here if (returnVal == JFileChooser.APPROVE_OPTION) { // In response to a button click: File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spbk")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spbk"); }/*from w w w. j a va2 s . c o m*/ b.bankFileName = fileToBeSaved.getName(); int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame = new JFrame(); n = JOptionPane.showConfirmDialog(frame, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { try { fileSaveBank(b); } finally { } } } else { fileSaveBank(b); } b.changed = false; recentBankFileList.add(fileToBeSaved); saveMRUBankFolder(fileToBeSaved.getPath()); b.bankFileName = fileToBeSaved.getName(); } }
From source file:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java
private void loadLicenseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadLicenseButtonActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("License File", "lic")); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); License license = License.loadFromFile(file); if (license != null) try { licenseManager.setLicense(license); updateLicenseInfo();//from w ww. ja v a2s. c o m } catch (IOException e) { GUIUtils.displayError(this, "Error updating license. You may need to reload the license next time you start EventManager"); } else GUIUtils.displayError(this, "Error while loading license file"); } }
From source file:ar.edu.uns.cs.vyglab.arq.rockar.gui.JFrameControlPanel.java
public void saveTable() { File currentDir = new File(System.getProperty("user.dir")); JFileChooser saveDialog = new JFileChooser(currentDir); FileNameExtensionFilter filter = new FileNameExtensionFilter("MTF File", "mtf", "mtf"); saveDialog.setFileFilter(filter); int response = saveDialog.showSaveDialog(this); if (response == saveDialog.APPROVE_OPTION) { File file = saveDialog.getSelectedFile(); if (file.getName().lastIndexOf(".") == -1) { file = new File(file.getName() + ".mtf"); }/* www. j a v a 2 s . co m*/ DataCenter.fileMineralList = file; try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // root elements Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement("table"); doc.appendChild(rootElement); // para cada mineral en la tabla de minerales, agrego un Element for (int i = 0; i < this.jTableMineralsModel.getRowCount(); i++) { Element mineral = doc.createElement("mineral"); // set attribute id to mineral element Attr attr = doc.createAttribute("key"); //attr.setValue(this.jTableMinerales.getModel().getValueAt(i, 0).toString()); attr.setValue(this.jTableMineralsModel.getValueAt(i, 0).toString()); mineral.setAttributeNode(attr); // set attribute name to mineral element attr = doc.createAttribute("name"); attr.setValue(this.jTableMineralsModel.getValueAt(i, 1).toString()); mineral.setAttributeNode(attr); // set attribute color to mineral element attr = doc.createAttribute("color"); attr.setValue(String.valueOf(((Color) this.jTableMineralsModel.getValueAt(i, 2)).getRGB())); mineral.setAttributeNode(attr); // agrego el mineral a los minerales rootElement.appendChild(mineral); } // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(DataCenter.fileMineralList); transformer.transform(source, result); } catch (Exception e) { } } }
From source file:captureplugin.CapturePlugin.java
/** * Check the programs after data update. *///from w w w . j a v a 2 s. co m public void handleTvDataUpdateFinished() { mNeedsUpdate = true; if (mAllowedToShowDialog) { mNeedsUpdate = false; DeviceIf[] devices = mConfig.getDeviceArray(); final DefaultTableModel model = new DefaultTableModel() { public boolean isCellEditable(int row, int column) { return false; } }; model.setColumnCount(5); model.setColumnIdentifiers(new String[] { mLocalizer.msg("device", "Device"), Localizer.getLocalization(Localizer.I18N_CHANNEL), mLocalizer.msg("date", "Date"), ProgramFieldType.START_TIME_TYPE.getLocalizedName(), ProgramFieldType.TITLE_TYPE.getLocalizedName() }); JTable table = new JTable(model); table.getTableHeader().setReorderingAllowed(false); table.getTableHeader().setResizingAllowed(false); table.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable renderTable, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(renderTable, value, isSelected, hasFocus, row, column); if (value instanceof DeviceIf) { if (((DeviceIf) value).getDeleteRemovedProgramsAutomatically() && !isSelected) { c.setForeground(Color.red); } } return c; } }); int[] columnWidth = new int[5]; for (int i = 0; i < columnWidth.length; i++) { columnWidth[i] = UiUtilities.getStringWidth(table.getFont(), model.getColumnName(i)) + 10; } for (DeviceIf device : devices) { Program[] deleted = device.checkProgramsAfterDataUpdateAndGetDeleted(); if (deleted != null && deleted.length > 0) { for (Program p : deleted) { if (device.getDeleteRemovedProgramsAutomatically() && !p.isExpired() && !p.isOnAir()) { device.remove(UiUtilities.getLastModalChildOf(getParentFrame()), p); } else { device.removeProgramWithoutExecution(p); } if (!p.isExpired()) { Object[] o = new Object[] { device, p.getChannel().getName(), p.getDateString(), p.getTimeString(), p.getTitle() }; for (int i = 0; i < columnWidth.length; i++) { columnWidth[i] = Math.max(columnWidth[i], UiUtilities.getStringWidth(table.getFont(), o[i].toString()) + 10); } model.addRow(o); } } } device.getProgramList(); } if (model.getRowCount() > 0) { int sum = 0; for (int i = 0; i < columnWidth.length; i++) { table.getColumnModel().getColumn(i).setPreferredWidth(columnWidth[i]); if (i < columnWidth.length - 1) { table.getColumnModel().getColumn(i).setMaxWidth(columnWidth[i]); } sum += columnWidth[i]; } JScrollPane scrollPane = new JScrollPane(table); scrollPane.setPreferredSize(new Dimension(450, 250)); if (sum > 500) { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); scrollPane.getViewport().setPreferredSize( new Dimension(sum, scrollPane.getViewport().getPreferredSize().height)); } JButton export = new JButton(mLocalizer.msg("exportList", "Export list")); export.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.toString().toLowerCase().endsWith(".txt"); } public String getDescription() { return "*.txt"; } }); chooser.setSelectedFile(new File("RemovedPrograms.txt")); if (chooser.showSaveDialog( UiUtilities.getLastModalChildOf(getParentFrame())) == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { String file = chooser.getSelectedFile().getAbsolutePath(); if (!file.toLowerCase().endsWith(".txt") && file.indexOf('.') == -1) { file = file + ".txt"; } if (file.indexOf('.') != -1) { try { RandomAccessFile write = new RandomAccessFile(file, "rw"); write.setLength(0); String eolStyle = File.separator.equals("/") ? "\n" : "\r\n"; for (int i = 0; i < model.getRowCount(); i++) { StringBuilder line = new StringBuilder(); for (int j = 0; j < model.getColumnCount(); j++) { line.append(model.getValueAt(i, j)).append(' '); } line.append(eolStyle); write.writeBytes(line.toString()); } write.close(); } catch (Exception ee) { } } } } } }); Object[] message = { mLocalizer.msg("deletedText", "The data was changed and the following programs were deleted:"), scrollPane, export }; JOptionPane pane = new JOptionPane(); pane.setMessage(message); pane.setMessageType(JOptionPane.PLAIN_MESSAGE); final JDialog d = pane.createDialog(UiUtilities.getLastModalChildOf(getParentFrame()), mLocalizer.msg("CapturePlugin", "CapturePlugin") + " - " + mLocalizer.msg("deletedTitle", "Deleted programs")); d.setResizable(true); d.setModal(false); SwingUtilities.invokeLater(new Runnable() { public void run() { d.setVisible(true); } }); } } }
From source file:com.wet.wired.jsr.player.JPlayer.java
public void actionPerformed(ActionEvent ev) { if (ev.getActionCommand().equals("open")) { UIManager.put("FileChooser.readOnly", true); JFileChooser fileChooser = new JFileChooser(); FileExtensionFilter filter = new FileExtensionFilter(); filter = new FileExtensionFilter(); filter.addExtension("owl"); filter.setDescription("TestingOwl File"); if (target != null) { fileChooser.setSelectedFile(new File(target + ".owl")); }//from w w w. j av a 2 s . com fileChooser.setFileFilter(filter); fileChooser.setCurrentDirectory(new File(".")); fileChooser.showOpenDialog(this); if (fileChooser.getSelectedFile() != null) { // target = fileChooser.getSelectedFile().getAbsolutePath(); String targetCapOwl = fileChooser.getSelectedFile().getAbsolutePath(); target = targetCapOwl.substring(0, targetCapOwl.lastIndexOf(".owl")); open(); } } else if (ev.getActionCommand().equals("play")) { play(); } else if (ev.getActionCommand().equals("reset")) { reset(); } else if (ev.getActionCommand().equals("fastForward")) { fastForward(); } else if (ev.getActionCommand().equals("pause")) { pause(); } else if (ev.getActionCommand().equals("close")) { close(); } else if (ev.getActionCommand().equals("recorder")) { closePlayer(); Main.getRecorder().init(new String[0]); } }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveAsm(SpinCADPatch patch) { // Create a file chooser String savedPath = prefs.get("MRUSpnFolder", ""); final JFileChooser fc = new JFileChooser(savedPath); // In response to a button click: FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin ASM Files", "spn"); fc.setFileFilter(filter); // XXX DEBUG// www . j a va 2s.c o m fc.showSaveDialog(new JFrame()); File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spn")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spn"); } 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) { String filePath = fileToBeSaved.getPath(); fileToBeSaved.delete(); try { fileSaveAsm(patch, filePath); } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } saveMRUSpnFolder(filePath); } }
From source file:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java
private void saveBackupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBackupButtonActionPerformed DatabaseInfo info = (DatabaseInfo) competitionList.getSelectedValue(); if (info == null || !info.local) return;//from w w w .j av a 2 s .com JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("Event Manager Files", "evm")); if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); if (!file.getName().toLowerCase().endsWith(".evm")) file = new File(file.getAbsolutePath() + ".evm"); if (file.exists()) { int result = JOptionPane.showConfirmDialog(rootPane, file.getName() + " already exists. Overwrite file?", "Save Backup", JOptionPane.YES_NO_OPTION); if (result != JOptionPane.YES_OPTION) return; } try { File tempDir = Files.createTempDirectory("event-manager").toFile(); FileUtils.copyDirectory(info.localDirectory, tempDir); File lockFile = new File(tempDir, "update.dat.lock"); lockFile.delete(); /* change id */ Properties props = new Properties(); FileReader fr = new FileReader(new File(tempDir, "info.dat")); props.load(fr); fr.close(); props.setProperty("old-UUID", props.getProperty("UUID", "none")); props.setProperty("UUID", UUID.randomUUID().toString()); FileWriter fw = new FileWriter(new File(tempDir, "info.dat")); props.store(fw, ""); fw.close(); ZipUtils.zipFolder(tempDir, file, false); } catch (Exception e) { GUIUtils.displayError(this, "Failed to save file: " + e.getMessage()); } } }