Java Code Examples for javax.swing.SwingUtilities#isMiddleMouseButton()

The following examples show how to use javax.swing.SwingUtilities#isMiddleMouseButton() . 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
@Override
public MouseEvent mouseReleased(MouseEvent event)
{
	if (SwingUtilities.isMiddleMouseButton(event))
	{
		return event;
	}

	if (SwingUtilities.isLeftMouseButton(event) && plugin.isCreatingScreenMarker())
	{
		/* Set the creation panel as "ready" (because the marker area as been drawn) */
		plugin.completeSelection();
	}

	event.consume();
	return event;
}
 
Example 2
Source Project: netbeans   File: HyperlinkOperation.java    License: Apache License 2.0 6 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    if(e.isConsumed()) return;
    boolean activate = false;
    HyperlinkType type = getHyperlinkType(e);
    if ( type != null ) {
        activate = !e.isPopupTrigger() && e.getClickCount() == 1 && SwingUtilities.isLeftMouseButton(e);
    } else if ( Utilities.isWindows() && e.getClickCount() == 1 && SwingUtilities.isMiddleMouseButton(e) ) {
        activate = true;
        type = HyperlinkType.GO_TO_DECLARATION;
    }
    
    if ( activate ) {
        int position = component.viewToModel(e.getPoint());
        
        if (position < 0) {
            return ;
        }
        
        performAction(position, type);
    }
}
 
Example 3
@Override
public void mouseClicked(MouseEvent e) {
    if (tabbedPane.getSelectedIndex() != -1) {
        Rectangle rect = tabbedPane.getUI().getTabBounds(tabbedPane, tabbedPane.getSelectedIndex());
        if (rect.contains(e.getPoint())) {
            if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
                if (checkIndexContains()) {
                    startEditing();
                }
            } else if (SwingUtilities.isMiddleMouseButton(e)) {
                if (onMiddleClickAction != null) {
                    onMiddleClickAction.actionPerformed(null);
                }
            }

        } else {
            renameTabTitle();
        }
    }
}
 
Example 4
@Override
public MouseEvent mouseReleased(MouseEvent event)
{
	if (SwingUtilities.isMiddleMouseButton(event))
	{
		return event;
	}

	if (SwingUtilities.isLeftMouseButton(event) && plugin.isCreatingScreenMarker())
	{
		/* Set the creation panel as "ready" (because the marker area as been drawn) */
		plugin.completeSelection();
	}

	event.consume();
	return event;
}
 
Example 5
@Override
public void mousePressed(MouseEvent e) {
	if (SwingUtilities.isRightMouseButton(e)) {
		drag = true;
		lastX = e.getX();
		lastY = e.getY();
	} else
	if (SwingUtilities.isMiddleMouseButton(e)) {
		offsetX = 0;
		offsetY = 0;
		if (e.isControlDown()) {
			scale = 1;
		}
		repaint();
	}
}
 
Example 6
Source Project: seaglass   File: SeaGlassScrollBarUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * If the mouse is pressed above the "thumb" component then reduce the
 * scrollbars value by one page ("page up"), otherwise increase it by
 * one page. If there is no thumb then page up if the mouse is in the
 * upper half of the track.
 */
public void mousePressed(MouseEvent e) {
    if (SwingUtilities.isRightMouseButton(e) || (!getSupportsAbsolutePositioning() && SwingUtilities.isMiddleMouseButton(e)))
        return;
    if (!scrollbar.isEnabled()) return;

    currentMouseX = e.getX();
    currentMouseY = e.getY();

    isMouseButtonDown = false;

    // Clicked in the Thumb area?
    if (getThumbBounds().contains(currentMouseX, currentMouseY)) {
        isMouseButtonDown = true;
        scrollbar.repaint();
    }
}
 
Example 7
@Override
public MouseEvent mouseClicked(MouseEvent event)
{
	if (SwingUtilities.isMiddleMouseButton(event))
	{
		return event;
	}

	event.consume();
	return event;
}
 
Example 8
@Override
public MouseEvent mousePressed(MouseEvent event)
{
	if (SwingUtilities.isMiddleMouseButton(event))
	{
		return event;
	}

	if (SwingUtilities.isLeftMouseButton(event))
	{
		final Rectangle bounds = plugin.getSelectedWidgetBounds();

		if (bounds != null)
		{
			plugin.startCreation(bounds.getLocation(), bounds.getSize());
		}
		else
		{
			plugin.startCreation(event.getPoint());
		}
	}
	else if (plugin.isCreatingScreenMarker())
	{
		plugin.finishCreation(true);
	}

	event.consume();
	return event;
}
 
Example 9
private static void processEvent(int eventType, MouseEvent e) {
    if (eventCount >= BUTTON_EVENTS_SEQUENCE.length) {
        throw new RuntimeException("Unexpected event " + e);
    }

    int[] arr = BUTTON_EVENTS_SEQUENCE[eventCount];

    if (arr[0] != eventType) {
        throw new RuntimeException("Unexpected eventType " + eventType + "on step " + eventCount);
    }

    boolean result;

    switch (arr[1]) {
        case 1:
            result = SwingUtilities.isLeftMouseButton(e);

            break;

        case 2:
            result = SwingUtilities.isMiddleMouseButton(e);

            break;

        case 3:
            result = SwingUtilities.isRightMouseButton(e);

            break;

        default:
            throw new RuntimeException("Incorrect arr[1] on step " + eventCount);
    }

    if (!result) {
        throw new RuntimeException("Test failed on step " + eventCount);
    }

    eventCount++;
}
 
Example 10
protected void processMouseEvent(MouseEvent e) {
    int index = indexAtLocation(e.getX(), e.getY());
    
    if (index != -1) {
        if (e.isPopupTrigger()) {
            // Show popup menu for the clicked tab
            final MouseEvent _e = e;
            final int _index = index;
            final Component _component = getComponentAt(index);
            
            SwingUtilities.invokeLater(new Runnable() {
                public void run() { showPopupMenu(_index, _component, _e); };
            });
            
            e.consume();
            return;
        } else if (e.getID() == MouseEvent.MOUSE_CLICKED && SwingUtilities.isMiddleMouseButton(e)) {
            // Close tab using middle button click
            if (isClosableAt(index)) closeTab(getComponentAt(index));
            
            e.consume();
            return;
        } else if (e.getID() == MouseEvent.MOUSE_PRESSED && !SwingUtilities.isLeftMouseButton(e)) {
            // Do not switch tabs using middle or right mouse button
            e.consume();
            return;
        }
    }
    
    super.processMouseEvent(e);
}
 
Example 11
private static void processEvent(int eventType, MouseEvent e) {
    if (eventCount >= BUTTON_EVENTS_SEQUENCE.length) {
        throw new RuntimeException("Unexpected event " + e);
    }

    int[] arr = BUTTON_EVENTS_SEQUENCE[eventCount];

    if (arr[0] != eventType) {
        throw new RuntimeException("Unexpected eventType " + eventType + "on step " + eventCount);
    }

    boolean result;

    switch (arr[1]) {
        case 1:
            result = SwingUtilities.isLeftMouseButton(e);

            break;

        case 2:
            result = SwingUtilities.isMiddleMouseButton(e);

            break;

        case 3:
            result = SwingUtilities.isRightMouseButton(e);

            break;

        default:
            throw new RuntimeException("Incorrect arr[1] on step " + eventCount);
    }

    if (!result) {
        throw new RuntimeException("Test failed on step " + eventCount);
    }

    eventCount++;
}
 
Example 12
@Override
public MouseEvent mouseClicked(MouseEvent event)
{
	if (SwingUtilities.isMiddleMouseButton(event))
	{
		return event;
	}

	event.consume();
	return event;
}
 
Example 13
@Override
public MouseEvent mousePressed(MouseEvent event)
{
	if (SwingUtilities.isMiddleMouseButton(event))
	{
		return event;
	}

	if (SwingUtilities.isLeftMouseButton(event))
	{
		final Rectangle bounds = plugin.getSelectedWidgetBounds();

		if (bounds != null)
		{
			plugin.startCreation(bounds.getLocation(), bounds.getSize());
		}
		else
		{
			plugin.startCreation(event.getPoint());
		}
	}
	else if (plugin.isCreatingScreenMarker())
	{
		plugin.finishCreation(true);
	}

	event.consume();
	return event;
}
 
Example 14
@Override
public void mouseClicked(MouseEvent e) {
   if (ignoreClick()) {
      return;
   }
   if (SwingUtilities.isRightMouseButton(e) | SwingUtilities.isLeftMouseButton(e) && e.isControlDown()) {
      onRight(e);
   } else if (SwingUtilities.isLeftMouseButton(e)) {
      onLeft(e);
   } else if (SwingUtilities.isMiddleMouseButton(e)) {
      onMiddle(e);
   }
}
 
Example 15
public void mouseClicked(MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e)) handleClick(e);
    if (SwingUtilities.isMiddleMouseButton(e)) handleMiddleClick(e);
}
 
Example 16
Source Project: binnavi   File: CMousePressedHandler.java    License: Apache License 2.0 4 votes vote down vote up
public static IMouseStateChange handleMousePressed(final CStateFactory<?, ?> factory,
    final IMouseState defaultState, final AbstractZyGraph<?, ?> graph, final MouseEvent event) {
  final double x = graph.getEditMode().translateX(event.getX());
  final double y = graph.getEditMode().translateY(event.getY());

  final HitInfo hitInfo = graph.getGraph().getHitInfo(x, y);

  if (hitInfo.hasHitNodes()) {
    final Node n = hitInfo.getHitNode();

    if (SwingUtilities.isLeftMouseButton(event) && !event.isAltDown()) {
      return new CStateChange(factory.createNodePressedLeftState(n, event), true);
    } else if (SwingUtilities.isRightMouseButton(event)) {
      return new CStateChange(factory.createNodePressedRightState(n, event), true);
    } else if (SwingUtilities.isMiddleMouseButton(event)
        || (event.isAltDown() && SwingUtilities.isLeftMouseButton(event))) {
      return new CStateChange(factory.createNodePressedMiddleState(n, event), false);
    } else {
      // A button was pressed that does not have any special functionality.

      return new CStateChange(defaultState, true);
    }
  } else if (hitInfo.hasHitNodeLabels()) {
    throw new IllegalStateException("yFiles Labels are not in use...");
  } else if (hitInfo.hasHitEdges()) {
    final Edge edge = hitInfo.getHitEdge();

    if (SwingUtilities.isLeftMouseButton(event)) {
      return new CStateChange(factory.createEdgePressedLeftState(edge, event), true);
    } else if (SwingUtilities.isRightMouseButton(event)) {
      return new CStateChange(factory.createEdgePressedRightState(edge, event), true);
    } else {
      return new CStateChange(defaultState, true);
    }
  } else if (hitInfo.hasHitEdgeLabels()) {
    // final EdgeLabel label = hitInfo.getHitEdgeLabel();
    //
    // if (SwingUtilities.isLeftMouseButton(event))
    // {
    // return new CStateChange(factory.createEdgeLabelPressedLeftState(label, event), true);
    // }
    // else if (SwingUtilities.isRightMouseButton(event))
    // {
    // return new CStateChange(factory.createEdgeLabelPressedRightState(label, event), true);
    // }
    // else
    // {
    return new CStateChange(defaultState, true);
    // }
  } else if (hitInfo.hasHitBends()) {
    final Bend bend = hitInfo.getHitBend();

    if (SwingUtilities.isLeftMouseButton(event)) {
      return new CStateChange(factory.createBendPressedLeftState(bend, event), true);
    } else {
      return new CStateChange(defaultState, true);
    }
  } else if (hitInfo.hasHitPorts()) {
    return new CStateChange(factory.createDefaultState(), true);
  } else {
    if (SwingUtilities.isLeftMouseButton(event)) {
      return new CStateChange(factory.createBackgroundPressedLeftState(event), true);
    } else if (SwingUtilities.isRightMouseButton(event)) {
      return new CStateChange(factory.createBackgroundPressedRightState(event), true);
    }

    return new CStateChange(factory.createDefaultState(), true);
  }
}
 
Example 17
Source Project: binnavi   File: CNodeEditState.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IMouseStateChange mousePressed(final MouseEvent event, final AbstractZyGraph<?, ?> graph) {
  final double x = graph.getEditMode().translateX(event.getX());
  final double y = graph.getEditMode().translateY(event.getY());

  final HitInfo hitInfo = graph.getGraph().getHitInfo(x, y);

  if (hitInfo.hasHitNodes()) {
    final Node n = hitInfo.getHitNode();

    if (SwingUtilities.isLeftMouseButton(event) && !event.isAltDown()) {
      if (n == m_node) {
        if (!m_isDragging) {
          // Change caret
          CEditNodeHelper.setCaretStart(graph, n, event);
        } else {
          m_isDragging = false;
        }

        return new CStateChange(this, false);
      } else {
        m_factory.createNodeEditExitState(m_node, event);

        return new CStateChange(m_factory.createNodePressedLeftState(n, event), true);
      }
    } else if (SwingUtilities.isRightMouseButton(event)) {
      if (n == m_node) {
        // Do nothing

        return new CStateChange(this, false);
      } else {
        m_factory.createNodeEditExitState(m_node, event);

        return new CStateChange(m_factory.createNodePressedRightState(n, event), true);
      }
    } else if (SwingUtilities.isMiddleMouseButton(event)
        || (event.isAltDown() && SwingUtilities.isLeftMouseButton(event))) {
      if (n == m_node) {
        // m_factory.createNodeEditExitState(m_node, event);

        if (!m_isDragging) {
          // Change caret
          CEditNodeHelper.setCaretStart(graph, n, event);
        } else {
          m_isDragging = false;
        }

        return new CStateChange(this, false);
      } else {
        m_factory.createNodeEditExitState(m_node, event);

        return new CStateChange(m_factory.createNodePressedMiddleState(n, event), true);
      }
    } else {
      // A button was pressed that does not have any special functionality.

      return new CStateChange(this, false);
    }
  } else if (hitInfo.hasHitNodeLabels()) {
    throw new IllegalStateException();
  } else if (hitInfo.hasHitEdges()) {
    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createEdgePressedLeftState(hitInfo.getHitEdge(), event),
        true);
  } else if (hitInfo.hasHitEdgeLabels()) {
    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createEdgePressedLeftState(hitInfo.getHitEdgeLabel()
        .getEdge(), event), true);
  } else if (hitInfo.hasHitBends()) {
    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createBendPressedLeftState(hitInfo.getHitBend(), event),
        true);
  } else if (hitInfo.hasHitPorts()) {
    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createDefaultState(), true);
  } else {
    // User left-pressed the background.

    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createBackgroundPressedLeftState(event), true);
  }
}
 
Example 18
Source Project: binnavi   File: CNodeEditState.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IMouseStateChange mouseReleased(final MouseEvent event, final AbstractZyGraph<?, ?> graph) {
  final double x = graph.getEditMode().translateX(event.getX());
  final double y = graph.getEditMode().translateY(event.getY());

  final HitInfo hitInfo = graph.getGraph().getHitInfo(x, y);

  if (hitInfo.hasHitNodes()) {
    final Node n = hitInfo.getHitNode();

    if (SwingUtilities.isLeftMouseButton(event) && !event.isAltDown()) {
      if (n == m_node) {
        if (!m_isDragging) {
          // Change caret
          CEditNodeHelper.setCaretEnd(graph, n, event);
        } else {
          m_isDragging = false;
        }

        return new CStateChange(this, false);
      } else {
        m_factory.createNodeEditExitState(m_node, event);

        return new CStateChange(m_factory.createNodePressedLeftState(n, event), true);
      }
    } else if (SwingUtilities.isRightMouseButton(event)) {
      if (n == m_node) {
        // Show context menu

        // NH 10.08.2010
        // m_factory.editNodeRightClicked(m_node, event, x, y);

        return new CStateChange(this, false);
      } else {
        m_factory.createNodeEditExitState(m_node, event);

        return new CStateChange(m_factory.createNodePressedRightState(n, event), true);
      }
    } else if (SwingUtilities.isMiddleMouseButton(event)
        || (event.isAltDown() && SwingUtilities.isLeftMouseButton(event))) {
      if (n == m_node) {
        // m_factory.createNodeEditExitState(m_node, event);

        if (!m_isDragging) {
          // Change caret
          CEditNodeHelper.setCaretEnd(graph, n, event);
        } else {
          m_isDragging = false;
        }

        return new CStateChange(this, false);
      } else {
        m_factory.createNodeEditExitState(m_node, event);

        return new CStateChange(m_factory.createNodePressedMiddleState(n, event), true);
      }
    } else {
      // A button was pressed that does not have any special functionality.

      return new CStateChange(this, false);
    }
  } else if (hitInfo.hasHitNodeLabels()) {
    throw new IllegalStateException();
  } else if (hitInfo.hasHitEdges()) {
    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createEdgePressedLeftState(hitInfo.getHitEdge(), event),
        true);
  } else if (hitInfo.hasHitEdgeLabels()) {
    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createEdgePressedLeftState(hitInfo.getHitEdgeLabel()
        .getEdge(), event), true);
  } else if (hitInfo.hasHitBends()) {
    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createBendPressedLeftState(hitInfo.getHitBend(), event),
        true);
  } else if (hitInfo.hasHitPorts()) {
    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createDefaultState(), true);
  } else {
    // User left-pressed the background.

    m_factory.createNodeEditExitState(m_node, event);

    return new CStateChange(m_factory.createBackgroundPressedLeftState(event), true);
  }
}
 
Example 19
/**
 * Create an UIMouse from a Mouse Event.
 * @param e the mouse event
 * @return the UI mouse
 */
public static UIMouse from(MouseEvent e) {
	UIMouse m = new UIMouse();
	m.x = e.getX();
	m.y = e.getY();
	if (SwingUtilities.isLeftMouseButton(e)) {
		m.buttons.add(Button.LEFT);
	}
	if (SwingUtilities.isMiddleMouseButton(e)) {
		m.buttons.add(Button.MIDDLE);
	}
	if (SwingUtilities.isRightMouseButton(e)) {
		m.buttons.add(Button.RIGHT);
	}
	if (e.isShiftDown()) {
		m.modifiers.add(Modifier.SHIFT);
	}
	if (e.isControlDown()) {
		m.modifiers.add(Modifier.CTRL);
	}
	if (e.isAltDown()) {
		m.modifiers.add(Modifier.ALT);
	}
	switch (e.getID()) {
	case MouseEvent.MOUSE_CLICKED:
		m.type = e.getClickCount() == 1 ? Type.CLICK : Type.DOUBLE_CLICK;
		m.z = e.getClickCount();
		break;
	case MouseEvent.MOUSE_PRESSED:
		m.type = Type.DOWN;
		break;
	case MouseEvent.MOUSE_RELEASED:
		m.type = Type.UP;
		break;
	case MouseEvent.MOUSE_MOVED:
		m.type = Type.MOVE;
		break;
	case MouseEvent.MOUSE_DRAGGED:
		m.type = Type.DRAG;
		break;
	case MouseEvent.MOUSE_ENTERED:
		m.type = Type.ENTER;
		break;
	case MouseEvent.MOUSE_EXITED:
		m.type = Type.LEAVE;
		break;
	case MouseEvent.MOUSE_WHEEL:
		m.type = Type.WHEEL;
		m.z = ((MouseWheelEvent)e).getUnitsToScroll();
		break;
	default:
	}
	
	return m;
}