Java Code Examples for java.awt.event.MouseEvent.BUTTON1

The following are Jave code examples for showing how to use BUTTON1 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: marathonv5   File: RTree.java   View Source Code Vote up 6 votes
@Override protected void mousePressed(MouseEvent me) {
    // Ignore double clicks on non-leaf tree nodes
    if (me.getButton() == MouseEvent.BUTTON1 && me.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK) {
        if (me.getClickCount() == 1) {
            return;
        }
        TreePath path = ((JTree) component).getPathForRow(row);
        if (path != null) {
            Object lastPathComponent = path.getLastPathComponent();
            if (lastPathComponent instanceof TreeNode) {
                TreeNode node = (TreeNode) lastPathComponent;
                if (node.getChildCount() != 0) {
                    return;
                }
            }
        }
    }
    // Ignore Ctrl+Clicks used to select the nodes
    if (me.getButton() == MouseEvent.BUTTON1 && isMenuShortcutKeyDown(me)) {
        return;
    }
    if (me.getButton() != MouseEvent.BUTTON1) {
        focusLost(null);
    }
    super.mousePressed(me);
}
 
Example 2
Project: Spark   File: Java2DFrame.java   View Source Code Vote up 6 votes
public final void mouseReleased(MouseEvent e)
{
	int internalButton = 0;
	switch (e.getButton())
	{
		case MouseEvent.BUTTON1:
			internalButton = 0;
			break;
		case MouseEvent.BUTTON3:
			internalButton = 1;
			break;
		case MouseEvent.BUTTON2:
			internalButton = 2;
			break;
	}
	
	game.gameQueue.add(new MousePressEvent(SparkEvents.E_MOUSEUP,
			internalButton, e.getX(), e.getY()));
}
 
Example 3
Project: MapAnalyst   File: DefaultMapController.java   View Source Code Vote up 6 votes
/**
 * Sets the mouse button that is used for moving the map. Possible values are:
 * <ul>
 * <li>{@link MouseEvent#BUTTON1} (left mouse button)</li>
 * <li>{@link MouseEvent#BUTTON2} (middle mouse button)</li>
 * <li>{@link MouseEvent#BUTTON3} (right mouse button)</li>
 * </ul>
 *
 * @param movementMouseButton the mouse button that is used for moving the map
 */
public void setMovementMouseButton(int movementMouseButton) {
    this.movementMouseButton = movementMouseButton;
    switch (movementMouseButton) {
        case MouseEvent.BUTTON1:
            movementMouseButtonMask = MouseEvent.BUTTON1_DOWN_MASK;
            break;
        case MouseEvent.BUTTON2:
            movementMouseButtonMask = MouseEvent.BUTTON2_DOWN_MASK;
            break;
        case MouseEvent.BUTTON3:
            movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK;
            break;
        default:
            throw new RuntimeException("Unsupported button");
    }
}
 
Example 4
Project: incubator-netbeans   File: ListComponent.java   View Source Code Vote up 6 votes
@Override
        public void mouseClicked(MouseEvent e) {
            if (e.getSource() == bar) {
                handle.requestExplicitSelection();
//                markAsSelected(true);
            }
            if (e.getClickCount() > 1 && (e.getSource() == mainLabel || e.getSource() == dynaLabel)) {
                handle.requestView();
            }
            if (e.getButton() != MouseEvent.BUTTON1) {
                showMenu(e);
            } else {
                ListComponent.this.requestFocus();
            }
            
//            System.out.println("list component requesting focus..");
        }
 
Example 5
Project: Recaf   File: OpcodeMouseListener.java   View Source Code Vote up 6 votes
@Override
public void mouseReleased(MouseEvent e) {
	int button = e.getButton();
	if (list.getSelectedIndices().length <= 1) {
		// If not left-click, enforce selection at the given location
		if (button != MouseEvent.BUTTON1) {
			int index = list.locationToIndex(e.getPoint());
			list.setSelectedIndex(index);
		}
	}
	Object value = list.getSelectedValue();
	if (value == null) {
		return;
	}
	if (button == MouseEvent.BUTTON3) {
		createContextMenu((AbstractInsnNode) value, e.getX(), e.getY());
	} else if (button == MouseEvent.BUTTON2) {
		createEdit((AbstractInsnNode) value, e.getX(), e.getY());
	}
}
 
Example 6
Project: Pogamut3   File: SelectableMapGLPanel.java   View Source Code Vote up 6 votes
@Override
public void mousePressed(MouseEvent e) {
    // we only want to select/deselect on left click, not middle click used during drag or something like that
    if (e.getButton() != MouseEvent.BUTTON1) {
        return;
    }
    // get global selection object for this map
    IPogamutEnvironments environments = Lookup.getDefault().lookup(IPogamutEnvironments.class);
    if (environments == null) {
        return;
    }
    IUnrealMap map = mapRenderer.getObject();

    EnvironmentSelection mapSelection = environments.getEnvironmentSelection(map);

    // Get list of selected bots
    Set<IRenderableUTAgent> clickedBots = this.getAgentsAt(e.getPoint());

    mapSelection.clearSelection();
    
    for (IRenderableUTAgent selectedAgent : clickedBots) {
        mapSelection.addSelected(selectedAgent.getDataSource());
    }
}
 
Example 7
Project: QN-ACTR-Release   File: Scatter.java   View Source Code Vote up 5 votes
public void mousePressed(MouseEvent e) {
	// Controllo che la pressione del mouse risulti all'interno dell'area del grafico
	if ((e.getX() - UpperLeftGraph.x) >= 0 && (e.getY() - UpperLeftGraph.y) >= 0 && (e.getX() - UpperLeftGraph.x) < Scatter.this.WIDTH
			&& (e.getY() - UpperLeftGraph.y) < Scatter.this.HEIGHT) {
		// Start visualizzazione zoom area
		if (e.getButton() == MouseEvent.BUTTON1) {
			xStart = e.getX();
			yStart = e.getY();
			zoomming = true;
		}
	}
}
 
Example 8
Project: DreamBlocks   File: AwtEventsHandler.java   View Source Code Vote up 5 votes
@Override
public void mouseReleased(MouseEvent arg0) {
	switch (arg0.getButton()) {
	case MouseEvent.BUTTON1:
		game.leftClick = false;
		break;
	case MouseEvent.BUTTON2: // fall through
	case MouseEvent.BUTTON3:
		game.rightClick = false;
		break;
	}
}
 
Example 9
Project: AutonomousCar   File: DraggingWindow.java   View Source Code Vote up 5 votes
protected void mouseReleased(MouseEvent e)
{
    if(e.getButton() == MouseEvent.BUTTON1)
    {
        dragging = false;
    }
}
 
Example 10
Project: openjdk-jdk10   File: InfoWindow.java   View Source Code Vote up 5 votes
public void mouseClicked(MouseEvent e) {
    // hide the balloon by any click
    hide();
    if (e.getButton() == MouseEvent.BUTTON1) {
        ActionEvent aev = new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
                                          liveArguments.getActionCommand(),
                                          e.getWhen(), e.getModifiers());
        XToolkit.postEvent(XToolkit.targetToAppContext(aev.getSource()), aev);
    }
}
 
Example 11
Project: OpenJSharp   File: XToolkit.java   View Source Code Vote up 5 votes
static boolean isLeftMouseButton(MouseEvent me) {
    switch (me.getID()) {
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
          return (me.getButton() == MouseEvent.BUTTON1);
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_DRAGGED:
          return ((me.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0);
    }
    return false;
}
 
Example 12
Project: Mafia   File: MouseInput.java   View Source Code Vote up 5 votes
@Override
public void mouseReleased(MouseEvent event) {
	if(event.getButton() == MouseEvent.BUTTON1) {
		isPrimaryPressed = false;
		wasPrimaryClicked = true;
		
	} else if(event.getButton() == MouseEvent.BUTTON2) {
		isMiddlePressed = false;
		wasMiddleClicked = true;
		
	} else if(event.getButton() == MouseEvent.BUTTON3) {
		isSecondaryPressed = false;
		wasSecondaryClicked = true;
	}
}
 
Example 13
Project: hearthstone   File: PartidaView.java   View Source Code Vote up 5 votes
/**
 * Captura o alvo clicado logo após um evento grito de guerra ter sido
 * gerado
 *
 * @param component alvo clicado
 * @param evt evento do mouse
 */
private void capturarAlvoGritoDeGuerra(Component component, MouseEvent evt) {
    if (evt.getButton() == MouseEvent.BUTTON1) {
        String name = component != null ? component.toString() : "";
        if (name.contains(Values.TO_STRING_HEROI) || name.contains(Values.TO_STRING_LACAIO)) {
            setAlvoSelecionado(Partida.getIdLong(name));
        }
    } else {
        setAlvoSelecionado(ALVO_CANCEL);
    }
}
 
Example 14
Project: Proj4   File: SpaceSettlersGUI.java   View Source Code Vote up 5 votes
@Override
public void mouseReleased(MouseEvent e) {
	Point point = e.getPoint();

	//System.out.println("Original x, y " + point.getX() + " , " + point.getY());
	Point2D newPoint = new Point2D.Double(0, 0);
	clickTransform.transform(point, newPoint); 
	Position clickPosition = new Position(newPoint.getX(), newPoint.getY());
	//System.out.println("Transformed x, y " + newPoint.getX() + " , " + newPoint.getY());
	
	// only listens to left clicks
	if (e.getButton() == MouseEvent.BUTTON1) {
		// get the set of all objects and figure out if the user clicked inside an object
		Set<AbstractObject> allObjects = simulator.getAllObjects();
		Toroidal2DPhysics space = simulator.getSimulatedSpace();
		//System.out.println("Received a click at " + clickPosition);
		
		for (AbstractObject obj : allObjects) {
			//System.out.println("Object " + obj + " distance to click " + space.findShortestDistance(clickPosition, obj.getPosition()) + " radius is " + obj.getRadius());
			if (space.findShortestDistance(clickPosition, obj.getPosition()) <= obj.getRadius()) {
				infoPanel.setClickedObject(obj);
				//System.out.println("Click matched object " + obj);
				return;
			}
		}
		
	}
}
 
Example 15
Project: marathonv5   File: RTable.java   View Source Code Vote up 4 votes
@Override protected void mouseClicked(MouseEvent me) {
    if (me.getButton() == MouseEvent.BUTTON1 && isMenuShortcutKeyDown(me) || ((JTable)component).isEditing()) {
        return;
    }
    recorder.recordClick2(this, me, true);
}
 
Example 16
Project: marathonv5   File: RTree.java   View Source Code Vote up 4 votes
@Override protected void mouseClicked(MouseEvent me) {
    if (me.getButton() == MouseEvent.BUTTON1 && isMenuShortcutKeyDown(me) || ((JTree) component).isEditing()) {
        return;
    }
    recorder.recordClick2(this, me, true);
}
 
Example 17
Project: incubator-netbeans   File: ImageDetailProvider.java   View Source Code Vote up 4 votes
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
        openNewWindow();
    }
}
 
Example 18
Project: jmt   File: FuzzyKSingleClusterScatter.java   View Source Code Vote up 4 votes
public void mouseReleased(MouseEvent e) {
	if (xStart == e.getX() && yStart == e.getY()) {
		zoomming = false;
		return;
	}
	// Controllo che il mouse venga rilasciato all'interno del grafico
	if ((e.getX() - UpperLeftGraph.x) >= 0 && (e.getY() - UpperLeftGraph.y) >= 0
			&& (e.getX() - UpperLeftGraph.x) < FuzzyKSingleClusterScatter.this.WIDTH
			&& (e.getY() - UpperLeftGraph.y) < FuzzyKSingleClusterScatter.this.HEIGHT && zoomming && e.getButton() == MouseEvent.BUTTON1) {
		xEnd = e.getX();
		yEnd = e.getY();
		zoomming = false;
		double rangeX = xMax - xMin;
		double rangeY = yMax - yMin;
		if (xStart < xEnd && yStart < yEnd) {
			xMin = xMin + rangeX / FuzzyKSingleClusterScatter.this.WIDTH * (xStart - UpperLeftGraph.x);
			yMax = yMax - rangeY / FuzzyKSingleClusterScatter.this.WIDTH * (yStart - UpperLeftGraph.y);
			xMax = xMin + rangeX / FuzzyKSingleClusterScatter.this.WIDTH * (xEnd - xStart);
			yMin = yMax - rangeY / FuzzyKSingleClusterScatter.this.WIDTH * (yEnd - yStart);
		}
		if (xStart < xEnd && yStart > yEnd) {
			xMin = xMin + rangeX / FuzzyKSingleClusterScatter.this.WIDTH * (xStart - UpperLeftGraph.x);
			yMax = yMax - rangeY / FuzzyKSingleClusterScatter.this.WIDTH * (yEnd - UpperLeftGraph.y);
			xMax = xMin + rangeX / FuzzyKSingleClusterScatter.this.WIDTH * (xEnd - xStart);
			yMin = yMax - rangeY / FuzzyKSingleClusterScatter.this.WIDTH * (yStart - yEnd);
		}
		if (xStart > xEnd && yStart < yEnd) {
			xMin = xMin + rangeX / FuzzyKSingleClusterScatter.this.WIDTH * (xEnd - UpperLeftGraph.x);
			yMax = yMax - rangeY / FuzzyKSingleClusterScatter.this.WIDTH * (yStart - UpperLeftGraph.y);
			xMax = xMin + rangeX / FuzzyKSingleClusterScatter.this.WIDTH * (xStart - xEnd);
			yMin = yMax - rangeY / FuzzyKSingleClusterScatter.this.WIDTH * (yEnd - yStart);
		}
		if (xStart > xEnd && yStart > yEnd) {
			xMin = xMin + rangeX / FuzzyKSingleClusterScatter.this.WIDTH * (xEnd - UpperLeftGraph.x);
			yMax = yMax - rangeY / FuzzyKSingleClusterScatter.this.WIDTH * (yEnd - UpperLeftGraph.y);
			xMax = xMin + rangeX / FuzzyKSingleClusterScatter.this.WIDTH * (xStart - xEnd);
			yMin = yMax - rangeY / FuzzyKSingleClusterScatter.this.WIDTH * (yStart - yEnd);
		}

		first = true;
		FuzzyKSingleClusterScatter.this.repaint();
		this.repaint();
		return;
	} else {
		// Annullo lo zoom
		zoomming = false;
		this.repaint();
	}
}
 
Example 19
Project: incubator-netbeans   File: HtmlPreviewElement.java   View Source Code Vote up 4 votes
@Override
protected void processMouseEvent( MouseEvent e, JLayer<? extends JPanel> panel ) {
    super.processMouseEvent( e, panel );
    if( e.getButton() == MouseEvent.BUTTON1 )
        e.consume();
}
 
Example 20
Project: freecol   File: CanvasMapEditorMouseListener.java   View Source Code Vote up 4 votes
/**
 * {@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();
}