Example usage for java.awt.event MouseEvent getPoint

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

Introduction

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

Prototype

public Point getPoint() 

Source Link

Document

Returns the x,y position of the event relative to the source component.

Usage

From source file:ded.ui.DiagramController.java

@Override
public void mouseClicked(MouseEvent e) {
    this.eventReceived(e);

    // Double-click on control to edit it.
    if (SwingUtilities.isLeftMouseButton(e) && (e.getClickCount() == 2)) {
        Controller c = this.hitTest(e.getPoint(), null);
        if (c != null) {
            c.edit();/*from   ww  w  .  j a v  a 2s  .  co m*/
        }
    }
}

From source file:ded.ui.DiagramController.java

@Override
public void mousePressed(MouseEvent e) {
    this.eventReceived(e);

    switch (this.mode) {
    case DCM_SELECT: {
        // Clicked a controller?
        Controller c = this.hitTest(e.getPoint(), null);
        if (c == null) {
            // Missed controls, start a lasso selection
            // if left button.
            if (SwingUtilities.isLeftMouseButton(e)) {
                this.lassoOriginalSelected.clear();
                if (SwingUtil.controlPressed(e)) {
                    // Control is pressed.  Keep current selections.
                    this.lassoOriginalSelected.addAll(this.getAllSelected());
                } else {
                    if (this.deselectAll() > 0) {
                        this.repaint();
                    }//from ww w. j  ava 2s  . co  m
                }

                // Enter lasso mode.
                setMode(Mode.DCM_RECT_LASSO);
                this.lassoStart = this.lassoEnd = e.getPoint();
            }
        } else {
            c.mousePressed(e);
        }
        break;
    }

    case DCM_CREATE_RELATION: {
        // Make a Relation that starts and ends at the current location.
        RelationEndpoint start = this.getRelationEndpoint(e.getPoint());
        RelationEndpoint end = new RelationEndpoint(start);
        end.arrowStyle = ArrowStyle.AS_FILLED_TRIANGLE;
        Relation r = new Relation(start, end);
        this.diagram.relations.add(r);
        this.setDirty();

        // Build a controller and select it.
        RelationController rc = this.buildRelationController(r);
        this.selectOnly(rc);

        // Drag the end point while the mouse button is held.
        this.beginDragging(rc.getEndHandle(), e.getPoint());

        this.repaint();
        break;
    }

    case DCM_CREATE_ENTITY: {
        EntityController.createEntityAt(this, e.getPoint());
        this.setMode(Mode.DCM_SELECT);
        this.setDirty();
        break;
    }

    case DCM_CREATE_INHERITANCE: {
        if (SwingUtilities.isLeftMouseButton(e)) {
            this.createInheritanceAt(e.getPoint());
            this.setDirty();
        }
        break;
    }

    case DCM_DRAGGING:
    case DCM_RECT_LASSO:
        // These modes are entered with a mouse press and
        // exited with mouse release, so we should not get
        // a mouse press while already in such a mode.
        // Ignore it if it happens.
        break;
    }
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

@Override
public void mousePressed(MouseEvent e) {
    //        int mods = e.getModifiers();
    //        if (isMaskingEnabled() && (mods & maskingKeyMask) != 0) {
    if (isMaskingEnabled()) {
        // Prepare masking service.
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        if (cursorType == Cursor.DEFAULT_CURSOR) {
            Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
            if (screenDataArea != null) {
                this.maskPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea);
            } else {
                this.maskPoint = null;
            }/*from  www  .  j av a2  s.c o m*/
        } else {
            if (cursorType == Cursor.MOVE_CURSOR) {
                Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
                if (point != null) {
                    this.maskMovePoint = point;
                }
            }
            setMaskDragIndicator(cursorType);
        }
    }
    if (getMaskDragIndicator() == Cursor.DEFAULT_CURSOR) {
        if (e.getX() < getScreenDataArea().getMaxX()) {
            super.mousePressed(e);
        }
    }
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

/**
  * //from   w  ww.  j  a v a2s.c om
  */
protected void buildSpreadsheet() {

    this.setShowGrid(true);

    int numRows = model.getRowCount();

    scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    final SpreadSheet ss = this;
    JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll",
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    ss.selectAll();
                }
            });
    cornerBtn.setEnabled(true);
    scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn);

    // Allows row and collumn selections to exit at the same time
    setCellSelectionEnabled(true);

    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
         */
        @SuppressWarnings("synthetic-access")
        @Override
        public void mouseReleased(MouseEvent e) {
            // XXX For Java 5 Bug
            prevRowSelInx = getSelectedRow();
            prevColSelInx = getSelectedColumn();

            if (e.getClickCount() == 2) {
                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                ss.editCellAt(rowIndexStart, colIndexStart);
                if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) {
                    ss.getEditorComponent().requestFocus();

                    final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent();
                    String txt = txtComp.getText();
                    FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont());
                    int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1;
                    int prevWidth = 0;
                    for (int i = 0; i < txt.length(); i++) {

                        int width = fm.stringWidth(txt.substring(0, i));
                        int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5);
                        //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf);
                        //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i);
                        if (x < width) {
                            // Clearing the selection is needed for Window for some reason
                            final int inx = i + (x <= basePlusHalf ? -1 : 0);
                            SwingUtilities.invokeLater(new Runnable() {
                                @SuppressWarnings("synthetic-access")
                                public void run() {
                                    txtComp.setSelectionStart(0);
                                    txtComp.setSelectionEnd(0);
                                    txtComp.setCaretPosition(inx > 0 ? inx : 0);
                                }
                            });
                            break;
                        }
                        prevWidth = width;
                    }
                }
            }
        }
    });

    // Create a row-header to display row numbers.
    // This row-header is made of labels whose Borders,
    // Foregrounds, Backgrounds, and Fonts must be
    // the one used for the table column headers.
    // Also ensure that the row-header labels and the table
    // rows have the same height.

    //i have no idea WHY this has to be called.  i rearranged
    //the table and find replace panel, 
    // i started getting an array index out of
    //bounds on the column header ON MAC ONLY.  
    //tried firing this off, first and it fixed the problem.//meg
    this.getModel().fireTableStructureChanged();

    /*
     * Create the Row Header Panel
     */
    rowHeaderPanel = new JPanel((LayoutManager) null);

    if (getColumnModel().getColumnCount() > 0) {
        TableColumn column = getColumnModel().getColumn(0);
        TableCellRenderer renderer = getTableHeader().getDefaultRenderer();
        if (renderer == null) {
            renderer = column.getHeaderRenderer();
        }

        Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false,
                false, -1, 0);
        cellFont = cellRenderComp.getFont();

    } else {
        cellFont = (new JLabel()).getFont();
    }

    // Calculate Row Height
    cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder");
    Insets insets = cellBorder.getBorderInsets(tableHeader);
    FontMetrics metrics = getFontMetrics(cellFont);

    rowHeight = insets.bottom + metrics.getHeight() + insets.top;
    rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left;

    Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows);
    rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used.

    rhCellMouseAdapter = new RHCellMouseAdapter(this);

    // Adding the row header labels
    for (int ii = 0; ii < numRows; ii++) {
        addRow(ii, ii + 1, false);
    }

    JViewport viewPort = new JViewport();
    dim.height = rowHeight * numRows;
    viewPort.setViewSize(dim);
    viewPort.setView(rowHeaderPanel);
    scrollPane.setRowHeader(viewPort);

    // Experimental from the web, but I think it does the trick.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown()
                    && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB
                    && e.getKeyCode() != KeyEvent.VK_ENTER) {
                log.error("Grabbed the event as input");

                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                if (rowIndexStart == -1 || colIndexStart == -1)
                    return;

                ss.editCellAt(rowIndexStart, colIndexStart);
                Component c = ss.getEditorComponent();
                if (c instanceof JTextComponent)
                    ((JTextComponent) c).setText("");
            }
        }
    });

    resizeAndRepaint();

    // Taken from a JavaWorld Example (But it works)
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false);

    Action ssAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SpreadSheet.this.actionPerformed(e);
        }
    };

    getInputMap().put(cut, "Cut");
    getActionMap().put("Cut", ssAction);

    getInputMap().put(copy, "Copy");
    getActionMap().put("Copy", ssAction);

    getInputMap().put(paste, "Paste");
    getActionMap().put("Paste", ssAction);

    ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this);

    setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED);
}

From source file:de.codesourcery.jasm16.ide.ui.views.SourceCodeView.java

private final JPanel createPanel() {
    disableDocumentListener(); // necessary because setting colors on editor pane triggers document change listeners (is considered a style change...)

    try {/*from  w ww  .jav a  2s. c  o m*/
        editorPane.setEditable(editable);
        editorPane.getDocument().addUndoableEditListener(undoListener);
        editorPane.setCaretColor(Color.WHITE);
        setupKeyBindings(editorPane);
        setColors(editorPane);
        editorScrollPane = new JScrollPane(editorPane);
        setColors(editorScrollPane);
        editorPane.addCaretListener(listener);
        editorPane.addMouseListener(mouseListener);
        editorPane.addMouseMotionListener(new MouseMotionAdapter() {

            @Override
            public void mouseMoved(MouseEvent e) {
                if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0) // ctrl pressed
                {
                    final ASTNode node = getASTNodeForLocation(e.getPoint());
                    if (node instanceof SymbolReferenceNode) {
                        maybeUnderlineIdentifierAt(e.getPoint());
                    } else {
                        clearUnderlineHighlight();
                    }
                } else if (compilationUnit != null) {
                    String tooltipText = null;
                    if (compilationUnit != null) {
                        final ASTNode node = getASTNodeForLocation(e.getPoint());
                        if (node instanceof InvokeMacroNode) {
                            tooltipText = ExpandMacrosPhase.expandInvocation((InvokeMacroNode) node,
                                    compilationUnit);
                            if (tooltipText != null) {
                                tooltipText = "<html>" + tooltipText.replace("\n", "<br>") + "</html>";
                            }
                        }
                    }
                    if (!StringUtils.equals(editorPane.getToolTipText(), tooltipText)) {
                        editorPane.setToolTipText(tooltipText);
                    }
                }
            }
        });
        editorPane.addMouseListener(popupListener);
    } finally {
        enableDocumentListener();
    }

    EditorContainer.addEditorCloseKeyListener(editorPane, this);

    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setPreferredSize(new Dimension(400, 600));
    editorScrollPane.setMinimumSize(new Dimension(100, 100));

    final AdjustmentListener adjustmentListener = new AdjustmentListener() {

        @Override
        public void adjustmentValueChanged(AdjustmentEvent e) {
            if (!e.getValueIsAdjusting()) {
                if (compilationUnit != null) {
                    doHighlighting(compilationUnit, false);
                }
            }
        }
    };
    editorScrollPane.getVerticalScrollBar().addAdjustmentListener(adjustmentListener);
    editorScrollPane.getHorizontalScrollBar().addAdjustmentListener(adjustmentListener);

    // button panel
    final JPanel topPanel = new JPanel();

    final JToolBar toolbar = new JToolBar();

    setColors(toolbar);

    cursorPosition.setSize(new Dimension(400, 15));
    cursorPosition.setEditable(false);
    setColors(cursorPosition);

    /**
     * TOOLBAR
     * SOURCE
     * cursor position
     * status area 
     */
    topPanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;
    topPanel.add(toolbar, cnstrs);

    cnstrs = constraints(0, 1, GridBagConstraints.BOTH);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    topPanel.add(editorScrollPane, cnstrs);

    cnstrs = constraints(0, 2, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;
    topPanel.add(cursorPosition, cnstrs);

    cnstrs = constraints(0, 3, GridBagConstraints.HORIZONTAL);
    cnstrs.gridwidth = GridBagConstraints.REMAINDER;
    cnstrs.weighty = 0;

    // setup result panel
    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    setColors(panel);
    cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    panel.add(topPanel, cnstrs);
    return panel;
}

From source file:ded.ui.DiagramController.java

@Override
public void mouseDragged(MouseEvent e) {
    this.eventReceived(e);

    if (this.mode == Mode.DCM_DRAGGING) {
        this.selfCheck();

        // Where are we going to move the dragged object's main point?
        Point destLoc = GeomUtil.subtract(e.getPoint(), this.dragOffset);

        // Snap if Shift not held.
        if (!SwingUtil.shiftPressed(e)) {
            destLoc = GeomUtil.snapPoint(destLoc, SNAP_DIST);
        }//from   w ww  . jav a 2s. co m

        if (this.dragging.isSelected()) {
            // How far are we going to move the dragged object?
            Point delta = GeomUtil.subtract(destLoc, this.dragging.getLoc());

            // Move all selected controls by that amount.
            for (Controller c : this.controllers) {
                if (!c.isSelected()) {
                    continue;
                }

                Point cur = c.getLoc();
                c.dragTo(GeomUtil.add(cur, delta));
            }
        } else {
            // Dragging item is not selected; must be a resize handle.
            this.dragging.dragTo(destLoc);
        }

        this.repaint();
    }

    if (this.mode == Mode.DCM_RECT_LASSO) {
        this.lassoEnd = e.getPoint();
        this.selectAccordingToLasso();
        this.repaint();
    }
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/**
 * Reacts to mouse pressed and mouse release event.
 * //from  www  . j a  va  2 s  .  c o  m
 * @param me        The event to handle.
 * @param released  Pass <code>true</code> if the method is invoked when
 *                  the mouse is released, <code>false</code> otherwise.
 */
private void onClick(MouseEvent me, boolean released) {
    Point p = me.getPoint();
    int row = treeDisplay.getRowForLocation(p.x, p.y);
    if (row != -1) {
        if (me.getClickCount() == 1) {
            model.setClickPoint(p);
            if (mousePressedTime > eventHandledTime)
                /* have not yet seen the tree selection event */
                delayedHandlingTreeSelection = true;
            else
                handleTreeSelection();
            //if (released) {
            if ((me.isPopupTrigger() && !released)
                    || (me.isPopupTrigger() && released && !UIUtilities.isMacOS())
                    || (UIUtilities.isMacOS() && SwingUtilities.isLeftMouseButton(me) && me.isControlDown())) {
                if (rightClickButton && !model.isMultiSelection()) { //(!(me.isShiftDown() || ctrl))

                    TreePath path = treeDisplay.getPathForLocation(p.x, p.y);
                    //treeDisplay.removeTreeSelectionListener(
                    //      selectionListener);
                    if (path != null)
                        treeDisplay.setSelectionPath(path);
                    //treeDisplay.addTreeSelectionListener(selectionListener);
                    if (path != null && path.getLastPathComponent() instanceof TreeImageDisplay)
                        controller.onRightClick((TreeImageDisplay) path.getLastPathComponent());
                }
                if (model.getBrowserType() == Browser.ADMIN_EXPLORER)
                    controller.showPopupMenu(TreeViewer.ADMIN_MENU);
                else
                    controller.showPopupMenu(TreeViewer.FULL_POP_UP_MENU);
            }
        } else if (me.getClickCount() == 2 && !(me.isMetaDown() || me.isControlDown() || me.isShiftDown())) {
            //controller.cancel();
            //model.viewDataObject();
            TreeImageDisplay d = model.getLastSelectedDisplay();
            if (d == null)
                return;
            Object o = d.getUserObject();
            if (o instanceof ImageData) {
                model.browse(d);
            } else if (o instanceof PlateData) {
                if (!d.hasChildrenDisplay() || d.getChildrenDisplay().size() == 1)
                    model.browse(d);
            } else if (o instanceof PlateAcquisitionData) {
                model.browse(d);
            }
        }
    }
}

From source file:com.hp.alm.ali.idea.content.taskboard.TaskBoardPanel.java

public TaskBoardPanel(final Project project) {
    super(new BorderLayout());

    this.project = project;

    status = new EntityStatusPanel(project);
    queue = new QueryQueue(project, status, false);

    entityService = project.getComponent(EntityService.class);
    entityService.addEntityListener(this);
    sprintService = project.getComponent(SprintService.class);
    sprintService.addListener(this);

    loadTasks();/* w w  w.  j ava  2  s.  c o  m*/

    header = new Header();
    columnHeader = new ColumnHeader();

    content = new Content();
    add(content, BorderLayout.NORTH);

    header.assignedTo.reload();

    // force mouse-over task as visible (otherwise events are captured by the overlay and repaint quirks)
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing() && event.getID() == MouseEvent.MOUSE_MOVED) {
                MouseEvent m = (MouseEvent) event;
                TaskPanel currentPanel = locateContainer(m, TaskPanel.class);
                if (currentPanel != null) {
                    if (forcedTaskPanel == currentPanel) {
                        return;
                    } else if (forcedTaskPanel != null) {
                        forcedTaskPanel.removeForcedMatch(this);
                    }
                    forcedTaskPanel = currentPanel;
                    forcedTaskPanel.addForcedMatch(this);
                } else if (forcedTaskPanel != null) {
                    forcedTaskPanel.removeForcedMatch(this);
                    forcedTaskPanel = null;
                }
            }
        }
    }, AWTEvent.MOUSE_MOTION_EVENT_MASK);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        @Override
        public void eventDispatched(AWTEvent event) {
            if (isShowing()) {
                MouseEvent m = (MouseEvent) event;
                switch (event.getID()) {
                case MouseEvent.MOUSE_PRESSED:
                case MouseEvent.MOUSE_RELEASED:
                    // implement backlog item popup
                    if (m.isPopupTrigger()) {
                        final BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            ActionPopupMenu popupMenu = ActionUtil.createEntityActionPopup("taskboard");
                            Point p = SwingUtilities.convertPoint(m.getComponent(), m.getPoint(), itemPanel);
                            popupMenu.getComponent().show(itemPanel, p.x, p.y);
                        }
                    }
                    break;

                case MouseEvent.MOUSE_CLICKED:
                    // implement backlog item double click
                    if (m.getClickCount() > 1) {
                        BacklogItemPanel itemPanel = locateContainer(m, BacklogItemPanel.class);
                        if (itemPanel != null) {
                            Entity backlogItem = itemPanel.getItem();
                            Entity workItem = new Entity(backlogItem.getPropertyValue("entity-type"),
                                    Integer.valueOf(backlogItem.getPropertyValue("entity-id")));
                            AliContentFactory.loadDetail(project, workItem, true, true);
                        }
                    }
                }
            }

        }
    }, AWTEvent.MOUSE_EVENT_MASK);
}

From source file:oct.analysis.application.OCTAnalysisUI.java

private void octAnalysisPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_octAnalysisPanelMouseClicked
    octAnalysisPanel.requestFocus();/*from w  ww.  ja v  a 2s. c o m*/
    //only perform actions when mouse click occurs over image area
    if (analysisMngr.getAnalysisMode() != null
            && octAnalysisPanel.coordinateOverlapsOCT(evt.getX(), evt.getY())) {
        switch (evt.getButton()) {
        case MouseEvent.BUTTON1:
            switch (analysisMngr.getAnalysisMode()) {
            case SINGLE:
                switch (toolMode) {
                case SELECT_SINGLE:
                    //clear out any current analysis selection
                    selectionLRPManager.removeSelections(false);
                    octAnalysisPanel.repaint();
                    //add new selections and redraw panel
                    selectionLRPManager.addOrUpdateSelection(selectionLRPManager.getSelection(
                            octAnalysisPanel.translatePanelPointToOctPoint(evt.getPoint()).x, "Selection",
                            SelectionType.NONFOVEAL, true));
                    octAnalysisPanel.repaint();
                    break;
                case SCREEN_SELECT:
                    selectSelection(evt.getPoint());
                    break;
                }
                break;
            case MIRROR:
                switch (toolMode) {
                case SELECT_SINGLE:
                    //clear out any current analysis selection
                    selectionLRPManager.removeNonfovealSelections(false);
                    octAnalysisPanel.repaint();
                    //add new selections and redraw panel
                    int distFromFovea = Math.abs(analysisMngr.getFoveaCenterXPosition()
                            - octAnalysisPanel.translatePanelPointToOctPoint(evt.getPoint()).x);
                    selectionLRPManager.addOrUpdateSelection(selectionLRPManager.getSelection(
                            analysisMngr.getFoveaCenterXPosition() - distFromFovea, "Left",
                            SelectionType.NONFOVEAL, true));
                    selectionLRPManager.addOrUpdateSelection(selectionLRPManager.getSelection(
                            analysisMngr.getFoveaCenterXPosition() + distFromFovea, "Right",
                            SelectionType.NONFOVEAL, true));
                    octAnalysisPanel.repaint();
                    break;
                case SCREEN_SELECT:
                    selectSelection(evt.getPoint());
                    break;
                }
                break;
            case EZ:
                //allow user to select and change position of the EZ edge selections after the fact
                switch (toolMode) {
                case SCREEN_SELECT:
                    selectSelection(evt.getPoint());
                default:
                    break;
                }
                break;
            case EQUIDISTANT:
                //allow user to change placement of fovea after the fact
                if (toolMode == ToolMode.SELECT_FOVEA) {
                    //clear out any current analysis information
                    selectionLRPManager.removeSelections(true);
                    octAnalysisPanel.repaint();
                    //add new selections and redraw panel
                    selectionLRPManager.addOrUpdateEquidistantSelections(evt.getX(),
                            analysisMngr.getMicronsBetweenSelections());
                    octAnalysisPanel.repaint();
                }
                break;
            default:
                break;
            }
            break;
        case MouseEvent.BUTTON3:
            selectionLRPManager.removeSelections(true);
            octAnalysisPanel.repaint();
            break;
        default:
            break;
        }
    }
}

From source file:tauargus.gui.PanelTable.java

private void initTableSelectionListeners() {
    table.getTableHeader().addMouseListener(new MouseAdapter() {
        @Override/*  w w w . j a v  a2 s .  c  o m*/
        public void mouseClicked(MouseEvent e) {
            if (e.getSource() != table.getTableHeader())
                return;
            int col = table.getTableHeader().columnAtPoint(e.getPoint());
            if (col >= 1) {
                // column header is selected
                Code code = getColumnCode(col);
                if (code.state != Code.NODE) {
                    if (code.state == Code.EXPANDED) {
                        code.state = Code.COLLAPSED;
                    } else {
                        code.state = Code.EXPANDED;
                    }
                    createColumnIndices();
                    ((AbstractTableModel) table.getModel()).fireTableStructureChanged();
                    adjustColumnWidths();
                }
            }
        }
    });

    ListSelectionListener listSelectionListener = new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int row = table.getSelectedRow();
                int col = table.getSelectedColumn();
                if (row >= 0 && col >= 0) {
                    if (col == 0) {
                        Code code = getRowCode(row);
                        if (code.state != Code.NODE) {
                            if (code.state == Code.EXPANDED) {
                                code.state = Code.COLLAPSED;
                            } else {
                                code.state = Code.EXPANDED;
                            }
                            createRowIndices();
                            ((AbstractTableModel) table.getModel()).fireTableDataChanged();
                            adjustColumnWidths();
                        }
                    } else {
                        // cell is selected
                        Cell cell = getCell(row, col);
                        panelCellInformation.update(tableSet, cell, integerFormatter, doubleFormatter);
                        organiseSafetyButtons(cell.status);
                    }
                }
            }
        }
    };

    // react on row changes
    table.getSelectionModel().addListSelectionListener(listSelectionListener);
    // .. and react on column changes
    table.getColumnModel().getSelectionModel().addListSelectionListener(listSelectionListener);
}