Lines 216-231
AtomicLockListener, FoldHierarchyListene
Link Here
|
216 |
|
216 |
|
217 |
/** Is the caret italic for italic fonts */ |
217 |
/** Is the caret italic for italic fonts */ |
218 |
boolean italic; |
218 |
boolean italic; |
219 |
|
219 |
|
220 |
private int xPoints[] = new int[4]; |
220 |
private int xPoints[] = new int[4]; |
221 |
private int yPoints[] = new int[4]; |
221 |
private int yPoints[] = new int[4]; |
222 |
private Action selectWordAction; |
222 |
private Action selectWordAction; |
223 |
private Action selectLineAction; |
223 |
private Action selectLineAction; |
|
|
224 |
private Action navigationHistoryBackAction; |
225 |
private Action navigationHistoryForwardAction; |
224 |
|
226 |
|
225 |
/** Change event. Only one instance needed because it has only source property */ |
227 |
/** Change event. Only one instance needed because it has only source property */ |
226 |
protected ChangeEvent changeEvent; |
228 |
protected ChangeEvent changeEvent; |
227 |
|
229 |
|
228 |
/** Dot array of one character under caret */ |
230 |
/** Dot array of one character under caret */ |
229 |
protected char dotChar[] = {' '}; |
231 |
protected char dotChar[] = {' '}; |
230 |
|
232 |
|
231 |
private boolean overwriteMode; |
233 |
private boolean overwriteMode; |
Lines 1465-1548
AtomicLockListener, FoldHierarchyListene
Link Here
|
1465 |
// MouseListener methods |
1467 |
// MouseListener methods |
1466 |
@Override |
1468 |
@Override |
1467 |
public void mousePressed(MouseEvent evt) { |
1469 |
public void mousePressed(MouseEvent evt) { |
1468 |
if (LOG.isLoggable(Level.FINE)) { |
1470 |
if (LOG.isLoggable(Level.FINE)) { |
1469 |
LOG.fine("mousePressed: " + logMouseEvent(evt) + ", state=" + mouseState + '\n'); // NOI18N |
1471 |
LOG.fine("mousePressed: " + logMouseEvent(evt) + ", state=" + mouseState + '\n'); // NOI18N |
1470 |
} |
1472 |
} |
1471 |
|
1473 |
|
1472 |
JTextComponent c = component; |
1474 |
JTextComponent c = component; |
1473 |
if (c != null && isLeftMouseButtonExt(evt)) { |
1475 |
if (c != null) { |
1474 |
// Expand fold if offset is in collapsed fold |
1476 |
if (isLeftMouseButtonExt(evt)) { |
1475 |
int offset = mouse2Offset(evt); |
1477 |
// Expand fold if offset is in collapsed fold |
1476 |
switch (evt.getClickCount()) { |
1478 |
int offset = mouse2Offset(evt); |
1477 |
case 1: // Single press |
1479 |
switch (evt.getClickCount()) { |
1478 |
if (c.isEnabled() && !c.hasFocus()) { |
1480 |
case 1: // Single press |
1479 |
c.requestFocus(); |
1481 |
if (c.isEnabled() && !c.hasFocus()) { |
1480 |
} |
1482 |
c.requestFocus(); |
1481 |
c.setDragEnabled(true); |
1483 |
} |
1482 |
if (evt.isShiftDown()) { // Select till offset |
1484 |
c.setDragEnabled(true); |
1483 |
moveDot(offset); |
1485 |
if (evt.isShiftDown()) { // Select till offset |
1484 |
adjustRectangularSelectionMouseX(evt.getX(), evt.getY()); // also fires state change |
1486 |
moveDot(offset); |
1485 |
mouseState = MouseState.CHAR_SELECTION; |
1487 |
adjustRectangularSelectionMouseX(evt.getX(), evt.getY()); // also fires state change |
1486 |
} else { // Regular press |
|
|
1487 |
// check whether selection drag is possible |
1488 |
if (isDragPossible(evt) && mapDragOperationFromModifiers(evt) != TransferHandler.NONE) { |
1489 |
mouseState = MouseState.DRAG_SELECTION_POSSIBLE; |
1490 |
} else { // Drag not possible |
1491 |
mouseState = MouseState.CHAR_SELECTION; |
1488 |
mouseState = MouseState.CHAR_SELECTION; |
1492 |
setDot(offset); |
1489 |
} else { // Regular press |
|
|
1490 |
// check whether selection drag is possible |
1491 |
if (isDragPossible(evt) && mapDragOperationFromModifiers(evt) != TransferHandler.NONE) { |
1492 |
mouseState = MouseState.DRAG_SELECTION_POSSIBLE; |
1493 |
} else { // Drag not possible |
1494 |
mouseState = MouseState.CHAR_SELECTION; |
1495 |
setDot(offset); |
1496 |
} |
1493 |
} |
1497 |
} |
1494 |
} |
1498 |
break; |
1495 |
break; |
|
|
1496 |
|
1499 |
|
1497 |
case 2: // double-click => word selection |
1500 |
case 2: // double-click => word selection |
1498 |
mouseState = MouseState.WORD_SELECTION; |
1501 |
mouseState = MouseState.WORD_SELECTION; |
1499 |
// Disable drag which would otherwise occur when mouse would be over text |
1502 |
// Disable drag which would otherwise occur when mouse would be over text |
1500 |
c.setDragEnabled(false); |
1503 |
c.setDragEnabled(false); |
1501 |
// Check possible fold expansion |
1504 |
// Check possible fold expansion |
1502 |
try { |
1505 |
try { |
1503 |
// hack, to get knowledge of possible expansion. Editor depends on Folding, so it's not really possible |
1506 |
// hack, to get knowledge of possible expansion. Editor depends on Folding, so it's not really possible |
1504 |
// to have Folding depend on BaseCaret (= a cycle). If BaseCaret moves to editor.lib2, this contract |
1507 |
// to have Folding depend on BaseCaret (= a cycle). If BaseCaret moves to editor.lib2, this contract |
1505 |
// can be formalized as an interface. |
1508 |
// can be formalized as an interface. |
1506 |
Callable<Boolean> cc = (Callable<Boolean>)c.getClientProperty("org.netbeans.api.fold.expander"); |
1509 |
Callable<Boolean> cc = (Callable<Boolean>)c.getClientProperty("org.netbeans.api.fold.expander"); |
1507 |
if (cc == null || !cc.equals(this)) { |
1510 |
if (cc == null || !cc.equals(this)) { |
1508 |
if (selectWordAction == null) { |
1511 |
if (selectWordAction == null) { |
1509 |
selectWordAction = ((BaseKit) c.getUI().getEditorKit( |
1512 |
selectWordAction = ((BaseKit) c.getUI().getEditorKit( |
1510 |
c)).getActionByName(BaseKit.selectWordAction); |
1513 |
c)).getActionByName(BaseKit.selectWordAction); |
|
|
1514 |
} |
1515 |
if (selectWordAction != null) { |
1516 |
selectWordAction.actionPerformed(null); |
1517 |
} |
1518 |
// Select word action selects forward i.e. dot > mark |
1519 |
minSelectionStartOffset = getMark(); |
1520 |
minSelectionEndOffset = getDot(); |
1511 |
} |
1521 |
} |
1512 |
if (selectWordAction != null) { |
1522 |
} catch (Exception ex) { |
1513 |
selectWordAction.actionPerformed(null); |
1523 |
Exceptions.printStackTrace(ex); |
1514 |
} |
1524 |
} |
|
|
1525 |
break; |
1526 |
|
1527 |
case 3: // triple-click => line selection |
1528 |
mouseState = MouseState.LINE_SELECTION; |
1529 |
// Disable drag which would otherwise occur when mouse would be over text |
1530 |
c.setDragEnabled(false); |
1531 |
if (selectLineAction == null) { |
1532 |
selectLineAction = ((BaseKit) c.getUI().getEditorKit( |
1533 |
c)).getActionByName(BaseKit.selectLineAction); |
1534 |
} |
1535 |
if (selectLineAction != null) { |
1536 |
selectLineAction.actionPerformed(null); |
1515 |
// Select word action selects forward i.e. dot > mark |
1537 |
// Select word action selects forward i.e. dot > mark |
1516 |
minSelectionStartOffset = getMark(); |
1538 |
minSelectionStartOffset = getMark(); |
1517 |
minSelectionEndOffset = getDot(); |
1539 |
minSelectionEndOffset = getDot(); |
1518 |
} |
1540 |
} |
1519 |
} catch (Exception ex) { |
1541 |
break; |
1520 |
Exceptions.printStackTrace(ex); |
|
|
1521 |
} |
1522 |
break; |
1523 |
|
1524 |
case 3: // triple-click => line selection |
1525 |
mouseState = MouseState.LINE_SELECTION; |
1526 |
// Disable drag which would otherwise occur when mouse would be over text |
1527 |
c.setDragEnabled(false); |
1528 |
if (selectLineAction == null) { |
1529 |
selectLineAction = ((BaseKit) c.getUI().getEditorKit( |
1530 |
c)).getActionByName(BaseKit.selectLineAction); |
1531 |
} |
1532 |
if (selectLineAction != null) { |
1533 |
selectLineAction.actionPerformed(null); |
1534 |
// Select word action selects forward i.e. dot > mark |
1535 |
minSelectionStartOffset = getMark(); |
1536 |
minSelectionEndOffset = getDot(); |
1537 |
} |
1538 |
break; |
1539 |
|
1542 |
|
1540 |
default: // multi-click |
1543 |
default: // multi-click |
|
|
1544 |
} |
1545 |
} else if (isBackMouseButtonExt(evt)) { |
1546 |
if (navigationHistoryBackAction == null) { |
1547 |
navigationHistoryBackAction = ((BaseKit) c.getUI().getEditorKit( |
1548 |
c)).getActionByName(BaseKit.jumpListPrevAction); |
1549 |
} |
1550 |
if (navigationHistoryBackAction != null) { |
1551 |
navigationHistoryBackAction.actionPerformed(null); |
1552 |
} |
1553 |
} else if (isForwardMouseButtonExt(evt)) { |
1554 |
if (navigationHistoryForwardAction == null) { |
1555 |
navigationHistoryForwardAction = ((BaseKit) c.getUI().getEditorKit( |
1556 |
c)).getActionByName(BaseKit.jumpListNextAction); |
1557 |
} |
1558 |
if (navigationHistoryForwardAction != null) { |
1559 |
navigationHistoryForwardAction.actionPerformed(null); |
1560 |
} |
1541 |
} |
1561 |
} |
1542 |
} |
1562 |
} |
1543 |
} |
1563 |
} |
1544 |
|
1564 |
|
1545 |
@Override |
1565 |
@Override |
1546 |
public void mouseReleased(MouseEvent evt) { |
1566 |
public void mouseReleased(MouseEvent evt) { |
1547 |
if (LOG.isLoggable(Level.FINE)) { |
1567 |
if (LOG.isLoggable(Level.FINE)) { |
1548 |
LOG.fine("mouseReleased: " + logMouseEvent(evt) + ", state=" + mouseState + '\n'); // NOI18N |
1568 |
LOG.fine("mouseReleased: " + logMouseEvent(evt) + ", state=" + mouseState + '\n'); // NOI18N |
Lines 1934-1949
AtomicLockListener, FoldHierarchyListene
Link Here
|
1934 |
moveDot(Math.min(newDot, minSelectionStartOffset)); |
1954 |
moveDot(Math.min(newDot, minSelectionStartOffset)); |
1935 |
} else { // newDot > mark => swap mark and dot |
1955 |
} else { // newDot > mark => swap mark and dot |
1936 |
setDot(minSelectionStartOffset); |
1956 |
setDot(minSelectionStartOffset); |
1937 |
moveDot(Math.max(newDot, minSelectionEndOffset)); |
1957 |
moveDot(Math.max(newDot, minSelectionEndOffset)); |
1938 |
} |
1958 |
} |
1939 |
} |
1959 |
} |
1940 |
} |
1960 |
} |
1941 |
|
1961 |
|
|
|
1962 |
|
1963 |
private boolean isBackMouseButtonExt(MouseEvent evt) { |
1964 |
return (evt.getButton() == 6 |
1965 |
&& !(evt.isPopupTrigger()) |
1966 |
&& (evt.getModifiers() & (InputEvent.META_MASK | InputEvent.ALT_MASK)) == 0); |
1967 |
} |
1968 |
|
1969 |
private boolean isForwardMouseButtonExt(MouseEvent evt) { |
1970 |
return (evt.getButton() == 7 |
1971 |
&& !(evt.isPopupTrigger()) |
1972 |
&& (evt.getModifiers() & (InputEvent.META_MASK | InputEvent.ALT_MASK)) == 0); |
1973 |
} |
1974 |
|
1942 |
private boolean isLeftMouseButtonExt(MouseEvent evt) { |
1975 |
private boolean isLeftMouseButtonExt(MouseEvent evt) { |
1943 |
return (SwingUtilities.isLeftMouseButton(evt) |
1976 |
return (SwingUtilities.isLeftMouseButton(evt) |
1944 |
&& !(evt.isPopupTrigger()) |
1977 |
&& !(evt.isPopupTrigger()) |
1945 |
&& (evt.getModifiers() & (InputEvent.META_MASK | InputEvent.ALT_MASK)) == 0); |
1978 |
&& (evt.getModifiers() & (InputEvent.META_MASK | InputEvent.ALT_MASK)) == 0); |
1946 |
} |
1979 |
} |
1947 |
|
1980 |
|
1948 |
private boolean isMiddleMouseButtonExt(MouseEvent evt) { |
1981 |
private boolean isMiddleMouseButtonExt(MouseEvent evt) { |
1949 |
return (evt.getButton() == MouseEvent.BUTTON2) && |
1982 |
return (evt.getButton() == MouseEvent.BUTTON2) && |