当前位置: 首页>>代码示例>>Java>>正文


Java MouseEvent.MOUSE_PRESSED属性代码示例

本文整理汇总了Java中java.awt.event.MouseEvent.MOUSE_PRESSED属性的典型用法代码示例。如果您正苦于以下问题:Java MouseEvent.MOUSE_PRESSED属性的具体用法?Java MouseEvent.MOUSE_PRESSED怎么用?Java MouseEvent.MOUSE_PRESSED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.awt.event.MouseEvent的用法示例。


在下文中一共展示了MouseEvent.MOUSE_PRESSED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isRightMouseButton

static boolean isRightMouseButton(MouseEvent me) {
    int numButtons = ((Integer)getDefaultToolkit().getDesktopProperty("awt.mouse.numButtons")).intValue();
    switch (me.getID()) {
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
          return ((numButtons == 2 && me.getButton() == MouseEvent.BUTTON2) ||
                   (numButtons > 2 && me.getButton() == MouseEvent.BUTTON3));
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_DRAGGED:
          return ((numButtons == 2 && (me.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0) ||
                  (numButtons > 2 && (me.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0));
    }
    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:XToolkit.java

示例2: eventDispatched

@Override public void eventDispatched(AWTEvent event) {
    if (ignoreMouseEvents) {
        return;
    }
    Component root = SwingUtilities.getRoot((Component) event.getSource());
    if (root instanceof IRecordingArtifact || root.getName().startsWith("###")) {
        return;
    }
    if (!(event instanceof MouseEvent)) {
        return;
    }
    MouseEvent mouseEvent = (MouseEvent) event;
    mouseEvent.consume();
    if (event.getID() == MouseEvent.MOUSE_PRESSED) {
        disposeOverlay();
        Component mouseComponent = SwingUtilities.getDeepestComponentAt(mouseEvent.getComponent(), mouseEvent.getX(),
                mouseEvent.getY());
        if (mouseComponent == null) {
            return;
        }
        mouseEvent = SwingUtilities.convertMouseEvent(mouseEvent.getComponent(), mouseEvent, mouseComponent);
        setComponent(mouseComponent, mouseEvent.getPoint(), true);
        return;
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:25,代码来源:ContextMenuWindow.java

示例3: pressGeneratesSameEvents

public void pressGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_PRESSED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    b.click();
    AssertJUnit.assertEquals(expected, t.getText());

    tclear();
    new Actions(driver).moveToElement(b).click().perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:40,代码来源:NativeEventsTest.java

示例4: eventDispatched

/**
 * Popup should be closed under some circumstances. Namely when mouse is
 * pressed or released outside of popup or when key is pressed during the
 * time popup is visible.
 */
public void eventDispatched(AWTEvent event) {
    if (event.getSource() == this) {
        return;
    }
    if (event instanceof MouseEvent) {
        if (event.getID() == MouseEvent.MOUSE_RELEASED) {
            long time = System.currentTimeMillis();
            // check if button was just slowly clicked
            if (time - invocationTime > 500) {
                if (!onSwitcherTable((MouseEvent) event)) {
                    // Don't take any chances
                    hideCurrentPopup();
                }
            }
        } else if (event.getID() == MouseEvent.MOUSE_PRESSED) {
            if (!onSwitcherTable((MouseEvent) event)) {
                // Don't take any chances
                if (event.getSource() != invokingComponent) {
                    // If it's the invoker, don't do anything - it will
                    // generate another call to invoke(), which will do the
                    // hiding - if we do it here, it will get shown again
                    // when the button processes the event
                    hideCurrentPopup();
                }
            }
        }
    } else if (event instanceof KeyEvent) {
        if (event.getID() == KeyEvent.KEY_PRESSED) {
            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
            hideCurrentPopup();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:ButtonPopupSwitcher.java

示例5: handleJavaMouseEvent

void handleJavaMouseEvent(MouseEvent e) {
        switch (e.getID()) {
          case MouseEvent.MOUSE_PRESSED:
              if (target == e.getSource() &&
                  !target.isFocusOwner() &&
                  XKeyboardFocusManagerPeer.shouldFocusOnClick(target))
              {
                  XWindowPeer parentXWindow = getParentTopLevel();
                  Window parentWindow = ((Window)parentXWindow.getTarget());
                  // Simple windows are non-focusable in X terms but focusable in Java terms.
                  // As X-non-focusable they don't receive any focus events - we should generate them
                  // by ourselfves.
//                   if (parentXWindow.isFocusableWindow() /*&& parentXWindow.isSimpleWindow()*/ &&
//                       !(getCurrentNativeFocusedWindow() == parentWindow))
//                   {
//                       setCurrentNativeFocusedWindow(parentWindow);
//                       WindowEvent wfg = new WindowEvent(parentWindow, WindowEvent.WINDOW_GAINED_FOCUS);
//                       parentWindow.dispatchEvent(wfg);
//                   }
                  XKeyboardFocusManagerPeer.requestFocusFor(target, CausedFocusEvent.Cause.MOUSE_EVENT);
              }
              break;
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:XComponentPeer.java

示例6: handleEvent

@Override
public void handleEvent(java.awt.AWTEvent e) {
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        emulateActivation(true);
    }
    super.handleEvent(e);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:WLightweightFramePeer.java

示例7: eventToString

private static String eventToString(MouseEvent e) {
    StringBuilder result = new StringBuilder();

    switch (e.getID()) {
        case MouseEvent.MOUSE_PRESSED:
            result.append("MOUSE_PRESSED");
            break;
        case MouseEvent.MOUSE_RELEASED:
            result.append("MOUSE_RELEASED");
            break;
        case MouseEvent.MOUSE_CLICKED:
            result.append("MOUSE_CLICKED");
            break;
        case MouseEvent.MOUSE_ENTERED:
            result.append("MOUSE_ENTERED");
            break;
        case MouseEvent.MOUSE_EXITED:
            result.append("MOUSE_EXITED");
            break;
        case MouseEvent.MOUSE_MOVED:
            result.append("MOUSE_MOVED");
            break;
        case MouseEvent.MOUSE_DRAGGED:
            result.append("MOUSE_DRAGGED");
            break;
        case MouseEvent.MOUSE_WHEEL:
            result.append("MOUSE_WHEEL");
            break;
        default:
            result.append("unknown type");
    }

    result.append(", modifiers = " + MouseEvent.getMouseModifiersText(e.getModifiers()));
    result.append(", modifiersEx = " + MouseEvent.getMouseModifiersText(e.getModifiersEx()));
    result.append(", button = " + e.getButton());

    return result.toString();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:38,代码来源:bug7146377.java

示例8: processMouseEvent

@Override
protected void processMouseEvent(MouseEvent e) {
    switch(e.getID()) {
      case MouseEvent.MOUSE_PRESSED:
          selectionDisabled = false;
          break;
      case MouseEvent.MOUSE_RELEASED:
          selectionDisabled = false;
          break;
      case MouseEvent.MOUSE_CLICKED:
          selectionDisabled = false;
          break;
      case MouseEvent.MOUSE_ENTERED:
          selectionDisabled = false;
          break;
      case MouseEvent.MOUSE_EXITED:
          selectionDisabled = false;
          break;
      case MouseEvent.MOUSE_MOVED:
          break;
      case MouseEvent.MOUSE_DRAGGED:
          if (selectionDisabled) {
              //System.err.println("\nDrag DISABLED.");
              return ;
          }
          break;
      case MouseEvent.MOUSE_WHEEL:
          break;
    }
    super.processMouseEvent(e);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:Outline.java

示例9: eventDispatched

@Override
    public void eventDispatched(AWTEvent event) {
        if (event.getID() == MouseEvent.MOUSE_PRESSED) {
            onClick(event);
/*
        } else if (event.getID() == KeyEvent.KEY_PRESSED) {
            if (((KeyEvent) event).getKeyCode() == KeyEvent.VK_ESCAPE) {
                shutdown();
            }
*/
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:DiffActionTooltipWindow.java

示例10: processEventImpl

private void processEventImpl(AWTEvent e) {
    super.processEvent(e);
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        if (isFocusable()) requestFocus();
        else button.requestFocus();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:DropdownButton.java

示例11: isLeftMouseButton

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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:XToolkit.java

示例12: processMouseEvent

/** Forwards mouse events to a renderer (tree).
 */
private void processMouseEvent(MouseEvent e) {
    if (shouldIgnore(e)) {
        return;
    }

    Point p = e.getPoint();
    int row = table.rowAtPoint(p);
    int column = table.columnAtPoint(p);

    // The autoscroller can generate drag events outside the Table's range. 
    if ((column == -1) || (row == -1)) {
        return;
    }

    // for automatic jemmy testing purposes
    if ((getEditingColumn() == column) && (getEditingRow() == row)) {
        return;
    }

    boolean changeSelection = true;

    if (isTreeColumn(column)) {
        TreePath path = tree.getPathForRow(TreeTable.this.rowAtPoint(e.getPoint()));
        Rectangle r = tree.getPathBounds(path);
 
        if ((e.getX() >= (r.x - positionX)) && (e.getX() <= (r.x - positionX + r.width))
            || isLocationInExpandControl( path, p )
            || e.getID() == MouseEvent.MOUSE_RELEASED || e.getID() == MouseEvent.MOUSE_CLICKED ) {
            changeSelection = false;
        }
    }

    if (table.getSelectionModel().isSelectedIndex(row) && e.isPopupTrigger()) {
        return;
    }

    if (table.editCellAt(row, column, e)) {
        setDispatchComponent(e);
        repostEvent(e);
    }

    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        table.requestFocus();
    }

    CellEditor editor = table.getCellEditor();

    if (changeSelection && ((editor == null) || editor.shouldSelectCell(e))) {
        setValueIsAdjusting(true);
        table.changeSelection(row, column, 
                Utilities.isMac() ? e.isMetaDown() : e.isControlDown(), //use META key on Mac to toggle selection
                e.isShiftDown());
        setValueIsAdjusting(false);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:57,代码来源:TreeTable.java

示例13: onCustomEditorButton

/**  Returns true if a mouse event occured over the custom editor button.
 *   This is used to supply button specific tooltips and launch the custom
 *   editor without needing to instantiate a real button */
private boolean onCustomEditorButton(MouseEvent e) {
    //see if we're in the approximate bounds of the custom editor button
    Point pt = e.getPoint();
    int row = rowAtPoint(pt);
    int col = columnAtPoint(pt);
    FeatureDescriptor fd = getSheetModel().getPropertySetModel().getFeatureDescriptor(row);
    if( null == fd ) {
        //prevent NPE when the activated Node has been destroyed and a new one hasn't been set yet
        return false;
    }

    //see if the event happened over the custom editor button
    boolean success;

    if (PropUtils.noCustomButtons) {
        //#41412 - impossible to invoke custom editor on props w/ no inline
        //edit mode if the no custom buttons switch is set
        success = false;
    } else {
        success = e.getX() > (getWidth() - PropUtils.getCustomButtonWidth());
    }

    //if it's a mouse button event, then we're not showing a tooltip, we're
    //deciding if we should display a custom editor.  For read-only props that
    //support one, we should return true, since clicking the non-editable cell
    //is not terribly useful.
    if (
        (e.getID() == MouseEvent.MOUSE_PRESSED) || (e.getID() == MouseEvent.MOUSE_RELEASED) ||
            (e.getID() == MouseEvent.MOUSE_CLICKED)
    ) {
        //We will show the custom editor for any click on the text value
        //of a property that looks editable but sets canEditAsText to false -
        //the click means the user is trying to edit something, so to just
        //swallow the gesture is confusing
        success |= Boolean.FALSE.equals(fd.getValue("canEditAsText"));

        if (!success && fd instanceof Property) {
            PropertyEditor pe = PropUtils.getPropertyEditor((Property) fd);

            if ((pe != null) && pe.supportsCustomEditor()) {
                //Undocumented but used in Studio - in NB 3.5 and earlier, returning null from getAsText()
                //was a way to make a property non-editable
                success |= (pe.isPaintable() && (pe.getAsText() == null) && (pe.getTags() == null));
            }
        }
    }

    try {
        if (success) { //NOI18N

            if (fd instanceof Property && (col == 1)) {
                boolean supp = PropUtils.getPropertyEditor((Property) fd).supportsCustomEditor();

                return (supp);
            }
        }
    } catch (IllegalStateException ise) {
        //See bugtraq 4941073 - if a property accessed via Reflection throws
        //an unexpected exception (try customize bean on a vanilla GenericServlet
        //to produce this) when the getter is accessed, then we are already
        //displaying "Error fetching property value" in the value area of
        //the propertysheet.  No point in distracting the user with a 
        //stack trace - it's not our bug.
        Logger.getLogger(SheetTable.class.getName()).log(Level.WARNING, null, ise);
    }

    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:71,代码来源:SheetTable.java

示例14: testClickInvokesCustomEditor

public void testClickInvokesCustomEditor() throws Exception {
    if( !ExtTestCase.canSafelyRunFocusTests() )
        return;
    
    Node n = new ANode();
    setCurrentNode (n, sheet);

    sleep();

    requestFocus (sheet.table);
    sleep();

    Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    if (owner == sheet.table) { //sanity check to avoid random failures on some window managers

        System.out.println ("About to click cell");

        Rectangle r = sheet.table.getCellRect(1, 1, false);
        final MouseEvent me = new MouseEvent (sheet.table, MouseEvent.MOUSE_PRESSED,
            System.currentTimeMillis(), MouseEvent.BUTTON1_MASK, r.x + 3,
            r.y + 3, 2, false);

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                sheet.table.dispatchEvent(me);
            }
        });

        sleep();
        sleep();

        System.out.println ("Now checking focus");

        owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        assertTrue ("Focus owner should be custom editor, not " + owner, owner instanceof JTextArea);

        JComponent jc = (JComponent) owner;
        assertTrue ("Custom editor should have been invoked, but focus owner's top level ancestor is not a dialog", jc.getTopLevelAncestor() instanceof Dialog);

        Dialog d = (Dialog) jc.getTopLevelAncestor();

        d.setVisible(false);
    }

    requestFocus (sheet.table);
    sleep();

    owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    if (owner == sheet.table) { //sanity check to avoid random failures on some window managers
        pressKey(sheet.table, KeyEvent.VK_SPACE);
        sleep();

        owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
        assertTrue ("After pressing a key, focus owner should still be the table, not " + owner, sheet.table == owner);
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:57,代码来源:NonEditabilityTest.java

示例15: handleJavaMouseEvent

void handleJavaMouseEvent(MouseEvent e) {
    super.handleJavaMouseEvent(e);
    int id = e.getID();
    switch (id) {
      case MouseEvent.MOUSE_PRESSED:
          if (XToolkit.isLeftMouseButton(e) ) {
              Button b = (Button) e.getSource();

              if(b.contains(e.getX(), e.getY())) {
                  if (!isEnabled()) {
                      // Disabled buttons ignore all input...
                      return;
                  }
                  pressed = true;
                  armed = true;
                  repaint();
              }
          }

          break;

      case MouseEvent.MOUSE_RELEASED:
          if (XToolkit.isLeftMouseButton(e)) {
              if (armed)
              {
                  @SuppressWarnings("deprecation")
                  final int modifiers = e.getModifiers();
                  action(e.getWhen(), modifiers);
              }
              pressed = false;
              armed = false;
              repaint();
          }

          break;

      case  MouseEvent.MOUSE_ENTERED:
          if (pressed)
              armed = true;
          break;
      case MouseEvent.MOUSE_EXITED:
          armed = false;
          break;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:XButtonPeer.java


注:本文中的java.awt.event.MouseEvent.MOUSE_PRESSED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。