List of usage examples for javax.swing JFileChooser showSaveDialog
public int showSaveDialog(Component parent) throws HeadlessException
From source file:burlov.ultracipher.swing.SwingGuiApplication.java
public File chooseFile(boolean forSave) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int ret = forSave ? chooser.showSaveDialog(getMainFrame()) : chooser.showOpenDialog(getMainFrame()); if (JFileChooser.APPROVE_OPTION == ret) { File file = chooser.getSelectedFile(); return file; }//from w ww. j a v a2 s.c om return null; }
From source file:ispd.gui.JResultados.java
private void jButtonSalvarTracesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalvarTracesActionPerformed FiltroDeArquivos filtro = new FiltroDeArquivos("Workload Model of Simulation", ".wmsx", true); JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setFileFilter(filtro);//from ww w .ja v a2 s. co m int returnVal = jFileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = jFileChooser.getSelectedFile(); if (!file.getName().endsWith(".wmsx")) { File temp = new File(file.toString() + ".wmsx"); file = temp; } TraceXML interpret = new TraceXML(file.getAbsolutePath()); interpret.geraTraceSim(tarefas); } }
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);// w w w . j av a2 s . com fc.showSaveDialog(new JFrame()); File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".hex")) { fileToBeSaved = new File(fc.getSelectedFile() + ".hex"); } 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:PreferencesTest.java
public PreferencesFrame() { // get position, size, title from preferences Preferences root = Preferences.userRoot(); final Preferences node = root.node("/com/horstmann/corejava"); int left = node.getInt("left", 0); int top = node.getInt("top", 0); int width = node.getInt("width", DEFAULT_WIDTH); int height = node.getInt("height", DEFAULT_HEIGHT); setBounds(left, top, width, height); // if no title given, ask user String title = node.get("title", ""); if (title.equals("")) title = JOptionPane.showInputDialog("Please supply a frame title:"); if (title == null) title = ""; setTitle(title);/*from w w w .java 2 s .co m*/ // set up file chooser that shows XML files final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); // accept all files ending with .xml chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory(); } public String getDescription() { return "XML files"; } }); // set up menus JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem exportItem = new JMenuItem("Export preferences"); menu.add(exportItem); exportItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (chooser.showSaveDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) { try { OutputStream out = new FileOutputStream(chooser.getSelectedFile()); node.exportSubtree(out); out.close(); } catch (Exception e) { e.printStackTrace(); } } } }); JMenuItem importItem = new JMenuItem("Import preferences"); menu.add(importItem); importItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (chooser.showOpenDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) { try { InputStream in = new FileInputStream(chooser.getSelectedFile()); Preferences.importPreferences(in); in.close(); } catch (Exception e) { e.printStackTrace(); } } } }); JMenuItem exitItem = new JMenuItem("Exit"); menu.add(exitItem); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { node.putInt("left", getX()); node.putInt("top", getY()); node.putInt("width", getWidth()); node.putInt("height", getHeight()); node.put("title", getTitle()); System.exit(0); } }); }
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);//from ww w. ja va2 s . co m 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"); } 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:ispd.gui.JResultados.java
private void jButtonSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalvarActionPerformed JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = jFileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = jFileChooser.getSelectedFile(); salvarHTML(file);//from w ww.j a v a 2 s . c om try { HtmlPane.openDefaultBrowser(new URL("file://" + file.getAbsolutePath() + "/result.html")); } catch (MalformedURLException ex) { Logger.getLogger(JResultados.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:bio.gcat.gui.BDATool.java
public boolean saveFileAs() { JFileChooser chooser = new FileNameExtensionFileChooser(false, BDA_EXTENSION_FILTER); chooser.setDialogTitle("Save As"); if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) return saveFile(chooser.getSelectedFile()); else/*from w w w . jav a2 s . c om*/ return false; }
From source file:com.unsa.view.MainView.java
private void btnGuardarEnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarEnActionPerformed // TODO add your handling code here: JFileChooser jF1 = new javax.swing.JFileChooser(); String ruta = ""; try {/*from w w w . jav a 2 s . c om*/ if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); //Aqui ya tiens la ruta,,,ahora puedes crear un fichero n esa ruta y escribir lo k kieras... jTextField1.setText(ruta); } } catch (Exception ex) { ex.printStackTrace(); } }
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);/* w w w . j a v a 2 s . c om*/ 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"); } 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:de.fionera.javamailer.gui.mainView.controllerMain.java
/** * Adds the Actionlisteners to the Mainview * * @param viewMain The Mainview/*from w ww.java 2 s . c o m*/ */ private void addActionListener(viewMain viewMain) { /** * Changes the Amount in the AmountLabel when the slider is moved */ viewMain.getSetMailSettingsPanel().getSliderAmountMails().addChangeListener(e -> { Main.amountMails = ((JSlider) e.getSource()).getValue(); viewMain.getSetMailSettingsPanel().getLabelNumberAmountMails() .setText("" + ((JSlider) e.getSource()).getValue()); }); /** * Changes the Delay in the DelayLabel when the slider is moved */ viewMain.getSetMailSettingsPanel().getSliderDelayMails().addChangeListener(e -> { Main.delayMails = ((JSlider) e.getSource()).getValue(); viewMain.getSetMailSettingsPanel().getLabelNumberDelayMails() .setText("" + ((JSlider) e.getSource()).getValue()); }); /** * Closes the Program, when close is clicked */ viewMain.getCloseItem().addActionListener(e -> System.exit(0)); /** * Opens the Settings when the settingsbutton is clicked */ viewMain.getSettingsItem().addActionListener(e -> new controllerSettings()); /** * Save current Setup */ viewMain.getSaveSettings().addActionListener(e -> { JFileChooser jChooser = new JFileChooser(); JFrame parentFrame = new JFrame(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub"); jChooser.setFileFilter(filter); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.setDialogTitle("Select Setup"); int userSelection = jChooser.showSaveDialog(parentFrame); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = new File(jChooser.getSelectedFile() + ".jms"); saveSetup(viewMain, fileToSave, new ObjectMapper()); } }); /** * Load Setup */ viewMain.getLoadSettings().addActionListener(e -> { JFileChooser jChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub"); jChooser.setFileFilter(filter); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.setDialogTitle("Select Setup"); jChooser.showOpenDialog(null); File file = jChooser.getSelectedFile(); if (file != null) { if (file.getName().endsWith("jms")) { try { loadSetup(viewMain, file, new ObjectMapper()); } catch (Exception error) { error.printStackTrace(); } } } }); /** * Opens the Open File dialog and start the Parsing of it */ viewMain.getSelectRecipientsPanel().getSelectExcelFileButton().addActionListener(e -> { DefaultTableModel model; JFileChooser jChooser = new JFileChooser(); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel 97 - 2003 (.xls)", "xls")); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel (.xlsx)", "xlsx")); jChooser.setDialogTitle("Select only Excel workbooks"); jChooser.showOpenDialog(null); File file = jChooser.getSelectedFile(); if (file != null) { parseFilesForImport parseFilesForImport = new parseFilesForImport(); if (file.getName().endsWith("xls")) { ArrayList returnedData = parseFilesForImport.parseXLSFile(file); model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1)); int tableWidth = model.getColumnCount() * 150; int tableHeight = model.getRowCount() * 25; viewMain.getSelectRecipientsPanel().getTable() .setPreferredSize(new Dimension(tableWidth, tableHeight)); } else if (file.getName().endsWith("xlsx")) { ArrayList returnedData = parseFilesForImport.parseXLSXFile(file); model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1)); int tableWidth = model.getColumnCount() * 150; int tableHeight = model.getRowCount() * 25; viewMain.getSelectRecipientsPanel().getTable() .setPreferredSize(new Dimension(tableWidth, tableHeight)); } else { JOptionPane.showMessageDialog(null, "Please select only Excel file.", "Error", JOptionPane.ERROR_MESSAGE); model = new DefaultTableModel(); } } else { model = new DefaultTableModel(); } viewMain.getSelectRecipientsPanel().getTable().setModel(model); int tableWidth = model.getColumnCount() * 150; int tableHeight = model.getRowCount() * 25; viewMain.getSelectRecipientsPanel().getTable().setPreferredSize(new Dimension(tableWidth, tableHeight)); viewMain.getCheckAllSettings().getLabelRecipientsAmount().setText("" + model.getRowCount()); viewMain.getCheckAllSettings().getLabelTimeAmount() .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue() * viewMain.getSelectRecipientsPanel().getTable().getRowCount() / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue() + " Seconds"); }); /** * Starts the sending of th Mails, when the send button is clicked */ viewMain.getCheckAllSettings().getSendMails().addActionListener(e -> { String subject = viewMain.getSetMailSettingsPanel().getFieldSubject().getText(); Sender sender = (Sender) viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem(); JTable table = viewMain.getSelectRecipientsPanel().getTable(); if (table != null && sender != null && !subject.equals("")) { new sendMails(viewMain); } }); /** * Clears the Table on buttonclick */ viewMain.getSelectRecipientsPanel().getClearTableButton().addActionListener(e -> { viewMain.getSelectRecipientsPanel().getTable().setModel(new DefaultTableModel()); viewMain.getSelectRecipientsPanel().getTable().setBackground(null); }); /** * Removes a single Row on menu click in the editMailPanel */ viewMain.getSelectRecipientsPanel().getDeleteRow().addActionListener(e -> { ((DefaultTableModel) viewMain.getSelectRecipientsPanel().getTable().getModel()) .removeRow(viewMain.getSelectRecipientsPanel().getTable().getSelectedRowCount()); viewMain.getSelectRecipientsPanel().getTable().setBackground(null); }); /** * The Changes the displayed Value when the Time in the Timespinner is getting changed. */ viewMain.getSetMailSettingsPanel().getTimeSpinner().addChangeListener(e -> { parseDate.parseDate(viewMain); viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, " + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining"); viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString()); viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate()); }); viewMain.getSetMailSettingsPanel().getDatePicker().addActionListener(e -> { parseDate.parseDate(viewMain); viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, " + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining"); viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString()); viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate()); }); /** * Actionevent for the Edit Sender Button */ viewMain.getSetMailSettingsPanel().getButtonEditSender() .addActionListener(e -> new controllerEditSender(controllerMain)); /** * Actionevent for the Import Button in the EditMail View */ viewMain.getEditMailPanel().getImportWord().addActionListener(e -> { JFileChooser jChooser = new JFileChooser(); jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Word 97 - 2003 (.doc)", "doc")); jChooser.addChoosableFileFilter(new FileNameExtensionFilter("HTML File (.html)", "html")); jChooser.setDialogTitle("Select only Word Documents"); jChooser.showOpenDialog(null); File file = jChooser.getSelectedFile(); if (file != null) { parseFilesForImport parseFilesForImport = new parseFilesForImport(); if (file.getName().endsWith("doc")) { String returnedData = parseFilesForImport.parseDOCFile(file); viewMain.getEditMailPanel().setEditorText(returnedData); } else if (file.getName().endsWith("html")) { String content = ""; try { content = Jsoup.parse(file, "UTF-8").toString(); } catch (IOException e1) { e1.printStackTrace(); } viewMain.getEditMailPanel().setEditorText(content); } else { JOptionPane.showMessageDialog(null, "Please select a Document file.", "Error", JOptionPane.ERROR_MESSAGE); } } }); /** * The Tab Changelistener * The first if Statement sets the Labels on the Checkallsettings Panel to the right Values */ viewMain.getTabbedPane().addChangeListener(e -> { if (viewMain.getTabbedPane().getSelectedComponent() == viewMain.getCheckAllSettings()) { viewMain.getCheckAllSettings().getLabelMailBelow() .setText(viewMain.getEditMailPanel().getEditorText()); //Displays the Mail viewMain.getCheckAllSettings().getLabelRecipientsAmount() .setText("" + viewMain.getSelectRecipientsPanel().getTable().getModel().getRowCount()); //Displays the Amount of Recipients if (viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem() != null) { viewMain.getCheckAllSettings().getLabelFromInserted().setText( viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem().toString()); } else { viewMain.getCheckAllSettings().getLabelFromInserted().setText("Select a Sender first"); } viewMain.getCheckAllSettings().getLabelSubjectInserted() .setText(viewMain.getSetMailSettingsPanel().getFieldSubject().getText()); //Displays the Subject if (viewMain.getSetMailSettingsPanel().getCheckBoxDelayMails().isSelected()) { viewMain.getCheckAllSettings().getLabelDelay().setVisible(true); viewMain.getCheckAllSettings().getLabelAmount().setVisible(true); viewMain.getCheckAllSettings().getLabelTime().setVisible(true); viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(true); viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(true); viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(true); viewMain.getCheckAllSettings().getLabelDelayNumber() .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue()); //The Delay Number viewMain.getCheckAllSettings().getLabelAmountNumber() .setText("" + viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue()); //The Amount of Mail in one package viewMain.getCheckAllSettings().getLabelTimeAmount() .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue() * viewMain.getSelectRecipientsPanel().getTable().getRowCount() / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue() + " Seconds"); //The Time the Sending needs } else { viewMain.getCheckAllSettings().getLabelDelay().setVisible(false); viewMain.getCheckAllSettings().getLabelAmount().setVisible(false); viewMain.getCheckAllSettings().getLabelTime().setVisible(false); viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(false); viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(false); viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(false); } if (viewMain.getSetMailSettingsPanel().getCheckBoxSendLater().isSelected()) { viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(true); viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(true); viewMain.getCheckAllSettings().getLabelSendingAt() .setText(viewMain.getSetMailSettingsPanel().getDate().toString()); } else { viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(false); viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(false); } } }); }