List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE
int QUESTION_MESSAGE
To view the source code for javax.swing JOptionPane QUESTION_MESSAGE.
Click Source Link
From source file:gdt.jgui.entity.fields.JFieldsEditor.java
/** * Get the context menu./*www. j av a 2 s .com*/ * @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:DialogDemo.java
/** Creates the panel shown by the first tab. */ private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton showItButton = null;/*from ww w . j a v a 2 s .c om*/ final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("OK (in the L&F's words)"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("Yes/No (in the L&F's words)"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("Yes/No " + "(in the programmer's words)"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton("Yes/No/Cancel " + "(in the programmer's words)"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } radioButtons[0].setSelected(true); showItButton = new JButton("Show it!"); showItButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); // ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green."); // yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("Ewww!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("Me neither!"); } else { setLabel("Come on -- tell me!"); } // yes/no (not in those words) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No way!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like green eggs and ham?", "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("You're kidding!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("I don't like them, either."); } else { setLabel("Come on -- 'fess up!"); } // yes/no/cancel (not in those words) } else if (command == yncCommand) { Object[] options = { "Yes, please", "No, thanks", "No eggs, no ham!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like some green eggs to go " + "with that ham?", "A Silly Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Here you go: green eggs and ham!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("OK, just the ham, then."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to eat them!"); } else { setLabel("Please tell me what you want!"); } } return; } }); return createPane(simpleDialogDesc + ":", radioButtons, showItButton); }
From source file:com.pdk.DisassembleElfAction.java
private void showList() { Project project = NetbeansUtil.getPeterProject(); File dir = new File(project.getProjectDirectory().getPath()); Collection<File> files = FileUtils.listFiles(dir, new String[] { "o", "exe" }, true); if (files.isEmpty()) { return;// w ww. j a va 2 s . co m } files.add(new File(dir.getAbsolutePath() + File.separator + "kernel/kernel")); Iterator<File> iter = files.iterator(); while (iter.hasNext()) { File file = iter.next(); String relativePath = file.getAbsolutePath().substring(dir.getAbsolutePath().length()); if (relativePath.startsWith("/toolchain/")) { iter.remove(); } } String[] arr = new String[files.size()]; iter = files.iterator(); int x = 0; while (iter.hasNext()) { File file = iter.next(); String relativePath = file.getAbsolutePath().substring(dir.getAbsolutePath().length() + 1); arr[x] = relativePath; x++; } Arrays.sort(arr, new Comparator<String>() { @Override public int compare(String o1, String o2) { if (o1.startsWith("kernel/")) { return -1; } else if (o1.startsWith("kernel/")) { return 1; } else { return o1.compareTo(o2); } } }); String file = (String) JOptionPane.showInputDialog(null, null, "Please select an elf file", JOptionPane.QUESTION_MESSAGE, null, arr, arr[0]); if (file != null) { try { Object[] options = { "Disasm", "Sections", "Cancel" }; int n = JOptionPane.showOptionDialog(null, "Please select", "Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == 2) { return; } String command2 = null; if (n == 0) { command2 = "i586-peter-elf-objdump -S"; } else if (n == 1) { command2 = "i586-peter-elf-readelf -S"; } if (command2 == null) { return; } final String command = "/toolchain/bin/" + command2 + " " + file; process = Runtime.getRuntime().exec(command, null, dir); InputStreamReader isr = new InputStreamReader(process.getInputStream()); final BufferedReader br = new BufferedReader(isr, 1024 * 1024 * 50); final JProgressBarDialog d = new JProgressBarDialog(new JFrame(), "i586-peter-elf-objdump -S " + file, true); d.progressBar.setIndeterminate(true); d.progressBar.setStringPainted(true); d.progressBar.setString("Updating"); d.addCancelEventListener(this); Thread longRunningThread = new Thread() { public void run() { try { lines = new StringBuilder(); String line; stop = false; while (!stop && (line = br.readLine()) != null) { d.progressBar.setString(line); lines.append(line).append("\n"); } DisassembleDialog disassembleDialog = new DisassembleDialog(); disassembleDialog.setTitle(command); if (((DefaultComboBoxModel) disassembleDialog.enhancedTextArea1.fontComboBox.getModel()) .getIndexOf("Monospaced") != -1) { disassembleDialog.enhancedTextArea1.fontComboBox.setSelectedItem("Monospaced"); } if (((DefaultComboBoxModel) disassembleDialog.enhancedTextArea1.fontComboBox.getModel()) .getIndexOf("Monospaced.plain") != -1) { disassembleDialog.enhancedTextArea1.fontComboBox .setSelectedItem("Monospaced.plain"); } disassembleDialog.enhancedTextArea1.fontComboBox.setSelectedItem("Monospaced"); disassembleDialog.enhancedTextArea1.setText(lines.toString()); disassembleDialog.setVisible(true); } catch (Exception ex) { ModuleLib.log(CommonLib.printException(ex)); } } }; d.thread = longRunningThread; d.setVisible(true); } catch (Exception ex) { ModuleLib.log(CommonLib.printException(ex)); } } }
From source file:com.edduarte.protbox.ui.windows.RestoreFileWindow.java
private RestoreFileWindow(final PReg registry) { super();/*from ww w .j a va 2 s .c om*/ setLayout(null); final JTextField searchField = new JTextField(); searchField.setLayout(null); searchField.setBounds(2, 2, 301, 26); searchField.setBorder(new LineBorder(Color.lightGray)); searchField.setFont(Constants.FONT); add(searchField); final JLabel noBackupFilesLabel = new JLabel("<html>No backups files were found!<br><br>" + "<font color=\"gray\">If you think there is a problem with the<br>" + "backup system, please create an issue here:<br>" + "<a href=\"#\">https://github.com/com.edduarte/protbox/issues</a></font></html>"); noBackupFilesLabel.setLayout(null); noBackupFilesLabel.setBounds(20, 50, 300, 300); noBackupFilesLabel.setFont(Constants.FONT.deriveFont(14f)); noBackupFilesLabel.addMouseListener((OnMouseClick) e -> { String urlPath = "https://github.com/com.edduarte/protbox/issues"; try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(new URI(urlPath)); } else { if (SystemUtils.IS_OS_WINDOWS) { Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + urlPath); } else { java.util.List<String> browsers = Lists.newArrayList("firefox", "opera", "safari", "mozilla", "chrome"); for (String browser : browsers) { if (Runtime.getRuntime().exec(new String[] { "which", browser }).waitFor() == 0) { Runtime.getRuntime().exec(new String[] { browser, urlPath }); break; } } } } } catch (Exception ex) { ex.printStackTrace(); } }); DefaultMutableTreeNode rootTreeNode = registry.buildEntryTree(); final JTree tree = new JTree(rootTreeNode); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); if (rootTreeNode.getChildCount() == 0) { searchField.setEnabled(false); add(noBackupFilesLabel); } expandTree(tree); tree.setLayout(null); tree.setRootVisible(false); tree.setEditable(false); tree.setCellRenderer(new SearchableTreeCellRenderer(searchField)); searchField.addKeyListener((OnKeyReleased) e -> { // update and expand tree DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.nodeStructureChanged((TreeNode) model.getRoot()); expandTree(tree); }); final JScrollPane scroll = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setBorder(new DropShadowBorder()); scroll.setBorder(new LineBorder(Color.lightGray)); scroll.setBounds(2, 30, 334, 360); add(scroll); JLabel close = new JLabel(new ImageIcon(Constants.getAsset("close.png"))); close.setLayout(null); close.setBounds(312, 7, 18, 18); close.setFont(Constants.FONT); close.setForeground(Color.gray); close.addMouseListener((OnMouseClick) e -> dispose()); add(close); final JLabel permanentDeleteButton = new JLabel(new ImageIcon(Constants.getAsset("permanent.png"))); permanentDeleteButton.setLayout(null); permanentDeleteButton.setBounds(91, 390, 40, 39); permanentDeleteButton.setBackground(Color.black); permanentDeleteButton.setEnabled(false); permanentDeleteButton.addMouseListener((OnMouseClick) e -> { if (permanentDeleteButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (JOptionPane.showConfirmDialog(null, "Are you sure you wish to permanently delete '" + entry.realName() + "'?\nThis file and its " + "backup copies will be deleted immediately. You cannot undo this action.", "Confirm Cancel", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { registry.permanentDelete(entry); dispose(); RestoreFileWindow.getInstance(registry); } else { setVisible(true); } } }); add(permanentDeleteButton); final JLabel configBackupsButton = new JLabel(new ImageIcon(Constants.getAsset("config.png"))); configBackupsButton.setLayout(null); configBackupsButton.setBounds(134, 390, 40, 39); configBackupsButton.setBackground(Color.black); configBackupsButton.setEnabled(false); configBackupsButton.addMouseListener((OnMouseClick) e -> { if (configBackupsButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; JFrame frame = new JFrame("Choose backup policy"); Object option = JOptionPane.showInputDialog(frame, "Choose below the backup policy for this file:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, PbxFile.BackupPolicy.values(), pbxFile.getBackupPolicy()); if (option == null) { setVisible(true); return; } PbxFile.BackupPolicy pickedPolicy = PbxFile.BackupPolicy.valueOf(option.toString()); pbxFile.setBackupPolicy(pickedPolicy); } setVisible(true); } }); add(configBackupsButton); final JLabel restoreBackupButton = new JLabel(new ImageIcon(Constants.getAsset("restore.png"))); restoreBackupButton.setLayout(null); restoreBackupButton.setBounds(3, 390, 85, 39); restoreBackupButton.setBackground(Color.black); restoreBackupButton.setEnabled(false); restoreBackupButton.addMouseListener((OnMouseClick) e -> { if (restoreBackupButton.isEnabled()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); PbxEntry entry = (PbxEntry) node.getUserObject(); if (entry instanceof PbxFolder) { registry.restoreFolderFromEntry((PbxFolder) entry); } else if (entry instanceof PbxFile) { PbxFile pbxFile = (PbxFile) entry; java.util.List<String> snapshots = pbxFile.snapshotsToString(); if (snapshots.isEmpty()) { setVisible(true); return; } JFrame frame = new JFrame("Choose backup"); Object option = JOptionPane.showInputDialog(frame, "Choose below what backup snapshot would you like restore:", "Choose backup", JOptionPane.QUESTION_MESSAGE, null, snapshots.toArray(), snapshots.get(0)); if (option == null) { setVisible(true); return; } int pickedIndex = snapshots.indexOf(option.toString()); registry.restoreFileFromEntry((PbxFile) entry, pickedIndex); } dispose(); } }); add(restoreBackupButton); tree.addMouseListener((OnMouseClick) e -> { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node != null) { PbxEntry entry = (PbxEntry) node.getUserObject(); if ((entry instanceof PbxFolder && entry.areNativeFilesDeleted())) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(false); } else if (entry instanceof PbxFile) { permanentDeleteButton.setEnabled(true); restoreBackupButton.setEnabled(true); configBackupsButton.setEnabled(true); } else { permanentDeleteButton.setEnabled(false); restoreBackupButton.setEnabled(false); configBackupsButton.setEnabled(false); } } }); final JLabel cancel = new JLabel(new ImageIcon(Constants.getAsset("cancel.png"))); cancel.setLayout(null); cancel.setBounds(229, 390, 122, 39); cancel.setBackground(Color.black); cancel.addMouseListener((OnMouseClick) e -> dispose()); add(cancel); addWindowFocusListener(new WindowFocusListener() { private boolean gained = false; @Override public void windowGainedFocus(WindowEvent e) { gained = true; } @Override public void windowLostFocus(WindowEvent e) { if (gained) { dispose(); } } }); setSize(340, 432); setUndecorated(true); getContentPane().setBackground(Color.white); setResizable(false); getRootPane().setBorder(BorderFactory.createLineBorder(new Color(100, 100, 100))); Utils.setComponentLocationOnCenter(this); setVisible(true); }
From source file:es.emergya.ui.gis.popups.SaveGPXDialog.java
private SaveGPXDialog(final List<Layer> capas) { super("Consulta de Posiciones GPS"); setResizable(false);//from w w w. ja va2s.c o m setAlwaysOnTop(true); try { setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getIconImage()); } catch (Throwable e) { LOG.error("There is no icon image", e); } this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); JPanel dialogo = new JPanel(new BorderLayout()); dialogo.setBackground(Color.WHITE); dialogo.setBorder(new EmptyBorder(10, 10, 10, 10)); JPanel central = new JPanel(new FlowLayout()); central.setOpaque(false); final JTextField nombre = new JTextField(15); nombre.setEditable(false); central.add(nombre); final JButton button = new JButton("Examinar...", LogicConstants.getIcon("button_nuevo")); central.add(button); final JButton aceptar = new JButton("Guardar", LogicConstants.getIcon("button_save")); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); if (fileChooser.showSaveDialog(SaveGPXDialog.this) == JFileChooser.APPROVE_OPTION) { nombre.setText(fileChooser.getSelectedFile().getAbsolutePath()); aceptar.setEnabled(true); } } }); dialogo.add(central, BorderLayout.CENTER); JPanel botones = new JPanel(new FlowLayout()); botones.setOpaque(false); aceptar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String base_url = nombre.getText() + "_"; for (Layer layer : capas) { if (layer instanceof GpxLayer) { GpxLayer gpxLayer = (GpxLayer) layer; File f = new File(base_url + gpxLayer.name + ".gpx"); boolean sobreescribir = !f.exists(); try { while (!sobreescribir) { String original = f.getCanonicalPath(); f = checkFileOverwritten(nombre, f); sobreescribir = !f.exists() || original.equals(f.getCanonicalPath()); } } catch (NullPointerException t) { log.debug("Cancelando creacion de fichero: " + t); sobreescribir = false; } catch (Throwable t) { log.error("Error comprobando la sobreescritura", t); sobreescribir = false; } if (sobreescribir) { try { f.createNewFile(); } catch (IOException e1) { log.error(e1, e1); } if (!(f.isFile() && f.canWrite())) JOptionPane.showMessageDialog(SaveGPXDialog.this, "No tengo permiso para escribir en " + f.getAbsolutePath()); else { try { OutputStream out = new FileOutputStream(f); GpxWriter writer = new GpxWriter(out); writer.write(gpxLayer.data); out.close(); } catch (Throwable t) { log.error("Error al escribir el gpx", t); JOptionPane.showMessageDialog(SaveGPXDialog.this, "Ocurri un error al escribir en " + f.getAbsolutePath()); } } } else log.error("Por errores anteriores no se escribio el fichero"); } else log.error("Una de las capas no era gpx: " + layer.name); } SaveGPXDialog.this.dispose(); } private File checkFileOverwritten(final JTextField nombre, File f) throws Exception { String nueva = JOptionPane.showInputDialog(nombre, i18n.getString("savegpxdialog.overwrite"), "Sobreescribir archivo", JOptionPane.QUESTION_MESSAGE, null, null, f.getCanonicalPath()) .toString(); log.debug("Nueva ruta: " + nueva); return new File(nueva); } }); JButton cancelar = new JButton("Cancelar", LogicConstants.getIcon("button_cancel")); cancelar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SaveGPXDialog.this.dispose(); } }); aceptar.setEnabled(false); botones.add(aceptar); botones.add(cancelar); dialogo.add(botones, BorderLayout.SOUTH); add(dialogo); setPreferredSize(new Dimension(300, 200)); pack(); int x; int y; Container myParent; try { myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getContentPane(); java.awt.Point topLeft = myParent.getLocationOnScreen(); Dimension parentSize = myParent.getSize(); Dimension mySize = getSize(); if (parentSize.width > mySize.width) x = ((parentSize.width - mySize.width) / 2) + topLeft.x; else x = topLeft.x; if (parentSize.height > mySize.height) y = ((parentSize.height - mySize.height) / 2) + topLeft.y; else y = topLeft.y; setLocation(x, y); } catch (Throwable e1) { LOG.error("There is no basic window!", e1); } this.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { nombre.setText(""); nombre.repaint(); } @Override public void windowClosing(WindowEvent e) { nombre.setText(""); nombre.repaint(); } }); }
From source file:com.ebixio.virtmus.stats.StatsLogger.java
/** * Ask the user if they want to help by uploading stats logs. *//*from w w w .j ava2 s . com*/ private UploadStats promptUser() { String yes = NbBundle.getMessage(StatsLogger.class, "BTN_Yes"), maybeLater = NbBundle.getMessage(StatsLogger.class, "BTN_MaybeLater"), never = NbBundle.getMessage(StatsLogger.class, "BTN_Never"); Icon icon = ImageUtilities.loadImageIcon("com/ebixio/virtmus/resources/VirtMus32x32.png", false); int userChoice = JOptionPane.showOptionDialog(null, NbBundle.getMessage(StatsLogger.class, "MSG_Text"), NbBundle.getMessage(StatsLogger.class, "MSG_Title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon, new Object[] { yes, maybeLater, never }, yes); switch (userChoice) { case 0: return UploadStats.Yes; case 2: return UploadStats.No; case 1: return UploadStats.Maybe; case -1: // User closed the dialog. Leave it as "Unknown". default: return UploadStats.Unknown; } }
From source file:edu.harvard.i2b2.adminTool.dataModel.PatientIDConversionFactory.java
private String getKey() { String path = null;/*from w w w . ja v a 2 s .c o m*/ String key = UserInfoBean.getInstance().getKey(); if (key == null) { if ((path = getNoteKeyDrive()) == null) { Object[] possibleValues = { "Type in the key", "Browse to find the file containing the key" }; String selectedValue = (String) JOptionPane.showInputDialog(null, "You have selected an item associated with a report\n" + "which contains protected health information.\n" + "You need a decryption key to perform this operation.\n" + "How would you like to enter the key?\n" + "(If the key is on a floppy disk, insert the disk then\n select " + "\"Browse to find the file containing the key\")", "Notes Viewer", JOptionPane.QUESTION_MESSAGE, null, possibleValues, possibleValues[0]); if (selectedValue == null) { return "Not a valid key"; } if (selectedValue.equalsIgnoreCase("Type in the key")) { key = JOptionPane.showInputDialog(this, "Please input the decryption key"); if (key == null) { return "Not a valid key"; } } else { JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.CANCEL_OPTION) { return "Not a valid key"; } File f = null; if (returnVal == JFileChooser.APPROVE_OPTION) { f = chooser.getSelectedFile(); System.out.println("Open this file: " + f.getAbsolutePath()); BufferedReader in = null; try { in = new BufferedReader(new FileReader(f.getAbsolutePath())); String line = null; while ((line = in.readLine()) != null) { if (line.length() > 0) { key = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")); } } } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (Exception e) { e.printStackTrace(); } } } } } } else { System.out.println("Found key file: " + path); BufferedReader in = null; try { in = new BufferedReader(new FileReader(path)); String line = null; while ((line = in.readLine()) != null) { if (line.length() > 0) { key = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\"")); } } } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (Exception e) { e.printStackTrace(); } } } } } if (key == null) { return null; } else { UserInfoBean.getInstance().setKey(key); } return key; }
From source file:it.unibas.spicygui.controllo.mapping.ActionGenerateAndTranslate.java
private void checkForPKConstraints(MappingTask mappingTask, HashSet<String> pkTableNames, int scenarioNo) throws DAOException { if (!pkTableNames.isEmpty()) { NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Confirmation( NbBundle.getMessage(Costanti.class, Costanti.MESSAGE_PK_TABLES), DialogDescriptor.YES_NO_OPTION); DialogDisplayer.getDefault().notify(notifyDescriptor); if (notifyDescriptor.getValue().equals(NotifyDescriptor.YES_OPTION)) { String[] format = { NbBundle.getMessage(Costanti.class, Costanti.OUTPUT_TYPE_CSV), NbBundle.getMessage(Costanti.class, Costanti.OUTPUT_TYPE_JSON) }; int formatResponse = JOptionPane.showOptionDialog(null, NbBundle.getMessage(Costanti.class, Costanti.MESSAGE_PK_OUTPUT), NbBundle.getMessage(Costanti.class, Costanti.PK_OUTPUT_TITLE), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, format, format[0]); if (formatResponse != JOptionPane.CLOSED_OPTION) { JFileChooser chooser = vista.getFileChooserSalvaFolder(); File file;/*ww w .ja va 2 s . c o m*/ int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(Costanti.class, Costanti.EXPORT)); if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (formatResponse == 0) { DAOCsv daoCsv = new DAOCsv(); daoCsv.exportPKConstraintCSVinstances(mappingTask, pkTableNames, file.getAbsolutePath(), scenarioNo); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK))); } else if (formatResponse == 1) { DAOJson daoJson = new DAOJson(); daoJson.exportPKConstraintJsoninstances(mappingTask, pkTableNames, file.getAbsolutePath(), scenarioNo); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.EXPORT_COMPLETED_OK))); } } } } } }
From source file:com.igormaznitsa.sciareto.ui.tree.ExplorerTree.java
private void addChildTo(@Nonnull final NodeFileOrFolder folder, @Nullable final String extension) { String fileName = JOptionPane.showInputDialog(Main.getApplicationFrame(), extension == null ? "Folder name" : "File name", extension == null ? "New folder" : "New " + extension.toUpperCase(Locale.ENGLISH) + " file", JOptionPane.QUESTION_MESSAGE); if (fileName != null) { fileName = fileName.trim();/*from ww w . j a v a 2 s . c om*/ if (NodeProjectGroup.FILE_NAME.matcher(fileName).matches()) { if (extension != null) { final String providedExtension = FilenameUtils.getExtension(fileName); if (!extension.equalsIgnoreCase(providedExtension)) { fileName += '.' + extension; } } final File file = new File(folder.makeFileForNode(), fileName); if (file.exists()) { DialogProviderManager.getInstance().getDialogProvider() .msgError("File '" + fileName + "' already exists!"); return; } boolean ok = false; if (extension == null) { if (!file.mkdirs()) { LOGGER.error("Can't create folder"); DialogProviderManager.getInstance().getDialogProvider() .msgError("Can't create folder '" + fileName + "'!"); } else { ok = true; } } else { switch (extension) { case "mmd": { final MindMap model = new MindMap(null, true); try { FileUtils.write(file, model.write(new StringWriter()).toString(), "UTF-8"); ok = true; } catch (IOException ex) { LOGGER.error("Can't create MMD file", ex); DialogProviderManager.getInstance().getDialogProvider() .msgError("Can't create mind map '" + fileName + "'!"); } } break; case "txt": { try { FileUtils.write(file, "", "UTF-8"); ok = true; } catch (IOException ex) { LOGGER.error("Can't create TXT file", ex); DialogProviderManager.getInstance().getDialogProvider() .msgError("Can't create txt file '" + fileName + "'!"); } } break; default: throw new Error("Unexpected extension : " + extension); } } if (ok) { getCurrentGroup().addChild(folder, file); context.openFileAsTab(file); context.focusInTree(file); } } else { DialogProviderManager.getInstance().getDialogProvider().msgError("Illegal file name!"); } } }
From source file:com._17od.upm.gui.DatabaseActions.java
public void changeMasterPassword() throws IOException, ProblemReadingDatabaseFile, CryptoException, PasswordDatabaseException, TransportException { if (getLatestVersionOfDatabase()) { //The first task is to get the current master password boolean passwordCorrect = false; boolean okClicked = true; do {//from w w w .j av a2s . com char[] password = askUserForPassword(Translator.translate("enterDatabasePassword")); if (password == null) { okClicked = false; } else { try { dbPers.load(database.getDatabaseFile(), password); passwordCorrect = true; } catch (InvalidPasswordException e) { JOptionPane.showMessageDialog(mainWindow, Translator.translate("incorrectPassword")); } } } while (!passwordCorrect && okClicked); //If the master password was entered correctly then the next step is to get the new master password if (passwordCorrect == true) { final JPasswordField masterPassword = new JPasswordField(""); boolean passwordsMatch = false; Object buttonClicked; //Ask the user for the new master password //This loop will continue until the two passwords entered match or until the user hits the cancel button do { JPasswordField confirmedMasterPassword = new JPasswordField(""); JOptionPane pane = new JOptionPane( new Object[] { Translator.translate("enterNewMasterPassword"), masterPassword, Translator.translate("confirmation"), confirmedMasterPassword }, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dialog = pane.createDialog(mainWindow, Translator.translate("changeMasterPassword")); dialog.addWindowFocusListener(new WindowAdapter() { public void windowGainedFocus(WindowEvent e) { masterPassword.requestFocusInWindow(); } }); dialog.show(); buttonClicked = pane.getValue(); if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION))) { if (!Arrays.equals(masterPassword.getPassword(), confirmedMasterPassword.getPassword())) { JOptionPane.showMessageDialog(mainWindow, Translator.translate("passwordsDontMatch")); } else { passwordsMatch = true; } } } while (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && !passwordsMatch); //If the user clicked OK and the passwords match then change the database password if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && passwordsMatch) { this.dbPers.getEncryptionService().initCipher(masterPassword.getPassword()); saveDatabase(); } } } }