java.awt.event.MouseEvent#translatePoint()源码实例Demo

下面列出了java.awt.event.MouseEvent#translatePoint() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jclic   文件: JPanelActiveBox.java
@Override
protected void processEvent(AWTEvent e) {
  if (catchMouseEvents && e instanceof MouseEvent) {
    MouseEvent me = (MouseEvent) e;
    if (e.getID() == MouseEvent.MOUSE_PRESSED && ab != null && ps != null
        && (parentActivityPanel == null || parentActivityPanel.isPlaying())) {
      ps.stopMedia(1);
      ab.playMedia(ps);
    }
    if (mouseListener != null && (ab == null || ab.getContent().mediaContent == null
        || ab.getContent().mediaContent.catchMouseEvents == false)) {
      Point bkPt = me.getPoint();
      Point pt = Utils.mapPointTo(this, bkPt, mouseListener);
      me.translatePoint(pt.x - bkPt.x, pt.y - bkPt.y);
      mouseListener.dispatchEvent(e);
    }
    me.consume();
    return;
  }
  super.processEvent(e);
}
 
源代码2 项目: gate-core   文件: JTreeTable.java
protected MouseEvent convertEvent(MouseEvent e){
  int column = 0;
  int row = rowAtPoint(e.getPoint());

  //move the event from table to tree coordinates
  Rectangle tableCellRect = getCellRect(row, column, false);
  Rectangle treeCellRect = tree.getRowBounds(row);
  int dx = 0;
  if(tableCellRect != null) dx = -tableCellRect.x;
  int dy = 0;
  if(tableCellRect !=null && treeCellRect != null)
    dy = treeCellRect.y -tableCellRect.y;
  e.translatePoint(dx, dy);


  return new MouseEvent(
    tree, e.getID(), e.getWhen(), e.getModifiers(),
    e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger()
  );
}
 
源代码3 项目: Pixelitor   文件: DragReorderHandler.java
/**
 * Returns the layer button for the mouse event and also translate
 * the coordinates of the argument into the layer button space
 */
private static LayerButton getLayerButtonFromEvent(MouseEvent e) {
    LayerButton layerButton;
    Component c = e.getComponent();
    // the source of the event must be either the layer button
    // or the textfield inside it
    if (c instanceof LayerNameEditor) {
        LayerNameEditor nameEditor = (LayerNameEditor) c;
        layerButton = nameEditor.getLayerButton();
        // translate into the LayerButton coordinate system
        e.translatePoint(nameEditor.getX(), nameEditor.getY());
    } else if (c instanceof JLabel) {
        layerButton = (LayerButton) c.getParent();
        e.translatePoint(c.getX(), c.getY());
    } else {
        layerButton = (LayerButton) c;
    }
    return layerButton;
}
 
源代码4 项目: pcgen   文件: JTreeTable.java
/**
 * Overridden to return false, and if the event is a mouse event
 * it is forwarded to the tree.<p>
 * The behavior for this is debatable, and should really be offered
 * as a property. By returning false, all keyboard actions are
 * implemented in terms of the table. By returning true, the
 * tree would get a chance to do something with the keyboard
 * events. For the most part this is ok. But for certain keys,
 * such as left/right, the tree will expand/collapse where as
 * the table focus should really move to a different column. Page
 * up/down should also be implemented in terms of the table.
 * By returning false this also has the added benefit that clicking
 * outside of the bounds of the tree node, but still in the tree
 * column will select the row, whereas if this returned true
 * that wouldn't be the case.
 * <p>By returning false we are also enforcing the policy that
 * the tree will never be editable (at least by a key sequence).
 * @param e
 * @return true if cell editable
 */
@Override
public boolean isCellEditable(EventObject e)
{
	if (e instanceof MouseEvent)
	{
		for (int counter = getColumnCount() - 1; counter >= 0; counter--)
		{
			if (getColumnClass(counter) == TreeTableNode.class)
			{
				MouseEvent me = (MouseEvent) e;
				int column = JTreeTable.this.columnAtPoint(me.getPoint());
				Rectangle cell = JTreeTable.this.getCellRect(0, column, true);
				MouseEvent newME = new MouseEvent(tree, me.getID(), me.getWhen(), me.getModifiers(), me.getX(),
					me.getY(), me.getClickCount(), me.isPopupTrigger());
				//we translate the event into the tree's coordinate system
				newME.translatePoint(-cell.x, 0);
				tree.dispatchEvent(newME);

				break;
			}
		}
	}

	return false;
}
 
源代码5 项目: java-swing-tips   文件: MainPanel.java
@Override protected TrackListener createTrackListener(JSlider slider) {
  return new TrackListener() {
    @Override public void mouseDragged(MouseEvent e) {
      // case HORIZONTAL:
      int halfThumbWidth = thumbRect.width / 2;
      int thumbLeft = e.getX() - offset;
      int maxPos = xPositionForValue(MAXI) - halfThumbWidth;
      int minPos = xPositionForValue(MINI) - halfThumbWidth;
      if (thumbLeft > maxPos) {
        e.translatePoint(maxPos + offset - e.getX(), 0);
      } else if (thumbLeft < minPos) {
        e.translatePoint(minPos + offset - e.getX(), 0);
      }
      super.mouseDragged(e);
    }
  };
}
 
源代码6 项目: pcgen   文件: JTreeTable.java
/**
 * Overridden to return false, and if the event is a mouse event
 * it is forwarded to the tree.<p>
 * The behavior for this is debatable, and should really be offered
 * as a property. By returning false, all keyboard actions are
 * implemented in terms of the table. By returning true, the
 * tree would get a chance to do something with the keyboard
 * events. For the most part this is ok. But for certain keys,
 * such as left/right, the tree will expand/collapse where as
 * the table focus should really move to a different column. Page
 * up/down should also be implemented in terms of the table.
 * By returning false this also has the added benefit that clicking
 * outside of the bounds of the tree node, but still in the tree
 * column will select the row, whereas if this returned true
 * that wouldn't be the case.
 * <p>By returning false we are also enforcing the policy that
 * the tree will never be editable (at least by a key sequence).
 * @param e
 * @return true if cell editable
 */
@Override
public boolean isCellEditable(EventObject e)
{
	if (e instanceof MouseEvent)
	{
		for (int counter = getColumnCount() - 1; counter >= 0; counter--)
		{
			if (getColumnClass(counter) == TreeTableNode.class)
			{
				MouseEvent me = (MouseEvent) e;
				int column = JTreeTable.this.columnAtPoint(me.getPoint());
				Rectangle cell = JTreeTable.this.getCellRect(0, column, true);
				MouseEvent newME = new MouseEvent(tree, me.getID(), me.getWhen(), me.getModifiers(), me.getX(),
					me.getY(), me.getClickCount(), me.isPopupTrigger());
				//we translate the event into the tree's coordinate system
				newME.translatePoint(-cell.x, 0);
				tree.dispatchEvent(newME);

				break;
			}
		}
	}

	return false;
}
 
源代码7 项目: CrossMobile   文件: SwingNativeDispatcher.java
@Override
    public void sendTouchEvents(MouseEvent originalEvent, NativeTouch[] touches) {
        System.out.println("original event dispatching");
        if (originalEvent != null) {
            DesktopNativeWidget component = getWidgetWrapper().getNativeWidget();
            originalEvent.setSource(component);
            originalEvent.translatePoint((int) (touches[0].x) - originalEvent.getX(), (int) (touches[0].y) - originalEvent.getY());
//            component.dispatchEvent(originalEvent);
        }
    }
 
源代码8 项目: Logisim   文件: Canvas.java
public static void snapToGrid(MouseEvent e) {
	int old_x = e.getX();
	int old_y = e.getY();
	int new_x = snapXToGrid(old_x);
	int new_y = snapYToGrid(old_y);
	e.translatePoint(new_x - old_x, new_y - old_y);
}
 
源代码9 项目: Logisim   文件: Canvas.java
private void zoomEvent(MouseEvent e, double zoom) {
	int oldx = e.getX();
	int oldy = e.getY();
	int newx = (int) Math.round(e.getX() / zoom);
	int newy = (int) Math.round(e.getY() / zoom);
	e.translatePoint(newx - oldx, newy - oldy);
}
 
源代码10 项目: Logisim   文件: AppearanceCanvas.java
private void repairEvent(MouseEvent e, double zoom) {
	if (zoom != 1.0) {
		int oldx = e.getX();
		int oldy = e.getY();
		int newx = (int) Math.round(e.getX() / zoom);
		int newy = (int) Math.round(e.getY() / zoom);
		e.translatePoint(newx - oldx, newy - oldy);
	}
}
 
源代码11 项目: MercuryTrade   文件: AbstractAdrComponentFrame.java
@Override
public void mouseDragged(MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e)) {
        e.translatePoint(AbstractAdrComponentFrame.this.getLocation().x - x, AbstractAdrComponentFrame.this.getLocation().y - y);
        Point point = e.getPoint();
        AbstractAdrComponentFrame.this.setLocation(point);
    }
}
 
源代码12 项目: MercuryTrade   文件: AdrCaptureOutComponentFrame.java
@Override
public void mouseDragged(MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e)) {
        e.translatePoint(AdrCaptureOutComponentFrame.this.getLocation().x - x, AdrCaptureOutComponentFrame.this.getLocation().y - y);
        Point point = e.getPoint();
        AdrCaptureOutComponentFrame.this.setLocation(point);
    }
}
 
源代码13 项目: Pixelitor   文件: MultiThumbSliderUI.java
@Override
public void mouseDragged(MouseEvent e) {
    if (!slider.isEnabled()) {
        return;
    }

    e.translatePoint(dx, dy);

    mouseMoved(e);
    if (pressedState != null && pressedState.selectedThumb != -1) {
        slider.setValueIsAdjusting(true);

        State newState = new State(pressedState);
        float v;
        boolean outside;
        if (slider.getOrientation() == MultiThumbSlider.HORIZONTAL) {
            v = ((float) (e.getX() - trackRect.x)) / ((float) trackRect.width);
            if (slider.isInverted()) {
                v = 1 - v;
            }
            outside = (e.getY() < trackRect.y - 10) || (e.getY() > trackRect.y + trackRect.height + 10);

            //don't whack the thumb off the slider if you happen to be *near* the edge:
            if (e.getX() > trackRect.x - 10 && e.getX() < trackRect.x + trackRect.width + 10) {
                if (v < 0) {
                    v = 0;
                }
                if (v > 1) {
                    v = 1;
                }
            }
        } else {
            v = ((float) (e.getY() - trackRect.y)) / ((float) trackRect.height);
            if (!slider.isInverted()) {
                v = 1 - v;
            }
            outside = (e.getX() < trackRect.x - 10) || (e.getX() > trackRect.x + trackRect.width + 10);

            if (e.getY() > trackRect.y - 10 && e.getY() < trackRect.y + trackRect.height + 10) {
                if (v < 0) {
                    v = 0;
                }
                if (v > 1) {
                    v = 1;
                }
            }
        }
        if (newState.positions.length <= 2) {
            outside = false; //I don't care if you are outside: no removing!
        }
        newState.positions[newState.selectedThumb] = v;

        //because we delegate mouseReleased() to this method:
        if (outside) {
            newState.removeThumb(newState.selectedThumb);
        }
        if (validatePositions(newState)) {
            newState.install();
        }
        e.consume();
    }
}
 
源代码14 项目: netbeans   文件: SplittedPanel.java
/** A method implemented from the MouseMotionListener interface to handle the splitter dragging */
public void mouseDragged(MouseEvent e) {
    if (continuousLayout == true) {
        Dimension d = getSize();
        Point splitterPos = splitter.getLocation();
        e.translatePoint(splitterPos.x, splitterPos.y);

        if (splitType == VERTICAL) {
            dragPos = e.getY();

            if (dragPos > d.height) {
                dragPos = d.height;
            }
        } else {
            dragPos = e.getX();

            if (dragPos > d.width) {
                dragPos = d.width;
            }
        }

        if (dragPos < 0) {
            dragPos = 0;
        }

        if (continuousLayout) {
            if (dragPos == -1) {
                return;
            }

            int newDragPos = dragPos;

            if (!absolute) {
                if (splitType == VERTICAL) {
                    newDragPos = (100 * dragPos) / d.height;
                } else {
                    newDragPos = (100 * dragPos) / d.width;
                }
            }

            setSplitPosition(newDragPos);
        }
    }
}
 
源代码15 项目: pumpernickel   文件: MultiThumbSliderUI.java
public void mouseDragged(MouseEvent e) {
	if (slider.isEnabled() == false)
		return;

	e.translatePoint(dx, dy);

	mouseMoved(e);
	if (pressedState != null && pressedState.selectedThumb != -1) {
		slider.setValueIsAdjusting(true);

		State newState = new State(pressedState);
		float v;
		boolean outside;
		if (slider.getOrientation() == MultiThumbSlider.HORIZONTAL) {
			v = ((float) (e.getX() - trackRect.x))
					/ ((float) trackRect.width);
			if (slider.isInverted())
				v = 1 - v;
			outside = (e.getY() < trackRect.y - 10)
					|| (e.getY() > trackRect.y + trackRect.height + 10);

			// don't whack the thumb off the slider if you happen to be
			// *near* the edge:
			if (e.getX() > trackRect.x - 10
					&& e.getX() < trackRect.x + trackRect.width + 10) {
				if (v < 0)
					v = 0;
				if (v > 1)
					v = 1;
			}
		} else {
			v = ((float) (e.getY() - trackRect.y))
					/ ((float) trackRect.height);
			if (slider.isInverted() == false)
				v = 1 - v;
			outside = (e.getX() < trackRect.x - 10)
					|| (e.getX() > trackRect.x + trackRect.width + 10);

			if (e.getY() > trackRect.y - 10
					&& e.getY() < trackRect.y + trackRect.height + 10) {
				if (v < 0)
					v = 0;
				if (v > 1)
					v = 1;
			}
		}
		if (newState.positions.length <= slider.getMinimumThumbnailCount()) {
			outside = false; // I don't care if you are outside: no
								// removing!
		}
		newState.setPosition(newState.selectedThumb, v);

		// because we delegate mouseReleased() to this method:
		if (outside && slider.isThumbRemovalAllowed()) {
			newState.removeThumb(newState.selectedThumb);
		}
		if (validatePositions(newState)) {
			newState.install();
		}
		e.consume();
	}
}
 
源代码16 项目: MercuryTrade   文件: HelpIGFrame.java
@Override
public void mouseDragged(MouseEvent e) {
    e.translatePoint(HelpIGFrame.this.getLocation().x - x, HelpIGFrame.this.getLocation().y - y);
    HelpIGFrame.this.setLocation(new Point(e.getX(), e.getY()));
}
 
源代码17 项目: MercuryTrade   文件: AbstractComponentFrame.java
@Override
public void mouseDragged(MouseEvent e) {
    e.translatePoint(AbstractComponentFrame.this.getLocation().x - x, AbstractComponentFrame.this.getLocation().y - y);
    onFrameDragged(new Point(e.getX(), e.getY()));
}
 
源代码18 项目: java-swing-tips   文件: MainPanel.java
@Override protected TrackListener createTrackListener(JSlider slider) {
  return new TrackListener() {
    @Override public void mouseDragged(MouseEvent e) {
      if (!slider.getSnapToTicks() || slider.getMajorTickSpacing() == 0) {
        super.mouseDragged(e);
        return;
      }
      // case HORIZONTAL:
      int halfThumbWidth = thumbRect.width / 2;
      int trackLength = trackRect.width;
      int trackLeft = trackRect.x - halfThumbWidth;
      int trackRight = trackRect.x + trackRect.width - 1 + halfThumbWidth;
      int pos = e.getX();
      int snappedPos;
      if (pos <= trackLeft) {
        snappedPos = trackLeft;
      } else if (pos >= trackRight) {
        snappedPos = trackRight;
      } else {
        // int tickSpacing = slider.getMajorTickSpacing();
        // float actualPixelsForOneTick = trackLength * tickSpacing / (float) slider.getMaximum();

        // a problem if you choose to set a negative MINIMUM for the JSlider;
        // the calculated drag-positions are wrong.
        // Fixed by bobndrew:
        int possibleTickPositions = slider.getMaximum() - slider.getMinimum();
        boolean hasMinorTickSpacing = slider.getMinorTickSpacing() > 0;
        int tickSpacing = hasMinorTickSpacing ? slider.getMinorTickSpacing() : slider.getMajorTickSpacing();
        float actualPixelsForOneTick = trackLength * tickSpacing / (float) possibleTickPositions;
        pos -= trackLeft;
        // snappedPos = (int) (Math.round(pos / actualPixelsForOneTick) * actualPixelsForOneTick + .5) + trackLeft;
        snappedPos = Math.round(Math.round(pos / actualPixelsForOneTick) * actualPixelsForOneTick) + trackLeft;
        offset = 0;
        // System.out.println(snappedPos);
      }
      e.translatePoint(snappedPos - e.getX(), 0);
      super.mouseDragged(e);
      // MouseEvent me = new MouseEvent(
      //   e.getComponent(), e.getID(), e.getWhen(), e.getModifiers() | e.getModifiersEx(),
      //   snappedPos, e.getY(),
      //   e.getXOnScreen(), e.getYOnScreen(),
      //   e.getClickCount(), e.isPopupTrigger(), e.getButton());
      // e.consume();
      // super.mouseDragged(me);
    }
  };
}
 
源代码19 项目: java-swing-tips   文件: MainPanel.java
@Override protected TrackListener createTrackListener(JSlider slider) {
  return new TrackListener() {
    @Override public void mouseDragged(MouseEvent e) {
      if (!slider.getSnapToTicks() || slider.getMajorTickSpacing() == 0) {
        super.mouseDragged(e);
        return;
      }
      // case HORIZONTAL:
      int halfThumbWidth = thumbRect.width / 2;
      int trackLength = trackRect.width;
      int trackLeft = trackRect.x - halfThumbWidth;
      int trackRight = trackRect.x + trackRect.width - 1 + halfThumbWidth;
      int pos = e.getX();
      int snappedPos;
      if (pos <= trackLeft) {
        snappedPos = trackLeft;
      } else if (pos >= trackRight) {
        snappedPos = trackRight;
      } else {
        // int tickSpacing = slider.getMajorTickSpacing();
        // float actualPixelsForOneTick = trackLength * tickSpacing / (float) slider.getMaximum();

        // a problem if you choose to set a negative MINIMUM for the JSlider;
        // the calculated drag-positions are wrong.
        // Fixed by bobndrew:
        int possibleTickPositions = slider.getMaximum() - slider.getMinimum();
        boolean hasMinorTickSpacing = slider.getMinorTickSpacing() > 0;
        int tickSpacing = hasMinorTickSpacing ? slider.getMinorTickSpacing() : slider.getMajorTickSpacing();
        float actualPixelsForOneTick = trackLength * tickSpacing / (float) possibleTickPositions;
        pos -= trackLeft;
        // snappedPos = (int) (Math.round(pos / actualPixelsForOneTick) * actualPixelsForOneTick + .5) + trackLeft;
        snappedPos = Math.round(Math.round(pos / actualPixelsForOneTick) * actualPixelsForOneTick) + trackLeft;
        offset = 0;
        // System.out.println(snappedPos);
      }
      e.translatePoint(snappedPos - e.getX(), 0);
      super.mouseDragged(e);
      // MouseEvent me = new MouseEvent(
      //   e.getComponent(), e.getID(), e.getWhen(), e.getModifiers() | e.getModifiersEx(),
      //   snappedPos, e.getY(),
      //   e.getXOnScreen(), e.getYOnScreen(),
      //   e.getClickCount(), e.isPopupTrigger(), e.getButton());
      // super.mouseDragged(me);
    }
  };
}
 
源代码20 项目: PyramidShader   文件: MultiThumbSliderUI.java
public void mouseDragged(MouseEvent e) {
	if(slider.isEnabled()==false) return;

	e.translatePoint(dx, dy);

	mouseMoved(e);
	if(pressedState!=null && pressedState.selectedThumb!=-1) {
		slider.setValueIsAdjusting(true);

		State newState = new State(pressedState);
		float v;
		boolean outside;
		if(slider.getOrientation()==MultiThumbSlider.HORIZONTAL) {
			v = ((float)(e.getX()-trackRect.x))/((float)trackRect.width);
			if(slider.isInverted())
				v = 1-v;
			outside = (e.getY()<trackRect.y-10) || (e.getY()>trackRect.y+trackRect.height+10);

			//don't whack the thumb off the slider if you happen to be *near* the edge:
			if(e.getX()>trackRect.x-10 && e.getX()<trackRect.x+trackRect.width+10) {
				if(v<0) v = 0;
				if(v>1) v = 1;
			}
		} else {
			v = ((float)(e.getY()-trackRect.y))/((float)trackRect.height);
			if(slider.isInverted()==false)
				v = 1-v;
			outside = (e.getX()<trackRect.x-10) || (e.getX()>trackRect.x+trackRect.width+10);

			if(e.getY()>trackRect.y-10 && e.getY()<trackRect.y+trackRect.height+10) {
				if(v<0) v = 0;
				if(v>1) v = 1;
			}
		}
		if(newState.positions.length<=slider.getMinimumThumbnailCount()) {
			outside = false; //I don't care if you are outside: no removing!
		}
		newState.setPosition(newState.selectedThumb, v);

		//because we delegate mouseReleased() to this method:
		if(outside && slider.isThumbRemovalAllowed()) {
			newState.removeThumb(newState.selectedThumb);
		}
		if(validatePositions(newState)) {
			newState.install();
		}
		e.consume();
	}
}