List of usage examples for javax.swing JFrame addWindowListener
public synchronized void addWindowListener(WindowListener l)
From source file:org.swiftexplorer.SwiftExplorer.java
private static void openMainWindow(final MainPanel cp) throws IOException { JFrame frame = new JFrame(Configuration.INSTANCE.getAppName()); Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); float ratio = (float) 0.8; Dimension windowSize = new Dimension((int) (screenSize.getWidth() * ratio), (int) (screenSize.getHeight() * ratio)); frame.setSize(windowSize.getSize()); frame.setLocationByPlatform(true);//from www .j a v a 2s . c om frame.setIconImage(ImageIO.read(SwiftExplorer.class.getResource("/icons/logo.png"))); frame.getContentPane().add(cp); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (cp.onClose()) { System.exit(0); } } }); cp.setOwner(frame); frame.setJMenuBar(cp.createMenuBar()); // center the frame int x = (int) ((screenSize.getWidth() - frame.getWidth()) / 2); int y = (int) ((screenSize.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); frame.setVisible(true); }
From source file:org.syphr.mythtv.apps.previewer.Main.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); CommandLine cl;/*from w w w .j a va 2s . c o m*/ try { cl = parser.parse(PreviewerOption.getOptions(), args); if (PreviewerOption.HELP.hasOption(cl)) { dumpUsage(null); } try { final AutomaticProtocol protocol = connect(cl); protocol.mythProtoVersion(); protocol.ann(ConnectionType.PLAYBACK, InetAddress.getLocalHost().getHostName(), EventLevel.NONE); setLookAndFeel(); JFrame frame = new PreviewerWindow(protocol); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent event) { try { protocol.done(); } catch (IOException e) { // ignore failure on disconnect } } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); centerAndSize(frame, 0.8f); frame.setVisible(true); } catch (ProtocolVersionException e) { System.out.println("Host speaks unsupported protocol version " + e.getSupportedVersionStr()); System.exit(1); } catch (IOException e) { System.out.println("Connection with remote host failed."); System.out.println(e.getMessage()); System.exit(1); } } catch (ParseException e) { dumpUsage("Failed to parse command line: " + e.getMessage()); } }
From source file:test.uk.co.modularaudio.util.swing.colouredtoggle.TestUseColouredLabelToggle.java
public void go() throws Exception { final JFrame testFrame = new JFrame("TestFrame"); testFrame.setSize(new Dimension(300, 300)); testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Container contentPane = testFrame.getContentPane(); final MigLayoutStringHelper msh = new MigLayoutStringHelper(); msh.addLayoutConstraint("fill"); msh.addLayoutConstraint("gap 0"); msh.addLayoutConstraint("insets 0"); contentPane.setLayout(msh.createMigLayout()); final Color surroundColor = Color.decode("#FFFFFF"); final Color backgroundColor = Color.BLACK; final Color foregroundColor = Color.white; final ToggleReceiver testReceiver = new ToggleReceiver() { @Override/*from ww w . j a v a2s . com*/ public void receiveToggle(final int toggleId, final boolean active) { log.trace("Received a toggle of " + toggleId + " to " + active); } }; final ColouredLabelToggle clt = new ColouredLabelToggle("Trigger", "Tooltip Text", backgroundColor, foregroundColor, surroundColor, false, testReceiver, 0); contentPane.add(clt, "grow"); testFrame.pack(); testFrame.addWindowListener(new WindowListener() { @Override public void windowOpened(final WindowEvent e) { } @Override public void windowIconified(final WindowEvent e) { } @Override public void windowDeiconified(final WindowEvent e) { } @Override public void windowDeactivated(final WindowEvent e) { } @Override public void windowClosing(final WindowEvent e) { log.trace("Window closing. Value of control is \"" + clt.getControlValue() + "\""); } @Override public void windowClosed(final WindowEvent e) { } @Override public void windowActivated(final WindowEvent e) { } }); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { log.trace("Showing test frame"); testFrame.setVisible(true); } }); }
From source file:test.uk.co.modularaudio.util.swing.colouredtoggle.TestUseColouredTextToggle.java
public void go() throws Exception { final JFrame testFrame = new JFrame("TestFrame"); testFrame.setSize(new Dimension(300, 300)); testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Container contentPane = testFrame.getContentPane(); final MigLayoutStringHelper msh = new MigLayoutStringHelper(); msh.addLayoutConstraint("fill"); msh.addLayoutConstraint("gap 0"); msh.addLayoutConstraint("insets 0"); contentPane.setLayout(msh.createMigLayout()); final Color surroundColor = Color.decode("#44BB44"); final Color backgroundColor = Color.BLACK; final ToggleReceiver testReceiver = new ToggleReceiver() { @Override/*from w w w. j av a2s . c om*/ public void receiveToggle(final int toggleId, final boolean active) { log.trace("Received a toggle of " + toggleId + " to " + active); } }; final ColouredTextToggle ctt = new ColouredTextToggle("NoTS", "Tooltip Text", backgroundColor, surroundColor, false, testReceiver, 1); contentPane.add(ctt, "grow"); testFrame.pack(); testFrame.addWindowListener(new WindowListener() { @Override public void windowOpened(final WindowEvent e) { } @Override public void windowIconified(final WindowEvent e) { } @Override public void windowDeiconified(final WindowEvent e) { } @Override public void windowDeactivated(final WindowEvent e) { } @Override public void windowClosing(final WindowEvent e) { log.trace("Window closing. Value of control is \"" + ctt.getControlValue() + "\""); } @Override public void windowClosed(final WindowEvent e) { } @Override public void windowActivated(final WindowEvent e) { } }); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { log.trace("Showing test frame"); testFrame.setVisible(true); } }); }
From source file:test.uk.co.modularaudio.util.swing.texttoggle.TestUseTextToggle.java
public void go() throws Exception { final JFrame testFrame = new JFrame("TestFrame"); testFrame.setSize(new Dimension(300, 300)); testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Container contentPane = testFrame.getContentPane(); final MigLayoutStringHelper msh = new MigLayoutStringHelper(); msh.addLayoutConstraint("fill"); msh.addLayoutConstraint("gap 0"); msh.addLayoutConstraint("insets 0"); contentPane.setLayout(msh.createMigLayout()); final Color BACKGROUND_COLOR = Color.BLACK; final Color SCOPE_BODY = new Color(75, 131, 155); final Color SCOPE_AXIS_DETAIL = SCOPE_BODY.darker().darker(); final Color selectedTextColor = SCOPE_BODY; final Color unselectedTextColor = SCOPE_AXIS_DETAIL; final Color borderColor = SCOPE_AXIS_DETAIL; final Color backgroundColor = BACKGROUND_COLOR; final ToggleReceiver testReceiver = new ToggleReceiver() { @Override// w w w .ja v a2s. c om public void receiveToggle(final int toggleId, final boolean active) { log.trace("Received a toggle of " + toggleId + " to " + active); } }; final TextToggle tt = new TextToggle("Bi Polar", "Uni Polar", selectedTextColor, unselectedTextColor, backgroundColor, borderColor, true, true, testReceiver, -1); contentPane.add(tt, "grow"); testFrame.pack(); testFrame.addWindowListener(new WindowListener() { @Override public void windowOpened(final WindowEvent e) { } @Override public void windowIconified(final WindowEvent e) { } @Override public void windowDeiconified(final WindowEvent e) { } @Override public void windowDeactivated(final WindowEvent e) { } @Override public void windowClosing(final WindowEvent e) { log.trace("Window closing. Value of control is \"" + tt.getControlValue() + "\""); } @Override public void windowClosed(final WindowEvent e) { } @Override public void windowActivated(final WindowEvent e) { } }); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { log.trace("Showing test frame"); testFrame.setVisible(true); } }); }
From source file:uk.ac.abdn.csd.p2p.server.ServerGUI.java
/** * This method prepares all the graphical components that are contained with P2P Visualisation Server. *//* www .j a v a 2 s.com*/ // <editor-fold defaultstate="collapsed" desc="...GUI"> private void initializeComponent() { listeningPort = 0; JFrame frame = new JFrame(); BorderLayout layout = new BorderLayout(); //create a graph overlay = new UndirectedSparseGraph<Vertex, Edge>(); ObservableGraph<Vertex, Edge> og = new ObservableGraph<Vertex, Edge>(overlay); /* og.addGraphEventListener(new GraphEventListener<Vertex, Edge>() { @Override public void handleGraphEvent( GraphEvent<Vertex, Edge> evt) { System.err.println("got " + evt); } });*/ this.overlay = og; layout1 = new FRLayout2<Vertex, Edge>(overlay); vv = new VisualizationViewer<Vertex, Edge>(layout1, new Dimension(700, 200)); vv.setGraphMouse(new DefaultModalGraphMouse<Vertex, Edge>()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Vertex>()); vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); vv.getRenderContext().setVertexFillPaintTransformer(new VertexPainter()); DefaultModalGraphMouse gm1 = new DefaultModalGraphMouse(); gm1.setMode(ModalGraphMouse.Mode.TRANSFORMING); gm1.setMode(ModalGraphMouse.Mode.PICKING); gm1.add(new MyPopupGraphMousePlugin()); vv.setGraphMouse(gm1); vv.addKeyListener(gm1.getModeKeyListener()); contentPane = new JPanel(layout); displayPanel = new javax.swing.JPanel(); consoleTextArea = new JTextArea(); jScrollPane2 = new JScrollPane(); clearButton = new JButton(); consolePanel = new JPanel(); clearButton = new javax.swing.JButton(); nodeTextArea = new JTextArea(); jScrollPane1 = new JScrollPane(); nodePanel = new JPanel(); linkTextArea = new JTextArea(); jScrollPane3 = new JScrollPane(); linkPanel = new JPanel(); menuBar = new javax.swing.JMenuBar(); serverMenu = new javax.swing.JMenu(); startServerMenuItem = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JPopupMenu.Separator(); exitMenuItem = new javax.swing.JMenuItem(); editMenu = new javax.swing.JMenu(); settingMenuItem = new javax.swing.JMenuItem(); colorSettingMenuItem = new javax.swing.JMenuItem(); toolMenuItem = new javax.swing.JMenu(); clearMenuItem = new javax.swing.JMenuItem(); helpMenu = new javax.swing.JMenu(); aboutMenuItem = new javax.swing.JMenuItem(); zoominMenuItem = new javax.swing.JMenuItem(); zoomoutMenuItem = new javax.swing.JMenuItem(); layoutSettingMenuItem = new javax.swing.JMenuItem(); labelPositionMenuItem = new javax.swing.JMenuItem(); speedSettingMenuItem = new javax.swing.JMenuItem(); topologySettingMenuItem = new javax.swing.JMenuItem(); findNodeMenuItem = new javax.swing.JMenuItem(); serverMenu.setText("Server"); serverMenu.setToolTipText("Server"); startServerMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK)); startServerMenuItem.setText("Start Server"); startServerMenuItem.setToolTipText("Start Server"); startServerMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { startServerMenuItemActionPerformed(evt); } }); serverMenu.add(startServerMenuItem); serverMenu.add(jSeparator1); exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK)); exitMenuItem.setText("Exit"); exitMenuItem.setToolTipText("Exit"); exitMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { exitMenuItemActionPerformed(evt); } }); serverMenu.add(exitMenuItem); menuBar.add(serverMenu); editMenu.setText("Edit"); editMenu.setToolTipText("Edit"); settingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK)); settingMenuItem.setText("Server Settings"); settingMenuItem.setToolTipText("Server Settings"); settingMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { settingMenuItemActionPerformed(evt); } }); editMenu.add(settingMenuItem); colorSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.ALT_MASK)); colorSettingMenuItem.setText("Colour Settings"); colorSettingMenuItem.setToolTipText("Colour Settings"); colorSettingMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { colorSettingMenuItemActionPerformed(evt); } }); editMenu.add(colorSettingMenuItem); layoutSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.ALT_MASK)); layoutSettingMenuItem.setText("Layout Settings"); layoutSettingMenuItem.setToolTipText("Layout Settings"); layoutSettingMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { layoutSettingMenuItemActionPerformed(evt); } }); editMenu.add(layoutSettingMenuItem); speedSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.ALT_MASK)); speedSettingMenuItem.setText("Speed Settings"); speedSettingMenuItem.setToolTipText("Speed Settings"); speedSettingMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { speedSettingMenuItemActionPerformed(evt); } }); editMenu.add(speedSettingMenuItem); topologySettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK)); topologySettingMenuItem.setText("Topology Settings"); topologySettingMenuItem.setToolTipText("Topology Settings"); topologySettingMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { topologySettingMenuItemActionPerformed(evt); } }); editMenu.add(topologySettingMenuItem); menuBar.add(editMenu); toolMenuItem.setText("Tools"); toolMenuItem.setToolTipText("Tools"); labelPositionMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.ALT_MASK)); labelPositionMenuItem.setText("Vertex Label Position"); labelPositionMenuItem.setToolTipText("Vertex Label Position"); toolMenuItem.add(labelPositionMenuItem); labelPositionMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { labelPositionMenuItemActionPerformed(evt); } }); final ScalingControl scaler = new CrossoverScalingControl(); zoominMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.ALT_MASK)); zoominMenuItem.setText("Zoom-In"); zoominMenuItem.setToolTipText("Zoom-In"); toolMenuItem.add(zoominMenuItem); zoominMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); zoomoutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.ALT_MASK)); zoomoutMenuItem.setText("Zoom-Out"); zoomoutMenuItem.setToolTipText("Zoom-Out"); toolMenuItem.add(zoomoutMenuItem); zoomoutMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { scaler.scale(vv, 0.9f, vv.getCenter()); } }); findNodeMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.ALT_MASK)); findNodeMenuItem.setText("Find Node on Overlay"); findNodeMenuItem.setToolTipText("Find Node"); toolMenuItem.add(findNodeMenuItem); findNodeMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { findNodeMenuItemMenuItemActionPerformed(evt); } }); menuBar.add(toolMenuItem); helpMenu.setText("Help"); helpMenu.setToolTipText("Help"); aboutMenuItem.setText("About"); aboutMenuItem.setToolTipText("About"); aboutMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { aboutMenuItemActionPerformed(evt); } }); helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); displayPanel.setLayout(new BorderLayout()); displayPanel.setBorder(new TitledBorder("P2P Overlay")); displayPanel.add(vv); validate(); // // nodeTextArea // nodeTextArea.setEditable(false); nodeTextArea.setLineWrap(true); // // jScrollPane1 // jScrollPane1.setViewportView(nodeTextArea); //jScrollPane1.setsi // // nodePanel // nodePanel.setLayout(new BoxLayout(nodePanel, BoxLayout.X_AXIS)); nodePanel.add(jScrollPane1, 0); nodePanel.setBorder(new TitledBorder("Nodes Active")); // // linkTextArea // linkTextArea.setEditable(false); linkTextArea.setLineWrap(true); // // jScrollPane3 // jScrollPane3.setViewportView(linkTextArea); // // linkPanel // linkPanel.setLayout(new BoxLayout(linkPanel, BoxLayout.X_AXIS)); linkPanel.add(jScrollPane3, 0); linkPanel.setBorder(new TitledBorder("Node Links")); // // consoleTextArea // consoleTextArea.setEditable(false); consoleTextArea.setLineWrap(true); // // jScrollPane2 // jScrollPane2.setViewportView(consoleTextArea); // // clearButton // clearButton.setText("Clear"); clearButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { clearButton_actionPerformed(e); } }); // // consolePanel // consolePanel.setLayout(new BoxLayout(consolePanel, BoxLayout.X_AXIS)); consolePanel.add(jScrollPane2, 0); consolePanel.add(clearButton, 1); consolePanel.setBorder(new TitledBorder("Console")); // // ServerGUI // Dimension panelD = new Dimension(700, 330); // display Panel Dimension panelD1 = new Dimension(700, 134); // control Panel Dimension panelD2 = new Dimension(350, 140); // nodepanel and linkpanel Dimension panelD3 = new Dimension(700, 140); // nodepanel and linkpanel togther consolePanel.setPreferredSize(panelD1); displayPanel.setPreferredSize(panelD); nodePanel.setPreferredSize(panelD2); linkPanel.setPreferredSize(panelD2); Box box = new Box(BoxLayout.X_AXIS); // put nodepanel and linkpanel in one box box.add(nodePanel); box.add(linkPanel); box.setSize(panelD3); //contentPane.add(BorderLayout.NORTH,displayPanel); //contentPane.add(BorderLayout.CENTER,box); contentPane.add(BorderLayout.NORTH, box); contentPane.add(BorderLayout.CENTER, displayPanel); contentPane.add(BorderLayout.SOUTH, consolePanel); frame.setJMenuBar(menuBar); frame.getContentPane().add(contentPane); frame.setTitle("P2P Visualisation Server"); frame.setSize(new Dimension(800, 600)); frame.setResizable(true); // This code has been adapted from http://lookass.ch/?id=4&area=art&art=47 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = frame.getSize(); screenSize.height = screenSize.height / 2; screenSize.width = screenSize.width / 2; size.height = size.height / 2; size.width = size.width / 2; int y = screenSize.height - size.height; int x = screenSize.width - size.width; frame.setLocation(x, y); frame.setVisible(true); frame.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); }
From source file:weka.gui.beans.KnowledgeFlowRemoteSchedulerPerspective.java
/** * Main method for testing this class/*from ww w . j a v a 2 s . c o m*/ * * @param args command line arguments */ public static void main(String[] args) { final javax.swing.JFrame jf = new javax.swing.JFrame(); jf.getContentPane().setLayout(new java.awt.BorderLayout()); KnowledgeFlowRemoteSchedulerPerspective p = new KnowledgeFlowRemoteSchedulerPerspective(); jf.getContentPane().add(p, BorderLayout.CENTER); jf.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { jf.dispose(); System.exit(0); } }); jf.setSize(800, 600); jf.setVisible(true); }