List of usage examples for javax.swing JOptionPane showOptionDialog
@SuppressWarnings("deprecation") public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException
initialValue
parameter and the number of choices is determined by the optionType
parameter. From source file:ro.nextreports.designer.wizpublish.PublishFileWizardPanel.java
private boolean overwrite(JDialog parent, String name, int foundType) { Object[] options = { I18NSupport.getString("report.util.yes"), I18NSupport.getString("report.util.no") }; String type;/*from w ww. j a v a 2 s. co m*/ if (foundType == EntityConstants.REPORT_FOUND) { type = I18NSupport.getString("report"); } else { type = I18NSupport.getString("chart"); } int option = JOptionPane.showOptionDialog(parent, I18NSupport.getString("wizard.publish.overwrite", type, name), I18NSupport.getString("report.util.confirm"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); return (option == JOptionPane.YES_OPTION); }
From source file:savant.view.swing.BookmarkSheet.java
public BookmarkSheet(Container c) { // set the layout of the data sheet c.setLayout(new BorderLayout()); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); /**/*from w w w . j av a 2 s. c o m*/ * Create a toolbar. */ JMenuBar toolbar = new JMenuBar(); toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS)); c.add(toolbar, BorderLayout.NORTH); JButton previousButton = new JButton(); previousButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.UP)); previousButton.setToolTipText("Go to previous bookmark [ Ctrl+( ]"); previousButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); previousButton.putClientProperty("JButton.segmentPosition", "first"); previousButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { goToPreviousBookmark(); } }); toolbar.add(previousButton); JButton nextButton = new JButton(); nextButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.DOWN)); nextButton.setToolTipText("Go to next bookmark [ Ctrl+) ]"); nextButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); nextButton.putClientProperty("JButton.segmentPosition", "last"); nextButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { goToNextBookmark(); } }); toolbar.add(nextButton); JButton goButton = new JButton("Go"); goButton.setToolTipText("Go to selected bookmark"); goButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); goButton.putClientProperty("JButton.segmentPosition", "only"); goButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { goToSelectedBookmark(); } }); toolbar.add(goButton); toolbar.add(Box.createGlue()); addButton = new JButton(); addButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.BKMK_ADD)); addButton.setToolTipText("Add bookmark for current range"); addButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); addButton.putClientProperty("JButton.segmentPosition", "first"); addButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { BookmarkController fc = BookmarkController.getInstance(); fc.addCurrentRangeToBookmarks(); } }); toolbar.add(addButton); JButton deleteButton = new JButton(); deleteButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.BKMK_RM)); deleteButton.setToolTipText("Delete selected bookmarks"); deleteButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); deleteButton.putClientProperty("JButton.segmentPosition", "last"); deleteButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { BookmarkController fc = BookmarkController.getInstance(); int[] selectedRows = table.getSelectedRows(); Arrays.sort(selectedRows); boolean delete = false; if (selectedRows.length > 0 && confirmDelete) { Object[] options = { "Yes", "No", "Yes, don't ask again" }; JLabel message = new JLabel( "Are you sure you want to delete " + selectedRows.length + " item(s)?"); message.setPreferredSize(new Dimension(300, 20)); int confirmDeleteDialog = JOptionPane.showOptionDialog(DialogUtils.getMainWindow(), message, "Confirm Delete", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (confirmDeleteDialog == 0) { delete = true; } else if (confirmDeleteDialog == 2) { delete = true; confirmDelete = false; } } else if (selectedRows.length > 0 && !confirmDelete) { delete = true; } if (delete) { for (int i = selectedRows.length - 1; i >= 0; i--) { fc.removeBookmark(selectedRows[i]); } } } }); toolbar.add(deleteButton); toolbar.add(Box.createGlue()); JButton loadButton = new JButton(); loadButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.OPEN)); loadButton.setToolTipText("Load bookmarks from file"); loadButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); loadButton.putClientProperty("JButton.segmentPosition", "first"); loadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loadBookmarks(table); } }); toolbar.add(loadButton); JButton saveButton = new JButton(); saveButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SAVE)); saveButton.setToolTipText("Save bookmarks to file"); saveButton.putClientProperty("JButton.buttonType", "segmentedRoundRect"); saveButton.putClientProperty("JButton.segmentPosition", "last"); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveBookmarks(table); } }); toolbar.add(saveButton); // create a table (the most important component) table = new JTable(new BookmarksTableModel()); table.setAutoCreateRowSorter(true); table.setFillsViewportHeight(true); table.setShowGrid(true); table.setGridColor(Color.gray); //table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); // add the table and its header to the subpanel c.add(table.getTableHeader()); add(table); final JScrollPane sp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); sp.setWheelScrollingEnabled(false); sp.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { sp.getVerticalScrollBar().setValue(sp.getVerticalScrollBar().getValue() + e.getUnitsToScroll() * 2); } }); c.add(sp); // add glue to fill the remaining space add(Box.createGlue()); }
From source file:savant.view.swing.BookmarkSheet.java
private void loadBookmarks(JTable table) { final BookmarksTableModel btm = (BookmarksTableModel) table.getModel(); List<Bookmark> bookmarks = btm.getData(); if (bookmarks.size() > 0) { String message = "Clear existing bookmarks?"; String title = "Clear Bookmarks"; // display the JOptionPane showConfirmDialog int reply = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION); if (reply == JOptionPane.YES_OPTION) { btm.clearData();// w w w .java2s . c om BookmarkController.getInstance().clearBookmarks(); } } final File selectedFile = DialogUtils.chooseFileForOpen("Load Bookmarks", null, null); // set the genome if (selectedFile != null) { int result = JOptionPane.showOptionDialog(null, "Would you like to add padding to each bookmark range?", "Add a margin?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); final boolean addMargin = (result == JOptionPane.YES_OPTION); Window w = SwingUtilities.getWindowAncestor(BookmarkSheet.this); JOptionPane optionPane = new JOptionPane( "<html>Loading bookmarks from file.<br>This may take a moment.</html>", JOptionPane.INFORMATION_MESSAGE, JOptionPane.CANCEL_OPTION); final JDialog dialog = new JDialog(w, "Loading Bookmarks", Dialog.ModalityType.MODELESS); dialog.setContentPane(optionPane); dialog.pack(); dialog.setLocationRelativeTo(w); dialog.setVisible(true); new Thread("BookmarkSheet.loadBookmarks") { @Override public void run() { try { BookmarkController.getInstance().addBookmarksFromFile(selectedFile, addMargin); btm.fireTableDataChanged(); } catch (Exception ex) { DialogUtils.displayError("Error", "Unable to load bookmarks: " + ex.getMessage()); } finally { dialog.setVisible(false); dialog.dispose(); } } }.start(); } }
From source file:savant.view.swing.Savant.java
private void initBookmarksPanel() { DockableFrame df = DockableFrameFactory.createFrame("Bookmarks", DockContext.STATE_HIDDEN, DockContext.DOCK_SIDE_EAST); df.setAvailableButtons(// ww w . jav a 2 s.c om DockableFrame.BUTTON_AUTOHIDE | DockableFrame.BUTTON_FLOATING | DockableFrame.BUTTON_MAXIMIZE); auxDockingManager.addFrame(df); MiscUtils.setFrameVisibility("Bookmarks", false, auxDockingManager); df.getContentPane().setLayout(new BorderLayout()); //JPanel tablePanel = createTabPanel(jtp, "Bookmarks"); favoriteSheet = new BookmarkSheet(df.getContentPane()); BookmarkController bc = BookmarkController.getInstance(); bc.addListener(favoriteSheet); bc.addListener(new Listener<BookmarksChangedEvent>() { @Override public void handleEvent(BookmarksChangedEvent event) { if (showBookmarksChangedDialog) { //Custom button text Object[] options = { "OK", "Don't show again" }; int n = JOptionPane.showOptionDialog(Savant.this, event.isAdded() ? "Bookmark added at " + event.getBookmark().getReference() + ":" + event.getBookmark().getRange() : "Bookmark removed at " + event.getBookmark().getRange(), "Bookmarks changed", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); if (n == 1) { showBookmarksChangedDialog = false; } } } }); }
From source file:se.trixon.jota.client.ui.editor.JobsPanel.java
private void edit(Job job) { String title;//from ww w . ja v a 2s . co m boolean add = job == null; String type = Dict.JOB.toString().toLowerCase(); if (job == null) { job = new Job(); title = String.format("%s %s", Dict.ADD.toString(), type); } else { title = String.format("%s %s", Dict.EDIT.toString(), type); } JobPanel jobPanel = new JobPanel(); jobPanel.setJob(job); SwingHelper.makeWindowResizable(jobPanel); int retval = JOptionPane.showOptionDialog(getRoot(), jobPanel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (retval == JOptionPane.OK_OPTION) { Job modifiedJob = jobPanel.getJob(); if (modifiedJob.isValid() && !jobExists(modifiedJob)) { if (add) { getModel().addElement(modifiedJob); } else { getModel().set(getModel().indexOf(getSelectedJob()), modifiedJob); } sortModel(); list.setSelectedValue(modifiedJob, true); } else { showInvalidJobDialog(); edit(modifiedJob); } } }
From source file:se.trixon.jota.client.ui.editor.module.job.CronEditorPanel.java
private void edit(String cronString) { String title;/* ww w . j av a 2s . c o m*/ boolean add = cronString == null; if (cronString == null) { title = Dict.ADD.toString(); } else { title = Dict.EDIT.toString(); } CronPanel cronPanel = new CronPanel(); cronPanel.setCronString(cronString); SwingHelper.makeWindowResizable(cronPanel); int retval = JOptionPane.showOptionDialog(getRoot(), cronPanel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (retval == JOptionPane.OK_OPTION) { String modifiedCronString = cronPanel.getCronString(); if (cronPanel.isCronValid()) { if (add) { getModel().addElement(modifiedCronString); } else { getModel().set(getModel().indexOf(getSelectedCronString()), modifiedCronString); } sortModel(); list.setSelectedValue(modifiedCronString, true); } else { Message.error(this, "Invalid cron string", modifiedCronString); edit(modifiedCronString); } } }
From source file:se.trixon.jota.client.ui.editor.TasksPanel.java
private void edit(Task task) { String title;/*from ww w . jav a2 s . c om*/ boolean add = task == null; String type = Dict.TASK.toString().toLowerCase(); if (task == null) { task = new Task(); title = String.format("%s %s", Dict.ADD.toString(), type); } else { title = String.format("%s %s", Dict.EDIT.toString(), type); } TaskPanel taskPanel = new TaskPanel(); taskPanel.setTask(task); SwingHelper.makeWindowResizable(taskPanel); int retval = JOptionPane.showOptionDialog(getRoot(), taskPanel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (retval == JOptionPane.OK_OPTION) { Task modifiedTask = taskPanel.getTask(); if (modifiedTask.isValid()) { if (add) { getModel().addElement(modifiedTask); } else { getModel().set(getModel().indexOf(getSelectedTask()), modifiedTask); } sortModel(); list.setSelectedValue(modifiedTask, true); notifyTaskListenersChanged(); } else { showInvalidTaskDialog(); edit(modifiedTask); } } }
From source file:se.trixon.jota.client.ui.MainFrame.java
public boolean requestStartJob(Job job) { try {/*from ww w . jav a 2 s . co m*/ JobValidator validator = mManager.getServerCommander().validate(job); if (validator.isValid()) { Object[] options = { Dict.RUN.toString(), Dict.DRY_RUN.toString(), Dict.CANCEL.toString() }; HtmlPanel htmlPanel = new HtmlPanel(job.getSummaryAsHtml()); SwingHelper.makeWindowResizable(htmlPanel); int result = JOptionPane.showOptionDialog(this, htmlPanel, Dict.RUN.toString(), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if (result > -1 && result < 2) { boolean dryRun = result == 1; mManager.getServerCommander().startJob(job, dryRun); } } else { Message.html(this, Dict.ERROR_VALIDATION.toString(), validator.getSummaryAsHtml()); } } catch (RemoteException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } return false; }
From source file:se.trixon.jota.client.ui.MainFrame.java
private void requestConnect() throws NotBoundException { String[] hosts = mOptions.getHosts().split(";"); Arrays.sort(hosts);// w w w .j av a 2 s . c o m DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(hosts); JComboBox hostComboBox = new JComboBox(comboBoxModel); hostComboBox.setEditable(true); hostComboBox.setSelectedItem(mClient.getHost()); JTextField portTextField = new JTextField(String.valueOf(mClient.getPortHost())); final JComponent[] inputs = new JComponent[] { new JLabel(Dict.HOST.toString()), hostComboBox, new JLabel(Dict.PORT.toString()), portTextField, }; Object[] options = { Dict.CONNECT.toString(), Dict.CANCEL.toString() }; int retval = JOptionPane.showOptionDialog(this, inputs, Dict.CONNECT_TO_HOST.toString(), JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (retval == 0) { String currentHost = mClient.getHost(); int currentPort = mClient.getPortHost(); String host = (String) hostComboBox.getSelectedItem(); String portString = portTextField.getText(); try { int port = Integer.valueOf(portString); mManager.disconnect(); mManager.connect(host, port); if (comboBoxModel.getIndexOf(host) == -1) { comboBoxModel.addElement(host); } mOptions.setHosts(SwingHelper.comboBoxModelToString(comboBoxModel)); } catch (NumberFormatException e) { Message.error(this, Dict.ERROR.toString(), String.format(Dict.INVALID_PORT.toString(), portString)); } catch (NotBoundException | MalformedURLException | RemoteException | SocketException ex) { Message.error(this, Dict.ERROR.toString(), ex.getLocalizedMessage()); mClient.setHost(currentHost); mClient.setPortHost(currentPort); } } }
From source file:se.trixon.jota.client.ui.MainFrame.java
void showEditor(long jobId, boolean openJob) { EditorPanel editorPanel = new EditorPanel(jobId, openJob); SwingHelper.makeWindowResizable(editorPanel); int retval = JOptionPane.showOptionDialog(this, editorPanel, mBundle.getString("jobEditor"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (retval == JOptionPane.OK_OPTION) { editorPanel.save();// w ww . j av a2 s . co m try { mManager.getServerCommander().saveJota(); } catch (RemoteException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } } }