/** * Shows the dialog. First a dialog must be constructed using one of the constructors of this * class. After that this method should be called to actually show the dialog. This method returns * either JOptionPane.OK_OPTION if the user wants to select his choices or * JOptionPane.CANCEL_OPTION if he does not want to. * * @param parent The parent frame of this dialog. * @return int The returnvalue, can be either JOptionPane.OK_OPTION or JOptionPane.CANCEL_OPTION */ public int showDialog(Component parent) { Frame frame = parent instanceof Frame ? (Frame) parent : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); // String title = getUI().getDialogTitle(this); dialog = new JDialog(frame, title, true); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(this, BorderLayout.CENTER); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { cancel(); } }); dialog.pack(); dialog.setLocationRelativeTo(parent); dialog.setVisible(true); return returnValue; }
/** * Sets the dialog for this service to the specified dialog. * * @param dialog The dialog for this service to maintain. */ protected void setDialog(JDialog dialog) { this.dialog = dialog; dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { dispose(); } }); JRootPane root = dialog.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "closeDialog"); root.getActionMap() .put( "closeDialog", new AbstractAction() { private static final long serialVersionUID = 2759447330549410101L; @Override public void actionPerformed(ActionEvent e) { BaseService.this.dispose(); } }); root.setDefaultButton(defaultButton); }
/** * This method initializes jDialog * * @return javax.swing.JDialog */ private JDialog getJDialog() { if (jDialog == null) { jDialog = new JDialog(); jDialog.setContentPane(getJContentPane()); jDialog.setTitle(title); jDialog.setSize(this.getWidth() + 5, this.getHeight() + 35); jDialog.setLayout(new BorderLayout()); jDialog.getContentPane().add(this, BorderLayout.CENTER); jDialog.setModal(true); jDialog.setAlwaysOnTop(true); GuiUtils.centerOnScreen(jDialog); jDialog.setResizable(false); jDialog.setAlwaysOnTop(true); jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); jDialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { JOptionPane.showMessageDialog(jDialog, "You must enter a password!"); } }); // getJContentPane().paintImmediately(0, 0, 300, 300); jDialog.setIconImage(ImageUtils.getImage("images/neptus-icon.png")); jDialog.toFront(); jDialog.setFocusTraversalPolicy(new PasswordPanelFocusTraversalPolicy()); jDialog.setVisible(true); } return jDialog; }
private void init(String title) { diag = new JDialog(frame, title, false); preview = new PreviewPanel(null, new MetaData(), Globals.prefs.get("preview1")); sortedEntries = new SortedList<BibtexEntry>(entries, new EntryComparator(false, true, "author")); model = new EventTableModel<BibtexEntry>(sortedEntries, new EntryTableFormat()); entryTable = new JTable(model); GeneralRenderer renderer = new GeneralRenderer(Color.white); entryTable.setDefaultRenderer(JLabel.class, renderer); entryTable.setDefaultRenderer(String.class, renderer); setWidths(); TableComparatorChooser<BibtexEntry> tableSorter = new TableComparatorChooser<BibtexEntry>( entryTable, sortedEntries, TableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); setupComparatorChooser(tableSorter); JScrollPane sp = new JScrollPane(entryTable); EventSelectionModel<BibtexEntry> selectionModel = new EventSelectionModel<BibtexEntry>(sortedEntries); entryTable.setSelectionModel(selectionModel); selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); entryTable.addMouseListener(new TableClickListener()); contentPane.setTopComponent(sp); contentPane.setBottomComponent(preview); // Key bindings: AbstractAction closeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { diag.dispose(); } }; ActionMap am = contentPane.getActionMap(); InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.prefs.getKey("Close dialog"), "close"); am.put("close", closeAction); diag.addWindowListener( new WindowAdapter() { public void windowOpened(WindowEvent e) { contentPane.setDividerLocation(0.5f); } public void windowClosing(WindowEvent event) { Globals.prefs.putInt("searchDialogWidth", diag.getSize().width); Globals.prefs.putInt("searchDialogHeight", diag.getSize().height); } }); diag.getContentPane().add(contentPane, BorderLayout.CENTER); // Remember and default to last size: diag.setSize( new Dimension( Globals.prefs.getInt("searchDialogWidth"), Globals.prefs.getInt("searchDialogHeight"))); diag.setLocationRelativeTo(frame); }
public static void main(String[] args) { JDialog dialog = new JDialog(); JPanel_MemoryUsage panel = new JPanel_MemoryUsage("./"); dialog.getContentPane().add(panel); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setSize(500, 300); dialog.addWindowListener(panel); dialog.setVisible(true); }
public Object showWindow(final MkWindow macWindow, String title, boolean isModal) { listMkWindow.add(macWindow); if (isModal) { JDialog modalFrame = new JDialog(this, title, true); // macWindow.setJanela(modalFrame); final MkRun onCloseWindow = macWindow.onCloseWindow; modalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); modalFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { if (onCloseWindow != null) { onCloseWindow.execute(); } disposeWindow(macWindow); } }); modalFrame.setLayout(new BorderLayout()); modalFrame.add(macWindow, BorderLayout.CENTER); modalFrame.pack(); Dimension desktopSize = desktopPane.getSize(); int x = (desktopSize.width - modalFrame.getWidth()) / 2; int y = (desktopSize.height - modalFrame.getHeight()) / 2; modalFrame.setLocation((x < 0 ? 0 : x), (y < 0 ? 0 : y)); if (macWindow.panelButton != null) { modalFrame.getRootPane().setDefaultButton((JButton) macWindow.panelButton.getComponent(0)); } modalFrame.setVisible(true); return modalFrame; } else { JInternalFrame internalFrame = new JInternalFrame(title, true, true, true, true); internalFrame.setContentPane(macWindow); internalFrame.pack(); // internalFrame.setBounds(internalFrame.getBounds()); //pq? desktopPane.add(internalFrame); internalFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); final MkRun onCloseWindow = macWindow.onCloseWindow; if (onCloseWindow != null) { internalFrame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); internalFrame.addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameClosing(InternalFrameEvent e) { onCloseWindow.execute(); } }); } Dimension desktopSize = desktopPane.getSize(); int x = (desktopSize.width - internalFrame.getWidth()) / 2; int y = (desktopSize.height - internalFrame.getHeight()) / 2; internalFrame.setLocation((x < 0 ? 0 : x), (y < 0 ? 0 : y)); internalFrame.setVisible(true); return internalFrame; } }
public WhenDialogClosed(JDialog dialog) { dialog.addWindowListener( new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { doThis(); } }); }
private void editButton() { JDialog dialog = new JDialog(); dialog.getContentPane().add(new EditPersonSkillsPanel(connection, person)); dialog.setBounds(100, 100, 550, 400); dialog.setTitle("Change Skills"); dialog.setVisible(true); dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); dialog.addWindowListener(new EditWindowListener()); dialog.setModal(true); }
public void actionPerformed(ActionEvent e) { JColorChooser colorChooser = BasicComponentFactory.createColorChooser(bufferedColorModel); ActionListener okHandler = new OKHandler(trigger); JDialog dialog = JColorChooser.createDialog(parent, "Choose Color", true, colorChooser, okHandler, null); dialog.addWindowListener(new Closer()); dialog.addComponentListener(new DisposeOnClose()); dialog.setVisible(true); // blocks until user brings dialog down... }
public EventDialog(Frame frame, String title) { super(frame, title, true); try { jbInit(); pack(); } catch (Exception ex) { new ExceptionDialog(ex); } super.addWindowListener(this); }
private void initializeDlg() { if (pst.isEmbeddedView()) { return; } JDialog dlg = (JDialog) parentContainer; dlg.add(viewLayout.mainPanel, BorderLayout.CENTER); // SwingUtils.locateOnScreenCenter(dlg); SwingUtils.locateRelativeToMenu(dlg); dlg.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dlg.addWindowListener( new java.awt.event.WindowAdapter() { // todo ver cómo se va a hacer esto en la versión Filthy public void windowOpened(WindowEvent e) { if (pst != null) { pst.onWindowsOpened(e); pst.onWindowsOpenedInternalOnlyForAWFW(e); if (!pst.isReadOnly()) { // pst.setFocusToCmpOnWindowOpen(); // // ActionManager.instance().getVisualMgrForActions().repaintMainDisabledActions(pst.getActionRsr()); } else { pst.configureAsReanOnly(); JButton btnCancel = (JButton) pst.getIpView().getComponent("btnCancel"); if (btnCancel != null) { btnCancel.requestFocusInWindow(); } } } } public void windowClosing(WindowEvent e) { MsgDisplayer.showMessage("sw.common.closeWindowDisabled"); } public void windowActivated(WindowEvent e) { Object oppositeWindow = e.getOppositeWindow(); if (oppositeWindow instanceof DlgMensaje) { logger.debug("Ignoring Windows activated for DlgMensaje"); return; } if (oppositeWindow instanceof JDialog) { JDialog dlg = (JDialog) oppositeWindow; if (MessageDisplayer.GENERIC_MESSAGE_TITLE.equals(dlg.getTitle())) { logger.debug("Ignoring Windows activated for System Msg"); return; } } logger.debug("Windows Activated:" + pst); AWWindowsManager.instance().setPresenterActivated(pst); } }); }
public static Color showCommonJColorChooserDialog( Component component, String title, Color initialColor) throws HeadlessException { final JColorChooser pane = getCommonJColorChooser(); pane.setColor(initialColor); ColorTracker ok = new ColorTracker(pane); JDialog dialog = JColorChooser.createDialog(component, title, true, pane, ok, null); dialog.addWindowListener(new Closer()); dialog.addComponentListener(new DisposeOnClose()); dialog.show(); // blocks until user brings dialog down... return ok.getColor(); }
public static JDialog createDialog(JComponent parent, OWLEditorKit editorKit) { JFrame parentFrame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, parent); final JDialog dialog = new JDialog(parentFrame, "Search", Dialog.ModalityType.MODELESS); final SearchDialogPanel searchDialogPanel = new SearchDialogPanel(editorKit); searchDialogPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); searchDialogPanel .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "CLOSE_DIALOG"); searchDialogPanel .getActionMap() .put( "CLOSE_DIALOG", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }); searchDialogPanel .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "CLOSE_DIALOG_WITH_ENTER"); searchDialogPanel .getActionMap() .put( "CLOSE_DIALOG_WITH_ENTER", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.setVisible(false); searchDialogPanel.selectEntity(); } }); dialog.setContentPane(searchDialogPanel); dialog.setResizable(true); dialog.pack(); dialog.addWindowListener( new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { searchDialogPanel.searchField.requestFocusInWindow(); } }); return dialog; }
/** * Creates a window which contains the toolbar after it has been dragged out from its container * * <p>DAVE: Removed the custom root pane stuff as this was preventing user- resize... also removed * the setResizable( false ) for same reason. * * @return a <code>RootPaneContainer</code> object, containing the toolbar. * @since 1.4 */ protected RootPaneContainer createFloatingWindow(JToolBar toolbar) { class ToolBarDialog extends JDialog { public ToolBarDialog(Frame owner, String title, boolean modal) { super(owner, title, modal); } public ToolBarDialog(Dialog owner, String title, boolean modal) { super(owner, title, modal); } // Override createRootPane() to automatically resize // the frame when contents change protected JRootPane createRootPane() { JRootPane rootPane = new JRootPane(); // { // private boolean packing = false; // // public void validate() { // super.validate(); // if (!packing) { // packing = true; // pack(); // packing = false; // } // } // }; rootPane.setOpaque(true); return rootPane; } } JDialog dialog; Window window = SwingUtilities.getWindowAncestor(toolbar); if (window instanceof Frame) { dialog = new ToolBarDialog((Frame) window, toolbar.getName(), false); } else if (window instanceof Dialog) { dialog = new ToolBarDialog((Dialog) window, toolbar.getName(), false); } else { dialog = new ToolBarDialog((Frame) null, toolbar.getName(), false); } dialog.getRootPane().setName("ToolBar.FloatingWindow"); dialog.setTitle(toolbar.getName()); // dialog.setResizable(false); WindowListener wl = createFrameListener(); dialog.addWindowListener(wl); return dialog; }
@Override public void actionPerformed(ActionEvent arg0) { JButton but = (JButton) arg0.getSource(); if (but.getName().equals("start")) { buttonselected = "start"; } else if (but.getName().equals("end")) { buttonselected = "end"; } JDialog dia = new JDialog(); dia.setTitle("Kalendar"); dia.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); dia.addWindowListener(this); cal = new JCalendar(); dia.add(cal); dia.pack(); dia.setVisible(true); }
private void addDialogListeners() { main.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); main.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { close(); } }); main.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (highlight == null) return; if (e.isShiftDown() && range) previous = highlight; if (e.getKeyCode() == e.VK_LEFT) moveHighlight(-1); else if (e.getKeyCode() == e.VK_RIGHT) moveHighlight(1); else if (e.getKeyCode() == e.VK_UP) moveHighlight(-7); else if (e.getKeyCode() == e.VK_DOWN) moveHighlight(7); else if (e.getKeyCode() == e.VK_PAGE_UP) setHighlight(highlight.getMonth() - 1, highlight.getDay()); else if (e.getKeyCode() == e.VK_PAGE_DOWN) setHighlight(highlight.getMonth() + 1, highlight.getDay()); else if (e.getKeyCode() == e.VK_HOME) { if (highlight.getDay() == 1) setHighlight(0, 1); else setHighlight(highlight.getMonth(), 1); } else if (e.getKeyCode() == e.VK_END) { if (highlight.getDay() == highlight.getLastDay()) setHighlight(11, 31); else setHighlight(highlight.getMonth(), highlight.getLastDay()); } else if (e.getKeyCode() == e.VK_ESCAPE) { close(); } previous = null; } public void keyReleased(KeyEvent e) { if (highlight == null) return; if (e.getKeyCode() == e.VK_ENTER) { if (!range) setResult(); else if (first != null && last != null) setResultRange(); } } }); }
public Preferences(EPGSwingEngine swingEngine) { /** Initialize frame from preferences. */ final JDialog jDialog = (JDialog) swingEngine.find(EPGSwingEngine.PREFERENCES_DIALOG); jDialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { Preferences.this.dispatchViewEvent(Preferences.this, ViewEvent.CLOSE_PREFERENCES); jDialog.dispose(); } }); _midiInCheckBox = (JCheckBox) swingEngine.find("MIDI_IN_CHECKBOX"); _midiInCheckBox.addActionListener(this); _midiInComboBox = (JComboBox) swingEngine.find("MIDI_IN_COMBOBOX"); _midiInComboBox.setRenderer(new PromptComboBoxRenderer("Select...")); _midiInComboBox.addActionListener(this); _midiOutCheckBox = (JCheckBox) swingEngine.find("MIDI_OUT_CHECKBOX"); _midiOutCheckBox.addActionListener(this); _midiInClockSyncCheckBox = (JCheckBox) swingEngine.find("MIDI_IN_CLOCK_CHECKBOX"); _midiInClockSyncCheckBox.addActionListener(this); _midiInTriggerByNoteCheckBox = (JCheckBox) swingEngine.find("MIDI_IN_NOTE_TRIGGER_CHECKBOX"); _midiInTriggerByNoteCheckBox.addActionListener(this); _midiOutComboBox = (JComboBox) swingEngine.find("MIDI_OUT_COMBOBOX"); _midiOutComboBox.setRenderer(new PromptComboBoxRenderer("Select...")); _midiOutComboBox.addActionListener(this); _oscOutCheckBox = (JCheckBox) swingEngine.find("OSC_OUT_CHECKBOX"); _oscOutCheckBox.addActionListener(this); _oscOutTextField = (JTextField) swingEngine.find("OSC_OUT_TEXTFIELD"); _oscOutTextField.addActionListener(this); _displayMidiNoteNamesCheckBox = (JCheckBox) swingEngine.find("MIDI_NOTE_NAMES_CHECKBOX"); _displayMidiNoteNamesCheckBox.addActionListener(this); _reloadLastProjectCheckBox = (JCheckBox) swingEngine.find("RELOAD_LAST_PROJECT_CHECKBOX"); _reloadLastProjectCheckBox.addActionListener(this); }
public void performAction() { // TODO workaround; remove AFAIK Beans.setDesignTime(false); JDialog dialog = new JDialog(WindowManager.getDefault().getMainWindow(), "OpenGL Capabilities", false); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setResizable(false); dialog.addWindowListener(createWindowObserver()); capsPanel = new GLCapabilitiesPanel(); dialog.setContentPane(capsPanel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); EventQueue.invokeLater(createGLCapabilitiesQuery()); }
public void btnChoose_actionPerformed() { // java.awt.Rectangle r = dateField.getBounds(); // Point pOnScreen = dateField.getLocationOnScreen(); java.awt.Rectangle r = Jtext.getBounds(); Point pOnScreen = Jtext.getLocationOnScreen(); Point result = new Point(pOnScreen.x, pOnScreen.y + r.height); Point powner = owner.getLocation(); int offsetX = (pOnScreen.x + width) - (powner.x + owner.getWidth()); int offsetY = (pOnScreen.y + r.height + height) - (powner.y + owner.getHeight()); if (offsetX > 0) { result.x -= offsetX; } if (offsetY > 0) { result.y -= height + r.height; } javax.swing.JDialog dateFrame = new javax.swing.JDialog(); dateFrame.setModal(false); dateFrame.setUndecorated(true); dateFrame.setLocation(result); dateFrame.setSize(width, height); dateFrame.addWindowListener( new WindowAdapter() { // 鍦ㄤ换鎰忕殑闈炴棩鏈熼�夋嫨鍖哄崟鍑伙紝鍒欐棩鏈熼�夋嫨缁勪欢灏嗗彉涓洪潪娲诲姩鐘舵�侊紝鑷姩閲婃斁璧勬簮銆� public void windowDeactivated(WindowEvent e) { javax.swing.JDialog f = (javax.swing.JDialog) e.getSource(); f.dispose(); } }); DatePanel datePanel = new DatePanel(dateFrame, parten); dateFrame.getContentPane().setLayout(new BorderLayout()); dateFrame.getContentPane().add(datePanel); dateFrame.setVisible(true); }
@Override protected JDialog createDialog() { JButton cancelButton = new JButton(cancelAction); ButtonPanelBuilder builder = new ButtonPanelBuilder(); builder.add(cancelButton); JDialog newDialog = GuiUtilities.createDialog(parentComponent, title); newDialog.getContentPane().setLayout(new BorderLayout(2, 2)); newDialog.getContentPane().add(getContainerContent(), BorderLayout.CENTER); newDialog.getContentPane().add(builder.createPanel(), BorderLayout.SOUTH); newDialog.pack(); newDialog.setSize(Math.max(newDialog.getWidth(), 450), newDialog.getHeight()); newDialog.setResizable(false); newDialog.setModal(true); newDialog.getRootPane().setDefaultButton(cancelButton); newDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); newDialog.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { performCancel(); } @Override public void windowClosed(WindowEvent e) { synchronized (InternalProgressDialog.this) { setDialogClosed(true); } } }); GuiUtilities.centerToParent(newDialog); return newDialog; }
protected void populateDialog(JDialog dlg) { dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dlg.setResizable(false); dlg.setSize(new Dimension(350, 135)); dlg.setTitle("New TurboVNC Connection"); dlg.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { if (VncViewer.nViewers == 1) { if (cc.viewer instanceof VncViewer) { ((VncViewer) cc.viewer).exit(1); } } else { ret = false; endDialog(); } } }); dlg.getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.LINE_START; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = 1; gbc.insets = new Insets(0, 0, 0, 0); gbc.ipadx = 0; gbc.ipady = 0; gbc.weightx = 1; gbc.weighty = 1; dlg.getContentPane().add(topPanel, gbc); dlg.getContentPane().add(buttonPanel); dlg.pack(); }
private boolean showDialog(Component root, String title, boolean decorated) { if (dialog != null) { throw new IllegalStateException("Dialog already exists"); } dialog = Util.newJDialog(root, title, modal); if (!decorated) { dialog.setUndecorated(true); } JRootPane rootPane = dialog.getRootPane(); JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); // Do this to reorder buttons so "cancel" and "ok" are last! // For Windows L&F, cancel button is on the right. For Nimbus // check the "isYesLast" option. boolean cancelonright = Util.isLAFWindows() || !UIManager.getBoolean("OptionPane.isYesLast"); if (actions.containsKey("cancel") && !cancelonright) { actions.put("cancel", actions.remove("cancel")); } if (actions.containsKey("ok")) { actions.put("ok", actions.remove("ok")); } if (actions.containsKey("cancel") && cancelonright) { actions.put("cancel", actions.remove("cancel")); } for (Iterator<Map.Entry<String, Action>> i = actions.entrySet().iterator(); i.hasNext(); ) { Map.Entry<String, Action> e = i.next(); String name = e.getKey(); Action action = e.getValue(); rootPane.getActionMap().put(name, action); buttonpanel.add(new JButton(action)); for (Iterator<Map.Entry<KeyStroke, String>> j = keystrokes.entrySet().iterator(); j.hasNext(); ) { Map.Entry<KeyStroke, String> e2 = j.next(); if (e2.getValue().equals(name)) { rootPane .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(e2.getKey(), e2.getValue()); } } } GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = gbc.REMAINDER; gbc.anchor = gbc.EAST; gbc.weighty = 0.01; add(buttonpanel, gbc); dialog.setContentPane(this); dialog.setResizable(true); dialog.pack(); dialog.setLocationRelativeTo(root); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent event) { if (actions.containsKey("cancel")) { cancelDialog(); } else { acceptDialog(); } } }); dialog.setVisible(true); return response; }
/** * Creates a dialog where the user can specify the location of the database,including the type of * network connection (if this is a networked client)and IP address and port number; or search and * select the database on a local drive if this is a standalone client. * * @param parent Defines the Component that is to be the parent of this dialog box. For * information on how this is used, see <code>JOptionPane</code> * @param connectionMode Specifies the type of connection (standalone or networked) * @see JOptionPane */ public DatabaseLocationDialog(Frame parent, ApplicationMode connectionMode) { configOptions = (new ConfigOptions(connectionMode)); configOptions.getObservable().addObserver(this); // load saved configuration SavedConfiguration config = SavedConfiguration.getSavedConfiguration(); // the port and connection type are irrelevant in standalone mode if (connectionMode == ApplicationMode.STANDALONE_CLIENT) { validPort = true; validCnx = true; networkType = ConnectionType.DIRECT; location = config.getParameter(SavedConfiguration.DATABASE_LOCATION); } else { // there may not be a network connectivity type defined and, if // not, we do not set a default - force the user to make a choice // the at least for the first time they run this. String tmp = config.getParameter(SavedConfiguration.NETWORK_TYPE); if (tmp != null) { try { networkType = ConnectionType.valueOf(tmp); configOptions.setNetworkConnection(networkType); validCnx = true; } catch (IllegalArgumentException e) { log.warning("Unknown connection type: " + networkType); } } // there is always at least a default port number, so we don't have // to validate this. port = config.getParameter(SavedConfiguration.SERVER_PORT); configOptions.setPortNumberText(port); validPort = true; location = config.getParameter(SavedConfiguration.SERVER_ADDRESS); } // there may not be a default database location, so we had better // validate before using the returned value. if (location != null) { configOptions.setLocationFieldText(location); validDb = true; } options = new JOptionPane(configOptions, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); connectButton.setActionCommand(CONNECT); connectButton.addActionListener(this); boolean allValid = validDb && validPort && validCnx; connectButton.setEnabled(allValid); exitButton.setActionCommand(EXIT); exitButton.addActionListener(this); options.setOptions(new Object[] {connectButton, exitButton}); dialog = options.createDialog(parent, TITLE); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(this); dialog.setVisible(true); }
public static void initComponents() { final Browser browser = new Browser(); JFrame parent = new JFrame(); final JDialog dialog = new JDialog(parent, "QUIZ", true); browser.loadURL("http://dtprojecten.ehb.be/~PR-Ready/StatMenuWindow.html?85519519551951951"); dialog.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); } }); browser.registerFunction( "createPieChart", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); PieChartData[] dataArr = new PieChartData[6]; dataArr[0] = new PieChartData("De grote quiz", 50); dataArr[1] = new PieChartData("Test uw IQ!", 1); dataArr[2] = new PieChartData("Gestolen rijexamens", 15); dataArr[3] = new PieChartData("Win een reis!", 4); dataArr[4] = new PieChartData("Test uw kennis!", 10); dataArr[5] = new PieChartData("Kan u de verschillen aanwijzen?", 20); new PieChartWindow(factory, dataArr, "Populariteit per quiz"); return JSValue.createUndefined(); } }); browser.registerFunction( "createLineChart", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); LineChartData[] lineData = new LineChartData[3]; String title = "User creation"; String subtitle = "By month"; String leftTitle = "Users"; String[] categories = new String[3]; categories[0] = "September"; categories[1] = "Oktober"; categories[2] = "November"; double[] data = new double[3]; data[0] = 10; data[1] = 2; data[2] = 50; lineData[0] = new LineChartData("September", data); lineData[1] = new LineChartData("Oktober", data); lineData[2] = new LineChartData("November", data); new LineChartWindow(factory, lineData, title, subtitle, leftTitle, categories); return JSValue.createUndefined(); } }); browser.registerFunction( "createColumnChart", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); ColumnData[] dataColumn = new ColumnData[1]; double[] data = new double[3]; data[0] = 33.6; data[1] = 88; data[2] = 66; String title = "Gemiddelde score per quiz"; String subtitle = ""; dataColumn[0] = new ColumnData("Gemiddelde Score", data); new ColumnChartWindow(factory, dataColumn, title, subtitle); return JSValue.createUndefined(); } }); browser.registerFunction( "onExit", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); System.out.println("exit"); try { AdminMenuWindow amw = new AdminMenuWindow(factory); } catch (UserNoPermissionException e) { e.printStackTrace(); } return JSValue.createUndefined(); } }); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.add(new BrowserView(browser), BorderLayout.CENTER); dialog.setResizable(false); dialog.setUndecorated(true); dialog.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); dialog.setLocationRelativeTo(parent); dialog.setVisible(true); }
@SuppressWarnings("rawtypes") public static void runReport( List<List> customerData, List<List> projectData, JCheckBox markErrorsCheckBox, JTextField frameAgreement, JTextField category, File output, JFrame frame) { final JDialog dialog = new JDialog(); final ExcelDocumentCreator creator; JPanel contentPane; dialog.setTitle("Creating report"); dialog.setBounds(100, 100, 560, 189); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); dialog.setContentPane(contentPane); SpringLayout sl_contentPane = new SpringLayout(); contentPane.setLayout(sl_contentPane); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.black)); sl_contentPane.putConstraint(SpringLayout.NORTH, panel, -5, SpringLayout.NORTH, contentPane); panel.setBackground(Color.white); sl_contentPane.putConstraint(SpringLayout.WEST, panel, -5, SpringLayout.WEST, contentPane); sl_contentPane.putConstraint(SpringLayout.EAST, panel, 5, SpringLayout.EAST, contentPane); sl_contentPane.putConstraint(SpringLayout.SOUTH, panel, -50, SpringLayout.SOUTH, contentPane); contentPane.add(panel); JPanel panel_1 = new JPanel(); sl_contentPane.putConstraint(SpringLayout.WEST, panel_1, -5, SpringLayout.WEST, contentPane); sl_contentPane.putConstraint(SpringLayout.SOUTH, panel_1, 5, SpringLayout.SOUTH, contentPane); sl_contentPane.putConstraint(SpringLayout.NORTH, panel_1, 90, SpringLayout.NORTH, contentPane); sl_contentPane.putConstraint(SpringLayout.EAST, panel_1, 5, SpringLayout.EAST, contentPane); SpringLayout sl_panel = new SpringLayout(); panel.setLayout(sl_panel); final JProgressBar progressBar = new JProgressBar(); sl_panel.putConstraint(SpringLayout.NORTH, progressBar, -50, SpringLayout.SOUTH, panel); sl_panel.putConstraint(SpringLayout.WEST, progressBar, 20, SpringLayout.WEST, panel); panel.add(progressBar); JTextField stateField = new JTextField("Querying Database"); sl_panel.putConstraint(SpringLayout.EAST, progressBar, 247, SpringLayout.EAST, stateField); sl_panel.putConstraint(SpringLayout.NORTH, stateField, 10, SpringLayout.NORTH, panel); sl_panel.putConstraint(SpringLayout.WEST, stateField, 10, SpringLayout.WEST, panel); stateField.setBorder(BorderFactory.createEmptyBorder()); panel.add(stateField); stateField.setColumns(10); JTextField progressField = new JTextField(); sl_panel.putConstraint(SpringLayout.SOUTH, progressBar, -6, SpringLayout.NORTH, progressField); sl_panel.putConstraint(SpringLayout.WEST, progressField, 10, SpringLayout.WEST, panel); sl_panel.putConstraint(SpringLayout.EAST, progressField, -257, SpringLayout.EAST, panel); sl_panel.putConstraint(SpringLayout.EAST, stateField, 0, SpringLayout.EAST, progressField); progressField.setBorder(BorderFactory.createEmptyBorder()); sl_panel.putConstraint(SpringLayout.SOUTH, progressField, -10, SpringLayout.SOUTH, panel); panel.add(progressField); progressField.setColumns(10); contentPane.add(panel_1); SpringLayout sl_panel_1 = new SpringLayout(); panel_1.setLayout(sl_panel_1); JButton btnCancel = new JButton("Cancel") { private static final long serialVersionUID = 1L; public void addNotify() { super.addNotify(); requestFocus(); } }; sl_panel_1.putConstraint(SpringLayout.SOUTH, btnCancel, -10, SpringLayout.SOUTH, panel_1); sl_panel_1.putConstraint(SpringLayout.EAST, btnCancel, -10, SpringLayout.EAST, panel_1); panel_1.add(btnCancel); progressBar.setIndeterminate(true); creator = new ExcelDocumentCreator( customerData, projectData, frameAgreement, markErrorsCheckBox, category, stateField, progressField, output); creator.addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (creator.isDone()) dialog.dispose(); if ("progress".equals(evt.getPropertyName())) { progressBar.setValue((Integer) evt.getNewValue()); progressBar.setIndeterminate(false); } } }); creator.execute(); btnCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { creator.cancel(true); } }); dialog.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent evt) { creator.cancel(true); dialog.dispose(); } }); dialog.setModalityType(ModalityType.APPLICATION_MODAL); dialog.setLocationRelativeTo(frame); dialog.setResizable(false); dialog.setVisible(true); }
/** Default constructor. */ public ChangelogWindow() { // the dialog theDialog = new JDialog(); // set title theDialog.setTitle("TeXPrinter"); // set minimum size theDialog.setMinimumSize(new Dimension(300, 150)); // disable resize theDialog.setResizable(false); // set modal theDialog.setModal(true); // add a listener theDialog.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // dispose it theDialog.dispose(); } }); // set a new layout theDialog.setLayout(new MigLayout()); // create a main panel JPanel mainBlock = new JPanel(new MigLayout("ins dialog, gapx 7, hidemode 3", "[][grow]", "[][]20[grow]10[]")); // set the background color to white mainBlock.setBackground(Color.WHITE); // create a new icon JLabel lblScreenIcon = new JLabel( new ImageIcon( ChangelogWindow.class.getResource( "/net/sf/texprinter/ui/images/computericon.png"))); // create a new configuration Configuration config = new Configuration(); // create a new title JLabel lblTitle = new JLabel("<html>Changelog - TeXPrinter " + config.getAppVersionNumber() + "</html>"); // format it as a title UIUtils.formatLabelAsTitle(lblTitle); // create a new text JEditorPane lblText = new JEditorPane("text/html", "<html>New and noteworthy in this version.</html>"); // format it as a label UIUtils.formatEditorPaneAsLabel(lblText); // set the default font UIUtils.setDefaultFontToEditorPane(lblText, true); // add icon mainBlock.add(lblScreenIcon, "cell 0 0 0 4, aligny top"); // add title mainBlock.add(lblTitle, "cell 1 0, growx, aligny top"); // add text mainBlock.add(lblText, "cell 1 1, growx, aligny top"); // create a new changelog JEditorPane changelogEditor = new JEditorPane(); // create a scroll pane JScrollPane scrollerPanel = new JScrollPane(changelogEditor); // add the changelog mainBlock.add(scrollerPanel, "cell 1 2, growx, width 350!, height 150!, aligny top"); // create a footer JPanel footerBlock = new JPanel(); // set layout footerBlock.setLayout(new MigLayout("ins dialog", "[][][][]", "[]")); // add a separator footerBlock.add(new JSeparator(), "dock north"); // set editor to false changelogEditor.setEditable(false); // get the HTML page URL helpURL = ChangelogWindow.class.getResource("/net/sf/texprinter/config/changelog.html"); // if valid if (helpURL != null) { // lets try try { // set the page to the editor changelogEditor.setPage(helpURL); } catch (IOException e) { // log message log.log( Level.SEVERE, "I could not load the HTML changelog. MESSAGE: {0}", StringUtils.printStackTrace(e)); } } else { // log message log.log(Level.SEVERE, "HTML changelog was not found."); } // set the default font to the editor. UIUtils.setDefaultFontToEditorPane(changelogEditor, false); // add a layout fix footerBlock.add(new JLabel(), "dock center"); // create a new button JButton closeButton = new JButton("Close"); // add a new listener closeButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // make it invisible theDialog.setVisible(false); // dispose it theDialog.dispose(); } }); // disable focus closeButton.setFocusable(false); // add button footerBlock.add(closeButton); // add main block theDialog.add(mainBlock, "dock center"); // add footer theDialog.add(footerBlock, "dock south"); // pack theDialog.pack(); }
public SheetMessage( final Window owner, final String title, final String message, final Icon icon, final String[] buttons, final DialogWrapper.DoNotAskOption doNotAskOption, final String defaultButton, final String focusedButton) { myWindow = new JDialog(owner, "This should not be shown", Dialog.ModalityType.APPLICATION_MODAL); myWindow.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE); myWindow.addWindowListener( new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { super.windowActivated(e); } }); myParent = owner; myWindow.setUndecorated(true); myWindow.setBackground(Gray.TRANSPARENT); myController = new SheetController( this, title, message, icon, buttons, defaultButton, doNotAskOption, focusedButton); imageHeight = 0; registerMoveResizeHandler(); myWindow.setFocusable(true); myWindow.setFocusableWindowState(true); if (SystemInfo.isJavaVersionAtLeast("1.7")) { myWindow.setSize(myController.SHEET_NC_WIDTH, 0); setWindowOpacity(0.0f); myWindow.addComponentListener( new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { super.componentShown(e); setWindowOpacity(1.0f); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); } }); } else { myWindow.setModal(true); myWindow.setSize(myController.SHEET_NC_WIDTH, myController.SHEET_NC_HEIGHT); setPositionRelativeToParent(); } startAnimation(true); restoreFullscreenButton = couldBeInFullScreen(); if (restoreFullscreenButton) { FullScreenUtilities.setWindowCanFullScreen(myParent, false); } LaterInvocator.enterModal(myWindow); myWindow.setVisible(true); LaterInvocator.leaveModal(myWindow); }
private void showComparison() { // Find the instance that can be used for comparision. This instance // should be chosen from changedList or localHasUnexpInstance GKInstance instance = null; if (changedList != null) { // Check changedList first List selection = changedList.getSelection(); if (selection.size() > 0) instance = (GKInstance) selection.get(0); } if (instance == null && localHasMoreIEList != null) { List selection = localHasMoreIEList.getSelection(); if (selection.size() > 0) instance = (GKInstance) selection.get(0); } if (instance == null) return; final InstanceComparisonPane comparisonPane = new InstanceComparisonPane(); // Fine tune comparison pane for making comparisons with // database comparisonPane.setSaveDialogHideUnusedButtons(true); comparisonPane.setSaveDialogSaveAsNewBtnFirst(false); comparisonPane.setSaveDialogSaveAsNewBtnTitle( "Create new local instance and put merge into that"); comparisonPane.setSaveDialogReplaceFirstBtnTitle( "Overwrite existing instance with merge (recommended)"); comparisonPane.setCloseAfterSaving(true); try { String clsName = instance.getSchemClass().getName(); Long instanceId = instance.getDBID(); final GKInstance localCopy = fileAdaptor.fetchInstance(clsName, instanceId); dbAdaptor.setUseCache(false); // final GKInstance dbCopy = dbAdaptor.fetchInstance(clsName, instanceId); // The class type might be changed locally or remotely. So not clsName should be used // to fetch database instance. Otherwise, null exception will be thrown. The same thing // is done also in creating synchronization result. final GKInstance dbCopy = dbAdaptor.fetchInstance(instanceId); dbAdaptor.setUseCache(true); comparisonPane.setInstances(localCopy, dbCopy); String title = "Comparing Instances \"" + instance.getDisplayName() + "\" in the local and DB repositories"; JDialog parentDialog = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, centerPane); final JDialog dialog = new JDialog(parentDialog, title); // Try to update the list automatically dialog.addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent e) { handleMergeResult(localCopy, dbCopy, comparisonPane); // To prevent double calling. It is called again when parentDialog is closed. dialog.removeWindowListener(this); } }); dialog.getContentPane().add(comparisonPane, BorderLayout.CENTER); dialog.setModal(true); dialog.setSize(800, 600); GKApplicationUtilities.center(dialog); dialog.setVisible(true); // Update synchronization dialog panels depending on user // choice. if (comparisonPane.getSaveMergeOption() == InstanceComparisonPane.SAVE_AS_NEW) { GKInstance merged = comparisonPane.getMerged(); if (newList == null) { List list = new ArrayList(); list.add(merged); newList = initInstanceListPane(list, "Instances created locally: " + list.size()); } else newList.addInstance(merged); } else if (comparisonPane.getSaveMergeOption() == InstanceComparisonPane.OVERWRITE_FIRST) { dbAdaptor.setUseCache(false); GKInstance remoteCopy = dbAdaptor.fetchInstance(instance.getDBID()); dbAdaptor.setUseCache(true); if (remoteCopy != null) { InstanceComparer comparer = new InstanceComparer(); int reply = comparer.compare(instance, remoteCopy); if (reply == InstanceComparer.LOCAL_HAS_MORE_IE) { if (localHasMoreIEList == null) { List list = new ArrayList(); list.add(instance); localHasMoreIEList = initInstanceListPane( list, "Local instances having unexpected InstanceEdits: " + list.size()); } else localHasMoreIEList.addInstance(instance); } else if (reply == InstanceComparer.IS_IDENTICAL) { // Merge has made local and database copies // identical - don't need to check in anymore changedList.deleteInstance(instance); } else if (reply != InstanceComparer.NEW_CHANGE_IN_LOCAL) { // Merge has produced a conflict typeMap.put(mapCompareResultToString(reply), instance); } else // The user should now be allowed to commit this // instance, because it will now have changed. commitToDBAction.setEnabled(true); JOptionPane.showMessageDialog( parentDialog, "Merge successful, you will need to check the merged instance into the database.\n\n", "Merge OK", JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception e1) { System.err.println("Synchronization.createDisplayMapPane(): " + e1); e1.printStackTrace(); JOptionPane.showMessageDialog( this, "Error in comparing: " + instance.toString(), "Error in Comparing", JOptionPane.ERROR_MESSAGE); } }
protected final void showMsg(final String msg, final boolean quit) { final JPanel p = new JPanel(); p.setLayout(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(10, 10, 10, 10); c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.BOTH; final JImage im = new JImage(new ImageIcon(this.getClass().getResource("error.png"))); final JLabel l = new JLabel("Une erreur est survenue"); l.setFont(l.getFont().deriveFont(Font.BOLD)); final JLabel lError = new JLabel(msg); final JTextArea textArea = new JTextArea(); textArea.setFont(textArea.getFont().deriveFont(11f)); c.gridheight = 3; p.add(im, c); c.insets = new Insets(2, 4, 2, 4); c.gridheight = 1; c.gridx++; c.weightx = 1; c.gridwidth = 2; p.add(l, c); c.gridy++; p.add(lError, c); c.gridy++; p.add( new JLabel( "Il s'agit probablement d'une mauvaise configuration ou installation du logiciel."), c); c.gridx = 0; c.gridwidth = 3; c.gridy++; c.weighty = 0; c.gridwidth = 1; c.gridx = 1; c.gridy++; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.EAST; final Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; final boolean browseSupported = desktop != null && desktop.isSupported(Action.BROWSE); if (ForumURL != null) { final javax.swing.Action communityAction; if (browseSupported) { communityAction = new AbstractAction("Consulter le forum") { @Override public void actionPerformed(ActionEvent e) { try { desktop.browse(new URI(ForumURL)); } catch (Exception e1) { e1.printStackTrace(); } } }; } else { communityAction = new AbstractAction("Copier l'adresse du forum") { @Override public void actionPerformed(ActionEvent e) { copyToClipboard(ForumURL); } }; } p.add(new JButton(communityAction), c); } c.weightx = 0; c.gridx++; final javax.swing.Action supportAction; if (browseSupported) supportAction = new AbstractAction("Contacter l'assistance") { @Override public void actionPerformed(ActionEvent e) { try { desktop.browse(URI.create(ILM_CONTACT)); } catch (Exception e1) { e1.printStackTrace(); } } }; else supportAction = new AbstractAction("Copier l'adresse de l'assistance") { @Override public void actionPerformed(ActionEvent e) { copyToClipboard(ILM_CONTACT); } }; p.add(new JButton(supportAction), c); c.gridy++; c.gridx = 0; c.gridwidth = 3; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(0, 0, 0, 0); p.add(new JSeparator(), c); c.gridx = 0; c.gridwidth = 3; c.gridy++; c.insets = new Insets(2, 4, 2, 4); p.add(new JLabel("Détails de l'erreur:"), c); c.insets = new Insets(0, 0, 0, 0); c.gridy++; String message = this.getCause() == null ? null : this.getCause().getMessage(); if (message == null) { message = msg; } else { message = msg + "\n\n" + message; } message += "\n"; message += getTrace(); textArea.setText(message); textArea.setEditable(false); // Scroll JScrollPane scroll = new JScrollPane(textArea); scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scroll.getViewport().setMinimumSize(new Dimension(200, 300)); c.weighty = 1; c.gridwidth = 3; c.gridx = 0; c.gridy++; p.add(scroll, c); c.gridy++; c.fill = GridBagConstraints.NONE; c.weighty = 0; c.insets = new Insets(2, 4, 2, 4); final JButton buttonClose = new JButton("Fermer"); p.add(buttonClose, c); final Window window = this.comp == null ? null : SwingUtilities.getWindowAncestor(this.comp); final JDialog f; if (window instanceof Frame) { f = new JDialog((Frame) window, "Erreur", true); } else { f = new JDialog((Dialog) window, "Erreur", true); } f.setContentPane(p); f.pack(); f.setSize(580, 680); f.setMinimumSize(new Dimension(380, 380)); f.setLocationRelativeTo(this.comp); final ActionListener al = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (quit) { System.exit(1); } else { f.dispose(); } } }; buttonClose.addActionListener(al); // cannot set EXIT_ON_CLOSE on JDialog f.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { al.actionPerformed(null); } }); f.setVisible(true); }
/** * The constructor create all of the options windows and their components. * * @param treeManager the <tt>OptionsTreeManager</tt> instance to use for constructing the main * panels and adding elements * @param paneManager the <tt>OptionsPaneManager</tt> instance to use for constructing the main * panels and adding elements */ public OptionsConstructor( final OptionsTreeManager treeManager, final OptionsPaneManager paneManager) { TREE_MANAGER = treeManager; PANE_MANAGER = paneManager; final String title = I18n.tr("Options"); final boolean shouldBeModal = !OSUtils.isMacOSX(); DIALOG = new JDialog(GUIMediator.getAppFrame(), title, shouldBeModal); DIALOG.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); GUIUtils.addHideAction((JComponent) DIALOG.getContentPane()); if (UISettings.UI_OPTIONS_DIALOG_HEIGHT.getValue() < UISettings.UI_OPTIONS_DIALOG_HEIGHT.getDefaultValue()) { UISettings.UI_OPTIONS_DIALOG_HEIGHT.revertToDefault(); } if (UISettings.UI_OPTIONS_DIALOG_WIDTH.getValue() < UISettings.UI_OPTIONS_DIALOG_WIDTH.getDefaultValue()) { UISettings.UI_OPTIONS_DIALOG_WIDTH.revertToDefault(); } DialogSizeSettingUpdater.install( DIALOG, UISettings.UI_OPTIONS_DIALOG_WIDTH, UISettings.UI_OPTIONS_DIALOG_HEIGHT); // most Mac users expect changes to be saved when the window // is closed, so save them DIALOG.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { try { DialogOption answer = null; if (OptionsMediator.instance().isDirty()) { answer = GUIMediator.showYesNoCancelMessage( I18n.tr( "You have made changes to some of FrostWire's settings. Would you like to save these changes?")); if (answer == DialogOption.YES) { OptionsMediator.instance().applyOptions(); SettingsGroupManager.instance().save(); } } if (answer != DialogOption.CANCEL) { DIALOG.dispose(); OptionsMediator.instance().disposeOptions(); } } catch (IOException ioe) { // nothing we should do here. a message should // have been displayed to the user with more // information } } }); PaddedPanel mainPanel = new PaddedPanel(); Box splitBox = new Box(BoxLayout.X_AXIS); BoxPanel treePanel = new BoxPanel(BoxLayout.Y_AXIS); BoxPanel filterPanel = new BoxPanel(BoxLayout.X_AXIS); treePanel.add(filterPanel); filterTextField = new SearchField(); filterTextField.setPrompt(I18n.tr("Search here")); filterTextField.setMinimumSize(new Dimension(100, 27)); filterTextField.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { filter(); } }); filterPanel.add(filterTextField); filterPanel.add(Box.createHorizontalStrut(2)); treePanel.add(Box.createVerticalStrut(3)); Component treeComponent = TREE_MANAGER.getComponent(); treePanel.add(treeComponent); Component paneComponent = PANE_MANAGER.getComponent(); splitBox.add(treePanel); splitBox.add(paneComponent); mainPanel.add(splitBox); mainPanel.add(Box.createVerticalStrut(17)); mainPanel.add(new OptionsButtonPanel().getComponent()); DIALOG.getContentPane().add(mainPanel); OptionsTreeNode node = initializePanels(); PANE_MANAGER.show(node); }