List of usage examples for javax.swing JOptionPane YES_NO_OPTION
int YES_NO_OPTION
To view the source code for javax.swing JOptionPane YES_NO_OPTION.
Click Source Link
showConfirmDialog
. From source file:net.sf.jabref.external.DroppedFileHandler.java
/** * Copy the given file to the base directory for its file type, and give it * the given name.//from w w w . java2 s. c o m * * @param fileName The name of the source file. * @param toFile The destination filename. An existing path-component will be removed. * @param edits TODO we should be able to undo this! * @return */ private boolean doCopy(String fileName, String toFile, NamedCompound edits) { List<String> dirs = panel.getBibDatabaseContext().getFileDirectory(); int found = -1; for (int i = 0; i < dirs.size(); i++) { if (new File(dirs.get(i)).exists()) { found = i; break; } } if (found < 0) { // OOps, we don't know which directory to put it in, or the given // dir doesn't exist.... // This should not happen!! LOGGER.warn("Cannot determine destination directory or destination directory does not exist"); return false; } String destinationFileName = new File(toFile).getName(); File destFile = new File(dirs.get(found) + System.getProperty("file.separator") + destinationFileName); if (destFile.equals(new File(fileName))) { // File is already in the correct position. Don't override! return true; } if (destFile.exists()) { int answer = JOptionPane.showConfirmDialog(frame, Localization.lang("'%0' exists. Overwrite file?", destFile.getPath()), Localization.lang("File exists"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.NO_OPTION) { return false; } } try { FileUtil.copyFile(new File(fileName), destFile, true); } catch (IOException e) { LOGGER.error("Problem copying file", e); return false; } return true; }
From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java
/** * DOCUMENT ME!/* w w w . j ava 2 s. c o m*/ */ @SuppressWarnings("unchecked") protected void removeAction() { RegistryBrowser.setWaitCursor(); int[] selectedIndices = getSelectedRows(); if (selectedIndices.length >= 1) { try { ArrayList<?> selectedObjects = getSelectedRegistryObjects(); ArrayList<Key> removeKeys = new ArrayList<Key>(); int size = selectedObjects.size(); for (int i = size - 1; i >= 0; i--) { RegistryObject obj = (RegistryObject) selectedObjects.get(i); Key key = obj.getKey(); removeKeys.add(key); } // Confirm the remove boolean confirmRemoves = true; // I18N: Do not localize next statement. String confirmRemovesStr = ProviderProperties.getInstance() .getProperty("jaxr-ebxml.registryBrowser.confirmRemoves", "true"); if (confirmRemovesStr.equalsIgnoreCase("false") || confirmRemovesStr.toLowerCase().equals("off")) { confirmRemoves = false; } if (confirmRemoves) { int option = JOptionPane.showConfirmDialog(null, resourceBundle.getString("dialog.confirmRemove.text"), resourceBundle.getString("dialog.confirmRemove.title"), JOptionPane.YES_NO_OPTION); if (option == JOptionPane.NO_OPTION) { RegistryBrowser.setDefaultCursor(); return; } } // cancels the cell editor, if any removeEditor(); JAXRClient client = RegistryBrowser.getInstance().getClient(); BusinessLifeCycleManager lcm = client.getBusinessLifeCycleManager(); BulkResponse resp = lcm.deleteObjects(removeKeys); client.checkBulkResponse(resp); if (resp.getStatus() == JAXRResponse.STATUS_SUCCESS) { //Remove from UI model @SuppressWarnings("rawtypes") ArrayList objects = (ArrayList) ((tableModel.getRegistryObjects()).clone()); size = selectedIndices.length; for (int i = size - 1; i >= 0; i--) { RegistryObject ro = (RegistryObject) dataModel.getValueAt(selectedIndices[i], -1); objects.remove(ro); } tableModel.setRegistryObjects(objects); } } catch (JAXRException e) { RegistryBrowser.displayError(e); } } else { RegistryBrowser.displayError(resourceBundle.getString("error.removeAction")); } RegistryBrowser.setDefaultCursor(); }
From source file:com.floreantpos.main.SetUpWindow.java
private void saveConfigData() { User user = null;/*from w w w . j av a 2 s . co m*/ /*try { user = UserDAO.getInstance().findUser(Integer.valueOf(tfUserId.getText())); } catch (UserNotFoundException ex) { user = new User(); }*/ Terminal terminal = new Terminal(); if (!updateModel(user, terminal)) return; /*UserType administrator = new UserType(); administrator.setName(com.floreantpos.POSConstants.ADMINISTRATOR); administrator.setPermissions(new HashSet<UserPermission>(Arrays.asList(UserPermission.permissions))); UserTypeDAO.getInstance().saveOrUpdate(administrator); user.setType(administrator); UserDAO.getInstance().saveOrUpdate(user);*/ TerminalDAO.getInstance().saveOrUpdate(terminal); POSMessageDialog.showMessage(Messages.getString("SetUpWindow.0")); //$NON-NLS-1$ int i = JOptionPane.showConfirmDialog(this, "Do you want to start application?", "Message", //$NON-NLS-1$//$NON-NLS-2$ JOptionPane.YES_NO_OPTION); if (i != JOptionPane.YES_OPTION) { System.exit(1); } else { try { Main.restart(); } catch (IOException e) { } catch (InterruptedException e) { } catch (URISyntaxException e) { } } }
From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java
/** * Creates a tab pane for the given GridJob. * /*from w w w. ja v a 2s. com*/ * @param jobId JobId */ protected void createJobTab(final String jobId) { // Request Job Profile final InternalClusterJobService jobService = ClusterManager.getInstance().getJobService(); final GridJobProfile profile = jobService.getProfile(jobId); // Job Start Time final long startTime = System.currentTimeMillis(); final JPanel jobPanel = new JPanel(); jobPanel.setLayout(new BorderLayout(10, 10)); // Progess Panel JPanel progressPanel = new JPanel(); progressPanel.setLayout(new BorderLayout(10, 10)); progressPanel.setBorder(BorderFactory.createTitledBorder("Progress")); jobPanel.add(progressPanel, BorderLayout.NORTH); final JProgressBar progressBar = new JProgressBar(); progressBar.setStringPainted(true); progressPanel.add(progressBar, BorderLayout.CENTER); addUIElement("jobs." + jobId + ".progress", progressBar); // Add to components map // Buttons Panel JPanel buttonsPanel = new JPanel(); jobPanel.add(buttonsPanel, BorderLayout.SOUTH); buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); // Terminate Button JButton terminateButton = new JButton("Terminate"); terminateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread(new Runnable() { public void run() { // Job Name = Class Name String name = profile.getJob().getClass().getSimpleName(); // Request user confirmation int option = JOptionPane.showConfirmDialog(ClusterMainUI.this, "Are you sure to terminate GridJob " + name + "?", "Nebula - Terminate GridJob", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.NO_OPTION) return; // Attempt Cancel boolean result = profile.getFuture().cancel(); // Notify results if (result) { JOptionPane.showMessageDialog(ClusterMainUI.this, "Grid Job '" + name + "terminated successfully.", "Nebula - Job Terminated", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(ClusterMainUI.this, "Failed to terminate Grid Job '" + name, "Nebula - Job Termination Failed", JOptionPane.WARNING_MESSAGE); } } }).start(); } }); buttonsPanel.add(terminateButton); addUIElement("jobs." + jobId + ".terminate", terminateButton); // Add to components map // Close Tab Button JButton closeButton = new JButton("Close Tab"); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { removeJobTab(jobId); } }); } }); closeButton.setEnabled(false); buttonsPanel.add(closeButton); addUIElement("jobs." + jobId + ".closetab", closeButton); // Add to components map JPanel centerPanel = new JPanel(); centerPanel.setLayout(new GridBagLayout()); jobPanel.add(centerPanel, BorderLayout.CENTER); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weightx = 1.0; /* -- Job Information -- */ JPanel jobInfoPanel = new JPanel(); jobInfoPanel.setBorder(BorderFactory.createTitledBorder("Job Information")); jobInfoPanel.setLayout(new GridBagLayout()); c.gridy = 0; c.ipady = 30; centerPanel.add(jobInfoPanel, c); GridBagConstraints c1 = new GridBagConstraints(); c1.fill = GridBagConstraints.BOTH; c1.weightx = 1; c1.weighty = 1; // Name jobInfoPanel.add(new JLabel("Name :"), c1); JLabel jobNameLabel = new JLabel(); jobInfoPanel.add(jobNameLabel, c1); jobNameLabel.setText(profile.getJob().getClass().getSimpleName()); addUIElement("jobs." + jobId + ".job.name", jobNameLabel); // Add to components map // Gap jobInfoPanel.add(new JLabel(), c1); // Type jobInfoPanel.add(new JLabel("Type :"), c1); JLabel jobType = new JLabel(); jobType.setText(getJobType(profile.getJob())); jobInfoPanel.add(jobType, c1); addUIElement("jobs." + jobId + ".job.type", jobType); // Add to components map // Job Class Name c1.gridy = 1; c1.gridwidth = 1; jobInfoPanel.add(new JLabel("GridJob Class :"), c1); c1.gridwidth = GridBagConstraints.REMAINDER; JLabel jobClassLabel = new JLabel(); jobClassLabel.setText(profile.getJob().getClass().getName()); jobInfoPanel.add(jobClassLabel, c1); addUIElement("jobs." + jobId + ".job.class", jobClassLabel); // Add to components map /* -- Execution Information -- */ JPanel executionInfoPanel = new JPanel(); executionInfoPanel.setBorder(BorderFactory.createTitledBorder("Execution Statistics")); executionInfoPanel.setLayout(new GridBagLayout()); c.gridy = 1; c.ipady = 30; centerPanel.add(executionInfoPanel, c); GridBagConstraints c3 = new GridBagConstraints(); c3.weightx = 1; c3.weighty = 1; c3.fill = GridBagConstraints.BOTH; // Start Time executionInfoPanel.add(new JLabel("Job Status :"), c3); final JLabel statusLabel = new JLabel("Initializing"); executionInfoPanel.add(statusLabel, c3); addUIElement("jobs." + jobId + ".execution.status", statusLabel); // Add to components map // Status Update Listener profile.getFuture().addGridJobStateListener(new GridJobStateListener() { public void stateChanged(final GridJobState newState) { SwingUtilities.invokeLater(new Runnable() { public void run() { statusLabel.setText(StringUtils.capitalize(newState.toString().toLowerCase())); } }); } }); executionInfoPanel.add(new JLabel(), c3); // Space Holder // Percent Complete executionInfoPanel.add(new JLabel("Completed % :"), c3); final JLabel percentLabel = new JLabel("-N/A-"); executionInfoPanel.add(percentLabel, c3); addUIElement("jobs." + jobId + ".execution.percentage", percentLabel); // Add to components map c3.gridy = 1; // Start Time executionInfoPanel.add(new JLabel("Start Time :"), c3); JLabel startTimeLabel = new JLabel(DateFormat.getInstance().format(new Date(startTime))); executionInfoPanel.add(startTimeLabel, c3); addUIElement("jobs." + jobId + ".execution.starttime", startTimeLabel); // Add to components map executionInfoPanel.add(new JLabel(), c3); // Space Holder // Elapsed Time executionInfoPanel.add(new JLabel("Elapsed Time :"), c3); JLabel elapsedTimeLabel = new JLabel("-N/A-"); executionInfoPanel.add(elapsedTimeLabel, c3); addUIElement("jobs." + jobId + ".execution.elapsedtime", elapsedTimeLabel); // Add to components map c3.gridy = 2; // Tasks Deployed (Count) executionInfoPanel.add(new JLabel("Tasks Deployed :"), c3); JLabel tasksDeployedLabel = new JLabel("-N/A-"); executionInfoPanel.add(tasksDeployedLabel, c3); addUIElement("jobs." + jobId + ".execution.tasks", tasksDeployedLabel); // Add to components map executionInfoPanel.add(new JLabel(), c3); // Space Holder // Results Collected (Count) executionInfoPanel.add(new JLabel("Results Collected :"), c3); JLabel resultsCollectedLabel = new JLabel("-N/A-"); executionInfoPanel.add(resultsCollectedLabel, c3); addUIElement("jobs." + jobId + ".execution.results", resultsCollectedLabel); // Add to components map c3.gridy = 3; // Remaining Tasks (Count) executionInfoPanel.add(new JLabel("Remaining Tasks :"), c3); JLabel remainingTasksLabel = new JLabel("-N/A-"); executionInfoPanel.add(remainingTasksLabel, c3); addUIElement("jobs." + jobId + ".execution.remaining", remainingTasksLabel); // Add to components map executionInfoPanel.add(new JLabel(), c3); // Space Holder // Failed Tasks (Count) executionInfoPanel.add(new JLabel("Failed Tasks :"), c3); JLabel failedTasksLabel = new JLabel("-N/A-"); executionInfoPanel.add(failedTasksLabel, c3); addUIElement("jobs." + jobId + ".execution.failed", failedTasksLabel); // Add to components map /* -- Submitter Information -- */ UUID ownerId = profile.getOwner(); GridNodeDelegate owner = ClusterManager.getInstance().getClusterRegistrationService() .getGridNodeDelegate(ownerId); JPanel ownerInfoPanel = new JPanel(); ownerInfoPanel.setBorder(BorderFactory.createTitledBorder("Owner Information")); ownerInfoPanel.setLayout(new GridBagLayout()); c.gridy = 2; c.ipady = 10; centerPanel.add(ownerInfoPanel, c); GridBagConstraints c2 = new GridBagConstraints(); c2.fill = GridBagConstraints.BOTH; c2.weightx = 1; c2.weighty = 1; // Host Name ownerInfoPanel.add(new JLabel("Host Name :"), c2); JLabel hostNameLabel = new JLabel(owner.getProfile().getName()); ownerInfoPanel.add(hostNameLabel, c2); addUIElement("jobs." + jobId + ".owner.hostname", hostNameLabel); // Add to components map // Gap ownerInfoPanel.add(new JLabel(), c2); // Host IP Address ownerInfoPanel.add(new JLabel("Host IP :"), c2); JLabel hostIPLabel = new JLabel(owner.getProfile().getIpAddress()); ownerInfoPanel.add(hostIPLabel, c2); addUIElement("jobs." + jobId + ".owner.hostip", hostIPLabel); // Add to components map // Owner UUID c2.gridy = 1; c2.gridx = 0; ownerInfoPanel.add(new JLabel("Owner ID :"), c2); JLabel ownerIdLabel = new JLabel(profile.getOwner().toString()); c2.gridx = 1; c2.gridwidth = 4; ownerInfoPanel.add(ownerIdLabel, c2); addUIElement("jobs." + jobId + ".owner.id", ownerIdLabel); // Add to components map SwingUtilities.invokeLater(new Runnable() { public void run() { // Create Tab addUIElement("jobs." + jobId, jobPanel); JTabbedPane tabs = getUIElement("tabs"); tabs.addTab(profile.getJob().getClass().getSimpleName(), jobPanel); tabs.revalidate(); } }); // Execution Information Updater Thread new Thread(new Runnable() { boolean initialized = false; boolean unbounded = false; public void run() { // Unbounded, No Progress Supported if ((!initialized) && profile.getJob() instanceof UnboundedGridJob<?>) { SwingUtilities.invokeLater(new Runnable() { public void run() { progressBar.setIndeterminate(true); progressBar.setStringPainted(false); // Infinity Symbol percentLabel.setText(String.valueOf('\u221e')); } }); initialized = true; unbounded = true; } // Update Job Info while (true) { try { // 500ms Interval Thread.sleep(500); } catch (InterruptedException e) { log.warn("Interrupted Progress Updater Thread", e); } final int totalCount = profile.getTotalTasks(); final int tasksRem = profile.getTaskCount(); final int resCount = profile.getResultCount(); final int failCount = profile.getFailedCount(); showBusyIcon(); // Task Information JLabel totalTaskLabel = getUIElement("jobs." + jobId + ".execution.tasks"); totalTaskLabel.setText(String.valueOf(totalCount)); // Result Count JLabel resCountLabel = getUIElement("jobs." + jobId + ".execution.results"); resCountLabel.setText(String.valueOf(resCount)); // Remaining Task Count JLabel remLabel = getUIElement("jobs." + jobId + ".execution.remaining"); remLabel.setText(String.valueOf(tasksRem)); // Failed Task Count JLabel failedLabel = getUIElement("jobs." + jobId + ".execution.failed"); failedLabel.setText(String.valueOf(failCount)); // Elapsed Time JLabel elapsedLabel = getUIElement("jobs." + jobId + ".execution.elapsedtime"); elapsedLabel.setText(TimeUtils.timeDifference(startTime)); // Job State final JLabel statusLabel = getUIElement("jobs." + jobId + ".execution.status"); // If not in Executing Mode if ((!profile.getFuture().isJobFinished()) && profile.getFuture().getState() != GridJobState.EXECUTING) { SwingUtilities.invokeLater(new Runnable() { public void run() { // Progress Bar progressBar.setIndeterminate(true); progressBar.setStringPainted(false); // Status Text String state = profile.getFuture().getState().toString(); statusLabel.setText(StringUtils.capitalize(state.toLowerCase())); // Percentage Label percentLabel.setText(String.valueOf('\u221e')); } }); } else { // Executing Mode : Progress Information // Job Finished, Stop if (profile.getFuture().isJobFinished()) { showIdleIcon(); return; } // Double check for status label if (!statusLabel.getText().equalsIgnoreCase("executing")) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { String newstate = profile.getFuture().getState().toString(); statusLabel.setText(StringUtils.capitalize(newstate.toLowerCase())); } }); } if (!unbounded) { final int percentage = (int) (profile.percentage() * 100); //final int failCount = profile.get SwingUtilities.invokeLater(new Runnable() { public void run() { // If finished at this point, do not update if (progressBar.getValue() == 100) { return; } // If ProgressBar is in indeterminate if (progressBar.isIndeterminate()) { progressBar.setIndeterminate(false); progressBar.setStringPainted(true); } // Update Progress Bar / Percent Label progressBar.setValue(percentage); percentLabel.setText(percentage + " %"); } }); } } } } }).start(); // Job End Hook to Execute Job End Actions ServiceEventsSupport.addServiceHook(new ServiceHookCallback() { public void onServiceEvent(final ServiceMessage event) { SwingUtilities.invokeLater(new Runnable() { public void run() { JButton close = getUIElement("jobs." + jobId + ".closetab"); JButton terminate = getUIElement("jobs." + jobId + ".terminate"); terminate.setEnabled(false); close.setEnabled(true); JProgressBar progress = getUIElement("jobs." + jobId + ".progress"); JLabel percentage = getUIElement("jobs." + jobId + ".execution.percentage"); progress.setEnabled(false); // If Successfully Finished if (event.getType() == ServiceMessageType.JOB_END) { if (profile.getFuture().getState() != GridJobState.FAILED) { // If Not Job Failed progress.setValue(100); percentage.setText("100 %"); } else { // If Failed percentage.setText("N/A"); } // Stop (if) Indeterminate Progress Bar if (progress.isIndeterminate()) { progress.setIndeterminate(false); progress.setStringPainted(true); } } else if (event.getType() == ServiceMessageType.JOB_CANCEL) { if (progress.isIndeterminate()) { progress.setIndeterminate(false); progress.setStringPainted(false); percentage.setText("N/A"); } } showIdleIcon(); } }); } }, jobId, ServiceMessageType.JOB_CANCEL, ServiceMessageType.JOB_END); }
From source file:org.fhaes.jsea.JSEAFrame.java
/** * Initialize the menu/toolbar actions.// ww w . ja v a2 s . c o m */ private void initActions() { final JFrame glue = this; actionFileExit = new FHAESAction("Close", "close.png") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { dispose(); } }; actionChartProperties = new FHAESAction("Chart properties", "properties.png") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { ChartEditor editor = ChartEditorManager .getChartEditor(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart()); int result = JOptionPane.showConfirmDialog(glue, editor, "Properties", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { editor.updateChart(jsea.getChartList().get(segmentComboBox.getSelectedIndex()).getChart()); } } }; actionReset = new FHAESAction("Reset", "filenew.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { Object[] options = { "Yes", "No", "Cancel" }; int n = JOptionPane.showOptionDialog(glue, "Are you sure you want to start a new analysis?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setToDefault(); } } }; actionRun = new FHAESAction("Run analysis", "run.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { runAnalysis(); } }; actionSaveAll = new FHAESAction("Save all results", "save_all.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } File f; try { f = new File(file.getAbsolutePath() + File.separator + "report.txt"); saveReportTXT(f); f = new File(file.getAbsolutePath() + File.separator + "report.pdf"); saveReportPDF(f); f = new File(file.getAbsolutePath() + File.separator + "chart.png"); saveChartPNG(f); f = new File(file.getAbsolutePath() + File.separator + "chart.pdf"); saveChartPDF(f); f = new File(file.getAbsolutePath() + File.separator + "data.xls"); saveDataXLS(f); f = new File(file.getAbsolutePath()); saveDataCSV(f); } catch (IOException e) { e.printStackTrace(); } } }; actionSaveData = new FHAESAction("Save data tables", "table.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } try { saveDataCSV(file); } catch (IOException e) { e.printStackTrace(); } } }; actionSaveReport = new FHAESAction("Save report", "report.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } // Set file filters fc.setAcceptAllFileFilterUsed(false); TXTFileFilter txtfilter = new TXTFileFilter(); PDFFilter pdffilter = new PDFFilter(); fc.addChoosableFileFilter(txtfilter); fc.addChoosableFileFilter(pdffilter); fc.setFileFilter(txtfilter); FileFilter chosenFilter; // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); chosenFilter = fc.getFileFilter(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } // Handle file type and extensions nicely if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) { if (chosenFilter.equals(txtfilter)) { file = new File(file.getAbsoluteFile() + ".txt"); } else if (chosenFilter.equals(pdffilter)) { file = new File(file.getAbsoluteFile() + ".pdf"); } } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("txt") && chosenFilter.equals("pdf")) { chosenFilter = txtfilter; } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf") && chosenFilter.equals("txt")) { chosenFilter = pdffilter; } // If file already exists confirm overwrite if (file.exists()) { // Check we have write access to this file if (!file.canWrite()) { JOptionPane.showMessageDialog(glue, "You do not have write permission to this file", "Error", JOptionPane.ERROR_MESSAGE); return; } int n = JOptionPane.showConfirmDialog(glue, "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?", "Overwrite file?", JOptionPane.YES_NO_OPTION); if (n != JOptionPane.YES_OPTION) { return; } } // Do save try { if (chosenFilter.equals(txtfilter)) { saveReportTXT(file); } else if (chosenFilter.equals(pdffilter)) { saveReportPDF(file); } else { log.error("No export file format chosen. Shouldn't be able to get here!"); } } catch (IOException e) { JOptionPane.showMessageDialog(glue, "Unable to save report. Check log file.", "Warning", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }; actionSaveChart = new FHAESAction("Save chart", "barchart.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { if (jsea == null) return; File file; JFileChooser fc; // Open file chooser in last folder if possible if (App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null) != null) { fc = new JFileChooser(App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null)); } else { fc = new JFileChooser(); } // Set file filters fc.setAcceptAllFileFilterUsed(false); PNGFilter pngfilter = new PNGFilter(); PDFFilter pdffilter = new PDFFilter(); fc.addChoosableFileFilter(pngfilter); fc.addChoosableFileFilter(pdffilter); fc.setFileFilter(pngfilter); FileFilter chosenFilter; // Show dialog and get specified file int returnVal = fc.showSaveDialog(glue); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); chosenFilter = fc.getFileFilter(); App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, file.getAbsolutePath()); } else { return; } // Handle file type and extensions nicely if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("")) { if (chosenFilter.equals(pngfilter)) { file = new File(file.getAbsoluteFile() + ".png"); } else if (chosenFilter.equals(pdffilter)) { file = new File(file.getAbsoluteFile() + ".pdf"); } } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("png") && chosenFilter.equals("pdf")) { chosenFilter = pngfilter; } else if (FilenameUtils.getExtension(file.getAbsolutePath()).toLowerCase().equals("pdf") && chosenFilter.equals("png")) { chosenFilter = pdffilter; } // If file already exists confirm overwrite if (file.exists()) { // Check we have write access to this file if (!file.canWrite()) { JOptionPane.showMessageDialog(glue, "You do not have write permission to this file", "Error", JOptionPane.ERROR_MESSAGE); return; } int n = JOptionPane.showConfirmDialog(glue, "File: " + file.getName() + " already exists. " + "Would you like to overwrite it?", "Overwrite file?", JOptionPane.YES_NO_OPTION); if (n != JOptionPane.YES_OPTION) { return; } } // Do save try { if (chosenFilter.equals(pngfilter)) { saveChartPNG(file); } else if (chosenFilter.equals(pdffilter)) { saveChartPDF(file); } else { log.error("No export file format chosen. Shouldn't be able to get here!"); } } catch (IOException e) { JOptionPane.showMessageDialog(glue, "Unable to save chart. Check log file.", "Warning", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }; actionCopy = new FHAESAction("Copy", "edit_copy.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { copyCurrentSelectionToClipboard(); } }; actionLagMap = new FHAESAction("LagMap", "lagmap22.png") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { launchLagMap(); } }; }
From source file:edu.harvard.mcz.imagecapture.MainFrame.java
/** * This method initializes jMenuItemPreprocess * //from ww w .j ava 2 s .co m * @return javax.swing.JMenuItem */ private JMenuItem getJMenuItemPreprocess() { if (jMenuItemPreprocess == null) { jMenuItemPreprocess = new JMenuItem(); jMenuItemPreprocess.setText("Preprocess All"); jMenuItemPreprocess.setEnabled(true); try { jMenuItemPreprocess.setIcon(new ImageIcon(this.getClass() .getResource("/edu/harvard/mcz/imagecapture/resources/barcode_icon_16px.jpg"))); } catch (Exception e) { log.error("Can't open icon file for jMenuItemScanOneBarcode."); log.error(e.getLocalizedMessage()); } jMenuItemPreprocess.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { int result = JOptionPane.showConfirmDialog(Singleton.getSingletonInstance().getMainFrame(), "Are you sure, this will check all image files and may take some time.", "Preprocess All?", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { JobAllImageFilesScan scan = new JobAllImageFilesScan(); (new Thread(scan)).start(); } else { Singleton.getSingletonInstance().getMainFrame().setStatusMessage("Preprocess canceled."); } } }); } return jMenuItemPreprocess; }
From source file:com.proyecto.vista.MantenimientoUnidadMedida.java
private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed // TODO add your handling code here: accion = AbstractControlador.ELIMINAR; if (tblUnidad.getSelectedRow() != -1) { Integer id = tblUnidad.getSelectedRow(); UnidadMedida unidad = unidadControlador.buscarPorId(lista.get(id).getId()); if (unidad != null) { if (JOptionPane.showConfirmDialog(null, "Desea Eliminar la Unidad?", "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { int[] filas = tblUnidad.getSelectedRows(); for (int i = 0; i < filas.length; i++) { UnidadMedida unidad2 = lista.get(filas[0]); lista.remove(unidad2); unidadControlador.setSeleccionado(unidad2); unidadControlador.accion(accion); }//from w w w .j a v a 2s . c om if (unidadControlador.accion(accion) == 3) { JOptionPane.showMessageDialog(null, "Unidad eliminada correctamente", "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Unidad no eliminada", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(null, "Unidad no eliminada", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } } else { JOptionPane.showMessageDialog(null, "Debe seleccionar una Unidad de la lista", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } }
From source file:musite.ui.MusiteResultPanel.java
private void exportComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportComboBoxActionPerformed String name = panelName.replaceAll("[\\\\/:\\*\\?\"<>\\|]+", "-"); String defaultFile = MusiteInit.defaultPath + File.separator + name; if (sliderTitleComboBox.getSelectedItem().equals(SPECIFICITY)) { defaultFile += String.format("-Sp_%.2f", specificity); } else {/*from w w w. ja v a 2 s. c o m*/ defaultFile += String.format("-Score_%.3f", threshold); } defaultFile += ".result"; switch (exportComboBox.getSelectedIndex()) { case 1: // tab-delimited text file { JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); fc.setSelectedFile(new File(defaultFile)); ArrayList<String> exts = new ArrayList<String>(1); String fasta = "txt"; exts.add(fasta); FileExtensionsFilter fastaFilter = new FileExtensionsFilter(exts, "Tab-delimited file (.txt)"); fc.addChoosableFileFilter(fastaFilter); //fc.setAcceptAllFileFilterUsed(true); fc.setDialogTitle("Save the the result to..."); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); MusiteInit.defaultPath = file.getParent(); String filePath = MusiteInit.defaultPath + File.separator + file.getName(); String ext = FilePathParser.getExt(filePath); if (ext == null || !ext.equalsIgnoreCase("txt")) { filePath += ".txt"; } if (IOUtil.fileExist(filePath)) { int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.NO_OPTION) break; } Vector<Vector> data = formatData(proteinList, false, true); int n = data.size(); ArrayList<String> dataOut = new ArrayList(n + 1); dataOut.add(StringUtils.join(header.iterator(), '\t')); for (Vector vec : data) { dataOut.add(StringUtils.join(vec.iterator(), '\t')); } try { IOUtil.writeCollectionAscii(dataOut, filePath); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "Error: failed to write the file."); break; } JOptionPane.showMessageDialog(this, "Successfully exported."); } break; } // case 2: // fasta // { // JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); // fc.setSelectedFile(new File(defaultFile)); // // ArrayList<String> exts = new ArrayList<String>(1); // String fasta = "fasta"; // exts.add(fasta); // FileExtensionsFilter fastaFilter = new FileExtensionsFilter(exts,"Fasta file (.fasta)"); // fc.addChoosableFileFilter(fastaFilter); // // //fc.setAcceptAllFileFilterUsed(true); // fc.setDialogTitle("Save the the result to..."); // int returnVal = fc.showSaveDialog(this); // if (returnVal == JFileChooser.APPROVE_OPTION) { // File file = fc.getSelectedFile(); // MusiteInit.defaultPath = file.getParent(); // // String filePath = MusiteInit.defaultPath + File.separator + file.getName(); // // String ext = FilePathParser.getExt(filePath); // if (ext==null||!ext.equalsIgnoreCase("fasta")) { // filePath += ".fasta"; // } // // if (IOUtil.fileExist(filePath)) { // int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); // if (ret==JOptionPane.NO_OPTION) // break; // } // // ProteinsWriter writer = new ModifiedProteinsFastaWriter(); // WriteTask writeTask = new WriteTask(resultDisplay, writer, filePath); // TaskUtil.execute(writeTask); // if (!writeTask.success()) { // JOptionPane.showMessageDialog(this, "Failed to export."); // break; // } // // JOptionPane.showMessageDialog(this, "Successfully exported."); // } // // break; // } // case 3: // xml // { // JFileChooser fc = new JFileChooser(MusiteInit.defaultPath); // fc.setSelectedFile(new File(defaultFile)); // // ArrayList<String> exts = new ArrayList<String>(1); // String xml = "xml"; // exts.add(xml); // FileExtensionsFilter xmlFilter = new FileExtensionsFilter(exts,"XML file (.xml)"); // fc.addChoosableFileFilter(xmlFilter); // // //fc.setAcceptAllFileFilterUsed(true); // fc.setDialogTitle("Save the the result to..."); // int returnVal = fc.showSaveDialog(this); // if (returnVal == JFileChooser.APPROVE_OPTION) { // File file = fc.getSelectedFile(); // MusiteInit.defaultPath = file.getParent(); // // String filePath = MusiteInit.defaultPath + File.separator + file.getName(); // // String ext = FilePathParser.getExt(filePath); // if (ext==null||!ext.equalsIgnoreCase("xml")) { // filePath += ".xml"; // } // // if (IOUtil.fileExist(filePath)) { // int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?", "Relace the existing file?", JOptionPane.YES_NO_OPTION); // if (ret==JOptionPane.NO_OPTION) // break; // } // // ProteinsXMLWriter writer = ProteinsXMLWriter.createWriter(); // WriteTask xmlWriteTask = new WriteTask(resultDisplay, writer, filePath); // TaskUtil.execute(xmlWriteTask); // if (!xmlWriteTask.success()) { // JOptionPane.showMessageDialog(this, "Failed to export."); // break; // } // // JOptionPane.showMessageDialog(this, "Successfully exported."); // } // // break; // } } exportComboBox.setSelectedIndex(0); }
From source file:com.proyecto.vista.MantenimientoCampo.java
private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed // TODO add your handling code here: accion = Controlador.ELIMINAR;//w ww . j a v a 2 s . co m if (tblclase.getSelectedRow() != -1) { Integer id = tblclase.getSelectedRow(); Campo campo = campoControlador.buscarPorId(lista.get(id).getId()); if (campo != null) { if (JOptionPane.showConfirmDialog(null, "Desea Eliminar el Campo?", "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { int[] filas = tblclase.getSelectedRows(); for (int i = 0; i < filas.length; i++) { Campo campo2 = lista.get(filas[0]); lista.remove(campo2); campoControlador.setSeleccionado(campo2); campoControlador.accion(accion); } if (campoControlador.accion(accion) == 3) { JOptionPane.showMessageDialog(null, "Campo eliminada correctamente", "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Campo no eliminada", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(null, "Campo no eliminada", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } } else { JOptionPane.showMessageDialog(null, "Debe seleccionar un Campo de la lista", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveSpj(SpinCADBank bank) { // Create a file chooser String savedPath = prefs.get("MRUSpjFolder", ""); String[] spnFileNames = new String[8]; final JFileChooser fc = new JFileChooser(savedPath); // In response to a button click: FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin Project Files", "spj"); fc.setFileFilter(filter);//from ww w. j a va2 s . c o m // XXX debug fc.showSaveDialog(new JFrame()); File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spj")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spj"); } int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame1 = new JFrame(); n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); } if (n == JOptionPane.YES_OPTION) { // filePath points at the desired Spj file String filePath = fileToBeSaved.getPath(); String folder = fileToBeSaved.getParent().toString(); // export the individual SPN files for (int i = 0; i < 8; i++) { try { String asmFileNameRoot = FilenameUtils.removeExtension(bank.patch[i].patchFileName); String asmFileName = folder + "\\" + asmFileNameRoot + ".spn"; if (bank.patch[i].patchFileName != "Untitled") { fileSaveAsm(bank.patch[i], asmFileName); spnFileNames[i] = asmFileName; } } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } finally { } } // now create the Spin Project file fileToBeSaved.delete(); BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(fileToBeSaved, true)); } catch (IOException e1) { e1.printStackTrace(); } try { writer.write("NUMDOCS:8"); writer.newLine(); } catch (IOException e1) { e1.printStackTrace(); } for (int i = 0; i < 8; i++) { try { if (bank.patch[i].patchFileName != "Untitled") { writer.write(spnFileNames[i] + ",1"); } else { writer.write(",0"); } writer.newLine(); } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!\n" + filePath, "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } } // write the build flags try { writer.write(",1,1,1"); writer.newLine(); } catch (IOException e1) { e1.printStackTrace(); } try { writer.close(); } catch (IOException e) { e.printStackTrace(); } saveMRUSpjFolder(filePath); } }