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

The following examples show how to use java.awt.event.MouseEvent#getYOnScreen() . These examples are extracted from open source projects. 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 Project: java-swing-tips   File: MainPanel.java    License: MIT License 6 votes vote down vote up
@Override protected TrackListener createTrackListener() {
  return new TrackListener() {
    @Override public void mousePressed(MouseEvent e) {
      if (SwingUtilities.isLeftMouseButton(e)) {
        super.mousePressed(new MouseEvent(
            e.getComponent(), e.getID(), e.getWhen(),
            InputEvent.BUTTON2_DOWN_MASK ^ InputEvent.BUTTON2_MASK, // e.getModifiers(),
            e.getX(), e.getY(),
            e.getXOnScreen(), e.getYOnScreen(),
            e.getClickCount(),
            e.isPopupTrigger(),
            MouseEvent.BUTTON2));
      } else {
        super.mousePressed(e);
      }
    }
  };
}
 
Example 2
Source Project: java-swing-tips   File: MainPanel.java    License: MIT License 6 votes vote down vote up
@Override protected TrackListener createTrackListener() {
  return new TrackListener() {
    @Override public void mousePressed(MouseEvent e) {
      if (SwingUtilities.isLeftMouseButton(e)) {
        super.mousePressed(new MouseEvent(
            e.getComponent(), e.getID(), e.getWhen(),
            InputEvent.BUTTON2_DOWN_MASK ^ InputEvent.BUTTON2_MASK,
            e.getX(), e.getY(),
            e.getXOnScreen(), e.getYOnScreen(),
            e.getClickCount(),
            e.isPopupTrigger(),
            MouseEvent.BUTTON2));
      } else {
        super.mousePressed(e);
      }
    }
  };
}
 
Example 3
Source Project: FlatLaf   File: FlatWindowResizer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mousePressed( MouseEvent e ) {
	if( window == null )
		return;

	dragStartMouseX = e.getXOnScreen();
	dragStartMouseY = e.getYOnScreen();
	dragStartWindowBounds = window.getBounds();
}
 
Example 4
Source Project: arcusplatform   File: CapabilityTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {
   super.mouseReleased(e);

   int rowindex = table.rowAtPoint(e.getPoint());

   if (rowindex < 0)
      return;

   if (SwingUtilities.isRightMouseButton(e) && e.getComponent() instanceof JTable) {
      Point point = new Point(e.getXOnScreen(), e.getYOnScreen() - CapabilityTable.this.getHeight());
      copy(rowindex, point);
   }
}
 
Example 5
@Override
public void mouseReleased (MouseEvent e)
{
    ScreenPoint screenPoint = new ScreenPoint(
            e.getXOnScreen(),
            e.getYOnScreen());

    glassPane.setVisible(false);
    glassPane.setImage(null);

    fireDropEvent(new GhostDropEvent<>(action, screenPoint));
}
 
Example 6
@Override
public void mousePressed (MouseEvent e)
{
    glassPane.setVisible(true);

    ScreenPoint screenPoint = new ScreenPoint(
            e.getXOnScreen(),
            e.getYOnScreen());

    glassPane.setImage(image);
    glassPane.setPoint(screenPoint);
}
 
Example 7
@Override
public void mouseDragged(MouseEvent e) {
  if (mIsDragging) {
    final int deltaY = e.getYOnScreen() - mOriginalScreenY;
    mPanel.setLocation(mPanel.getX(), mOriginalY + deltaY);
  }
}
 
Example 8
@Override
public void mousePressed (MouseEvent e)
{
    glassPane.setVisible(true);

    ScreenPoint screenPoint = new ScreenPoint(e.getXOnScreen(), e.getYOnScreen());

    glassPane.setImage(image);
    glassPane.setPoint(screenPoint);
}
 
Example 9
@Override
public void mouseReleased (MouseEvent e)
{
    ScreenPoint screenPoint = new ScreenPoint(e.getXOnScreen(), e.getYOnScreen());

    glassPane.setVisible(false);
    glassPane.setImage(null);

    fireDropEvent(new GhostDropEvent<>(action, screenPoint));
}
 
Example 10
Source Project: xnx3   File: UI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 显示鼠标跟随的信息提示,配合{@link UI#hiddenMessageForMouse()} 使用
 * @param mouseEvent 添加鼠标监听后,传入鼠标的监听对象 java.awt.event.MouseEvent
 * @param width 显示的提示框宽度
 * @param height 显示的提示框高度
 * @param html 显示的文字,支持html格式
 * @return 显示文字的组件JLabel,可对此组件进行调整
 * @see UI#showMessageForMouse(int, int, int, int, String)
 */
public static JLabel showMessageForMouse(MouseEvent mouseEvent,int width,int height,String html){
	int x=0;
	int y=0;
	if(mouseEvent!=null){
		x=mouseEvent.getXOnScreen();
		y=mouseEvent.getYOnScreen();
	}
	
	return showMessageForMouse(x, y, width, height, html);
}
 
Example 11
Source Project: java-swing-tips   File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override protected void processMouseMotionEvent(MouseEvent e) {
  if (pointOutsidePrefSize(e.getPoint())) {
    MouseEvent ev = new MouseEvent(
        e.getComponent(), MouseEvent.MOUSE_EXITED, e.getWhen(),
        e.getModifiersEx(), e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(),
        e.getClickCount(), e.isPopupTrigger(), MouseEvent.NOBUTTON);
    super.processMouseEvent(ev);
  } else {
    super.processMouseMotionEvent(e);
  }
}
 
Example 12
Source Project: binnavi   File: CHelpManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a point that describes the upper left corner of the dialog
 * to show. The function makes sure that the point is chosen so that
 * the whole dialog is visible.
 *
 * @param event The mouse event that contains the click information.
 *
 * @return The normalized coordinates of the dialog.
 */
private Point getDialogLocation(final MouseEvent event)
{
	// Get the default toolkit
	final Toolkit toolkit = Toolkit.getDefaultToolkit();

	// Get the current screen size
	final Dimension scrnsize = toolkit.getScreenSize();

	final int x = event.getXOnScreen(); 
	final int y = event.getYOnScreen(); 

	return new Point(normalize(x, m_helpDialog.getWidth(), scrnsize.width), normalize(y, m_helpDialog.getHeight(), scrnsize.height));
}
 
Example 13
Source Project: FlatLaf   File: FlatTitlePane.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void mousePressed( MouseEvent e ) {
	lastXOnScreen = e.getXOnScreen();
	lastYOnScreen = e.getYOnScreen();
}
 
Example 14
Source Project: FlatLaf   File: FlatWindowResizer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void mouseDragged( MouseEvent e ) {
	if( dragStartWindowBounds == null )
		return;

	if( !isWindowResizable() )
		return;

	int mouseDeltaX = e.getXOnScreen() - dragStartMouseX;
	int mouseDeltaY = e.getYOnScreen() - dragStartMouseY;

	int deltaX = 0;
          int deltaY = 0;
          int deltaWidth = 0;
          int deltaHeight = 0;

	// north
	if( resizeDir == N_RESIZE_CURSOR || resizeDir == NW_RESIZE_CURSOR || resizeDir == NE_RESIZE_CURSOR ) {
		deltaY = mouseDeltaY;
		deltaHeight = -mouseDeltaY;
	}

	// south
	if( resizeDir == S_RESIZE_CURSOR || resizeDir == SW_RESIZE_CURSOR || resizeDir == SE_RESIZE_CURSOR )
		deltaHeight = mouseDeltaY;

	// west
	if( resizeDir == W_RESIZE_CURSOR || resizeDir == NW_RESIZE_CURSOR || resizeDir == SW_RESIZE_CURSOR ) {
		deltaX = mouseDeltaX;
		deltaWidth = -mouseDeltaX;
	}

	// east
	if( resizeDir == E_RESIZE_CURSOR || resizeDir == NE_RESIZE_CURSOR || resizeDir == SE_RESIZE_CURSOR )
		deltaWidth = mouseDeltaX;

	// compute new window bounds
	Rectangle newBounds = new Rectangle( dragStartWindowBounds );
	newBounds.x += deltaX;
	newBounds.y += deltaY;
	newBounds.width += deltaWidth;
	newBounds.height += deltaHeight;

	// apply minimum window size
	Dimension minimumSize = honorMinimumSizeOnResize ? window.getMinimumSize() : null;
	if( minimumSize == null )
		minimumSize = UIScale.scale( new Dimension( 150, 50 ) );
	if( newBounds.width < minimumSize.width ) {
		if( deltaX != 0 )
			newBounds.x -= (minimumSize.width - newBounds.width);
		newBounds.width = minimumSize.width;
	}
	if( newBounds.height < minimumSize.height ) {
		if( deltaY != 0 )
			newBounds.y -= (minimumSize.height - newBounds.height);
		newBounds.height = minimumSize.height;
	}

	// set window bounds
	if( !newBounds.equals( dragStartWindowBounds ) ) {
		window.setBounds( newBounds );

		// immediately layout drag border components
		FlatWindowResizer.this.setBounds( 0, 0, newBounds.width, newBounds.height );
		FlatWindowResizer.this.validate();

		if( Toolkit.getDefaultToolkit().isDynamicLayoutActive() ) {
			window.validate();
			rootPane.repaint();
		}
	}
}
 
Example 15
Source Project: weblaf   File: WebTree.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Unlike {@link JTree#getToolTipText()} this implementation takes row selection style into account.
 * That means that tooltips for {@link TreeSelectionStyle#line} will be displayed at any point in the row, not just on the node.
 *
 * @param event {@link MouseEvent}
 * @return tooltip text
 */
@Nullable
@Override
public String getToolTipText ( @Nullable final MouseEvent event )
{
    String tip = null;
    if ( event != null )
    {
        final Point point = event.getPoint ();
        final WTreeUI ui = getUI ();
        final int row = ui.getExactRowForLocation ( point );
        final TreeCellRenderer cellRenderer = getCellRenderer ();
        if ( row != -1 && cellRenderer != null )
        {
            final TreePath path = getPathForRow ( row );
            final Object value = path.getLastPathComponent ();
            final boolean selected = isRowSelected ( row );
            final boolean expanded = isExpanded ( row );
            final boolean leaf = isLeaf ( ( N ) value );
            final Component renderer = cellRenderer.getTreeCellRendererComponent ( this, value, selected, expanded, leaf, row, true );
            if ( renderer instanceof JComponent )
            {
                final Rectangle pathBounds = getPathBounds ( path );
                if ( pathBounds != null )
                {
                    final MouseEvent newEvent = new MouseEvent ( renderer, event.getID (),
                            event.getWhen (),
                            event.getModifiers (),
                            point.x - pathBounds.x,
                            point.y - pathBounds.y,
                            event.getXOnScreen (),
                            event.getYOnScreen (),
                            event.getClickCount (),
                            event.isPopupTrigger (),
                            MouseEvent.NOBUTTON );

                    final JComponent jComponent = ( JComponent ) renderer;
                    tip = jComponent.getToolTipText ( newEvent );
                }
            }
        }
    }
    if ( tip == null )
    {
        tip = getToolTipText ();
    }
    return tip;
}
 
Example 16
Source Project: MobyDroid   File: JFrame_Main.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent me) {
    // dragging
    if (dragging) {
        int x = me.getXOnScreen();
        int y = me.getYOnScreen();
        // Move frame by the mouse delta
        setLocation(getLocationOnScreen().x + x - prevX, getLocationOnScreen().y + y - prevY);
        prevX = x;
        prevY = y;
    }
    // resizing
    if (resizing) {
        Component component = me.getComponent();
        Rectangle rect = prevR;
        int xInc = me.getXOnScreen() - prevX;
        int yInc = me.getYOnScreen() - prevY;

        //  Resizing the West or North border affects the size and location
        switch (outcode) {
            case Rectangle.OUT_TOP:
                rect.y += yInc;
                rect.height -= yInc;
                break;
            case Rectangle.OUT_TOP + Rectangle.OUT_LEFT:
                rect.y += yInc;
                rect.height -= yInc;
                rect.x += xInc;
                rect.width -= xInc;
                break;
            case Rectangle.OUT_LEFT:
                rect.x += xInc;
                rect.width -= xInc;
                break;
            case Rectangle.OUT_LEFT + Rectangle.OUT_BOTTOM:
                rect.height += yInc;
                rect.x += xInc;
                rect.width -= xInc;
                break;
            case Rectangle.OUT_BOTTOM:
                rect.height += yInc;
                break;
            case Rectangle.OUT_BOTTOM + Rectangle.OUT_RIGHT:
                rect.height += yInc;
                rect.width += xInc;
                break;
            case Rectangle.OUT_RIGHT:
                rect.width += xInc;
                break;
            case Rectangle.OUT_RIGHT + Rectangle.OUT_TOP:
                rect.y += yInc;
                rect.height -= yInc;
                rect.width += xInc;
                break;
            default:
                break;
        }

        prevX = me.getXOnScreen();
        prevY = me.getYOnScreen();

        component.setBounds(rect);
        component.validate();
        component.repaint();
    }
}
 
Example 17
Source Project: netbeans   File: ProfilerPopup.java    License: Apache License 2.0 4 votes vote down vote up
public void mouseDragged(MouseEvent e) {
    if (dragX >= 0 && dragY >= 0) {
        int x = e.getXOnScreen();
        int y = e.getYOnScreen();
        
        int dx = x - dragX;
        int dy = y - dragY;
        
        int newX = window.getX();
        int newY = window.getY();
        int newW = window.getWidth();
        int newH = window.getHeight();
        
        int xx = 0;
        int yy = 0;
        Dimension min = window.getMinimumSize();
        
        if (isResizeLeft(currentResizing)) {
            newX += dx;
            newW -= dx;
            if (newW < min.width) {
                xx = newW - min.width;
                newX += xx;
                newW = min.width;
            }
        } else if (isResizeRight(currentResizing)) {
            newW += dx;
            if (newW < min.width) {
                xx = min.width - newW;
                newW = min.width;
            }
        }
        if (isResizeTop(currentResizing)) {
            newY += dy;
            newH -= dy;
            if (newH < min.height) {
                yy = newH - min.height;
                newY += yy;
                newH = min.height;
            }
        } else if (isResizeBottom(currentResizing)) {
            newH += dy;
            if (newH < min.height) {
                yy = min.height - newH;
                newH = min.height;
            }
        }
        
        window.setBounds(newX, newY, newW, newH);
        content.setSize(newW, newH);
        
        dragX = x + xx;
        dragY = y + yy;
    }
}
 
Example 18
/**
 * In this specific implementation, we update the size of the
 * shape image according to the interline scale and to the
 * display zoom of the droppable target underneath.
 *
 * @param e the mouse event
 */
@Override
public void mouseDragged (MouseEvent e)
{
    final ShapeButton button = (ShapeButton) e.getSource();
    final Shape shape = button.shape;
    final ScreenPoint screenPoint = new ScreenPoint(e.getXOnScreen(), e.getYOnScreen());
    final OmrGlassPane glass = (OmrGlassPane) glassPane;

    // The (zoomed) sheet view
    ScrollView scrollView = sheet.getStub().getAssembly().getSelectedView();
    Component component = scrollView.getComponent().getViewport();

    if (screenPoint.isInComponent(component)) {
        final RubberPanel view = scrollView.getView();
        final Zoom zoom = view.getZoom();
        final Point localPt = zoom.unscaled(screenPoint.getLocalPoint(view));
        glass.setOverTarget(true);

        // Moving into this component?
        if (component != prevComponent.get()) {
            if (shape.isDraggable()) {
                if (dndOperation == null) {
                    // Set payload
                    dndOperation = new DndOperation(
                            sheet,
                            zoom,
                            InterFactory.createManual(shape, sheet));
                }

                dndOperation.enteringTarget();
            } else {
                glass.setImage(getNonDraggableImage(zoom));
                glass.setReference(null);
            }

            prevComponent = new WeakReference<>(component);
        }

        if (shape.isDraggable()) {
            // Update reference point
            Point localRef = dndOperation.getReference(localPt);
            glass.setReference(
                    (localRef != null) ? new ScreenPoint(view, zoom.scaled(localRef))
                            : null);
        }
    } else if (prevComponent.get() != null) {
        // No longer on a droppable target, reuse initial image & size
        glass.setOverTarget(false);
        glass.setImage(dropAdapter.getImage());
        glass.setReference(null);
        reset();
    }

    glass.setPoint(screenPoint); // This triggers a repaint of glassPane
}
 
Example 19
public void mousePressed(MouseEvent e) {
    dragging = true;
    dragX = e.getXOnScreen();
    dragY = e.getYOnScreen();
}
 
Example 20
public void mouseDragged(MouseEvent e) {
    if (dragX >= 0 && dragY >= 0) {
        int x = e.getXOnScreen();
        int y = e.getYOnScreen();
        
        int dx = x - dragX;
        int dy = y - dragY;
        
        int newX = window.getX();
        int newY = window.getY();
        int newW = window.getWidth();
        int newH = window.getHeight();
        
        int xx = 0;
        int yy = 0;
        Dimension min = window.getMinimumSize();
        
        if (isResizeLeft(currentResizing)) {
            newX += dx;
            newW -= dx;
            if (newW < min.width) {
                xx = newW - min.width;
                newX += xx;
                newW = min.width;
            }
        } else if (isResizeRight(currentResizing)) {
            newW += dx;
            if (newW < min.width) {
                xx = min.width - newW;
                newW = min.width;
            }
        }
        if (isResizeTop(currentResizing)) {
            newY += dy;
            newH -= dy;
            if (newH < min.height) {
                yy = newH - min.height;
                newY += yy;
                newH = min.height;
            }
        } else if (isResizeBottom(currentResizing)) {
            newH += dy;
            if (newH < min.height) {
                yy = min.height - newH;
                newH = min.height;
            }
        }
        
        window.setBounds(newX, newY, newW, newH);
        content.setSize(newW, newH);
        
        dragX = x + xx;
        dragY = y + yy;
    }
}