// $$ modif from Oury private static JFileChooser getFileChooser(Component owner, int mode) { JFileChooser chooser = null; String last = /*Jext*/ AbstractEditorPanel.getProperty("lastdir." + mode); if (last == null) last = /*Jext*/ AbstractEditorPanel.getHomeDirectory(); if (owner instanceof AbstractEditorPanel) { chooser = ((/*Jext*/ AbstractEditorPanel) owner).getFileChooser(mode); if ( /*Jext*/ AbstractEditorPanel.getBooleanProperty("editor.dirDefaultDialog") && mode != SCRIPT) { String file = ((AbstractEditorPanel) owner) // $$ from Seb [[ // .getTextArea() // $$ from Seb ]] .getCurrentFile(); if (file != null) chooser.setCurrentDirectory(new File(file)); } else chooser.setCurrentDirectory(new File(last)); } else { chooser = new JFileChooser(last); if (mode == SAVE) chooser.setDialogType(JFileChooser.SAVE_DIALOG); else chooser.setDialogType(JFileChooser.OPEN_DIALOG); } chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setFileHidingEnabled(true); return chooser; }
private void jMenuItemImportActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemImportActionPerformed JFileChooser jfc = new JFileChooser(); jfc.setMultiSelectionEnabled(true); if (lastPath != null) { jfc.setCurrentDirectory(lastPath); } int fileDialogReturnVal = jfc.showOpenDialog(this); // now select the file if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) { // add code here to allow selection of a document class DocumentClassDialog d = DocumentClassDialog.showClassDialog(this, this.theProject); DocumentClass selectedClass = d.getSelectedDocumentClass(); File[] selected = jfc.getSelectedFiles(); for (int i = 0; i < selected.length; i++) { theProject.addNewDocument(selected[i], 1.0f, selected[i].toString(), selectedClass); } docFrameTableModel.fireTableDataChanged(); lastPath = new File(jfc.getSelectedFile().getPath()); } } // GEN-LAST:event_jMenuItemImportActionPerformed
/** * Actions-handling method. * * @param e The event. */ public void actionPerformed(ActionEvent e) { // Prepares the file chooser JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(idata.getInstallPath())); fc.setMultiSelectionEnabled(false); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); // fc.setCurrentDirectory(new File(".")); // Shows it try { if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { // We handle the xml data writing File file = fc.getSelectedFile(); FileOutputStream out = new FileOutputStream(file); BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120); parent.writeXMLTree(idata.xmlData, outBuff); outBuff.flush(); outBuff.close(); autoButton.setEnabled(false); } } catch (Exception err) { err.printStackTrace(); JOptionPane.showMessageDialog( this, err.toString(), parent.langpack.getString("installer.error"), JOptionPane.ERROR_MESSAGE); } }
private void changeDirectory(File dir) { JFileChooser fc = getFileChooser(); // Traverse shortcuts on Windows if (dir != null && FilePane.usesShellFolder(fc)) { try { ShellFolder shellFolder = ShellFolder.getShellFolder(dir); if (shellFolder.isLink()) { File linkedTo = shellFolder.getLinkLocation(); // If linkedTo is null we try to use dir if (linkedTo != null) { if (fc.isTraversable(linkedTo)) { dir = linkedTo; } else { return; } } else { dir = shellFolder; } } } catch (FileNotFoundException ex) { return; } } fc.setCurrentDirectory(dir); if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES && fc.getFileSystemView().isFileSystem(dir)) { setFileName(dir.getAbsolutePath()); } }
private void setStartingDirectory() { File startingDirectoryFile = new File(ISAcreatorProperties.getProperty("isacreator.mappingFileLocations")); if (!startingDirectoryFile.getAbsolutePath().isEmpty() && startingDirectoryFile.exists()) { fileChooser.setCurrentDirectory(startingDirectoryFile); } }
public void initGame() { String cfgname = null; if (isApplet()) { cfgname = getParameter("configfile"); } else { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(System.getProperty("user.dir"))); chooser.setDialogTitle("Choose a config file"); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { cfgname = chooser.getSelectedFile().getAbsolutePath(); } else { System.exit(0); } // XXX read this as resource! // cfgname = "mygeneratedgame.appconfig"; } gamecfg = new AppConfig("Game parameters", this, cfgname); gamecfg.loadFromFile(); gamecfg.defineFields("gp_", "", "", ""); gamecfg.saveToObject(); initMotionPars(); // unpause and copy settingswhen config window is closed gamecfg.setListener( new ActionListener() { public void actionPerformed(ActionEvent e) { start(); requestGameFocus(); initMotionPars(); } }); defineMedia("simplegeneratedgame.tbl"); setFrameRate(35, 1); }
@Override public void mouseClicked(MouseEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); TypeFileFilter fileFilter = new TypeFileFilter("db"); fileChooser.setFileFilter(fileFilter); int result = fileChooser.showOpenDialog(_parent); }
private File openFile(String title) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images (*.jpg, *.png, *.gif)", "jpg", "png", "gif"); chooser.setFileFilter(filter); chooser.setCurrentDirectory(openPath); int ret = chooser.showDialog(this, title); if (ret == JFileChooser.APPROVE_OPTION) return chooser.getSelectedFile(); return null; }
public Path dateiAuswählen(Path neuesLaufwerk) { JFileChooser fc1 = new JFileChooser(); fc1.setDialogTitle("SyncOrdner auswählen"); fc1.setCurrentDirectory(neuesLaufwerk.toFile()); fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) return fc1.getSelectedFile().toPath(); else return null; }
private String getFileName(String title, String okButton, String currentDirectory) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(title); fileChooser.setApproveButtonText(okButton); fileChooser.setCurrentDirectory(new File(currentDirectory)); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); return selectedFile.getAbsolutePath(); } return null; }
private void downloadDirectoryButtonActionPerformed(ActionEvent evt) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(Groovesquid.getConfig().getDownloadDirectory())); chooser.setDialogTitle(I18n.getLocaleString("SELECT_DOWNLOAD_DIRECTORY")); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String downloadDirectory = chooser.getSelectedFile().getPath(); Groovesquid.getConfig().setDownloadDirectory(downloadDirectory); downloadDirectoryTextField.setText(downloadDirectory); } }
/** * Use a JFileChooser in Save mode to select files to open. Use a filter for FileFilter subclass * to select for "*.java" files. If a file is selected, then this file will be used as final * output */ boolean saveFile() { File file = null; JFileChooser fc = new JFileChooser(); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(fJavaFilter); // Set to a default name for save. fc.setSelectedFile(fFile); // Open chooser dialog int result = fc.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return true; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); String textFile = fFile.toString(); if (fileNo.equalsIgnoreCase("SAVE")) { UpLoadFile.outputfile.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVE2")) { UpLoadMAGEMLFile.outputfile1.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVE3")) { UpLoadMAGEMLFile.outputfile2.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVEJPAG")) { JPEGFileName = textFile; // System.out.println ("JPG filename OpenFileDir= " +JPEGFileName); File fFile = new File(JPEGFileName); if (fFile.exists()) { int response = JOptionPane.showConfirmDialog( null, "Overwrite existing file " + JPEGFileName + " ??", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) { /* go back to reload the file*/ return false; } } SetUpPlotWindow.saveComponentAsJPEG(SetUpPlotWindow.content, JPEGFileName); } return true; } else { return false; } } // saveFile
/* * This function just finds and loads the file */ private boolean loadFile() { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Load File"); // Choose only files, not directories fc.setFileSelectionMode(JFileChooser.FILES_ONLY); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(fJavaFilter); // Now open chooser int result = fc.showOpenDialog(this); if (result == JFileChooser.CANCEL_OPTION) { // return true; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); String textFile = fFile.toString(); if (fileNo.equalsIgnoreCase("LOAD1")) { UpLoadFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD2")) { UpLoadFile.filePath2.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD3")) { VisualizationInput.originalFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD4")) { VisualizationInput.DWDVecFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD5")) { VisualizationInput.DWDOutputFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD6")) { UpLoadMAGEMLFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD7")) { UpLoadMAGEMLFile.filePath2.setText(textFile); } // Get the absolute path for the file being opened filePath = fFile.getAbsolutePath(); if (filePath == null) { // fTextField.setText (filePath); return false; } } else { return false; } return true; } /*End of loadFile*/
/** Loads a file and computes its message digest. */ public void loadFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int r = chooser.showOpenDialog(this); if (r == JFileChooser.APPROVE_OPTION) { try { String name = chooser.getSelectedFile().getAbsolutePath(); computeDigest(loadBytes(name)); } catch (IOException e) { JOptionPane.showMessageDialog(null, e); } } }
public void actionPerformed(ActionEvent e) { chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("C:\\Program Files (x86)\\Tango04\\Dashboards\\Web")); chooser.setDialogTitle("Browse..."); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { textArea.setText(""); new Exportator().startExporting(chooser.getSelectedFile().getPath(), textArea); } else { textArea.setText("No Selection"); } }
private void selectFolder() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(textFolder.getText())); fileChooser.setDialogTitle(CAPTION_SELECT_FOLDER); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setApproveButtonText("Select"); fileChooser.setApproveButtonToolTipText(TOOL_TIP_SELECT_FOLDER); if (fileChooser.showOpenDialog(FileTransferServer.this) == JFileChooser.APPROVE_OPTION) { // Get the selected file String path = fileChooser.getSelectedFile().getPath() + "\\"; textFolder.setText(path); } }
public JFileChooser createFileChooser() { // create a filechooser JFileChooser fc = new JFileChooser(); if (getSwingSet2() != null && getSwingSet2().isDragEnabled()) { fc.setDragEnabled(true); } // set the current directory to be the images directory File swingFile = new File("resources/images/About.jpg"); if (swingFile.exists()) { fc.setCurrentDirectory(swingFile); fc.setSelectedFile(swingFile); } return fc; }
public SwingWorkerFrame() { chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); textArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS); add(new JScrollPane(textArea)); statusLine = new JLabel(" "); add(statusLine, BorderLayout.SOUTH); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("File"); menuBar.add(menu); openItem = new JMenuItem("Open"); menu.add(openItem); openItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // show file chooser dialog int result = chooser.showOpenDialog(null); // if file selected, set it as icon of the label if (result == JFileChooser.APPROVE_OPTION) { textArea.setText(""); openItem.setEnabled(false); textReader = new TextReader(chooser.getSelectedFile()); textReader.execute(); cancelItem.setEnabled(true); } } }); cancelItem = new JMenuItem("Cancel"); menu.add(cancelItem); cancelItem.setEnabled(false); cancelItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { textReader.cancel(true); } }); pack(); }
public static Map[] showOpenMapDialog(final JFrame owner) throws IOException { final JFileChooser ch = new JFileChooser(); if (config.getFile("mapLastOpenDir") != null) { ch.setCurrentDirectory(config.getFile("mapLastOpenDir")); } ch.setDialogType(JFileChooser.OPEN_DIALOG); ch.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (ch.showOpenDialog(MainFrame.getInstance()) != JFileChooser.APPROVE_OPTION) { return null; } final File dir = ch.getSelectedFile(); config.set("mapLastOpenDir", dir); final String[] maps = dir.list(FILTER_TILES); for (int i = 0; i < maps.length; ++i) { maps[i] = maps[i].substring(0, maps[i].length() - MapIO.EXT_TILE.length()); } final JDialog dialog = new JDialog(owner, Lang.getMsg("gui.chooser")); dialog.setModal(true); dialog.setLocationRelativeTo(null); dialog.setLayout(new BorderLayout()); final JList list = new JList(maps); final JButton btn = new JButton(Lang.getMsg("gui.chooser.Ok")); btn.addActionListener( new AbstractAction() { @Override public void actionPerformed(final ActionEvent e) { if (list.getSelectedValue() != null) { dialog.setVisible(false); } } }); dialog.add(new JScrollPane(list), BorderLayout.CENTER); dialog.add(btn, BorderLayout.SOUTH); dialog.pack(); dialog.setVisible(true); dialog.dispose(); Map[] loadedMaps = new Map[list.getSelectedIndices().length]; for (int i = 0; i < list.getSelectedIndices().length; i++) { loadedMaps[i] = MapIO.loadMap(dir.getPath(), (String) list.getSelectedValues()[i]); } return loadedMaps; }
private void backup_folder_buttonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_backup_folder_buttonActionPerformed try { JFileChooser sel = new JFileChooser(); sel.setCurrentDirectory(new java.io.File(".")); sel.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); sel.setAcceptAllFileFilterUsed(false); if (sel.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File selFile = sel.getSelectedFile(); Backup_textfield.setText(selFile.getCanonicalPath()); path_save_chat = selFile.getCanonicalPath() + "\\"; } else { // do nothing } } catch (IOException ex) { Logger.getLogger(Options.class.getName()).log(Level.SEVERE, null, ex); } } // GEN-LAST:event_backup_folder_buttonActionPerformed
/** Open a file and load the image. */ public void openFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); String[] extensions = ImageIO.getReaderFileSuffixes(); chooser.setFileFilter(new FileNameExtensionFilter("Image files", extensions)); int r = chooser.showOpenDialog(this); if (r != JFileChooser.APPROVE_OPTION) return; try { Image img = ImageIO.read(chooser.getSelectedFile()); image = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); image.getGraphics().drawImage(img, 0, 0, null); } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } repaint(); }
@Override public void actionPerformed(ActionEvent e) { JFileChooser directoryChooser = new JFileChooser(); directoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); directoryChooser.setCurrentDirectory(new File(AbstractDownloader.directory)); directoryChooser.setDialogTitle("Choose directory"); // disable the "All files" option. directoryChooser.setAcceptAllFileFilterUsed(false); if (directoryChooser.showOpenDialog(directoryChooser) == JFileChooser.APPROVE_OPTION) { AbstractDownloader.directory = directoryChooser.getSelectedFile().getAbsolutePath() + "\\"; } else { AbstractDownloader.directory = AbstractDownloader.DEFAULT_DIRECTORY; } // показываем обновленную надпись в label view.getPathTextField().setText(AbstractDownloader.directory); }
private void Download_buttonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_Download_buttonActionPerformed try { JFileChooser sel = new JFileChooser(); sel.setCurrentDirectory(new java.io.File(".")); sel.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); sel.setAcceptAllFileFilterUsed(false); if (sel.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File selFile = sel.getSelectedFile(); Download_Textfield.setText(selFile.getCanonicalPath()); path_save_download = selFile.getCanonicalPath(); } else { } } catch (Exception ex) { } } // GEN-LAST:event_Download_buttonActionPerformed
private void jMenuItemLoadProjectActionPerformed( java.awt.event.ActionEvent evt) // GEN-FIRST:event_jMenuItemLoadProjectActionPerformed { // GEN-HEADEREND:event_jMenuItemLoadProjectActionPerformed JFileChooser jfc = new JFileChooser(); if (lastPath != null) { jfc.setCurrentDirectory(lastPath); } int fileDialogReturnVal = jfc.showOpenDialog(this); if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) { try { File inputFile = jfc.getSelectedFile(); FileInputStream fis = new FileInputStream(inputFile); ObjectInputStream ois = new ObjectInputStream(fis); this.theProject = (Project) ois.readObject(); this.currentResults = (LSAResults) ois.readObject(); lastPath = new File(jfc.getSelectedFile().getPath()); } catch (IOException e) { if (this.theProject == null) { log.log(Log.ERROR, "Failed to load project"); } if (this.currentResults == null) { log.log(Log.WARNING, "Failed to load results"); } log.log(Log.WARNING, e.getMessage()); } catch (ClassNotFoundException e) { log.log(Log.ERROR, "Class not found error, version mismatch"); } } if (this.theProject != null) { jMenuItemViewDocuments.setEnabled(true); jMenuItemSaveProject.setEnabled(true); this.setTitle(theProject.getProjectName()); log.log(Log.INFO, "Project Loaded"); } if (this.currentResults != null) { log.log(Log.INFO, "Results loaded"); } } // GEN-LAST:event_jMenuItemLoadProjectActionPerformed
/** * Checks whether the given window is either a FileDialog, or contains a JFileChooser component. * If so, its current directory is stored in the given properties. * * @param aNamespace the name space to use; * @param aProperties the properties to store the found directory in; * @param aWindow the window to check for. */ private static void loadFileDialogState(final Preferences aProperties, final Window aWindow) { final String propKey = "lastDirectory"; if (aWindow instanceof FileDialog) { final String dir = aProperties.get(propKey, null); if (dir != null) { ((FileDialog) aWindow).setDirectory(dir); } } else if (aWindow instanceof JDialog) { final Container contentPane = ((JDialog) aWindow).getContentPane(); final JFileChooser fileChooser = (JFileChooser) findComponent(contentPane, JFileChooser.class); if (fileChooser != null) { final String dir = aProperties.get(propKey, null); if (dir != null) { fileChooser.setCurrentDirectory(new File(dir)); } } } }
/** * Shows a file-open selection dialog for the given working directory. * * @param aOwner the owning window to show the dialog in; * @param aCurrentDirectory the working directory to start the dialog in, can be <code>null</code> * . * @return the selected file, or <code>null</code> if the user aborted the dialog. */ public static final File showFileOpenDialog( final Window aOwner, final String aCurrentDirectory, final javax.swing.filechooser.FileFilter... aFileFilters) { if (HostUtils.isMacOS()) { final FileDialog dialog; if (aOwner instanceof Dialog) { dialog = new FileDialog((Dialog) aOwner, "Open file", FileDialog.LOAD); } else { dialog = new FileDialog((Frame) aOwner, "Open file", FileDialog.LOAD); } dialog.setDirectory(aCurrentDirectory); if ((aFileFilters != null) && (aFileFilters.length > 0)) { dialog.setFilenameFilter(new FilenameFilterAdapter(aFileFilters)); } try { dialog.setVisible(true); final String selectedFile = dialog.getFile(); return selectedFile == null ? null : new File(dialog.getDirectory(), selectedFile); } finally { dialog.dispose(); } } else { final JFileChooser dialog = new JFileChooser(); dialog.setCurrentDirectory((aCurrentDirectory == null) ? null : new File(aCurrentDirectory)); for (javax.swing.filechooser.FileFilter filter : aFileFilters) { dialog.addChoosableFileFilter(filter); } File result = null; if (dialog.showOpenDialog(aOwner) == JFileChooser.APPROVE_OPTION) { result = dialog.getSelectedFile(); } return result; } }
private void prepareChooser(SipModel sipModel) { File directory = new File(sipModel.getPreferences().get(RECENT_DIR, System.getProperty("user.home"))); chooser.setCurrentDirectory(directory); chooser.setFileFilter( new FileFilter() { @Override public boolean accept(File file) { return file.isFile() && (file.getName().endsWith(".xml") || file.getName().endsWith(".xml.gz") || file.getName().endsWith(".xml.zip") || file.getName().endsWith(".csv")); } @Override public String getDescription() { return "Files ending with .xml, .xml.gz, .xml.zip, or .csv"; } }); chooser.setMultiSelectionEnabled(false); }
private void outputToExcel(ActionEvent e) { JFileChooser chooser = new JFileChooser() { @Override protected JDialog createDialog(Component parent) throws HeadlessException { JDialog dialog = super.createDialog(parent); dialog.setTitle("Export the content to an Excel file"); return dialog; } }; chooser.setCurrentDirectory(new File(_lastDirectory)); int result = chooser.showDialog(((JButton) e.getSource()).getTopLevelAncestor(), "Export"); if (result == JFileChooser.APPROVE_OPTION) { _lastDirectory = chooser.getCurrentDirectory().getAbsolutePath(); try { System.out.println("Exporting to " + chooser.getSelectedFile().getAbsolutePath()); HssfTableUtils.export( _sortableTable, chooser.getSelectedFile().getAbsolutePath(), "SortableTable", false, true, new HssfTableUtils.DefaultCellValueConverter() { @Override public int getDataFormat(JTable table, Object value, int rowIndex, int columnIndex) { if (value instanceof Double) { return 2; // use 0.00 format } else if (value instanceof Date) { return 0xe; // use "m/d/yy" format } return super.getDataFormat(table, value, rowIndex, columnIndex); } }); System.out.println("Exported"); } catch (IOException e1) { e1.printStackTrace(); } } }
public ConverterView(ConverterModel model) { // this.model = model; this.fileChooser = new JFileChooser(); this.fileChooser.setFileFilter(new ConverterFileFilter()); this.fileChooser.setMultiSelectionEnabled(true); setTitle(getGuiString(model.getName())); this.addButton = new JButton(getGuiString("buttons.change")); this.addButton.addActionListener( e -> { if (this.changeActionListener != null) { Action details = fileChooser.getActionMap().get("viewTypeDetails"); details.actionPerformed(null); if (FilePath.getFilePath(this.getTitle()) != null) { File file = new File(FilePath.getFilePath(this.getTitle()).getPath()); fileChooser.setCurrentDirectory(file); } int ret = fileChooser.showDialog(null, getGuiString("buttons.openFile")); if (ret == JFileChooser.APPROVE_OPTION) { File[] files = fileChooser.getSelectedFiles(); FilePath.setFilePath(this.getTitle(), fileChooser.getCurrentDirectory().getPath()); this.changeActionListener.actionPerformed(files); } } hide(); }); this.cancelButton = new JButton(getGuiString("buttons.cancel")); this.cancelButton.addActionListener( e -> { hide(); }); buildLayout(); show(); }
/** Sets up dialog for saving instances in a file */ public void setUpFile() { removeAll(); m_fileChooser.setFileFilter( new FileFilter() { public boolean accept(File f) { return f.isDirectory(); } public String getDescription() { return "Directory"; } }); m_fileChooser.setAcceptAllFileFilterUsed(false); try { if (!(((m_dsSaver.getSaver()).retrieveDir()).equals(""))) { String dirStr = m_dsSaver.getSaver().retrieveDir(); if (Environment.containsEnvVariables(dirStr)) { try { dirStr = m_env.substitute(dirStr); } catch (Exception ex) { // ignore } } File tmp = new File(dirStr); tmp = new File(tmp.getAbsolutePath()); m_fileChooser.setCurrentDirectory(tmp); } } catch (Exception ex) { System.out.println(ex); } JPanel innerPanel = new JPanel(); innerPanel.setLayout(new BorderLayout()); JPanel alignedP = new JPanel(); GridBagLayout gbLayout = new GridBagLayout(); alignedP.setLayout(gbLayout); JLabel prefixLab = new JLabel("Prefix for file name", SwingConstants.RIGHT); prefixLab.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); GridBagConstraints gbConstraints = new GridBagConstraints(); gbConstraints.anchor = GridBagConstraints.EAST; gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.gridy = 0; gbConstraints.gridx = 0; gbLayout.setConstraints(prefixLab, gbConstraints); alignedP.add(prefixLab); m_prefixText = new EnvironmentField(); m_prefixText.setEnvironment(m_env); m_prefixText.setToolTipText( "Prefix for file name " + "(or filename itself if relation name is not used)"); /* int width = m_prefixText.getPreferredSize().width; int height = m_prefixText.getPreferredSize().height; m_prefixText.setMinimumSize(new Dimension(width * 2, height)); m_prefixText.setPreferredSize(new Dimension(width * 2, height)); */ gbConstraints = new GridBagConstraints(); gbConstraints.anchor = GridBagConstraints.EAST; gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.gridy = 0; gbConstraints.gridx = 1; gbLayout.setConstraints(m_prefixText, gbConstraints); alignedP.add(m_prefixText); try { // m_prefixText = new JTextField(m_dsSaver.getSaver().filePrefix(),25); m_prefixText.setText(m_dsSaver.getSaver().filePrefix()); /* final JLabel prefixLab = new JLabel(" Prefix for file name:", SwingConstants.LEFT); */ JLabel relationLab = new JLabel("Relation name for filename", SwingConstants.RIGHT); relationLab.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); gbConstraints = new GridBagConstraints(); gbConstraints.anchor = GridBagConstraints.EAST; gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.gridy = 1; gbConstraints.gridx = 0; gbLayout.setConstraints(relationLab, gbConstraints); alignedP.add(relationLab); m_relationNameForFilename = new JCheckBox(); m_relationNameForFilename.setSelected(m_dsSaver.getRelationNameForFilename()); m_relationNameForFilename.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_relationNameForFilename.isSelected()) { m_prefixText.setLabel("Prefix for file name"); m_fileChooser.setApproveButtonText("Select directory and prefix"); } else { m_prefixText.setLabel("File name"); m_fileChooser.setApproveButtonText("Select directory and filename"); } } }); gbConstraints = new GridBagConstraints(); gbConstraints.anchor = GridBagConstraints.EAST; gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.gridy = 1; gbConstraints.gridx = 1; gbConstraints.weightx = 5; gbLayout.setConstraints(m_relationNameForFilename, gbConstraints); alignedP.add(m_relationNameForFilename); } catch (Exception ex) { } // innerPanel.add(m_SaverEditor, BorderLayout.SOUTH); JPanel about = m_SaverEditor.getAboutPanel(); if (about != null) { innerPanel.add(about, BorderLayout.NORTH); } add(innerPanel, BorderLayout.NORTH); // add(m_fileChooser, BorderLayout.CENTER); JLabel directoryLab = new JLabel("Directory", SwingConstants.RIGHT); directoryLab.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); gbConstraints = new GridBagConstraints(); gbConstraints.anchor = GridBagConstraints.EAST; gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.gridy = 2; gbConstraints.gridx = 0; gbLayout.setConstraints(directoryLab, gbConstraints); alignedP.add(directoryLab); m_directoryText = new EnvironmentField(); // m_directoryText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); m_directoryText.setEnvironment(m_env); /* width = m_directoryText.getPreferredSize().width; height = m_directoryText.getPreferredSize().height; m_directoryText.setMinimumSize(new Dimension(width * 2, height)); m_directoryText.setPreferredSize(new Dimension(width * 2, height)); */ try { m_directoryText.setText(m_dsSaver.getSaver().retrieveDir()); } catch (IOException ex) { // ignore } JButton browseBut = new JButton("Browse..."); browseBut.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { final JFrame jf = new JFrame("Choose directory"); jf.getContentPane().setLayout(new BorderLayout()); jf.getContentPane().add(m_fileChooser, BorderLayout.CENTER); jf.pack(); jf.setVisible(true); m_fileChooserFrame = jf; } catch (Exception ex) { ex.printStackTrace(); } } }); JPanel efHolder = new JPanel(); efHolder.setLayout(new BorderLayout()); JPanel bP = new JPanel(); bP.setLayout(new BorderLayout()); bP.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5)); bP.add(browseBut, BorderLayout.CENTER); efHolder.add(m_directoryText, BorderLayout.CENTER); efHolder.add(bP, BorderLayout.EAST); // efHolder.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); gbConstraints = new GridBagConstraints(); gbConstraints.anchor = GridBagConstraints.EAST; gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.gridy = 2; gbConstraints.gridx = 1; gbLayout.setConstraints(efHolder, gbConstraints); alignedP.add(efHolder); JLabel relativeLab = new JLabel("Use relative file paths", SwingConstants.RIGHT); relativeLab.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); gbConstraints = new GridBagConstraints(); gbConstraints.anchor = GridBagConstraints.EAST; gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.gridy = 3; gbConstraints.gridx = 0; gbLayout.setConstraints(relativeLab, gbConstraints); alignedP.add(relativeLab); m_relativeFilePath = new JCheckBox(); m_relativeFilePath.setSelected( ((FileSourcedConverter) m_dsSaver.getSaver()).getUseRelativePath()); m_relativeFilePath.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ((FileSourcedConverter) m_dsSaver.getSaver()) .setUseRelativePath(m_relativeFilePath.isSelected()); } }); gbConstraints = new GridBagConstraints(); gbConstraints.anchor = GridBagConstraints.EAST; gbConstraints.fill = GridBagConstraints.HORIZONTAL; gbConstraints.gridy = 3; gbConstraints.gridx = 1; gbLayout.setConstraints(m_relativeFilePath, gbConstraints); alignedP.add(m_relativeFilePath); JButton OKBut = new JButton("OK"); OKBut.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { (m_dsSaver.getSaver()).setFilePrefix(m_prefixText.getText()); (m_dsSaver.getSaver()).setDir(m_directoryText.getText()); m_dsSaver.setRelationNameForFilename(m_relationNameForFilename.isSelected()); } catch (Exception ex) { ex.printStackTrace(); } m_parentFrame.dispose(); } }); JButton CancelBut = new JButton("Cancel"); CancelBut.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { m_parentFrame.dispose(); } }); JPanel butHolder = new JPanel(); butHolder.setLayout(new FlowLayout()); butHolder.add(OKBut); butHolder.add(CancelBut); JPanel holder2 = new JPanel(); holder2.setLayout(new BorderLayout()); holder2.add(alignedP, BorderLayout.NORTH); holder2.add(butHolder, BorderLayout.SOUTH); add(holder2, BorderLayout.SOUTH); }