Java Code Examples for java.awt.event.MouseEvent#getSource()

The following examples show how to use java.awt.event.MouseEvent#getSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VisualGraphComponentProvider.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private V getVertexUnderMouse(MouseEvent event) {

		Object source = event.getSource();
		GraphViewer<V, E> viewer = getPrimaryGraphViewer(source);
		if (viewer == null) {
			return null;
		}

		VertexMouseInfo<V, E> info =
			GraphViewerUtils.convertMouseEventToVertexMouseEvent(viewer, event);
		if (info == null) {
			return null;
		}

		V vertex = info.getVertex();
		return vertex;
	}
 
Example 2
Source File: CTableSorter.java    From binnavi with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseClicked(final MouseEvent e) {
  final JTableHeader h = (JTableHeader) e.getSource();
  final TableColumnModel columnModel = h.getColumnModel();
  final int viewColumn = columnModel.getColumnIndexAtX(e.getX());
  final int column = columnModel.getColumn(viewColumn).getModelIndex();
  if (column != -1) {
    int status = getSortingStatus(column);
    if (!e.isControlDown()) {
      cancelSorting();
    }
    // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
    // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
    status = status + (e.isShiftDown() ? -1 : 1);
    status = ((status + 4) % 3) - 1; // signed mod, returning {-1, 0, 1}
    setSortingStatus(column, status);
  }
}
 
Example 3
Source File: ImportPreviewTable.java    From chipster with MIT License 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
	// Mark drag start point just in case user starts dragging
	lastDragPoint = e.getPoint();
	
	// Listeners for first step
	if(e.getSource() == this && screen.getCurrentStep() == ImportScreen.Step.FIRST){
		
		// Mark header
		if(tableFrame.isInHeaderMarkingMode()){
			markHeaderAtPoint(e.getPoint());
		} 
		
		// Mark footer
		else if(tableFrame.isInFooterMarkingMode()){
			markFooterAtPoint(e.getPoint());
		} 
		
		// Mark title row
		else if(tableFrame.isInTitleMarkingMode()){
			markTitleAtPoint(e.getPoint(), true);
		} 
		
		else {
			JOptionPane.showMessageDialog(screen.getFrame(), NO_TOOL_DIALOG_TITLE, NO_TOOL_DIALOG_TEXT, JOptionPane.WARNING_MESSAGE);
		}
	} 
	
	// Listeners for second step
	else if(e.getSource() == this && screen.getCurrentStep() == ImportScreen.Step.SECOND){			
		markColumnAtPoint(e.getPoint());
	}
}
 
Example 4
Source File: ListRendererMouseEventForwarder.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void redispatchEvent(MouseEvent event) {
	JList list = (JList) event.getSource();
	int index = list.locationToIndex(event.getPoint());
	Rectangle cellBounds = list.getCellBounds(index, index);
	if (cellBounds == null) {
		return;
	}

	ListModel model = list.getModel();
	Object state = model.getElementAt(index);

	ListCellRenderer renderer = list.getCellRenderer();
	Component rendererComponent =
		renderer.getListCellRendererComponent(list, state, index, true, true);
	rendererComponent.setBounds(cellBounds);

	Point p = event.getPoint();
	p.translate(-cellBounds.x, -cellBounds.y);

	MouseEvent newEvent =
		new MouseEvent(rendererComponent, event.getID(), event.getWhen(), event.getModifiers(),
			p.x, p.y, event.getXOnScreen(), event.getYOnScreen(), event.getClickCount(),
			event.isPopupTrigger(), event.getButton());

	rendererComponent.dispatchEvent(newEvent);
	list.repaint();
}
 
Example 5
Source File: Chart.java    From Astrosoft with GNU General Public License v2.0 5 votes vote down vote up
public void mouseEntered(MouseEvent e) {
	
	source = (Container) e.getSource();
	
	if (source instanceof JTable){
		source = ((JTable)source).getParent();
	}
	
	//if (previous_source != null && previous_source == source){
	//	return;
	//}
	
	Rasi ascendant = chartData.getAscendant();
	
	if (ascendant != null){
		
		int bhava = Rasi.ofIndex(housePanel.indexOf(source)).bhava(ascendant);
		
		WindowLabelModel windowModel = new DefaultWindowLabelModel(String.valueOf(bhava));
		
		window = new AstrosoftWindow(windowModel);
		window.setPreferredSize(new Dimension(30,20));
  			Point houseLoc = source.getLocationOnScreen();
  			Point loc = e.getPoint();
              
              loc.translate(houseLoc.x + 10,houseLoc.y - 10);
              window.show(loc);
	}
}
 
Example 6
Source File: InterListMenu.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void mouseEntered (MouseEvent e)
{
    JMenuItem item = (JMenuItem) e.getSource();
    InterAction action = (InterAction) item.getAction();
    action.publish();
}
 
Example 7
Source File: Constraints.java    From iBioSim with Apache License 2.0 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
	if (e.getClickCount() == 2) {
		if (e.getSource() == constraints) {
			if (constraints.getSelectedIndex() == -1) {
				JOptionPane.showMessageDialog(Gui.frame, "No constraint selected.", "Must Select a Constraint", JOptionPane.ERROR_MESSAGE);
				return;
			}
			String selected = ((String) constraints.getSelectedValue()).split("\\[")[0];
			constraintEditor("OK",selected);
		}
	}
}
 
Example 8
Source File: ZoomHandler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
    ChartPanel chartPanel = (ChartPanel) e.getSource();
    Rectangle2D screenDataArea = chartPanel.getScreenDataArea(e.getX(),
            e.getY());
    if (screenDataArea != null) {
        this.zoomPoint = ShapeUtilities.getPointInRectangle(e.getX(),
                e.getY(), screenDataArea);
    }
    else {
        this.zoomPoint = null;
    }
}
 
Example 9
Source File: WComponentPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void handleJavaMouseEvent(MouseEvent e) {
    switch (e.getID()) {
      case MouseEvent.MOUSE_PRESSED:
          // Note that Swing requests focus in its own mouse event handler.
          if (target == e.getSource() &&
              !((Component)target).isFocusOwner() &&
              WKeyboardFocusManagerPeer.shouldFocusOnClick((Component)target))
          {
              WKeyboardFocusManagerPeer.requestFocusFor((Component)target,
                                                        CausedFocusEvent.Cause.MOUSE_EVENT);
          }
          break;
    }
}
 
Example 10
Source File: PDFDefinitionTableController.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Updates active of uncertainties if checkboxes in table are clicked.
 * This method uses currentRow to check which row was clicked, because
 * this listener is added to all checkboxes in active column.
 *
 * This method will not work correctly if table rows are in different order
 * than uncertainties in list in dataModel, but current getValueAt ensures
 * that order is the same.
 */
private void checkBoxActionListener(MouseEvent e) {
	JCheckBox checkBox = (JCheckBox) e.getSource();
	checkBox.setSelected(!checkBox.isSelected());

	if (this.pdfDefinitionTableModel.getCurrentColumn() == PDFDefinitionTableModel.COLUMN_IS_ACTIVE) {
		PDF pdf = this.pdfDefinitionTableModel.getUncertaintiesObject().getPdf(this.pdfDefinitionTableModel.getCurrentRow());
		pdf.getUncertainItem().setActive(checkBox.isSelected());

		//if set to inactive.
		if (!pdf.getUncertainItem().isActive()) {
			//remove autocorrelation for deactivated pdf, if present.

			//get autocorrelation object with same Id as pdf.
			AutoCorrelationFunction autoCorrelationFunction =
				this.pdfDefinitionTableModel.getUncertaintiesObject()
						.getAutoCorrelationFunction(pdf.getUncertainItem().getId());
			//remove autoCorrelationFunction if present.
			if (autoCorrelationFunction != null) {
				this.pdfDefinitionTableModel.getUncertaintiesObject()
						.removeAutoCorrelationFunction(autoCorrelationFunction);
			}
		}

		//update only correlationTable (via parentController and correlationTableController).
        this.parentController.getCorrelationTableController().updateCorrelationTable(this.parentController.getModel());
	}
}
 
Example 11
Source File: NbEditorToolBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void mouseExited(MouseEvent evt) {
    Object src = evt.getSource();
    if (src instanceof AbstractButton)
    {
        AbstractButton button = (AbstractButton)evt.getSource();
        removeButtonContentAreaAndBorder(button);
    }
}
 
Example 12
Source File: JRViewer.java    From nordpos with GNU General Public License v3.0 5 votes vote down vote up
/**
*/
void hyperlinkClicked(MouseEvent evt)
{
	JPanel link = (JPanel)evt.getSource();
	JRPrintHyperlink element = linksMap.get(link);
	hyperlinkClicked(element);
}
 
Example 13
Source File: DecorationUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void mouseMoved(MouseEvent e) {
    check(e);
    Component comp = (Component)e.getSource();
    movedBounds = comp.getBounds(movedBounds);

    cursorType = getCursorType(movedBounds, e.getPoint());
    comp.setCursor(Cursor.getPredefinedCursor(cursorType));
}
 
Example 14
Source File: WindowMouseHandler.java    From littleluck with Apache License 2.0 4 votes vote down vote up
/**
 *  v1.0.1:修复自定义拖拽区域BUG, 增加边界判断
 */
public void mousePressed(MouseEvent e)
{
    Window window = (Window) e.getSource();

    JRootPane root = LuckWindowUtil.getRootPane(window);

    // 不包含窗体装饰直接返回
    if (root == null || root.getWindowDecorationStyle() == JRootPane.NONE)
    {
        return;
    }
    
    if (window != null)
    {
        window.toFront();
    }

    // 如果是单击标题栏, 则标记接下来的拖动事件为移动窗口, 判断当前鼠标是否超出边界
    if (dragArea.contains(e.getPoint())
            && dragCursor == Cursor.DEFAULT_CURSOR)
    {
        if(window instanceof JFrame)
        {
            JFrame frame = (JFrame)window;

            // 如果当前窗体是全屏状态则直接返回
            if(frame.getExtendedState() == JFrame.MAXIMIZED_BOTH)
            {
                return;
            }
        }

        // 设置为可以移动并记录当前坐标
        isMovingWindow = true;

        dragOffsetX = e.getPoint().x;

        dragOffsetY = e.getPoint().y;
    }
    else if(LuckWindowUtil.isResizable(window))
    {
        dragOffsetX = e.getPoint().x;

        dragOffsetY = e.getPoint().y;

        dragWidth = window.getWidth();

        dragHeight = window.getHeight();

        JRootPane rootPane = LuckWindowUtil.getRootPane(window);

        if(rootPane != null && LuckWindowUtil.isResizable(window))
        {
            dragCursor = getCursor(dragWidth, dragHeight, e.getPoint(), rootPane.getInsets());
        }
    }
}
 
Example 15
Source File: XButtonPeer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
void handleJavaMouseEvent(MouseEvent e) {
    super.handleJavaMouseEvent(e);
    int id = e.getID();
    switch (id) {
      case MouseEvent.MOUSE_PRESSED:
          if (XToolkit.isLeftMouseButton(e) ) {
              Button b = (Button) e.getSource();

              if(b.contains(e.getX(), e.getY())) {
                  if (!isEnabled()) {
                      // Disabled buttons ignore all input...
                      return;
                  }
                  pressed = true;
                  armed = true;
                  repaint();
              }
          }

          break;

      case MouseEvent.MOUSE_RELEASED:
          if (XToolkit.isLeftMouseButton(e)) {
              if (armed)
              {
                  action(e.getWhen(),e.getModifiers());
              }
              pressed = false;
              armed = false;
              repaint();
          }

          break;

      case  MouseEvent.MOUSE_ENTERED:
          if (pressed)
              armed = true;
          break;
      case MouseEvent.MOUSE_EXITED:
          armed = false;
          break;
    }
}
 
Example 16
Source File: CanvasMapEditorMouseListener.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void mouseReleased(MouseEvent e) {
    if (getMap() == null
        || e.getButton() == MouseEvent.BUTTON1
        || getGUI().getFocus() == null) return;
    final JComponent component = (JComponent)e.getSource();
    final MapEditorController controller
        = getFreeColClient().getMapEditorController();
    final boolean isTransformActive = controller.getMapTransform() != null;

    endPoint = e.getPoint();
    if (startPoint == null) startPoint = endPoint;
    drawBox(component, startPoint, endPoint);
    Tile start = canvas.convertToMapTile(startPoint.x, startPoint.y);
    Tile end = (startPoint == endPoint) ? start
        : canvas.convertToMapTile(endPoint.x, endPoint.y);

    // edit 2 more conditions in if statement.  we need to
    // check for coordinator of X and Y if (x,y) outside of
    // map then dont focus to that else setfocus to that
    // position no option selected, just center map
    if (!isTransformActive && end.getX() >= 0 && end.getY() >= 0) {
        getGUI().setFocus(end);
        return;
    }

    // find the area to transform
    int min_x, max_x, min_y, max_y;
    if (start.getX() < end.getX()) {
        min_x = start.getX();
        max_x = end.getX();
    } else {
        min_x = end.getX();
        max_x = start.getX();
    }
    if (start.getY() < end.getY()) {
        min_y = start.getY();
        max_y = end.getY();
    } else {
        min_y = end.getY();
        max_y = start.getY();
    }

    // apply transformation to all tiles in the area
    Tile t = null;
    for (int x = min_x; x <= max_x; x++) {
        for (int y = min_y; y <= max_y; y++) {
            t = getMap().getTile(x, y);
            if (t != null) {
                controller.transform(t);
            }
        }
    }
    if (controller.getMapTransform() instanceof TileTypeTransform) {
        for (int x = min_x - 2; x <= max_x + 2; x++) {
            for (int y = min_y - 2; y <= max_y + 2; y++) {
                t = getMap().getTile(x, y);
                if (t != null && t.getType().isWater()) {
                    TerrainGenerator.encodeStyle(t);
                }
            }
        }
    }
    getGUI().refresh();
    canvas.requestFocus();
}
 
Example 17
Source File: SeaGlassRootPaneUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
 */
public void mouseExited(MouseEvent ev) {
    Window w = (Window) ev.getSource();

    w.setCursor(lastCursor);
}
 
Example 18
Source File: HyperlinkCellRenderer.java    From littleluck with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseMoved(MouseEvent event) {
    // This should only be called if underlineOnRollover is true
    JTable table = (JTable) event.getSource();

    // Locate the table cell under the event location
    int oldHitColumnIndex = hitColumnIndex;
    int oldHitRowIndex = hitRowIndex;

    checkIfPointInsideHyperlink(event.getPoint());

    if (hitRowIndex != oldHitRowIndex ||
            hitColumnIndex != oldHitColumnIndex) {
        if (hitRowIndex != -1) {
            if (tableCursor == null) {
                tableCursor = table.getCursor();
            }
            table.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        } else {
            table.setCursor(tableCursor);
        }

        // repaint the cells affected by rollover
        Rectangle repaintRect;
        if (hitRowIndex != -1 && hitColumnIndex != -1) {
            // we need to repaint new cell with rollover underline
            // cellRect already contains rect of hit cell
            if (oldHitRowIndex != -1 && oldHitColumnIndex != -1) {
                // we also need to repaint previously underlined hyperlink cell
                // to remove the underline
                repaintRect = cellRect.union(
                        table.getCellRect(oldHitRowIndex, oldHitColumnIndex, false));
            } else {
                // we don't have a previously underlined hyperlink, so just repaint new one'
                repaintRect = table.getCellRect(hitRowIndex, hitColumnIndex, false);
            }
        } else {
            // we just need to repaint previously underlined hyperlink cell
            //to remove the underline
            repaintRect = table.getCellRect(oldHitRowIndex, oldHitColumnIndex, false);
        }
        table.repaint(repaintRect);
    }

}
 
Example 19
Source File: XButtonPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void handleJavaMouseEvent(MouseEvent e) {
    super.handleJavaMouseEvent(e);
    int id = e.getID();
    switch (id) {
      case MouseEvent.MOUSE_PRESSED:
          if (XToolkit.isLeftMouseButton(e) ) {
              Button b = (Button) e.getSource();

              if(b.contains(e.getX(), e.getY())) {
                  if (!isEnabled()) {
                      // Disabled buttons ignore all input...
                      return;
                  }
                  pressed = true;
                  armed = true;
                  repaint();
              }
          }

          break;

      case MouseEvent.MOUSE_RELEASED:
          if (XToolkit.isLeftMouseButton(e)) {
              if (armed)
              {
                  action(e.getWhen(),e.getModifiers());
              }
              pressed = false;
              armed = false;
              repaint();
          }

          break;

      case  MouseEvent.MOUSE_ENTERED:
          if (pressed)
              armed = true;
          break;
      case MouseEvent.MOUSE_EXITED:
          armed = false;
          break;
    }
}
 
Example 20
Source File: GraphicUtils.java    From xyTalk-pc with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
    * Returns a point where the given popup menu should be shown. The point is
    * calculated by adjusting the X and Y coordinates from the given mouse
    * event so that the popup menu will not be clipped by the screen
    * boundaries.
    * 
    * @param popup
    *            the popup menu
    * @param event
    *            the mouse event
    * @return the point where the popup menu should be shown
    */
   public static Point getPopupMenuShowPoint(JPopupMenu popup, MouseEvent event) {
Component source = (Component) event.getSource();
Point topLeftSource = source.getLocationOnScreen();
Point ptRet = getPopupMenuShowPoint(popup,
	topLeftSource.x + event.getX(), topLeftSource.y + event.getY());
ptRet.translate(-topLeftSource.x, -topLeftSource.y);
return ptRet;
   }