Ejemplo n.º 1
0
private void Drop (MouseEvent ev)
    {
	switch (state) {
	case stateDrag:
	    state = stateIdle;
	    CheckResize ();
	    break;

	case stateCreate:
	    CGNode node = new CGNode (ev.getX(), ev.getY(), "something",
				      getFontMetrics (getFont()),
				      !curnode.IsConcept());
            curnode.AddChild (node, curarrow);
            node.SetParent (curnode, curarrow);
            ToBottom (curarrow);
            Add (node);

	    if (!node.IsConcept()) {
		int x = ev.getX() + node.Bbox().width + layoutXDist;
		CGNode node2 = new CGNode (x, ev.getY(), "something",
					   getFontMetrics (getFont()),
					   true);
		CGArrow arrow2 = new CGArrow (0, 0, 0, 0);
		node.AddChild (node2, arrow2);
		node2.SetParent (node, arrow2);
		Add (node2);
		Add (arrow2);
                ToBottom (arrow2);
	    }
            state = stateIdle;
            NotifyViewers();
            break;
	}
        ShowStatus (ev.getX(), ev.getY());
    }
Ejemplo n.º 2
0
    private void showJPopupMenu(MouseEvent e) {
      try {
        if (e.isPopupTrigger() && menu != null) {
          if (window == null) {

            if (isWindows) {
              window = new JDialog((Frame) null);
              ((JDialog) window).setUndecorated(true);
            } else {
              window = new JWindow((Frame) null);
            }
            window.setAlwaysOnTop(true);
            Dimension size = menu.getPreferredSize();

            Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
            if (e.getY() > centerPoint.getY()) window.setLocation(e.getX(), e.getY() - size.height);
            else window.setLocation(e.getX(), e.getY());

            window.setVisible(true);

            menu.show(((RootPaneContainer) window).getContentPane(), 0, 0);

            // popup works only for focused windows
            window.toFront();
          }
        }
      } catch (Exception ignored) {
      }
    }
Ejemplo n.º 3
0
  @Override
  public void mouseDragged(MouseEvent e) {

    if (_mousedown != null && _up == null) {
      _display_offset[0] += e.getX() - _mousedown[0];
      _display_offset[1] += e.getY() - _mousedown[1];
      _mousedown = new int[] {e.getX(), e.getY()};
    }
    if (_up != null) {
      if (_up.getType() == BoardObject.type.ROAD) {
        if (((Road) _up).oneDown == false) {
          _up.setX(e.getX());
          _up.setY(e.getY());
        } else {
          ((Road) _up).setX2(e.getX());
          ((Road) _up).setY2(e.getY());
        }
      } else {
        _up.setX(e.getX() - _up.getW() / 2);
        _up.setY(e.getY() - _up.getH() / 2);
      }
    }

    repaint();
  }
Ejemplo n.º 4
0
    public void mousePressed(MouseEvent evt) {
      requestFocus();

      // Focus events not fired sometimes?
      setCaretVisible(true);
      focusedComponent = JEditTextArea.this;

      if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) != 0 && popup != null) {
        popup.show(painter, evt.getX(), evt.getY());
        return;
      }

      int line = yToLine(evt.getY());
      int offset = xToOffset(line, evt.getX());
      int dot = getLineStartOffset(line) + offset;

      switch (evt.getClickCount()) {
        case 1:
          doSingleClick(evt, line, offset, dot);
          break;
        case 2:
          // It uses the bracket matching stuff, so
          // it can throw a BLE
          try {
            doDoubleClick(evt, line, offset, dot);
          } catch (BadLocationException bl) {
            bl.printStackTrace();
          }
          break;
        case 3:
          doTripleClick(evt, line, offset, dot);
          break;
      }
    }
Ejemplo n.º 5
0
  public void mousePressed(MouseEvent e) {
    System.out.println("mousePressed");
    Point1 p2;
    switch (toolFlag) {
      case 3: // 直线
        x = (int) e.getX();
        y = (int) e.getY();
        p2 = new Point1(x, y, c, toolFlag, con);
        paintInfo.addElement(p2);
        break;

      case 4: // 圆
        x = (int) e.getX();
        y = (int) e.getY();
        p2 = new Point1(x, y, c, toolFlag, con);
        paintInfo.addElement(p2);
        break;

      case 5: // 矩形
        x = (int) e.getX();
        y = (int) e.getY();
        p2 = new Point1(x, y, c, toolFlag, con);
        paintInfo.addElement(p2);
        break;

      default:
    }
  }
Ejemplo n.º 6
0
 /** Select or grow image when clicked. */
 public void mousePressed(MouseEvent e) {
   Dimension size = fComponent.getSize();
   if (e.getX() >= size.width - 7 && e.getY() >= size.height - 7 && getSelectionState() == 2) {
     // Click in selected grow-box:
     if (DEBUG) System.out.println("ImageView: grow!!! Size=" + fWidth + "x" + fHeight);
     Point loc = fComponent.getLocationOnScreen();
     fGrowBase = new Point(loc.x + e.getX() - fWidth, loc.y + e.getY() - fHeight);
     fGrowProportionally = e.isShiftDown();
   } else {
     // Else select image:
     fGrowBase = null;
     JTextComponent comp = (JTextComponent) fContainer;
     int start = fElement.getStartOffset();
     int end = fElement.getEndOffset();
     int mark = comp.getCaret().getMark();
     int dot = comp.getCaret().getDot();
     if (e.isShiftDown()) {
       // extend selection if shift key down:
       if (mark <= start) comp.moveCaretPosition(end);
       else comp.moveCaretPosition(start);
     } else {
       // just select image, without shift:
       if (mark != start) comp.setCaretPosition(start);
       if (dot != end) comp.moveCaretPosition(end);
     }
   }
 }
    public void mouseClicked(MouseEvent e) {
      int selRow = tree.getRowForLocation(e.getX(), e.getY());
      TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());

      if (e.getClickCount() == 2) {
        myDoubleClick(selRow, selPath);
      }
    }
Ejemplo n.º 8
0
  @Override
  public final void mouseDragged(final MouseEvent e) {
    if (!SwingUtilities.isLeftMouseButton(e)) return;

    // selection mode
    select(e.getPoint(), false);
    final int y = Math.max(20, Math.min(e.getY(), getHeight() - 20));
    if (y != e.getY()) scroll.pos(scroll.pos() + e.getY() - y);
  }
Ejemplo n.º 9
0
 public void mouseDragged(MouseEvent e) {
   int m = e.getModifiers();
   int type = DnDEvent.DND_ONE;
   if (e.isControlDown()) type = DnDEvent.DND_LINE;
   else if (((m & InputEvent.BUTTON2_MASK) != 0) || ((m & InputEvent.BUTTON3_MASK) != 0))
     type = DnDEvent.DND_END;
   if (startPoint == null) startPoint = new Point(e.getX(), e.getY());
   fireDragToolbar(e.getX() - startPoint.x, (e.getY() - startPoint.y), type);
   dragging = true;
 }
Ejemplo n.º 10
0
 public void mousePressed(MouseEvent e) {
   if ((e.getModifiers() & java.awt.event.MouseEvent.BUTTON1_MASK) != 0) {
     this.startX = e.getX();
     this.startY = e.getY();
     System.out.println(startX);
     System.out.println(startY);
   } else if ((e.getModifiers() & java.awt.event.MouseEvent.BUTTON3_MASK) != 0) {
     panel.popup.show(panel, e.getX(), e.getY());
   }
 }
Ejemplo n.º 11
0
 public void mouseMoved(MouseEvent e) {
   if (isEnabled()) {
     setXY(
         ((double) e.getX() - (double) getWidth() / (double) 2)
             / ((double) (getWidth() + 1) / 2.0),
         -((double) e.getY() - (double) getHeight() / (double) 2)
             / ((double) (getHeight() + 1) / 2.0));
     face.setEmotion(p, a, d, e.getX(), e.getY());
   }
   paint();
 }
Ejemplo n.º 12
0
 /** Handles mouse down events. The event is delegated to the currently active tool. */
 public void mousePressed(MouseEvent e) {
   try {
     requestFocus(); // JDK1.1
     Point p = constrainPoint(new Point(e.getX(), e.getY()));
     setLastClick(new Point(e.getX(), e.getY()));
     tool().mouseDown(e, p.x, p.y);
     checkDamage();
   } catch (Throwable t) {
     handleMouseEventException(t);
   }
 }
Ejemplo n.º 13
0
 /**
  * Hook method which can be overriden by subclasses to provide specialised behaviour in the event
  * of a popup trigger.
  */
 protected void handlePopupMenu(MouseEvent e, int x, int y) {
   Figure figure = drawing().findFigure(e.getX(), e.getY());
   if (figure != null) {
     Object attribute = figure.getAttribute(Figure.POPUP_MENU);
     if (attribute == null) {
       figure = drawing().findFigureInside(e.getX(), e.getY());
     }
     if (figure != null) {
       showPopupMenu(figure, e.getX(), e.getY(), e.getComponent());
     }
   }
 }
Ejemplo n.º 14
0
  @Override
  public void mouseReleased(MouseEvent evt) {
    dragLocation = new Point(evt.getX(), evt.getY());
    multicaster.trackEnd(anchor, dragLocation, evt.getModifiersEx(), getView());

    // Note: we must not fire "Tool Done" in this method, because then we can not
    // listen to keyboard events for the handle.

    Rectangle r = new Rectangle(anchor.x, anchor.y, 0, 0);
    r.add(evt.getX(), evt.getY());
    maybeFireBoundsInvalidated(r);
    dragLocation = null;
  }
Ejemplo n.º 15
0
  public void mousePressed(MouseEvent e) {
    // super.mousePressed(e);
    ImageProcessor ip = imp.getProcessor();
    ip.setLineWidth(1);
    if (Toolbar.getToolId() == Toolbar.DROPPER) IJ.setTool(Toolbar.RECTANGLE);

    Rectangle flipperRect = new Rectangle(86, 268, 18, 18);
    Rectangle resetRect = new Rectangle(86, 294, 18, 18);
    Rectangle foreground1Rect = new Rectangle(9, 266, 45, 10);
    Rectangle foreground2Rect = new Rectangle(9, 276, 23, 25);
    Rectangle background1Rect = new Rectangle(33, 302, 45, 10);
    Rectangle background2Rect = new Rectangle(56, 277, 23, 25);
    int x = offScreenX(e.getX());
    int y = offScreenY(e.getY());
    long difference = System.currentTimeMillis() - mouseDownTime;
    boolean doubleClick = (difference <= 250);
    mouseDownTime = System.currentTimeMillis();
    if (flipperRect.contains(x, y)) {
      Color c = Toolbar.getBackgroundColor();
      Toolbar.setBackgroundColor(Toolbar.getForegroundColor());
      Toolbar.setForegroundColor(c);
    } else if (resetRect.contains(x, y)) {
      Toolbar.setForegroundColor(new Color(0x000000));
      Toolbar.setBackgroundColor(new Color(0xffffff));
    } else if ((background1Rect.contains(x, y)) || (background2Rect.contains(x, y))) {
      background = true;
      if (doubleClick) editColor();
      ((ColorGenerator) ip).refreshForeground();
      ((ColorGenerator) ip).refreshBackground();
    } else if ((foreground1Rect.contains(x, y)) || (foreground2Rect.contains(x, y))) {
      background = false;
      if (doubleClick) editColor();
      ((ColorGenerator) ip).refreshBackground();
      ((ColorGenerator) ip).refreshForeground();
    } else {
      // IJ.log(" " + difference + " " + doubleClick);
      if (doubleClick) editColor();
      else {
        setDrawingColor(offScreenX(e.getX()), offScreenY(e.getY()), background);
      }
    }
    if (ip instanceof ColorGenerator) {
      if (background) {
        ((ColorGenerator) ip).refreshForeground();
        ((ColorGenerator) ip).refreshBackground();
      } else {
        ((ColorGenerator) ip).refreshBackground();
        ((ColorGenerator) ip).refreshForeground();
      }
    }
  }
Ejemplo n.º 16
0
  public synchronized void mouseMoved(MouseEvent e) {
    if (centering && center.x == e.getX() && center.y == e.getY()) {
      centering = false;
    } else {
      int dx = e.getX() - mouse.x;
      int dy = e.getY() - mouse.y;
      image.x += dx;
      image.y += dy;
      recenterMouse();
    }

    mouse.x = e.getX();
    mouse.y = e.getY();
  }
Ejemplo n.º 17
0
private void Drag (MouseEvent ev)
    {
	switch (state) {
	case stateDrag:
            curnode.Move (ev.getX() - dragx, ev.getY() - dragy);
            dragx = ev.getX();
            dragy = ev.getY();
	    break;

	case stateCreate:
	    curarrow.MoveHeadTo (ev.getX(), ev.getY());
	    break;
        }
    }
Ejemplo n.º 18
0
      @Override
      public void mouseEntered(MouseEvent e) {

        int x = e.getX();
        int y = e.getY();
        // mPt.x = x;
        // mPt.y = y;
        Point p = new Point(hexmech.pxtoHex(e.getX(), e.getY()));
        if (p.x < 0 || p.y < 0 || p.x >= BSIZE || p.y >= BSIZE) return;

        //                boardBiArray[p.x][p.y] = (int)'H';
        System.out.println("Entered in " + p.x + "  and  " + p.y);
        repaint();
      }
Ejemplo n.º 19
0
    public void mouseMoved(MouseEvent ev) {
      JRootPane root = getRootPane();

      if (root.getWindowDecorationStyle() == JRootPane.NONE) {
        return;
      }

      Window w = (Window) ev.getSource();

      Frame f = null;
      Dialog d = null;

      if (w instanceof Frame) {
        f = (Frame) w;
      } else if (w instanceof Dialog) {
        d = (Dialog) w;
      }

      // Update the cursor
      int cursor = getCursor(calculateCorner(w, ev.getX(), ev.getY()));

      if (cursor != 0
          && ((f != null && (f.isResizable() && (f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0))
              || (d != null && d.isResizable()))) {
        w.setCursor(Cursor.getPredefinedCursor(cursor));
      } else {
        w.setCursor(lastCursor);
      }
    }
Ejemplo n.º 20
0
  /** Shows popup with forward history entries */
  private void showForwardHistory(MouseEvent e) {

    JPopupMenu forwardMenu = new JPopupMenu("Forward History");

    if (historyModel == null) {
      return;
    }

    Locale locale = ((JHelp) getControl()).getModel().getHelpSet().getLocale();
    Enumeration items = historyModel.getForwardHistory().elements();
    JMenuItem mi = null;
    int index = historyModel.getIndex() + 1;
    // while(items.hasMoreElements()){
    for (int i = 0; items.hasMoreElements(); i++) {
      HelpModelEvent item = (HelpModelEvent) items.nextElement();
      if (item != null) {
        String title = item.getHistoryName();
        if (title == null) {
          title = HelpUtilities.getString(locale, "history.unknownTitle");
        }
        mi = new JMenuItem(title);
        // mi.setToolTipText(item.getURL().getPath());
        mi.addActionListener(new HistoryActionListener(i + index));
        forwardMenu.add(mi);
      }
    }
    // if(e.isPopupTrigger())
    forwardMenu.show(e.getComponent(), e.getX(), e.getY());
  }
Ejemplo n.º 21
0
 /** Handles mouse move events. The event is delegated to the currently active tool. */
 public void mouseMoved(MouseEvent e) {
   try {
     tool().mouseMove(e, e.getX(), e.getY());
   } catch (Throwable t) {
     handleMouseEventException(t);
   }
 }
 public void mouseClicked(MouseEvent e) {
   int x = e.getX();
   int y = e.getY();
   int currentTabIndex = -1;
   int tabCount = tabPane.getTabCount();
   for (int i = 0; i < tabCount; i++) {
     if (rects[i].contains(x, y)) {
       currentTabIndex = i;
       break;
     } // if contains
   } // for i
   if (currentTabIndex >= 0) {
     Rectangle tabRect = rects[currentTabIndex];
     x = x - tabRect.x;
     y = y - tabRect.y;
     if ((x >= 5) && (x <= 15) && (y >= 5) && (y <= 15)) {
       try {
         tabbedPane.remove(currentTabIndex);
       } catch (Exception ex) {
         ex.printStackTrace();
       }
     } // if
   } // if currentTabIndex >= 0
   System.gc();
 } // mouseClicked
Ejemplo n.º 23
0
 public void mouseDragged(MouseEvent e) {
   int x = e.getX();
   int y = e.getY();
   boolean oldMouseOverButton = mMouseOverButton;
   if (mPressedButton != -1) mMouseOverButton = mRect[mPressedButton].contains(x, y);
   if (mMouseOverButton ^ oldMouseOverButton) repaint();
 }
Ejemplo n.º 24
0
 /** This method cannot be called directly. */
 public void mousePressed(MouseEvent e) {
   synchronized (mouseLock) {
     mouseX = StdDraw.userX(e.getX());
     mouseY = StdDraw.userY(e.getY());
     mousePressed = true;
   }
 }
Ejemplo n.º 25
0
 private void onMouseUp(MouseEvent e) {
   if (hasMotionListener()) {
     changeSelectedPoint(e.getX(), e.getY());
     removeMotionListener();
   }
   updateAll();
 }
Ejemplo n.º 26
0
 public void mouseReleased(MouseEvent e) {
   if (gameover) return;
   if (!blown) {
     if (started == false) {
       started = true;
       processActionEvent(new ActionEvent(this, START_TIMER, "MineSweeper"));
     }
     if (!xy2index(e.getX(), e.getY())) return;
     if (right_clicked) {
       if (hidden[cr][cc]) {
         flagged[cr][cc] = !flagged[cr][cc];
         processActionEvent(
             new ActionEvent(this, SQUARE_FLAGGED * (!flagged[cr][cc] ? 1 : -1), "MineSweeper"));
       }
     } else {
       if (hidden[cr][cc] && !flagged[cr][cc]) hidden[cr][cc] = false;
       if (!flagged[cr][cc] && field[cr][cc] == -1) {
         blown = true;
         started = false;
         processActionEvent(new ActionEvent(this, GAME_LOST, "MineSweeper"));
         paint(getGraphics());
         return;
       }
       if (field[cr][cc] == 0) showNeighbours(cr, cc, false);
     }
     drawBlock(buffG, cr, cc, status(cr, cc));
     paint(getGraphics());
     if ((gameover = is_game_over())) end_game();
   }
 }
Ejemplo n.º 27
0
    public void mousePressed(MouseEvent e) {
      if (e.getButton() == e.BUTTON3) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);
        int index = list.locationToIndex(e.getPoint());
        GetImageFile gif = new GetImageFile(files[index]);

        JTextArea area =
            new JTextArea(
                "File: "
                    + gif.getImageString()
                    + "\n"
                    + "Score: "
                    + nf.format(scores[index])
                    + "\n"
                    + "Pairs: "
                    + nrpairs[index]);
        area.setEditable(false);
        area.setBorder(BorderFactory.createLineBorder(Color.black));
        area.setFont(new Font("times", Font.PLAIN, 12));
        PopupFactory factory = PopupFactory.getSharedInstance();
        popup =
            factory.getPopup(
                null,
                area,
                (int) e.getComponent().getLocationOnScreen().getX() + e.getX() + 25,
                (int) e.getComponent().getLocationOnScreen().getY() + e.getY());
        popup.show();
      }
    }
Ejemplo n.º 28
0
  public void leftMouseReleased(MouseEvent e) {
    double x = e.getX();
    double y = e.getY();

    // If no start vertex selected or start vertex is virtual, do nothing
    if (startVertex == null || startVertex.isVirtual()) {
      displayFrame.controlFrame.updateDisplays(true);
      return;
    }
    endVertex =
        getSelectedVertex(
            x, y, displayFrame.getMainDiagramPanel(), displayFrame.getFreeVertexPanel());
    // If no end vertex selected, still do nothing
    if (endVertex == null) {
      displayFrame.controlFrame.updateDisplays(true);
      return;
    }
    // If mouse pressed and released within the same vertex, print vertex label
    if (endVertex == startVertex) {
      canCreateEdge = false;
      startVertex.setSelected(!startVertex.isSelected());
      displayFrame.controlFrame.updateDisplays(true);
      return;
    } else {
      addNewEdge();
    }
  }
 // Die Methoden des Interface MouseMotionListener implementieren
 public void mouseDragged(MouseEvent e) {
   // Die Koordinaten des Mausklicks lesen
   int x = e.getX();
   int y = e.getY();
   // und mit der Maus malen
   g.fillRect(x, y, 3, 3);
 }
Ejemplo n.º 30
0
 @Override
 public void mousePressed(MouseEvent evt) {
   // handle.mousePressed(evt);
   anchor = new Point(evt.getX(), evt.getY());
   multicaster.trackStart(anchor, evt.getModifiersEx(), getView());
   clearHoverHandles();
 }