List of usage examples for javax.swing WindowConstants HIDE_ON_CLOSE
int HIDE_ON_CLOSE
To view the source code for javax.swing WindowConstants HIDE_ON_CLOSE.
Click Source Link
From source file:de.bwravencl.controllerbuddy.gui.Main.java
private Main() { Singleton.start(this, SINGLETON_ID); frame = new JFrame(); frame.addWindowListener(new WindowAdapter() { @Override/*ww w . ja va 2 s .c o m*/ public void windowClosing(final WindowEvent e) { super.windowClosing(e); if (showMenuItem != null) showMenuItem.setEnabled(true); } @Override public void windowDeiconified(final WindowEvent e) { super.windowDeiconified(e); if (showMenuItem != null) showMenuItem.setEnabled(false); } @Override public void windowIconified(final WindowEvent e) { super.windowIconified(e); if (showMenuItem != null) showMenuItem.setEnabled(true); } @Override public void windowOpened(final WindowEvent e) { super.windowOpened(e); if (showMenuItem != null) showMenuItem.setEnabled(false); } }); frame.setBounds(DIALOG_BOUNDS_X, DIALOG_BOUNDS_Y, DIALOG_BOUNDS_WIDTH, DIALOG_BOUNDS_HEIGHT); frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); final var icons = new ArrayList<Image>(); for (final var path : ICON_RESOURCE_PATHS) { final var icon = new ImageIcon(Main.class.getResource(path)); icons.add(icon.getImage()); } frame.setIconImages(icons); frame.setJMenuBar(menuBar); menuBar.add(fileMenu); final QuitAction quitAction = new QuitAction(); fileMenu.add(quitAction); menuBar.add(deviceMenu); if (windows) { menuBar.add(localMenu, 2); final var buttonGroupLocalState = new ButtonGroup(); startLocalRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("START_MENU_ITEM")); startLocalRadioButtonMenuItem.setAction(new StartLocalAction()); buttonGroupLocalState.add(startLocalRadioButtonMenuItem); localMenu.add(startLocalRadioButtonMenuItem); stopLocalRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("STOP_MENU_ITEM")); stopLocalRadioButtonMenuItem.setAction(new StopLocalAction()); buttonGroupLocalState.add(stopLocalRadioButtonMenuItem); localMenu.add(stopLocalRadioButtonMenuItem); menuBar.add(clientMenu); final var buttonGroupClientState = new ButtonGroup(); startClientRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("START_MENU_ITEM")); startClientRadioButtonMenuItem.setAction(new StartClientAction()); buttonGroupClientState.add(startClientRadioButtonMenuItem); clientMenu.add(startClientRadioButtonMenuItem); stopClientRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("STOP_MENU_ITEM")); stopClientRadioButtonMenuItem.setAction(new StopClientAction()); buttonGroupClientState.add(stopClientRadioButtonMenuItem); clientMenu.add(stopClientRadioButtonMenuItem); } final var buttonGroupServerState = new ButtonGroup(); startServerRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("START_MENU_ITEM")); startServerRadioButtonMenuItem.setAction(new StartServerAction()); buttonGroupServerState.add(startServerRadioButtonMenuItem); serverMenu.add(startServerRadioButtonMenuItem); stopServerRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("STOP_MENU_ITEM")); stopServerRadioButtonMenuItem.setAction(new StopServerAction()); buttonGroupServerState.add(stopServerRadioButtonMenuItem); serverMenu.add(stopServerRadioButtonMenuItem); final var helpMenu = new JMenu(rb.getString("HELP_MENU")); menuBar.add(helpMenu); helpMenu.add(new ShowAboutDialogAction()); frame.getContentPane().add(tabbedPane); settingsPanel = new JPanel(); settingsPanel.setLayout(new GridBagLayout()); settingsScrollPane.setViewportView(settingsPanel); tabbedPane.addTab(rb.getString("SETTINGS_TAB"), null, settingsScrollPane); final var panelGridBagConstraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 5); final var panelFlowLayout = new FlowLayout(FlowLayout.LEADING, 10, 10); final var pollIntervalPanel = new JPanel(panelFlowLayout); settingsPanel.add(pollIntervalPanel, panelGridBagConstraints); final var pollIntervalLabel = new JLabel(rb.getString("POLL_INTERVAL_LABEL")); pollIntervalLabel.setPreferredSize(new Dimension(120, 15)); pollIntervalPanel.add(pollIntervalLabel); final var pollIntervalSpinner = new JSpinner(new SpinnerNumberModel( preferences.getInt(PREFERENCES_POLL_INTERVAL, OutputThread.DEFAULT_POLL_INTERVAL), 10, 500, 1)); final JSpinner.DefaultEditor pollIntervalSpinnerEditor = new JSpinner.NumberEditor(pollIntervalSpinner, "#"); ((DefaultFormatter) pollIntervalSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true); pollIntervalSpinner.setEditor(pollIntervalSpinnerEditor); pollIntervalSpinner.addChangeListener( e -> preferences.putInt(PREFERENCES_POLL_INTERVAL, (int) ((JSpinner) e.getSource()).getValue())); pollIntervalPanel.add(pollIntervalSpinner); if (windows) { final var vJoyDirectoryPanel = new JPanel(panelFlowLayout); settingsPanel.add(vJoyDirectoryPanel, panelGridBagConstraints); final var vJoyDirectoryLabel = new JLabel(rb.getString("VJOY_DIRECTORY_LABEL")); vJoyDirectoryLabel.setPreferredSize(new Dimension(120, 15)); vJoyDirectoryPanel.add(vJoyDirectoryLabel); vJoyDirectoryLabel1 = new JLabel( preferences.get(PREFERENCES_VJOY_DIRECTORY, VJoyOutputThread.getDefaultInstallationPath())); vJoyDirectoryPanel.add(vJoyDirectoryLabel1); final var vJoyDirectoryButton = new JButton(new ChangeVJoyDirectoryAction()); vJoyDirectoryPanel.add(vJoyDirectoryButton); final var vJoyDevicePanel = new JPanel(panelFlowLayout); settingsPanel.add(vJoyDevicePanel, panelGridBagConstraints); final var vJoyDeviceLabel = new JLabel(rb.getString("VJOY_DEVICE_LABEL")); vJoyDeviceLabel.setPreferredSize(new Dimension(120, 15)); vJoyDevicePanel.add(vJoyDeviceLabel); final var vJoyDeviceSpinner = new JSpinner(new SpinnerNumberModel( preferences.getInt(PREFERENCES_VJOY_DEVICE, VJoyOutputThread.DEFAULT_VJOY_DEVICE), 1, 16, 1)); final JSpinner.DefaultEditor vJoyDeviceSpinnerEditor = new JSpinner.NumberEditor(vJoyDeviceSpinner, "#"); ((DefaultFormatter) vJoyDeviceSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true); vJoyDeviceSpinner.setEditor(vJoyDeviceSpinnerEditor); vJoyDeviceSpinner.addChangeListener( e -> preferences.putInt(PREFERENCES_VJOY_DEVICE, (int) ((JSpinner) e.getSource()).getValue())); vJoyDevicePanel.add(vJoyDeviceSpinner); final var hostPanel = new JPanel(panelFlowLayout); settingsPanel.add(hostPanel, panelGridBagConstraints); final var hostLabel = new JLabel(rb.getString("HOST_LABEL")); hostLabel.setPreferredSize(new Dimension(120, 15)); hostPanel.add(hostLabel); hostTextField = new JTextField(preferences.get(PREFERENCES_HOST, ClientVJoyOutputThread.DEFAULT_HOST), 10); final var setHostAction = new SetHostAction(hostTextField); hostTextField.addActionListener(setHostAction); hostTextField.addFocusListener(setHostAction); hostPanel.add(hostTextField); } final var portPanel = new JPanel(panelFlowLayout); settingsPanel.add(portPanel, panelGridBagConstraints); final var portLabel = new JLabel(rb.getString("PORT_LABEL")); portLabel.setPreferredSize(new Dimension(120, 15)); portPanel.add(portLabel); final var portSpinner = new JSpinner(new SpinnerNumberModel( preferences.getInt(PREFERENCES_PORT, ServerOutputThread.DEFAULT_PORT), 1024, 65535, 1)); final JSpinner.DefaultEditor portSpinnerEditor = new JSpinner.NumberEditor(portSpinner, "#"); ((DefaultFormatter) portSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true); portSpinner.setEditor(portSpinnerEditor); portSpinner.addChangeListener( e -> preferences.putInt(PREFERENCES_PORT, (int) ((JSpinner) e.getSource()).getValue())); portPanel.add(portSpinner); final var timeoutPanel = new JPanel(panelFlowLayout); settingsPanel.add(timeoutPanel, panelGridBagConstraints); final var timeoutLabel = new JLabel(rb.getString("TIMEOUT_LABEL")); timeoutLabel.setPreferredSize(new Dimension(120, 15)); timeoutPanel.add(timeoutLabel); final var timeoutSpinner = new JSpinner(new SpinnerNumberModel( preferences.getInt(PREFERENCES_TIMEOUT, ServerOutputThread.DEFAULT_TIMEOUT), 10, 60000, 1)); final JSpinner.DefaultEditor timeoutSpinnerEditor = new JSpinner.NumberEditor(timeoutSpinner, "#"); ((DefaultFormatter) timeoutSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true); timeoutSpinner.setEditor(timeoutSpinnerEditor); timeoutSpinner.addChangeListener( e -> preferences.putInt(PREFERENCES_TIMEOUT, (int) ((JSpinner) e.getSource()).getValue())); timeoutPanel.add(timeoutSpinner); final var alwaysOnTopSupported = Toolkit.getDefaultToolkit().isAlwaysOnTopSupported(); if (alwaysOnTopSupported || preferences.getBoolean(PREFERENCES_SHOW_OVERLAY, alwaysOnTopSupported)) { final var overlaySettingsPanel = new JPanel(panelFlowLayout); settingsPanel.add(overlaySettingsPanel, panelGridBagConstraints); final var overlayLabel = new JLabel(rb.getString("OVERLAY_LABEL")); overlayLabel.setPreferredSize(new Dimension(120, 15)); overlaySettingsPanel.add(overlayLabel); final var showOverlayCheckBox = new JCheckBox(rb.getString("SHOW_OVERLAY_CHECK_BOX")); showOverlayCheckBox.setSelected(preferences.getBoolean(PREFERENCES_SHOW_OVERLAY, true)); showOverlayCheckBox.addActionListener(e -> { final boolean showOverlay = ((JCheckBox) e.getSource()).isSelected(); preferences.putBoolean(PREFERENCES_SHOW_OVERLAY, showOverlay); }); overlaySettingsPanel.add(showOverlayCheckBox); } if (windows) { if (preferences.getBoolean(PREFERENCES_SHOW_VR_OVERLAY, true)) { final var vrOverlaySettingsPanel = new JPanel(panelFlowLayout); settingsPanel.add(vrOverlaySettingsPanel, panelGridBagConstraints); final var vrOverlayLabel = new JLabel(rb.getString("VR_OVERLAY_LABEL")); vrOverlayLabel.setPreferredSize(new Dimension(120, 15)); vrOverlaySettingsPanel.add(vrOverlayLabel); final var showVrOverlayCheckBox = new JCheckBox(rb.getString("SHOW_VR_OVERLAY_CHECK_BOX")); showVrOverlayCheckBox.setSelected(preferences.getBoolean(PREFERENCES_SHOW_VR_OVERLAY, true)); showVrOverlayCheckBox.addActionListener(e -> { final var showVrOverlay = ((JCheckBox) e.getSource()).isSelected(); preferences.putBoolean(PREFERENCES_SHOW_VR_OVERLAY, showVrOverlay); }); vrOverlaySettingsPanel.add(showVrOverlayCheckBox); } final var preventPowerSaveModeSettingsPanel = new JPanel(panelFlowLayout); settingsPanel.add(preventPowerSaveModeSettingsPanel, panelGridBagConstraints); final var preventPowerSaveModeLabel = new JLabel(rb.getString("POWER_SAVE_MODE_LABEL")); preventPowerSaveModeLabel.setPreferredSize(new Dimension(120, 15)); preventPowerSaveModeSettingsPanel.add(preventPowerSaveModeLabel); final var preventPowerSaveModeCheckBox = new JCheckBox( rb.getString("PREVENT_POWER_SAVE_MODE_CHECK_BOX")); preventPowerSaveModeCheckBox .setSelected(preferences.getBoolean(PREFERENCES_PREVENT_POWER_SAVE_MODE, true)); preventPowerSaveModeCheckBox.addActionListener(e -> { final var preventPowerSaveMode = ((JCheckBox) e.getSource()).isSelected(); preferences.putBoolean(PREFERENCES_PREVENT_POWER_SAVE_MODE, preventPowerSaveMode); }); preventPowerSaveModeSettingsPanel.add(preventPowerSaveModeCheckBox); } if (SystemTray.isSupported()) { final var popupMenu = new PopupMenu(); final var showAction = new ShowAction(); showMenuItem = new MenuItem((String) showAction.getValue(Action.NAME)); showMenuItem.addActionListener(showAction); popupMenu.add(showMenuItem); popupMenu.addSeparator(); final var openMenuItem = new MenuItem((String) openAction.getValue(Action.NAME)); openMenuItem.addActionListener(openAction); popupMenu.add(openMenuItem); popupMenu.addSeparator(); final var quitMenuItem = new MenuItem((String) quitAction.getValue(Action.NAME)); quitMenuItem.addActionListener(quitAction); popupMenu.add(quitMenuItem); trayIcon = new TrayIcon(frame.getIconImage()); trayIcon.addActionListener(showAction); trayIcon.setPopupMenu(popupMenu); try { SystemTray.getSystemTray().add(trayIcon); } catch (final AWTException e) { log.log(Logger.Level.ERROR, e.getMessage(), e); } } updateTitleAndTooltip(); settingsPanel.add(Box.createGlue(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); final var outsideBorder = BorderFactory.createEtchedBorder(EtchedBorder.RAISED); final var insideBorder = BorderFactory.createEmptyBorder(0, 5, 0, 5); statusLabel.setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder)); frame.add(statusLabel, BorderLayout.SOUTH); final var glfwInitialized = glfwInit(); if (!glfwInitialized) if (windows) JOptionPane.showMessageDialog(frame, rb.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT_WINDOWS"), rb.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); else { JOptionPane.showMessageDialog(frame, rb.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT"), rb.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); quit(); } final var presentJids = new HashSet<Integer>(); for (var jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++) if (glfwJoystickPresent(jid) && glfwJoystickIsGamepad(jid)) presentJids.add(jid); final var lastControllerGuid = preferences.get(PREFERENCES_LAST_CONTROLLER, null); for (final var jid : presentJids) { final var lastControllerFound = lastControllerGuid != null ? lastControllerGuid.equals(glfwGetJoystickGUID(jid)) : false; if (!isSelectedJidValid() || lastControllerFound) selectedJid = jid; if (lastControllerFound) break; } newProfile(); onControllersChanged(true); glfwSetJoystickCallback(new GLFWJoystickCallback() { @Override public void invoke(final int jid, final int event) { final var disconnected = event == GLFW_DISCONNECTED; if (disconnected || glfwJoystickIsGamepad(jid)) { if (disconnected && selectedJid == jid) selectedJid = INVALID_JID; invokeOnEventDispatchThreadIfRequired(() -> onControllersChanged(false)); } } }); if (glfwInitialized && presentJids.isEmpty()) { if (windows) JOptionPane.showMessageDialog(frame, rb.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT_WINDOWS"), rb.getString("INFORMATION_DIALOG_TITLE"), JOptionPane.INFORMATION_MESSAGE); else JOptionPane.showMessageDialog(frame, rb.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT"), rb.getString("INFORMATION_DIALOG_TITLE"), JOptionPane.INFORMATION_MESSAGE); } else { final String path = preferences.get(PREFERENCES_LAST_PROFILE, null); if (path != null) loadProfile(new File(path)); } }
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 ww . ja v a2 s .com*/ 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 w w w. j a v a 2s . c o m 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.datavyu.views.DataControllerV.java
/** * Constructor. Creates a new DataControllerV. * * @param parent/*from w w w . j a v a 2 s. com*/ * The parent of this form. * @param modal * Should the dialog be modal or not? */ public DataControllerV(final java.awt.Frame parent, final boolean modal) { super(parent, modal); clock.registerListener(this); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); if (Datavyu.getPlatform() == Platform.MAC) { initComponentsMac(); } else { initComponents(); } setResizable(false); setName(this.getClass().getSimpleName()); viewers = new LinkedHashSet<DataViewer>(); playbackModel = new PlaybackModel(); playbackModel.setPauseRate(0); playbackModel.setLastSync(0); playbackModel.setMaxDuration(ViewportStateImpl.MINIMUM_MAX_END); final int defaultEndTime = (int) MixerConstants.DEFAULT_DURATION; playbackModel.setWindowPlayStart(0); playbackModel.setWindowPlayEnd(defaultEndTime); mixerController = new MixerController(); tracksPanel.add(mixerController.getTracksPanel(), "growx"); mixerController.addTracksControllerListener(this); mixerController.getMixerModel().getViewportModel().addPropertyChangeListener(this); mixerController.getMixerModel().getRegionModel().addPropertyChangeListener(this); mixerController.getMixerModel().getNeedleModel().addPropertyChangeListener(this); tracksPanelEnabled = true; showTracksPanel(tracksPanelEnabled); updateCurrentTimeLabel(); }
From source file:org.genedb.jogra.plugins.TermRationaliser.java
/** * Return a new JFrame which is the main interface to the Rationaliser. *///from w w w. ja v a 2 s .c om public JFrame getMainPanel() { /* JFRAME */ frame.setTitle(WINDOW_TITLE); frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); frame.setLayout(new BorderLayout()); /* MENU */ JMenuBar menuBar = new JMenuBar(); JMenu actions_menu = new JMenu("Actions"); JMenuItem actions_mitem_1 = new JMenuItem("Refresh lists"); actions_mitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { initModels(); } }); actions_menu.add(actions_mitem_1); JMenu about_menu = new JMenu("About"); JMenuItem about_mitem_1 = new JMenuItem("About"); about_mitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JOptionPane.showMessageDialog(null, "Term Rationaliser \n" + "Wellcome Trust Sanger Institute, UK \n" + "2009", "Term Rationaliser", JOptionPane.PLAIN_MESSAGE); } }); about_menu.add(about_mitem_1); menuBar.add(about_menu); menuBar.add(actions_menu); frame.add(menuBar, BorderLayout.NORTH); /* MAIN BOX */ Box center = Box.createHorizontalBox(); //A box that displays contents from left to right center.add(Box.createHorizontalStrut(5)); //Invisible fixed-width component /* FROM LIST AND PANEL */ fromList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //Allow multiple products to be selected fromList.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) { synchroniseLists(fromList, toList); //synchronise from left to right } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyTyped(KeyEvent arg0) { } }); Box fromPanel = this.createRationaliserPanel(FROM_LIST_NAME, fromList); //Box on left hand side fromPanel.add(Box.createVerticalStrut(55)); //Add some space center.add(fromPanel); //Add to main box center.add(Box.createHorizontalStrut(3)); //Add some space /* MIDDLE PANE */ Box middlePane = Box.createVerticalBox(); ClassLoader classLoader = this.getClass().getClassLoader(); //Needed to access the images later on ImageIcon leftButtonIcon = new ImageIcon(classLoader.getResource("left_arrow.gif")); ImageIcon rightButtonIcon = new ImageIcon(classLoader.getResource("right_arrow.gif")); leftButtonIcon = new ImageIcon(leftButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon! rightButtonIcon = new ImageIcon(rightButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon! JButton rightSynch = new JButton(rightButtonIcon); rightSynch.setToolTipText("Synchronise TO list. \n Shortcut: Right-arrow key"); rightSynch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { synchroniseLists(fromList, toList); } }); JButton leftSynch = new JButton(leftButtonIcon); leftSynch.setToolTipText("Synchronise FROM list. \n Shortcut: Left-arrow key"); leftSynch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { synchroniseLists(toList, fromList); } }); middlePane.add(rightSynch); middlePane.add(leftSynch); center.add(middlePane); //Add middle pane to main box center.add(Box.createHorizontalStrut(3)); /* TO LIST AND PANEL */ toList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //Single product selection in TO list toList.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_LEFT) { synchroniseLists(toList, fromList); //synchronise from right to left } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyTyped(KeyEvent arg0) { } }); Box toPanel = this.createRationaliserPanel(TO_LIST_NAME, toList); Box newTerm = Box.createVerticalBox(); textField = new JTextArea(1, 1); //textfield to let the user edit the name of an existing term textField.setMaximumSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().height, 10)); textField.setForeground(Color.BLUE); JScrollPane jsp = new JScrollPane(textField); //scroll pane so that there is a horizontal scrollbar jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); newTerm.add(jsp); TitledBorder editBorder = BorderFactory.createTitledBorder("Edit term name"); editBorder.setTitleColor(Color.DARK_GRAY); newTerm.setBorder(editBorder); toPanel.add(newTerm); //add textfield to panel center.add(toPanel); //add panel to main box center.add(Box.createHorizontalStrut(5)); frame.add(center); //add the main panel to the frame initModels(); //load the lists with data /* BOTTOM HALF OF FRAME */ Box main = Box.createVerticalBox(); TitledBorder border = BorderFactory.createTitledBorder("Information"); border.setTitleColor(Color.DARK_GRAY); /* INFORMATION BOX */ Box info = Box.createVerticalBox(); Box scope = Box.createHorizontalBox(); scope.add(Box.createHorizontalStrut(5)); scope.add(scopeLabel); //label showing the scope of the terms scope.add(Box.createHorizontalGlue()); Box productCount = Box.createHorizontalBox(); productCount.add(Box.createHorizontalStrut(5)); productCount.add(productCountLabel); //display the label showing the number of terms productCount.add(Box.createHorizontalGlue()); info.add(scope); info.add(productCount); info.setBorder(border); /* ACTION BUTTONS */ Box actionButtons = Box.createHorizontalBox(); actionButtons.add(Box.createHorizontalGlue()); actionButtons.add(Box.createHorizontalStrut(10)); JButton findFix = new JButton(new FindClosestMatchAction()); actionButtons.add(findFix); actionButtons.add(Box.createHorizontalStrut(10)); RationaliserAction ra = new RationaliserAction(); // RationaliserAction2 ra2 = new RationaliserAction2(); JButton go = new JButton(ra); actionButtons.add(go); actionButtons.add(Box.createHorizontalGlue()); /* MORE INFORMATION TOGGLE */ Box buttonBox = Box.createHorizontalBox(); final JButton toggle = new JButton("Hide information <<"); buttonBox.add(Box.createHorizontalStrut(5)); buttonBox.add(toggle); buttonBox.add(Box.createHorizontalGlue()); Box textBox = Box.createHorizontalBox(); final JScrollPane scrollPane = new JScrollPane(information); scrollPane.setPreferredSize(new Dimension(frame.getWidth(), 100)); scrollPane.setVisible(true); textBox.add(Box.createHorizontalStrut(5)); textBox.add(scrollPane); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (toggle.getText().equals("Show information >>")) { scrollPane.setVisible(true); toggle.setText("Hide information <<"); frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() + 100)); frame.pack(); } else if (toggle.getText().equals("Hide information <<")) { scrollPane.setVisible(false); toggle.setText("Show information >>"); frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() - 100)); frame.pack(); } } }; toggle.addActionListener(actionListener); main.add(Box.createVerticalStrut(5)); main.add(info); main.add(Box.createVerticalStrut(5)); main.add(Box.createVerticalStrut(5)); main.add(actionButtons); main.add(Box.createVerticalStrut(10)); main.add(buttonBox); main.add(textBox); frame.add(main, BorderLayout.SOUTH); frame.pack(); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setVisible(true); //initModels(); return frame; }
From source file:org.intermine.install.swing.CreatePropertiesDialog.java
/** * Common initialisation: lays out the child components and wires up the necessary * event listeners. // ww w . j a v a 2s . c o m */ private void init() { setName("Create Properties Dialog"); setTitle(Messages.getMessage("mineinfo.title")); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); Container cp = getContentPane(); GridBagConstraints cons = GridBagHelper.setup(cp); cons.weightx = 1; cons.gridwidth = GridBagConstraints.REMAINDER; cp.add(new JLabel(Messages.getMessage("properties.project.header")), cons); cons.weightx = 0; cons.gridwidth = 1; cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.project.title")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.project.subtitle")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.project.releaseversion")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.project.siteprefix")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.project.helplocation")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.project.feedback")), cons); cons.gridy++; cons.weightx = 1; cons.gridwidth = GridBagConstraints.REMAINDER; cp.add(new JLabel(Messages.getMessage("properties.webapp.header")), cons); cons.gridy++; cons.weightx = 0; cons.gridwidth = 1; cp.add(new JLabel(Messages.getMessage("properties.webapp.deploy")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.webapp.path")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.webapp.baseurl")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.webapp.manager")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.webapp.manager.password")), cons); cons.gridy++; cons.weightx = 1; cons.gridwidth = GridBagConstraints.REMAINDER; cp.add(new JLabel(Messages.getMessage("properties.mail.header")), cons); cons.gridy++; cons.weightx = 0; cons.gridwidth = 1; cp.add(new JLabel(Messages.getMessage("properties.mail.host")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.mail.from")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.mail.subject")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.mail.text")), cons); cons.gridy++; cons.weightx = 1; cons.gridwidth = GridBagConstraints.REMAINDER; cp.add(new JLabel(Messages.getMessage("properties.superuser.header")), cons); cons.gridy++; cons.weightx = 0; cons.gridwidth = 1; cp.add(new JLabel(Messages.getMessage("properties.superuser")), cons); cons.gridy++; cp.add(new JLabel(Messages.getMessage("properties.superuser.password")), cons); cons.gridy++; cons.weightx = 1; cons.gridwidth = GridBagConstraints.REMAINDER; cp.add(new JLabel(Messages.getMessage("properties.misc.header")), cons); cons.gridy++; cp.add(verboseLogCheck, cons); // Record the next free row for the button panel. int rowIndex = cons.gridy + 1; cons.gridx++; cons.gridy = 1; cons.weightx = 1; cons.gridwidth = 1; cp.add(titleField, cons); cons.gridy++; cp.add(subtitleField, cons); cons.gridy++; cp.add(versionField, cons); cons.gridy++; cp.add(prefixField, cons); cons.gridy++; cp.add(helpField, cons); cons.gridy++; cp.add(feedbackField, cons); cons.gridy += 2; cp.add(webDeployUrlField, cons); cons.gridy++; cp.add(webPathField, cons); cons.gridy++; cp.add(webBaseUrlField, cons); cons.gridy++; cp.add(webManagerField, cons); cons.gridy++; cp.add(webPasswordField, cons); cons.gridy += 2; cp.add(mailHostField, cons); cons.gridy++; cp.add(mailFromField, cons); cons.gridy++; cp.add(mailSubjectField, cons); cons.gridy++; cp.add(mailTextField, cons); cons.gridy += 2; cp.add(superuserField, cons); cons.gridy++; cp.add(superuserPasswordField, cons); cons.gridy = rowIndex; cons.gridx = 0; cons.gridwidth = GridBagConstraints.REMAINDER; cons.weightx = 1.0; cp.add(new ButtonPanel(getRootPane(), 0, nextAction, new CancelAction()), cons); standardBackground = webBaseUrlField.getBackground(); errorBackground = new Color(255, 232, 232); verboseLogCheck.setToolTipText(Messages.getMessage("properties.misc.verboselog.tooltip")); new EmailFieldListener(superuserField, true); new EmailFieldListener(mailFromField, true); new EmailFieldListener(feedbackField, true); new UrlFieldListener(webDeployUrlField, false); new UrlFieldListener(webBaseUrlField, false); new UrlFieldListener(prefixField, false); new UrlFieldListener(helpField, true); pack(); }
From source file:org.openflexo.view.controller.FlexoInspectorController.java
public static void main(String[] args) { JFrame frame = new JFrame(); final JDialog dialog = new JDialog(frame); dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); JButton button = new JButton("Show dialog"); button.addActionListener(new ActionListener() { @Override/*w w w . ja va2 s .co m*/ public void actionPerformed(ActionEvent e) { dialog.setVisible(true); } }); JLabel label = new JLabel("coucou"); dialog.add(label); dialog.pack(); JPanel panel = new JPanel(new BorderLayout()); panel.add(button); panel.setPreferredSize(new Dimension(500, 400)); frame.add(panel); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:pcgen.gui2.dialog.RandomNameDialog.java
/** * Create a new Random Name Dialog/*from w ww . ja v a 2 s. c o m*/ * @param frame The parent frame. The dialog will be centred on this frame * @param gender The current gender of the character. */ public RandomNameDialog(JFrame frame, String gender) { super(frame, LanguageBundle.getString("in_rndNameTitle"), true); //$NON-NLS-1$ nameGenPanel = new NameGenPanel(new File(getDataDir())); nameGenPanel.setGender(gender); initUserInterface(); pack(); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); if (frame != null) { Utility.setComponentRelativeLocation(frame, this); } cancelled = false; Utility.installEscapeCloseOperation(this); }
From source file:plugins.tprovoost.Microscopy.MicroManagerForIcy.MMMainFrame.java
/** * Singleton pattern : private constructor Use instead. */// w w w .ja va 2s . co m private MMMainFrame() { super(NODE_NAME, false, true, false, true); instancing = true; // -------------- // INITIALIZATION // -------------- _sysConfigFile = ""; _isConfigLoaded = false; _root = PluginPreferences.getPreferences().node(NODE_NAME); final MainFrame mainFrame = Icy.getMainInterface().getMainFrame(); // -------------- // PROGRESS FRAME // -------------- ThreadUtil.invokeLater(new Runnable() { @Override public void run() { _progressFrame = new IcyFrame("", false, false, false, false); _progressBar = new JProgressBar(); _progressBar.setString("Please wait while loading..."); _progressBar.setStringPainted(true); _progressBar.setIndeterminate(true); _progressBar.setMinimum(0); _progressBar.setMaximum(1000); _progressBar.setBounds(50, 50, 100, 30); _progressFrame.setSize(300, 100); _progressFrame.setResizable(false); _progressFrame.add(_progressBar); _progressFrame.addToMainDesktopPane(); loadConfig(true); if (_sysConfigFile == "") { instancing = false; return; } ThreadUtil.bgRun(new Runnable() { @Override public void run() { while (!_isConfigLoaded) { if (!instancing) return; try { Thread.sleep(10); } catch (InterruptedException e) { } } ThreadUtil.invokeLater(new Runnable() { @Override public void run() { // -------------------- // START INITIALIZATION // -------------------- if (_progressBar != null) getContentPane().remove(_progressBar); if (mCore == null) { close(); return; } // ReportingUtils.setCore(mCore); _afMgr = new AutofocusManager(MMMainFrame.this); acqMgr = new AcquisitionManager(); PositionList posList = new PositionList(); _camera_label = MMCoreJ.getG_Keyword_CameraName(); if (_camera_label == null) _camera_label = ""; try { setPositionList(posList); } catch (MMScriptException e1) { e1.printStackTrace(); } posListDlg_ = new PositionListDlg(mCore, MMMainFrame.this, _posList, null, dlg); posListDlg_.setModalityType(ModalityType.APPLICATION_MODAL); callback = new EventCallBackManager(); mCore.registerCallback(callback); engine_ = new AcquisitionWrapperEngineIcy(); engine_.setParentGUI(MMMainFrame.this); engine_.setCore(mCore, getAutofocusManager()); engine_.setPositionList(getPositionList()); setSystemMenuCallback(new MenuCallback() { @Override public JMenu getMenu() { JMenu toReturn = MMMainFrame.this.getDefaultSystemMenu(); JMenuItem hconfig = new JMenuItem("Configuration Wizard"); hconfig.setIcon(new IcyIcon("cog", MENU_ICON_SIZE)); hconfig.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!_pluginListEmpty && !ConfirmDialog.confirm("Are you sure ?", "<html>Loading the Configuration Wizard will unload all the devices and pause all running acquisitions.</br> Are you sure you want to continue ?</html>")) return; notifyConfigAboutToChange(null); try { mCore.unloadAllDevices(); } catch (Exception e1) { e1.printStackTrace(); } String previous_config = _sysConfigFile; ConfiguratorDlg2 configurator = new ConfiguratorDlg2(mCore, _sysConfigFile); configurator.setVisible(true); String res = configurator.getFileName(); if (_sysConfigFile == "" || _sysConfigFile == res || res == "") { _sysConfigFile = previous_config; loadConfig(); } refreshGUI(); notifyConfigChanged(null); } }); JMenuItem menuPxSizeConfigItem = new JMenuItem("Pixel Size Config"); menuPxSizeConfigItem.setIcon(new IcyIcon("link", MENU_ICON_SIZE)); menuPxSizeConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); menuPxSizeConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CalibrationListDlg dlg = new CalibrationListDlg(mCore); dlg.setDefaultCloseOperation(2); dlg.setParentGUI(MMMainFrame.this); dlg.setVisible(true); dlg.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { super.windowClosed(e); notifyConfigChanged(null); } }); notifyConfigAboutToChange(null); } }); JMenuItem loadConfigItem = new JMenuItem("Load Configuration"); loadConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); loadConfigItem.setIcon(new IcyIcon("folder_open", MENU_ICON_SIZE)); loadConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loadConfig(); initializeGUI(); refreshGUI(); } }); JMenuItem saveConfigItem = new JMenuItem("Save Configuration"); saveConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK)); saveConfigItem.setIcon(new IcyIcon("save", MENU_ICON_SIZE)); saveConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveConfig(); } }); JMenuItem advancedConfigItem = new JMenuItem("Advanced Configuration"); advancedConfigItem.setIcon(new IcyIcon("wrench_plus", MENU_ICON_SIZE)); advancedConfigItem.addActionListener(new ActionListener() { /** */ @Override public void actionPerformed(ActionEvent e) { new ToolTipFrame( "<html><h3>About Advanced Config</h3><p>Advanced Configuration is a tool " + "in which you fill some data <br/>about your configuration that some " + "plugins may need to access to.<br/> Exemple: the real values of the magnification" + "of your objectives.</p></html>", "MM4IcyAdvancedConfig"); if (advancedDlg == null) advancedDlg = new AdvancedConfigurationDialog(); advancedDlg.setVisible(!advancedDlg.isVisible()); advancedDlg.setLocationRelativeTo(mainFrame); } }); JMenuItem loadPresetConfigItem = new JMenuItem( "Load Configuration Presets"); loadPresetConfigItem.setIcon(new IcyIcon("doc_import", MENU_ICON_SIZE)); loadPresetConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { notifyConfigAboutToChange(null); loadPresets(); notifyConfigChanged(null); } }); JMenuItem savePresetConfigItem = new JMenuItem( "Save Configuration Presets"); savePresetConfigItem.setIcon(new IcyIcon("doc_export", MENU_ICON_SIZE)); savePresetConfigItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { savePresets(); } }); JMenuItem aboutItem = new JMenuItem("About"); aboutItem.setIcon(new IcyIcon("info", MENU_ICON_SIZE)); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JDialog dialog = new JDialog(mainFrame, "About"); JPanel panel_container = new JPanel(); panel_container .setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); JPanel center = new JPanel(new BorderLayout()); final JLabel value = new JLabel("<html><body>" + "<h2>About</h2><p>Micro-Manager for Icy is being developed by Thomas Provoost." + "<br/>Copyright 2011, Institut Pasteur</p><br/>" + "<p>This plugin is based on Micro-Manager v1.4.6. which is developed under the following license:<br/>" + "<i>This software is distributed free of charge in the hope that it will be<br/>" + "useful, but WITHOUT ANY WARRANTY; without even the implied<br/>" + "warranty of merchantability or fitness for a particular purpose. In no<br/>" + "event shall the copyright owner or contributors be liable for any direct,<br/>" + "indirect, incidental spacial, examplary, or consequential damages.<br/>" + "Copyright University of California San Francisco, 2007, 2008, 2009,<br/>" + "2010. All rights reserved.</i>" + "</p>" + "</body></html>"); JLabel link = new JLabel( "<html><a href=\"\">For more information, please follow this link.</a></html>"); link.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseevent) { NetworkUtil.openBrowser( "http://valelab.ucsf.edu/~MM/MMwiki/index.php/Micro-Manager"); } }); value.setSize(new Dimension(50, 18)); value.setAlignmentX(SwingConstants.HORIZONTAL); value.setBorder(BorderFactory.createEmptyBorder(0, 0, 20, 0)); center.add(value, BorderLayout.CENTER); center.add(link, BorderLayout.SOUTH); JPanel panel_south = new JPanel(); panel_south.setLayout(new BoxLayout(panel_south, BoxLayout.X_AXIS)); JButton btn = new JButton("OK"); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionevent) { dialog.dispose(); } }); panel_south.add(Box.createHorizontalGlue()); panel_south.add(btn); panel_south.add(Box.createHorizontalGlue()); dialog.setLayout(new BorderLayout()); panel_container.setLayout(new BorderLayout()); panel_container.add(center, BorderLayout.CENTER); panel_container.add(panel_south, BorderLayout.SOUTH); dialog.add(panel_container, BorderLayout.CENTER); dialog.setResizable(false); dialog.setVisible(true); dialog.pack(); dialog.setLocation( (int) mainFrame.getSize().getWidth() / 2 - dialog.getWidth() / 2, (int) mainFrame.getSize().getHeight() / 2 - dialog.getHeight() / 2); dialog.setLocationRelativeTo(mainFrame); } }); JMenuItem propertyBrowserItem = new JMenuItem("Property Browser"); propertyBrowserItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, SHORTCUTKEY_MASK)); propertyBrowserItem.setIcon(new IcyIcon("db", MENU_ICON_SIZE)); propertyBrowserItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editor.setVisible(!editor.isVisible()); } }); int idx = 0; toReturn.insert(hconfig, idx++); toReturn.insert(loadConfigItem, idx++); toReturn.insert(saveConfigItem, idx++); toReturn.insert(advancedConfigItem, idx++); toReturn.insertSeparator(idx++); toReturn.insert(loadPresetConfigItem, idx++); toReturn.insert(savePresetConfigItem, idx++); toReturn.insertSeparator(idx++); toReturn.insert(propertyBrowserItem, idx++); toReturn.insert(menuPxSizeConfigItem, idx++); toReturn.insertSeparator(idx++); toReturn.insert(aboutItem, idx++); return toReturn; } }); saveConfigButton_ = new JButton("Save Button"); // SETUP _groupPad = new ConfigGroupPad(); _groupPad.setParentGUI(MMMainFrame.this); _groupPad.setFont(new Font("", 0, 10)); _groupPad.setCore(mCore); _groupPad.setParentGUI(MMMainFrame.this); _groupButtonsPanel = new ConfigButtonsPanel(); _groupButtonsPanel.setCore(mCore); _groupButtonsPanel.setGUI(MMMainFrame.this); _groupButtonsPanel.setConfigPad(_groupPad); // LEFT PART OF INTERFACE _panelConfig = new JPanel(); _panelConfig.setLayout(new BoxLayout(_panelConfig, BoxLayout.Y_AXIS)); _panelConfig.add(_groupPad, BorderLayout.CENTER); _panelConfig.add(_groupButtonsPanel, BorderLayout.SOUTH); _panelConfig.setPreferredSize(new Dimension(300, 300)); // MIDDLE PART OF INTERFACE _panel_cameraSettings = new JPanel(); _panel_cameraSettings.setLayout(new GridLayout(5, 2)); _panel_cameraSettings.setMinimumSize(new Dimension(100, 200)); _txtExposure = new JTextField(); try { mCore.setExposure(90.0D); _txtExposure.setText(String.valueOf(mCore.getExposure())); } catch (Exception e2) { _txtExposure.setText("90"); } _txtExposure.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20)); _txtExposure.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent keyevent) { if (keyevent.getKeyCode() == KeyEvent.VK_ENTER) setExposure(); } }); _panel_cameraSettings.add(new JLabel("Exposure [ms]: ")); _panel_cameraSettings.add(_txtExposure); _combo_binning = new JComboBox(); _combo_binning.setMaximumRowCount(4); _combo_binning.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25)); _combo_binning.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { changeBinning(); } }); _panel_cameraSettings.add(new JLabel("Binning: ")); _panel_cameraSettings.add(_combo_binning); _combo_shutters = new JComboBox(); _combo_shutters.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { if (_combo_shutters.getSelectedItem() != null) { mCore.setShutterDevice((String) _combo_shutters.getSelectedItem()); _prefs.put(PREF_SHUTTER, (String) _combo_shutters .getItemAt(_combo_shutters.getSelectedIndex())); } } catch (Exception e) { e.printStackTrace(); } } }); _combo_shutters.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25)); _panel_cameraSettings.add(new JLabel("Shutter : ")); _panel_cameraSettings.add(_combo_shutters); ActionListener action_listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateHistogram(); } }; _cbAbsoluteHisto = new JCheckBox(); _cbAbsoluteHisto.addActionListener(action_listener); _cbAbsoluteHisto.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionevent) { _comboBitDepth.setEnabled(_cbAbsoluteHisto.isSelected()); _prefs.putBoolean(PREF_ABS_HIST, _cbAbsoluteHisto.isSelected()); } }); _panel_cameraSettings.add(new JLabel("Display absolute histogram ?")); _panel_cameraSettings.add(_cbAbsoluteHisto); _comboBitDepth = new JComboBox(new String[] { "8-bit", "9-bit", "10-bit", "11-bit", "12-bit", "13-bit", "14-bit", "15-bit", "16-bit" }); _comboBitDepth.addActionListener(action_listener); _comboBitDepth.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionevent) { _prefs.putInt(PREF_BITDEPTH, _comboBitDepth.getSelectedIndex()); } }); _comboBitDepth.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20)); _comboBitDepth.setEnabled(false); _panel_cameraSettings.add(new JLabel("Select your bit depth for abs. hitogram: ")); _panel_cameraSettings.add(_comboBitDepth); // Acquisition _panelAcquisitions = new JPanel(); _panelAcquisitions.setLayout(new BoxLayout(_panelAcquisitions, BoxLayout.Y_AXIS)); // Color settings _panelColorChooser = new JPanel(); _panelColorChooser.setLayout(new BoxLayout(_panelColorChooser, BoxLayout.Y_AXIS)); painterPreferences = MicroscopePainterPreferences.getInstance(); painterPreferences.setPreferences(_prefs.node("paintersPreferences")); painterPreferences.loadColors(); HashMap<String, Color> allColors = painterPreferences.getColors(); String[] allKeys = (String[]) allColors.keySet().toArray(new String[0]); String[] columnNames = { "Painter", "Color", "Transparency" }; Object[][] data = new Object[allKeys.length][3]; for (int i = 0; i < allKeys.length; ++i) { final int actualRow = i; String actualKey = allKeys[i].toString(); data[i][0] = actualKey; data[i][1] = allColors.get(actualKey); final JSlider slider = new JSlider(0, 255, allColors.get(actualKey).getAlpha()); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent changeevent) { painterTable.setValueAt(slider, actualRow, 2); } }); data[i][2] = slider; } final AbstractTableModel tableModel = new JTableEvolvedModel(columnNames, data); painterTable = new JTable(tableModel); painterTable.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent tablemodelevent) { if (tablemodelevent.getType() == TableModelEvent.UPDATE) { int row = tablemodelevent.getFirstRow(); int col = tablemodelevent.getColumn(); String columnName = tableModel.getColumnName(col); String painterName = (String) tableModel.getValueAt(row, 0); if (columnName.contains("Color")) { // New color value int alpha = painterPreferences.getColor(painterName).getAlpha(); Color coloNew = (Color) tableModel.getValueAt(row, 1); painterPreferences.setColor(painterName, new Color(coloNew.getRed(), coloNew.getGreen(), coloNew.getBlue(), alpha)); } else if (columnName.contains("Transparency")) { // New alpha value Color c = painterPreferences.getColor(painterName); int alphaValue = ((JSlider) tableModel.getValueAt(row, 2)) .getValue(); painterPreferences.setColor(painterName, new Color(c.getRed(), c.getGreen(), c.getBlue(), alphaValue)); } /* * for (int i = 0; i < * tableModel.getRowCount(); ++i) { try { * String painterName = (String) * tableModel.getValueAt(i, 0); Color c = * (Color) tableModel.getValueAt(i, 1); int * alphaValue; if (ASpinnerChanged && * tablemodelevent.getFirstRow() == i) { * alphaValue = ((JSlider) * tableModel.getValueAt(i, 2)).getValue(); * } else { alphaValue = * painterPreferences.getColor * (painterPreferences * .getPainterName(i)).getAlpha(); } * painterPreferences.setColor(painterName, * new Color(c.getRed(), c.getGreen(), * c.getBlue(), alphaValue)); } catch * (Exception e) { System.out.println( * "error with painter table update"); } } */ } } }); painterTable.setPreferredScrollableViewportSize(new Dimension(500, 70)); painterTable.setFillsViewportHeight(true); // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(painterTable); // Set up renderer and editor for the Favorite Color // column. painterTable.setDefaultRenderer(Color.class, new ColorRenderer(true)); painterTable.setDefaultEditor(Color.class, new ColorEditor()); painterTable.setDefaultRenderer(JSlider.class, new SliderRenderer(0, 255)); painterTable.setDefaultEditor(JSlider.class, new SliderEditor()); _panelColorChooser.add(scrollPane); _panelColorChooser.add(Box.createVerticalGlue()); _mainPanel = new JPanel(); _mainPanel.setLayout(new BorderLayout()); // EDITOR // will refresh the data and verify if any change // occurs. // editor = new PropertyEditor(MMMainFrame.this); // editor.setCore(mCore); // editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); // editor.addToMainDesktopPane(); // editor.refresh(); // editor.start(); editor = new PropertyEditor(); editor.setGui(MMMainFrame.this); editor.setCore(mCore); editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); // editor.addToMainDesktopPane(); // editor.refresh(); // editor.start(); add(_mainPanel); initializeGUI(); loadPreferences(); refreshGUI(); setResizable(true); addToMainDesktopPane(); instanced = true; instancing = false; _singleton = MMMainFrame.this; setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addFrameListener(new IcyFrameAdapter() { @Override public void icyFrameClosing(IcyFrameEvent e) { customClose(); } }); acceptListener = new AcceptListener() { @Override public boolean accept(Object source) { close(); return _pluginListEmpty; } }; adapter = new MainAdapter() { @Override public void sequenceOpened(MainEvent event) { updateHistogram(); } }; Icy.getMainInterface().addCanExitListener(acceptListener); Icy.getMainInterface().addListener(adapter); } }); } }); } }); }
From source file:statechum.analysis.learning.Visualiser.java
public void construct(Graph g, LayoutOptions options) { if (!globalConfig.isAssertEnabled() && Boolean.getBoolean(globalConfig.getProperty(G_PROPERTIES.ASSERT_ENABLED))) { System.err.println("Pass the -ea argument to JVM to enable assertions"); }/*w ww .j a v a 2s.c o m*/ // if (Boolean.valueOf(GlobalConfiguration.getConfiguration() .getProperty(GlobalConfiguration.G_PROPERTIES.CLOSE_TERMINATE))) this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); else if (Boolean.valueOf( GlobalConfiguration.getConfiguration().getProperty(GlobalConfiguration.G_PROPERTIES.ESC_TERMINATE))) this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); else this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); this.addWindowListener(new WindowEventHandler()); /* this.addComponentListener(new ComponentListener() { @Override public void componentShown(@SuppressWarnings("unused") ComponentEvent e) {} @Override public void componentResized(@SuppressWarnings("unused") ComponentEvent e) { if (viewer != null) viewer.getModel().getGraphLayout().resize(getSize()); } @Override public void componentMoved(@SuppressWarnings("unused") ComponentEvent e) {} @Override public void componentHidden(@SuppressWarnings("unused") ComponentEvent e) {} });*/ this.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { Action act = keyToActionMap.get(arg0.getKeyCode()); if (act != null) { act.actionPerformed(null); } } @Override public void keyReleased(@SuppressWarnings("unused") KeyEvent arg0) {// this method is intentionally left blank - keypresses/releases are handled by the keyPressed method. } @Override public void keyTyped(@SuppressWarnings("unused") KeyEvent key) {// this method is intentionally left blank - keypresses/releases are handled by the keyPressed method. } }); popupMenu = new JPopupMenu(); // Icon loading is from http://www.javaworld.com/javaworld/javaqa/2000-06/03-qa-0616-icon.html Image icon = Toolkit.getDefaultToolkit() .getImage(GlobalConfiguration.getConfiguration().getProperty(G_PROPERTIES.RESOURCES) + File.separator + "icon.jpg"); if (icon != null) { setIconImage(icon); } setVisualiserKeyBindings(); setStateChumKeyBindings(this, propName, keyToActionMap); updatePopupMenu(popupMenu, keyToActionMap); //getContentPane().removeAll(); WindowPosition framePosition = globalConfig.loadFrame(propName); viewer = new VisualizationViewer( new DefaultVisualizationModel( new XMLPersistingLayout(propName >= 0 ? new FRLayout(g) : new KKLayout(g))), constructRenderer(g, options)); viewer.setBackground(Color.WHITE); final DefaultModalGraphMouse graphMouse = new XMLModalGraphMouse(); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); graphMouse.add(new PickingGraphMousePlugin()); viewer.setGraphMouse(graphMouse); viewer.setPickSupport(new ShapePickSupport()); viewer.addMouseListener(this); final GraphZoomScrollPane panel = new GraphZoomScrollPane(viewer); getContentPane().add(panel); pack(); viewer.setPreferredSize(getSize()); //viewer.getModel().getGraphLayout().initialize(getSize()); restoreLayout(true, currentGraph); setBounds(framePosition.getRect()); framesVisible.add(this);// register as an active frame. setVisible(true); }