List of usage examples for javax.swing JDialog setVisible
public void setVisible(boolean b)
From source file:org.accada.hal.impl.sim.GraphicSimulator.java
/** * creates the help menu item if it does not already exists * /*from w ww.j av a 2 s . co m*/ * @return help menu */ private JMenu getHelpMenu() { JMenu helpMenu = new JMenu(guiTextConfig.getString("HelpMenuItem")); // about JMenuItem aboutMenuItem = new JMenuItem(); aboutMenuItem.setText(guiTextConfig.getString("AboutMenuItem")); aboutMenuItem.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { JDialog aboutDialog = new JDialog(GraphicSimulator.this, guiTextConfig.getString("AboutDialogTitle"), true); Point pos = new Point(); pos.x = jLayeredPane.getLocationOnScreen().x + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2; pos.y = jLayeredPane.getLocationOnScreen().y + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2; aboutDialog.setLocation(pos); aboutDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight")); aboutDialog.setTitle(guiTextConfig.getString("AboutDialogTitle")); JLabel text = new JLabel(guiTextConfig.getString("AboutDialogContent")); text.setHorizontalAlignment(JLabel.CENTER); aboutDialog.add(text); aboutDialog.setVisible(true); } }); helpMenu.add(aboutMenuItem); return helpMenu; }
From source file:org.accada.hal.impl.sim.multi.GraphicSimulatorServer.java
/** * creates the help menu item/*w w w. j a v a2 s .c om*/ * * @return help menu */ private JMenu getHelpMenu() { JMenu helpMenu = new JMenu(guiTextConfig.getString("HelpMenuItem")); // about JMenuItem aboutMenuItem = new JMenuItem(); aboutMenuItem.setText(guiTextConfig.getString("AboutMenuItem")); aboutMenuItem.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { JDialog aboutDialog = new JDialog(GraphicSimulatorServer.this, guiTextConfig.getString("AboutDialogTitle"), true); Point pos = new Point(); pos.x = jLayeredPane.getLocationOnScreen().x + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2; pos.y = jLayeredPane.getLocationOnScreen().y + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2; aboutDialog.setLocation(pos); aboutDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight")); aboutDialog.setTitle(guiTextConfig.getString("AboutDialogTitle")); JLabel text = new JLabel(guiTextConfig.getString("AboutDialogContent")); text.setHorizontalAlignment(JLabel.CENTER); aboutDialog.add(text); aboutDialog.setVisible(true); } }); helpMenu.add(aboutMenuItem); return helpMenu; }
From source file:org.accada.reader.hal.impl.sim.GraphicSimulator.java
/** * creates the help menu item if it does not already exists * /* w w w .jav a 2 s . c o m*/ * @return help menu */ private JMenu getHelpMenu() { JMenu helpMenu = new JMenu(guiText.getString("HelpMenuItem")); // about JMenuItem aboutMenuItem = new JMenuItem(); aboutMenuItem.setText(guiText.getString("AboutMenuItem")); aboutMenuItem.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { JDialog aboutDialog = new JDialog(GraphicSimulator.this, guiText.getString("AboutDialogTitle"), true); Point pos = new Point(); pos.x = jLayeredPane.getLocationOnScreen().x + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2; pos.y = jLayeredPane.getLocationOnScreen().y + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2; aboutDialog.setLocation(pos); aboutDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight")); aboutDialog.setTitle(guiText.getString("AboutDialogTitle")); JLabel text = new JLabel(guiText.getString("AboutDialogContent")); text.setHorizontalAlignment(JLabel.CENTER); aboutDialog.add(text); aboutDialog.setVisible(true); } }); helpMenu.add(aboutMenuItem); return helpMenu; }
From source file:org.accada.reader.hal.impl.sim.multi.GraphicSimulatorServer.java
/** * creates the help menu item//from w w w . j a v a2s. c o m * * @return help menu */ private JMenu getHelpMenu() { JMenu helpMenu = new JMenu(guiText.getString("HelpMenuItem")); // about JMenuItem aboutMenuItem = new JMenuItem(); aboutMenuItem.setText(guiText.getString("AboutMenuItem")); aboutMenuItem.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { JDialog aboutDialog = new JDialog(GraphicSimulatorServer.this, guiText.getString("AboutDialogTitle"), true); Point pos = new Point(); pos.x = jLayeredPane.getLocationOnScreen().x + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2; pos.y = jLayeredPane.getLocationOnScreen().y + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2; aboutDialog.setLocation(pos); aboutDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight")); aboutDialog.setTitle(guiText.getString("AboutDialogTitle")); JLabel text = new JLabel(guiText.getString("AboutDialogContent")); text.setHorizontalAlignment(JLabel.CENTER); aboutDialog.add(text); aboutDialog.setVisible(true); } }); helpMenu.add(aboutMenuItem); return helpMenu; }
From source file:org.apache.cayenne.modeler.util.CayenneController.java
/** * If this view or a parent view is a JDialog, makes it closeable on ESC hit. Dialog * "defaultCloseOperation" property is taken into account when processing ESC button * click./*from ww w . j av a 2 s. c o m*/ */ protected void makeCloseableOnEscape() { Window window = getWindow(); if (!(window instanceof JDialog)) { return; } final JDialog dialog = (JDialog) window; KeyStroke escReleased = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true); ActionListener closeAction = new ActionListener() { public void actionPerformed(ActionEvent e) { if (dialog.isVisible()) { switch (dialog.getDefaultCloseOperation()) { case JDialog.HIDE_ON_CLOSE: dialog.setVisible(false); break; case JDialog.DISPOSE_ON_CLOSE: dialog.setVisible(false); dialog.dispose(); break; case JDialog.DO_NOTHING_ON_CLOSE: default: break; } } } }; dialog.getRootPane().registerKeyboardAction(closeAction, escReleased, JComponent.WHEN_IN_FOCUSED_WINDOW); }
From source file:org.apache.log4j.chainsaw.LogUI.java
/** * Displays a dialog which will provide options for selecting a configuration *//*from w w w . ja v a2 s.c o m*/ private void showReceiverConfigurationPanel() { SwingUtilities.invokeLater(new Runnable() { public void run() { final JDialog dialog = new JDialog(LogUI.this, true); dialog.setTitle("Load events into Chainsaw"); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.setResizable(false); receiverConfigurationPanel.setCompletionActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); if (receiverConfigurationPanel.getModel().isCancelled()) { return; } applicationPreferenceModel .setShowNoReceiverWarning(!receiverConfigurationPanel.isDontWarnMeAgain()); //remove existing plugins List plugins = pluginRegistry.getPlugins(); for (Iterator iter = plugins.iterator(); iter.hasNext();) { Plugin plugin = (Plugin) iter.next(); //don't stop ZeroConfPlugin if it is registered if (!plugin.getName().toLowerCase(Locale.ENGLISH).contains("zeroconf")) { pluginRegistry.stopPlugin(plugin.getName()); } } URL configURL = null; if (receiverConfigurationPanel.getModel().isNetworkReceiverMode()) { int port = receiverConfigurationPanel.getModel().getNetworkReceiverPort(); try { Class receiverClass = receiverConfigurationPanel.getModel() .getNetworkReceiverClass(); Receiver networkReceiver = (Receiver) receiverClass.newInstance(); networkReceiver.setName(receiverClass.getSimpleName() + "-" + port); Method portMethod = networkReceiver.getClass().getMethod("setPort", new Class[] { int.class }); portMethod.invoke(networkReceiver, new Object[] { new Integer(port) }); networkReceiver.setThreshold(Level.TRACE); pluginRegistry.addPlugin(networkReceiver); networkReceiver.activateOptions(); receiversPanel.updateReceiverTreeInDispatchThread(); } catch (Exception e3) { MessageCenter.getInstance().getLogger().error("Error creating Receiver", e3); MessageCenter.getInstance().getLogger() .info("An error occurred creating your Receiver"); } } else if (receiverConfigurationPanel.getModel().isLog4jConfig()) { File log4jConfigFile = receiverConfigurationPanel.getModel().getLog4jConfigFile(); if (log4jConfigFile != null) { try { Map entries = LogFilePatternLayoutBuilder .getAppenderConfiguration(log4jConfigFile); for (Iterator iter = entries.entrySet().iterator(); iter.hasNext();) { try { Map.Entry entry = (Map.Entry) iter.next(); String name = (String) entry.getKey(); Map values = (Map) entry.getValue(); //values: conversion, file String conversionPattern = values.get("conversion").toString(); File file = new File(values.get("file").toString()); URL fileURL = file.toURI().toURL(); String timestampFormat = LogFilePatternLayoutBuilder .getTimeStampFormat(conversionPattern); String receiverPattern = LogFilePatternLayoutBuilder .getLogFormatFromPatternLayout(conversionPattern); VFSLogFilePatternReceiver fileReceiver = new VFSLogFilePatternReceiver(); fileReceiver.setName(name); fileReceiver.setAutoReconnect(true); fileReceiver.setContainer(LogUI.this); fileReceiver.setAppendNonMatches(true); fileReceiver.setFileURL(fileURL.toURI().toString()); fileReceiver.setTailing(true); fileReceiver.setLogFormat(receiverPattern); fileReceiver.setTimestampFormat(timestampFormat); fileReceiver.setThreshold(Level.TRACE); pluginRegistry.addPlugin(fileReceiver); fileReceiver.activateOptions(); receiversPanel.updateReceiverTreeInDispatchThread(); } catch (URISyntaxException e1) { e1.printStackTrace(); } } } catch (IOException e1) { e1.printStackTrace(); } } } else if (receiverConfigurationPanel.getModel().isLoadConfig()) { configURL = receiverConfigurationPanel.getModel().getConfigToLoad(); } else if (receiverConfigurationPanel.getModel().isLogFileReceiverConfig()) { try { URL fileURL = receiverConfigurationPanel.getModel().getLogFileURL(); if (fileURL != null) { VFSLogFilePatternReceiver fileReceiver = new VFSLogFilePatternReceiver(); fileReceiver.setName(fileURL.getFile()); fileReceiver.setAutoReconnect(true); fileReceiver.setContainer(LogUI.this); fileReceiver.setAppendNonMatches(true); fileReceiver.setFileURL(fileURL.toURI().toString()); fileReceiver.setTailing(true); if (receiverConfigurationPanel.getModel().isPatternLayoutLogFormat()) { fileReceiver.setLogFormat( LogFilePatternLayoutBuilder.getLogFormatFromPatternLayout( receiverConfigurationPanel.getModel().getLogFormat())); } else { fileReceiver .setLogFormat(receiverConfigurationPanel.getModel().getLogFormat()); } fileReceiver.setTimestampFormat( receiverConfigurationPanel.getModel().getLogFormatTimestampFormat()); fileReceiver.setThreshold(Level.TRACE); pluginRegistry.addPlugin(fileReceiver); fileReceiver.activateOptions(); receiversPanel.updateReceiverTreeInDispatchThread(); } } catch (Exception e2) { MessageCenter.getInstance().getLogger().error("Error creating Receiver", e2); MessageCenter.getInstance().getLogger() .info("An error occurred creating your Receiver"); } } if (configURL == null && receiverConfigurationPanel.isDontWarnMeAgain()) { //use the saved config file as the config URL if defined if (receiverConfigurationPanel.getModel().getSaveConfigFile() != null) { try { configURL = receiverConfigurationPanel.getModel().getSaveConfigFile().toURI() .toURL(); } catch (MalformedURLException e1) { e1.printStackTrace(); } } else { //no saved config defined but don't warn me is checked - use default config configURL = receiverConfigurationPanel.getModel().getDefaultConfigFileURL(); } } if (configURL != null) { MessageCenter.getInstance().getLogger() .debug("Initialiazing Log4j with " + configURL.toExternalForm()); final URL finalURL = configURL; new Thread(new Runnable() { public void run() { if (receiverConfigurationPanel.isDontWarnMeAgain()) { applicationPreferenceModel.setConfigurationURL(finalURL.toExternalForm()); } else { try { if (new File(finalURL.toURI()).exists()) { loadConfigurationUsingPluginClassLoader(finalURL); } } catch (URISyntaxException e) { //ignore } } receiversPanel.updateReceiverTreeInDispatchThread(); } }).start(); } File saveConfigFile = receiverConfigurationPanel.getModel().getSaveConfigFile(); if (saveConfigFile != null) { ReceiversHelper.getInstance().saveReceiverConfiguration(saveConfigFile); } } }); receiverConfigurationPanel.setDialog(dialog); dialog.getContentPane().add(receiverConfigurationPanel); dialog.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); dialog.setLocation((screenSize.width / 2) - (dialog.getWidth() / 2), (screenSize.height / 2) - (dialog.getHeight() / 2)); dialog.setVisible(true); } }); }
From source file:org.apache.marmotta.splash.common.ui.MessageDialog.java
public static void show(String title, String message, String description) { final JDialog dialog = new JDialog((Frame) null, title); dialog.setModal(true);/*from w w w .j a va 2 s. c o m*/ dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); final JPanel root = new JPanel(new GridBagLayout()); root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); dialog.getRootPane().setContentPane(root); final JButton close = new JButton("OK"); close.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }); GridBagConstraints cClose = new GridBagConstraints(); cClose.gridx = 0; cClose.gridy = 2; cClose.gridwidth = 2; cClose.weightx = 1; cClose.weighty = 0; cClose.insets = new Insets(5, 5, 5, 5); root.add(close, cClose); dialog.getRootPane().setDefaultButton(close); Icon icon = loadIcon(MARMOTTA_ICON); if (icon != null) { JLabel lblIcn = new JLabel(icon); GridBagConstraints cIcon = new GridBagConstraints(); cIcon.gridx = 1; cIcon.gridy = 0; cIcon.gridheight = 2; cIcon.fill = GridBagConstraints.NONE; cIcon.weightx = 0; cIcon.weighty = 1; cIcon.anchor = GridBagConstraints.NORTH; cIcon.insets = new Insets(10, 5, 5, 0); root.add(lblIcn, cIcon); } JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>")); lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f)); GridBagConstraints cLabel = new GridBagConstraints(); cLabel.gridx = 0; cLabel.gridy = 0; cLabel.fill = GridBagConstraints.BOTH; cLabel.weightx = 1; cLabel.weighty = 0.5; cLabel.insets = new Insets(5, 5, 5, 5); root.add(lblMsg, cLabel); JLabel lblDescr = new JLabel( "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>")); cLabel.gridy++; cLabel.insets = new Insets(0, 5, 5, 5); root.add(lblDescr, cLabel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.dispose(); }
From source file:org.apache.marmotta.splash.common.ui.SelectionDialog.java
public static int select(String title, String message, String description, List<Option> options, int defaultOption) { final JDialog dialog = new JDialog((Frame) null, title); dialog.setModal(true);/*from ww w. j a v a2 s . c om*/ dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); final AtomicInteger result = new AtomicInteger(Math.max(defaultOption, -1)); JButton defaultBtn = null; final JPanel root = new JPanel(new GridBagLayout()); root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); dialog.getRootPane().setContentPane(root); JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>")); lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f)); GridBagConstraints cLabel = new GridBagConstraints(); cLabel.gridx = 0; cLabel.gridy = 0; cLabel.fill = GridBagConstraints.BOTH; cLabel.weightx = 1; cLabel.weighty = 0.5; cLabel.insets = new Insets(5, 5, 5, 5); root.add(lblMsg, cLabel); JLabel lblDescr = new JLabel( "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>")); cLabel.gridy++; cLabel.insets = new Insets(0, 5, 5, 5); root.add(lblDescr, cLabel); // All the options cLabel.ipadx = 10; cLabel.ipady = 10; cLabel.insets = new Insets(5, 15, 0, 15); for (int i = 0; i < options.size(); i++) { cLabel.gridy++; final Option o = options.get(i); final JButton btn = new JButton( "<html>" + StringEscapeUtils.escapeHtml3(o.label).replaceAll("\\n", "<br>"), MessageDialog.loadIcon(o.icon)); if (StringUtils.isNotBlank(o.info)) { btn.setToolTipText("<html>" + StringEscapeUtils.escapeHtml3(o.info).replaceAll("\\n", "<br>")); } btn.setHorizontalAlignment(AbstractButton.LEADING); btn.setVerticalTextPosition(AbstractButton.CENTER); btn.setHorizontalTextPosition(AbstractButton.TRAILING); final int myAnswer = i; btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { result.set(myAnswer); dialog.setVisible(false); } }); root.add(btn, cLabel); if (i == defaultOption) { dialog.getRootPane().setDefaultButton(btn); defaultBtn = btn; } } final Icon icon = MessageDialog.loadIcon(); if (icon != null) { JLabel lblIcn = new JLabel(icon); GridBagConstraints cIcon = new GridBagConstraints(); cIcon.gridx = 1; cIcon.gridy = 0; cIcon.gridheight = 2 + options.size(); cIcon.fill = GridBagConstraints.NONE; cIcon.weightx = 0; cIcon.weighty = 1; cIcon.anchor = GridBagConstraints.NORTH; cIcon.insets = new Insets(10, 5, 5, 0); root.add(lblIcn, cIcon); } final JButton close = new JButton("Cancel"); close.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { result.set(-1); dialog.setVisible(false); } }); GridBagConstraints cClose = new GridBagConstraints(); cClose.gridx = 0; cClose.gridy = 2 + options.size(); cClose.gridwidth = 2; cClose.weightx = 1; cClose.weighty = 0; cClose.insets = new Insets(15, 5, 5, 5); root.add(close, cClose); if (defaultOption < 0) { dialog.getRootPane().setDefaultButton(close); defaultBtn = close; } dialog.pack(); dialog.setLocationRelativeTo(null); defaultBtn.requestFocusInWindow(); dialog.setVisible(true); dialog.dispose(); return result.get(); }
From source file:org.apache.tika.gui.TikaGUI.java
private void handleError(String name, Throwable t) { StringWriter writer = new StringWriter(); writer.append("Apache Tika was unable to parse the document\n"); writer.append("at " + name + ".\n\n"); writer.append("The full exception stack trace is included below:\n\n"); t.printStackTrace(new PrintWriter(writer)); JEditorPane editor = new JEditorPane("text/plain", writer.toString()); editor.setEditable(false);// w ww .ja v a 2 s . co m editor.setBackground(Color.WHITE); editor.setCaretPosition(0); editor.setPreferredSize(new Dimension(600, 400)); JDialog dialog = new JDialog(this, "Apache Tika error"); dialog.add(new JScrollPane(editor)); dialog.pack(); dialog.setVisible(true); }
From source file:org.apache.tika.gui.TikaGUI.java
private void textDialog(String title, URL resource) { try {/* w w w.j ava2 s .co m*/ JDialog dialog = new JDialog(this, title); JEditorPane editor = new JEditorPane(resource); editor.setContentType("text/html"); editor.setEditable(false); editor.setBackground(Color.WHITE); editor.setPreferredSize(new Dimension(400, 250)); editor.addHyperlinkListener(this); dialog.add(editor); dialog.pack(); dialog.setVisible(true); } catch (IOException e) { e.printStackTrace(); } }