Example usage for java.awt.event MouseEvent getX

List of usage examples for java.awt.event MouseEvent getX

Introduction

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

Prototype

public int getX() 

Source Link

Document

Returns the horizontal x position of the event relative to the source component.

Usage

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Creates the tree view, that holds the data structure. <br>
 * <br>/*ww w .  j a v a 2 s  . c o m*/
 * Initially, the root node is <b>not</b> visible, so that the tree appears empty at the beginning.
 */
private void createTree() {

    /**
     * Mouse listener to listen for mouse events on the tree. <br>
     * This will mark the selected tree entry as "selected" or "unselected",
     * which will cause this nodes checkbox to appear as either "checked" or
     * "unchecked".
     */
    treeMouseListener = new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            int x = e.getX();
            int y = e.getY();

            int row = tree.getRowForLocation(x, y);

            TreePath path = tree.getPathForRow(row);
            if (path != null) {
                CheckableTreeNode node = (CheckableTreeNode) path.getLastPathComponent();
                if (e.getClickCount() == 2) {
                    Object userObject = node.getUserObject();
                    if ((userObject instanceof FileNodeWrapper) && node.isLeaf()) {
                        FileNodeWrapper fnw = (FileNodeWrapper) userObject;
                        try {
                            JabRefDesktop.openExternalViewer(
                                    JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext(),
                                    fnw.file.getAbsolutePath(), "pdf");
                        } catch (IOException e1) {
                            LOGGER.info("Error opening file", e1);
                        }
                    }
                } else {
                    node.check();
                    tree.invalidate();
                    tree.repaint();
                }
            }
        }

    };

    CheckableTreeNode startNode = new CheckableTreeNode("ROOT");
    DefaultTreeModel model = new DefaultTreeModel(startNode);

    tree.setModel(model);
    tree.setRootVisible(false);

    DefaultTreeCellRenderer renderer = new CheckboxTreeCellRenderer();
    tree.setCellRenderer(renderer);

    tree.addMouseListener(treeMouseListener);

}

From source file:com.peterbochs.sourceleveldebugger.SourceLevelDebugger3.java

private void refreshCallGrapphButtonActionPerformed(ActionEvent evt) {
    graph = new mxGraph() {
        public void drawState(mxICanvas canvas, mxCellState state, String label) {
            if (getModel().isVertex(state.getCell()) && canvas instanceof PeterSwingCanvas) {
                PeterSwingCanvas c = (PeterSwingCanvas) canvas;
                c.drawVertex(state, label);
            } else {
                // draw edge, at least
                //               super.drawState(canvas, state, label);
                super.drawState(canvas, state, true);
            }//  ww  w  .j a  v  a  2  s  .c o  m
        }

        // Ports are not used as terminals for edges, they are
        // only used to compute the graphical connection point

        public boolean isPort(Object cell) {
            mxGeometry geo = getCellGeometry(cell);

            return (geo != null) ? geo.isRelative() : false;
        }

        // Implements a tooltip that shows the actual
        // source and target of an edge
        public String getToolTipForCell(Object cell) {
            if (model.isEdge(cell)) {
                return convertValueToString(model.getTerminal(cell, true)) + " -> "
                        + convertValueToString(model.getTerminal(cell, false));
            }

            return super.getToolTipForCell(cell);
        }

        public boolean isCellFoldable(Object cell, boolean collapse) {
            return false;
        }
    };
    graphComponent = new CallGraphComponent(graph);
    Object parent = graph.getDefaultParent();

    //      addCells(parent);
    graph.setCellsDisconnectable(false);

    graphComponent.setGridVisible(true);
    graphComponent.setGridColor(Color.lightGray);
    graphComponent.setBackground(Color.white);
    graphComponent.getViewport().setOpaque(false);
    graphComponent.setBackground(Color.WHITE);
    graphComponent.setConnectable(false);
    graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            Object cell = graphComponent.getCellAt(e.getX(), e.getY());

            if (cell != null) {
                String label = graph.getLabel(cell);
                if (label.contains("->")) {
                    //                  cellClientEvent(label);
                }
            }
        }
    });

    graph.setCellsResizable(false);
    graph.setCellsMovable(false);
    graph.setCellsEditable(false);
    graph.foldCells(false);
    graph.setGridSize(10);
    callGraphPanel.removeAll();
    callGraphPanel.add(graphComponent, BorderLayout.CENTER);

    //      mxGraphOutline graphOutline = new mxGraphOutline(graphComponent);
    //      graphOutline.setBackground(Color.white);
    //      graphOutline.setBorder(new LineBorder(Color.LIGHT_GRAY));
    //      callGraphPanel.removeAll();
    //      callGraphPanel.add(graphOutline, BorderLayout.CENTER);
    //      callGraphPanel.setPreferredSize(new Dimension(100, 100));
}

From source file:src.gui.ItTabbedPane.java

public void mousePressed(MouseEvent mouseEvent) {// this is for Linux
    if (mouseEvent.isPopupTrigger()) {
        //selectedTabIndex = indexAtLocation(mouseEvent.getX(), mouseEvent.getY()); 

        // Only show for top row
        if (getTabPlacement() == JTabbedPane.TOP) {
            popupMenu.show(this, mouseEvent.getX(), mouseEvent.getY());
        }/*from  ww w. j a va2s . c om*/
    }
}

From source file:src.gui.ItTabbedPane.java

public void mouseReleased(MouseEvent mouseEvent) {//this is for Windows
    if (mouseEvent.isPopupTrigger()) {
        // selectedTabIndex = indexAtLocation(mouseEvent.getX(), mouseEvent.getY()); 

        // Only show for top row
        if (getTabPlacement() == JTabbedPane.TOP) {
            popupMenu.show(this, mouseEvent.getX(), mouseEvent.getY());
        }//from w ww.ja  v a  2 s  .c  o  m
    }

}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java

@Override
public void mouseDragged(MouseEvent e) {
    // when not allowed to zoom / select, return
    if (blockSelectionOrZoom) {
        return;//from  w  ww  .  j a v  a  2  s .c om
    }
    // if the popup menu has already been triggered, then ignore dragging...
    if (getChartFieldValueByName("popup") != null
            && ((JPopupMenu) getChartFieldValueByName("popup")).isShowing()) {
        return;
    }

    // handle panning if we have a start point
    if (getChartFieldValueByName("panLast") != null) {
        double dx = e.getX() - ((Point) getChartFieldValueByName("panLast")).getX();
        double dy = e.getY() - ((Point) getChartFieldValueByName("panLast")).getY();
        if (dx == 0.0 && dy == 0.0) {
            return;
        }
        double wPercent = -dx / ((Double) getChartFieldValueByName("panW"));
        double hPercent = dy / ((Double) getChartFieldValueByName("panH"));
        boolean old = getChart().getPlot().isNotify();
        getChart().getPlot().setNotify(false);
        Pannable p = (Pannable) getChart().getPlot();
        if (p.getOrientation() == PlotOrientation.VERTICAL) {
            p.panDomainAxes(wPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
            p.panRangeAxes(hPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
        } else {
            p.panDomainAxes(hPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
            p.panRangeAxes(wPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
        }
        setChartFieldValue((getChartFieldByName("panLast")), e.getPoint());
        getChart().getPlot().setNotify(old);
        return;
    }

    // if no initial zoom point was set, ignore dragging...
    if (getChartFieldValueByName("zoomPoint") == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any). We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!(Boolean) getChartFieldValueByName("useBuffer")) {
        drawZoomRectangle(g2, true);
    }

    boolean hZoom = false;
    boolean vZoom = false;
    if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) {
        hZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
        vZoom = (Boolean) getChartFieldValueByName("domainZoomable");
    } else {
        hZoom = (Boolean) getChartFieldValueByName("domainZoomable");
        vZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
    }
    Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint");
    Rectangle2D scaledDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY());
    if (hZoom && vZoom) {
        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(),
                zoomPoint.getY(), xmax - zoomPoint.getX(), ymax - zoomPoint.getY()));
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(),
                scaledDataArea.getMinY(), xmax - zoomPoint.getX(), scaledDataArea.getHeight()));
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        setChartFieldValue(getChartFieldByName("zoomRectangle"),
                new Rectangle2D.Double(scaledDataArea.getMinX(), zoomPoint.getY(), scaledDataArea.getWidth(),
                        ymax - zoomPoint.getY()));
    }

    // Draw the new zoom rectangle...
    if ((Boolean) getChartFieldValueByName("useBuffer")) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        drawZoomRectangle(g2, true);
    }
    g2.dispose();

}

From source file:canreg.client.gui.analysis.FrequenciesByYearInternalFrame.java

private void columnTableMousePressed(java.awt.event.MouseEvent evt) {
    if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
        JTable target = (JTable) evt.getSource();
        int columnNumber = target.getSelectedColumn();

        JPopupMenu jpm = new JPopupMenu("" + columnNumber);
        jpm.add(java.util.ResourceBundle
                .getBundle("canreg/client/gui/analysis/resources/FrequenciesByYearInternalFrame")
                .getString("COLUMN ")
                + tableColumnModel.getColumn(tableColumnModel.getColumnIndexAtX(evt.getX())).getHeaderValue());
        jpm.show(target, evt.getX(), evt.getY());
    }/* www  . ja  v a  2s  .  co m*/
}

From source file:com.mirth.connect.client.ui.dependencies.ChannelDependenciesPanel.java

private void initComponents() {
    setBackground(UIConstants.BACKGROUND_COLOR);

    dependencyLabel = new JLabel("This channel depends upon:");

    dependencyTreeTable = new MirthTreeTable();

    DefaultTreeTableModel dependencyModel = new SortableTreeTableModel();
    DefaultMutableTreeTableNode dependencyRootNode = new DefaultMutableTreeTableNode();
    dependencyModel.setRoot(dependencyRootNode);

    dependencyTreeTable.setTreeTableModel(dependencyModel);
    dependencyTreeTable.setRootVisible(false);
    dependencyTreeTable.setDoubleBuffered(true);
    dependencyTreeTable.setDragEnabled(false);
    dependencyTreeTable.setRowSelectionAllowed(true);
    dependencyTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dependencyTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    dependencyTreeTable.setFocusable(true);
    dependencyTreeTable.setOpaque(true);
    dependencyTreeTable.setEditable(false);
    dependencyTreeTable.setSortable(true);
    dependencyTreeTable.putClientProperty("JTree.lineStyle", "Horizontal");
    dependencyTreeTable.setAutoCreateColumnsFromModel(false);
    dependencyTreeTable.setShowGrid(true, true);
    dependencyTreeTable.setTableHeader(null);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        dependencyTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }//from ww  w.j  a  va2 s  .c o m

    dependencyTreeTable.setTreeCellRenderer(new DependencyTreeCellRenderer(dependencyTreeTable));

    dependencyTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            if (dependencyTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) {
                dependencyTreeTable.clearSelection();
            }
        }
    });

    dependencyTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                boolean removeEnabled = false;
                int[] rows = dependencyTreeTable.getSelectedModelRows();

                if (rows.length == 1) {
                    TreePath selectedPath = dependencyTreeTable.getPathForRow(rows[0]);

                    if (selectedPath != null) {
                        if (selectedPath.getPathCount() == 2) {
                            removeEnabled = true;
                        }
                    }
                }

                dependencyRemoveButton.setEnabled(removeEnabled);
            }
        }
    });

    dependencyScrollPane = new JScrollPane(dependencyTreeTable);

    dependencyExpandAllLabel = new JLabel("<html><u>Expand All</u></html>");
    dependencyExpandAllLabel.setForeground(Color.BLUE);
    dependencyExpandAllLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    dependencyExpandAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            dependencyTreeTable.expandAll();
        }
    });

    dependencyCollapseAllLabel = new JLabel("<html><u>Collapse All</u></html>");
    dependencyCollapseAllLabel.setForeground(Color.BLUE);
    dependencyCollapseAllLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    dependencyCollapseAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            dependencyTreeTable.collapseAll();
        }
    });

    dependencyAddButton = new JButton("Add");
    dependencyAddButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            Map<String, String> allowedChannelsMap = getAllowedChannels(true);

            if (MapUtils.isNotEmpty(allowedChannelsMap)) {
                AddDialog dialog = new AddDialog(allowedChannelsMap, true);

                if (dialog.wasSaved()) {
                    for (String dependencyId : dialog.getSelectedChannelIds()) {
                        dependencies.add(new ChannelDependency(channel.getId(), dependencyId));
                    }

                    updateTreeTable(true, dependencies);
                    updateAddButton();
                }
            }
        }
    });

    dependencyRemoveButton = new JButton("Remove");
    dependencyRemoveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            int[] rows = dependencyTreeTable.getSelectedModelRows();

            if (rows.length == 1) {
                TreePath selectedPath = dependencyTreeTable.getPathForRow(rows[0]);

                if (selectedPath != null && selectedPath.getPathCount() == 2) {
                    Pair<String, String> pair = (Pair<String, String>) ((MutableTreeTableNode) selectedPath
                            .getLastPathComponent()).getUserObject();

                    for (Iterator<ChannelDependency> it = dependencies.iterator(); it.hasNext();) {
                        ChannelDependency dependency = it.next();
                        if (StringUtils.equals(channel.getId(), dependency.getDependentId())
                                && StringUtils.equals(pair.getLeft(), dependency.getDependencyId())) {
                            it.remove();
                        }
                    }

                    updateTreeTable(true, dependencies);
                    updateAddButton();
                }
            }
        }
    });
    dependencyRemoveButton.setEnabled(false);

    dependentLabel = new JLabel("This channel is depended upon by:");

    dependentTreeTable = new MirthTreeTable();

    DefaultTreeTableModel dependentModel = new SortableTreeTableModel();
    DefaultMutableTreeTableNode dependentRootNode = new DefaultMutableTreeTableNode();
    dependentModel.setRoot(dependentRootNode);

    dependentTreeTable.setTreeTableModel(dependentModel);
    dependentTreeTable.setRootVisible(false);
    dependentTreeTable.setDoubleBuffered(true);
    dependentTreeTable.setDragEnabled(false);
    dependentTreeTable.setRowSelectionAllowed(true);
    dependentTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dependentTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    dependentTreeTable.setFocusable(true);
    dependentTreeTable.setOpaque(true);
    dependentTreeTable.setEditable(false);
    dependentTreeTable.setSortable(true);
    dependentTreeTable.putClientProperty("JTree.lineStyle", "Horizontal");
    dependentTreeTable.setAutoCreateColumnsFromModel(false);
    dependentTreeTable.setShowGrid(true, true);
    dependentTreeTable.setTableHeader(null);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        dependentTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    dependentTreeTable.setTreeCellRenderer(new DependencyTreeCellRenderer(dependentTreeTable));

    dependentTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            if (dependentTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) {
                dependentTreeTable.clearSelection();
            }
        }
    });

    dependentTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                boolean removeEnabled = false;
                int[] rows = dependentTreeTable.getSelectedModelRows();

                if (rows.length == 1) {
                    TreePath selectedPath = dependentTreeTable.getPathForRow(rows[0]);

                    if (selectedPath != null) {
                        if (selectedPath.getPathCount() == 2) {
                            removeEnabled = true;
                        }
                    }
                }

                dependentRemoveButton.setEnabled(removeEnabled);
            }
        }
    });

    dependentScrollPane = new JScrollPane(dependentTreeTable);

    dependentExpandAllLabel = new JLabel("<html><u>Expand All</u></html>");
    dependentExpandAllLabel.setForeground(Color.BLUE);
    dependentExpandAllLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    dependentExpandAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            dependentTreeTable.expandAll();
        }
    });

    dependentCollapseAllLabel = new JLabel("<html><u>Collapse All</u></html>");
    dependentCollapseAllLabel.setForeground(Color.BLUE);
    dependentCollapseAllLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    dependentCollapseAllLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent evt) {
            dependentTreeTable.collapseAll();
        }
    });

    dependentAddButton = new JButton("Add");
    dependentAddButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            Map<String, String> allowedChannelsMap = getAllowedChannels(false);

            if (MapUtils.isNotEmpty(allowedChannelsMap)) {
                AddDialog dialog = new AddDialog(allowedChannelsMap, false);

                if (dialog.wasSaved()) {
                    for (String dependentId : dialog.getSelectedChannelIds()) {
                        dependencies.add(new ChannelDependency(dependentId, channel.getId()));
                    }

                    updateTreeTable(false, dependencies);
                    updateAddButton();
                }
            }
        }
    });

    dependentRemoveButton = new JButton("Remove");
    dependentRemoveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            int[] rows = dependentTreeTable.getSelectedModelRows();

            if (rows.length == 1) {
                TreePath selectedPath = dependentTreeTable.getPathForRow(rows[0]);

                if (selectedPath != null && selectedPath.getPathCount() == 2) {
                    Pair<String, String> pair = (Pair<String, String>) ((MutableTreeTableNode) selectedPath
                            .getLastPathComponent()).getUserObject();

                    for (Iterator<ChannelDependency> it = dependencies.iterator(); it.hasNext();) {
                        ChannelDependency dependency = it.next();
                        if (StringUtils.equals(pair.getLeft(), dependency.getDependentId())
                                && StringUtils.equals(channel.getId(), dependency.getDependencyId())) {
                            it.remove();
                        }
                    }

                    updateTreeTable(false, dependencies);
                    updateAddButton();
                }
            }
        }
    });
    dependentRemoveButton.setEnabled(false);
}

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

@Override
public JXTreeTable getTable() {
    if (table == null) {
        if (model == null) {
            model = new HttpFuzzTableModel();
        }/*w  w w.j a va2 s  .c  o m*/
        table = new JXTreeTable(model);
        table.setDoubleBuffered(true);
        table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        table.setName("HttpFuzzResultTable");
        table.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12));
        table.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 = table.getColumnModel().getColumn(i);
            column.setPreferredWidth(widths[i]);
        }
        table.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()) {
                    if (e.isPopupTrigger()) {
                        // 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());
                    }
                }
            }

        });
        table.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {

            @Override
            public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    if (table.getSelectedRowCount() == 0) {
                        return;
                    }
                    final int row = table.getSelectedRow();
                    if (getEntry(row) instanceof HttpFuzzRequestRecord) {
                        final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(row))
                                .getHistory();
                        try {
                            getMessageInspection().setMessage(historyReference.getHttpMessage());
                        } catch (HttpMalformedHeaderException | SQLException ex) {
                            logger.error(ex.getMessage(), ex);
                        }
                    }
                    updateValues();
                    redrawDiagrams();
                }
            }
        });
    }
    table.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 = table.columnAtPoint(e.getPoint());
            List<HttpFuzzRecord> list = model.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;
            }
            table.updateUI();
        }
    });
    table.setRootVisible(false);
    table.setVisible(true);
    return table;
}

From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java

void pnlLinksMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMouseDragged
    // Add your handling code here:

    Container container = pnlInScroll.getParent();
    if (container instanceof JViewport) {
        JViewport viewport = (JViewport) container;
        Point point = viewport.getViewPosition();
        int newX = point.x - (evt.getX() - downX);
        int newY = point.y - (evt.getY() - downY);

        int maxX = pnlInScroll.getWidth() - viewport.getWidth();
        int maxY = pnlInScroll.getHeight() - viewport.getHeight();

        if (newX < 0) {
            newX = 0;//from w  ww  .  j  av  a2 s. c om
        }
        if (newX > maxX) {
            newX = maxX;
        }
        if (newY < 0) {
            newY = 0;
        }
        if (newY > maxY) {
            newY = maxY;
        }

        viewport.setViewPosition(new Point(newX, newY));
    }
}

From source file:edu.purdue.cc.bionet.ui.GraphVisualizer.java

/**
 * The mouseClicked method of the MouseListener interface.
 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
 * /*from w  ww .j a  v  a  2  s.  co m*/
 * @param event The event which triggered this action.
 */
public void mouseClicked(MouseEvent event) {
    E edge = this.getPickSupport().getEdge(this.getGraphLayout(), event.getX(), event.getY());
    V vertex = this.getPickSupport().getVertex(this.getGraphLayout(), event.getX(), event.getY());
    if (edge != null && vertex == null) {
        this.fireGraphMouseEdgeClickedEvent(edge, event);
    }
}