下面列出了java.awt.event.MouseEvent#isShiftDown() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
@Override
public void mouseClicked(MouseEvent me) {
super.mouseClicked(me);
int inClick = 1;
current = inClick;
if (me.getClickCount() == 1) {
if (me.isShiftDown()) {
if (selectedBlock.isSelected()) {
if (!selectedBlock.isSelectedCol(getCol(me.getPoint())))
selectedBlock.extendSelection(-1, getCol(me.getPoint()));
else
selectedBlock.reduceSelection(-1, getCol(me.getPoint()));
}
} else {
selectedBlock.clear();
}
} else if (me.getClickCount() == 2) {
selectedBlock.selectCol(getCol(me.getPoint()), alignment.isTranslate());
}
}
@Override
public boolean isForceMarqueeEvent(MouseEvent e) {
if (e.isShiftDown()) {
return false;
}
if (SwingUtilities.isRightMouseButton(e)) {
return true;
}
port = getSourcePortAt(e.getPoint());
if (port != null) {
return true;
}
return super.isForceMarqueeEvent(e);
}
public void mouseDragged(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if (!list.isEnabled()) {
return;
}
if (e.isShiftDown() || e.isControlDown()) {
return;
}
int row = MultiColumnListUI.this.locationToIndex(e.getX(), e.getY());
if (row != -1) {
Rectangle cellBounds = getCellBounds(list, row, row);
if (cellBounds != null) {
list.scrollRectToVisible(cellBounds);
list.setSelectionInterval(row, row);
}
}
}
@Override
public void mouseClicked(final MouseEvent e) {
if (currentTransform == null || Input.getKeyboardInput().isSpace()) {
final float x = Input.getCursorPosition().getX();
final float y = Input.getCursorPosition().getY();
origin.setX(x);
origin.setY(y);
upRight.setX(x + 100);
upRight.setY(y);
downRight.setX(x + 100);
downRight.setY(y + 100);
downLeft.setX(x);
downLeft.setY(y + 100);
} else if (e.isShiftDown() || e.isAltDown()) {
savedTransforms.add(currentTransform);
rects.addTag("rect" + savedTransforms.size(), currentTransform.getX() + "f, " + currentTransform.getY() + "f, " + currentTransform.getWidth() + "f, " + currentTransform.getHeight() + "f");
currentTransform = null;
}
}
@Override public void mouseClicked(MouseEvent e) {
JTableHeader h = (JTableHeader) e.getComponent();
TableColumnModel columnModel = h.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
// ArrayIndexOutOfBoundsException: -1
if (viewColumn < 0) {
return;
}
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column) + (e.isShiftDown() ? -1 : 1);
if (!e.isControlDown()) {
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
// int d = e.isShiftDown() ? -1 : 1;
// status = status + d;
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
setSortingStatus(column, status);
}
}
@Override public boolean isCellEditable(EventObject e) {
if (e instanceof MouseEvent) {
MouseEvent me = (MouseEvent) e;
return !(me.isShiftDown() || me.isControlDown());
}
return super.isCellEditable(e);
}
public void mousePressed(MouseEvent e)
{
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if (!list.isEnabled()) {
return;
}
/* Request focus before updating the list selection. This implies
* that the current focus owner will see a focusLost() event
* before the lists selection is updated IF requestFocus() is
* synchronous (it is on Windows). See bug 4122345
*/
if (!list.hasFocus()) {
list.requestFocus();
}
int row = locationToIndex(e.getX(), e.getY());
if (row != -1) {
list.setValueIsAdjusting(true);
int anchorIndex = list.getAnchorSelectionIndex();
if (e.isControlDown()) {
if (list.isSelectedIndex(row)) {
list.removeSelectionInterval(row, row);
}
else {
list.addSelectionInterval(row, row);
}
}
else if (e.isShiftDown() && (anchorIndex != -1)) {
list.setSelectionInterval(anchorIndex, row);
}
else {
list.setSelectionInterval(row, row);
}
}
}
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
showPopupMenu(e);
} else {
if (e.getSource() instanceof JTableHeader) {
columnPressed = jTable.getTableHeader().columnAtPoint(e.getPoint());
if (columnPressed >= 0) {
if (!e.isShiftDown() && !e.isMetaDown())
clearSelection();
selectColumn(columnPressed, true);
}
}
}
}
@Override
public void mouseReleased(final MouseEvent me, final Layer la, final int x_p, final int y_p, final int x_d, final int y_d, final int x_r, final int y_r) {
if (null == getActive()) return;
if (me.isShiftDown() && me.isAltDown() && !Utils.isControlDown(me)) {
updateViewData(getActive());
return;
}
super.mouseReleased(me, la, x_p, y_p, x_d, y_d, x_r, y_r);
}
@Override
public void mouseReleased(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
prevLeftMousePoint = e.getPoint();
}
if(e.isPopupTrigger()) {
showContextMenu(e.getPoint());
return;
}
if(dragop.isStarted() && !e.isShiftDown()) {
dragop.end(e);
} else {
if(!isEditing) {
JComponent c = dragop.getDeepestComponentInPopups(e.getPoint());
if(c != null) {
if(c instanceof JMenuItem) {
Point localPt = SwingUtilities.convertPoint(glassLayer, e.getPoint(), c);
selectedPortion = DropTargetLayer.calculateSelectedPortion((JMenuItem)c, localPt);
dropTargetLayer.repaint();
} else {
selectedPortion = SelectedPortion.None;
}
glassLayer.requestFocusInWindow();
RADComponent rad = formDesigner.getMetaComponent(c);
//add to selection if shift is down, instead of replacing
if(DropTargetLayer.isMultiselectPressed(e)) {
if(e.isShiftDown()) {// add component to selection
addSelectedRADComponent(rad);
} else if (e.isControlDown()) {// #119217: toggle component's selection status
toggleSelectedRADComponent(rad);
}
} else {
setSelectedRADComponent(rad);
}
}
}
isEditing = false;
}
}
@Override
public void mousePressed(final MouseEvent me, final Layer layer, int x_p, int y_p, final double mag) {
// transform the x_p, y_p to the local coordinates
if (!this.at.isIdentity()) {
final Point2D.Double po = inverseTransformPoint(x_p, y_p);
x_p = (int)po.x;
y_p = (int)po.y;
}
final int tool = ProjectToolbar.getToolId();
if (ProjectToolbar.PEN == tool) {
final long layer_id = layer.getId();
if (Utils.isControlDown(me) && me.isShiftDown()) {
index = findNearestPoint(p, p_layer, n_points, x_p, y_p, layer.getId()); // should go to an AbstractProfile or something
} else {
index = findPoint(p, x_p, y_p, mag, layer.getId());
}
if (-1 != index) {
if (layer_id == p_layer[index]) {
if (Utils.isControlDown(me) && me.isShiftDown() && p_layer[index] == Display.getFrontLayer().getId()) {
removePoint(index);
index = -1; // to prevent saving in the database twice
repaint(false, layer);
return;
}
} else index = -1; // disable if not in the front layer (so a new point will be added)
if (-1 != index) {
// Make the radius for newly added balls that of the last selected
last_radius = p_width[index];
}
}
if (-1 == index) {
index = addPoint(x_p, y_p, layer_id, (0 == n_points ? Ball.getFirstWidth() : p_width[n_points -1])); // either 10 screen pixels or the same as the last point
repaint(false, layer);
}
}
}
/**
* Invoked when a mouse button has been pressed and released on a component
*
* @param e the mouse event
*/
@Override
public void mouseClicked(MouseEvent e) {
int col;
boolean popup;
col = m_TableData.columnAtPoint(e.getPoint());
popup =
((e.getButton() == MouseEvent.BUTTON3) && (e.getClickCount() == 1))
|| ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 1)
&& e.isAltDown() && !e.isControlDown() && !e.isShiftDown());
popup = popup && (getInstances() != null);
if (e.getSource() == m_TableData.getTableHeader()) {
m_CurrentCol = col;
// Popup-Menu
if (popup) {
e.consume();
setMenu();
initPopupMenus();
m_PopupHeader.show(e.getComponent(), e.getX(), e.getY());
}
} else if (e.getSource() == m_TableData) {
// Popup-Menu
if (popup) {
e.consume();
setMenu();
initPopupMenus();
m_PopupRows.show(e.getComponent(), e.getX(), e.getY());
}
}
// highlihgt column
if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 1)
&& (!e.isAltDown()) && (col > -1)) {
m_TableData.setSelectedColumn(col);
}
}
@Override
public void mousePressed( final MouseEvent me, final int x_p, final int y_p, final double magnification )
{
/* find if clicked on a point */
p_clicked = null;
double min = Double.MAX_VALUE;
final Point mouse = new Point( new double[]{ x_p, y_p } );
final double a = 64.0 / magnification / magnification;
for ( final Point p : points )
{
final double sd = Point.squareDistance( p, mouse );
if ( sd < min && sd < a )
{
p_clicked = p;
min = sd;
}
}
if ( me.isShiftDown() )
{
if ( null == p_clicked )
{
/* add one */
try
{
if ( points.size() > 0 )
{
/*
* Create a pseudo-invertible (TransformMesh) for the screen.
*/
final CoordinateTransform mlst = createCT();
final SimilarityModel2D toWorld = new SimilarityModel2D();
toWorld.set( 1.0 / magnification, 0, srcRect.x, srcRect.y );
final SimilarityModel2D toScreen = toWorld.createInverse();
final mpicbg.models.CoordinateTransformList< mpicbg.models.CoordinateTransform > ctl = new mpicbg.models.CoordinateTransformList< mpicbg.models.CoordinateTransform >();
ctl.add( toWorld );
ctl.add( mlst );
ctl.add( toScreen );
final CoordinateTransformMesh ctm = new CoordinateTransformMesh(
ctl,
32,
( int )Math.ceil( srcRect.width * magnification ),
( int )Math.ceil( srcRect.height * magnification ) );
final double[] l = mouse.getL();
toScreen.applyInPlace( l );
ctm.applyInverseInPlace( l );
toWorld.applyInPlace( l );
}
points.add( mouse );
p_clicked = mouse;
}
catch ( final Exception e )
{
Utils.log( "Could not add point" );
e.printStackTrace();
}
}
else if ( Utils.isControlDown( me ) )
{
// remove it
points.remove(p_clicked);
p_clicked = null;
}
}
}
/**
* Invoked when a mouse button has been pressed on a component.
*/
public void mousePressed( final MouseEvent e ) {
if ( isMouseOperationPossible() ) {
return;
}
if ( getDesignerContext().isSelectionWaiting() == false ) {
return;
}
newlySelectedElements.clear();
normalizedSelectionRectangleOrigin = normalize( e.getPoint() );
normalizedSelectionRectangleOrigin.setLocation( Math.max( 0,
normalizedSelectionRectangleOrigin.getX() ), Math.max( 0, normalizedSelectionRectangleOrigin.getY() ) );
selectionRectangleOrigin = e.getPoint();
if ( e.isShiftDown() == false ) {
clearSelectionOnDrag = true;
}
final ReportDocumentContext renderContext = getRenderContext();
final ElementRenderer rendererRoot = getElementRenderer();
final DocumentContextSelectionModel selectionModel = renderContext.getSelectionModel();
final Element[] allNodes = rendererRoot.getElementsAt
( normalizedSelectionRectangleOrigin.getX(), normalizedSelectionRectangleOrigin.getY() );
for ( int i = allNodes.length - 1; i >= 0; i -= 1 ) {
final Element element = allNodes[ i ];
if ( element instanceof RootLevelBand ) {
continue;
}
if ( !e.isShiftDown() ) {
if ( !selectionModel.isSelected( element ) ) {
selectionModel.clearSelection();
selectionModel.add( element );
return;
}
}
}
}
@Override
public void mouseDragged(final MouseEvent me, final Layer layer, int x_p, int y_p, int x_d, int y_d, int x_d_old, int y_d_old) {
// transform to the local coordinates
if (!this.at.isIdentity()) {
final Point2D.Double p = inverseTransformPoint(x_p, y_p);
x_p = (int)p.x;
y_p = (int)p.y;
final Point2D.Double pd = inverseTransformPoint(x_d, y_d);
x_d = (int)pd.x;
y_d = (int)pd.y;
final Point2D.Double pdo = inverseTransformPoint(x_d_old, y_d_old);
x_d_old = (int)pdo.x;
y_d_old = (int)pdo.y;
}
final int tool = ProjectToolbar.getToolId();
if (ProjectToolbar.PEN == tool) {
//if a point in the backbone is found, then:
if (-1 != index) {
if (!me.isAltDown() && !me.isShiftDown()) {
dragPoint(index, x_d - x_d_old, y_d - y_d_old);
} else if (me.isShiftDown()) {
// resize radius
p_width[index] = Math.sqrt((x_d - p[0][index])*(x_d - p[0][index]) + (y_d - p[1][index])*(y_d - p[1][index]));
last_radius = p_width[index];
Utils.showStatus("radius: " + p_width[index], false);
} else { //TODO in linux the alt+click is stolen by the KDE window manager but then the middle-click works as if it was the alt+click. Weird!
//drag both control points symmetrically
dragControlPoint(index, x_d, y_d, p_l, p_r, true);
}
generateInterpolatedPoints(0.05);
repaint(false, layer);
return;
}
//if a control point is found, then drag it, adjusting the other control point non-symmetrically
if (-1 != index_r) {
dragControlPoint(index_r, x_d, y_d, p_r, p_l, is_new_point); //((index_r != n_points-1)?false:true)); //last point gets its 2 control points dragged symetrically
generateInterpolatedPoints(0.05);
repaint(false, layer);
return;
}
if (-1 != index_l) {
dragControlPoint(index_l, x_d, y_d, p_l, p_r, is_new_point); //((index_l != n_points-1)?false:true)); //last point gets its 2 control points dragged symetrically
generateInterpolatedPoints(0.05);
repaint(false, layer);
return;
}
}
}
private static boolean onlyShift(MouseEvent e) {
return e.isShiftDown() && !(e.isAltDown() || e.isAltGraphDown() ||
e.isControlDown() || e.isMetaDown());
}
private void LabeledRectangleClicked(MouseEvent event, List<LabeledRectangle> components) {
int startIndex = 0;
int endIndex = 0;
for (LabeledRectangle component : components) {
if (component.contains(event.getPoint())) {
if ((event.getModifiers() & shortcutMask) == shortcutMask) { // Add one at a time
component.toggleSelected();
} else if (event.isShiftDown()) { // Add in consecutive order
startIndex = Math.min(components.indexOf(lastSelectedRectangle), components.indexOf(component));
endIndex = Math.max(components.indexOf(lastSelectedRectangle), components.indexOf(component));
if (startIndex >= 0 && endIndex >= 0) {
for (int i = startIndex; i <= endIndex; i++) {
components.get(i).setSelected(true);
}
} else {
component.toggleSelected();
}
} else {
component.setSelected(true);
}
if (component.isSelected()) {
lastSelectedRectangle = component;
} else {
lastSelectedRectangle = null;
}
boolean isSourceComponent = sourceComponents.contains(component);
detailsListener.showDetails(component.getItem(), isSourceComponent);
repaint();
if (event.getClickCount() == 2 && isSourceComponent && !component.getItem().isStem()) {
if (slaveMappingPanel != null) {
// Create dummy mapping
slaveMappingPanel.setMapping(
new Mapping<>(((Table) component.getItem()).getFields(), new ArrayList<>(), new ArrayList<>())
);
// Zoom arrow has to be set, but will not be shown
zoomArrow = new Arrow(
component,
components.get(0) // random target for the arrow
);
new AnimateThread(true).start();
slaveMappingPanel.filterComponents("", false);
slaveMappingPanel.filterComponents("", true);
}
}
break;
}
}
}
@Override
public void mousePressed(MouseEvent evt) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("mousePressed: " + logMouseEvent(evt) + ", state=" + mouseState + '\n'); // NOI18N
}
JTextComponent c = component;
if (c != null && isLeftMouseButtonExt(evt)) {
// Expand fold if offset is in collapsed fold
int offset = mouse2Offset(evt);
switch (evt.getClickCount()) {
case 1: // Single press
if (c.isEnabled() && !c.hasFocus()) {
c.requestFocus();
}
c.setDragEnabled(true);
if (evt.isShiftDown()) { // Select till offset
moveDot(offset);
adjustRectangularSelectionMouseX(evt.getX(), evt.getY()); // also fires state change
mouseState = MouseState.CHAR_SELECTION;
} else { // Regular press
// check whether selection drag is possible
if (isDragPossible(evt) && mapDragOperationFromModifiers(evt) != TransferHandler.NONE) {
mouseState = MouseState.DRAG_SELECTION_POSSIBLE;
} else { // Drag not possible
mouseState = MouseState.CHAR_SELECTION;
setDot(offset);
}
}
break;
case 2: // double-click => word selection
mouseState = MouseState.WORD_SELECTION;
// Disable drag which would otherwise occur when mouse would be over text
c.setDragEnabled(false);
// Check possible fold expansion
try {
// hack, to get knowledge of possible expansion. Editor depends on Folding, so it's not really possible
// to have Folding depend on BaseCaret (= a cycle). If BaseCaret moves to editor.lib2, this contract
// can be formalized as an interface.
Callable<Boolean> cc = (Callable<Boolean>)c.getClientProperty("org.netbeans.api.fold.expander");
if (cc == null || !cc.equals(this)) {
if (selectWordAction == null) {
selectWordAction = ((BaseKit) c.getUI().getEditorKit(
c)).getActionByName(BaseKit.selectWordAction);
}
if (selectWordAction != null) {
selectWordAction.actionPerformed(null);
}
// Select word action selects forward i.e. dot > mark
minSelectionStartOffset = getMark();
minSelectionEndOffset = getDot();
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
break;
case 3: // triple-click => line selection
mouseState = MouseState.LINE_SELECTION;
// Disable drag which would otherwise occur when mouse would be over text
c.setDragEnabled(false);
if (selectLineAction == null) {
selectLineAction = ((BaseKit) c.getUI().getEditorKit(
c)).getActionByName(BaseKit.selectLineAction);
}
if (selectLineAction != null) {
selectLineAction.actionPerformed(null);
// Select word action selects forward i.e. dot > mark
minSelectionStartOffset = getMark();
minSelectionEndOffset = getDot();
}
break;
default: // multi-click
}
}
}
@Override
public void mouseClicked(final MouseEvent e) {
if (!tracerPlugin.isReady())
return;
final int currentState = tracerPlugin.resultsDialog.getState();
if (currentState == NeuriteTracerResultsDialog.LOADING || currentState == NeuriteTracerResultsDialog.SAVING
|| currentState == NeuriteTracerResultsDialog.IMAGE_CLOSED) {
// Do nothing
} else if (currentState == NeuriteTracerResultsDialog.WAITING_FOR_SIGMA_POINT) {
tracerPlugin.launchPaletteAround(myOffScreenX(e.getX()), myOffScreenY(e.getY()), imp.getCurrentSlice() - 1);
} else if (currentState == NeuriteTracerResultsDialog.WAITING_FOR_SIGMA_CHOICE) {
SNT.error("You must close the sigma palette to continue");
} else if (tracerPlugin.setupTrace) {
final boolean join = IJ.isMacintosh() ? e.isAltDown() : e.isControlDown();
if (tracerPlugin.snapCursor && !join && !e.isShiftDown()) {
tracerPlugin.clickForTrace(last_x_in_pane_precise, last_y_in_pane_precise, plane, join);
} else {
tracerPlugin.clickForTrace(myOffScreenXD(e.getX()), myOffScreenYD(e.getY()), plane, join);
}
} else
SNT.error("BUG: No operation chosen");
}