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();
}
});
}
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);
}
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();
}
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);
}
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);
}
Aggregations