Java Code Examples for java.awt.event.MouseEvent#isControlDown()

The following examples show how to use java.awt.event.MouseEvent#isControlDown() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void mouseClicked(final MouseEvent e) {
    final JTableHeader h = (JTableHeader) e.getSource();
    final TableColumnModel columnModel = h.getColumnModel();
    final int viewColumnIndex = columnModel.getColumnIndexAtX(e.getX());
    final int columnIndex = columnModel.getColumn(viewColumnIndex).getModelIndex();
    if (columnIndex != -1) {
        int direction = getSortingDirection(columnIndex);
        if (!e.isControlDown()) {
            clearSortingDirections();
            _tableHeader.repaint();
        }
        // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
        // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
        direction += (e.isShiftDown() ? -1 : 1);
        direction = (direction + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
        setDirectionForColumn(columnIndex, direction);
        doSortBy = false;
        initViewToModel();
        fireTableDataChanged();
    }
}
 
Example 2
Source Project: consulo   File: mxGraphHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param dx
 * @param dy
 * @param e
 */
protected void moveCells(Object[] cells, double dx, double dy, Object target, MouseEvent e) {
  mxGraph graph = graphComponent.getGraph();
  boolean clone = e.isControlDown() && isCloneEnabled();

  if (clone) {
    cells = graph.getCloneableCells(cells);
  }

  // Removes cells from parent
  if (target == null && isRemoveCellsFromParent() && shouldRemoveCellFromParent(graph.getModel().getParent(initialCell), cells, e)) {
    target = graph.getDefaultParent();
  }

  Object[] tmp = graph.moveCells(cells, dx, dy, clone, target, e.getPoint());

  if (isSelectEnabled() && clone && tmp != null && tmp.length == cells.length) {
    graph.setSelectionCells(tmp);
  }
}
 
Example 3
Source Project: openAGV   File: GroupsMouseAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void evaluateRightClick(MouseEvent e,
                                  UserObject userObject,
                                  Set<UserObject> oldSelection) {
  JTree objectTree = treeView.getTree();
  if (userObject instanceof PointUserObject
      || userObject instanceof LocationUserObject
      || userObject instanceof PathUserObject) {
    if (e.isControlDown()) {
      oldSelection.add(userObject);
      Set<ModelComponent> dataObjects = new HashSet<>();

      for (UserObject userObj : oldSelection) {
        dataObjects.add(userObj.getModelComponent());
      }

      treeView.selectItems(dataObjects);
    }

    FigureUserObject pub = (FigureUserObject) userObject;
    pub.rightClicked(objectTree, e.getX(), e.getY());
  }
  else {
    showPopupMenuGroup(userObject.getModelComponent(), e.getX(), e.getY());
  }
}
 
Example 4
Source Project: chipster   File: CoordinateArea.java    License: MIT License 6 votes vote down vote up
/**
 * 
 * @param e 
 */
public void mouseClicked(MouseEvent e) {

	//double deg = 0;
	switch (e.getButton()) {
	case MouseEvent.BUTTON1:
		if (e.isControlDown()) {
			addToSelections(e);
		}
		else {
			selectOne(e);
		}
		break;
	case MouseEvent.BUTTON2:
		break;
	case MouseEvent.BUTTON3:
		break;
	default:
	}

	this.repaint();
}
 
Example 5
@Override
public void mouseClicked(MouseEvent e) {
	JTableHeader h = (JTableHeader) e.getSource();
	TableColumnModel columnModel = h.getColumnModel();
	int viewColumn = columnModel.getColumnIndexAtX(e.getX());
	int column = columnModel.getColumn(viewColumn).getModelIndex();
	if (column != -1) {
		int status = getSortingStatus(column);
		if (!e.isControlDown()) {
			cancelSorting();
		}
		// Cycle the sorting states through {NOT_SORTED, ASCENDING,
		// DESCENDING} or
		// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether
		// shift is pressed.
		status = status + (e.isShiftDown() ? -1 : 1);
		status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0,
										// 1}
		setSortingStatus(column, status);
	}
}
 
Example 6
Source Project: jplag   File: TableSorter.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    JTableHeader h = (JTableHeader) e.getSource();
    TableColumnModel columnModel = h.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int column = columnModel.getColumn(viewColumn).getModelIndex();
    if (column != -1) {
        int status = getSortingStatus(column);
        if (!e.isControlDown()) {
            cancelSorting();
        }
        // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or 
        // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. 
        status = status + (e.isShiftDown() ? -1 : 1);
        status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
        setSortingStatus(column, status);
    }
}
 
Example 7
Source Project: chipster   File: SelectableChartPanel.java    License: MIT License 6 votes vote down vote up
public void mouseClicked(MouseEvent e) {
	if (!e.isControlDown()) {
		setSelection(null);
	}
	
	//Rectangle made by single click is grown by couple pixels to make clicking easier.
	//Growing should be done by screen pixels, and this is the latest point for that for now.
	//If accurate single click detection is needed some day later, this should be moved to 
	//SelectionChangeListeners and implement needed methods or parameters.
	
	Rectangle rect = new Rectangle((int)e.getPoint().getX(), (int)e.getPoint().getY(), 0 ,0);
	rect.grow(3, 3);
	
	Rectangle.Double translatedRect = translateToChart(rect);
			
	setSelection(translatedRect);
}
 
Example 8
public void mouseClicked(MouseEvent e) {
    JTableHeader h = (JTableHeader) e.getSource();
    TableColumnModel columnModel = h.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int column = columnModel.getColumn(viewColumn).getModelIndex();
    if (column != -1) {
        int status = getSortingStatus(column);
        if (!e.isControlDown()) {
            cancelSorting();
        }
        // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
        // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
        status = status + (e.isShiftDown() ? -1 : 1);
        status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
        setSortingStatus(column, status);
    }
}
 
Example 9
Source Project: Pixelitor   File: Debug.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static String mouseModifiers(MouseEvent e) {
    boolean altDown = e.isAltDown();
    boolean controlDown = e.isControlDown();
    boolean shiftDown = e.isShiftDown();
    boolean rightMouse = SwingUtilities.isRightMouseButton(e);
    StringBuilder msg = new StringBuilder(25);
    if (controlDown) {
        msg.append(Ansi.red("ctrl-"));
    }
    if (altDown) {
        msg.append(Ansi.green("alt-"));
    }
    if (shiftDown) {
        msg.append(Ansi.blue("shift-"));
    }
    if (rightMouse) {
        msg.append(Ansi.yellow("right-"));
    }
    if (e.isPopupTrigger()) {
        msg.append(Ansi.cyan("popup-"));
    }
    return msg.toString();
}
 
Example 10
Source Project: binnavi   File: CGraphPanelSynchronizer.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void proximityBrowserNodeClicked(final ZyProximityNode<?> proximityNode,
    final MouseEvent event, final double x, final double y) {
  if (event.getButton() == MouseEvent.BUTTON1) {
    if (!event.isShiftDown() && !event.isControlDown()) {
      m_proximityFunctions.showHiddenNodes(m_model.getParent(), m_model.getGraph(),
          (ZyProximityNode<INaviViewNode>) proximityNode);
    } else if (event.isShiftDown()) {
      m_proximityFunctions.unhideAndSelect(m_model.getGraph(),
          (ZyProximityNode<INaviViewNode>) proximityNode);
    } else if (event.isControlDown()) {
      m_proximityFunctions.unhideAndSelectOnly(m_model.getGraph(),
          (ZyProximityNode<INaviViewNode>) proximityNode);
    }
  } else if (event.getButton() == MouseEvent.BUTTON3) {
    final JPopupMenu menu =
        new CProximityNodeMenu(m_model.getParent(), m_model.getGraph(),
            (ZyProximityNode<INaviViewNode>) proximityNode);

    menu.show(m_model.getGraph().getView(), event.getX(), event.getY());
  }
}
 
Example 11
Source Project: java-swing-tips   File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override public void mousePressed(MouseEvent e) {
  Container c = SwingUtilities.getAncestorOfClass(JTable.class, e.getComponent());
  if (c instanceof JTable) {
    JTable table = (JTable) c;
    if (checkBox.getModel().isPressed() && table.isRowSelected(table.getEditingRow()) && e.isControlDown()) {
      renderer.setBackground(table.getBackground());
    } else {
      renderer.setBackground(table.getSelectionBackground());
    }
  }
}
 
Example 12
Source Project: netbeans   File: DropTargetLayer.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isMultiselectPressed(MouseEvent evt) {
    if(evt.isShiftDown()) {
        return true;
    }
    if(!isAqua() && evt.isControlDown()) {
        return true;
    }
    return false;
}
 
Example 13
public void mousePressed(MouseEvent me) {
	//must enable cancel!//if (display.isTransforming()) return;
	display.setActive(d);
	if (me.isPopupTrigger() || (ij.IJ.isMacOSX() && me.isControlDown()) || MouseEvent.BUTTON2 == me.getButton()) {
		display.showPopup(this, me.getX(), me.getY());
	}
}
 
Example 14
@Override
public void mouseEntered(MouseEvent e) {
   onEnter();
   if (inside) {
      if (b1Down(e) && e.isControlDown() || b3Down(e)) {
         onRight(e);
      } else if (b1Down(e)) {
         onLeft(e);
      } else if (b2Down(e)) {
         onMiddle(e);
      }
   }
}
 
Example 15
@Override
public void mousePressed(MouseEvent e) {
   PressOrClickMouseAdapter.inside = true;
   if (b1Down(e) && e.isControlDown() || b3Down(e)) {
      onRight(e);
   } else if (b1Down(e)) {
      onLeft(e);
   } else if (b2Down(e)) {
      onMiddle(e);
   }
}
 
Example 16
Source Project: consulo   File: WideSelectionTreeUI.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isToggleSelectionEvent(MouseEvent e) {
  return SwingUtilities.isLeftMouseButton(e) && (SystemInfo.isMac ? e.isMetaDown() : e.isControlDown()) && !e.isPopupTrigger();
}
 
Example 17
void onMouseDragged(MouseEvent e) {
        this.dragMode = true;
        int x = e.getX();
        int y = e.getY();
        switch (this.mouseMode) {
            case ZOOM_IN:
            case SELECT:
                this.repaintOld();
                break;
            case PAN:
                Plot plot = selPlot(e.getX(), e.getY());
                if (plot != null) {
                    Graphics2D g = (Graphics2D) this.getGraphics();
                    Rectangle2D mapRect = plot.getGraphArea();
                    g.setClip(mapRect);
                    g.setColor(Color.white);
                    int aX = e.getX() - mouseDownPoint.x;
                    int aY = e.getY() - mouseDownPoint.y;
                    if (aX > 0) {
                        if (mapRect.getX() >= 0) {
                            g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), aX, (int) mapRect.getHeight());
                        } else {
                            g.fillRect(0, (int) mapRect.getY(), aX, (int) mapRect.getHeight());
                        }
                    } else if (mapRect.getX() <= this.getWidth()) {
                        g.fillRect((int) (mapRect.getX() + mapRect.getWidth() + aX), (int) mapRect.getY(), Math.abs(aX), (int) mapRect.getHeight());
                    } else {
                        g.fillRect(this.getWidth() + aX, (int) mapRect.getY(), Math.abs(aX), (int) mapRect.getHeight());
                    }
                    if (aY > 0) {
                        if (mapRect.getY() >= 0) {
                            g.fillRect((int) mapRect.getX(), (int) mapRect.getY(), (int) mapRect.getWidth(), aY);
                        } else {
                            g.fillRect((int) mapRect.getX(), 0, (int) mapRect.getWidth(), aY);
                        }
                    } else if (mapRect.getY() + mapRect.getHeight() <= this.getX() + this.getHeight()) {
                        g.fillRect((int) mapRect.getX(), (int) mapRect.getY() + (int) mapRect.getHeight() + aY, (int) mapRect.getWidth(), Math.abs(aY));
                    } else {
                        g.fillRect((int) mapRect.getX(), this.getY() + this.getHeight() + aY, (int) mapRect.getWidth(), Math.abs(aY));
                    }
                    int startX = (int) mapRect.getX() + aX;
                    int startY = (int) mapRect.getY() + aY;
                    g.drawImage(tempImage, startX, startY, this);
                    g.setColor(this.getForeground());
                    g.draw(mapRect);
                }
                break;
            case ROTATE:
                plot = selPlot(this.mouseDownPoint.x, this.mouseDownPoint.y);
                if (plot != null && plot.getPlotType() == PlotType.XYZ) {
                    Plot3D plot3d = (Plot3D) plot;
                    Projector projector = plot3d.getProjector();
                    float new_value = 0.0f;
                    // if (!thread.isAlive() || !data_available) {
                    if (e.isControlDown()) {
                        projector.set2D_xTranslation(projector.get2D_xTranslation() + (x - this.mouseLastPos.x));
                        projector.set2D_yTranslation(projector.get2D_yTranslation() + (y - this.mouseLastPos.y));
                    } else if (e.isShiftDown()) {
                        new_value = projector.getY2DScaling() + (y - this.mouseLastPos.y) * 0.5f;
                        if (new_value > 60.0f) {
                            new_value = 60.0f;
                        }
                        if (new_value < 2.0f) {
                            new_value = 2.0f;
                        }
                        projector.set2DScaling(new_value);
                    } else {
                        new_value = projector.getRotationAngle() + (x - this.mouseLastPos.x);
                        while (new_value > 360) {
                            new_value -= 360;
                        }
                        while (new_value < 0) {
                            new_value += 360;
                        }
                        projector.setRotationAngle(new_value);
                        new_value = projector.getElevationAngle() + (y - this.mouseLastPos.y);
                        if (new_value > 90) {
                            new_value = 90;
                        } else if (new_value < 0) {
                            new_value = 0;
                        }
                        projector.setElevationAngle(new_value);
                    }
                    this.repaintNew();
                    //this.paintGraphics();
//                    if (!model.isExpectDelay()) {
//                        repaint();
//                    } else {
//                        if (!dragged) {
//                            is_data_available = data_available;
//                            dragged = true;
//                        }
//                        data_available = false;
//                        repaint();
//                    }
                }
                break;
        }
        mouseLastPos.x = x;
        mouseLastPos.y = y;
    }
 
Example 18
Source Project: ramus   File: Handler.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mouseDragged(final MouseEvent me) {
    ourDraggingWindow = getDraggingWindow();
    if (ourDraggingWindow == null)
        return;

    // Only allow Button 1 to perform the drag...
    if ((me.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK) {
        hideDraggingWindow();
        return;
    }

    final Container target = ourDockLayout.getTargetContainer();
    if (target == null)
        return;

    Point p = me.getPoint();
    p = SwingUtilities.convertPoint(ourToolBar, p, target);

    // Make sure the DockBoundary containing this point
    // and this toolbar wishes to allow the drag operation
    // to commence or continue...
    if (!isDraggable(p, ourToolBar)) {
        hideDraggingWindow();
        return;
    }

    // Determine if this point lies within a
    // DockBoundary's dockable range...
    int orient = ToolBarLayout.HORIZONTAL;
    boolean dockable = false;

    if (!me.isControlDown()) {
        final DockBoundary dock = getDockableBoundary(p);

        if (dock != null) {
            dockable = true;
            orient = dock.getOrientation();
        }
    }

    // Present the dragging window at this point on the screen...
    SwingUtilities.convertPointToScreen(p, target);
    ourDraggingWindow.presentWindow(p, dockable, orient);
    ourToolBarIsDragging = true;

}
 
Example 19
Source Project: netbeans   File: TableSorter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    JTableHeader h = (JTableHeader) e.getSource();
    JTable table = h.getTable();
    int selectedRow = table.getSelectedRow();
    TableModel model = table.getModel();
    //remember selection to keep after sorting
    Object selectedAction=null;
    int objectColumn=-1;
    if(selectedRow>-1) {
        for(int i=0; i<table.getColumnCount(); i++) {
            //first find colum with appropriate object
            if(model.getValueAt(selectedRow, i) instanceof ActionHolder) {
                //remember this object
                selectedAction=model.getValueAt(selectedRow, i);
                objectColumn=i;
                //stop edition as we click somewhere ouside of editor
                TableCellEditor editor=table.getCellEditor();
                if(editor!=null) {
                    editor.stopCellEditing();
                }
                break;
            }
        }
    }
    TableColumnModel columnModel = h.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int column = columnModel.getColumn(viewColumn).getModelIndex();
    if (column != -1) {
        int status = getSortingStatus(column);
        if (!e.isControlDown()) {
            cancelSorting();
        }
        // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or 
        // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. 
        status = status + (e.isShiftDown() ? -1 : 1);
        status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
        setSortingStatus(column, status);
        //reselect the same object
        if(selectedAction!=null)setSelectedRow(table, selectedAction, objectColumn);
    }
}
 
Example 20
/**
 * Predicate to check if the display should be rezoomed to fit as
 * close as possible to the rubber definition.
 * Default is to have both Shift and Control keys pressed when the mouse is
 * released.
 *
 * @param e the mouse context
 * @return the predicate result
 */
public static boolean isRezoomWanted (MouseEvent e)
{
    if (WellKnowns.MAC_OS_X) {
        return e.isMetaDown() && e.isShiftDown();
    } else {
        return e.isControlDown() && e.isShiftDown();
    }
}