Пример #1
0
 /**
  * Manages mouse clicks
  *
  * @param e the event
  * @see javax.swing.text.DefaultCaret#mouseClicked(java.awt.event.MouseEvent)
  */
 public void mouseClicked(MouseEvent e) {
   if (SwingUtilities.isMiddleMouseButton(e) && e.getClickCount() == 1) {
     /** * PASTE USING MIDDLE BUTTON ** */
     JTextComponent c = (JTextComponent) e.getSource();
     if (c != null) {
       Toolkit tk = c.getToolkit();
       Clipboard buffer = tk.getSystemSelection();
       if (buffer != null) {
         Transferable trans = buffer.getContents(null);
         if (trans.isDataFlavorSupported(DataFlavor.stringFlavor)) {
           try {
             String pastedText = (String) trans.getTransferData(DataFlavor.stringFlavor);
             ((JTextPane) getConsole().getConfiguration().getInputCommandView())
                 .replaceSelection(pastedText);
           } catch (UnsupportedFlavorException e1) {
             e1.printStackTrace();
           } catch (IOException e1) {
             e1.printStackTrace();
           }
         }
       }
     }
   } else if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1) {
     /** * SEND THE FOCUS TO THE INPUT COMMAND VIEW ** */
     ((JTextPane) getConsole().getConfiguration().getInputCommandView()).requestFocus();
     ((JTextPane) getConsole().getConfiguration().getInputCommandView())
         .getCaret()
         .setVisible(true);
   } else {
     /** * DELEGATE TO THE SYSTEM ** */
     super.mouseClicked(e);
   }
 }
Пример #2
0
  @Override
  public final void mousePressed(final MouseEvent e) {
    if (!isEnabled() || !isFocusable()) return;

    requestFocusInWindow();
    caret(true);

    if (SwingUtilities.isMiddleMouseButton(e)) copy();

    final boolean shift = e.isShiftDown();
    final boolean selected = editor.selected();
    if (SwingUtilities.isLeftMouseButton(e)) {
      final int c = e.getClickCount();
      if (c == 1) {
        // selection mode
        if (shift) editor.startSelection(true);
        select(e.getPoint(), !shift);
      } else if (c == 2) {
        editor.selectWord();
      } else {
        editor.selectLine();
      }
    } else if (!selected) {
      select(e.getPoint(), true);
    }
  }
Пример #3
0
  @Override
  public final void mousePressed(final MouseEvent e) {
    if (!isEnabled() || !isFocusable()) return;

    requestFocusInWindow();
    cursor(true);

    if (SwingUtilities.isMiddleMouseButton(e)) copy();

    final boolean marking = e.isShiftDown();
    final boolean nomark = !text.marked();
    if (SwingUtilities.isLeftMouseButton(e)) {
      final int c = e.getClickCount();
      if (c == 1) {
        // selection mode
        if (marking && nomark) text.startMark();
        rend.select(scroll.pos(), e.getPoint(), marking);
      } else if (c == 2) {
        text.selectWord();
      } else {
        text.selectLine();
      }
    } else if (nomark) {
      rend.select(scroll.pos(), e.getPoint(), false);
    }
  }
Пример #4
0
 @Override
 public void mouseClicked(final MouseEvent e) {
   if (!SwingUtilities.isMiddleMouseButton(e)) return;
   if (!paste()) return;
   finish();
   repaint();
 }
  protected boolean isAssertTrigger(AWTEvent event) {
    if (event == null || !(event instanceof MouseEvent)) {
      return false;
    }
    MouseEvent mouseEvent = ((MouseEvent) event);

    return MouseEvent.MOUSE_RELEASED == mouseEvent.getID()
        && SwingUtilities.isMiddleMouseButton(mouseEvent);
  }
Пример #6
0
 /**
  * Event handler when mouse is clicked
  *
  * @param e object that holds mouse event
  */
 public void mouseClicked(MouseEvent e) {
   int tabNumber = getUI().tabForCoordinate(this, e.getX(), e.getY());
   if (tabNumber < 0) return;
   if (SwingUtilities.isMiddleMouseButton(e)) {
     this.closeTab(tabNumber);
     return;
   }
   if (!(getIconAt(tabNumber) instanceof CloseTabIcon)) {
     return;
   }
   Rectangle rect = ((CloseTabIcon) getIconAt(tabNumber)).getBounds();
   if (rect.contains(e.getX(), e.getY())) {
     this.closeTab(tabNumber);
   }
 }
Пример #7
0
 private static int createButtonCode(MouseEvent event) {
   // for mouse dragged, button is stored in modifiers
   if (SwingUtilities.isLeftMouseButton(event)) {
     return MouseButtonCodes.LEFT;
   } else if (SwingUtilities.isMiddleMouseButton(event)) {
     return MouseButtonCodes.MIDDLE;
   } else if (SwingUtilities.isRightMouseButton(event)) {
     return MouseButtonCodes
         .NONE; // we don't handle right mouse button as it used for the context menu invocation
   } else if (event instanceof MouseWheelEvent) {
     if (((MouseWheelEvent) event).getWheelRotation() > 0) {
       return MouseButtonCodes.SCROLLUP;
     } else {
       return MouseButtonCodes.SCROLLDOWN;
     }
   }
   return MouseButtonCodes.NONE;
 }
  /**
   * Called when a Mouse-Event occurs
   *
   * @param e Event
   */
  private void mouseClickedOnTable(final MouseEvent e) {
    final Program prg = getProgramByClick(e);

    if (prg == null) {
      return;
    }
    if (SwingUtilities.isLeftMouseButton(e)
        && (e.getClickCount() == 1)
        && e.getModifiersEx() == 0) {
      mLeftClickThread =
          new Thread("Single left click") {
            @Override
            public void run() {
              try {
                mPerformingSingleClick = false;
                sleep(Plugin.SINGLE_CLICK_WAITING_TIME);
                mPerformingSingleClick = true;

                Plugin.getPluginManager().handleProgramSingleClick(prg, mPlugin);
                mPerformingSingleClick = false;
              } catch (InterruptedException e) { // ignore
              }
            }
          };

      mLeftClickThread.setPriority(Thread.MIN_PRIORITY);
      mLeftClickThread.start();
    } else if (SwingUtilities.isLeftMouseButton(e)
        && (e.getClickCount() == 2)
        && e.getModifiersEx() == 0) {
      if (!mPerformingSingleClick && mLeftClickThread != null && mLeftClickThread.isAlive()) {
        mLeftClickThread.interrupt();
      }

      if (!mPerformingSingleClick) {
        devplugin.Plugin.getPluginManager().handleProgramDoubleClick(prg, mPlugin);
      }
    } else if (SwingUtilities.isMiddleMouseButton(e) && (e.getClickCount() == 1)) {
      mMiddleSingleClickThread =
          new Thread("Single click") {
            @Override
            public void run() {
              try {
                mPerformingMiddleSingleClick = false;
                sleep(Plugin.SINGLE_CLICK_WAITING_TIME);
                mPerformingMiddleSingleClick = true;

                Plugin.getPluginManager().handleProgramMiddleClick(prg, mPlugin);
                mPerformingMiddleSingleClick = false;
              } catch (InterruptedException e) { // ignore
              }
            }
          };

      mMiddleSingleClickThread.setPriority(Thread.MIN_PRIORITY);
      mMiddleSingleClickThread.start();
    } else if (SwingUtilities.isMiddleMouseButton(e) && (e.getClickCount() == 2)) {
      if (!mPerformingMiddleSingleClick
          && mMiddleSingleClickThread != null
          && mMiddleSingleClickThread.isAlive()) {
        mMiddleSingleClickThread.interrupt();
      }

      if (!mPerformingMiddleSingleClick) {
        devplugin.Plugin.getPluginManager().handleProgramMiddleDoubleClick(prg, mPlugin);
      }
    }
  }
Пример #9
0
 @Override
 public void mouseClicked(final MouseEvent e) {
   if (!SwingUtilities.isMiddleMouseButton(e)) return;
   new PasteCmd().execute(gui);
 }
Пример #10
0
  /**
   * An implementation of the the DisplayListener interface. This method turns on/off the wait
   * cursor when it gets a WAIT_ON or WAIT_OFF event. It also, when it receives a FRAME_DONE event
   * for the fist time, calls <code>firstFrameDone</code> on the {@link DisplayControl}s
   *
   * @param de The <code>DisplayEvent</code>
   * @throws RemoteException
   * @throws VisADException
   */
  public void displayChanged(DisplayEvent de) throws VisADException, RemoteException {
    if (getIsDestroyed()) {
      return;
    }

    int eventId = de.getId();
    InputEvent inputEvent = de.getInputEvent();

    if ((inputEvent instanceof MouseEvent) && (eventId == DisplayEvent.MOUSE_PRESSED)) {
      mousePressedTime = System.currentTimeMillis();
      getViewpointControl().setAutoRotate(false);
      startMoveMatrix = getProjectionControl().getMatrix();

      MouseEvent mouseEvent = (MouseEvent) inputEvent;

      mouseStartPoint = new Point(mouseEvent.getX(), mouseEvent.getY());

      if ((mouseEvent.getClickCount() > 1) && mouseEvent.isShiftDown()) {
        NavigatedDisplay navDisplay = getNavigatedDisplay();
        double[] box =
            navDisplay.getSpatialCoordinatesFromScreen(mouseEvent.getX(), mouseEvent.getY());

        navDisplay.center(navDisplay.getEarthLocation(box));
      }
    }

    if ((eventId == DisplayEvent.MOUSE_PRESSED) || (eventId == DisplayEvent.MOUSE_DRAGGED)) {
      mouseMovedTime = System.currentTimeMillis();

      MouseEvent mouseEvent = (MouseEvent) inputEvent;
      int[][][] functionMap = getMaster().getMouseFunctionMap();

      if (functionMap != null) {
        int ctrlIdx = (GuiUtils.isControlKey(mouseEvent) ? 1 : 0);
        int shiftIdx = (mouseEvent.isShiftDown() ? 1 : 0);
        int mouseIdx =
            ((SwingUtilities.isLeftMouseButton(mouseEvent)
                    && !SwingUtilities.isRightMouseButton(mouseEvent))
                ? 0
                : (SwingUtilities.isMiddleMouseButton(mouseEvent)
                    ? 1
                    : ((SwingUtilities.isRightMouseButton(mouseEvent)
                            && !SwingUtilities.isLeftMouseButton(mouseEvent))
                        ? 2
                        : 1)));
        int function = functionMap[mouseIdx][ctrlIdx][shiftIdx];

        if (function == MouseHelper.CURSOR_TRANSLATE) {
          if (cursorReadoutWindow == null) {
            cursorReadoutWindow = new CursorReadoutWindow(this);
          }

          cursorReadoutWindow.handleMousePressedOrDragged(mouseEvent);
        }
      }
    } else if (eventId == DisplayEvent.MOUSE_RELEASED) {
      MouseEvent mouseEvent = (MouseEvent) inputEvent;

      if (cursorReadoutWindow != null) {
        cursorReadoutWindow.handleMouseReleased(mouseEvent);
        cursorReadoutWindow = null;
      }

      Point mouseStart = mouseStartPoint;

      if (mouseStart != null) {
        Point toPoint = new Point(mouseEvent.getX(), mouseEvent.getY());
        double distance = GuiUtils.distance(mouseStart.x, mouseStart.y, toPoint.x, toPoint.y);
        long deltaTime = System.currentTimeMillis() - mouseMovedTime;

        if (System.currentTimeMillis() - mousePressedTime > 0) {
          double speed = distance / (System.currentTimeMillis() - mousePressedTime);

          if ((distance > 50) && (deltaTime < 200) && (speed > 0.5)) {
            double[] endMatrix = getProjectionControl().getMatrix();

            mouseFlicked(mouseStart, toPoint, startMoveMatrix, endMatrix, speed);
          }
        }
      }

      mouseMovedTime = -1;
    }

    super.displayChanged(de);
  }