Search in sources :

Example 96 with JDialog

use of javax.swing.JDialog in project libgdx by libgdx.

the class JglfwInput method getTextInput.

public void getTextInput(final TextInputListener listener, final String title, final String text, final String hint) {
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            JPanel panel = new JPanel(new FlowLayout());
            JPanel textPanel = new JPanel() {

                public boolean isOptimizedDrawingEnabled() {
                    return false;
                }

                ;
            };
            textPanel.setLayout(new OverlayLayout(textPanel));
            panel.add(textPanel);
            final JTextField textField = new JTextField(20);
            textField.setText(text);
            textField.setAlignmentX(0.0f);
            textPanel.add(textField);
            final JLabel placeholderLabel = new JLabel(hint);
            placeholderLabel.setForeground(Color.GRAY);
            placeholderLabel.setAlignmentX(0.0f);
            textPanel.add(placeholderLabel, 0);
            textField.getDocument().addDocumentListener(new DocumentListener() {

                public void removeUpdate(DocumentEvent event) {
                    this.updated();
                }

                public void insertUpdate(DocumentEvent event) {
                    this.updated();
                }

                public void changedUpdate(DocumentEvent event) {
                    this.updated();
                }

                private void updated() {
                    placeholderLabel.setVisible(textField.getText().length() == 0);
                }
            });
            JOptionPane pane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
            pane.setComponentOrientation(JOptionPane.getRootFrame().getComponentOrientation());
            pane.selectInitialValue();
            placeholderLabel.setBorder(new EmptyBorder(textField.getBorder().getBorderInsets(textField)));
            JDialog dialog = pane.createDialog(null, title);
            dialog.addWindowFocusListener(new WindowFocusListener() {

                public void windowLostFocus(WindowEvent arg0) {
                }

                public void windowGainedFocus(WindowEvent arg0) {
                    textField.requestFocusInWindow();
                }
            });
            dialog.setVisible(true);
            dialog.dispose();
            Object selectedValue = pane.getValue();
            if (selectedValue != null && (selectedValue instanceof Integer) && (Integer) selectedValue == JOptionPane.OK_OPTION)
                listener.input(textField.getText());
            else
                listener.canceled();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) FlowLayout(java.awt.FlowLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) JOptionPane(javax.swing.JOptionPane) WindowEvent(java.awt.event.WindowEvent) OverlayLayout(javax.swing.OverlayLayout) EmptyBorder(javax.swing.border.EmptyBorder) JDialog(javax.swing.JDialog) WindowFocusListener(java.awt.event.WindowFocusListener)

Example 97 with JDialog

use of javax.swing.JDialog in project Openfire by igniterealtime.

the class Launcher method installPlugin.

private void installPlugin(final File plugin) {
    final JDialog dialog = new JDialog(frame, "Installing Plugin", true);
    dialog.getContentPane().setLayout(new BorderLayout());
    JProgressBar bar = new JProgressBar();
    bar.setIndeterminate(true);
    bar.setString("Installing Plugin.  Please wait...");
    bar.setStringPainted(true);
    dialog.getContentPane().add(bar, BorderLayout.CENTER);
    dialog.pack();
    dialog.setSize(225, 55);
    final SwingWorker<File, Void> installerThread = new SwingWorker<File, Void>() {

        @Override
        public File doInBackground() {
            File pluginsDir = new File(binDir.getParentFile(), "plugins");
            String tempName = plugin.getName() + ".part";
            File tempPluginsFile = new File(pluginsDir, tempName);
            File realPluginsFile = new File(pluginsDir, plugin.getName());
            // Copy Plugin into Dir.
            try {
                // Just for fun. Show no matter what for two seconds.
                Thread.sleep(2000);
                copy(plugin.toURI().toURL(), tempPluginsFile);
                // If successfull, rename to real plugin name.
                tempPluginsFile.renameTo(realPluginsFile);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return realPluginsFile;
        }

        @Override
        public void done() {
            dialog.setVisible(false);
        }
    };
    // Start installation
    installerThread.execute();
    dialog.setLocationRelativeTo(frame);
    dialog.setVisible(true);
}
Also used : BorderLayout(java.awt.BorderLayout) JProgressBar(javax.swing.JProgressBar) SwingWorker(javax.swing.SwingWorker) File(java.io.File) JDialog(javax.swing.JDialog) BadLocationException(javax.swing.text.BadLocationException) FileNotFoundException(java.io.FileNotFoundException) AWTException(java.awt.AWTException) IOException(java.io.IOException)

Example 98 with JDialog

use of javax.swing.JDialog in project hid-serial by rayshobby.

the class G4P method selectColor.

/**
	 * This will open a version of the Java Swing color chooser dialog. The dialog's
	 * UI is dependent on the OS and JVM implementation running. <br>
	 * 
	 * If you click on Cancel then it returns the last color previously selected.
	 * 
	 * @return the ARGB colour as a 32 bit integer (as used in Processing). 
	 */
public static int selectColor() {
    Frame owner = (sketchApplet == null) ? null : sketchApplet.frame;
    if (chooser == null) {
        chooser = new JColorChooser();
        AbstractColorChooserPanel[] oldPanels = chooser.getChooserPanels();
        // Do not assume what panels are present
        LinkedList<AbstractColorChooserPanel> panels = new LinkedList<AbstractColorChooserPanel>();
        for (AbstractColorChooserPanel p : oldPanels) {
            String displayName = p.getDisplayName().toLowerCase();
            if (displayName.equals("swatches"))
                panels.addLast(p);
            else if (displayName.equals("rgb"))
                panels.addFirst(p);
            else if (displayName.startsWith("hs"))
                panels.addFirst(p);
        }
        AbstractColorChooserPanel[] newPanels;
        newPanels = panels.toArray(new AbstractColorChooserPanel[panels.size()]);
        chooser.setChooserPanels(newPanels);
        ColorPreviewPanel pp = new ColorPreviewPanel(lastColor);
        chooser.getSelectionModel().addChangeListener(pp);
        chooser.setPreviewPanel(pp);
    }
    // Set the preview color
    ((ColorPreviewPanel) chooser.getPreviewPanel()).setPrevColor(lastColor);
    // Use the last color selected to start it off
    chooser.setColor(lastColor);
    JDialog dialog = JColorChooser.createDialog(owner, "Color picker", true, chooser, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            lastColor = chooser.getColor();
        }
    }, null);
    dialog.setVisible(true);
    return lastColor.getRGB();
}
Also used : Frame(java.awt.Frame) AbstractColorChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JColorChooser(javax.swing.JColorChooser) LinkedList(java.util.LinkedList) JDialog(javax.swing.JDialog)

Example 99 with JDialog

use of javax.swing.JDialog in project EnrichmentMapApp by BaderLab.

the class LegendPanelMediator method showCreationParamsDialog.

@SuppressWarnings("serial")
private void showCreationParamsDialog() {
    JDialog d = new JDialog(dialog, "EnrichmentMap Creation Parameters", ModalityType.APPLICATION_MODAL);
    d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    d.setMinimumSize(new Dimension(420, 260));
    d.setPreferredSize(new Dimension(580, 460));
    JButton closeButton = new JButton(new AbstractAction("Close") {

        @Override
        public void actionPerformed(ActionEvent e) {
            d.dispose();
        }
    });
    JPanel bottomPanel = LookAndFeelUtil.createOkCancelPanel(null, closeButton);
    d.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
    CyNetworkView netView = legendPanelProvider.get().getOptions().getNetworkView();
    if (netView != null) {
        EnrichmentMap map = emManager.getEnrichmentMap(netView.getModel().getSUID());
        CreationParametersPanel paramsPanel = new CreationParametersPanel(map);
        d.getContentPane().add(paramsPanel, BorderLayout.CENTER);
    }
    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(d.getRootPane(), null, closeButton.getAction());
    d.getRootPane().setDefaultButton(closeButton);
    d.setLocationRelativeTo(dialog);
    d.pack();
    d.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) AbstractAction(javax.swing.AbstractAction) CyNetworkView(org.cytoscape.view.model.CyNetworkView) JDialog(javax.swing.JDialog)

Example 100 with JDialog

use of javax.swing.JDialog in project CoreNLP by stanfordnlp.

the class PreferencesPanel method doEncodingPrompt.

private void doEncodingPrompt(final String encoding, final String oldEncoding) {
    final JPanel encodingPanel = new JPanel();
    encodingPanel.setLayout(new BoxLayout(encodingPanel, BoxLayout.PAGE_AXIS));
    JLabel text = new JLabel("<html>A head finder or tree reader was selected that has the default encoding " + encoding + "; this differs from " + oldEncoding + ", which was being used. If the encoding is changed, all newly loaded" + "treebanks will be read using the new encoding. Choosing an encoding that is not the true encoding of your tree " + "files may cause errors and unexpected behavior.</html>");
    //text.setBorder(BorderFactory.createLineBorder(Color.black));
    text.setAlignmentX(SwingConstants.LEADING);
    JPanel textPanel = new JPanel(new BorderLayout());
    textPanel.setPreferredSize(new Dimension(100, 100));
    textPanel.add(text);
    encodingPanel.add(textPanel);
    encodingPanel.add(Box.createVerticalStrut(5));
    final JOptionPane fileFilterDialog = new JOptionPane();
    fileFilterDialog.setMessage(encodingPanel);
    JButton[] options = new JButton[3];
    JButton useNewEncoding = new JButton("Use " + encoding);
    JButton useOldEncoding = new JButton("Use " + oldEncoding);
    JButton useAnotherEncoding = new JButton("Use encoding...");
    options[0] = useNewEncoding;
    options[1] = useOldEncoding;
    options[2] = useAnotherEncoding;
    fileFilterDialog.setOptions(options);
    final JDialog dialog = fileFilterDialog.createDialog(null, "Default encoding changed...");
    useNewEncoding.addActionListener(arg0 -> {
        FileTreeModel.setCurEncoding(encoding);
        if (setEncoding == null)
            System.out.println("encoding null!!");
        setEncoding.setText(encoding);
        dialog.setVisible(false);
    });
    useOldEncoding.addActionListener(e -> dialog.setVisible(false));
    useAnotherEncoding.addActionListener(e -> {
        dialog.setVisible(false);
        alternateEncodingPrompt(encoding);
    });
    dialog.getRootPane().setDefaultButton(useNewEncoding);
    dialog.pack();
    dialog.setLocationRelativeTo(this);
    dialog.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Aggregations

JDialog (javax.swing.JDialog)181 JButton (javax.swing.JButton)70 JPanel (javax.swing.JPanel)61 ActionEvent (java.awt.event.ActionEvent)51 ActionListener (java.awt.event.ActionListener)39 JLabel (javax.swing.JLabel)39 JOptionPane (javax.swing.JOptionPane)34 BorderLayout (java.awt.BorderLayout)30 Dimension (java.awt.Dimension)27 JScrollPane (javax.swing.JScrollPane)27 JFrame (javax.swing.JFrame)23 BoxLayout (javax.swing.BoxLayout)21 FlowLayout (java.awt.FlowLayout)19 JCheckBox (javax.swing.JCheckBox)15 AbstractAction (javax.swing.AbstractAction)14 WindowEvent (java.awt.event.WindowEvent)13 JComponent (javax.swing.JComponent)12 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 WindowAdapter (java.awt.event.WindowAdapter)11 IOException (java.io.IOException)10