List of usage examples for javax.swing JDialog setVisible
public void setVisible(boolean b)
From source file:com.sshtools.common.ui.OptionsPanel.java
/** * * * @param parent//from w ww .j av a2 s. c o m * @param tabs tabs * * @return */ public static boolean showOptionsDialog(Component parent, OptionsTab[] tabs) { final OptionsPanel opts = new OptionsPanel(tabs); opts.reset(); JDialog d = null; Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent); if (w instanceof JDialog) { d = new JDialog((JDialog) w, "Options", true); } else if (w instanceof JFrame) { d = new JDialog((JFrame) w, "Options", true); } else { d = new JDialog((JFrame) null, "Options", true); } final JDialog dialog = d; // Create the bottom button panel final JButton cancel = new JButton("Cancel"); cancel.setMnemonic('c'); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { opts.cancelled = true; dialog.setVisible(false); } }); final JButton ok = new JButton("Ok"); ok.setMnemonic('o'); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (opts.validateTabs()) { dialog.setVisible(false); } } }); dialog.getRootPane().setDefaultButton(ok); JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(6, 6, 0, 0); gbc.weighty = 1.0; UIUtil.jGridBagAdd(buttonPanel, ok, gbc, GridBagConstraints.RELATIVE); UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER); JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); southPanel.add(buttonPanel); // JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPanel.add(opts, BorderLayout.CENTER); mainPanel.add(southPanel, BorderLayout.SOUTH); // Show the dialog dialog.getContentPane().setLayout(new GridLayout(1, 1)); dialog.getContentPane().add(mainPanel); dialog.pack(); dialog.setResizable(true); UIUtil.positionComponent(SwingConstants.CENTER, dialog); dialog.setVisible(true); if (!opts.cancelled) { opts.applyTabs(); } return !opts.cancelled; }
From source file:Main.java
/** * Creates an animation to fade the dialog opacity from 0 to 1. *///from w ww .jav a 2 s . c om public static void fadeIn(final JDialog dialog) { final Timer timer = new Timer(10, null); timer.setRepeats(true); timer.addActionListener(new ActionListener() { private float opacity = 0; @Override public void actionPerformed(ActionEvent e) { opacity += 0.15f; dialog.setOpacity(Math.min(opacity, 1)); if (opacity >= 1) { timer.stop(); } } }); dialog.setOpacity(0); timer.start(); dialog.setVisible(true); }
From source file:Main.java
/** * Displays an {@link JDialog}./*ww w . j a v a 2 s . c o m*/ * * @param parentComponent * @param title * @return */ public static void showDialog(Component parentComponent, JComponent component, String title) { final JDialog dialog; final Window window = getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame) window, title, true); } else { dialog = new JDialog((Dialog) window, title, true); } initDialog(dialog, component, parentComponent); dialog.setLocationRelativeTo(parentComponent); dialog.setVisible(true); }
From source file:Main.java
static public JDialog addModelessWindow(Window mainWindow, Component jpanel, String title) { JDialog dialog; if (mainWindow != null) { dialog = new JDialog(mainWindow, title); } else {/* www . j av a 2s. c om*/ dialog = new JDialog(); dialog.setTitle(title); } dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(jpanel, BorderLayout.CENTER); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.pack(); dialog.setLocationRelativeTo(mainWindow); dialog.setModalityType(ModalityType.MODELESS); dialog.setSize(jpanel.getPreferredSize()); dialog.setVisible(true); return dialog; }
From source file:Main.java
/** * Creates an animation to fade the dialog opacity from 0 to 1. * * @param dialog the dialog to fade in/*ww w .j ava2 s . c o m*/ * @param delay the delay in ms before starting and between each change * @param incrementSize the increment size */ public static void fadeIn(final JDialog dialog, int delay, final float incrementSize) { final Timer timer = new Timer(delay, null); timer.setRepeats(true); timer.addActionListener(new ActionListener() { private float opacity = 0; @Override public void actionPerformed(ActionEvent e) { opacity += incrementSize; dialog.setOpacity(Math.min(opacity, 1)); // requires java 1.7 if (opacity >= 1) { timer.stop(); } } }); dialog.setOpacity(0); // requires java 1.7 timer.start(); dialog.setVisible(true); }
From source file:com.quinsoft.zeidon.utils.JoeUtils.java
public static final void sysMessageBox(String msgTitle, String msgText) { //JOptionPane.showMessageDialog( null, msgText, msgTitle, JOptionPane.PLAIN_MESSAGE ); JOptionPane pane = new JOptionPane(msgText, JOptionPane.INFORMATION_MESSAGE); JDialog dialog = pane.createDialog(msgTitle); dialog.setModalityType(ModalityType.MODELESS); dialog.setAlwaysOnTop(true);//w ww. j av a2 s . c o m dialog.setVisible(true); }
From source file:com.t3.macro.api.functions.input.InputFunctions.java
/** * <pre>//from www. ja v a 2 s . c om * <span style="font-family:sans-serif;">The input() function prompts the user to input several variable values at once. * * Each of the string parameters has the following format: * "varname|value|prompt|inputType|options" * * Only the first section is required. * varname - the variable name to be assigned * value - sets the initial contents of the input field * prompt - UI text shown for the variable * inputType - specifies the type of input field * options - a string of the form "opt1=val1; opt2=val2; ..." * * The inputType field can be any of the following (defaults to TEXT): * TEXT - A text field. * "value" sets the initial contents. * The return value is the string in the text field. * Option: WIDTH=nnn sets the width of the text field (default 16). * LIST - An uneditable combo box. * "value" populates the list, and has the form "item1,item2,item3..." (trailing empty strings are dropped) * The return value is the numeric index of the selected item. * Option: SELECT=nnn sets the initial selection (default 0). * Option: VALUE=STRING returns the string contents of the selected item (default NUMBER). * Option: TEXT=FALSE suppresses the text of the list item (default TRUE). * Option: ICON=TRUE causes icon asset URLs to be extracted from the "value" and displayed (default FALSE). * Option: ICONSIZE=nnn sets the size of the icons (default 50). * CHECK - A checkbox. * "value" sets the initial state of the box (anything but "" or "0" checks the box) * The return value is 0 or 1. * No options. * RADIO - A group of radio buttons. * "value" is a list "name1, name2, name3, ..." which sets the labels of the buttons. * The return value is the index of the selected item. * Option: SELECT=nnn sets the initial selection (default 0). * Option: ORIENT=H causes the radio buttons to be laid out on one line (default V). * Option: VALUE=STRING causes the return value to be the string of the selected item (default NUMBER). * LABEL - A label. * The "varname" is ignored and no value is assigned to it. * Option: TEXT=FALSE, ICON=TRUE, ICONSIZE=nnn, as in the LIST type. * PROPS - A sub-panel with multiple text boxes. * "value" contains a StrProp of the form "key1=val1; key2=val2; ..." * One text box is created for each key, populated with the matching value. * Option: SETVARS=SUFFIXED causes variable assignment to each key name, with appended "_" (default NONE). * Option: SETVARS=UNSUFFIXED causes variable assignment to each key name. * TAB - A tabbed dialog tab is created. Subsequent variables are contained in the tab. * Option: SELECT=TRUE causes this tab to be shown at start (default SELECT=FALSE). * * All inputTypes except TAB accept the option SPAN=TRUE, which causes the prompt to be hidden and the input * control to span both columns of the dialog layout (default FALSE). * </span> * </pre> * @param parameters a list of strings containing information as described above * @return a HashMap with the returned values or null if the user clicked on cancel * @author knizia.fan * @throws MacroException */ public static Map<String, String> input(TokenView token, String... parameters) throws MacroException { // Extract the list of specifier strings from the parameters // "name | value | prompt | inputType | options" List<String> varStrings = new ArrayList<String>(); for (Object param : parameters) { String paramStr = (String) param; if (StringUtils.isEmpty(paramStr)) { continue; } // Multiple vars can be packed into a string, separated by "##" for (String varString : StringUtils.splitByWholeSeparator(paramStr, "##")) { if (StringUtils.isEmpty(paramStr)) { continue; } varStrings.add(varString); } } // Create VarSpec objects from each variable's specifier string List<VarSpec> varSpecs = new ArrayList<VarSpec>(); for (String specifier : varStrings) { VarSpec vs; try { vs = new VarSpec(specifier); } catch (VarSpec.SpecifierException se) { throw new MacroException(se); } catch (InputType.OptionException oe) { throw new MacroException(I18N.getText("macro.function.input.invalidOptionType", oe.key, oe.value, oe.type, specifier)); } varSpecs.add(vs); } // Check if any variables were defined if (varSpecs.isEmpty()) return Collections.emptyMap(); // No work to do, so treat it as a successful invocation. // UI step 1 - First, see if a token is given String dialogTitle = "Input Values"; if (token != null) { String name = token.getName(), gm_name = token.getGMName(); boolean isGM = TabletopTool.getPlayer().isGM(); String extra = ""; if (isGM && gm_name != null && gm_name.compareTo("") != 0) extra = " for " + gm_name; else if (name != null && name.compareTo("") != 0) extra = " for " + name; dialogTitle = dialogTitle + extra; } // UI step 2 - build the panel with the input fields InputPanel ip = new InputPanel(varSpecs); // Calculate the height // TODO: remove this workaround int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int maxHeight = screenHeight * 3 / 4; Dimension ipPreferredDim = ip.getPreferredSize(); if (maxHeight < ipPreferredDim.height) { ip.modifyMaxHeightBy(maxHeight - ipPreferredDim.height); } // UI step 3 - show the dialog JOptionPane jop = new JOptionPane(ip, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); JDialog dlg = jop.createDialog(TabletopTool.getFrame(), dialogTitle); // Set up callbacks needed for desired runtime behavior dlg.addComponentListener(new FixupComponentAdapter(ip)); dlg.setVisible(true); int dlgResult = JOptionPane.CLOSED_OPTION; try { dlgResult = (Integer) jop.getValue(); } catch (NullPointerException npe) { } dlg.dispose(); if (dlgResult == JOptionPane.CANCEL_OPTION || dlgResult == JOptionPane.CLOSED_OPTION) return null; HashMap<String, String> results = new HashMap<String, String>(); // Finally, assign values from the dialog box to the variables for (ColumnPanel cp : ip.columnPanels) { List<VarSpec> panelVars = cp.varSpecs; List<JComponent> panelControls = cp.inputFields; int numPanelVars = panelVars.size(); StringBuilder allAssignments = new StringBuilder(); // holds all values assigned in this tab for (int varCount = 0; varCount < numPanelVars; varCount++) { VarSpec vs = panelVars.get(varCount); JComponent comp = panelControls.get(varCount); String newValue = null; switch (vs.inputType) { case TEXT: { newValue = ((JTextField) comp).getText(); break; } case LIST: { Integer index = ((JComboBox) comp).getSelectedIndex(); if (vs.optionValues.optionEquals("VALUE", "STRING")) { newValue = vs.valueList.get(index); } else { // default is "NUMBER" newValue = index.toString(); } break; } case CHECK: { Integer value = ((JCheckBox) comp).isSelected() ? 1 : 0; newValue = value.toString(); break; } case RADIO: { // This code assumes that the Box container returns components // in the same order that they were added. Component[] comps = ((Box) comp).getComponents(); int componentCount = 0; Integer index = 0; for (Component c : comps) { if (c instanceof JRadioButton) { JRadioButton radio = (JRadioButton) c; if (radio.isSelected()) index = componentCount; } componentCount++; } if (vs.optionValues.optionEquals("VALUE", "STRING")) { newValue = vs.valueList.get(index); } else { // default is "NUMBER" newValue = index.toString(); } break; } case LABEL: { newValue = null; // The variable name is ignored and not set. break; } case PROPS: { // Read out and assign all the subvariables. // The overall return value is a property string (as in StrPropFunctions.java) with all the new settings. Component[] comps = ((JPanel) comp).getComponents(); StringBuilder sb = new StringBuilder(); int setVars = 0; // "NONE", no assignments made if (vs.optionValues.optionEquals("SETVARS", "SUFFIXED")) setVars = 1; if (vs.optionValues.optionEquals("SETVARS", "UNSUFFIXED")) setVars = 2; if (vs.optionValues.optionEquals("SETVARS", "TRUE")) setVars = 2; // for backward compatibility for (int compCount = 0; compCount < comps.length; compCount += 2) { String key = ((JLabel) comps[compCount]).getText().split("\\:")[0]; // strip trailing colon String value = ((JTextField) comps[compCount + 1]).getText(); sb.append(key); sb.append("="); sb.append(value); sb.append(" ; "); switch (setVars) { case 0: // Do nothing break; case 1: results.put(key + "_", value); break; case 2: results.put(key, value); break; } } newValue = sb.toString(); break; } default: // should never happen newValue = null; break; } // Set the variable to the value we got from the dialog box. if (newValue != null) { results.put(vs.name, newValue.trim()); allAssignments.append(vs.name + "=" + newValue.trim() + " ## "); } } if (cp.tabVarSpec != null) { results.put(cp.tabVarSpec.name, allAssignments.toString()); } } return results; // success // for debugging: //return debugOutput(varSpecs); }
From source file:org.duracloud.syncui.SyncUIDriver.java
/** * Note: The embedded Jetty server setup below is based on the example configuration in the Eclipse documentation: * https://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html#embedded-webapp-jsp *//*from w w w.j av a 2 s . co m*/ private static void launchServer(final String url, final CloseableHttpClient client) { try { final JDialog dialog = new JDialog(); dialog.setSize(new java.awt.Dimension(400, 75)); dialog.setModalityType(ModalityType.MODELESS); dialog.setTitle("DuraCloud Sync"); dialog.setLocationRelativeTo(null); JPanel panel = new JPanel(); final JLabel label = new JLabel("Loading..."); final JProgressBar progress = new JProgressBar(); progress.setStringPainted(true); panel.add(label); panel.add(progress); dialog.add(panel); dialog.setVisible(true); port = SyncUIConfig.getPort(); contextPath = SyncUIConfig.getContextPath(); Server srv = new Server(port); // Setup JMX MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); srv.addBean(mbContainer); ProtectionDomain protectionDomain = org.duracloud.syncui.SyncUIDriver.class.getProtectionDomain(); String warFile = protectionDomain.getCodeSource().getLocation().toExternalForm(); log.debug("warfile: {}", warFile); WebAppContext context = new WebAppContext(); context.setContextPath(contextPath); context.setWar(warFile); context.setExtractWAR(Boolean.TRUE); Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(srv); classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration"); context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$"); srv.setHandler(context); new Thread(new Runnable() { @Override public void run() { createSysTray(url, srv); while (true) { if (progress.getValue() < 100) { progress.setValue(progress.getValue() + 3); } sleep(2000); if (isAppRunning(url, client)) { break; } } progress.setValue(100); label.setText("Launching browser..."); launchBrowser(url); dialog.setVisible(false); } }).start(); srv.start(); srv.join(); } catch (Exception e) { log.error("Error launching server: " + e.getMessage(), e); } }
From source file:Main.java
/** * Displays the given file chooser. Utility method for avoiding of memory leak in JDK * 1.3 {@link javax.swing.JFileChooser#showDialog}. * * @param chooser the file chooser to display. * @param parent the parent window./*w ww . ja v a2s . c o m*/ * @param approveButtonText the text for the approve button. * * @return the return code of the chooser. */ public static final int showJFileChooser(JFileChooser chooser, Component parent, String approveButtonText) { if (approveButtonText != null) { chooser.setApproveButtonText(approveButtonText); chooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG); } Frame frame = (parent instanceof Frame) ? (Frame) parent : (Frame) javax.swing.SwingUtilities.getAncestorOfClass(java.awt.Frame.class, parent); String title = chooser.getDialogTitle(); if (title == null) { title = chooser.getUI().getDialogTitle(chooser); } final JDialog dialog = new JDialog(frame, title, true); dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(chooser, BorderLayout.CENTER); dialog.pack(); dialog.setLocationRelativeTo(parent); chooser.rescanCurrentDirectory(); final int[] retValue = new int[] { javax.swing.JFileChooser.CANCEL_OPTION }; ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent ev) { if (ev.getActionCommand() == JFileChooser.APPROVE_SELECTION) { retValue[0] = JFileChooser.APPROVE_OPTION; } dialog.setVisible(false); dialog.dispose(); } }; chooser.addActionListener(l); dialog.show(); return (retValue[0]); }
From source file:com.sshtools.common.ui.SshToolsConnectionPanel.java
/** * * * @param parent/*from w w w .ja v a2 s . c o m*/ * @param profile * @param optionalTabs * * @return */ public static SshToolsConnectionProfile showConnectionDialog(Component parent, SshToolsConnectionProfile profile, SshToolsConnectionTab[] optionalTabs) { // If no properties are provided, then use the default if (profile == null) { int port = DEFAULT_PORT; String port_S = Integer.toString(DEFAULT_PORT); port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S); try { port = Integer.parseInt(port_S); } catch (NumberFormatException e) { log.warn("Could not parse the port number from defaults file (property name" + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ")."); } profile = new SshToolsConnectionProfile(); profile.setHost(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_HOST, "")); profile.setPort(PreferencesStore.getInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, port)); profile.setUsername(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_USER, "")); } final SshToolsConnectionPanel conx = new SshToolsConnectionPanel(true); if (optionalTabs != null) { for (int i = 0; i < optionalTabs.length; i++) { conx.addTab(optionalTabs[i]); } } conx.setConnectionProfile(profile); JDialog d = null; Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent); if (w instanceof JDialog) { d = new JDialog((JDialog) w, "Connection Profile", true); } else if (w instanceof JFrame) { d = new JDialog((JFrame) w, "Connection Profile", true); } else { d = new JDialog((JFrame) null, "Connection Profile", true); } final JDialog dialog = d; class UserAction { boolean connect; } final UserAction userAction = new UserAction(); // Create the bottom button panel final JButton cancel = new JButton("Cancel"); cancel.setMnemonic('c'); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { userAction.connect = false; dialog.setVisible(false); } }); final JButton connect = new JButton("Connect"); connect.setMnemonic('t'); connect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (conx.validateTabs()) { userAction.connect = true; dialog.setVisible(false); } } }); dialog.getRootPane().setDefaultButton(connect); JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(6, 6, 0, 0); gbc.weighty = 1.0; UIUtil.jGridBagAdd(buttonPanel, connect, gbc, GridBagConstraints.RELATIVE); UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER); JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0)); southPanel.add(buttonPanel); // JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPanel.add(conx, BorderLayout.CENTER); mainPanel.add(southPanel, BorderLayout.SOUTH); // Show the dialog dialog.getContentPane().setLayout(new GridLayout(1, 1)); dialog.getContentPane().add(mainPanel); dialog.pack(); dialog.setResizable(false); UIUtil.positionComponent(SwingConstants.CENTER, dialog); //show the simple box and act on the answer. SshToolsSimpleConnectionPrompt stscp = SshToolsSimpleConnectionPrompt.getInstance(); StringBuffer sb = new StringBuffer(); userAction.connect = !stscp.getHostname(sb, profile.getHost()); boolean advanced = stscp.getAdvanced(); if (advanced) { userAction.connect = false; profile.setHost(sb.toString()); conx.hosttab.setConnectionProfile(profile); dialog.setVisible(true); } // Make sure we didn't cancel if (!userAction.connect) { return null; } conx.applyTabs(); if (!advanced) profile.setHost(sb.toString()); if (!advanced) { int port = DEFAULT_PORT; String port_S = Integer.toString(DEFAULT_PORT); port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S); try { port = Integer.parseInt(port_S); } catch (NumberFormatException e) { log.warn("Could not parse the port number from defaults file (property name" + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ")."); } profile.setPort(port); } if (!advanced) profile.setUsername(""); PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_HOST, profile.getHost()); // only save user inputed configuration if (advanced) { PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_USER, profile.getUsername()); PreferencesStore.putInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, profile.getPort()); } // Return the connection properties return profile; }