/** 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);
     }
   }
 }
예제 #2
0
  public void mousePressed(MouseEvent e) {
    
    // jdf
    if (!isEnabled())
      return;
    
    final int x = e.getX();
    final int y = e.getY();

    int sel = findSelection(x, y);
    ///if (sel == -1) return false;
    if (sel == -1) return;
    currentRollover = -1;

    switch (sel) {
    case RUN:
      editor.handleRun(e.isShiftDown());
      break;

//    case STOP:
//      editor.handleStop();
//      break;
//
    case OPEN:
      popup = menu.getPopupMenu();
      popup.show(EditorToolbar.this, x, y);
      break;

    case NEW:
      if (shiftPressed) {
        editor.base.handleNew();
      } else {
      editor.base.handleNewReplace();
      }
      break;

    case SAVE:
      editor.handleSave(false);
      break;

    case EXPORT:
      boolean t = e.isControlDown();
      editor.handleExport(e.isShiftDown(),autoOpenSerialMonitor ? !t : t); // Control is down if autoOpenSerialMonitor is true in preferences
      break;

    case SERIAL:
      editor.handleSerial();
      handleMouse(e);
      break;
    }
  }
    private void adjustFocusAndSelection(MouseEvent e) {
      if (shouldIgnore(e)) {
        return;
      }

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

      // The autoscroller can generate drag events outside range.
      if ((column == -1) || (row == -1)) {
        System.err.println("Out of bounds");
        return;
      }

      if (grid.editCellAt(row, column, e)) {
        setDispatchComponent(e);
        repostEvent(e);
      } else {
        grid.requestFocus();
      }

      GridCellEditor editor = grid.getCurrentCellEditor();
      if (editor == null || editor.shouldSelectCell(e)) {
        // Update selection model
        setValueIsAdjusting(true);
        grid.changeSelection(row, column, e.isControlDown(), e.isShiftDown());
      }
    }
예제 #4
0
    // {{{ mouseClicked() method
    @Override
    public void mouseClicked(MouseEvent evt) {
      Point p = evt.getPoint();
      int row = table.rowAtPoint(p);
      int column = table.columnAtPoint(p);
      if (row == -1) return;
      if (column == 0) {
        VFSDirectoryEntryTableModel.Entry entry =
            (VFSDirectoryEntryTableModel.Entry) table.getModel().getValueAt(row, 0);
        if (FileCellRenderer.ExpansionToggleBorder.isExpansionToggle(entry.level, p.x)) {
          return;
        }
      }

      if ((evt.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && evt.getClickCount() % 2 == 0) {
        browser.filesActivated(
            evt.isShiftDown() ? VFSBrowser.M_OPEN_NEW_VIEW : VFSBrowser.M_OPEN, true);
      } else if (GUIUtilities.isMiddleButton(evt.getModifiers())) {
        if (evt.isShiftDown()) table.getSelectionModel().addSelectionInterval(row, row);
        else table.getSelectionModel().setSelectionInterval(row, row);
        browser.filesActivated(
            evt.isShiftDown() ? VFSBrowser.M_OPEN_NEW_VIEW : VFSBrowser.M_OPEN, true);
      }
    } // }}}
예제 #5
0
 public void mouseDragged(MouseEvent e) {
   if (!e.isShiftDown()) // normal drag
   move(this, e);
   else // drag entire connected component
   {
     ArrayList connectedNodes = dNode.connectedNodes();
     if (connectedNodes.size() == 0) move(this, e);
     else
       for (Iterator it = connectedNodes.iterator(); it.hasNext(); ) {
         ASDDigraphNode dNode2 = (ASDDigraphNode) it.next();
         ASDEditNode eNode2 = dNode2.getEditNode();
         move(eNode2, e);
       }
   }
   getEditor().setGrammarChanged(true);
   getContext().repaint();
 }
  /** Resize image if initial click was in grow-box: */
  public void mouseDragged(MouseEvent e) {
    if (fGrowBase != null) {
      Point loc = fComponent.getLocationOnScreen();
      int width = Math.max(2, loc.x + e.getX() - fGrowBase.x);
      int height = Math.max(2, loc.y + e.getY() - fGrowBase.y);

      if (e.isShiftDown() && fImage != null) {
        // Make sure size is proportional to actual image size:
        float imgWidth = fImage.getWidth(this);
        float imgHeight = fImage.getHeight(this);
        if (imgWidth > 0 && imgHeight > 0) {
          float prop = imgHeight / imgWidth;
          float pwidth = height / prop;
          float pheight = width * prop;
          if (pwidth > width) width = (int) pwidth;
          else height = (int) pheight;
        }
      }

      resize(width, height);
    }
  }
예제 #7
0
    // {{{ mousePressed() method
    @Override
    public void mousePressed(MouseEvent evt) {
      Point p = evt.getPoint();
      if (evt.getSource() != table) {
        p.x -= table.getX();
        p.y -= table.getY();
      }

      int row = table.rowAtPoint(p);
      int column = table.columnAtPoint(p);
      if (column == 0 && row != -1) {
        VFSDirectoryEntryTableModel.Entry entry =
            (VFSDirectoryEntryTableModel.Entry) table.getModel().getValueAt(row, 0);
        if (FileCellRenderer.ExpansionToggleBorder.isExpansionToggle(entry.level, p.x)) {
          table.toggleExpanded(row);
          return;
        }
      }

      if (GUIUtilities.isMiddleButton(evt.getModifiers())) {
        if (row == -1) /* nothing */ ;
        else if (evt.isShiftDown()) table.getSelectionModel().addSelectionInterval(row, row);
        else table.getSelectionModel().setSelectionInterval(row, row);
      } else if (GUIUtilities.isPopupTrigger(evt)) {
        if (popup != null && popup.isVisible()) {
          popup.setVisible(false);
          popup = null;
          return;
        }

        if (row == -1) showFilePopup(null, table, evt.getPoint());
        else {
          if (!table.getSelectionModel().isSelectedIndex(row))
            table.getSelectionModel().setSelectionInterval(row, row);
          showFilePopup(getSelectedFiles(), table, evt.getPoint());
        }
      }
    } // }}}
  public void mousePressed(MouseEvent e) {
    final int x = e.getX();
    final int y = e.getY();

    int sel = findSelection(x, y);
    /// if (sel == -1) return false;
    if (sel == -1) return;
    currentRollover = -1;
    // int currentSelection = sel;
    // if (!(disableRun && ((sel == RUN) || (sel == STOP)))) {
    // moving the handling of this over into the editor
    // setState(sel, ACTIVE, true);
    // }

    // if (currentSelection == OPEN) {
    // switch (currentSelection) {
    switch (sel) {
      case RUN:
        // if (!disableRun) {
        editor.handleRun(e.isShiftDown());
        // }
        break;

      case STOP:
        // if (!disableRun) {
        // setState(RUN, INACTIVE, true);
        // setInactive();
        editor.handleStop();
        // }
        break;

      case OPEN:
        if (popup == null) {
          // popup = new JPopupMenu();
          popup = editor.sketchbook.getPopupMenu();
          // no events properly being fired, so nevermind
          /*
          popup.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                System.out.println("action " + e);
              }
            });
          popup.addComponentListener(new ComponentAdapter() {
              public void componentHidden(ComponentEvent e) {
                System.out.println("hidden " + e);
              }
            });
          */
          add(popup);
        }
        // activate(OPEN);
        // SwingUtilities.invokeLater(new Runnable() {
        // public void run() {
        popup.show(EditorButtons.this, x, y);
        // }});
        break;

      case NEW:
        editor.handleNew(e.isShiftDown());
        break;

      case SAVE:
        editor.handleSave(false);
        break;

      case EXPORT:
        editor.handleExport();
        break;

      case SERIAL:
        editor.handleSerial();
        break;
    }
  }