List of usage examples for javax.swing JFileChooser setCurrentDirectory
@BeanProperty(preferred = true, description = "The directory that the JFileChooser is showing files of.") public void setCurrentDirectory(File dir)
From source file:net.rptools.maptool.launcher.MapToolLauncher.java
private JPanel buildAdvancedPanel() { final JPanel p = new JPanel(); p.setLayout(new BorderLayout()); p.setBorder(new LineBorder(Color.BLACK)); final JPanel controlPanel = new JPanel(); controlPanel.setLayout(new BorderLayout()); final JPanel argPanel = new JPanel(); argPanel.setLayout(new BorderLayout()); jtfArgs.setInfo(CopiedFromOtherJars.getText("msg.info.javaArgumentsHere")); //$NON-NLS-1$ jtfArgs.setText(extraArgs);//from www . j a v a 2s.com jtfArgs.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaArgumentsHere")); //$NON-NLS-1$ jtfArgs.setCaretPosition(0); jtfArgs.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { jbLaunch.requestFocusInWindow(); } } }); jtfArgs.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent arg0) { jtfArgs.selectAll(); } @Override public void focusLost(FocusEvent arg0) { jtfArgs.setCaretPosition(0); if (!jtfArgs.getText().trim().equals(extraArgs)) { extraArgs = jtfArgs.getText(); jcbEnableAssertions.setSelected(extraArgs.contains(ASSERTIONS_OPTION)); if (extraArgs.contains(DATADIR_OPTION)) { extraArgs = cleanExtraArgs(extraArgs); } updateCommand(); } } }); argPanel.add(jtfArgs, BorderLayout.CENTER); controlPanel.add(argPanel, BorderLayout.NORTH); final JPanel holdPanel = new JPanel(); holdPanel.setLayout(new GridLayout(0, 1)); jcbRelativePath.setText(CopiedFromOtherJars.getText("msg.info.useRelativePathnames")); //$NON-NLS-1$ jcbRelativePath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.useRelativePathnames")); //$NON-NLS-1$ jcbRelativePath.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { updateCommand(); } }); // jcbRelativePath.setSelected(false); // since initComponents() is called after reading the config, don't do this here jcbConsole.setText(CopiedFromOtherJars.getText("msg.info.launchWithConsole")); //$NON-NLS-1$ jcbConsole.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.launchWithConsole")); //$NON-NLS-1$ jcbConsole.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { startConsole = jcbConsole.isSelected(); updateCommand(); } }); jcbConsole.setSelected(startConsole); jbPath.setText(jbPathText); jbPath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.dirForAltJava")); //$NON-NLS-1$ jbPath.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jbPath.getText().equalsIgnoreCase(CopiedFromOtherJars.getText("msg.info.setJavaVersion"))) { //$NON-NLS-1$ final JFileChooser jfc = new JFileChooser(); if (!javaDir.isEmpty()) { jfc.setCurrentDirectory(new File(javaDir)); } else { jfc.setCurrentDirectory(new File(".")); //$NON-NLS-1$ } jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); final int returnVal = jfc.showOpenDialog(jbPath); if (returnVal == JFileChooser.APPROVE_OPTION) { final File f = jfc.getSelectedFile(); final String test = f.getPath() + File.separator; // Lee: naive search for java command. will improve in the future final List<String> fileList = Arrays.asList(f.list()); boolean javaFound = false; for (final String fileName : fileList) { final File check = new File(f, fileName); final String lc = check.getName().toLowerCase(); if (lc.equals("java") || (IS_WINDOWS && lc.startsWith("java."))) { //$NON-NLS-1$ //$NON-NLS-2$ javaFound = true; break; } } if (javaFound) { jbPath.setText(CopiedFromOtherJars.getText("msg.info.resetToDefaultJava")); //$NON-NLS-1$ javaDir = test; updateCommand(); } else { logMsg(Level.SEVERE, "Java executable not found in {0}", //$NON-NLS-1$ "msg.error.javaCommandNotFound", f); //$NON-NLS-2$ } } } else { jbPath.setText(CopiedFromOtherJars.getText("msg.info.setJavaVersion")); //$NON-NLS-1$ javaDir = EMPTY; } } }); holdPanel.add(jcbRelativePath); holdPanel.add(jcbConsole); holdPanel.add(jbPath); controlPanel.add(holdPanel, BorderLayout.SOUTH); final JPanel logPanel = new JPanel(); logPanel.setLayout(new GridLayout(0, 1)); logPanel.setBorder( new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logPanel.border"))); //$NON-NLS-1$ for (final LoggingConfig config : logConfigs) { config.chkbox.setText(config.getProperty("desc")); //$NON-NLS-1$ config.chkbox.setToolTipText(config.getProperty("ttip")); //$NON-NLS-1$ logPanel.add(config.chkbox); } p.add(logPanel, BorderLayout.CENTER); p.add(controlPanel, BorderLayout.SOUTH); return p; }
From source file:com.g2inc.scap.editor.gui.windows.EditorMainWindow.java
private void initFilemenu() { final EditorMainWindow parentWinRef = this; exitMenuItem.addActionListener(new ActionListener() { @Override// w ww. java2s . c o m public void actionPerformed(ActionEvent e) { parentWinRef.dispose(); } }); openOvalMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { final JFileChooser fc = new JFileChooser(); fc.setDialogType(JFileChooser.OPEN_DIALOG); File lastOpenedFrom = guiProps.getLastOpenedFromFile(); // Set current directory fc.setCurrentDirectory(lastOpenedFrom); FileFilter ff = new OcilOrOvalFilesFilter("OVAL"); fc.setFileFilter(ff); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int ret = fc.showOpenDialog(EditorMainWindow.getInstance()); if (ret == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); File parent = f.getAbsoluteFile().getParentFile(); guiProps.setLastOpenedFrom(parent.getAbsolutePath()); guiProps.save(); openFile(f, SCAPDocumentClassEnum.OVAL); } } }); saveMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { // get the currently open window JInternalFrame selectedWin = desktopPane.getSelectedFrame(); if (selectedWin != null) { SCAPDocument scapDoc = null; Document dom = null; String filename = null; if (selectedWin instanceof OvalEditorForm) { OvalEditorForm oef = (OvalEditorForm) selectedWin; scapDoc = oef.getDocument(); dom = scapDoc.getDoc(); filename = scapDoc.getFilename(); } else if (selectedWin instanceof CPEDictionaryEditorForm) { CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin; scapDoc = cef.getDocument(); dom = scapDoc.getDoc(); filename = scapDoc.getFilename(); } if (dom != null) { // since this is a save operation, not save as, we won't // prompt the user for where to store the file try { scapDoc.save(); ((EditorForm) selectedWin).setDirty(false); } catch (Exception e) { String message = "An error occured trying to save to file " + filename + ": " + e.getMessage(); EditorUtil.showMessageDialog(parentWinRef, message, EditorMessages.SAVE_ERROR_DIALOG_TITLE, JOptionPane.ERROR_MESSAGE); } } } } }); saveAsMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { // get the currently open window JInternalFrame selectedWin = desktopPane.getSelectedFrame(); if (selectedWin != null) { SCAPDocument scapDoc = null; Document dom = null; String filename = null; String windowTitle = null; if (selectedWin instanceof OvalEditorForm) { windowTitle = OvalEditorForm.WINDOW_TITLE_BASE; OvalEditorForm oef = (OvalEditorForm) selectedWin; scapDoc = oef.getDocument(); dom = scapDoc.getDoc(); filename = scapDoc.getFilename(); } else if (selectedWin instanceof CPEDictionaryEditorForm) { windowTitle = CPEDictionaryEditorForm.WINDOW_TITLE_BASE; CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin; scapDoc = cef.getDocument(); dom = scapDoc.getDoc(); filename = scapDoc.getFilename(); } else { return; } if (dom != null) { String newFilename = null; SCAPDocumentTypeEnum docType = scapDoc.getDocumentType(); FileSaveAsWizard saveAsWiz = new FileSaveAsWizard(EditorMainWindow.getInstance(), true, docType); //saveAsWiz.pack(); saveAsWiz.setLocationRelativeTo(EditorMainWindow.getInstance()); saveAsWiz.setVisible(true); if (saveAsWiz.wasCancelled()) { return; } newFilename = saveAsWiz.getFilename(); try { scapDoc.setFilename(newFilename); scapDoc.saveAs(newFilename); EditorUtil.markActiveWindowDirty(EditorMainWindow.getInstance(), false); ((EditorForm) selectedWin).refreshRootNode(); } catch (Exception e) { LOG.error(e.getMessage(), e); EditorUtil.showMessageDialog(parentWinRef, "An error occured trying to save to file " + newFilename + ": " + e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE); return; } SCAPContentManager scm = SCAPContentManager.getInstance(); if (scm != null) { scm.removeDocument(filename); scm.addDocument(newFilename, scapDoc); selectedWin.setTitle(windowTitle + (new File(newFilename)).getAbsolutePath()); } else { LOG.error("SCM instance is null here!"); } } } } }); newXCCDFFromOvalMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { //generateXccdfFromOvalOrOcil("OVAL"); final JFileChooser fc = new JFileChooser(); fc.setDialogType(JFileChooser.OPEN_DIALOG); File lastOpenedFrom = guiProps.getLastOpenedFromFile(); // Set current directory fc.setCurrentDirectory(lastOpenedFrom); FileFilter ff = new OcilOrOvalFilesFilter("OVAL"); fc.setFileFilter(ff); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int ret = fc.showOpenDialog(EditorMainWindow.getInstance()); if (ret == JFileChooser.APPROVE_OPTION) { File f = fc.getSelectedFile(); File parent = f.getAbsoluteFile().getParentFile(); guiProps.setLastOpenedFrom(parent.getAbsolutePath()); guiProps.save(); try { InputStream is = this.getClass().getClassLoader().getResourceAsStream("oval-to-xccdf.xsl"); File xsltfile = new File("oval-to-xccdf.xsl"); OutputStream outputStream = new FileOutputStream(xsltfile); IOUtils.copy(is, outputStream); outputStream.close(); OvalToXCCDF1.ovalToXccdf(f, xsltfile); xsltfile.delete(); String reverseDNS = JOptionPane.showInputDialog("reverse_DNS:"); if (reverseDNS == null || reverseDNS.length() == 0) { JOptionPane.showMessageDialog(null, "Enter the reverse_DNS", "alert", JOptionPane.ERROR_MESSAGE); } else { JFileChooser fc1 = new JFileChooser(); fc1.setCurrentDirectory(f); int ret1 = fc1.showSaveDialog(EditorMainWindow.getInstance()); if (ret1 == JFileChooser.APPROVE_OPTION) { File savefile = fc1.getSelectedFile(); is = this.getClass().getClassLoader().getResourceAsStream("xccdf_1.1_to_1.2.xsl"); xsltfile = new File("oval-to-xccdf.xsl"); outputStream = new FileOutputStream(xsltfile); IOUtils.copy(is, outputStream); outputStream.close(); File temp = new File("temp.xml"); XCCDF1to2.xccdf12(savefile, reverseDNS, xsltfile, temp); JOptionPane.showMessageDialog(null, "XCCDF File Created: " + savefile.getAbsolutePath(), "XCCDF Created", JOptionPane.PLAIN_MESSAGE); xsltfile.delete(); temp.delete(); temp = null; } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } // openFile(f, SCAPDocumentClassEnum.OVAL); } } }); newOvalMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { CreateOvalWizard wiz = new CreateOvalWizard(true); wiz.setName("create_oval_wizard"); wiz.pack(); wiz.setVisible(true); if (!wiz.wasCancelled()) { // User has been through the wizard to select // 1. an Oval schema version (eg, OVAL55) // 2. one or more platforms (eg, "windows", "solaris", etc) // 3. a file name for the new Oval file // Now we are ready to actually create the file String createdFilename = createNewOvalDocument(wiz); if (createdFilename == null) { LOG.error("newOvalMenuItem.actionlistener: Created filename was null!"); return; } File f = new File(createdFilename); guiProps.setLastOpenedFromFile(f.getParentFile()); guiProps.save(); SCAPContentManager scm = SCAPContentManager.getInstance(); if (scm != null) { OvalDefinitionsDocument dd = (OvalDefinitionsDocument) scm.getDocument(f.getAbsolutePath()); openFile(dd); } } wiz.setVisible(false); wiz.dispose(); } }); /* wizModeMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { WizardModeWindow wizModeWin = new WizardModeWindow(); EditorMainWindow emw = EditorMainWindow.getInstance(); JDesktopPane emwDesktopPane = emw.getDesktopPane(); wizModeWin.setTitle("Wizard Mode"); wizModeWin.pack(); wizModeWin.addInternalFrameListener(new WeakInternalFrameListener(EditorMainWindow.getInstance())); Dimension dpDim = emwDesktopPane.getSize(); int x = (dpDim.width - wizModeWin.getWidth()) / 2; int y = (dpDim.height - wizModeWin.getHeight()) / 2; wizModeWin.setLocation(x, y); emwDesktopPane.add(wizModeWin); wizModeWin.setVisible(true); setWizMode(true); } });*/ ugMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); InputStream resource = this.getClass().getResourceAsStream("/User_Guide.pdf"); try { File userGuideFile = File.createTempFile("UserGuide", ".pdf"); userGuideFile.deleteOnExit(); OutputStream out = new FileOutputStream(userGuideFile); try { // copy contents from resource to out IOUtils.copy(resource, out); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Couldn't copy between streams."); } finally { out.close(); } desktop.open(userGuideFile); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Could not call Open on desktop object."); } finally { try { if (resource != null) { resource.close(); } } catch (IOException ex) { LOG.error("Error displaying user guide", ex); JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide."); } } } else { JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide."); } } }); }
From source file:com.jug.MoMA.java
/** * Shows a JFileChooser set up to accept the selection of folders. If * 'cancel' is pressed this method terminates the MotherMachine app. * * @param guiFrame/*from w w w .jav a 2s. c o m*/ * parent frame * @param path * path to the folder to open initially * @return an instance of {@link File} pointing at the selected folder. */ private File showFolderChooser(final JFrame guiFrame, final String path) { File selectedFile = null; if (SystemUtils.IS_OS_MAC) { // --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- System.setProperty("apple.awt.fileDialogForDirectories", "true"); final FileDialog fd = new FileDialog(guiFrame, "Select folder containing image sequence...", FileDialog.LOAD); fd.setDirectory(path); // fd.setLocation(50,50); fd.setVisible(true); selectedFile = new File(fd.getDirectory() + "/" + fd.getFile()); if (fd.getFile() == null) { System.exit(0); return null; } System.setProperty("apple.awt.fileDialogForDirectories", "false"); } else { // --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(path)); chooser.setDialogTitle("Select folder containing image sequence..."); chooser.setFileFilter(new FileFilter() { @Override public final boolean accept(final File file) { return file.isDirectory(); } @Override public String getDescription() { return "We only take directories"; } }); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(guiFrame) == JFileChooser.APPROVE_OPTION) { selectedFile = chooser.getSelectedFile(); } else { System.exit(0); return null; } } return selectedFile; }
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
@Override public void doExport(IExporter exporter) throws IOException { boolean isMultipleSeries = getDataset().getSeriesCount() > 1; JFileChooser fileChooser = new JFileChooser(); String currentDirectory = System.getProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL); if (currentDirectory != null) { File savePath = new File(currentDirectory); if (savePath.exists() && savePath.isDirectory()) { fileChooser.setCurrentDirectory(savePath); }/*from w ww . j a v a 2s . c o m*/ } String fileExtension = exporter.getExtensionName(); ExtensionFileFilter extensionFilter = new ExtensionFileFilter(exporter.toString(), "." + fileExtension); fileChooser.addChoosableFileFilter(extensionFilter); if (isMultipleSeries) { fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); int confirm = JOptionPane.YES_OPTION; File selectedFile; if (isMultipleSeries) { selectedFile = new File(filename); if (!selectedFile.exists()) { selectedFile.mkdirs(); } exporter.export(selectedFile, getDataset()); System.setProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL, fileChooser.getSelectedFile().getAbsolutePath()); } else { if (!filename.toLowerCase().endsWith("." + fileExtension)) { filename = filename + "." + fileExtension; } selectedFile = new File(filename); if (selectedFile.exists()) { confirm = JOptionPane.showConfirmDialog(this, selectedFile.getName() + " exists, overwrite?", "Confirm Overwriting", JOptionPane.YES_NO_OPTION); } else { selectedFile.createNewFile(); } if (confirm == JOptionPane.YES_OPTION) { exporter.export(selectedFile, getDataset()); System.setProperty(StaticValues.SYSTEM_SAVE_PATH_LABEL, fileChooser.getSelectedFile().getParent()); } } } }
From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java
private void exportActiveOutlineToAtom() { if (MindRaider.profile.getActiveOutline() == null) { JOptionPane.showMessageDialog(MindRaiderMainWindow.this, Messages.getString("MindRaiderJFrame.exportNotebookWarning"), Messages.getString("MindRaiderJFrame.exportError"), JOptionPane.ERROR_MESSAGE); return;//from w w w. j a va 2s . com } JFileChooser fc = new JFileChooser(); fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export")); fc.setControlButtonsAreShown(true); fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // prepare directory String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export" + File.separator + "sharing"; Utils.createDirectory(exportDirectory); fc.setCurrentDirectory(new File(exportDirectory)); int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { String dstDirectory = fc.getSelectedFile().getAbsolutePath(); Utils.createDirectory(dstDirectory); final String dstFileName = dstDirectory + File.separator + "MindRaider-" + MindRaider.outlineCustodian.getActiveNotebookNcName() + "-" + Utils.getCurrentDataTimeAsPrettyString() + ".atom.xml"; logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName)); MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_ATOM, dstFileName); } else { logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser")); } }
From source file:eu.apenet.dpt.standalone.gui.DataPreparationToolGUI.java
private void wireUp() { fileItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (actionEvent.getSource() == fileItem) { currentLocation = new File(retrieveFromDb.retrieveOpenLocation()); fileChooser.setCurrentDirectory(currentLocation); int returnedVal = fileChooser.showOpenDialog(getParent()); if (returnedVal == JFileChooser.APPROVE_OPTION) { currentLocation = fileChooser.getCurrentDirectory(); retrieveFromDb.saveOpenLocation(currentLocation.getAbsolutePath()); RootPaneContainer root = (RootPaneContainer) getRootPane().getTopLevelAncestor(); root.getGlassPane().setCursor(WAIT_CURSOR); root.getGlassPane().setVisible(true); File[] files = fileChooser.getSelectedFiles(); for (File file : files) { if (file.isDirectory()) { File[] fileArray = file.listFiles(); Arrays.sort(fileArray, new FileNameComparator()); for (File children : fileArray) { if (isCorrect(children)) { xmlEadListModel.addFile(children); }/*from ww w . j ava 2 s . c o m*/ } } else { if (isCorrect(file)) { xmlEadListModel.addFile(file); } } } root.getGlassPane().setCursor(DEFAULT_CURSOR); root.getGlassPane().setVisible(false); } } } }); repositoryCodeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { createOptionPaneForRepositoryCode(); } }); countryCodeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { createOptionPaneForCountryCode(); } }); checksLoadingFilesItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { createOptionPaneForChecksLoadingFiles(); } }); createEag2012FromExistingEag2012.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser eagFileChooser = new JFileChooser(); eagFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); eagFileChooser.setMultiSelectionEnabled(false); eagFileChooser.setCurrentDirectory(new File(retrieveFromDb.retrieveOpenLocation())); if (eagFileChooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { currentLocation = eagFileChooser.getCurrentDirectory(); retrieveFromDb.saveOpenLocation(currentLocation.getAbsolutePath()); File eagFile = eagFileChooser.getSelectedFile(); if (!Eag2012Frame.isUsed()) { try { if (ReadXml.isXmlFile(eagFile, "eag")) { new Eag2012Frame(eagFile, getContentPane().getSize(), (ProfileListModel) getXmlEadList().getModel(), labels); } else { JOptionPane.showMessageDialog(rootPane, labels.getString("eag2012.errors.notAnEagFile")); } } catch (SAXException ex) { if (ex instanceof SAXParseException) { JOptionPane.showMessageDialog(rootPane, labels.getString("eag2012.errors.notAnEagFile")); } java.util.logging.Logger.getLogger(DataPreparationToolGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IOException ex) { java.util.logging.Logger.getLogger(DataPreparationToolGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (ParserConfigurationException ex) { java.util.logging.Logger.getLogger(DataPreparationToolGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (Exception ex) { try { JOptionPane.showMessageDialog(rootPane, labels.getString(ex.getMessage())); } catch (Exception ex1) { JOptionPane.showMessageDialog(rootPane, "Error..."); } } } } } }); createEag2012FromScratch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!Eag2012Frame.isUsed()) { new Eag2012Frame(getContentPane().getSize(), (ProfileListModel) getXmlEadList().getModel(), labels, retrieveFromDb.retrieveCountryCode(), retrieveFromDb.retrieveRepositoryCode()); } } }); digitalObjectTypeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!DigitalObjectAndRightsOptionFrame.isInUse()) { JFrame DigitalObjectAndRightsOptionFrame = new DigitalObjectAndRightsOptionFrame(labels, retrieveFromDb); DigitalObjectAndRightsOptionFrame.setPreferredSize(new Dimension( getContentPane().getWidth() * 3 / 8, getContentPane().getHeight() * 3 / 4)); DigitalObjectAndRightsOptionFrame.setLocation(getContentPane().getWidth() / 8, getContentPane().getHeight() / 8); DigitalObjectAndRightsOptionFrame.pack(); DigitalObjectAndRightsOptionFrame.setVisible(true); } } }); defaultSaveFolderItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JFileChooser defaultSaveFolderChooser = new JFileChooser(); defaultSaveFolderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); defaultSaveFolderChooser.setMultiSelectionEnabled(false); defaultSaveFolderChooser.setCurrentDirectory(new File(retrieveFromDb.retrieveDefaultSaveFolder())); if (defaultSaveFolderChooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { File directory = defaultSaveFolderChooser.getSelectedFile(); if (directory.canWrite() && DirectoryPermission.canWrite(directory)) { retrieveFromDb.saveDefaultSaveFolder(directory + "/"); } else { createErrorOrWarningPanel(new Exception(labels.getString("error.directory.nowrites")), false, labels.getString("error.directory.nowrites"), getContentPane()); } } } }); listDateConversionRulesItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JDialog dateConversionRulesDialog = new DateConversionRulesDialog(labels, retrieveFromDb); dateConversionRulesDialog.setPreferredSize( new Dimension(getContentPane().getWidth() * 3 / 8, getContentPane().getHeight() * 7 / 8)); dateConversionRulesDialog.setLocation(getContentPane().getWidth() / 8, getContentPane().getHeight() / 8); dateConversionRulesDialog.pack(); dateConversionRulesDialog.setVisible(true); } }); edmGeneralOptionsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!EdmGeneralOptionsFrame.isInUse()) { JFrame edmGeneralOptionsFrame = new EdmGeneralOptionsFrame(labels, retrieveFromDb); edmGeneralOptionsFrame.setPreferredSize(new Dimension(getContentPane().getWidth() * 3 / 8, getContentPane().getHeight() * 3 / 8)); edmGeneralOptionsFrame.setLocation(getContentPane().getWidth() / 8, getContentPane().getHeight() / 8); edmGeneralOptionsFrame.pack(); edmGeneralOptionsFrame.setVisible(true); } } }); closeSelectedItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { xmlEadListModel.removeFiles(xmlEadList.getSelectedValues()); } }); saveSelectedItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String defaultOutputDirectory = retrieveFromDb.retrieveDefaultSaveFolder(); boolean isMultipleFiles = xmlEadList.getSelectedIndices().length > 1; RootPaneContainer root = (RootPaneContainer) getRootPane().getTopLevelAncestor(); root.getGlassPane().setCursor(WAIT_CURSOR); root.getGlassPane().setVisible(true); for (Object selectedValue : xmlEadList.getSelectedValues()) { File selectedFile = (File) selectedValue; String filename = selectedFile.getName(); FileInstance fileInstance = fileInstances.get(filename); String filePrefix = fileInstance.getFileType().getFilePrefix(); //todo: do we really need this? filename = filename.startsWith("temp_") ? filename.replace("temp_", "") : filename; filename = !filename.endsWith(".xml") ? filename + ".xml" : filename; if (!fileInstance.isValid()) { filePrefix = "NOT_" + filePrefix; } if (fileInstance.getLastOperation().equals(FileInstance.Operation.EDIT_TREE)) { TreeTableModel treeTableModel = tree.getTreeTableModel(); Document document = (Document) treeTableModel.getRoot(); try { File file2 = new File(defaultOutputDirectory + filePrefix + "_" + filename); File filetemp = new File(Utilities.TEMP_DIR + "temp_" + filename); TransformerFactory tf = TransformerFactory.newInstance(); Transformer output = tf.newTransformer(); output.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes"); output.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); DOMSource domSource = new DOMSource(document.getFirstChild()); output.transform(domSource, new StreamResult(filetemp)); output.transform(domSource, new StreamResult(file2)); fileInstance.setLastOperation(FileInstance.Operation.SAVE); fileInstance.setCurrentLocation(filetemp.getAbsolutePath()); } catch (Exception ex) { createErrorOrWarningPanel(ex, true, labels.getString("errorSavingTreeXML"), getContentPane()); } } else if (fileInstance.isConverted()) { try { File newFile = new File(defaultOutputDirectory + filePrefix + "_" + filename); FileUtils.copyFile(new File(fileInstance.getCurrentLocation()), newFile); fileInstance.setLastOperation(FileInstance.Operation.SAVE); // fileInstance.setCurrentLocation(newFile.getAbsolutePath()); } catch (IOException ioe) { LOG.error("Error when saving file", ioe); } } else { try { File newFile = new File(defaultOutputDirectory + filePrefix + "_" + filename); FileUtils.copyFile(selectedFile, newFile); fileInstance.setLastOperation(FileInstance.Operation.SAVE); // fileInstance.setCurrentLocation(newFile.getAbsolutePath()); } catch (IOException ioe) { LOG.error("Error when saving file", ioe); } } } root.getGlassPane().setCursor(DEFAULT_CURSOR); root.getGlassPane().setVisible(false); if (isMultipleFiles) { JOptionPane.showMessageDialog(getContentPane(), MessageFormat.format(labels.getString("filesInOutput"), defaultOutputDirectory) + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } else { JOptionPane.showMessageDialog(getContentPane(), MessageFormat.format(labels.getString("fileInOutput"), defaultOutputDirectory) + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } xmlEadList.updateUI(); } }); saveMessageReportItem.addActionListener( new MessageReportActionListener(retrieveFromDb, this, fileInstances, labels, this)); sendFilesWebDAV.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("Not supported yet."); } }); quitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); xsltItem.addActionListener(new XsltAdderActionListener(this, labels)); xsdItem.addActionListener(new XsdAdderActionListener(this, labels, retrieveFromDb)); if (Utilities.isDev) { databaseItem.addActionListener(new DatabaseCheckerActionListener(retrieveFromDb, getContentPane())); } xmlEadList.addMouseListener(new ListMouseAdapter(xmlEadList, xmlEadListModel, deleteFileItem, this)); xmlEadList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (xmlEadList.getSelectedValues() != null && xmlEadList.getSelectedValues().length != 0) { if (xmlEadList.getSelectedValues().length > 1) { // convertAndValidateBtn.setEnabled(true); // validateSelectionBtn.setEnabled(true); // if (isValidated(xmlEadList)) { // convertEdmSelectionBtn.setEnabled(true); // } else { // convertEdmSelectionBtn.setEnabled(false); // } // disableAllBtnAndItems(); saveMessageReportItem.setEnabled(true); changeInfoInGUI(""); } else { // convertAndValidateBtn.setEnabled(false); // validateSelectionBtn.setEnabled(false); // convertEdmSelectionBtn.setEnabled(false); changeInfoInGUI(((File) xmlEadList.getSelectedValue()).getName()); if (apePanel.getApeTabbedPane().getSelectedIndex() == APETabbedPane.TAB_EDITION) { apePanel.getApeTabbedPane() .createEditionTree(((File) xmlEadList.getSelectedValue())); if (tree != null) { FileInstance fileInstance = fileInstances .get(((File) getXmlEadList().getSelectedValue()).getName()); tree.addMouseListener(new PopupMouseListener(tree, getDataPreparationToolGUI(), getContentPane(), fileInstance)); } } disableTabFlashing(); } checkHoldingsGuideButton(); } else { // convertAndValidateBtn.setEnabled(false); // validateSelectionBtn.setEnabled(false); // convertEdmSelectionBtn.setEnabled(false); createHGBtn.setEnabled(false); analyzeControlaccessBtn.setEnabled(false); changeInfoInGUI(""); } } } private boolean isValidated(JList xmlEadList) { for (Object selectedValue : xmlEadList.getSelectedValues()) { File selectedFile = (File) selectedValue; String filename = selectedFile.getName(); FileInstance fileInstance = fileInstances.get(filename); if (!fileInstance.isValid()) { return false; } } return true; } }); summaryWindowItem.addActionListener(new TabItemActionListener(apePanel, APETabbedPane.TAB_SUMMARY)); validationWindowItem.addActionListener(new TabItemActionListener(apePanel, APETabbedPane.TAB_VALIDATION)); conversionWindowItem.addActionListener(new TabItemActionListener(apePanel, APETabbedPane.TAB_CONVERSION)); edmConversionWindowItem.addActionListener(new TabItemActionListener(apePanel, APETabbedPane.TAB_EDM)); editionWindowItem.addActionListener(new TabItemActionListener(apePanel, APETabbedPane.TAB_EDITION)); internetApexItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { BareBonesBrowserLaunch.openURL("http://www.apex-project.eu/"); } }); /** * Option Edit apeEAC-CPF file in the menu */ this.editEacCpfFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser eacFileChooser = new JFileChooser(); eacFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); eacFileChooser.setMultiSelectionEnabled(false); eacFileChooser.setCurrentDirectory(new File(retrieveFromDb.retrieveOpenLocation())); if (eacFileChooser.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) { currentLocation = eacFileChooser.getCurrentDirectory(); retrieveFromDb.saveOpenLocation(currentLocation.getAbsolutePath()); File eacFile = eacFileChooser.getSelectedFile(); if (!EacCpfFrame.isUsed()) { try { if (ReadXml.isXmlFile(eacFile, "eac-cpf")) { new EacCpfFrame(eacFile, true, getContentPane().getSize(), (ProfileListModel) getXmlEadList().getModel(), labels); } else { JOptionPane.showMessageDialog(rootPane, labels.getString("eaccpf.error.notAnEacCpfFile")); } } catch (SAXException ex) { if (ex instanceof SAXParseException) { JOptionPane.showMessageDialog(rootPane, labels.getString("eaccpf.error.notAnEacCpfFile")); } java.util.logging.Logger.getLogger(DataPreparationToolGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IOException ex) { java.util.logging.Logger.getLogger(DataPreparationToolGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (ParserConfigurationException ex) { java.util.logging.Logger.getLogger(DataPreparationToolGUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (Exception ex) { try { JOptionPane.showMessageDialog(rootPane, labels.getString(ex.getMessage())); } catch (Exception ex1) { JOptionPane.showMessageDialog(rootPane, "Error..."); } } } } } }); /** * Option Create apeEAC-CPF in the menu */ this.createEacCpf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!EacCpfFrame.isUsed()) { EacCpfFrame eacCpfFrame = new EacCpfFrame(getContentPane().getSize(), (ProfileListModel) getXmlEadList().getModel(), labels, retrieveFromDb.retrieveCountryCode(), retrieveFromDb.retrieveRepositoryCode(), null, null, null); } } }); }
From source file:br.com.jinsync.view.FrmJInSync.java
public void openDirFile() { JFileChooser dir = new JFileChooser(); // String path = "C:\\"; String path = System.getProperty("user.dir").substring(0, 3); if (!txtFile.getText().equals("") && (!txtFile.getText().contains("("))) { path = txtFile.getText();/* w w w.j av a2 s .co m*/ } dir.setFileSelectionMode(JFileChooser.FILES_ONLY); dir.setCurrentDirectory(new File(path)); int res = dir.showOpenDialog(null); if (res == JFileChooser.APPROVE_OPTION) { txtFile.setText(dir.getSelectedFile().toString()); String nameFile = dir.getSelectedFile().toString(); ParameterFile parFile = new ParameterFile(); parFile.setFile(nameFile); tableFile = new JTable(); scrFile.setViewportView(tableFile); } }
From source file:br.com.jinsync.view.FrmJInSync.java
public void openDirectory() { JFileChooser dir = new JFileChooser(); // String path = "C:\\"; String path = System.getProperty("user.dir").substring(0, 3); if (!txtPath.getText().equals("") && (!txtPath.getText().contains("("))) { path = txtPath.getText();//from ww w . j ava2 s . c om } dir.setFileSelectionMode(JFileChooser.FILES_ONLY); dir.setCurrentDirectory(new File(path)); int res = dir.showOpenDialog(null); if (res == JFileChooser.APPROVE_OPTION) { txtPath.setText(dir.getSelectedFile().toString()); String nomeDir = dir.getSelectedFile().toString(); ParameterDir parDir = new ParameterDir(); parDir.setDir(nomeDir); arquivo = dir.getSelectedFile(); nameCopy = arquivo.getName(); tableCopy = new JTable(); scrCopy.setViewportView(tableCopy); tableFile = new JTable(); scrFile.setViewportView(tableFile); } }
From source file:ded.ui.DiagramController.java
/** Prompt for a file name to load, then replace the current diagram with it. */ public void loadFromFile() { if (this.isDirty()) { int res = JOptionPane.showConfirmDialog(this, "There are unsaved changes. Load new diagram anyway?", "Load Confirmation", JOptionPane.YES_NO_OPTION); if (res != JOptionPane.YES_OPTION) { return; }/*from w w w . jav a 2 s. c om*/ } JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(this.currentFileChooserDirectory); chooser.addChoosableFileFilter( new FileNameExtensionFilter("Diagram and ER Editor Files (.ded, .png, .er)", "ded", "png", "er")); int res = chooser.showOpenDialog(this); if (res == JFileChooser.APPROVE_OPTION) { this.currentFileChooserDirectory = chooser.getCurrentDirectory(); this.loadFromNamedFile(chooser.getSelectedFile().getAbsolutePath()); } }
From source file:ded.ui.DiagramController.java
/** Prompt user for file name and save to it. */ public void chooseAndSaveToFile() { // Prompt for a file name, confirming if the file already exists. String result = this.fileName; while (true) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(this.currentFileChooserDirectory); chooser.addChoosableFileFilter(new FileNameExtensionFilter("Diagram Editor Files (.ded)", "ded")); int res = chooser.showSaveDialog(this); if (res != JFileChooser.APPROVE_OPTION) { return; }//from w ww. j a va 2 s .c o m this.currentFileChooserDirectory = chooser.getCurrentDirectory(); result = chooser.getSelectedFile().getAbsolutePath(); if (new File(result).exists()) { res = JOptionPane.showConfirmDialog(this, "A file called \"" + result + "\" already exists. Overwrite it?", "Confirm Overwrite", JOptionPane.YES_NO_OPTION); if (res != JOptionPane.YES_OPTION) { continue; // Ask again. } } break; } // Save to the chosen file. this.saveToNamedFile(result); }