本文整理汇总了Java中javafx.scene.input.MouseEvent类的典型用法代码示例。如果您正苦于以下问题:Java MouseEvent类的具体用法?Java MouseEvent怎么用?Java MouseEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MouseEvent类属于javafx.scene.input包,在下文中一共展示了MouseEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleSelectImage
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
public void handleSelectImage(MouseEvent mouseEvent) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(imageChooserTitle);
fileChooser.getExtensionFilters().add(new ExtensionFilter("PNG", "*.png"));
final File file = fileChooser
.showOpenDialog(((Node) mouseEvent.getSource()).getScene().getWindow());
if (file == null) {
return;
}
try {
final byte[] image = ImageUtils.readImage(file);
model.imageRaw.set(image);
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: setButtonEffect
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
private static void setButtonEffect(Node node)
{
DropShadow rollOverColor = new DropShadow();
rollOverColor.setColor(Color.ORANGERED);
DropShadow clickColor = new DropShadow();
clickColor.setColor(Color.DARKBLUE);
node.addEventHandler(MouseEvent.MOUSE_ENTERED,
(event) -> node.setEffect(rollOverColor));
// Removing the shadow when the mouse cursor is off
node.addEventHandler(MouseEvent.MOUSE_EXITED, (event) -> node.setEffect(null));
// Darken shadow on click
node.addEventHandler(MouseEvent.MOUSE_PRESSED,
(event) -> node.setEffect(clickColor));
// Restore hover style on click end
node.addEventHandler(MouseEvent.MOUSE_RELEASED,
(event) -> node.setEffect(rollOverColor));
}
示例3: getText
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
@Test public void getText() {
Button button = (Button) getPrimaryStage().getScene().getRoot().lookup(".button");
LoggingRecorder lr = new LoggingRecorder();
List<String> text = new ArrayList<>();
Platform.runLater(new Runnable() {
@Override public void run() {
RFXButtonBase rfxButtonBase = new RFXButtonBase(button, null, null, lr);
Point2D sceneXY = button.localToScene(new Point2D(3, 3));
PickResult pickResult = new PickResult(button, sceneXY.getX(), sceneXY.getY());
Point2D screenXY = button.localToScreen(new Point2D(3, 3));
MouseEvent me = new MouseEvent(button, button, MouseEvent.MOUSE_PRESSED, 3, 3, sceneXY.getX(), screenXY.getY(),
MouseButton.PRIMARY, 1, false, false, false, false, true, false, false, false, false, false, pickResult);
rfxButtonBase.mouseButton1Pressed(me);
text.add(rfxButtonBase.getAttribute("text"));
}
});
new Wait("Waiting for button text.") {
@Override public boolean until() {
return text.size() > 0;
}
};
AssertJUnit.assertEquals("Color", text.get(0));
}
示例4: start
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
@Override public void start(Stage stage) {
StackPane pane = new StackPane(heatMap);
// Setup a mouse event filter which adds spots to the heatmap as soon as the mouse will be moved across the pane
pane.addEventFilter(MouseEvent.MOUSE_MOVED, event -> {
double x = event.getX();
double y = event.getY();
if (x < heatMap.getSpotRadius()) x = heatMap.getSpotRadius();
if (x > pane.getWidth() - heatMap.getSpotRadius()) x = pane.getWidth() - heatMap.getSpotRadius();
if (y < heatMap.getSpotRadius()) y = heatMap.getSpotRadius();
if (y > pane.getHeight() - heatMap.getSpotRadius()) y = pane.getHeight() - heatMap.getSpotRadius();
heatMap.addSpot(x, y);
});
pane.widthProperty().addListener((ov, oldWidth, newWidth) -> heatMap.setSize(newWidth.doubleValue(), pane.getHeight()));
pane.heightProperty().addListener((ov, oldHeight, newHeight) -> heatMap.setSize(pane.getWidth(), newHeight.doubleValue()));
Scene scene = new Scene(pane, 400, 400);
stage.setTitle("HeatMap (move mouse over pane)");
stage.setScene(scene);
stage.show();
}
示例5: mousePressed
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
private void mousePressed(MouseEvent event) {
// ignore clicks outside of the draggable margin
if (!isInDraggableZone(event)) {
return;
}
dragging = true;
// make sure that the minimum size is set to the current size once;
// setting a min size that is smaller than the current size will have no effect
if (!didDragInit) {
tile.setMinHeight(tile.getHeight());
tile.setMinWidth(tile.getWidth());
didDragInit = true;
}
lastX = event.getX();
lastY = event.getY();
ResizeUtils.setCurrentTile(tile);
TileLayout layout = tilePane.getTileLayout(tile);
tilePane.setHighlight(true);
tilePane.setHighlightSize(layout.size);
tilePane.setHighlightPoint(layout.origin);
}
示例6: onBackgroundDragged
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
private void onBackgroundDragged(MouseEvent event) {
if (event.getButton() == MouseButton.PRIMARY && dragActive) {
double x = event.getX() - panningComponent.panXProperty().get();
double y = event.getY() - panningComponent.panYProperty().get();
double minX = Math.min(x, xAtPress);
double minY = Math.min(y, yAtPress);
double maxX = Math.max(x, xAtPress);
double maxY = Math.max(y, yAtPress);
root.setVisible(true);
root.setLayoutX(minX);
root.setLayoutY(minY);
root.setWidth(maxX - minX);
root.setHeight(maxY - minY);
}
}
示例7: drawingAreaMouseClicked
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
@FXML
private void drawingAreaMouseClicked(MouseEvent e)
{
polyline.getPoints().addAll(e.getX(), e.getY());
polygon.getPoints().addAll(e.getX(), e.getY());
// if path is empty, move to first click position and close path
if (path.getElements().isEmpty())
{
path.getElements().add(new MoveTo(e.getX(), e.getY()));
path.getElements().add(new ClosePath());
}
else // insert a new path segment before the ClosePath element
{
// create an arc segment and insert it in the path
ArcTo arcTo = new ArcTo();
arcTo.setX(e.getX());
arcTo.setY(e.getY());
arcTo.setRadiusX(100.0);
arcTo.setRadiusY(100.0);
arcTo.setSweepFlag(sweepFlag);
sweepFlag = !sweepFlag;
path.getElements().add(path.getElements().size() - 1, arcTo);
}
}
示例8: handle
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
@Override
public void handle(MouseEvent event) {
double offsetX = event.getSceneX() - dragContext.mouseAnchorX;
double offsetY = event.getSceneY() - dragContext.mouseAnchorY;
if( offsetX > 0) {
rect.setWidth( offsetX);
} else {
rect.setX(event.getSceneX());
rect.setWidth(dragContext.mouseAnchorX - rect.getX());
}
if( offsetY > 0) {
rect.setHeight( offsetY);
} else {
rect.setY(event.getSceneY());
rect.setHeight(dragContext.mouseAnchorY - rect.getY());
}
event.consume();
}
示例9: onTreeClick
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
private void onTreeClick(MouseEvent event)
{
if (event.getClickCount() == 2)
{
if (onFileDoubleClicked != null)
{
Pair<Project, ASMFile> selection = getActiveSelection();
if (selection == null)
return;
ASMFile selectedFile = selection.getValue();
if (selectedFile != null)
onFileDoubleClicked.accept(selectedFile);
}
}
}
示例10: setIconEvents
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
private void setIconEvents() {
icon.addEventFilter(MouseEvent.MOUSE_PRESSED,
new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent click) {
if (click.getClickCount() == 2) {
click.consume();
if (isDir == true) {
System.out.println(path);
setTabView(path, tilePane, txtDirPath);
} else if (isImage == true) {
openImage();
} else {
try {
System.out.println(runCommand);
pb = Runtime.getRuntime().exec(runCommand);
} catch(Throwable imgIOErr) {
System.out.println(imgIOErr);
}
}
}
}
});
}
示例11: testMouseMoveCoordinatesLongLong
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
public void testMouseMoveCoordinatesLongLong() {
EventQueueWait.requestFocus(button);
final StringBuilder text = new StringBuilder();
button.addEventHandler(MouseEvent.ANY, new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent e) {
if (e.getEventType() == MouseEvent.MOUSE_DRAGGED) {
text.append("dragged ");
}
if (e.getEventType() == MouseEvent.MOUSE_MOVED) {
text.append("moved(" + e.getX() + "," + e.getY() + ") ");
}
}
});
driver.moveto(button, 3, 3);
driver.moveto(button, 5, 10);
final String expected = "moved(3.0,3.0) moved(5.0,10.0)";
new WaitWithoutException() {
@Override public boolean until() {
return expected.equals(text.toString().trim());
}
}.wait("Text is empty", 3000, 500);
AssertJUnit.assertEquals(expected, text.toString().trim());
}
示例12: init
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
@Override
public void init(Stage stage, Scene scene, Pane pane) {
addButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
//add transition
String eventName = eventNameTextField.getText();
if (eventName.isEmpty()) {
return;
}
RaiseEventTransition transition = new RaiseEventTransition(eventName);
entry.getTranstionList(index).add(transition);
//refresh listview
paneController.refreshListView();
stage.close();
}
});
}
示例13: ImageToggleButton
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
public ImageToggleButton(String imageurl) {
setGraphic(new ImageView(new Image(getClass().getResourceAsStream(imageurl))));
setStyle(STYLE_NORMAL);
setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (toggle) {
setStyle(STYLE_NORMAL);
toggle = false;
} else {
setStyle(STYLE_PRESSED);
toggle = true;
}
}
});
}
示例14: press
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
private void press(MouseEvent e) {
Node node = get();
if (isEnable() && e.isConsumed() == false && node != null) {
Corner corner = calcCorner(e);
if (corner != Corner.CENTER) {
pressedCorner = corner;
startX = e.getScreenX();
startY = e.getScreenY();
startWidth = width.get() == -1 ? node.prefWidth(-1) : width.get();
startHeight = height.get() == -1 ? node.prefHeight(-1) : height.get();
startPosX = node.getLayoutX();
startPosY = node.getLayoutY();
e.consume();
}
}
}
示例15: canvasClicked
import javafx.scene.input.MouseEvent; //导入依赖的package包/类
@Override
public void canvasClicked(MouseEvent mouseEvent) {
DrawCoords mousePosition = new DrawCoords(mouseEvent.getX(), mouseEvent.getY());
CoordProjector projector = getProjector(boardCanvas);
Coords boardPos = projector.nearestCoords(mousePosition);
if ( !projector.isWithinBounds(mousePosition) )
return;
if ( game.isLegalMove(play(boardPos, getTurnPlayer())) ) {
game.playMove(play(boardPos, getTurnPlayer()));
}
}