Example #1
0
 /* mouse events */
 public void mousePressed(MouseEvent e) {
   int x = e.getX();
   int y = e.getY();
   /* left click */
   if (e.getButton() == MouseEvent.BUTTON1) {
     if (x >= posX && x < posX + Constant.BATTLEFIELD_WIDTH) {
       if (y >= posY) {
         if (y < posY + Constant.BATTLEFIELD_HEIGHT) {
           battle_field.doPress((x - posX), (y - posY));
           return;
         } else if (y < posY + Constant.BATTLEFIELD_HEIGHT + Constant.CARDPANEL_HEIGHT) {
           card_panel.doDrag(x - posX, y - (posY + Constant.BATTLEFIELD_HEIGHT));
           return;
         }
       }
     }
     /* right click */
   } else if (e.getButton() == MouseEvent.BUTTON3) {
     if (x >= posX && x < posX + Constant.BATTLEFIELD_WIDTH) {
       if (y >= posY) {
         if (y < posY + Constant.BATTLEFIELD_HEIGHT) {
           Skill skill = arena.player.useSkill(skill_id, x - posX, y - posY);
           if (skill != null) {
             arena.addSkill(skill);
           }
           return;
         } else if (y < posY + Constant.BATTLEFIELD_HEIGHT + Constant.CARDPANEL_HEIGHT) {
           card_panel.changeDetail(x - posX, y - (posY + Constant.BATTLEFIELD_HEIGHT));
           return;
         }
       }
     }
   }
 }
  public void mouseReleased(MouseEvent e) {
    lastInteractionTime = System.currentTimeMillis();
    if (enabled && !readOnly && lastPressEvent != null && dragInProgress) {

      if (enableMouseDrags && !e.getPoint().equals(lastPressEvent.getPoint())) {

        dragInProgress = false;

        // Generate the command string
        String s = "Mouse " + MouseCommand.MOUSE_DRAG;

        // Insert the button identifier if other than left button was pressed
        if (e.getButton() != MouseEvent.BUTTON1) {
          s += " " + MouseCommand.PARAM_BUTTON_SHORT + "=" + parser.buttonToString(e.getButton());
        }

        // Insert modifiers if there are any
        String modifiers = parser.modifiersToString(e.getModifiers());
        if (modifiers.length() > 0) {
          s += " " + MouseCommand.PARAM_MODIFIER + "=" + modifiers;
        }

        // Generate coordinates
        s += " " + MouseCommand.PARAM_FROM + "=" + parser.pointToString(lastPressEvent.getPoint());
        s += " " + MouseCommand.PARAM_TO + "=" + parser.pointToString(e.getPoint());

        // Insert the command to the current editor
        insertLine(s, false, true, false);
        insertEvent(e);
      }
    }
  }
 protected void processMouseEvent(MouseEvent e) {
   MouseEvent transformedEvent = transformMouseEvent(e);
   switch (e.getID()) {
     case MouseEvent.MOUSE_ENTERED:
       if (mouseDraggedComponent == null || mouseCurrentComponent == mouseDraggedComponent) {
         dispatchMouseEvent(transformedEvent);
       }
       break;
     case MouseEvent.MOUSE_EXITED:
       if (mouseEnteredComponent != null) {
         dispatchMouseEvent(
             createEnterExitEvent(mouseEnteredComponent, MouseEvent.MOUSE_EXITED, e));
         mouseEnteredComponent = null;
       }
       break;
     case MouseEvent.MOUSE_RELEASED:
       if (mouseDraggedComponent != null && e.getButton() == MouseEvent.BUTTON1) {
         transformedEvent.setSource(mouseDraggedComponent);
         mouseDraggedComponent = null;
       }
       dispatchMouseEvent(transformedEvent);
       break;
     default:
       dispatchMouseEvent(transformedEvent);
   }
   super.processMouseEvent(e);
 }
 public void mousePressed(MouseEvent e) {
   if (e.getButton() != MouseEvent.BUTTON1) {
     return;
   }
   if (e.getClickCount() != 2) {
     return;
   }
   JTable table = (JTable) e.getSource();
   Point p = e.getPoint();
   int row = table.rowAtPoint(p);
   if (row < 0) {
     return;
   }
   PickerTableModel model = getDataModel();
   ICFInternetISOCountryObj o =
       (ICFInternetISOCountryObj) model.getValueAt(row, COLID_ROW_HEADER);
   invokeWhenChosen.choseISOCountry(o);
   try {
     Container cont = getParent();
     while ((cont != null) && (!(cont instanceof JInternalFrame))) {
       cont = cont.getParent();
     }
     if (cont != null) {
       ((JInternalFrame) cont).setClosed(true);
     }
   } catch (Exception x) {
   }
 }
Example #5
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();
      }
    }
  protected void processMouseEvent(final MouseEvent e) {
    if (e.isPopupTrigger() && e.getComponent().isShowing()) {
      super.processMouseEvent(e);
      return;
    }

    if (UIUtil.isCloseClick(e)) {
      myDecorator.fireHiddenSide();
      return;
    }

    if (e.getButton() == MouseEvent.BUTTON1) {
      if (MouseEvent.MOUSE_PRESSED == e.getID()) {
        myPressedPoint = e.getPoint();
        myPressedWhenSelected = isSelected();
        myDragCancelled = false;
      } else if (MouseEvent.MOUSE_RELEASED == e.getID()) {
        finishDragging();
        myPressedPoint = null;
        myDragButtonImage = null;
      }
    }

    super.processMouseEvent(e);
  }
 public void mousePressed(MouseEvent e) {
   if (e.getButton() != MouseEvent.BUTTON1) {
     return;
   }
   if (e.getClickCount() != 2) {
     return;
   }
   JTable table = (JTable) e.getSource();
   Point p = e.getPoint();
   int row = table.rowAtPoint(p);
   if (row < 0) {
     return;
   }
   FinderTableModel model = getDataModel();
   ICFSecurityISOTimezoneObj o =
       (ICFSecurityISOTimezoneObj) model.getValueAt(row, COLID_ROW_HEADER);
   if (o == null) {
     return;
   }
   JInternalFrame frame = swingSchema.getISOTimezoneFactory().newViewEditJInternalFrame(o);
   ((ICFSecuritySwingISOTimezoneJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
   if (frame == null) {
     return;
   }
   Container cont = getParent();
   while ((cont != null) && (!(cont instanceof JInternalFrame))) {
     cont = cont.getParent();
   }
   if (cont != null) {
     JInternalFrame myInternalFrame = (JInternalFrame) cont;
     myInternalFrame.getDesktopPane().add(frame);
     frame.setVisible(true);
     frame.show();
   }
 }
 @Override
 public void mousePressed(MouseEvent me) {
   x = me.getX();
   y = me.getY();
   altDown = me.isAltDown() || me.isAltGraphDown();
   undo = (me.getButton() == MouseEvent.BUTTON3) || altDown;
   ctrlDown = me.isControlDown() || me.isMetaDown();
   shiftDown = me.isShiftDown();
   first = true;
   if (!oneShot) {
     if (timer == null) {
       timer =
           new Timer(
               delay,
               e -> {
                 Point worldCoords = view.viewToWorld((int) x, (int) y);
                 tick(worldCoords.x, worldCoords.y, undo, first, 1.0f);
                 view.updateStatusBar(worldCoords.x, worldCoords.y);
                 first = false;
               });
       timer.setInitialDelay(0);
       timer.start();
       //                start = System.currentTimeMillis();
     }
   } else {
     Point worldCoords = view.viewToWorld((int) x, (int) y);
     tick(worldCoords.x, worldCoords.y, undo, true, 1.0f);
     view.updateStatusBar(worldCoords.x, worldCoords.y);
     Dimension dimension = getDimension();
     if (dimension != null) {
       dimension.armSavePoint();
     }
     logOperation(undo ? statisticsKeyUndo : statisticsKey);
   }
 }
Example #9
0
  public void mouseClicked(MouseEvent e) {
    // loop through game buttons to see if one has been clicked
    for (int i = 0; i < row; i++) {
      for (int j = 0; j < col; j++) {
        if (e.getSource() == gbuttons[i][j]) {
          // see if that button has a flag or mine, and what mouse button clicked it
          if (e.getButton() == e.BUTTON1) {

            if (bombs[i][j] == true && flag[i][j] == false) {
              ImageIcon bomb = new ImageIcon("bomb.png");
              gbuttons[i][j].setIcon(bomb); // set label to bomb (* for now, picture later)
              clicked[i][j] = true;
              gameover();

            } else if (flag[i][j]
                == true) // checks to see if button that was clicked has a flag on it
            {

              gbuttons[i][j].setIcon(null);
              flag[i][j] = false;
              clicked[i][j] =
                  false; // it's important to change this, as it changes the button to act as if it
                         // was never clicked.
            } else {
              SurroundB(
                  i,
                  j); // if no bomb or flag on button pressed, the implement this method to
                      // determine how many bombs are around the button clicked
            }
          } else if (e.getButton() == e.BUTTON3) {
            if (flag[i][j] == false
                && clicked[i][j]
                    == false) // if no flag, and button has not been clicked (does not have a flag,
                              // is greyed out, and does not have a number)
            {
              ImageIcon flags = new ImageIcon("flags.png");
              gbuttons[i][j].setIcon(flags);
              flag[i][j] = true;
              clicked[i][j] = true;
            }
          }
        }
      }
    }
    win();
  }
Example #10
0
    public void mouseClicked(MouseEvent e) {
      if (e.getButton() == e.BUTTON1) {
        showButton.setEnabled(list.getSelectedIndex() != -1 ? true : false);

        if (e.getClickCount() == 2) {
          int index = list.locationToIndex(e.getPoint());
          sp.doVisualComparison(index, scores[index]);
        }
      }
    }
Example #11
0
    public void mouseReleased(MouseEvent e) {
      int mods = e.getModifiersEx();

      if (nodrag && e.getButton() == MouseEvent.BUTTON3) {
        popupMenu.show(JImage.this, (int) e.getPoint().getX(), (int) e.getPoint().getY());
      }

      nodrag = true;
      dragBegin = null;
    }
 public void mousePressed(MouseEvent e) {
   if (e.getButton() != MouseEvent.BUTTON1) {
     return;
   }
   if (e.getClickCount() != 2) {
     return;
   }
   JTable table = (JTable) e.getSource();
   Point p = e.getPoint();
   int row = table.rowAtPoint(p);
   if (row < 0) {
     return;
   }
   ListTableModel model = getDataModel();
   ICFInternetVersionObj o = (ICFInternetVersionObj) model.getValueAt(row, COLID_ROW_HEADER);
   if (o == null) {
     return;
   }
   JInternalFrame frame = null;
   String classCode = o.getClassCode();
   if (classCode.equals("VERN")) {
     frame = swingSchema.getVersionFactory().newViewEditJInternalFrame(o);
     frame.addInternalFrameListener(getViewEditInternalFrameListener());
     ((ICFInternetSwingVersionJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
   } else if (classCode.equals("MJVR")) {
     frame =
         swingSchema
             .getMajorVersionFactory()
             .newViewEditJInternalFrame((ICFInternetMajorVersionObj) o);
     frame.addInternalFrameListener(getViewEditInternalFrameListener());
     ((ICFInternetSwingMajorVersionJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
   } else if (classCode.equals("MNVR")) {
     frame =
         swingSchema
             .getMinorVersionFactory()
             .newViewEditJInternalFrame((ICFInternetMinorVersionObj) o);
     frame.addInternalFrameListener(getViewEditInternalFrameListener());
     ((ICFInternetSwingMinorVersionJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
   } else {
     frame = null;
   }
   if (frame == null) {
     return;
   }
   Container cont = getParent();
   while ((cont != null) && (!(cont instanceof JInternalFrame))) {
     cont = cont.getParent();
   }
   if (cont != null) {
     JInternalFrame myInternalFrame = (JInternalFrame) cont;
     myInternalFrame.getDesktopPane().add(frame);
     frame.setVisible(true);
     frame.show();
   }
 }
 public void mouseReleased(MouseEvent e) {
   if (e.getButton() == e.BUTTON1 && connected) {
     if (dec == null) return;
     lc.increment();
     TextEvent cu = new CaretUpdate(area1.getCaretPosition(), lc.getTimeStamp());
     dec.sendObjectToAllPeers(cu);
     er.getEventHistoryLock().lock();
     er.getEventHistory().add(cu);
     er.getEventHistoryLock().unlock();
   }
 }
Example #14
0
 public void mousePressed(MouseEvent e) {
   if (e.getButton() == 3 && !(currentTool instanceof CursorTool)) {
     setTool(cursorTool, cursorButton);
   } else {
     Point p = new Point(e.getX(), e.getY());
     WorkingView.this.getTool().mouseDown(p.x, p.y, e);
   }
   if (currentTool instanceof ArrowTool || currentTool instanceof TextBoxTool) {
     setTool(cursorTool, cursorButton);
   }
   board.requestFocus();
 }
Example #15
0
 /**
  * Allow to close the editor with a middle click on his tab.
  *
  * @param e The event.
  */
 @Override
 public void mouseClicked(MouseEvent e) {
   if (e.getButton() == MouseEvent.BUTTON2 && countEditors() > 0) {
     Point clic = e.getPoint();
     int idx = indexAtLocation(clic.x, clic.y);
     if (idx != -1) {
       // Middle click on a tab was clicked: close it.
       AbstractEditorPanel editor = (AbstractEditorPanel) getComponentAt(idx);
       removeEditor(editor, true);
     }
   }
 }
Example #16
0
    public void mousePressed(MouseEvent event) {

      // Point selectedPoint = event.getPoint();
      int xPos = event.getX() - 20;
      int yPos = event.getY() - 50;
      int col = (int) (xPos / 50);
      int row = (int) (yPos / 50);
      // If left mouse is clicked, reveal
      // Get the coordinates of the click and use cascade on square

      if (event.getButton() == MouseEvent.BUTTON1) {

        if (xPos > 0 && xPos < 800 && yPos > 0 && yPos < 800) {

          if (!board[row][col].isReveal() && !board[row][col].isFlag()) cascade(board[row][col]);
        }
      }
      // If right mouse button is clicked, place flag
      else if (event.getButton() == MouseEvent.BUTTON3) {
        if (xPos > 0 && xPos < 800 && yPos > 0 && yPos < 800) {

          if (!board[row][col].isFlag && !board[row][col].isReveal() && currentFlags < maxFlags) {
            board[row][col].addFlag();
            currentFlags++;
            if (board[row][col].isBear()) {
              bearsCovered++;
              checkWin();
            }
          } else if (board[row][col].isFlag) {
            board[row][col].removeFlag();
            currentFlags--;
            if (board[row][col].isBear()) {
              bearsCovered--;
            }
          }
        }
      }
      repaint();
    }
    public void mousePressed(MouseEvent e) {
      if (e == null || e.isConsumed()) {
        return;
      }

      if (!this.isEnabled()) {
        return;
      }

      if (e.getButton() == MouseEvent.BUTTON1) {
        this.handleSelect();
      }
    }
Example #18
0
 public void mousePressed(MouseEvent e) {
   // #if (tar)
   // @    		if (e.getButton() == 1){
   // @	            if (current_Player.isMo() && current_Player.getSch().getStart_X() == 0 &&
   // current_Player.getSch().isIsActive() == false){
   // @	                current_Player.getSch().setIsActive(true);
   // @	                current_Player.getSch().setStart_X(e.getX());
   // @	                current_Player.getSch().setStart_Y(e.getY());
   // @	                current_Player.getSch().setStart_time();
   // @	            }
   // @	        }
   // #else
   if (e.getButton() == 3) {
     TankInfo ti = new TankInfo();
     System.out.println("ISIDE");
   }
   // #endif
 }
Example #19
0
    public void mouseClicked(MouseEvent e) {
      if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1) {
        JButton source = (JButton) e.getSource();

        String value = source.getText();
        int day = Integer.parseInt(value);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        Date selectDate = this.getSelectDate();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        MyDateChooseBtn.this.setText(simpleDateFormat.format(selectDate));
        Jtext.setText(simpleDateFormat.format(selectDate));

        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        //        System.out.println(year + "骞�" + month + "鏈�" + day + "鏃�");
        f.dispose();
      }
    }
Example #20
0
  /**
   * Propagates certain mouse events, such as MOUSE_CLICKED, MOUSE_RELEASED etc. to the deepest
   * component.
   *
   * @param e The MouseEvent to be propagated.
   */
  protected void propagateMouseListenerEvent(MouseEvent e) {
    if (POPUP_IS_MODAL == false) {

      Component deepestComponent = getDeepestComponent(e.getPoint());

      if (deepestComponent != null) {
        MouseListener[] mouseListeners = deepestComponent.getMouseListeners();

        int eventID;

        // Get the event type
        eventID = e.getID();

        Point pt = e.getPoint();

        Point convertedPt = SwingUtilities.convertPoint(glassPane, e.getPoint(), deepestComponent);

        MouseEvent evt =
            new MouseEvent(
                deepestComponent,
                e.getID(),
                System.currentTimeMillis(),
                e.getModifiers(),
                convertedPt.x,
                convertedPt.y,
                e.getClickCount(),
                e.isPopupTrigger(),
                e.getButton());

        // Distibute the event to the component's listeners.
        for (int i = 0; i < mouseListeners.length; i++) {

          // Forward the appropriate mouse event
          if (eventID == MouseEvent.MOUSE_PRESSED) {
            mouseListeners[i].mousePressed(evt);
          } else if (eventID == MouseEvent.MOUSE_RELEASED) {
            mouseListeners[i].mouseReleased(evt);
          } else if (eventID == MouseEvent.MOUSE_CLICKED) {
            mouseListeners[i].mouseClicked(evt);
          }
        }
      }
    }
  }
 private void dispatchEvent(MouseEvent me) {
   if (rect != null && rect.contains(me.getX(), me.getY())) {
     Point pt = me.getPoint();
     pt.translate(-offset, 0);
     comp.setBounds(rect);
     comp.dispatchEvent(
         new MouseEvent(
             comp,
             me.getID(),
             me.getWhen(),
             me.getModifiers(),
             pt.x,
             pt.y,
             me.getClickCount(),
             me.isPopupTrigger(),
             me.getButton()));
     if (!comp.isValid()) container.repaint();
   }
 }
Example #22
0
  protected void propagateMouseMotionListenerEvents(MouseEvent e) {
    if (FORWARD_MOUSE_MOTION_EVENTS == true) {
      // Get the correct component
      Component deepestComponent = getDeepestComponent(e.getPoint());

      if (deepestComponent != null) {
        // Distribute the event to the components listeners
        MouseMotionListener[] mouseMotionListeners = deepestComponent.getMouseMotionListeners();

        // Get the event type
        int eventID = e.getID();

        Point pt = e.getPoint();

        Point convertedPt = SwingUtilities.convertPoint(glassPane, e.getPoint(), deepestComponent);

        MouseEvent evt =
            new MouseEvent(
                deepestComponent,
                e.getID(),
                System.currentTimeMillis(),
                e.getModifiers(),
                convertedPt.x,
                convertedPt.y,
                e.getClickCount(),
                e.isPopupTrigger(),
                e.getButton());

        for (int i = 0; i < mouseMotionListeners.length; i++) {
          if (eventID == MouseEvent.MOUSE_MOVED) {
            mouseMotionListeners[i].mouseMoved(e);
          } else if (eventID == MouseEvent.MOUSE_DRAGGED) {
            mouseMotionListeners[i].mouseDragged(e);
          }
        }
      }
    }
  }
Example #23
0
 @Override
 public void mouseReleased(MouseEvent e) {
   newMouseX = e.getX();
   newMouseY = e.getY();
   mouseDrag[(mouseY - border) / squareSize][(mouseX - border) / squareSize][0] = 0;
   mouseDrag[(mouseY - border) / squareSize][(mouseX - border) / squareSize][1] = 0;
   repaint();
   if (e.getButton() == MouseEvent.BUTTON1) { // if left mouse click
     String dragMove;
     if ((newMouseY - border) / squareSize == 0
         && (mouseY - border) / squareSize == 1
         && "P"
             .equals(
                 ChessEngine.chessboard[(mouseY - border) / squareSize][
                     (mouseX - border) / squareSize])) {
       // pawn promotion
       dragMove =
           ""
               + (mouseX - border) / squareSize
               + (newMouseX - border) / squareSize
               + ChessEngine.chessboard[(newMouseY - border) / squareSize][
                   (newMouseX - border) / squareSize]
               + "QP"; // assumes queen promotion
     } else if (Math.abs((mouseX - border) / squareSize - (newMouseX - border) / squareSize) == 2
         && "A"
             .equals(
                 ChessEngine.chessboard[(mouseY - border) / squareSize][
                     (mouseX - border) / squareSize])) {
       // castling
       if ((mouseX - border) / squareSize > (newMouseX - border) / squareSize) { // left
         dragMove =
             ""
                 + (mouseX - border) / squareSize
                 + "0"
                 + (newMouseX - border) / squareSize
                 + ((newMouseX - border) / squareSize + 1)
                 + "C";
       } else { // right
         dragMove =
             ""
                 + (mouseX - border) / squareSize
                 + "7"
                 + (newMouseX - border) / squareSize
                 + ((newMouseX - border) / squareSize - 1)
                 + "C";
       }
     } else {
       dragMove =
           ""
               + (mouseY - border) / squareSize
               + (mouseX - border) / squareSize
               + (newMouseY - border) / squareSize
               + (newMouseX - border) / squareSize
               + ChessEngine.chessboard[(newMouseY - border) / squareSize][
                   (newMouseX - border) / squareSize];
     }
     String userMovePosibilities = ChessEngine.possibleMoves();
     if (userMovePosibilities.replace(dragMove, "").length() < userMovePosibilities.length()) {
       ChessEngine.makeMove(dragMove);
       ChessEngine.history += dragMove;
       movePieceEvent();
     }
   }
 }
Example #24
0
 public void mouseClicked(MouseEvent e) {
   if (e.getButton() == 1 && e.getClickCount() == 2) {
     adjustZoom(1, null);
   }
 }
Example #25
0
 public void mousePressed(MouseEvent e) {
   if (e.getButton() == e.BUTTON3) cbpm.show(e.getComponent(), e.getX(), e.getY());
   cbstarty = e.getY();
 }
  /**
   * This method gets called when user performs a mouse click. It decodes whether it is a single
   * click or part of a multiple click (double click, triple click etc.) and inserts appropriate
   * command to the current editor.
   *
   * @param e a MouseEvent describing the mouse click.
   */
  public void mouseClicked(MouseEvent e) {
    if (enabled && !readOnly) {
      if (timer != null && timer.isRunning()) {
        timer.stop();
      }
      if (enableMouseClicks) {
        int count = 1;
        MouseEvent e2;

        long lastEventTime = e.getWhen();

        // This cycle is to determine multiple clicks like double click, triple click etc.
        // We go through the vector of events and check whether there are events corresponding to
        // multiple clicks.
        for (int i = 0; i < events.size() && events.get(i) instanceof MouseEvent; i++) {
          e2 = (MouseEvent) events.get(i);

          // The events are considered to be a multiple click when:
          // 1. Coordinates are equal
          // 2. Modifiers are equal
          // 3. Button is equal
          // 4. Delay between two subsequent clicks is lower than given number of miliseconds
          if (e2.getX() == e.getX()
              && e2.getY() == e.getY()
              && e2.getModifiers() == e.getModifiers()
              && (lastEventTime - e2.getWhen() < mouseMultiDelay)
              && e.getButton() == e2.getButton()
              && e2.getID() == e.getID()) {
            count++;
            lastEventTime = e2.getWhen();
          } else {
            break;
          }
        }

        // Generate the command string
        String s = "Mouse " + MouseCommand.MOUSE_CLICK;

        // Insert the button identifier if other than left button was pressed
        if (e.getButton() != MouseEvent.BUTTON1) {
          s += " " + MouseCommand.PARAM_BUTTON_SHORT + "=" + parser.buttonToString(e.getButton());
        }

        // Insert modifiers if there are any
        String modifiers = parser.modifiersToString(e.getModifiers());
        if (modifiers.length() > 0) {
          s += " " + MouseCommand.PARAM_MODIFIER + "=" + modifiers;
        }

        // Generate the count parameter
        if (count > 1) {
          s += " " + MouseCommand.PARAM_COUNT + "=" + count;
        }

        // This will determine whether this click is preceded by a mouse
        // move command with the same coordinates.
        // It will be replaced if yes.
        boolean replaceLastMove = false;
        //                if (enableMouseMoves) {
        //                    if (events.size() > 0 && events.get(events.size() - 1) instanceof
        // MouseEvent) {
        //                        MouseEvent me = (MouseEvent) events.get(events.size() - 1);
        //                        if (me.getID() == MouseEvent.MOUSE_MOVED && e.getX() == me.getX()
        // && e.getY() == me.getY()) {
        //                            replaceLastMove = true;
        //                        }
        //                    }
        //                }

        // Generate coordinates
        s += " " + MouseCommand.PARAM_TO + "=" + parser.pointToString(e.getPoint());

        // Insert the command to the current editor
        insertLine(s, count > 1 || replaceLastMove, true, false);
        dragInProgress = false;
      }
      insertEvent(e);
    }
  }
Example #27
0
 public void mouseReleased(MouseEvent e) {
   if (e.getButton() == e.BUTTON3) {
     popup.hide();
   }
 }
 public void mousePressed(MouseEvent e) {
   mouseButtons.setNextState(e.getButton(), true);
 }
    private MouseEvent transformMouseEvent(MouseEvent event) {
      if (event == null) {
        throw new IllegalArgumentException("MouseEvent is null");
      }
      MouseEvent newEvent;
      if (event instanceof MouseWheelEvent) {
        MouseWheelEvent mouseWheelEvent = (MouseWheelEvent) event;
        newEvent =
            new MouseWheelEvent(
                mouseWheelEvent.getComponent(),
                mouseWheelEvent.getID(),
                mouseWheelEvent.getWhen(),
                mouseWheelEvent.getModifiers(),
                mouseWheelEvent.getX(),
                mouseWheelEvent.getY(),
                mouseWheelEvent.getClickCount(),
                mouseWheelEvent.isPopupTrigger(),
                mouseWheelEvent.getScrollType(),
                mouseWheelEvent.getScrollAmount(),
                mouseWheelEvent.getWheelRotation());
      } else {
        newEvent =
            new MouseEvent(
                event.getComponent(),
                event.getID(),
                event.getWhen(),
                event.getModifiers(),
                event.getX(),
                event.getY(),
                event.getClickCount(),
                event.isPopupTrigger(),
                event.getButton());
      }
      if (view != null && at.getDeterminant() != 0) {
        Rectangle viewBounds = getTransformedSize();
        Insets insets = JXTransformer.this.getInsets();
        int xgap = (getWidth() - (viewBounds.width + insets.left + insets.right)) / 2;
        int ygap = (getHeight() - (viewBounds.height + insets.top + insets.bottom)) / 2;

        double x = newEvent.getX() + viewBounds.getX() - insets.left;
        double y = newEvent.getY() + viewBounds.getY() - insets.top;
        Point2D p = new Point2D.Double(x - xgap, y - ygap);

        Point2D tp;
        try {
          tp = at.inverseTransform(p, null);
        } catch (NoninvertibleTransformException ex) {
          // can't happen, we check it before
          throw new AssertionError("NoninvertibleTransformException");
        }
        // Use transformed coordinates to get the current component
        mouseCurrentComponent =
            SwingUtilities.getDeepestComponentAt(view, (int) tp.getX(), (int) tp.getY());
        if (mouseCurrentComponent == null) {
          mouseCurrentComponent = JXTransformer.this;
        }
        Component tempComponent = mouseCurrentComponent;
        if (mouseDraggedComponent != null) {
          tempComponent = mouseDraggedComponent;
        }

        Point point =
            SwingUtilities.convertPoint(view, (int) tp.getX(), (int) tp.getY(), tempComponent);
        newEvent.setSource(tempComponent);
        newEvent.translatePoint(point.x - event.getX(), point.y - event.getY());
      }
      return newEvent;
    }
 public void mouseReleased(MouseEvent e) {
   mouseButtons.setNextState(e.getButton(), false);
 }