1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
476 else bounds.width = 8;
477
478 int boxLeftX = (i != null) ? i.left : 0;
479 if (AquaUtils.isLeftToRight(tree)) {
480 boxLeftX += (((path.getPathCount() + depthOffset - 2) * totalChildIndent) + getLeftChildIndent()) - bounds.width / 2;
481 } else {
482 boxLeftX += tree.getWidth() - 1 - ((path.getPathCount() - 2 + depthOffset) * totalChildIndent) - getLeftChildIndent() - bounds.width / 2;
483 }
484 bounds.x = boxLeftX;
485 return bounds;
486 }
487
488 protected void installKeyboardActions() {
489 super.installKeyboardActions();
490 tree.getActionMap().put("aquaExpandNode", new KeyboardExpandCollapseAction(true, false));
491 tree.getActionMap().put("aquaCollapseNode", new KeyboardExpandCollapseAction(false, false));
492 tree.getActionMap().put("aquaFullyExpandNode", new KeyboardExpandCollapseAction(true, true));
493 tree.getActionMap().put("aquaFullyCollapseNode", new KeyboardExpandCollapseAction(false, true));
494 }
495
496 class KeyboardExpandCollapseAction extends AbstractAction {
497 /**
498 * Determines direction to traverse, 1 means expand, -1 means collapse.
499 */
500 final boolean expand;
501 final boolean recursive;
502
503 /**
504 * True if the selection is reset, false means only the lead path changes.
505 */
506 public KeyboardExpandCollapseAction(final boolean expand, final boolean recursive) {
507 this.expand = expand;
508 this.recursive = recursive;
509 }
510
511 public void actionPerformed(final ActionEvent e) {
512 if (tree == null || 0 > getRowCount(tree)) return;
513
514 final TreePath[] selectionPaths = tree.getSelectionPaths();
515 if (selectionPaths == null) return;
|
1 /*
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
476 else bounds.width = 8;
477
478 int boxLeftX = (i != null) ? i.left : 0;
479 if (AquaUtils.isLeftToRight(tree)) {
480 boxLeftX += (((path.getPathCount() + depthOffset - 2) * totalChildIndent) + getLeftChildIndent()) - bounds.width / 2;
481 } else {
482 boxLeftX += tree.getWidth() - 1 - ((path.getPathCount() - 2 + depthOffset) * totalChildIndent) - getLeftChildIndent() - bounds.width / 2;
483 }
484 bounds.x = boxLeftX;
485 return bounds;
486 }
487
488 protected void installKeyboardActions() {
489 super.installKeyboardActions();
490 tree.getActionMap().put("aquaExpandNode", new KeyboardExpandCollapseAction(true, false));
491 tree.getActionMap().put("aquaCollapseNode", new KeyboardExpandCollapseAction(false, false));
492 tree.getActionMap().put("aquaFullyExpandNode", new KeyboardExpandCollapseAction(true, true));
493 tree.getActionMap().put("aquaFullyCollapseNode", new KeyboardExpandCollapseAction(false, true));
494 }
495
496 @SuppressWarnings("serial") // Superclass is not serializable across versions
497 class KeyboardExpandCollapseAction extends AbstractAction {
498 /**
499 * Determines direction to traverse, 1 means expand, -1 means collapse.
500 */
501 final boolean expand;
502 final boolean recursive;
503
504 /**
505 * True if the selection is reset, false means only the lead path changes.
506 */
507 public KeyboardExpandCollapseAction(final boolean expand, final boolean recursive) {
508 this.expand = expand;
509 this.recursive = recursive;
510 }
511
512 public void actionPerformed(final ActionEvent e) {
513 if (tree == null || 0 > getRowCount(tree)) return;
514
515 final TreePath[] selectionPaths = tree.getSelectionPaths();
516 if (selectionPaths == null) return;
|