Java Code Examples for java.awt.event.MouseEvent.getXOnScreen()

The following are Jave code examples for showing how to use getXOnScreen() of the java.awt.event.MouseEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Motunautr   File: FixedMouseAdapter.java   View Source Code Vote up 6 votes
@Override
public final void mouseReleased(final MouseEvent e) {
	FixedMouseAdapter.this.mouseReleased(e);
	final int b = e.getButton() - 1;
	if (b >= 0 && b < NUM_BUTTONS
			&& startPoints[b] != null
			&& startPoints[b].distanceSq(e.getLocationOnScreen()) <= CLICK_SENSITIVITY_SQ) {
		
		if (e.getWhen() > lastClickTime[b] + MULTI_CLICK_SENSITIVITY_MS
				|| lastClickPos[b] == null || lastClickPos[b].distanceSq(e.getLocationOnScreen()) > CLICK_SENSITIVITY_SQ)
			clickCounts[b] = 1;
		else
			clickCounts[b]++;
		
		lastClickPos[b] = e.getLocationOnScreen();
		lastClickTime[b] = e.getWhen();
		
		final MouseEvent newEvent = new MouseEvent(e.getComponent(), MouseEvent.MOUSE_CLICKED, e.getWhen(), e.getModifiers(), e.getY(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), clickCounts[b], false, b + 1);
		FixedMouseAdapter.this.mouseClicked(newEvent);
		
		startPoints[b] = null;
	}
}
 
Example 2
Project: litiengine   File: Mouse.java   View Source Code Vote up 5 votes
/**
 * Calculates the location of the ingame mouse by the position diff and locks
 * the original mouse to the center of the screen.
 *
 * @param mouseLocation
 *          The location of the original mouse.
 */
private void setLocation(final MouseEvent e) {
  if (this.grabMouse && !Game.getScreenManager().isFocusOwner()) {
    return;
  }

  double diffX;
  double diffY;
  if (!this.grabMouse) {
    // get diff relative from last mouse location
    diffX = e.getX() - this.lastLocation.getX();
    diffY = e.getY() - this.lastLocation.getY();
    this.lastLocation = new Point(e.getPoint().x - Game.getScreenManager().getRenderComponent().getCursorOffsetX(), e.getPoint().y - Game.getScreenManager().getRenderComponent().getCursorOffsetY());
  } else {
    // get diff relative from grabbed position
    final double screenCenterX = Game.getScreenManager().getResolution().getWidth() * 0.5;
    final double screenCenterY = Game.getScreenManager().getResolution().getHeight() * 0.5;
    final Point screenLocation = Game.getScreenManager().getScreenLocation();
    final int grabX = (int) (screenLocation.x + screenCenterX);
    final int grabY = (int) (screenLocation.y + screenCenterY);

    // lock original mouse back to the center of the screen
    this.robot.mouseMove(grabX, grabY);

    // calculate diffs and new location for the ingame mouse
    diffX = e.getXOnScreen() - (double) grabX;
    diffY = e.getYOnScreen() - (double) grabY;
  }

  // set new mouse location
  double newX = this.getLocation().getX() + diffX * this.sensitivity;
  double newY = this.getLocation().getY() + diffY * this.sensitivity;
  newX = MathUtilities.clamp(newX, 0, Game.getScreenManager().getResolution().getWidth());
  newY = MathUtilities.clamp(newY, 0, Game.getScreenManager().getResolution().getHeight());

  this.location = new Point2D.Double(newX, newY);
}
 
Example 3
Project: rapidminer   File: BubbleWindow.java   View Source Code Vote up 5 votes
@Override
public void mouseDragged(MouseEvent e) {
	int x = startLoc.x;
	int y = startLoc.y;
	int xOffset = e.getXOnScreen() - x;
	int yOffset = e.getYOnScreen() - y;

	Point newLoc = new Point(lastLoc.x + xOffset, lastLoc.y + yOffset);
	comp.setLocation(newLoc);
}
 
Example 4
Project: hearthstone   File: PartidaView.java   View Source Code Vote up 5 votes
/**
 * Captura o nome do componente onde o clique do mouse foi solto
 *
 * @param evt MouseEvent
 */
private void jPanelJanelaMouseReleased(MouseEvent evt) {//GEN-FIRST:event_jPanelJanelaMouseReleased
    mouseIsDown = false;
    DRAG_AND_DROP.setVisible(false);
    Component c = jPanelJanela.findComponentAt(evt.getPoint());
    if (ESPERANDO_ALVO) {
        capturarAlvoGritoDeGuerra(c, evt);
    } else if (PARTIDA.isVezHeroi()) {
        lado = evt.getXOnScreen() < (tela.width / 2) ? Values.LEFT : Values.RIGHT;
        setReleased(c);
    }
    revalidate();
}
 
Example 5
Project: litiengine   File: Mouse.java   View Source Code Vote up 4 votes
private MouseEvent createEvent(final MouseEvent original) {
  return new MouseEvent(original.getComponent(), original.getID(), original.getWhen(), original.getModifiers(), (int) this.getLocation().getX(), (int) this.getLocation().getY(), original.getXOnScreen(), original.getYOnScreen(), original.getClickCount(), original.isPopupTrigger(),
      original.getButton());
}
 
Example 6
Project: incubator-netbeans   File: Outline.java   View Source Code Vote up 4 votes
@Override
public String getToolTipText(MouseEvent event) {
    try {
        // Required to really get the tooltip text:
        putClientProperty("ComputingTooltip", Boolean.TRUE);

        toolTip = null;
        String tipText = null;
        Point p = event.getPoint();

        // Locate the renderer under the event location
        int hitColumnIndex = columnAtPoint(p);
        int hitRowIndex = rowAtPoint(p);

        if ((hitColumnIndex != -1) && (hitRowIndex != -1)) {
            //Outline tbl = (Outline) table;
            if (convertColumnIndexToModel(hitColumnIndex) == 0) {   // tree column index
                // For tree column get the tooltip directly from the renderer data provider
                RenderDataProvider rendata = getRenderDataProvider();
                if (rendata != null) {
                    Object value = getValueAt(hitRowIndex, hitColumnIndex);
                    if (value != null) {
                        String toolT = rendata.getTooltipText(value);
                        if (toolT != null && (toolT = toolT.trim ()).length () > 0) {
                            tipText = toolT;
                        }
                    }
                }
            }

            TableCellRenderer renderer = getCellRenderer(hitRowIndex, hitColumnIndex);
            Component component = prepareRenderer(renderer, hitRowIndex, hitColumnIndex);

            // Now have to see if the component is a JComponent before
            // getting the tip
            if (component instanceof JComponent) {
                // Convert the event to the renderer's coordinate system
                Rectangle cellRect = getCellRect(hitRowIndex, hitColumnIndex, false);
                p.translate(-cellRect.x, -cellRect.y);
                MouseEvent newEvent = new MouseEvent(component, event.getID(),
                                          event.getWhen(), event.getModifiers(),
                                          p.x, p.y,
                                          event.getXOnScreen(),
                                          event.getYOnScreen(),
                                          event.getClickCount(),
                                          event.isPopupTrigger(),
                                          MouseEvent.NOBUTTON);

                if (tipText == null) {
                    tipText = ((JComponent)component).getToolTipText(newEvent);
                }
                toolTip = ((JComponent)component).createToolTip();
            }
        }

        // No tip from the renderer get our own tip
        if (tipText == null)
            tipText = getToolTipText();

        if (tipText != null) {
            tipText = tipText.trim();
            if (tipText.length() > MAX_TOOLTIP_LENGTH &&
                !tipText.regionMatches(false, 0, "<html>", 0, 6)) {   // Do not cut HTML tooltips

                tipText = tipText.substring(0, MAX_TOOLTIP_LENGTH) + "...";
            }
        }
        return tipText;
    } finally {
        putClientProperty("ComputingTooltip", Boolean.FALSE);
    }
    //return super.getToolTipText(event);
}
 
Example 7
Project: incubator-netbeans   File: ProfilerPopup.java   View Source Code Vote up 4 votes
public void mousePressed(MouseEvent e) {
    dragging = true;
    dragX = e.getXOnScreen();
    dragY = e.getYOnScreen();
}
 
Example 8
Project: incubator-netbeans   File: ProfilerPopup.java   View Source Code Vote up 4 votes
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 9
Project: Weather-Forecast   File: MainWeatherFrame.java   View Source Code Vote up 4 votes
private void formMouseDragged(MouseEvent evt) {                                  
    int x = evt.getXOnScreen();
    int y = evt.getYOnScreen();

    this.setLocation(x - xMouse, y - yMouse);
}