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:edu.ucla.stat.SOCR.analyses.gui.PrincipalComponentAnalysis.java
/**This method defines the specific statistical Analysis to be carried our on the user specified data. ANOVA is done in this case. */ public void doAnalysis() { if (dataTable.isEditing()) dataTable.getCellEditor().stopCellEditing(); if (!hasExample) { JOptionPane.showMessageDialog(this, DATA_MISSING_MESSAGE); return;// w ww.j a va2s .co m } Data data = new Data(); String firstMessage = "Would you like to use all the data columns in this Principal Components Analysis?"; String title = "SOCR - Principal Components Analysis"; String secondMessage = "Please enter the column numbers (seperated by comma) that you would like to use."; String columnNumbers = ""; int reply = JOptionPane.showConfirmDialog(null, firstMessage, title, JOptionPane.YES_NO_OPTION); if (reply == JOptionPane.YES_OPTION) { String cellValue = null; int originalRow = 0; for (int k = 0; k < dataTable.getRowCount(); k++) { cellValue = ((String) dataTable.getValueAt(k, 0)); if (cellValue != null && !cellValue.equals("")) { originalRow++; } } cellValue = null; int originalColumn = 0; for (int k = 0; k < dataTable.getColumnCount(); k++) { cellValue = ((String) dataTable.getValueAt(0, k)); if (cellValue != null && !cellValue.equals("")) { originalColumn++; } } dataRow = originalRow; dataColumn = originalColumn; String PCA_Data1[][] = new String[originalRow][originalColumn]; double PCA_Data[][] = new double[originalRow][originalColumn]; for (int k = 0; k < originalRow; k++) for (int j = 0; j < originalColumn; j++) { if (dataTable.getValueAt(k, j) != null && !dataTable.getValueAt(k, j).equals("")) { PCA_Data1[k][j] = (String) dataTable.getValueAt(k, j); PCA_Data[k][j] = Double.parseDouble(PCA_Data1[k][j]); } } double PCA_Adjusted_Data[][] = new double[originalRow][originalColumn]; double column_Total = 0; double column_Mean = 0; for (int j = 0; j < originalColumn; j++) for (int k = 0; k < originalRow; k++) { column_Total += PCA_Data[k][j]; if (k == (originalRow - 1)) { column_Mean = column_Total / originalRow; for (int p = 0; p < originalRow; p++) { PCA_Adjusted_Data[p][j] = PCA_Data[p][j] - column_Mean; } column_Total = 0; column_Mean = 0; } } Covariance cov = new Covariance(PCA_Adjusted_Data); RealMatrix matrix = cov.getCovarianceMatrix(); EigenDecomposition eigenDecomp = new EigenDecomposition(matrix, 0); storedData = eigenDecomp; RealMatrix eigenvectorMatrix = eigenDecomp.getV(); EValueArray = eigenDecomp.getRealEigenvalues(); eigenvectorMatrix = eigenvectorMatrix.transpose(); double eigenvectorArray[][] = eigenvectorMatrix.getData(); /*for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) { System.out.println(eigenvectorArray[j][k] + " "); } */ Matrix matrix1 = new Matrix(eigenvectorArray); Matrix matrix2 = new Matrix(PCA_Adjusted_Data); matrix2 = matrix2.transpose(); Matrix finalProduct = matrix1.times(matrix2); finalProduct = finalProduct.transpose(); double finalArray[][] = finalProduct.getArrayCopy(); for (int j = 0; j < originalRow; j++) for (int k = 0; k < originalColumn; k++) { PCATable.setValueAt(finalArray[j][k], j, k); } xData = new double[originalRow]; yData = new double[originalRow]; for (int i = 0; i < originalRow; i++) { xData[i] = finalArray[i][0]; } for (int i = 0; i < originalRow; i++) { yData[i] = finalArray[i][1]; } dependentHeader = "C1"; independentHeader = "C2"; } else { // start here try { columnNumbers = JOptionPane.showInputDialog(secondMessage); } catch (Exception e) { } String columnNumbersFinal = "," + columnNumbers.replaceAll("\\s", "") + ","; Vector<Integer> locationOfComma = new Vector<Integer>(100); for (int i = 0; i < columnNumbersFinal.length(); i++) { char d = columnNumbersFinal.charAt(i); if (d == ',') locationOfComma.add(i); } Vector<Integer> vector = new Vector<Integer>(100); // vector containing column selected numbers for (int i = 0; i < locationOfComma.size() - 1; i++) { String temp = columnNumbersFinal.substring(locationOfComma.get(i) + 1, locationOfComma.get(i + 1)); if (temp == "") continue; vector.add((Integer.parseInt(temp) - 1)); } dependentHeader = "C" + (vector.get(0) + 1); independentHeader = "C" + (vector.get(1) + 1); // System.out.println("Vector size is: " + vector.size() + "\n"); String cellValue = null; int originalRow = 0; for (int k = 0; k < dataTable.getRowCount(); k++) { cellValue = ((String) dataTable.getValueAt(k, 0)); if (cellValue != null && !cellValue.equals("")) { originalRow++; } } int originalColumn = vector.size(); dataRow = originalRow; dataColumn = originalColumn; String PCA_Data1[][] = new String[originalRow][originalColumn]; double PCA_Data[][] = new double[originalRow][originalColumn]; for (int k = 0; k < originalRow; k++) for (int j = 0; j < originalColumn; j++) { if (dataTable.getValueAt(k, vector.get(j)) != null && !dataTable.getValueAt(k, vector.get(j)).equals("")) { PCA_Data1[k][j] = (String) dataTable.getValueAt(k, vector.get(j)); PCA_Data[k][j] = Double.parseDouble(PCA_Data1[k][j]); } } double PCA_Adjusted_Data[][] = new double[originalRow][originalColumn]; double column_Total = 0; double column_Mean = 0; for (int j = 0; j < originalColumn; j++) for (int k = 0; k < originalRow; k++) { column_Total += PCA_Data[k][j]; if (k == (originalRow - 1)) { column_Mean = column_Total / originalRow; for (int p = 0; p < originalRow; p++) { PCA_Adjusted_Data[p][j] = PCA_Data[p][j] - column_Mean; } column_Total = 0; column_Mean = 0; } } Covariance cov = new Covariance(PCA_Adjusted_Data); RealMatrix matrix = cov.getCovarianceMatrix(); EigenDecomposition eigenDecomp = new EigenDecomposition(matrix, 0); storedData = eigenDecomp; RealMatrix eigenvectorMatrix = eigenDecomp.getV(); EValueArray = eigenDecomp.getRealEigenvalues(); // added eigenvectorMatrix = eigenvectorMatrix.transpose(); double eigenvectorArray[][] = eigenvectorMatrix.getData(); /*for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) { System.out.println(eigenvectorArray[j][k] + " "); } */ Matrix matrix1 = new Matrix(eigenvectorArray); Matrix matrix2 = new Matrix(PCA_Adjusted_Data); matrix2 = matrix2.transpose(); Matrix finalProduct = matrix1.times(matrix2); finalProduct = finalProduct.transpose(); double finalArray[][] = finalProduct.getArrayCopy(); /* for (int j = 0; j < dataTable.getColumnCount(); j++) for (int k = 0; k < dataTable.getRowCount(); k++) { System.out.println(finalArray[j][k] + " "); }*/ for (int j = 0; j < originalRow; j++) for (int k = 0; k < originalColumn; k++) { PCATable.setValueAt(finalArray[j][k], j, k); } xData = new double[originalRow]; yData = new double[originalRow]; for (int i = 0; i < originalRow; i++) { xData[i] = finalArray[i][0]; } for (int i = 0; i < originalRow; i++) { yData[i] = finalArray[i][1]; } } map = new HashMap<Double, double[]>(); for (int i = 0; i < dataColumn; i++) { map.put(EValueArray[i], storedData.getEigenvector(i).toArray()); } Arrays.sort(EValueArray); xData1 = new double[EValueArray.length]; // for Scree Plot yData1 = new double[EValueArray.length]; for (int i = 0; i < EValueArray.length; i++) { xData1[i] = i + 1; } for (int i = 0; i < EValueArray.length; i++) { yData1[i] = EValueArray[i]; } for (int i = 0; i < yData1.length / 2; i++) { double temp = yData1[i]; yData1[i] = yData1[yData1.length - i - 1]; yData1[yData1.length - i - 1] = temp; } for (int i = 0; i < xData1.length; i++) { System.out.println("xData1 contains: " + xData1[i] + "\n"); } for (int i = 0; i < yData1.length; i++) { System.out.println("yData1 contains: " + yData1[i] + "\n"); } for (int i = 0; i < EValueArray.length / 2; i++) { double temp = EValueArray[i]; EValueArray[i] = EValueArray[EValueArray.length - i - 1]; EValueArray[EValueArray.length - i - 1] = temp; } resultPanelTextArea.append( "Click on \"PCA RESULT\" panel to view the transformed data (Eigenvector Transposed * Adjusted Data Transposed)"); resultPanelTextArea.append("\n\nThe real eigenvalues (in descending order) are: \n\n"); resultPanelTextArea.append("" + round(EValueArray[0], 3)); for (int i = 1; i < EValueArray.length; i++) { resultPanelTextArea.append("\n" + round(EValueArray[i], 3)); } resultPanelTextArea.append("\n\nThe corresponding eigenvectors (in columns) are: \n\n"); double temp[] = new double[100]; for (int j = 0; j < temp.length; j++) for (int i = 0; i < EValueArray.length; i++) { temp = map.get(EValueArray[i]); resultPanelTextArea.append("" + round(temp[j], 3) + "\t"); if (i == EValueArray.length - 1) { resultPanelTextArea.append("\n"); } } doGraph(); }
From source file:dataviewer.DataViewer.java
/** * Creates new form DataViewer/*from ww w .java 2s . c om*/ */ public DataViewer() { try { for (Enum ee : THREAD.values()) { t[ee.ordinal()] = new Thread(); } initComponents(); DropTarget dropTarget = new DropTarget(tr_files, new DropTargetListenerImpl()); TreeSelectionListener treeSelectionListener = new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { javax.swing.JTree tree = (javax.swing.JTree) e.getSource(); TreePath path = tree.getSelectionPath(); Object[] pnode = (Object[]) path.getPath(); String name = pnode[pnode.length - 1].toString(); String ex = getExtension(name); if (ex.equals(".txt") || ex.equals(".dat") || ex.equals(".csv") || ex.equals(".tsv")) { selected_file = name; } else { selected_file = ""; } } }; tr_files.addTreeSelectionListener(treeSelectionListener); tr_files.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() >= 2) { if (!"".equals(selected_file)) { //count_data(); read_data(); } else { TreePath path = tr_files.getSelectionPath(); if (path.getLastPathComponent().toString().equals(cur_path)) { cur_path = (new File(cur_path)).getParent(); } else { cur_path = cur_path + File.separator + path.getLastPathComponent().toString(); } fill_tree(); } } } }); tr_files.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) { cur_path = (new File(cur_path)).getParent(); fill_tree(); } else if (evt.getKeyCode() == KeyEvent.VK_ENTER) { if (!"".equals(selected_file)) { //count_data(); read_data(); } else { TreePath path = tr_files.getSelectionPath(); if (path.getLastPathComponent().toString().equals(cur_path)) { cur_path = (new File(cur_path)).getParent(); } else { cur_path = cur_path + File.separator + path.getLastPathComponent().toString(); } fill_tree(); } } else if (evt.getKeyCode() == KeyEvent.VK_DELETE) { if (!"".equals(selected_file)) { String name = cur_path + File.separator + selected_file; if ((new File(name)).isFile()) { int dialogResult = JOptionPane.showConfirmDialog(null, "Selected file [" + selected_file + "] will be removed and not recoverable.", "Are you sure?", JOptionPane.YES_NO_OPTION); if (dialogResult == JOptionPane.YES_OPTION) { (new File(name)).delete(); fill_tree(); } } } else { JOptionPane.showMessageDialog(null, "For safety concern, removing folder is not supported.", "Information", JOptionPane.ERROR_MESSAGE); } } } }); tr_files.setCellRenderer(new MyTreeCellRenderer()); p_count.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); //tp_menu.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(ctrl1, "tab_read"); //tp_menu.getActionMap().put("tab_read", (Action) new ActionListenerImpl()); //tp_menu.setMnemonicAt(0, KeyEvent.VK_1); //tp_menu.setMnemonicAt(1, KeyEvent.VK_2); /*InputMap inputMap = tp_menu.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap actionMap = tp_menu.getActionMap(); KeyStroke ctrl1 = KeyStroke.getKeyStroke("ctrl 1"); inputMap.put(ctrl1, "tab_read"); actionMap.put("tab_read", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { tp_menu.setSelectedIndex(0); } }); KeyStroke ctrl2 = KeyStroke.getKeyStroke("ctrl 2"); inputMap.put(ctrl2, "tab_analyze"); actionMap.put("tab_analyze", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { tp_menu.setSelectedIndex(1); } });*/ config(); } catch (Exception e) { txt_count.setText(e.getMessage()); } }
From source file:edu.clemson.cs.nestbed.client.gui.TestbedManagerFrame.java
private void doExit() { int choice;/*from w w w . j av a 2 s. com*/ choice = JOptionPane.showConfirmDialog(this, "Do you wish to exit NESTbed?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (choice == JOptionPane.YES_OPTION) { log.fatal("Application shutdown per user request."); System.exit(0); } }
From source file:edu.mit.fss.examples.member.gui.PowerSubsystemPanel.java
/** * Export this panel's generation dataset. */// w w w .j a v a2s . c o m private void exportDataset() { if (JFileChooser.APPROVE_OPTION == fileChooser.showSaveDialog(this)) { File f = fileChooser.getSelectedFile(); if (!f.exists() || JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, "Overwrite existing file " + f.getName() + "?", "File Exists", JOptionPane.YES_NO_OPTION)) { logger.info("Exporting dataset to file " + f.getPath() + "."); try { BufferedWriter bw = Files.newBufferedWriter(Paths.get(f.getPath()), Charset.defaultCharset()); StringBuilder b = new StringBuilder(); b.append(" Generation\n").append("Time, Value\n"); for (int j = 0; j < generationSeries.getItemCount(); j++) { b.append(generationSeries.getTimePeriod(j).getStart().getTime()).append(", ") .append(generationSeries.getValue(j)).append("\n"); } bw.write(b.toString()); bw.close(); } catch (IOException e) { logger.error(e); } } } }
From source file:com.clank.launcher.swing.SwingHelper.java
/** * Asks the user a binary yes or no question. * * @param parentComponent the component/*from w ww . j av a 2 s .com*/ * @param message the message to display * @param title the title string for the dialog * @return whether 'yes' was selected */ public static boolean confirmDialog(final Component parentComponent, @NonNull final String message, @NonNull final String title) { if (SwingUtilities.isEventDispatchThread()) { return JOptionPane.showConfirmDialog(parentComponent, message, title, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; } else { // Use an AtomicBoolean to pass the result back from the // Event Dispatcher Thread final AtomicBoolean yesSelected = new AtomicBoolean(); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { yesSelected.set(confirmDialog(parentComponent, title, message)); } }); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } return yesSelected.get(); } }
From source file:com.massabot.codesender.utils.FirmwareUtils.java
public synchronized static void initialize() { System.out.println("Initializing firmware... ..."); File firmwareConfig = new File(SettingsFactory.getSettingsDirectory(), FIRMWARE_CONFIG_DIRNAME); // Create directory if it's missing. if (!firmwareConfig.exists()) { firmwareConfig.mkdirs();//from w w w. ja v a 2 s. c o m } FileSystem fileSystem = null; // Copy firmware config files. try { final String dir = "/resources/firmware_config/"; URI location = FirmwareUtils.class.getResource(dir).toURI(); Path myPath; if (location.getScheme().equals("jar")) { try { // In case the filesystem already exists. fileSystem = FileSystems.getFileSystem(location); } catch (FileSystemNotFoundException e) { // Otherwise create the new filesystem. fileSystem = FileSystems.newFileSystem(location, Collections.<String, String>emptyMap()); } myPath = fileSystem.getPath(dir); } else { myPath = Paths.get(location); } Stream<Path> files = Files.walk(myPath, 1); for (Path path : (Iterable<Path>) () -> files.iterator()) { System.out.println(path); final String name = path.getFileName().toString(); File fwConfig = new File(firmwareConfig, name); if (name.endsWith(".json")) { boolean copyFile = !fwConfig.exists(); ControllerSettings jarSetting = getSettingsForStream(Files.newInputStream(path)); // If the file is outdated... ask the user (once). if (fwConfig.exists()) { ControllerSettings current = getSettingsForStream(new FileInputStream(fwConfig)); boolean outOfDate = current.getVersion() < jarSetting.getVersion(); if (outOfDate && !userNotified && !overwriteOldFiles) { int result = NarrowOptionPane.showNarrowConfirmDialog(200, Localization.getString("settings.file.outOfDate.message"), Localization.getString("settings.file.outOfDate.title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); overwriteOldFiles = result == JOptionPane.OK_OPTION; userNotified = true; } if (overwriteOldFiles) { copyFile = true; jarSetting.getProcessorConfigs().Custom = current.getProcessorConfigs().Custom; } } // Copy file from jar to firmware_config directory. if (copyFile) { try { save(fwConfig, jarSetting); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } } } } } catch (Exception ex) { String errorMessage = String.format("%s %s", Localization.getString("settings.file.generalError"), ex.getLocalizedMessage()); GUIHelpers.displayErrorDialog(errorMessage); logger.log(Level.SEVERE, errorMessage, ex); } finally { if (fileSystem != null) { try { fileSystem.close(); } catch (IOException ex) { logger.log(Level.SEVERE, "Problem closing filesystem.", ex); } } } configFiles.clear(); for (File f : firmwareConfig.listFiles()) { try { ControllerSettings config = new Gson().fromJson(new FileReader(f), ControllerSettings.class); // ConfigLoader config = new ConfigLoader(f); configFiles.put(config.getName(), new ConfigTuple(config, f)); } catch (FileNotFoundException | JsonSyntaxException | JsonIOException ex) { GUIHelpers.displayErrorDialog("Unable to load configuration files: " + f.getAbsolutePath()); } } }
From source file:gdt.jgui.entity.fields.JFieldsEditor.java
/** * Get the context menu./*from ww w . j a v a2s . c o m*/ * @return the context menu. */ @Override public JMenu getContextMenu() { menu = new JMenu("Context"); menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { // System.out.println("FieldsEditor:getConextMenu:menu selected"); if (editCellItem != null) menu.remove(editCellItem); if (deleteItemsItem != null) menu.remove(deleteItemsItem); if (copyItem != null) menu.remove(copyItem); if (pasteItem != null) menu.remove(pasteItem); if (cutItem != null) menu.remove(cutItem); if (hasEditingCell()) { editCellItem = new JMenuItem("Edit item"); editCellItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { JTextEditor textEditor = new JTextEditor(); String locator$ = textEditor.getLocator(); locator$ = Locator.append(locator$, Entigrator.ENTIHOME, entihome$); locator$ = Locator.append(locator$, EntityHandler.ENTITY_KEY, entityKey$); String responseLocator$ = getEditCellLocator(); text$ = Locator.getProperty(responseLocator$, JTextEditor.TEXT); locator$ = Locator.append(locator$, JTextEditor.TEXT, text$); // System.out.println("FieldsEditor:edit cell:text="+text$); locator$ = Locator.append(locator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(responseLocator$)); JConsoleHandler.execute(console, locator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); menu.add(editCellItem); } if (hasSelectedRows()) { deleteItemsItem = new JMenuItem("Delete items"); deleteItemsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(JFieldsEditor.this, "Delete selected fields ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { deleteRows(); } } }); menu.add(deleteItemsItem); copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copy(false); } }); menu.add(copyItem); cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copy(true); } }); menu.add(cutItem); } if (hasFieldsToPaste()) { pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String[] sa = console.clipboard.getContent(); Properties locator; String type$; String sourceEntityKey$; Sack sourceEntity; String sourceEntihome$; Entigrator sourceEntigrator; for (String aSa : sa) { //System.out.println("FieldsEditor:paste:"+aSa); locator = Locator.toProperties(aSa); type$ = locator.getProperty(Locator.LOCATOR_TYPE); if (LOCATOR_TYPE_FIELD.equals(type$)) { String action$ = locator.getProperty(JRequester.REQUESTER_ACTION); String name$ = locator.getProperty(CELL_FIELD_NAME); String value$ = locator.getProperty(CELL_FIELD_VALUE); if (name$ != null) { if (ACTION_COPY_FIELDS.equals(action$)) entity.putElementItem("field", new Core(null, name$, value$)); if (ACTION_CUT_FIELDS.equals(action$)) { entity.putElementItem("field", new Core(null, name$, value$)); sourceEntihome$ = locator.getProperty(Entigrator.ENTIHOME); sourceEntigrator = console.getEntigrator(sourceEntihome$); sourceEntityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); sourceEntity = sourceEntigrator.getEntityAtKey(sourceEntityKey$); sourceEntity.removeElementItem("field", name$); sourceEntigrator.save(sourceEntity); } } } } entigrator.save(entity); Core[] ca = entity.elementGet("field"); replaceTable(ca); } catch (Exception ee) { LOGGER.info(ee.toString()); } } }); menu.add(pasteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); if (requesterResponseLocator$ != null) { try { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); responseLocator$ = Locator.append(responseLocator$, Entigrator.ENTIHOME, entihome$); responseLocator$ = Locator.append(responseLocator$, EntityHandler.ENTITY_KEY, entityKey$); // System.out.println("FieldsEditor:done.response locator="+responseLocator$); JConsoleHandler.execute(console, responseLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } else console.back(); } }); menu.add(doneItem); JMenuItem cancelItem = new JMenuItem("Cancel"); cancelItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console.back(); } }); menu.add(cancelItem); menu.addSeparator(); JMenuItem addItemItem = new JMenuItem("Add item"); addItemItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addRow(); } }); menu.add(addItemItem); if (postMenu != null) { //System.out.println("JFieldsEditor:postMenu="+postMenu.length); for (JMenuItem jmi : postMenu) menu.add(jmi); } //else // System.out.println("JFieldsEditor:postMenu empty"); return menu; }
From source file:au.org.ala.delta.intkey.ui.MultiStateInputDialog.java
@Override void handleBtnOKClicked() { int[] selectedIndicies = _list.getSelectedIndices(); // Show confirmation dialog if all of the states have been // selected./*from ww w . j a va2 s . co m*/ if (selectedIndicies.length == _list.getModel().getSize()) { int dlgSelection = JOptionPane.showConfirmDialog(this, selectionConfirmationMessage, selectionConfirmationTitle, JOptionPane.YES_NO_OPTION); if (dlgSelection == JOptionPane.NO_OPTION) { return; } } for (int i : selectedIndicies) { _inputData.add(i + 1); } setVisible(false); }
From source file:jgnash.ui.report.compiled.PayeePieChart.java
private JPanel createPanel() { JButton refreshButton = new JButton(rb.getString("Button.Refresh")); JButton addFilterButton = new JButton(rb.getString("Button.AddFilter")); final JButton saveButton = new JButton(rb.getString("Button.SaveFilters")); JButton deleteFilterButton = new JButton(rb.getString("Button.DeleteFilter")); JButton clearPrefButton = new JButton(rb.getString("Button.MasterDelete")); filterCombo = new JComboBox<>(); startField = new DatePanel(); endField = new DatePanel(); txtAddFilter = new TextField(); filterList = new ArrayList<>(); filtersChanged = false;//from w ww . j av a 2 s .c o m useFilters = new JCheckBox(rb.getString("Label.UseFilters")); useFilters.setSelected(true); showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues")); combo = AccountListComboBox.getFullInstance(); final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now().minusYears(1)); long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart)); startField.setDate(DateUtils.asLocalDate(start)); currentAccount = combo.getSelectedAccount(); PieDataset[] data = createPieDataSet(currentAccount); JFreeChart chartCredit = createPieChart(currentAccount, data, 0); chartPanelCredit = new ChartPanel(chartCredit, true, true, true, false, true); // (chart, properties, save, print, zoom, tooltips) JFreeChart chartDebit = createPieChart(currentAccount, data, 1); chartPanelDebit = new ChartPanel(chartDebit, true, true, true, false, true); FormLayout layout = new FormLayout("p, $lcgap, 70dlu, 8dlu, p, $lcgap, 70dlu, $ugap, p, $lcgap:g, left:p", "d, $rgap, d, $ugap, f:p:g, $rgap, d"); DefaultFormBuilder builder = new DefaultFormBuilder(layout); layout.setRowGroups(new int[][] { { 1, 3 } }); // row 1 builder.append(combo, 9); builder.append(useFilters); builder.nextLine(); builder.nextLine(); // row 3 builder.append(rb.getString("Label.StartDate"), startField); builder.append(rb.getString("Label.EndDate"), endField); builder.append(refreshButton); builder.append(showPercentCheck); builder.nextLine(); builder.nextLine(); // row 5 FormLayout subLayout = new FormLayout("180dlu:g, 1dlu, 180dlu:g", "f:180dlu:g"); DefaultFormBuilder subBuilder = new DefaultFormBuilder(subLayout); subBuilder.append(chartPanelCredit); subBuilder.append(chartPanelDebit); builder.append(subBuilder.getPanel(), 11); builder.nextLine(); builder.nextLine(); // row 7 builder.append(txtAddFilter, 3); builder.append(addFilterButton, 3); builder.append(saveButton); builder.nextLine(); // row builder.append(filterCombo, 3); builder.append(deleteFilterButton, 3); builder.append(clearPrefButton); builder.nextLine(); JPanel panel = builder.getPanel(); combo.addActionListener(e -> { Account newAccount = combo.getSelectedAccount(); if (filtersChanged) { int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.SaveFilters"), "Warning", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { saveButton.doClick(); } } filtersChanged = false; String[] list = POUND_DELIMITER_PATTERN.split(pref.get(FILTER_TAG + newAccount.hashCode(), "")); filterList.clear(); for (String filter : list) { if (!filter.isEmpty()) { //System.out.println("Adding filter: #" + filter + "#"); filterList.add(filter); } } refreshFilters(); setCurrentAccount(newAccount); pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate())); }); refreshButton.addActionListener(e -> { setCurrentAccount(currentAccount); pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate())); }); clearPrefButton.addActionListener(e -> { int result = JOptionPane.showConfirmDialog(null, rb.getString("Message.MasterDelete"), "Warning", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { try { pref.clear(); } catch (Exception ex) { System.out.println("Exception clearing preferences" + ex); } } }); saveButton.addActionListener(e -> { final StringBuilder sb = new StringBuilder(); for (String filter : filterList) { sb.append(filter); sb.append('#'); } //System.out.println("Save = " + FILTER_TAG + currentAccount.hashCode() + " = " + sb.toString()); pref.put(FILTER_TAG + currentAccount.hashCode(), sb.toString()); filtersChanged = false; }); addFilterButton.addActionListener(e -> { String newFilter = txtAddFilter.getText(); filterList.remove(newFilter); if (!newFilter.isEmpty()) { filterList.add(newFilter); filtersChanged = true; txtAddFilter.setText(""); } refreshFilters(); }); deleteFilterButton.addActionListener(e -> { if (!filterList.isEmpty()) { String filter = (String) filterCombo.getSelectedItem(); filterList.remove(filter); filtersChanged = true; } refreshFilters(); }); useFilters.addActionListener(e -> setCurrentAccount(currentAccount)); showPercentCheck.addActionListener(e -> { ((PiePlot) chartPanelCredit.getChart().getPlot()) .setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels); ((PiePlot) chartPanelDebit.getChart().getPlot()) .setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels); }); return panel; }
From source file:de.atomfrede.tools.evalutation.ui.AppWindow.java
/** * Display a simple dialog, so the user does not close the application by * accident/*from ww w . ja v a 2 s. com*/ * * @return */ private int reallyExit() { Object[] options = { Messages.getString("AppWindow.11"), Messages.getString("AppWindow.12") }; //$NON-NLS-1$ //$NON-NLS-2$ int result = JOptionPane.showOptionDialog(frame, Messages.getString("AppWindow.13"), //$NON-NLS-1$ Messages.getString("AppWindow.14"), JOptionPane.YES_NO_OPTION, //$NON-NLS-1$ JOptionPane.WARNING_MESSAGE, Icons.IC_DIALOG_WARNING_LARGE, options, options[1]); return result; }