Search in sources :

Example 86 with WindowAdapter

use of java.awt.event.WindowAdapter in project jmonkeyengine by jMonkeyEngine.

the class TestCanvas method createFrame.

private static void createFrame() {
    frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            app.stop();
        }
    });
    createTabs();
    createMenu();
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 87 with WindowAdapter

use of java.awt.event.WindowAdapter in project Smack by igniterealtime.

the class EnhancedDebuggerWindow method createDebug.

/**
     * Creates the main debug window that provides information about Smack and also shows
     * a tab panel for each connection that is being debugged.
     */
@SuppressWarnings({ "rawtypes", "unchecked" })
private void createDebug() {
    frame = new JFrame("Smack Debug Window");
    if (!PERSISTED_DEBUGGER) {
        // Add listener for window closing event
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent evt) {
                rootWindowClosing(evt);
            }
        });
    }
    // We'll arrange the UI into tabs. The last tab contains Smack's information.
    // All the connection debugger tabs will be shown before the Smack info tab. 
    tabbedPane = new JTabbedPane();
    // Create the Smack info panel 
    JPanel informationPanel = new JPanel();
    informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.Y_AXIS));
    // Add the Smack version label
    JPanel versionPanel = new JPanel();
    versionPanel.setLayout(new BoxLayout(versionPanel, BoxLayout.X_AXIS));
    versionPanel.setMaximumSize(new Dimension(2000, 31));
    versionPanel.add(new JLabel(" Smack version: "));
    JFormattedTextField field = new JFormattedTextField(SmackConfiguration.getVersion());
    field.setEditable(false);
    field.setBorder(null);
    versionPanel.add(field);
    informationPanel.add(versionPanel);
    // Add the list of installed IQ Providers
    JPanel iqProvidersPanel = new JPanel();
    iqProvidersPanel.setLayout(new GridLayout(1, 1));
    iqProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed IQ Providers"));
    Vector<String> providers = new Vector<String>();
    for (Object provider : ProviderManager.getIQProviders()) {
        if (provider.getClass() == Class.class) {
            providers.add(((Class<?>) provider).getName());
        } else {
            providers.add(provider.getClass().getName());
        }
    }
    // Sort the collection of providers
    Collections.sort(providers);
    JList list = new JList(providers);
    iqProvidersPanel.add(new JScrollPane(list));
    informationPanel.add(iqProvidersPanel);
    // Add the list of installed Extension Providers
    JPanel extensionProvidersPanel = new JPanel();
    extensionProvidersPanel.setLayout(new GridLayout(1, 1));
    extensionProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed Extension Providers"));
    providers = new Vector<String>();
    for (Object provider : ProviderManager.getExtensionProviders()) {
        if (provider.getClass() == Class.class) {
            providers.add(((Class<?>) provider).getName());
        } else {
            providers.add(provider.getClass().getName());
        }
    }
    // Sort the collection of providers
    Collections.sort(providers);
    list = new JList(providers);
    extensionProvidersPanel.add(new JScrollPane(list));
    informationPanel.add(extensionProvidersPanel);
    tabbedPane.add("Smack Info", informationPanel);
    // Add pop-up menu.
    JPopupMenu menu = new JPopupMenu();
    // Add a menu item that allows to close the current selected tab
    JMenuItem menuItem = new JMenuItem("Close");
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Remove the selected tab pane if it's not the Smack info pane
            if (tabbedPane.getSelectedIndex() < tabbedPane.getComponentCount() - 1) {
                int index = tabbedPane.getSelectedIndex();
                // Notify to the debugger to stop debugging
                EnhancedDebugger debugger = debuggers.get(index);
                debugger.cancel();
                // Remove the debugger from the root window
                tabbedPane.remove(debugger.tabbedPane);
                debuggers.remove(debugger);
                // Update the root window title
                frame.setTitle("Smack Debug Window -- Total connections: " + (tabbedPane.getComponentCount() - 1));
            }
        }
    });
    menu.add(menuItem);
    // Add a menu item that allows to close all the tabs that have their connections closed
    menuItem = new JMenuItem("Close All Not Active");
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ArrayList<EnhancedDebugger> debuggersToRemove = new ArrayList<EnhancedDebugger>();
            // Remove all the debuggers of which their connections are no longer valid
            for (int index = 0; index < tabbedPane.getComponentCount() - 1; index++) {
                EnhancedDebugger debugger = debuggers.get(index);
                if (!debugger.isConnectionActive()) {
                    // Notify to the debugger to stop debugging
                    debugger.cancel();
                    debuggersToRemove.add(debugger);
                }
            }
            for (EnhancedDebugger debugger : debuggersToRemove) {
                // Remove the debugger from the root window
                tabbedPane.remove(debugger.tabbedPane);
                debuggers.remove(debugger);
            }
            // Update the root window title
            frame.setTitle("Smack Debug Window -- Total connections: " + (tabbedPane.getComponentCount() - 1));
        }
    });
    menu.add(menuItem);
    // Add listener to the text area so the popup menu can come up.
    tabbedPane.addMouseListener(new PopupListener(menu));
    frame.getContentPane().add(tabbedPane);
    frame.setSize(650, 400);
    if (!PERSISTED_DEBUGGER) {
        frame.setVisible(true);
    }
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) JTabbedPane(javax.swing.JTabbedPane) BoxLayout(javax.swing.BoxLayout) ArrayList(java.util.ArrayList) WindowAdapter(java.awt.event.WindowAdapter) GridLayout(java.awt.GridLayout) JFrame(javax.swing.JFrame) JMenuItem(javax.swing.JMenuItem) Vector(java.util.Vector) JScrollPane(javax.swing.JScrollPane) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) JList(javax.swing.JList)

Example 88 with WindowAdapter

use of java.awt.event.WindowAdapter in project Smack by igniterealtime.

the class LiteDebugger method createDebug.

/**
     * Creates the debug process, which is a GUI window that displays XML traffic.
     */
private void createDebug() {
    frame = new JFrame("Smack Debug Window -- " + connection.getXMPPServiceDomain() + ":" + connection.getPort());
    // Add listener for window closing event 
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            rootWindowClosing(evt);
        }
    });
    // We'll arrange the UI into four tabs. The first tab contains all data, the second
    // client generated XML, the third server generated XML, and the fourth is packet
    // data from the server as seen by Smack.
    JTabbedPane tabbedPane = new JTabbedPane();
    JPanel allPane = new JPanel();
    allPane.setLayout(new GridLayout(3, 1));
    tabbedPane.add("All", allPane);
    // Create UI elements for client generated XML traffic.
    final JTextArea sentText1 = new JTextArea();
    final JTextArea sentText2 = new JTextArea();
    sentText1.setEditable(false);
    sentText2.setEditable(false);
    sentText1.setForeground(new Color(112, 3, 3));
    sentText2.setForeground(new Color(112, 3, 3));
    allPane.add(new JScrollPane(sentText1));
    tabbedPane.add("Sent", new JScrollPane(sentText2));
    // Add pop-up menu.
    JPopupMenu menu = new JPopupMenu();
    JMenuItem menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(sentText1.getText()), null);
        }
    });
    JMenuItem menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            sentText1.setText("");
            sentText2.setText("");
        }
    });
    // Add listener to the text area so the popup menu can come up.
    MouseListener popupListener = new PopupListener(menu);
    sentText1.addMouseListener(popupListener);
    sentText2.addMouseListener(popupListener);
    menu.add(menuItem1);
    menu.add(menuItem2);
    // Create UI elements for server generated XML traffic.
    final JTextArea receivedText1 = new JTextArea();
    final JTextArea receivedText2 = new JTextArea();
    receivedText1.setEditable(false);
    receivedText2.setEditable(false);
    receivedText1.setForeground(new Color(6, 76, 133));
    receivedText2.setForeground(new Color(6, 76, 133));
    allPane.add(new JScrollPane(receivedText1));
    tabbedPane.add("Received", new JScrollPane(receivedText2));
    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(receivedText1.getText()), null);
        }
    });
    menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            receivedText1.setText("");
            receivedText2.setText("");
        }
    });
    // Add listener to the text area so the popup menu can come up.
    popupListener = new PopupListener(menu);
    receivedText1.addMouseListener(popupListener);
    receivedText2.addMouseListener(popupListener);
    menu.add(menuItem1);
    menu.add(menuItem2);
    // Create UI elements for interpreted XML traffic.
    final JTextArea interpretedText1 = new JTextArea();
    final JTextArea interpretedText2 = new JTextArea();
    interpretedText1.setEditable(false);
    interpretedText2.setEditable(false);
    interpretedText1.setForeground(new Color(1, 94, 35));
    interpretedText2.setForeground(new Color(1, 94, 35));
    allPane.add(new JScrollPane(interpretedText1));
    tabbedPane.add("Interpreted", new JScrollPane(interpretedText2));
    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(interpretedText1.getText()), null);
        }
    });
    menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            interpretedText1.setText("");
            interpretedText2.setText("");
        }
    });
    // Add listener to the text area so the popup menu can come up.
    popupListener = new PopupListener(menu);
    interpretedText1.addMouseListener(popupListener);
    interpretedText2.addMouseListener(popupListener);
    menu.add(menuItem1);
    menu.add(menuItem2);
    frame.getContentPane().add(tabbedPane);
    frame.setSize(550, 400);
    frame.setVisible(true);
    // Create a special Reader that wraps the main Reader and logs data to the GUI.
    ObservableReader debugReader = new ObservableReader(reader);
    readerListener = new ReaderListener() {

        @Override
        public void read(String str) {
            int index = str.lastIndexOf(">");
            if (index != -1) {
                receivedText1.append(str.substring(0, index + 1));
                receivedText2.append(str.substring(0, index + 1));
                receivedText1.append(NEWLINE);
                receivedText2.append(NEWLINE);
                if (str.length() > index) {
                    receivedText1.append(str.substring(index + 1));
                    receivedText2.append(str.substring(index + 1));
                }
            } else {
                receivedText1.append(str);
                receivedText2.append(str);
            }
        }
    };
    debugReader.addReaderListener(readerListener);
    // Create a special Writer that wraps the main Writer and logs data to the GUI.
    ObservableWriter debugWriter = new ObservableWriter(writer);
    writerListener = new WriterListener() {

        @Override
        public void write(String str) {
            sentText1.append(str);
            sentText2.append(str);
            if (str.endsWith(">")) {
                sentText1.append(NEWLINE);
                sentText2.append(NEWLINE);
            }
        }
    };
    debugWriter.addWriterListener(writerListener);
    // Assign the reader/writer objects to use the debug versions. The packet reader
    // and writer will use the debug versions when they are created.
    reader = debugReader;
    writer = debugWriter;
    // Create a thread that will listen for all incoming packets and write them to
    // the GUI. This is what we call "interpreted" packet data, since it's the packet
    // data as Smack sees it and not as it's coming in as raw XML.
    listener = new StanzaListener() {

        @Override
        public void processStanza(Stanza packet) {
            interpretedText1.append(packet.toXML().toString());
            interpretedText2.append(packet.toXML().toString());
            interpretedText1.append(NEWLINE);
            interpretedText2.append(NEWLINE);
        }
    };
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) JTabbedPane(javax.swing.JTabbedPane) WindowAdapter(java.awt.event.WindowAdapter) StanzaListener(org.jivesoftware.smack.StanzaListener) StringSelection(java.awt.datatransfer.StringSelection) GridLayout(java.awt.GridLayout) MouseListener(java.awt.event.MouseListener) JFrame(javax.swing.JFrame) ObservableWriter(org.jivesoftware.smack.util.ObservableWriter) JMenuItem(javax.swing.JMenuItem) ReaderListener(org.jivesoftware.smack.util.ReaderListener) JScrollPane(javax.swing.JScrollPane) ObservableReader(org.jivesoftware.smack.util.ObservableReader) Color(java.awt.Color) WriterListener(org.jivesoftware.smack.util.WriterListener) Stanza(org.jivesoftware.smack.packet.Stanza) JPopupMenu(javax.swing.JPopupMenu) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) Clipboard(java.awt.datatransfer.Clipboard)

Example 89 with WindowAdapter

use of java.awt.event.WindowAdapter in project Smack by igniterealtime.

the class ScreenShareSession method initialize.

/**
     * Initialize the screen share channels.
     */
@Override
public void initialize() {
    JingleSession session = getJingleSession();
    if ((session != null) && (session.getInitiator().equals(session.getConnection().getUser()))) {
        // If the initiator of the jingle session is us then we transmit a screen share.
        try {
            InetAddress remote = InetAddress.getByName(getRemote().getIp());
            transmitter = new ImageTransmitter(new DatagramSocket(getLocal().getPort()), remote, getRemote().getPort(), new Rectangle(0, 0, width, height));
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
    } else {
        // Otherwise we receive a screen share.
        JFrame window = new JFrame();
        JPanel jp = new JPanel();
        window.add(jp);
        window.setLocation(0, 0);
        window.setSize(600, 600);
        window.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosed(WindowEvent e) {
                receiver.stop();
            }
        });
        try {
            receiver = new ImageReceiver(InetAddress.getByName("0.0.0.0"), getRemote().getPort(), getLocal().getPort(), width, height);
            LOGGER.fine("Receiving on:" + receiver.getLocalPort());
        } catch (UnknownHostException e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
        jp.add(receiver);
        receiver.setVisible(true);
        window.setAlwaysOnTop(true);
        window.setVisible(true);
    }
}
Also used : JPanel(javax.swing.JPanel) ImageTransmitter(org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.ImageTransmitter) UnknownHostException(java.net.UnknownHostException) Rectangle(java.awt.Rectangle) JingleSession(org.jivesoftware.smackx.jingleold.JingleSession) WindowAdapter(java.awt.event.WindowAdapter) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ImageReceiver(org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.ImageReceiver) DatagramSocket(java.net.DatagramSocket) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) InetAddress(java.net.InetAddress)

Example 90 with WindowAdapter

use of java.awt.event.WindowAdapter in project jodd by oblac.

the class CaddyDialog method initDialog.

private void initDialog(Window parent, String title, boolean isModal) {
    this.owner = parent;
    this.modal = isModal;
    parentWindowListener = new WindowAdapter() {

        @Override
        public void windowActivated(WindowEvent e) {
            if (isVisible()) {
                getFocusBack();
            }
        }
    };
    setTitle(title);
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Aggregations

WindowAdapter (java.awt.event.WindowAdapter)143 WindowEvent (java.awt.event.WindowEvent)140 JPanel (javax.swing.JPanel)40 JButton (javax.swing.JButton)36 JFrame (javax.swing.JFrame)34 BorderLayout (java.awt.BorderLayout)32 Dimension (java.awt.Dimension)30 JLabel (javax.swing.JLabel)26 JScrollPane (javax.swing.JScrollPane)25 ActionEvent (java.awt.event.ActionEvent)22 ActionListener (java.awt.event.ActionListener)20 FlowLayout (java.awt.FlowLayout)18 GridBagConstraints (java.awt.GridBagConstraints)18 GridBagLayout (java.awt.GridBagLayout)18 Insets (java.awt.Insets)14 Frame (java.awt.Frame)13 Container (java.awt.Container)12 JTextArea (javax.swing.JTextArea)12 JDialog (javax.swing.JDialog)11 IOException (java.io.IOException)9