Search in sources :

Example 61 with BorderLayout

use of java.awt.BorderLayout in project Smack by igniterealtime.

the class EnhancedDebugger method addInformationPanel.

private void addInformationPanel() {
    // Create UI elements for connection information.
    JPanel informationPanel = new JPanel();
    informationPanel.setLayout(new BorderLayout());
    // Add the Host information
    JPanel connPanel = new JPanel();
    connPanel.setLayout(new GridBagLayout());
    connPanel.setBorder(BorderFactory.createTitledBorder("XMPPConnection information"));
    JLabel label = new JLabel("Host: ");
    label.setMinimumSize(new java.awt.Dimension(150, 14));
    label.setMaximumSize(new java.awt.Dimension(150, 14));
    connPanel.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    JFormattedTextField field = new JFormattedTextField(connection.getXMPPServiceDomain());
    field.setMinimumSize(new java.awt.Dimension(150, 20));
    field.setMaximumSize(new java.awt.Dimension(150, 20));
    field.setEditable(false);
    field.setBorder(null);
    connPanel.add(field, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
    // Add the Port information
    label = new JLabel("Port: ");
    label.setMinimumSize(new java.awt.Dimension(150, 14));
    label.setMaximumSize(new java.awt.Dimension(150, 14));
    connPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    field = new JFormattedTextField(connection.getPort());
    field.setMinimumSize(new java.awt.Dimension(150, 20));
    field.setMaximumSize(new java.awt.Dimension(150, 20));
    field.setEditable(false);
    field.setBorder(null);
    connPanel.add(field, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
    // Add the connection's User information
    label = new JLabel("User: ");
    label.setMinimumSize(new java.awt.Dimension(150, 14));
    label.setMaximumSize(new java.awt.Dimension(150, 14));
    connPanel.add(label, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    userField = new JFormattedTextField();
    userField.setMinimumSize(new java.awt.Dimension(150, 20));
    userField.setMaximumSize(new java.awt.Dimension(150, 20));
    userField.setEditable(false);
    userField.setBorder(null);
    connPanel.add(userField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
    // Add the connection's creationTime information
    label = new JLabel("Creation time: ");
    label.setMinimumSize(new java.awt.Dimension(150, 14));
    label.setMaximumSize(new java.awt.Dimension(150, 14));
    connPanel.add(label, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd HH:mm:ss:SS"));
    field.setMinimumSize(new java.awt.Dimension(150, 20));
    field.setMaximumSize(new java.awt.Dimension(150, 20));
    field.setValue(creationTime);
    field.setEditable(false);
    field.setBorder(null);
    connPanel.add(field, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
    // Add the connection's creationTime information
    label = new JLabel("Status: ");
    label.setMinimumSize(new java.awt.Dimension(150, 14));
    label.setMaximumSize(new java.awt.Dimension(150, 14));
    connPanel.add(label, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    statusField = new JFormattedTextField();
    statusField.setMinimumSize(new java.awt.Dimension(150, 20));
    statusField.setMaximumSize(new java.awt.Dimension(150, 20));
    statusField.setValue("Active");
    statusField.setEditable(false);
    statusField.setBorder(null);
    connPanel.add(statusField, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
    // Add the connection panel to the information panel
    informationPanel.add(connPanel, BorderLayout.NORTH);
    // Add the Number of sent packets information
    JPanel packetsPanel = new JPanel();
    packetsPanel.setLayout(new GridLayout(1, 1));
    packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets"));
    statisticsTable = new DefaultTableModel(new Object[][] { { "IQ", 0, 0 }, { "Message", 0, 0 }, { "Presence", 0, 0 }, { "Other", 0, 0 }, { "Total", 0, 0 } }, new Object[] { "Type", "Received", "Sent" }) {

        // CHECKSTYLE:OFF
        private static final long serialVersionUID = -6793886085109589269L;

        @Override
        public boolean isCellEditable(int rowIndex, int mColIndex) {
            // CHECKSTYLE:ON
            return false;
        }
    };
    JTable table = new JTable(statisticsTable);
    // Allow only single a selection
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    packetsPanel.add(new JScrollPane(table));
    // Add the packets panel to the information panel
    informationPanel.add(packetsPanel, BorderLayout.CENTER);
    tabbedPane.add("Information", new JScrollPane(informationPanel));
    tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection");
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) DefaultTableModel(javax.swing.table.DefaultTableModel) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) SimpleDateFormat(java.text.SimpleDateFormat)

Example 62 with BorderLayout

use of java.awt.BorderLayout in project apjp by jvansteirteghem.

the class Main method main.

public static void main(final String[] args) {
    EventQueue.invokeLater(new Runnable() {

        public void run() {
            try {
                System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
                Security.addProvider(new IAIK());
                Properties properties = new Properties();
                properties.load(new FileInputStream("APJP_LOCAL.properties"));
                APJP.APJP_KEY = properties.getProperty("APJP_KEY", "");
                APJP.APJP_LOGGER_ID = "APJP";
                APJP.APJP_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_PROXY_SERVER";
                APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_PROXY_SERVER";
                APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_HTTP_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTP_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTP_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_SERVER";
                APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL = new String[10];
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
                APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
                for (int i = 0; i < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
                    APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_URL", "");
                    for (int j = 0; j < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
                        APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
                        APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
                    }
                }
                APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_PROXY_SERVER";
                APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_LOCAL_HTTPS_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_LOCAL_HTTPS_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_LOCAL_HTTPS_SERVER_PORT = 0;
                }
                APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_SERVER";
                APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_LEVEL = 1;
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL = new String[10];
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
                APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
                for (int i = 0; i < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
                    APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_URL", "");
                    for (int j = 0; j < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
                        APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
                        APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
                    }
                }
                APJP.APJP_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTP_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTP_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_HTTP_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_HTTP_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTP_PROXY_SERVER_USERNAME", "");
                APJP.APJP_HTTP_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTP_PROXY_SERVER_PASSWORD", "");
                APJP.APJP_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTPS_PROXY_SERVER_ADDRESS", "");
                try {
                    APJP.APJP_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTPS_PROXY_SERVER_PORT", "0"));
                } catch (Exception e) {
                    APJP.APJP_HTTPS_PROXY_SERVER_PORT = 0;
                }
                APJP.APJP_HTTPS_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTPS_PROXY_SERVER_USERNAME", "");
                APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTPS_PROXY_SERVER_PASSWORD", "");
                Authenticator.setDefault(new Authenticator() {

                    protected PasswordAuthentication getPasswordAuthentication() {
                        PasswordAuthentication passwordAuthentication = null;
                        if (this.getRequestorType() == Authenticator.RequestorType.PROXY) {
                            if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTP") == true) {
                                passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTP_PROXY_SERVER_USERNAME, APJP.APJP_HTTP_PROXY_SERVER_PASSWORD.toCharArray());
                            } else {
                                if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTPS") == true) {
                                    passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTPS_PROXY_SERVER_USERNAME, APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD.toCharArray());
                                }
                            }
                        }
                        return passwordAuthentication;
                    }
                });
                logger = Logger.getLogger(APJP.APJP_LOGGER_ID);
                final ProxyServer proxyServer = new ProxyServer();
                final JTextArea outputTextArea = new JTextArea();
                outputTextArea.setEditable(false);
                outputTextArea.setLineWrap(true);
                outputTextArea.setBackground(new Color(0, 0, 0));
                outputTextArea.setForeground(new Color(255, 255, 255));
                outputTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
                final JScrollPane outputScrollPane = new JScrollPane(outputTextArea);
                final OutputStream outputStream = new OutputStream() {

                    public void write(final int b) throws IOException {
                        outputTextArea.append(new String(new char[] { (char) b }));
                    }

                    public void write(final byte[] b, final int off, final int len) throws IOException {
                        outputTextArea.append(new String(b, off, len));
                    }
                };
                final PrintStream printStream = new PrintStream(outputStream, true);
                System.setOut(printStream);
                final JButton startButton = new JButton();
                startButton.setText("Start");
                startButton.setPreferredSize(new Dimension(100, 30));
                startButton.addActionListener(new ActionListener() {

                    public void actionPerformed(final ActionEvent actionEvent) {
                        outputTextArea.setText("");
                        logger.log(1, "START_PROXY_SERVER");
                        try {
                            proxyServer.start();
                            logger.log(1, "START_PROXY_SERVER: OK");
                        } catch (Exception e) {
                            logger.log(1, "START_PROXY_SERVER: EXCEPTION", e);
                            logger.log(1, "START_PROXY_SERVER: NOT OK");
                        }
                        HTTPRequests httpRequests = HTTPRequests.getHTTPRequests();
                        logger.log(1, "TEST_HTTP_REQUESTS");
                        try {
                            httpRequests.test();
                            logger.log(1, "TEST_HTTP_REQUESTS: OK");
                        } catch (Exception e) {
                            logger.log(1, "TEST_HTTP_REQUESTS: EXCEPTION", e);
                            logger.log(1, "TEST_HTTP_REQUESTS: NOT OK");
                        }
                        HTTPSRequests httpsRequests = HTTPSRequests.getHTTPSRequests();
                        logger.log(1, "TEST_HTTPS_REQUESTS");
                        try {
                            httpsRequests.test();
                            logger.log(1, "TEST_HTTPS_REQUESTS: OK");
                        } catch (Exception e) {
                            logger.log(1, "TEST_HTTPS_REQUESTS: EXCEPTION", e);
                            logger.log(1, "TEST_HTTPS_REQUESTS: NOT OK");
                        }
                    }
                });
                final JButton stopButton = new JButton();
                stopButton.setText("Stop");
                stopButton.setPreferredSize(new Dimension(100, 30));
                stopButton.addActionListener(new ActionListener() {

                    public void actionPerformed(final ActionEvent actionEvent) {
                        outputTextArea.setText("");
                        logger.log(1, "STOP_PROXY_SERVER");
                        try {
                            proxyServer.stop();
                            logger.log(1, "STOP_PROXY_SERVER: OK");
                        } catch (Exception e) {
                            logger.log(1, "STOP_PROXY_SERVER: EXCEPTION", e);
                            logger.log(1, "STOP_PROXY_SERVER: NOT OK");
                        }
                    }
                });
                final Panel buttonPanel = new Panel();
                buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
                buttonPanel.add(startButton);
                buttonPanel.add(stopButton);
                final ImageIcon imageIcon = new ImageIcon("APJP_LOCAL.png");
                final JFrame frame = new JFrame();
                frame.setIconImage(imageIcon.getImage());
                frame.setSize(675, 375);
                frame.setResizable(false);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new BorderLayout());
                frame.add(buttonPanel, BorderLayout.NORTH);
                frame.add(outputScrollPane, BorderLayout.CENTER);
                if (SystemTray.isSupported()) {
                    final TrayIcon trayIcon = new TrayIcon(imageIcon.getImage());
                    trayIcon.setImageAutoSize(true);
                    trayIcon.addActionListener(new ActionListener() {

                        public void actionPerformed(final ActionEvent actionEvent) {
                            frame.setVisible(!frame.isVisible());
                        }
                    });
                    SystemTray.getSystemTray().add(trayIcon);
                }
                frame.setVisible(true);
            } catch (Exception e) {
                logger.log(1, "EXCEPTION", e);
            }
        }
    });
}
Also used : ImageIcon(javax.swing.ImageIcon) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) OutputStream(java.io.OutputStream) JButton(javax.swing.JButton) HTTPRequests(APJP.HTTP11.HTTPRequests) Properties(java.util.Properties) Font(java.awt.Font) HTTPSRequests(APJP.HTTP11.HTTPSRequests) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) TrayIcon(java.awt.TrayIcon) IAIK(iaik.security.provider.IAIK) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication) JScrollPane(javax.swing.JScrollPane) PrintStream(java.io.PrintStream) Color(java.awt.Color) IOException(java.io.IOException) Dimension(java.awt.Dimension) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ProxyServer(APJP.ProxyServer) Panel(java.awt.Panel) ActionListener(java.awt.event.ActionListener)

Example 63 with BorderLayout

use of java.awt.BorderLayout in project jna by java-native-access.

the class AlphaMaskDemo2 method run.

public void run() {
    // Must find a graphics configuration with a depth of 32 bits
    GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
    frame = new JFrame("Alpha Mask Demo");
    alphaWindow = new JWindow(frame, gconfig);
    icon = new JLabel();
    icon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    alphaWindow.getContentPane().add(icon);
    JButton quit = new JButton("Quit");
    JLabel label = new JLabel("Drag this window by its image");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    alphaWindow.getContentPane().add(label, BorderLayout.NORTH);
    alphaWindow.getContentPane().add(quit, BorderLayout.SOUTH);
    quit.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    MouseInputAdapter handler = new MouseInputAdapter() {

        private Point offset;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e))
                offset = e.getPoint();
        }

        public void mouseReleased(MouseEvent e) {
            offset = null;
        }

        public void mouseDragged(MouseEvent e) {
            if (offset != null) {
                Window w = (Window) e.getSource();
                Point where = e.getPoint();
                where.translate(-offset.x, -offset.y);
                Point loc = w.getLocationOnScreen();
                loc.translate(where.x, where.y);
                w.setLocation(loc.x, loc.y);
            }
        }
    };
    alphaWindow.addMouseListener(handler);
    alphaWindow.addMouseMotionListener(handler);
    JPanel p = new JPanel(new BorderLayout(8, 8));
    p.setBorder(new EmptyBorder(8, 8, 8, 8));
    p.setTransferHandler(new TransferHandler() {

        private static final long serialVersionUID = 1L;

        public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
            List<DataFlavor> list = Arrays.asList(transferFlavors);
            if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR) || list.contains(DataFlavor.imageFlavor) || list.contains(DataFlavor.javaFileListFlavor)) {
                return true;
            }
            if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
                return true;
            }
            System.err.println("No acceptable flavor found in " + Arrays.asList(transferFlavors));
            return false;
        }

        public boolean importData(JComponent comp, Transferable t) {
            try {
                if (t.isDataFlavorSupported(URL_FLAVOR)) {
                    URL url = (URL) t.getTransferData(URL_FLAVOR);
                    setImage(Toolkit.getDefaultToolkit().getImage(url));
                    return true;
                }
                if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
                    String s = (String) t.getTransferData(URI_LIST_FLAVOR);
                    String[] uris = s.split("[\r\n]");
                    if (uris.length > 0) {
                        URL url = new URL(uris[0]);
                        setImage(Toolkit.getDefaultToolkit().getImage(url));
                        return true;
                    }
                    return false;
                }
                if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                    Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
                    setImage(image);
                    return true;
                }
                if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                    List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
                    File f = files.get(0);
                    URL url = new URL("file://" + f.toURI().toURL().getPath());
                    Image image = Toolkit.getDefaultToolkit().getImage(url);
                    setImage(image);
                    return true;
                }
                DataFlavor flavor = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
                if (flavor != null) {
                    Reader reader = flavor.getReaderForText(t);
                    char[] buf = new char[512];
                    StringBuilder b = new StringBuilder();
                    int count;
                    // encoding wrong
                    while ((count = reader.read(buf)) > 0) {
                        for (int i = 0; i < count; i++) {
                            if (buf[i] != 0)
                                b.append(buf, i, 1);
                        }
                    }
                    String html = b.toString();
                    Pattern p = Pattern.compile("<img.*src=\"([^\\\"\">]+)\"", Pattern.CANON_EQ | Pattern.UNICODE_CASE);
                    Matcher m = p.matcher(html);
                    if (m.find()) {
                        URL url = new URL(m.group(1));
                        System.out.println("Load image from " + url);
                        Image image = Toolkit.getDefaultToolkit().getImage(url);
                        setImage(image);
                        return true;
                    }
                    System.err.println("Can't parse text: " + html);
                    return false;
                }
                System.err.println("No flavor available: " + Arrays.asList(t.getTransferDataFlavors()));
            } catch (UnsupportedFlavorException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Throwable e) {
                e.printStackTrace();
            }
            return false;
        }
    });
    p.add(new JLabel("<html><center>Drop an image with an alpha channel onto this window<br>" + "You may also adjust the overall transparency with the slider</center></html>"), BorderLayout.NORTH);
    p.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    final JSlider slider = new JSlider(0, 255, 255);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            int value = slider.getValue();
            WindowUtils.setWindowAlpha(alphaWindow, value / 255f);
        }
    });
    p.add(slider, BorderLayout.SOUTH);
    frame.getContentPane().add(p);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    centerOnScreen(frame);
    frame.setVisible(true);
    WindowUtils.setWindowTransparent(alphaWindow, true);
    alphaWindow.setLocation(frame.getX() + frame.getWidth() + 4, frame.getY());
    try {
        URL url = getClass().getResource("tardis.png");
        if (url != null) {
            setImage(Toolkit.getDefaultToolkit().getImage(url));
        }
    } catch (Exception e) {
    }
}
Also used : JPanel(javax.swing.JPanel) Matcher(java.util.regex.Matcher) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Reader(java.io.Reader) Image(java.awt.Image) URL(java.net.URL) GraphicsConfiguration(java.awt.GraphicsConfiguration) DataFlavor(java.awt.datatransfer.DataFlavor) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JSlider(javax.swing.JSlider) List(java.util.List) ChangeListener(javax.swing.event.ChangeListener) EmptyBorder(javax.swing.border.EmptyBorder) Window(java.awt.Window) JWindow(javax.swing.JWindow) Pattern(java.util.regex.Pattern) MouseEvent(java.awt.event.MouseEvent) JWindow(javax.swing.JWindow) JComponent(javax.swing.JComponent) Transferable(java.awt.datatransfer.Transferable) JLabel(javax.swing.JLabel) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) TransferHandler(javax.swing.TransferHandler) File(java.io.File) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Example 64 with BorderLayout

use of java.awt.BorderLayout in project jna by java-native-access.

the class FilteredTextField method main.

/*
   * A main entry point to test the FilteredTextField.
   * @param args application arguments
   */
public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    JFrame jframe = new JFrame("Balloon Tips on FilteredTextField");
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jframe.setSize(400, 75);
    jframe.setLocation(400, 400);
    JPanel jpanel = new JPanel();
    jpanel.setLayout(new BorderLayout());
    FilteredTextField ftfield = new FilteredTextField(10);
    ftfield.setCharacters(LOWERCASE_CHARS);
    ftfield.addCharacter('-');
    ftfield.addCharacter('_');
    ftfield.addCharacter(' ');
    ftfield.setMaximumLength(10);
    ftfield.setEntryError("Only lower case letters, hyphens, underscores, and spaces allowed.");
    ftfield.setValidRegex("^a+[a-z-_ ]*");
    ftfield.setValidError("The string must begin with the letter 'a'.");
    jpanel.add(new JLabel("Type some text into either field"), BorderLayout.NORTH);
    jpanel.add(ftfield, BorderLayout.CENTER);
    jpanel.add(new FilteredTextField(10), BorderLayout.SOUTH);
    jframe.getContentPane().add(jpanel);
    jframe.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JLabel(javax.swing.JLabel) BadLocationException(javax.swing.text.BadLocationException)

Example 65 with BorderLayout

use of java.awt.BorderLayout in project GT by Tencent.

the class CPUView method createChartPanel.

/**
	 * 初始化jfreechart
	 * @param rootFrame
	 */
private void createChartPanel(Composite parent) {
    // 放置图表的容器对象
    chartComposite = new Composite(parent, SWT.NO_BACKGROUND | SWT.EMBEDDED);
    FormData formData = new FormData();
    formData.left = new FormAttachment(0, Constant.VIEW_MARGIN_WIDTH);
    formData.right = new FormAttachment(cpuViewer.getTable(), -Constant.VIEW_MARGIN_WIDTH);
    formData.top = new FormAttachment(0, Constant.VIEW_MARGIN_WIDTH);
    formData.bottom = new FormAttachment(100, -Constant.VIEW_MARGIN_WIDTH);
    chartComposite.setLayoutData(formData);
    // AWT的根容器
    Frame frame = SWT_AWT.new_Frame(chartComposite);
    // 据说加入这个Panel可以无闪烁
    Panel panel = new Panel(new BorderLayout()) {

        private static final long serialVersionUID = 1L;

        public void update(java.awt.Graphics g) {
            /* Do not erase the background */
            paint(g);
        }
    };
    frame.add(panel);
    JRootPane root = new JRootPane();
    panel.add(root);
    java.awt.Container contentPane = root.getContentPane();
    cpuRealTimeChart = new CPURealTimeChart();
    contentPane.add(cpuRealTimeChart);
}
Also used : FormData(org.eclipse.swt.layout.FormData) Panel(java.awt.Panel) Frame(java.awt.Frame) Composite(org.eclipse.swt.widgets.Composite) BorderLayout(java.awt.BorderLayout) JRootPane(javax.swing.JRootPane) FormAttachment(org.eclipse.swt.layout.FormAttachment) CPURealTimeChart(com.tencent.wstt.apt.chart.CPURealTimeChart)

Aggregations

BorderLayout (java.awt.BorderLayout)966 JPanel (javax.swing.JPanel)668 JLabel (javax.swing.JLabel)311 JScrollPane (javax.swing.JScrollPane)258 Dimension (java.awt.Dimension)206 JButton (javax.swing.JButton)170 FlowLayout (java.awt.FlowLayout)115 JTextField (javax.swing.JTextField)115 ActionEvent (java.awt.event.ActionEvent)107 Insets (java.awt.Insets)104 GridBagLayout (java.awt.GridBagLayout)98 GridBagConstraints (java.awt.GridBagConstraints)97 ActionListener (java.awt.event.ActionListener)88 EmptyBorder (javax.swing.border.EmptyBorder)87 JCheckBox (javax.swing.JCheckBox)83 JTable (javax.swing.JTable)76 BoxLayout (javax.swing.BoxLayout)72 JSplitPane (javax.swing.JSplitPane)69 GridLayout (java.awt.GridLayout)66 JTextArea (javax.swing.JTextArea)62