Example usage for java.awt.event MouseListener MouseListener

List of usage examples for java.awt.event MouseListener MouseListener

Introduction

In this page you can find the example usage for java.awt.event MouseListener MouseListener.

Prototype

MouseListener

Source Link

Usage

From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzerContentPanel.java

public JXTreeTable getFuzzResultTable() {
    if (fuzzResultTable == null) {
        resetFuzzResultTable();/*  www  .  j  av  a2 s. c  om*/
        fuzzResultTable = new JXTreeTable(getResultsModel());
        fuzzResultTable.setName("HttpFuzzResultTable");
        fuzzResultTable.setDoubleBuffered(true);
        fuzzResultTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        fuzzResultTable.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12));
        fuzzResultTable.setDefaultRenderer(Pair.class, new IconTableCellRenderer());

        int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 };
        for (int i = 0, count = widths.length; i < count; i++) {
            TableColumn column = fuzzResultTable.getColumnModel().getColumn(i);
            column.setPreferredWidth(widths[i]);
        }
        fuzzResultTable.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) {
                if (e.isPopupTrigger() && SwingUtilities.isRightMouseButton(e)) {
                    // Select list item on right click
                    JTable table = (JTable) e.getSource();
                    int row = table.rowAtPoint(e.getPoint());

                    if (!table.isRowSelected(row)) {
                        table.changeSelection(row, 0, false, false);
                    }
                    View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
                }
            }

        });

        fuzzResultTable.getSelectionModel()
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {

                    @Override
                    public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                        if (!e.getValueIsAdjusting()) {
                            if (fuzzResultTable.getSelectedRowCount() == 0) {
                                return;
                            }
                            final int row = fuzzResultTable.getSelectedRow();
                            if (getEntry(row) instanceof HttpFuzzRequestRecord) {
                                final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(
                                        row)).getHistory();
                                try {
                                    displayMessage(historyReference.getHttpMessage());
                                } catch (HttpMalformedHeaderException | SQLException ex) {
                                    logger.error(ex.getMessage(), ex);
                                }
                            }
                        }
                    }
                });
        fuzzResultTable.getTableHeader().addMouseListener(new MouseListener() {
            int sortedOn = -1;

            @Override
            public void mouseReleased(MouseEvent arg0) {
            }

            @Override
            public void mousePressed(MouseEvent arg0) {
            }

            @Override
            public void mouseExited(MouseEvent arg0) {
            }

            @Override
            public void mouseEntered(MouseEvent arg0) {
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                int index = fuzzResultTable.columnAtPoint(e.getPoint());
                List<HttpFuzzRecord> list = getResultsModel().getEntries();
                if (list.size() == 0) {
                    return;
                }
                HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator();
                comp.setFeature(index);
                if (index == sortedOn) {
                    Collections.sort(list, comp);
                    Collections.reverse(list);
                    sortedOn = -1;
                } else {
                    Collections.sort(list, comp);
                    sortedOn = index;
                }
                fuzzResultTable.updateUI();
            }
        });
        fuzzResultTable.setRootVisible(false);
        fuzzResultTable.setVisible(true);
    }
    return fuzzResultTable;
}

From source file:com.dragoniade.deviantart.ui.PreferencesDialog.java

public PreferencesDialog(final DownloaderGUI owner, Properties config) {
    super(owner, "Preferences", true);

    HttpClientParams params = new HttpClientParams();
    params.setVersion(HttpVersion.HTTP_1_1);
    params.setSoTimeout(30000);/*from  ww w .  j av a2  s .c  o m*/
    client = new HttpClient(params);
    setProxy(ProxyCfg.parseConfig(config));

    sample = new Deviation();
    sample.setId(15972367L);
    sample.setTitle("Fella Promo");
    sample.setArtist("devart");
    sample.setImageDownloadUrl(DOWNLOAD_URL);
    sample.setImageFilename(Deviation.extractFilename(DOWNLOAD_URL));
    sample.setCollection(new Collection(1L, "MyCollect"));
    setLayout(new BorderLayout());
    panes = new JTabbedPane(JTabbedPane.TOP);

    JPanel genPanel = new JPanel();
    BoxLayout genLayout = new BoxLayout(genPanel, BoxLayout.Y_AXIS);
    genPanel.setLayout(genLayout);
    panes.add("General", genPanel);

    JLabel userLabel = new JLabel("Username");

    userLabel.setToolTipText("The username the account you want to download the favorites from.");

    userField = new JTextField(config.getProperty(Constants.USERNAME));

    userLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    userField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userField.setMaximumSize(new Dimension(Integer.MAX_VALUE, userField.getFont().getSize() * 2));

    genPanel.add(userLabel);
    genPanel.add(userField);

    JPanel radioPanel = new JPanel();
    BoxLayout radioLayout = new BoxLayout(radioPanel, BoxLayout.X_AXIS);
    radioPanel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    radioPanel.setBorder(new EmptyBorder(0, 5, 0, 5));

    radioPanel.setLayout(radioLayout);

    JLabel searchLabel = new JLabel("Search for");
    searchLabel
            .setToolTipText("Select what you want to download from that user: it favorites or it galleries.");
    searchLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searchLabel.setBorder(new EmptyBorder(0, 5, 0, 5));

    selectedSearch = SEARCH.lookup(config.getProperty(Constants.SEARCH, SEARCH.getDefault().getId()));
    buttonGroup = new ButtonGroup();

    for (final SEARCH search : SEARCH.values()) {
        JRadioButton radio = new JRadioButton(search.getLabel());
        radio.setAlignmentX(JLabel.LEFT_ALIGNMENT);
        radio.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                selectedSearch = search;
            }
        });

        buttonGroup.add(radio);
        radioPanel.add(radio);
        if (search.equals(selectedSearch)) {
            radio.setSelected(true);
        }
    }

    genPanel.add(radioPanel);

    final JTextField sampleField = new JTextField("");
    sampleField.setEditable(false);

    JLabel locationLabel = new JLabel("Download location");
    locationLabel.setToolTipText("The folder pattern where you want the file to be downloaded in.");

    JLabel legendsLabel = new JLabel(
            "<html><body>Field names: %user%, %artist%, %title%, %id%, %filename%, %collection%, %ext%<br></br>Example:</body></html>");
    legendsLabel.setToolTipText("An example of where a file will be downloaded to.");

    locationString = new StringBuilder();
    locationField = new JTextField(config.getProperty(Constants.LOCATION));
    locationField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationString.setLength(0);
            locationString.append(dest.getAbsolutePath());
            sampleField.setText(locationString.toString());
            if (useSameForMatureBox.isSelected()) {
                locationMatureString.setLength(0);
                locationMatureString.append(sampleField.getText());
                locationMatureField.setText(locationField.getText());
            }
        }

        public void keyTyped(KeyEvent e) {
        }

    });
    locationField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });
    JLabel locationMatureLabel = new JLabel("Mature download location");
    locationMatureLabel.setToolTipText(
            "The folder pattern where you want the file marked as 'Mature' to be downloaded in.");

    locationMatureString = new StringBuilder();
    locationMatureField = new JTextField(config.getProperty(Constants.MATURE));
    locationMatureField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationMatureString.setLength(0);
            locationMatureString.append(dest.getAbsolutePath());
            sampleField.setText(locationMatureString.toString());
        }

        public void keyTyped(KeyEvent e) {
        }

    });

    locationMatureField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationMatureString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });

    useSameForMatureBox = new JCheckBox("Use same location for mature deviation?");
    useSameForMatureBox.setSelected(locationLabel.getText().equals(locationMatureField.getText()));
    useSameForMatureBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (useSameForMatureBox.isSelected()) {
                locationMatureField.setEditable(false);
                locationMatureField.setText(locationField.getText());
                locationMatureString.setLength(0);
                locationMatureString.append(locationString);
            } else {
                locationMatureField.setEditable(true);
            }

        }
    });

    File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    sampleField.setText(dest.getAbsolutePath());
    locationString.append(sampleField.getText());

    dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    locationMatureString.append(dest.getAbsolutePath());

    locationLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationField.setMaximumSize(new Dimension(Integer.MAX_VALUE, locationField.getFont().getSize() * 2));
    locationMatureLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationMatureField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureField
            .setMaximumSize(new Dimension(Integer.MAX_VALUE, locationMatureField.getFont().getSize() * 2));
    useSameForMatureBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    legendsLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, legendsLabel.getFont().getSize() * 2));
    sampleField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    sampleField.setMaximumSize(new Dimension(Integer.MAX_VALUE, sampleField.getFont().getSize() * 2));

    genPanel.add(locationLabel);
    genPanel.add(locationField);

    genPanel.add(locationMatureLabel);
    genPanel.add(locationMatureField);
    genPanel.add(useSameForMatureBox);

    genPanel.add(legendsLabel);
    genPanel.add(sampleField);
    genPanel.add(Box.createVerticalBox());

    final KeyListener prxChangeListener = new KeyListener() {

        public void keyTyped(KeyEvent e) {
            proxyChangeState = true;
        }

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
        }
    };

    JPanel prxPanel = new JPanel();
    BoxLayout prxLayout = new BoxLayout(prxPanel, BoxLayout.Y_AXIS);
    prxPanel.setLayout(prxLayout);
    panes.add("Proxy", prxPanel);

    JLabel prxHostLabel = new JLabel("Proxy Host");
    prxHostLabel.setToolTipText("The hostname of the proxy server");
    prxHostField = new JTextField(config.getProperty(Constants.PROXY_HOST));
    prxHostLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxHostField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxHostField.getFont().getSize() * 2));

    JLabel prxPortLabel = new JLabel("Proxy Port");
    prxPortLabel.setToolTipText("The port of the proxy server (Default 80).");

    prxPortSpinner = new JSpinner();
    prxPortSpinner.setModel(new SpinnerNumberModel(
            Integer.parseInt(config.getProperty(Constants.PROXY_PORT, "80")), 1, 65535, 1));

    prxPortLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPortSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPortSpinner.getFont().getSize() * 2));

    JLabel prxUserLabel = new JLabel("Proxy username");
    prxUserLabel.setToolTipText("The username used for authentication, if applicable.");
    prxUserField = new JTextField(config.getProperty(Constants.PROXY_USERNAME));
    prxUserLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxUserField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxUserField.getFont().getSize() * 2));

    JLabel prxPassLabel = new JLabel("Proxy username");
    prxPassLabel.setToolTipText("The username used for authentication, if applicable.");
    prxPassField = new JPasswordField(config.getProperty(Constants.PROXY_PASSWORD));
    prxPassLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPassField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPassField.getFont().getSize() * 2));

    prxUseBox = new JCheckBox("Use a proxy?");
    prxUseBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            prxChangeListener.keyTyped(null);

            if (prxUseBox.isSelected()) {
                prxHostField.setEditable(true);
                prxPortSpinner.setEnabled(true);
                prxUserField.setEditable(true);
                prxPassField.setEditable(true);

            } else {
                prxHostField.setEditable(false);
                prxPortSpinner.setEnabled(false);
                prxUserField.setEditable(false);
                prxPassField.setEditable(false);
            }
        }
    });

    prxUseBox.setSelected(!Boolean.parseBoolean(config.getProperty(Constants.PROXY_USE)));
    prxUseBox.doClick();
    proxyChangeState = false;

    prxHostField.addKeyListener(prxChangeListener);
    prxUserField.addKeyListener(prxChangeListener);
    prxPassField.addKeyListener(prxChangeListener);
    prxPortSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            proxyChangeState = true;
        }
    });
    prxPanel.add(prxUseBox);

    prxPanel.add(prxHostLabel);
    prxPanel.add(prxHostField);

    prxPanel.add(prxPortLabel);
    prxPanel.add(prxPortSpinner);

    prxPanel.add(prxUserLabel);
    prxPanel.add(prxUserField);

    prxPanel.add(prxPassLabel);
    prxPanel.add(prxPassField);
    prxPanel.add(Box.createVerticalBox());

    final JPanel advPanel = new JPanel();
    BoxLayout advLayout = new BoxLayout(advPanel, BoxLayout.Y_AXIS);
    advPanel.setLayout(advLayout);
    panes.add("Advanced", advPanel);
    panes.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JTabbedPane pane = (JTabbedPane) e.getSource();

            if (proxyChangeState && pane.getSelectedComponent() == advPanel) {
                Properties properties = new Properties();
                properties.setProperty(Constants.PROXY_USERNAME, prxUserField.getText().trim());
                properties.setProperty(Constants.PROXY_PASSWORD, new String(prxPassField.getPassword()).trim());
                properties.setProperty(Constants.PROXY_HOST, prxHostField.getText().trim());
                properties.setProperty(Constants.PROXY_PORT, prxPortSpinner.getValue().toString());
                properties.setProperty(Constants.PROXY_USE, Boolean.toString(prxUseBox.isSelected()));
                ProxyCfg prx = ProxyCfg.parseConfig(properties);
                setProxy(prx);
                revalidateSearcher(null);
            }
        }
    });
    JLabel domainLabel = new JLabel("Deviant Art domain name");
    domainLabel.setToolTipText("The deviantART main domain, should it ever change.");

    domainField = new JTextField(config.getProperty(Constants.DOMAIN));
    domainLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    domainField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainField.setMaximumSize(new Dimension(Integer.MAX_VALUE, domainField.getFont().getSize() * 2));

    advPanel.add(domainLabel);
    advPanel.add(domainField);

    JLabel throttleLabel = new JLabel("Throttle search delay");
    throttleLabel.setToolTipText(
            "Slow down search query by inserting a pause between them. This help prevent abuse when doing a massive download.");

    throttleSpinner = new JSpinner();
    throttleSpinner.setModel(
            new SpinnerNumberModel(Integer.parseInt(config.getProperty(Constants.THROTTLE, "0")), 5, 60, 1));

    throttleLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    throttleSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, throttleSpinner.getFont().getSize() * 2));

    advPanel.add(throttleLabel);
    advPanel.add(throttleSpinner);

    JLabel searcherLabel = new JLabel("Searcher");
    searcherLabel.setToolTipText("Select a searcher that will look for your favorites.");

    searcherBox = new JComboBox();
    searcherBox.setRenderer(new TogglingRenderer());

    final AtomicInteger index = new AtomicInteger(0);
    searcherBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            Object selectedItem = combo.getSelectedItem();
            if (selectedItem instanceof SearchItem) {
                SearchItem item = (SearchItem) selectedItem;
                if (item.isValid) {
                    index.set(combo.getSelectedIndex());
                } else {
                    combo.setSelectedIndex(index.get());
                }
            }
        }
    });

    try {
        for (Class<Search> clazz : SearcherClassCache.getInstance().getClasses()) {

            Search searcher = clazz.newInstance();
            String name = searcher.getName();

            SearchItem item = new SearchItem(name, clazz.getName(), true);
            searcherBox.addItem(item);
        }
        String selectedClazz = config.getProperty(Constants.SEARCHER,
                com.dragoniade.deviantart.deviation.SearchRss.class.getName());
        revalidateSearcher(selectedClazz);
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }

    searcherLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    searcherBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, searcherBox.getFont().getSize() * 2));

    advPanel.add(searcherLabel);
    advPanel.add(searcherBox);

    advPanel.add(Box.createVerticalBox());

    add(panes, BorderLayout.CENTER);

    JButton saveBut = new JButton("Save");

    userField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            if (field.getText().trim().length() == 0) {
                JOptionPane.showMessageDialog(input, "The user musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The location must contains at least a %filename% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationMatureField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The Mature location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The Mature location must contains at least a %username% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    domainField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String domain = field.getText().trim();
            if (domain.length() == 0) {
                JOptionPane.showMessageDialog(input, "You must specify the deviantART main domain.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (domain.toLowerCase().startsWith("http://")) {
                JOptionPane.showMessageDialog(input,
                        "You must specify the deviantART main domain, not the full URL (aka www.deviantart.com).",
                        "Warning", JOptionPane.WARNING_MESSAGE);
                return false;
            }

            return true;
        }
    });
    locationField.setVerifyInputWhenFocusTarget(true);

    final JDialog parent = this;
    saveBut.addActionListener(new ActionListener() {

        String errorMsg = "The location is invalid or cannot be written to.";

        public void actionPerformed(ActionEvent e) {

            String username = userField.getText().trim();
            String location = locationField.getText().trim();
            String locationMature = locationMatureField.getText().trim();
            String domain = domainField.getText().trim();
            String throttle = throttleSpinner.getValue().toString();
            String searcher = searcherBox.getSelectedItem().toString();

            String prxUse = Boolean.toString(prxUseBox.isSelected());
            String prxHost = prxHostField.getText().trim();
            String prxPort = prxPortSpinner.getValue().toString();
            String prxUsername = prxUserField.getText().trim();
            String prxPassword = new String(prxPassField.getPassword()).trim();

            if (!testPath(location, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }
            if (!testPath(locationMature, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }

            Properties p = new Properties();
            p.setProperty(Constants.USERNAME, username);
            p.setProperty(Constants.LOCATION, location);
            p.setProperty(Constants.MATURE, locationMature);
            p.setProperty(Constants.DOMAIN, domain);
            p.setProperty(Constants.THROTTLE, throttle);
            p.setProperty(Constants.SEARCHER, searcher);
            p.setProperty(Constants.SEARCH, selectedSearch.getId());

            p.setProperty(Constants.PROXY_USE, prxUse);
            p.setProperty(Constants.PROXY_HOST, prxHost);
            p.setProperty(Constants.PROXY_PORT, prxPort);
            p.setProperty(Constants.PROXY_USERNAME, prxUsername);
            p.setProperty(Constants.PROXY_PASSWORD, prxPassword);

            owner.savePreferences(p);
            parent.dispose();
        }
    });

    JButton cancelBut = new JButton("Cancel");
    cancelBut.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            parent.dispose();
        }
    });

    JPanel buttonPanel = new JPanel();
    BoxLayout butLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS);
    buttonPanel.setLayout(butLayout);

    buttonPanel.add(saveBut);
    buttonPanel.add(cancelBut);
    add(buttonPanel, BorderLayout.SOUTH);

    pack();
    setResizable(false);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);
    setVisible(true);
}

From source file:org.gridchem.client.gui.panels.myccg.resource.HPCChartPanel.java

/**
 * Populate the display area with a multiple rows of graphs representing
 * the loads on each ComputeBean object within the HashSet.
 * @param resource//from   w  w w . java 2  s  .  c  o m
 * @param chartType
 */
private JPanel createChartPanel() {

    JPanel chartPanel = new JPanel();

    if (CURRENT_CHARTTYPE.equals(ChartType.METER) || CURRENT_CHARTTYPE.equals(ChartType.PIE)) {

        chartPanel.setLayout(new GridLayout(resources.size(), 1));

        LoadType[] loadTypes;

        if (CURRENT_LOADTYPE.equals(LoadType.SUMMARY)) {
            loadTypes = LoadType.values();
        } else {
            loadTypes = new LoadType[1];
            loadTypes[0] = CURRENT_LOADTYPE;
        }

        for (ComputeBean resource : resources) {
            // create a row to insert in the chartPanel
            JPanel multiChartPanelRow = new JPanel();
            multiChartPanelRow.setLayout(new GridBagLayout());
            GridBagConstraints c = new GridBagConstraints();

            // first part is name of the row
            c.weightx = 0;
            c.weighty = 0;
            c.gridx = 0;
            c.gridy = 0;
            c.fill = GridBagConstraints.NONE;
            multiChartPanelRow.add(new JLabel(resource.getName()));

            // chart row will take up the remainder of this panel.
            c.weightx = 1.0;
            c.weighty = 1.0;
            c.gridx = 0;
            c.gridy = 1;
            c.fill = GridBagConstraints.BOTH;

            JPanel chartRow = new JPanel();
            chartRow.setLayout(new GridLayout(1, (LoadType.values().length - 1)));

            for (int i = 0; i < ((loadTypes.length == 1) ? 1 : loadTypes.length - 1); i++) {
                JFreeChart chart = createChart(resource, CURRENT_CHARTTYPE, loadTypes[i]);

                ChartPanel cp = new ChartPanel(chart);

                cp.setPreferredSize(new Dimension(40, 45));

                cp.addMouseListener(new MouseListener() {
                    public void mouseClicked(MouseEvent event) {
                        // if they double click on the graph, then zoom in on it and
                        // make it the single display in the screen.
                        if (event.getClickCount() == 2) {
                            if (zoomOnSingleChart) {
                                zoomOnSingleChart = false;
                                setChartDisplayType(CURRENT_CHARTTYPE);
                            } else {
                                zoomOnSingleChart = true;
                                removeAll();
                                GridBagConstraints c = new GridBagConstraints();
                                c.weightx = 1.0;
                                c.weighty = 1.0;
                                c.gridx = 0;
                                c.gridy = 0;
                                c.fill = GridBagConstraints.BOTH;
                                add((ChartPanel) event.getSource(), c);
                                c.weightx = 0;
                                c.weighty = 0;
                                c.gridx = 0;
                                c.gridy = 1;
                                add(createSelectionBar(), c);
                                revalidate();
                            }
                        }

                    }

                    public void mousePressed(MouseEvent arg0) {
                    }

                    public void mouseReleased(MouseEvent arg0) {
                    }

                    public void mouseEntered(MouseEvent arg0) {
                    }

                    public void mouseExited(MouseEvent arg0) {
                    }
                });

                chartRow.add(cp);
            }
            multiChartPanelRow.add(chartRow, c);
            chartPanel.add(multiChartPanelRow);

        }
    } else {
        chartPanel.setLayout(new GridLayout(1, 1));
        JFreeChart chart = createChart(resources, CURRENT_CHARTTYPE, CURRENT_LOADTYPE);
        ChartPanel cp = new ChartPanel(chart);
        cp.setPreferredSize(new Dimension(40, 45));
        chartPanel.add(cp);
    }

    return chartPanel;

}

From source file:org.tinymediamanager.ui.tvshows.dialogs.TvShowEpisodeChooserDialog.java

public TvShowEpisodeChooserDialog(TvShowEpisode ep, MediaScraper mediaScraper) {
    super(BUNDLE.getString("tvshowepisode.choose"), "episodeChooser"); //$NON-NLS-1$
    setBounds(5, 5, 600, 400);//ww  w  . ja va 2 s .  c o  m

    this.episode = ep;
    this.mediaScraper = mediaScraper;
    this.metadata = new MediaEpisode(mediaScraper.getId());
    episodeEventList = new ObservableElementList<>(
            GlazedLists.threadSafeList(new BasicEventList<TvShowEpisodeChooserModel>()),
            GlazedLists.beanConnector(TvShowEpisodeChooserModel.class));
    sortedEpisodes = new SortedList<>(GlazedListsSwing.swingThreadProxyList(episodeEventList),
            new EpisodeComparator());

    getContentPane().setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("590px:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("200dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("fill:37px"),
                    FormSpecs.RELATED_GAP_ROWSPEC, }));
    {
        JSplitPane splitPane = new JSplitPane();
        getContentPane().add(splitPane, "2, 2, fill, fill");

        JPanel panelLeft = new JPanel();
        panelLeft.setLayout(new FormLayout(
                new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("150dlu:grow"),
                        FormSpecs.RELATED_GAP_COLSPEC, },
                new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                        FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                        FormSpecs.RELATED_GAP_ROWSPEC, }));

        textField = EnhancedTextField.createSearchTextField();
        panelLeft.add(textField, "2, 2, fill, default");
        textField.setColumns(10);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setMinimumSize(new Dimension(200, 23));
        panelLeft.add(scrollPane, "2, 4, fill, fill");
        splitPane.setLeftComponent(panelLeft);

        MatcherEditor<TvShowEpisodeChooserModel> textMatcherEditor = new TextComponentMatcherEditor<>(textField,
                new TvShowEpisodeChooserModelFilterator());
        FilterList<TvShowEpisodeChooserModel> textFilteredEpisodes = new FilterList<>(sortedEpisodes,
                textMatcherEditor);
        AdvancedTableModel<TvShowEpisodeChooserModel> episodeTableModel = GlazedListsSwing
                .eventTableModelWithThreadProxyList(textFilteredEpisodes, new EpisodeTableFormat());
        DefaultEventSelectionModel<TvShowEpisodeChooserModel> selectionModel = new DefaultEventSelectionModel<>(
                textFilteredEpisodes);
        selectedEpisodes = selectionModel.getSelected();

        selectionModel.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                    return;
                }
                // display first selected episode
                if (!selectedEpisodes.isEmpty()) {
                    TvShowEpisodeChooserModel episode = selectedEpisodes.get(0);
                    taPlot.setText(episode.getOverview());
                } else {
                    taPlot.setText("");
                }
                taPlot.setCaretPosition(0);
            }
        });

        table = new JTable(episodeTableModel);
        table.setSelectionModel(selectionModel);
        scrollPane.setViewportView(table);

        JPanel panelRight = new JPanel();
        panelRight.setLayout(new FormLayout(
                new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("150dlu:grow"),
                        FormSpecs.RELATED_GAP_COLSPEC, },
                new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                        FormSpecs.RELATED_GAP_ROWSPEC, }));
        JScrollPane scrollPane_1 = new JScrollPane();
        panelRight.add(scrollPane_1, "2, 2, fill, fill");
        splitPane.setRightComponent(panelRight);

        taPlot = new JTextArea();
        taPlot.setEditable(false);
        taPlot.setWrapStyleWord(true);
        taPlot.setLineWrap(true);
        scrollPane_1.setViewportView(taPlot);
        splitPane.setDividerLocation(300);

    }
    JPanel bottomPanel = new JPanel();
    getContentPane().add(bottomPanel, "2, 4, fill, top");

    bottomPanel.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("25px"),
                    FormFactory.RELATED_GAP_ROWSPEC, }));

    JPanel buttonPane = new JPanel();
    bottomPanel.add(buttonPane, "5, 2, fill, fill");
    EqualsLayout layout = new EqualsLayout(5);
    layout.setMinWidth(100);
    buttonPane.setLayout(layout);
    final JButton okButton = new JButton(BUNDLE.getString("Button.ok")); //$NON-NLS-1$
    okButton.setToolTipText(BUNDLE.getString("tvshow.change"));
    okButton.setIcon(IconManager.APPLY);
    buttonPane.add(okButton);
    okButton.setActionCommand("OK");
    okButton.addActionListener(this);

    JButton cancelButton = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
    cancelButton.setToolTipText(BUNDLE.getString("edit.discard"));
    cancelButton.setIcon(IconManager.CANCEL);
    buttonPane.add(cancelButton);
    cancelButton.setActionCommand("Cancel");
    cancelButton.addActionListener(this);

    // column widths
    table.getColumnModel().getColumn(0).setMaxWidth(50);
    table.getColumnModel().getColumn(1).setMaxWidth(50);

    SearchTask task = new SearchTask();
    task.execute();

    MouseListener mouseListener = new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2 && !e.isConsumed() && e.getButton() == MouseEvent.BUTTON1) {
                actionPerformed(new ActionEvent(okButton, ActionEvent.ACTION_PERFORMED, "OK"));
            }
        }

    };
    table.addMouseListener(mouseListener);
}

From source file:wef.articulab.view.ui.CombinedBNXYPlot.java

/**
 * Creates a panel for the demo (used by SuperDemo.java).
 *
 * @return A panel./*  www  .  j av  a  2 s .co  m*/
 */
public JPanel createChartPanel(ChartContainer chartContainer) {
    chartContainer.chart = createChart(chartContainer);
    ChartPanel panel = new ChartPanel(chartContainer.chart);
    panel.setPreferredSize(new Dimension(970, 370));
    panel.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (DMmain.pause) {
                DMmain.pause = false;
            } else {
                DMmain.pause = true;
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    return panel;
}

From source file:org.zaproxy.zap.extension.ascan.PolicyManagerDialog.java

private JTable getParamsTable() {
    if (paramsTable == null) {
        paramsTable = new JTable();
        paramsTable.setModel(getParamsModel());
        paramsTable.addMouseListener(new MouseListener() {
            @Override//from   www . j  a v  a  2  s .  c  om
            public void mouseClicked(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
                if (e.getClickCount() >= 2) {
                    int row = paramsTable.rowAtPoint(e.getPoint());
                    if (row >= 0) {
                        String name = (String) getParamsModel().getValueAt(row, 0);
                        if (name != null) {
                            try {
                                extension.showPolicyDialog(PolicyManagerDialog.this, name);
                            } catch (ConfigurationException e1) {
                                logger.error(e1.getMessage(), e1);
                            }
                        }
                    }
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }
        });
        paramsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (getParamsTable().getSelectedRowCount() == 0) {
                    getModifyButton().setEnabled(false);
                    getRemoveButton().setEnabled(false);
                    getExportButton().setEnabled(false);
                } else if (getParamsTable().getSelectedRowCount() == 1) {
                    getModifyButton().setEnabled(true);
                    // Dont let the last policy be removed
                    getRemoveButton().setEnabled(getParamsModel().getRowCount() > 1);
                    getExportButton().setEnabled(true);
                } else {
                    getModifyButton().setEnabled(false);
                    getRemoveButton().setEnabled(false);
                    getExportButton().setEnabled(false);
                }
            }
        });
    }
    return paramsTable;
}

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

private JTable createTable(final ViewState state) {
    JTable table;//from ww w.j a  v  a  2  s.c o m
    final ModelGraph selected = state.getSelected();
    if (selected != null) {
        final Vector<Vector<String>> rows = new Vector<Vector<String>>();
        ConcurrentHashMap<String, String> keyToGroupMap = new ConcurrentHashMap<String, String>();
        Metadata staticMet = selected.getModel().getStaticMetadata();
        Metadata inheritedMet = selected.getInheritedStaticMetadata(state);
        Metadata completeMet = new Metadata();
        if (staticMet != null) {
            completeMet.replaceMetadata(staticMet.getSubMetadata(state.getCurrentMetGroup()));
        }
        if (selected.getModel().getExtendsConfig() != null) {
            for (String configGroup : selected.getModel().getExtendsConfig()) {
                Metadata extendsMetadata = state.getGlobalConfigGroups().get(configGroup).getMetadata()
                        .getSubMetadata(state.getCurrentMetGroup());
                for (String key : extendsMetadata.getAllKeys()) {
                    if (!completeMet.containsKey(key)) {
                        keyToGroupMap.put(key, configGroup);
                        completeMet.replaceMetadata(key, extendsMetadata.getAllMetadata(key));
                    }
                }
            }
        }
        if (inheritedMet != null) {
            Metadata inheritedMetadata = inheritedMet.getSubMetadata(state.getCurrentMetGroup());
            for (String key : inheritedMetadata.getAllKeys()) {
                if (!completeMet.containsKey(key)) {
                    keyToGroupMap.put(key, "__inherited__");
                    completeMet.replaceMetadata(key, inheritedMetadata.getAllMetadata(key));
                }
            }
        }
        List<String> keys = completeMet.getAllKeys();
        Collections.sort(keys);
        for (String key : keys) {
            if (key.endsWith("/envReplace")) {
                continue;
            }
            String values = StringUtils.join(completeMet.getAllMetadata(key), ",");
            Vector<String> row = new Vector<String>();
            row.add(keyToGroupMap.get(key));
            row.add(key);
            row.add(values);
            row.add(Boolean.toString(Boolean.parseBoolean(completeMet.getMetadata(key + "/envReplace"))));
            rows.add(row);
        }
        table = new JTable();// rows, new Vector<String>(Arrays.asList(new
                             // String[] { "key", "values", "envReplace" })));
        table.setModel(new AbstractTableModel() {
            public String getColumnName(int col) {
                switch (col) {
                case 0:
                    return "group";
                case 1:
                    return "key";
                case 2:
                    return "values";
                case 3:
                    return "envReplace";
                default:
                    return null;
                }
            }

            public int getRowCount() {
                return rows.size() + 1;
            }

            public int getColumnCount() {
                return 4;
            }

            public Object getValueAt(int row, int col) {
                if (row >= rows.size()) {
                    return null;
                }
                String value = rows.get(row).get(col);
                if (value == null && col == 3) {
                    return "false";
                }
                if (value == null && col == 0) {
                    return "__local__";
                }
                return value;
            }

            public boolean isCellEditable(int row, int col) {
                if (row >= rows.size()) {
                    return selected.getModel().getStaticMetadata().containsGroup(state.getCurrentMetGroup());
                }
                if (col == 0) {
                    return false;
                }
                String key = rows.get(row).get(1);
                return key == null || (selected.getModel().getStaticMetadata() != null
                        && selected.getModel().getStaticMetadata().containsKey(getKey(key, state)));
            }

            public void setValueAt(Object value, int row, int col) {
                if (row >= rows.size()) {
                    Vector<String> newRow = new Vector<String>(
                            Arrays.asList(new String[] { null, null, null, null }));
                    newRow.add(col, (String) value);
                    rows.add(newRow);
                } else {
                    Vector<String> rowValues = rows.get(row);
                    rowValues.add(col, (String) value);
                    rowValues.remove(col + 1);
                }
                this.fireTableCellUpdated(row, col);
            }

        });
        MyTableListener tableListener = new MyTableListener(state);
        table.getModel().addTableModelListener(tableListener);
        table.getSelectionModel().addListSelectionListener(tableListener);
    } else {
        table = new JTable(new Vector<Vector<String>>(),
                new Vector<String>(Arrays.asList(new String[] { "key", "values", "envReplace" })));
    }

    // table.setFillsViewportHeight(true);
    table.setSelectionBackground(Color.cyan);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    TableCellRenderer cellRenderer = new TableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JLabel field = new JLabel((String) value);
            if (column == 0) {
                field.setForeground(Color.gray);
            } else {
                if (isSelected) {
                    field.setBorder(new EtchedBorder(1));
                }
                if (table.isCellEditable(row, 1)) {
                    field.setForeground(Color.black);
                } else {
                    field.setForeground(Color.gray);
                }
            }
            return field;
        }

    };
    TableColumn groupCol = table.getColumnModel().getColumn(0);
    groupCol.setPreferredWidth(75);
    groupCol.setCellRenderer(cellRenderer);
    TableColumn keyCol = table.getColumnModel().getColumn(1);
    keyCol.setPreferredWidth(200);
    keyCol.setCellRenderer(cellRenderer);
    TableColumn valuesCol = table.getColumnModel().getColumn(2);
    valuesCol.setPreferredWidth(300);
    valuesCol.setCellRenderer(cellRenderer);
    TableColumn envReplaceCol = table.getColumnModel().getColumn(3);
    envReplaceCol.setPreferredWidth(75);
    envReplaceCol.setCellRenderer(cellRenderer);

    table.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3 && DefaultPropView.this.table.getSelectedRow() != -1) {
                int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
                String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state);
                Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
                override.setVisible(staticMet == null || !staticMet.containsKey(key));
                delete.setVisible(staticMet != null && staticMet.containsKey(key));
                tableMenu.show(DefaultPropView.this.table, e.getX(), e.getY());
            }
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent e) {
        }
    });

    return table;
}

From source file:com.epiq.bitshark.ui.FrequencyDomainPanel.java

/**
 * Initialize the graph/*from   www.  j  a v a 2s. c  o  m*/
 */
private void initGraph() {

    this.series = new BasicSeries("FFT");
    XYSeriesCollection dataset = new XYSeriesCollection(series);

    JFreeChart graph = ChartFactory.createXYLineChart(null, // title
            "", // no x-axis label
            "", // no y-axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // no legend
            false, // no tooltips
            false // no URLs
    );

    graph.setBorderVisible(false);
    graph.setPadding(new RectangleInsets(-5, 0, 0, 0));
    graph.setBackgroundPaint(null);
    graph.setBackgroundImageAlpha(0.0f);
    graph.setAntiAlias(true);

    plot = (XYPlot) graph.getPlot();

    powerAxis = new PowerAxis();
    plot.setRangeAxis(powerAxis);

    frequencyAxis = new FrequencyAxis();
    frequencyAxis.setTickLabelInsets(new RectangleInsets(10, 0, 0, 0));
    plot.setDomainAxis(frequencyAxis);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, Common.EPIQ_GREEN);
        renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    }

    plot.setBackgroundAlpha(0.0f);
    plot.setBackgroundPaint(null);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // X-axis setup
    plot.getDomainAxis().setAutoRange(false);
    plot.getDomainAxis().setVisible(true);
    plot.getDomainAxis().setRange(0, FMCUartClient.BLOCK_SIZE - 1);
    plot.setDomainCrosshairVisible(false);
    plot.setDomainCrosshairPaint(new Color(46, 46, 46));

    // Y-axis setup
    plot.getRangeAxis().setAutoRange(false);
    plot.getRangeAxis().setVisible(true);
    plot.getRangeAxis().setRange(-50, 70);
    plot.setRangeCrosshairVisible(false);

    markerAnnotation.setVisible(false);
    plot.addAnnotation(markerAnnotation);
    plot.addAnnotation(markerTextAnnotation);

    this.markerTitle.setFont(new Font("Tahoma", Font.BOLD, 12));
    this.markerTitle.setFrame(new BlockBorder(new Color(46, 46, 46)));
    this.markerTitle.setBackgroundPaint(new Color(200, 200, 255, 100));
    this.markerTitle.setText("");
    this.markerTitle.setPadding(5, 15, 5, 15);
    this.markerTitle.setExpandToFitSpace(false);
    this.markerTitle.setBounds(new Rectangle2D.Double(0, 0, 100, 30));

    chartPanel = new ChartPanel(graph, false);
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    chartPanel.setMinimumDrawWidth(0);
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMouseZoomable(true);
    chartPanel.setOpaque(false);

    chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            markerLocked = !markerLocked;
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            updateMouseMarker(event);
        }

    });

    chartPanel.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (!markerLocked) {
                markerAnnotation.setVisible(false);
                plot.setDomainCrosshairVisible(false);
                markerTitle.setVisible(false);
                markerTitle.setText("");
            }
        }

    });

    chartPanel.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            int clicks = e.getWheelRotation();
            plot.getRangeAxis().setUpperBound(plot.getRangeAxis().getUpperBound() + clicks);
            plot.getRangeAxis().setLowerBound(plot.getRangeAxis().getLowerBound() + clicks);
        }
    });

}

From source file:net.sf.dsig.DSApplet.java

private void initSwing() {
    try {/* w  w  w .  j a  va 2  s.c o  m*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        logger.warn("UIManager.setLookAndFeel() failed", e);
    }

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
    panel.setBackground(Color.decode(backgroundColor));
    add(panel);

    boolean lockPrinted = false;
    if (formId != null) {
        Icon lockIcon = new ImageIcon(getClass().getResource("/icons/lock.png"));
        lockPrinted = true;

        JButton button = new JButton("Sign", lockIcon);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                available.acquireUninterruptibly();
                try {
                    signInternal(formId, null);
                } catch (Exception ex) {
                    logger.error("Internal sign failed", e);
                } finally {
                    available.release();
                }
            }
        });
        panel.add(button);
    }

    Icon infoIcon = new ImageIcon(getClass().getResource(lockPrinted ? "/icons/info.png" : "/icons/lock.png"));
    JLabel infoLabel = new JLabel(infoIcon);
    infoLabel.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            JOptionPane.showMessageDialog(null, printInfoMessage());
        }

        public void mouseEntered(MouseEvent e) {
            /* NOOP */ }

        public void mouseExited(MouseEvent e) {
            /* NOOP */ }

        public void mousePressed(MouseEvent e) {
            /* NOOP */ }

        public void mouseReleased(MouseEvent e) {
            /* NOOP */ }
    });
    panel.add(infoLabel);
}

From source file:savant.plugin.builtin.SAFEBrowser.java

public final Component getCenterPanel(List<TreeBrowserEntry> roots) {
    table = new TreeTable(new TreeBrowserModel(roots) {
        @Override//from   w  ww. j  av a2s.c o m
        public String[] getColumnNames() {
            return new String[] { "Name", "Description" };
        }

    });
    table.setSortable(false);
    table.setRespectRenderPreferredHeight(true);

    // configure the TreeTable
    table.setExpandAllAllowed(true);
    table.setShowTreeLines(false);
    table.setSortingEnabled(false);
    table.setRowHeight(18);
    table.setShowGrid(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.expandFirstLevel();
    table.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                actOnSelectedItem(true);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });

    // do not select row when expanding a row.
    table.setSelectRowWhenToggling(false);

    table.getColumnModel().getColumn(0).setPreferredWidth(200);
    //table.getColumnModel().getColumn(1).setPreferredWidth(400);
    //table.getColumnModel().getColumn(2).setPreferredWidth(100);
    //table.getColumnModel().getColumn(3).setPreferredWidth(100);
    //table.getColumnModel().getColumn(4).setPreferredWidth(50);

    table.getColumnModel().getColumn(0).setCellRenderer(FILE_RENDERER);

    // add searchable feature
    TableSearchable searchable = new TableSearchable(table) {

        @Override
        protected String convertElementToString(Object item) {
            if (item instanceof TreeBrowserEntry) {
                return ((TreeBrowserEntry) item).getType();
            }
            return super.convertElementToString(item);
        }
    };
    searchable.setMainIndex(0); // only search for name column

    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.getViewport().setBackground(Color.WHITE);

    JPanel panel = new JPanel(new BorderLayout(6, 6));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setPreferredSize(new Dimension(800, 500));
    return panel;
}