src/share/classes/javax/swing/plaf/synth/SynthTreeUI.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2013, 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


 667             r = tree.getPathBounds(loc.getPath());
 668             if (r != null) {
 669                 r.x = 0;
 670                 r.width = tree.getWidth();
 671             }
 672         }
 673 
 674         if (r != null) {
 675             tree.repaint(r);
 676         }
 677     }
 678 
 679     /**
 680      * {@inheritDoc}
 681      */
 682     @Override
 683     protected int getRowX(int row, int depth) {
 684         return super.getRowX(row, depth) + padding;
 685     }
 686 
 687 
 688     private class SynthTreeCellRenderer extends DefaultTreeCellRenderer
 689                                implements UIResource {
 690         SynthTreeCellRenderer() {
 691         }
 692 
 693         @Override
 694         public String getName() {
 695             return "Tree.cellRenderer";
 696         }
 697 
 698         @Override
 699         public Component getTreeCellRendererComponent(JTree tree, Object value,
 700                                                       boolean sel,
 701                                                       boolean expanded,
 702                                                       boolean leaf, int row,
 703                                                       boolean hasFocus) {
 704             if (!useTreeColors && (sel || hasFocus)) {
 705                 SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel.
 706                              getUIOfType(getUI(), SynthLabelUI.class),
 707                                    sel, hasFocus, tree.isEnabled(), false);


 745                 else {
 746                     context.getPainter().paintTreeCellFocus(context, g,
 747                             0, 0, getWidth() - imageOffset, getHeight());
 748                 }
 749                 context.dispose();
 750             }
 751             SynthLookAndFeel.resetSelectedUI();
 752         }
 753     }
 754 
 755 
 756     private static class SynthTreeCellEditor extends DefaultTreeCellEditor {
 757         public SynthTreeCellEditor(JTree tree,
 758                                    DefaultTreeCellRenderer renderer) {
 759             super(tree, renderer);
 760             setBorderSelectionColor(null);
 761         }
 762 
 763         @Override
 764         protected TreeCellEditor createTreeCellEditor() {

 765             JTextField tf = new JTextField() {
 766                 @Override
 767                 public String getName() {
 768                     return "Tree.cellEditor";
 769                 }
 770             };
 771             DefaultCellEditor editor = new DefaultCellEditor(tf);
 772 
 773             // One click to edit.
 774             editor.setClickCountToStart(1);
 775             return editor;
 776         }
 777     }
 778 
 779     //
 780     // BasicTreeUI directly uses expandIcon outside of the Synth methods.
 781     // To get the correct context we return an instance of this that fetches
 782     // the SynthContext as needed.
 783     //
 784     private class ExpandedIconWrapper extends SynthIcon {


   1 /*
   2  * Copyright (c) 2002, 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


 667             r = tree.getPathBounds(loc.getPath());
 668             if (r != null) {
 669                 r.x = 0;
 670                 r.width = tree.getWidth();
 671             }
 672         }
 673 
 674         if (r != null) {
 675             tree.repaint(r);
 676         }
 677     }
 678 
 679     /**
 680      * {@inheritDoc}
 681      */
 682     @Override
 683     protected int getRowX(int row, int depth) {
 684         return super.getRowX(row, depth) + padding;
 685     }
 686 
 687     @SuppressWarnings("serial") // Superclass is not serializable across versions
 688     private class SynthTreeCellRenderer extends DefaultTreeCellRenderer
 689                                implements UIResource {
 690         SynthTreeCellRenderer() {
 691         }
 692 
 693         @Override
 694         public String getName() {
 695             return "Tree.cellRenderer";
 696         }
 697 
 698         @Override
 699         public Component getTreeCellRendererComponent(JTree tree, Object value,
 700                                                       boolean sel,
 701                                                       boolean expanded,
 702                                                       boolean leaf, int row,
 703                                                       boolean hasFocus) {
 704             if (!useTreeColors && (sel || hasFocus)) {
 705                 SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel.
 706                              getUIOfType(getUI(), SynthLabelUI.class),
 707                                    sel, hasFocus, tree.isEnabled(), false);


 745                 else {
 746                     context.getPainter().paintTreeCellFocus(context, g,
 747                             0, 0, getWidth() - imageOffset, getHeight());
 748                 }
 749                 context.dispose();
 750             }
 751             SynthLookAndFeel.resetSelectedUI();
 752         }
 753     }
 754 
 755 
 756     private static class SynthTreeCellEditor extends DefaultTreeCellEditor {
 757         public SynthTreeCellEditor(JTree tree,
 758                                    DefaultTreeCellRenderer renderer) {
 759             super(tree, renderer);
 760             setBorderSelectionColor(null);
 761         }
 762 
 763         @Override
 764         protected TreeCellEditor createTreeCellEditor() {
 765             @SuppressWarnings("serial") // anonymous class
 766             JTextField tf = new JTextField() {
 767                 @Override
 768                 public String getName() {
 769                     return "Tree.cellEditor";
 770                 }
 771             };
 772             DefaultCellEditor editor = new DefaultCellEditor(tf);
 773 
 774             // One click to edit.
 775             editor.setClickCountToStart(1);
 776             return editor;
 777         }
 778     }
 779 
 780     //
 781     // BasicTreeUI directly uses expandIcon outside of the Synth methods.
 782     // To get the correct context we return an instance of this that fetches
 783     // the SynthContext as needed.
 784     //
 785     private class ExpandedIconWrapper extends SynthIcon {