Ejemplo n.º 1
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);
    }
  }
  private void updateRolloverColumn(MouseEvent e) {
    if (header.getDraggedColumn() == null && header.contains(e.getPoint())) {

      int col = header.columnAtPoint(e.getPoint());
      if (col != rolloverColumn) {
        rolloverColumn = col;
        header.repaint();
      }
    }
  }
Ejemplo n.º 3
0
    public void mouseClicked(MouseEvent ev) {
      Window w = (Window) ev.getSource();
      Frame f = null;

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

      Point convertedPoint = SwingUtilities.convertPoint(w, ev.getPoint(), getTitlePane());

      int state = f.getExtendedState();
      if (getTitlePane() != null && getTitlePane().contains(convertedPoint)) {
        if ((ev.getClickCount() % 2) == 0 && ((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) {
          if (f.isResizable()) {
            if ((state & Frame.MAXIMIZED_BOTH) != 0) {
              f.setExtendedState(state & ~Frame.MAXIMIZED_BOTH);
            } else {
              f.setExtendedState(state | Frame.MAXIMIZED_BOTH);
            }
            return;
          }
        }
      }
    }
    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());
      }
    }
Ejemplo n.º 5
0
 @Override
 public void mouseMoved(MouseEvent e) {
   Point pt = e.getPoint();
   int prevRow = row;
   int prevCol = col;
   row = table.rowAtPoint(pt);
   col = table.columnAtPoint(pt);
   if (row < 0 || col < 0) {
     row = -1;
     col = -1;
   }
   // >>>> HyperlinkCellRenderer.java
   // @see
   // http://java.net/projects/swingset3/sources/svn/content/trunk/SwingSet3/src/com/sun/swingset3/demos/table/HyperlinkCellRenderer.java
   if (row == prevRow && col == prevCol) {
     return;
   }
   Rectangle repaintRect;
   if (row >= 0 && col >= 0) {
     Rectangle r = table.getCellRect(row, col, false);
     if (prevRow >= 0 && prevCol >= 0) {
       repaintRect = r.union(table.getCellRect(prevRow, prevCol, false));
     } else {
       repaintRect = r;
     }
   } else {
     repaintRect = table.getCellRect(prevRow, prevCol, false);
   }
   table.repaint(repaintRect);
   // <<<<
   // table.repaint();
 }
Ejemplo n.º 6
0
 void profileList_mouseClicked(MouseEvent e) {
   JList theList = (JList) e.getSource();
   ListModel aModel = theList.getModel();
   int index = theList.locationToIndex(e.getPoint());
   if (index < 0) return;
   UniProfile aProfile = (UniProfile) aModel.getElementAt(index);
   nameTextField.setText(aProfile.toString());
 }
Ejemplo n.º 7
0
  @Override
  public final void mouseDragged(final MouseEvent e) {
    if (!SwingUtilities.isLeftMouseButton(e)) return;

    // selection mode
    rend.select(scroll.pos(), e.getPoint(), true);
    final int y = Math.max(20, Math.min(e.getY(), getHeight() - 20));
    if (y != e.getY()) scroll.pos(scroll.pos() + e.getY() - y);
  }
 @Override
 public String getToolTipText(MouseEvent evt) {
   int index = locationToIndex(evt.getPoint());
   if (index == -1) {
     return "";
   } else {
     ListItem<T> item = (ListItem<T>) model.getElementAt(index);
     return item.dataItem.toString();
   }
 }
    private void setDispatchComponent(MouseEvent e) {
      // Get location
      Point spreadPoint = e.getPoint();
      int row = grid.rowAtPoint(spreadPoint);
      int column = grid.columnAtPoint(spreadPoint);

      // Get editor component
      Component editorComponent = grid.getEditorComponent();

      // Get dispatchComponent
      Point editorPoint = SwingUtilities.convertPoint(grid, spreadPoint, editorComponent);
      dispatchComponent =
          SwingUtilities.getDeepestComponentAt(editorComponent, editorPoint.x, editorPoint.y);
    }
 public void processMouseEvent(
     JMenuItem item, MouseEvent e, MenuElement path[], MenuSelectionManager manager) {
   Point p = e.getPoint();
   if (p.x >= 0 && p.x < item.getWidth() && p.y >= 0 && p.y < item.getHeight()) {
     if (e.getID() == MouseEvent.MOUSE_RELEASED) {
       manager.clearSelectedPath();
       item.doClick(0);
       item.setArmed(false);
     } else manager.setSelectedPath(path);
   } else if (item.getModel().isArmed()) {
     MenuElement newPath[] = new MenuElement[path.length - 1];
     int i, c;
     for (i = 0, c = path.length - 1; i < c; i++) newPath[i] = path[i];
     manager.setSelectedPath(newPath);
   }
 }
 // {{{ getToolTipText()
 public String getToolTipText(MouseEvent event) {
   Point p = event.getPoint();
   switch (this.columnAtPoint(p)) {
     case 0:
       return "Start column for the sort field";
     case 1:
       return "End column for the sort field";
     case 2:
       return "Enable for descending sort order";
     case 3:
       return "Enable for case insensitive sort";
     case 4:
       return "Enable for numeric type sort";
     case 5:
       return "Trim whitespace before sorting";
   }
   return null;
 } // }}}
Ejemplo n.º 12
0
    public void mousePressed(MouseEvent ev) {
      JRootPane rootPane = getRootPane();

      if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) {
        return;
      }
      Point dragWindowOffset = ev.getPoint();
      Window w = (Window) ev.getSource();
      if (w != null) {
        w.toFront();
      }
      Point convertedDragWindowOffset =
          SwingUtilities.convertPoint(w, dragWindowOffset, getTitlePane());

      Frame f = null;
      Dialog d = null;

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

      int frameState = (f != null) ? f.getExtendedState() : 0;

      if (getTitlePane() != null && getTitlePane().contains(convertedDragWindowOffset)) {
        if ((f != null && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null))
            && dragWindowOffset.y >= BORDER_DRAG_THICKNESS
            && dragWindowOffset.x >= BORDER_DRAG_THICKNESS
            && dragWindowOffset.x < w.getWidth() - BORDER_DRAG_THICKNESS) {
          isMovingWindow = true;
          dragOffsetX = dragWindowOffset.x;
          dragOffsetY = dragWindowOffset.y;
        }
      } else if (f != null && f.isResizable() && ((frameState & Frame.MAXIMIZED_BOTH) == 0)
          || (d != null && d.isResizable())) {
        dragOffsetX = dragWindowOffset.x;
        dragOffsetY = dragWindowOffset.y;
        dragWidth = w.getWidth();
        dragHeight = w.getHeight();
        dragCursor = getCursor(calculateCorner(w, dragWindowOffset.x, dragWindowOffset.y));
      }
    }
    public void mouseDragged(MouseEvent e) {
      if (shouldIgnore(e)) {
        return;
      }

      repostEvent(e);

      CellEditor editor = grid.getCurrentCellEditor();
      if (editor == null || editor.shouldSelectCell(e)) {
        Point p = e.getPoint();
        int row = grid.rowAtPoint(p);
        int column = grid.columnAtPoint(p);
        // The autoscroller can generate drag events outside the Table's range.
        if ((column == -1) || (row == -1)) {
          return;
        }
        grid.changeSelection(row, column, false, true);
      }
    }
Ejemplo n.º 14
0
    public void mouseDragged(MouseEvent ev) {
      Window w = (Window) ev.getSource();
      Point pt = ev.getPoint();

      if (isMovingWindow) {
        Point windowPt;
        try {
          windowPt = (Point) AccessController.doPrivileged(getLocationAction);
          windowPt.x = windowPt.x - dragOffsetX;
          windowPt.y = windowPt.y - dragOffsetY;
          w.setLocation(windowPt);
        } catch (PrivilegedActionException e) {
        }
      } else if (dragCursor != 0) {
        Rectangle r = w.getBounds();
        Rectangle startBounds = new Rectangle(r);
        Dimension min = w.getMinimumSize();

        switch (dragCursor) {
          case Cursor.E_RESIZE_CURSOR:
            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);
            break;
          case Cursor.S_RESIZE_CURSOR:
            adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          case Cursor.N_RESIZE_CURSOR:
            adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));
            break;
          case Cursor.W_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);
            break;
          case Cursor.NE_RESIZE_CURSOR:
            adjust(
                r,
                min,
                0,
                pt.y - dragOffsetY,
                pt.x + (dragWidth - dragOffsetX) - r.width,
                -(pt.y - dragOffsetY));
            break;
          case Cursor.SE_RESIZE_CURSOR:
            adjust(
                r,
                min,
                0,
                0,
                pt.x + (dragWidth - dragOffsetX) - r.width,
                pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          case Cursor.NW_RESIZE_CURSOR:
            adjust(
                r,
                min,
                pt.x - dragOffsetX,
                pt.y - dragOffsetY,
                -(pt.x - dragOffsetX),
                -(pt.y - dragOffsetY));
            break;
          case Cursor.SW_RESIZE_CURSOR:
            adjust(
                r,
                min,
                pt.x - dragOffsetX,
                0,
                -(pt.x - dragOffsetX),
                pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          default:
            break;
        }
        if (!r.equals(startBounds)) {
          w.setBounds(r);
          // Defer repaint/validate on mouseReleased unless dynamic
          // layout is active.
          if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
            w.validate();
            getRootPane().repaint();
          }
        }
      }
    }