@Override
public void mousePressed(MouseEvent e) {
Point point = e.getPoint();
draggingStart = point;
boolean leftMousePressed = (e.getButton() == MouseEvent.BUTTON1);
boolean rightMousePressed = (e.getButton() == MouseEvent.BUTTON3);
if (leftMousePressed) {
if (resizingMode == 0) {
focusedComponent = findComponent(point);
if (e.isPopupTrigger()) { // Mac
if (!selection.contains(focusedComponent)) {
setSelection(focusedComponent);
}
showPopupMenu(point);
} else if (!e.isShiftDown()) { // shift adding to selection on mouse release
if (focusedComponent != null && ctrlOrCmdModifier(e)) {
Set newSelection = new HashSet();
newSelection.addAll(selection);
if (selection.contains(focusedComponent)) {
newSelection.remove(focusedComponent);
} else {
newSelection.add(focusedComponent);
}
setSelection(newSelection);
} else if (!selection.contains(focusedComponent)) {
setSelection(focusedComponent);
}
}
// // Column selection
// int column = findColumnHeader(point);
// if (column != -1) {
selectedColumns.flip(column);
// }
// // Row selection
// int row = findRowHeader(point);
// if (row != -1) {
selectedRows.flip(row);
// }
} else {
// Resizing (start)
resizing = true;
requestFocusInWindow();
draggingRect = fromComponentPane(selectionResizingBounds(focusedComponent));
newGridX = gridInfo.getGridX(focusedComponent);
newGridY = gridInfo.getGridY(focusedComponent);
newGridHeight = gridInfo.getGridHeight(focusedComponent);
newGridWidth = gridInfo.getGridWidth(focusedComponent);
initSelFields();
}
} else if (rightMousePressed) {
if (moving || resizing) {
moving = false;
resizing = false;
draggingStart = null;
} else {
focusedComponent = findComponent(point);
if (!selection.contains(focusedComponent)) {
setSelection(focusedComponent);
}
if (e.isPopupTrigger()) { // Linux
showPopupMenu(point);
}
}
}
repaint();
}