Skip to content

Commit 49d76d1

Browse files
hansonrhansonr
authored andcommitted
2019.07.01 working on JTable key navigation events
1 parent 674d2d9 commit 49d76d1

File tree

3 files changed

+37
-103
lines changed

3 files changed

+37
-103
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
2019.07.01 working on JSEditorPaneUI tab business
2-
2019.07.01 AppContext.getApplet(name) initial work
2+
2019.07.01 AppContext.getApplet(name) initial work
3+
2019.07.01 working on JTable key navigation events

sources/net.sf.j2s.java.core/src/swingjs/plaf/HTML5LookAndFeel.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,8 +1644,8 @@ public Object createValue(UIDefaults table) {
16441644
controlText,
16451645
//"Table.focusCellHighlightBorder", focusCellHighlightBorder,
16461646
"Table.scrollPaneBorder", loweredBevelBorder,
1647-
// "Table.ancestorInputMap",
1648-
// new UIDefaults.LazyInputMap(new Object[] {
1647+
"Table.ancestorInputMap",
1648+
new UIDefaults.LazyInputMap(new Object[] {
16491649
// "ctrl C", "copy",
16501650
// "ctrl V", "paste",
16511651
// "ctrl X", "cut",
@@ -1655,69 +1655,69 @@ public Object createValue(UIDefaults table) {
16551655
// "control INSERT", "copy",
16561656
// "shift INSERT", "paste",
16571657
// "shift DELETE", "cut",
1658-
// "RIGHT", "selectNextColumn",
1659-
// "KP_RIGHT", "selectNextColumn",
1660-
// "shift RIGHT", "selectNextColumnExtendSelection",
1661-
// "shift KP_RIGHT", "selectNextColumnExtendSelection",
1658+
"RIGHT", "selectNextColumn",
1659+
"KP_RIGHT", "selectNextColumn",
1660+
"shift RIGHT", "selectNextColumnExtendSelection",
1661+
"shift KP_RIGHT", "selectNextColumnExtendSelection",
16621662
// "ctrl shift RIGHT", "selectNextColumnExtendSelection",
16631663
// "ctrl shift KP_RIGHT", "selectNextColumnExtendSelection",
16641664
// "ctrl RIGHT", "selectNextColumnChangeLead",
16651665
// "ctrl KP_RIGHT", "selectNextColumnChangeLead",
1666-
// "LEFT", "selectPreviousColumn",
1667-
// "KP_LEFT", "selectPreviousColumn",
1668-
// "shift LEFT", "selectPreviousColumnExtendSelection",
1669-
// "shift KP_LEFT", "selectPreviousColumnExtendSelection",
1666+
"LEFT", "selectPreviousColumn",
1667+
"KP_LEFT", "selectPreviousColumn",
1668+
"shift LEFT", "selectPreviousColumnExtendSelection",
1669+
"shift KP_LEFT", "selectPreviousColumnExtendSelection",
16701670
// "ctrl shift LEFT", "selectPreviousColumnExtendSelection",
16711671
// "ctrl shift KP_LEFT", "selectPreviousColumnExtendSelection",
16721672
// "ctrl LEFT", "selectPreviousColumnChangeLead",
16731673
// "ctrl KP_LEFT", "selectPreviousColumnChangeLead",
1674-
// "DOWN", "selectNextRow",
1675-
// "KP_DOWN", "selectNextRow",
1676-
// "shift DOWN", "selectNextRowExtendSelection",
1677-
// "shift KP_DOWN", "selectNextRowExtendSelection",
1674+
"DOWN", "selectNextRow",
1675+
"KP_DOWN", "selectNextRow",
1676+
"shift DOWN", "selectNextRowExtendSelection",
1677+
"shift KP_DOWN", "selectNextRowExtendSelection",
16781678
// "ctrl shift DOWN", "selectNextRowExtendSelection",
16791679
// "ctrl shift KP_DOWN", "selectNextRowExtendSelection",
16801680
// "ctrl DOWN", "selectNextRowChangeLead",
16811681
// "ctrl KP_DOWN", "selectNextRowChangeLead",
1682-
// "UP", "selectPreviousRow",
1683-
// "KP_UP", "selectPreviousRow",
1684-
// "shift UP", "selectPreviousRowExtendSelection",
1685-
// "shift KP_UP", "selectPreviousRowExtendSelection",
1682+
"UP", "selectPreviousRow",
1683+
"KP_UP", "selectPreviousRow",
1684+
"shift UP", "selectPreviousRowExtendSelection",
1685+
"shift KP_UP", "selectPreviousRowExtendSelection",
16861686
// "ctrl shift UP", "selectPreviousRowExtendSelection",
16871687
// "ctrl shift KP_UP", "selectPreviousRowExtendSelection",
16881688
// "ctrl UP", "selectPreviousRowChangeLead",
16891689
// "ctrl KP_UP", "selectPreviousRowChangeLead",
1690-
// "HOME", "selectFirstColumn",
1691-
// "shift HOME", "selectFirstColumnExtendSelection",
1690+
"HOME", "selectFirstColumn",
1691+
"shift HOME", "selectFirstColumnExtendSelection",
16921692
// "ctrl shift HOME", "selectFirstRowExtendSelection",
16931693
// "ctrl HOME", "selectFirstRow",
1694-
// "END", "selectLastColumn",
1695-
// "shift END", "selectLastColumnExtendSelection",
1694+
"END", "selectLastColumn",
1695+
"shift END", "selectLastColumnExtendSelection",
16961696
// "ctrl shift END", "selectLastRowExtendSelection",
16971697
// "ctrl END", "selectLastRow",
1698-
// "PAGE_UP", "scrollUpChangeSelection",
1699-
// "shift PAGE_UP", "scrollUpExtendSelection",
1698+
"PAGE_UP", "scrollUpChangeSelection",
1699+
"shift PAGE_UP", "scrollUpExtendSelection",
17001700
// "ctrl shift PAGE_UP", "scrollLeftExtendSelection",
17011701
// "ctrl PAGE_UP", "scrollLeftChangeSelection",
1702-
// "PAGE_DOWN", "scrollDownChangeSelection",
1703-
// "shift PAGE_DOWN", "scrollDownExtendSelection",
1702+
"PAGE_DOWN", "scrollDownChangeSelection",
1703+
"shift PAGE_DOWN", "scrollDownExtendSelection",
17041704
// "ctrl shift PAGE_DOWN", "scrollRightExtendSelection",
17051705
// "ctrl PAGE_DOWN", "scrollRightChangeSelection",
17061706
// "TAB", "selectNextColumnCell",
17071707
// "shift TAB", "selectPreviousColumnCell",
1708-
// "ENTER", "selectNextRowCell",
1709-
// "shift ENTER", "selectPreviousRowCell",
1710-
// "ctrl A", "selectAll",
1708+
"ENTER", "selectNextRowCell",
1709+
"shift ENTER", "selectPreviousRowCell",
1710+
"ctrl A", "selectAll",
17111711
// "ctrl SLASH", "selectAll",
17121712
// "ctrl BACK_SLASH", "clearSelection",
1713-
// "ESCAPE", "cancel",
1714-
// "F2", "startEditing",
1713+
"ESCAPE", "cancel",
1714+
"F2", "startEditing",
17151715
// "SPACE", "addToSelection",
17161716
// "ctrl SPACE", "toggleAndAnchor",
17171717
// "shift SPACE", "extendTo",
17181718
// "ctrl shift SPACE", "moveSelectionTo",
17191719
// "F8", "focusHeader"
1720-
// }),
1720+
}),
17211721
// "Table.ancestorInputMap.RightToLeft",
17221722
// new UIDefaults.LazyInputMap(new Object[] {
17231723
// "RIGHT", "selectPreviousColumn",

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTableUI.java

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
import sun.swing.DefaultLookup;
8181
import sun.swing.SwingUtilities2;
8282
import sun.swing.UIAction;
83-
import swingjs.JSUtil;
8483
import swingjs.api.js.DOMNode;
8584

8685
/**
@@ -212,6 +211,7 @@ public DOMNode updateDOMNode() {
212211

213212
if (domNode == null) {
214213
domNode = newDOMObject("div", id);
214+
bindJSKeyEvents(domNode, true);
215215
}
216216
if (rebuild) {
217217
currentRowMin = currentRowMax = -1;
@@ -1126,7 +1126,7 @@ public void mouseDragged(MouseEvent e) {
11261126
}
11271127

11281128
private class Handler
1129-
implements FocusListener, MouseInputListener, PropertyChangeListener, ListSelectionListener, ActionListener
1129+
implements KeyListener, FocusListener, MouseInputListener, PropertyChangeListener, ListSelectionListener, ActionListener
11301130
// ,
11311131
// BeforeDrag
11321132
{
@@ -1519,17 +1519,6 @@ public void mouseExited(MouseEvent e) {
15191519
public void mouseMoved(MouseEvent e) {
15201520
}
15211521

1522-
public void dragStarting(MouseEvent me) {
1523-
dragStarted = true;
1524-
1525-
if (me.isControlDown() && isFileList) {
1526-
table.getSelectionModel().addSelectionInterval(pressedRow, pressedRow);
1527-
table.getColumnModel().getSelectionModel().addSelectionInterval(pressedCol, pressedCol);
1528-
}
1529-
1530-
pressedEvent = null;
1531-
}
1532-
15331522
@Override
15341523
public void mouseDragged(MouseEvent e) {
15351524
if (SwingUtilities2.shouldIgnore(e, table)) {
@@ -1672,7 +1661,7 @@ private Handler getHandler() {
16721661
* Creates the key listener for handling keyboard navigation in the JTable.
16731662
*/
16741663
protected KeyListener createKeyListener() {
1675-
return null;
1664+
return getHandler();
16761665
}
16771666

16781667
/**
@@ -1779,7 +1768,6 @@ protected void installListeners() {
17791768
focusListener = createFocusListener();
17801769
keyListener = createKeyListener();
17811770
mouseInputListener = createMouseInputListener();
1782-
17831771
table.addFocusListener(focusListener);
17841772
table.addKeyListener(keyListener);
17851773
table.addMouseListener(mouseInputListener);
@@ -2436,61 +2424,6 @@ private void paintDropLines(Graphics g) {
24362424
// return rect;
24372425
// }
24382426

2439-
private void paintDraggedArea(Graphics g, int rMin, int rMax, TableColumn draggedColumn, int distance) {
2440-
rebuildTable();
2441-
// int draggedColumnIndex = viewIndexForColumn(draggedColumn);
2442-
//
2443-
// Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex, true);
2444-
// Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex, true);
2445-
//
2446-
// Rectangle vacatedColumnRect = minCell.union(maxCell);
2447-
//
2448-
// // Paint a gray well in place of the moving column.
2449-
// g.setColor(table.getParent().getBackground());
2450-
// g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
2451-
// vacatedColumnRect.width, vacatedColumnRect.height);
2452-
//
2453-
// // Move to the where the cell has been dragged.
2454-
// vacatedColumnRect.x += distance;
2455-
//
2456-
// // Fill the background.
2457-
// g.setColor(table.getBackground());
2458-
// g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y,
2459-
// vacatedColumnRect.width, vacatedColumnRect.height);
2460-
//
2461-
// // Paint the vertical grid lines if necessary.
2462-
// if (table.getShowVerticalLines()) {
2463-
// g.setColor(table.getGridColor());
2464-
// int x1 = vacatedColumnRect.x;
2465-
// int y1 = vacatedColumnRect.y;
2466-
// int x2 = x1 + vacatedColumnRect.width - 1;
2467-
// int y2 = y1 + vacatedColumnRect.height - 1;
2468-
// // Left
2469-
// g.drawLine(x1-1, y1, x1-1, y2);
2470-
// // Right
2471-
// g.drawLine(x2, y1, x2, y2);
2472-
// }
2473-
//
2474-
// for(int row = rMin; row <= rMax; row++) {
2475-
// // Render the cell value
2476-
// Rectangle r = table.getCellRect(row, draggedColumnIndex, false);
2477-
// r.x += distance;
2478-
// paintCell(g, r, row, draggedColumnIndex);
2479-
//
2480-
// // Paint the (lower) horizontal grid line if necessary.
2481-
// if (table.getShowHorizontalLines()) {
2482-
// g.setColor(table.getGridColor());
2483-
// Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true);
2484-
// rcr.x += distance;
2485-
// int x1 = rcr.x;
2486-
// int y1 = rcr.y;
2487-
// int x2 = x1 + rcr.width - 1;
2488-
// int y2 = y1 + rcr.height - 1;
2489-
// g.drawLine(x1, y2, x2, y2);
2490-
// }
2491-
// }
2492-
}
2493-
24942427
private static int getAdjustedLead(JTable table, boolean row, ListSelectionModel model) {
24952428

24962429
int index = model.getLeadSelectionIndex();

0 commit comments

Comments
 (0)