Example usage for javax.swing JOptionPane showInputDialog

List of usage examples for javax.swing JOptionPane showInputDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane showInputDialog.

Prototype

@SuppressWarnings("deprecation")
public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType,
        Icon icon, Object[] selectionValues, Object initialSelectionValue) throws HeadlessException 

Source Link

Document

Prompts the user for input in a blocking dialog where the initial selection, possible selections, and all other options can be specified.

Usage

From source file:org.monome.pages.MIDIKeyboardJulienBPage.java

public void actionPerformed(ActionEvent e) {
    System.out.println(e.getActionCommand());
    if (e.getActionCommand().equals("Add MIDI Output")) {
        String[] midiOutOptions = this.monome.getMidiOutOptions();
        String deviceName = (String) JOptionPane.showInputDialog(this.monome, "Choose a MIDI Output to add",
                "Add MIDI Output", JOptionPane.PLAIN_MESSAGE, null, midiOutOptions, "");

        if (deviceName == null) {
            return;
        }// w  w w.jav  a  2s  .  c  o m

        this.addMidiOutDevice(deviceName);

    }
}

From source file:org.monome.pages.MIDIKeyboardPage.java

public void actionPerformed(ActionEvent e) {
    System.out.println(e.getActionCommand());
    if (e.getActionCommand().equals("Set MIDI Output")) {
        String[] midiOutOptions = this.monome.getMidiOutOptions();
        String deviceName = (String) JOptionPane.showInputDialog(this.monome, "Choose a MIDI Output to use",
                "Set MIDI Output", JOptionPane.PLAIN_MESSAGE, null, midiOutOptions, "");

        if (deviceName == null) {
            return;
        }//  w  ww.j  av  a 2  s.c  o m

        this.addMidiOutDevice(deviceName);

    }
    if (e.getActionCommand().equals("Update Preferences")) {
        String s[] = new String[6];
        s[0] = this.scaleTF1.getText();
        s[1] = this.scaleTF2.getText();
        s[2] = this.scaleTF3.getText();
        s[3] = this.scaleTF4.getText();
        s[4] = this.scaleTF5.getText();
        s[5] = this.scaleTF6.getText();
        setScales(s);
    }

    if (e.getActionCommand().equals("Reset Scales")) {
        this.scales = this.scalesDefault;
        this.getScales();
    }
}

From source file:org.monome.pages.MIDISequencerPage.java

public void actionPerformed(ActionEvent e) {
    System.out.println(e.getActionCommand());
    if (e.getActionCommand().equals("Set MIDI Output")) {
        String[] midiOutOptions = this.monome.getMidiOutOptions();
        String deviceName = (String) JOptionPane.showInputDialog(this.monome, "Choose a MIDI Output to use",
                "Set MIDI Output", JOptionPane.PLAIN_MESSAGE, null, midiOutOptions, "");

        if (deviceName == null) {
            return;
        }//from ww w.j  a v a2  s.c o  m

        this.addMidiOutDevice(deviceName);
    }
    if (e.getActionCommand().equals("Update Preferences")) {
        this.noteNumbers[0] = this.noteToMidiNumber(this.row1tf.getText());
        this.noteNumbers[1] = this.noteToMidiNumber(this.row2tf.getText());
        this.noteNumbers[2] = this.noteToMidiNumber(this.row3tf.getText());
        this.noteNumbers[3] = this.noteToMidiNumber(this.row4tf.getText());
        this.noteNumbers[4] = this.noteToMidiNumber(this.row5tf.getText());
        this.noteNumbers[5] = this.noteToMidiNumber(this.row6tf.getText());
        this.noteNumbers[6] = this.noteToMidiNumber(this.row7tf.getText());
        this.noteNumbers[7] = this.noteToMidiNumber(this.row8tf.getText());
        this.noteNumbers[8] = this.noteToMidiNumber(this.row9tf.getText());
        this.noteNumbers[9] = this.noteToMidiNumber(this.row10tf.getText());
        this.noteNumbers[10] = this.noteToMidiNumber(this.row11tf.getText());
        this.noteNumbers[11] = this.noteToMidiNumber(this.row12tf.getText());
        this.noteNumbers[12] = this.noteToMidiNumber(this.row13tf.getText());
        this.noteNumbers[13] = this.noteToMidiNumber(this.row14tf.getText());
        this.noteNumbers[14] = this.noteToMidiNumber(this.row15tf.getText());
        this.midiChannel = this.channelTF.getText();
        try {
            this.setBankSize(Integer.parseInt(this.bankSizeTF.getText()));
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
    }
}

From source file:org.monome.pages.MIDISequencerPagePoly.java

public void actionPerformed(ActionEvent e) {
    //System.out.println(e.getActionCommand());
    if (e.getActionCommand().equals("Set MIDI Output")) {
        String[] midiOutOptions = this.monome.getMidiOutOptions();
        String deviceName = (String) JOptionPane.showInputDialog(this.monome, "Choose a MIDI Output to use",
                "Set MIDI Output", JOptionPane.PLAIN_MESSAGE, null, midiOutOptions, "");

        if (deviceName == null) {
            return;
        }/*from  ww  w. ja v  a 2  s. c o m*/

        this.addMidiOutDevice(deviceName);
    }
    if (e.getActionCommand().equals("Update Preferences")) {
        this.noteNumbers[0] = this.noteToMidiNumber(this.row1tf.getText());
        this.noteNumbers[1] = this.noteToMidiNumber(this.row2tf.getText());
        this.noteNumbers[2] = this.noteToMidiNumber(this.row3tf.getText());
        this.noteNumbers[3] = this.noteToMidiNumber(this.row4tf.getText());
        this.noteNumbers[4] = this.noteToMidiNumber(this.row5tf.getText());
        this.noteNumbers[5] = this.noteToMidiNumber(this.row6tf.getText());
        this.noteNumbers[6] = this.noteToMidiNumber(this.row7tf.getText());
        this.noteNumbers[7] = this.noteToMidiNumber(this.row8tf.getText());
        this.noteNumbers[8] = this.noteToMidiNumber(this.row9tf.getText());
        this.noteNumbers[9] = this.noteToMidiNumber(this.row10tf.getText());
        this.noteNumbers[10] = this.noteToMidiNumber(this.row11tf.getText());
        this.noteNumbers[11] = this.noteToMidiNumber(this.row12tf.getText());
        this.noteNumbers[12] = this.noteToMidiNumber(this.row13tf.getText());
        this.noteNumbers[13] = this.noteToMidiNumber(this.row14tf.getText());
        this.noteNumbers[14] = this.noteToMidiNumber(this.row15tf.getText());
        this.midiChannel = this.channelTF.getText();
        if (Integer.parseInt(this.midiChannel) < 1) {
            this.midiChannel = "1";
            this.channelTF.setText("1");
        }

        try {
            this.setBankSize(Integer.parseInt(this.bankSizeTF.getText()));
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
    }
}

From source file:org.monome.pages.MIDITriggersPage.java

public void actionPerformed(ActionEvent e) {
    System.out.println(e.getActionCommand());
    if (e.getActionCommand().equals("Set MIDI Output")) {
        String[] midiOutOptions = this.monome.getMidiOutOptions();
        String deviceName = (String) JOptionPane.showInputDialog(this.monome, "Choose a MIDI Output to add",
                "Add MIDI Output", JOptionPane.PLAIN_MESSAGE, null, midiOutOptions, "");

        if (deviceName == null) {
            return;
        }/*from  w w w. j a va  2 s .  c om*/

        this.addMidiOutDevice(deviceName);
    } else if (e.getActionCommand().equals("Columns")) {
        row1Label.setText("Col 1");
        row2Label.setText("Col 2");
        row3Label.setText("Col 3");
        row4Label.setText("Col 4");
        row5Label.setText("Col 5");
        row6Label.setText("Col 6");
        row7Label.setText("Col 7");
        row8Label.setText("Col 8");
        row9Label.setText("Col 9");
        row10Label.setText("Col 10");
        row11Label.setText("Col 11");
        row12Label.setText("Col 12");
        row13Label.setText("Col 13");
        row14Label.setText("Col 14");
        row15Label.setText("Col 15");
        row16Label.setText("Col 16");
        this.redrawMonome();
    } else if (e.getActionCommand().equals("Rows")) {
        row1Label.setText("Row 1");
        row2Label.setText("Row 2");
        row3Label.setText("Row 3");
        row4Label.setText("Row 4");
        row5Label.setText("Row 5");
        row6Label.setText("Row 6");
        row7Label.setText("Row 7");
        row8Label.setText("Row 8");
        row9Label.setText("Row 9");
        row10Label.setText("Row 10");
        row11Label.setText("Row 11");
        row12Label.setText("Row 12");
        row13Label.setText("Row 13");
        row14Label.setText("Row 14");
        row15Label.setText("Row 15");
        row16Label.setText("Row 16");
        this.redrawMonome();
    }
}

From source file:org.monome.pages.PageTemplate.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("Add MIDI Output")) {
        String[] midiOutOptions = this.monome.getMidiOutOptions();
        String deviceName = (String) JOptionPane.showInputDialog(this.monome, "Choose a MIDI Output to add",
                "Add MIDI Output", JOptionPane.PLAIN_MESSAGE, null, midiOutOptions, "");

        if (deviceName == null) {
            return;
        }// w  w  w.j av  a  2 s.c o  m
        this.addMidiOutDevice(deviceName);
    }
}

From source file:org.pmedv.blackboard.commands.MoveToLayerCommand.java

@Override
public void execute(ActionEvent e) {

    ApplicationContext ctx = AppContext.getContext();
    BoardEditor editor = EditorUtils.getCurrentActiveEditor();

    final String selectMsg = resources.getResourceByKey("MoveToLayerCommand.selectlayer");

    if (editor == null)
        return;//from ww w .j  a va  2s  .  com

    Object[] layers = editor.getModel().getLayers().toArray();

    if (editor.getSelectedItems().size() > 1) {

        Layer selectedLayer = (Layer) JOptionPane.showInputDialog(ctx.getBean(ApplicationWindow.class),
                selectMsg, selectMsg, JOptionPane.PLAIN_MESSAGE, null, layers,
                editor.getModel().getLayer(editor.getSelectedItems().get(0).getLayer()));

        editor.clearSelectionBorder();
        for (Item item : editor.getSelectedItems()) {
            moveItem(editor.getModel(), item, selectedLayer);
        }
    } else {
        if (editor.getSelectedItem() == null)
            return;
        editor.clearSelectionBorder();

        Layer selectedLayer = (Layer) JOptionPane.showInputDialog(ctx.getBean(ApplicationWindow.class),
                selectMsg, selectMsg, JOptionPane.PLAIN_MESSAGE, null, layers,
                editor.getModel().getLayer(editor.getSelectedItem().getLayer()));

        moveItem(editor.getModel(), editor.getSelectedItem(), selectedLayer);
        editor.setSelectedItem(null);
    }

    editor.setFileState(FileState.DIRTY);
    editor.updateStatusBar();

}

From source file:org.rdv.datapanel.AbstractDataPanel.java

/**
 * Get a component for displaying the title in top bar. This implementation
 * includes a button to remove a specific channel.
 * //from   w  w w . j ava2s  .c  o  m
 * Subclasses should overide this method if they don't want the default
 * implementation.
 * 
 * @return  A component for the top bar
 * @since   1.3
 */
JComponent getTitleComponent() {
    JPanel titleBar = new JPanel();
    titleBar.setOpaque(false);
    titleBar.setLayout(new BorderLayout());

    JPopupMenu popupMenu = new ScrollablePopupMenu();

    final String title;
    if (description != null) {
        title = "Edit description";
    } else {
        title = "Add description";
    }

    JMenuItem addDescriptionMenuItem = new JMenuItem(title);
    addDescriptionMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String response = (String) JOptionPane.showInputDialog(null, "Enter a description", title,
                    JOptionPane.QUESTION_MESSAGE, null, null, description);
            if (response == null) {
                return;
            } else if (response.length() == 0) {
                setDescription(null);
            } else {
                setDescription(response);
            }
        }
    });
    popupMenu.add(addDescriptionMenuItem);

    if (description != null) {
        JMenuItem removeDescriptionMenuItem = new JMenuItem("Remove description");
        removeDescriptionMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                setDescription(null);
            }
        });
        popupMenu.add(removeDescriptionMenuItem);
    }

    popupMenu.addSeparator();

    final JCheckBoxMenuItem showChannelsInTitleMenuItem = new JCheckBoxMenuItem("Show channels in title",
            showChannelsInTitle);
    showChannelsInTitleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setShowChannelsInTitle(showChannelsInTitleMenuItem.isSelected());
        }
    });
    popupMenu.add(showChannelsInTitleMenuItem);

    if (channels.size() > 0) {
        popupMenu.addSeparator();

        Iterator<String> i = channels.iterator();
        while (i.hasNext()) {
            final String channelName = i.next();

            JMenuItem unsubscribeChannelMenuItem = new JMenuItem("Unsubscribe from " + channelName);
            unsubscribeChannelMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    removeChannel(channelName);
                }
            });
            popupMenu.add(unsubscribeChannelMenuItem);
        }
    }

    // set component popup and mouselistener to trigger it
    titleBar.setComponentPopupMenu(popupMenu);
    titleBar.addMouseListener(new MouseInputAdapter() {
    });

    if (description != null) {
        titleBar.add(getDescriptionComponent(), BorderLayout.WEST);
    }

    JComponent titleComponent = getChannelComponent();
    if (titleComponent != null) {
        titleBar.add(titleComponent, BorderLayout.CENTER);
    }

    return titleBar;
}

From source file:org.rdv.DockingDataPanelManager.java

/**
 * Creates the root window and the views.
 *//* w  w  w . ja  v  a  2  s  .  c  o  m*/
private void createRootWindow() {

    // The mixed view map makes it easy to mix static and dynamic views inside the same root window
    MixedViewHandler handler = new MixedViewHandler(viewMap_, new ViewSerializer() {
        public void writeView(View view, ObjectOutputStream out) throws IOException {
            out.writeInt(((DockingView) view).getId());
        }

        public View readView(ObjectInputStream in) throws IOException {
            return viewMap_.getView(in.readInt());
        }
    });

    rootWindow_ = DockingUtil.createRootWindow(viewMap_, handler, true);

    // turn off tab window buttons
    rootWindow_.getRootWindowProperties().getTabWindowProperties().getCloseButtonProperties().setVisible(false);//getTabProperties().getFocusedButtonProperties().getCloseButtonProperties().setVisible(false);
    //rootWindow_.getRootWindowProperties().getTabWindowProperties().getCloseButtonProperties().setVisible(false);
    rootWindow_.getRootWindowProperties().setRecursiveTabsEnabled(true);

    rootWindow_.getRootWindowProperties().getFloatingWindowProperties().setUseFrame(true);

    // disable per-tab buttons like undock/minimize
    rootWindow_.getRootWindowProperties().getTabWindowProperties().getTabProperties()
            .getHighlightedButtonProperties().getUndockButtonProperties().setVisible(false);
    rootWindow_.getRootWindowProperties().getTabWindowProperties().getTabProperties()
            .getHighlightedButtonProperties().getDockButtonProperties().setVisible(false);
    rootWindow_.getRootWindowProperties().getTabWindowProperties().getTabProperties()
            .getHighlightedButtonProperties().getMinimizeButtonProperties().setVisible(false);

    final Icon closeIcon = rootWindow_.getRootWindowProperties().getTabWindowProperties()
            .getCloseButtonProperties().getIcon();
    final Icon undockIcon = rootWindow_.getRootWindowProperties().getTabWindowProperties()
            .getUndockButtonProperties().getIcon();
    final Icon dockIcon = rootWindow_.getRootWindowProperties().getTabWindowProperties()
            .getDockButtonProperties().getIcon();

    rootWindow_.setPopupMenuFactory(new WindowPopupMenuFactory() {
        public JPopupMenu createPopupMenu(final DockingWindow window) {

            JPopupMenu menu = new JPopupMenu();
            // Check that the window is a View
            if (window instanceof View) {
                final View v = (View) window;

                if (window instanceof DockingPanelView) {
                    final DockingPanelView dpv = (DockingPanelView) window;

                    JMenuItem renameItem = menu.add("Set Description");
                    renameItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {

                            String s = (String) JOptionPane.showInputDialog(window, "Enter new description:\n",
                                    "Set Description", JOptionPane.PLAIN_MESSAGE, null, null,
                                    dpv.getDataPanel().getDescription());

                            if (s != null) {
                                //v.setName(s); 
                                //v.getViewProperties().setTitle(s);
                                dpv.getDataPanel().setDescription((s.isEmpty()) ? null : s);
                            }
                        }
                    });
                }

                JMenuItem closeItem = menu.add("Close");
                closeItem.setIcon(closeIcon);
                closeItem.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        try {
                            window.closeWithAbort();
                        } catch (OperationAbortedException e1) {
                            //e1.printStackTrace();
                        }
                    }
                });

                if (v.isUndocked()) {
                    JMenuItem dockItem = menu.add("Dock");
                    dockItem.setIcon(dockIcon);
                    dockItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            try {
                                window.dock();
                            } catch (Exception e1) {
                                //e1.printStackTrace();
                            }
                        }
                    });
                } else {
                    JMenuItem undockItem = menu.add("Undock");
                    undockItem.setIcon(undockIcon);
                    undockItem.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            try {
                                window.undock(new Point(0, 0));
                            } catch (Exception e1) {
                                //e1.printStackTrace();
                            }
                        }
                    });
                }
            }
            return menu;
        }
    });

    properties_.addSuperObject(titleBarStyleProperties);
    titleBarTheme_ = true;

    // Set gradient theme. The theme properties object is the super object of our properties object, which
    // means our property value settings will override the theme values
    properties_.addSuperObject(currentTheme_.getRootWindowProperties());

    // Our properties object is the super object of the root window properties object, so all property values of the
    // theme and in our property object will be used by the root window
    rootWindow_.getRootWindowProperties().addSuperObject(properties_);

    // Enable the bottom window bar
    rootWindow_.getWindowBar(Direction.DOWN).setEnabled(true);

    // Add a listener which shows dialogs when a window is closing or closed.
    rootWindow_.addListener(new DockingWindowAdapter() {
        public void windowAdded(DockingWindow addedToWindow, DockingWindow addedWindow) {
            updateViews(addedWindow, true);

            // If the added window is a floating window, then update it
            if (addedWindow instanceof FloatingWindow)
                updateFloatingWindow((FloatingWindow) addedWindow);
        }

        public void windowRemoved(DockingWindow removedFromWindow, DockingWindow removedWindow) {
            //updateViews(removedWindow, false);
        }

        public void windowClosing(DockingWindow window) throws OperationAbortedException {
            // Confirm close operation
            if (JOptionPane.showConfirmDialog(UIUtilities.getMainFrame(),
                    "Really close data panel '" + window + "'?") != JOptionPane.YES_OPTION)
                throw new OperationAbortedException("Data panel close was aborted!");
            updateViews(window, false);
        }

        public void windowDocking(DockingWindow window) throws OperationAbortedException {
            // Confirm dock operation
            if (JOptionPane.showConfirmDialog(UIUtilities.getMainFrame(),
                    "Really dock data panel '" + window + "'?") != JOptionPane.YES_OPTION)
                throw new OperationAbortedException("Data panel dock was aborted!");
        }

        public void windowUndocking(DockingWindow window) throws OperationAbortedException {
            // Confirm undock operation 
            if (JOptionPane.showConfirmDialog(UIUtilities.getMainFrame(),
                    "Really undock data panel '" + window + "'?") != JOptionPane.YES_OPTION)
                throw new OperationAbortedException("Data panel undock was aborted!");
        }

    });

    // Add a mouse button listener that closes a window when it's clicked with the middle mouse button.
    rootWindow_.addTabMouseButtonListener(DockingWindowActionMouseButtonListener.MIDDLE_BUTTON_CLOSE_LISTENER);

    mainPanel_.add(rootWindow_);
}

From source file:pcgen.gui2.PCGenFrame.java

@Override
public String showInputDialog(String title, String message, String initialValue) {
    Object ret = JOptionPane.showInputDialog(this, message, title, JOptionPane.QUESTION_MESSAGE, null, null,
            initialValue);/*  w  ww  . ja  v a  2 s  .com*/
    return ret == null ? null : String.valueOf(ret);
}