/[classpath]/classpath/javax/swing/tree/DefaultTreeCellRenderer.java
ViewVC logotype

Diff of /classpath/javax/swing/tree/DefaultTreeCellRenderer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by mark, Thu Nov 11 17:22:52 2004 UTC revision 1.6 by langel, Thu Jun 30 14:42:57 2005 UTC
# Line 1  Line 1 
1  /* DefaultTreeCellRenderer.java --  /*
2     Copyright (C) 2002, 2004  Free Software Foundation, Inc.   * DefaultTreeCellRenderer.java -- Copyright (C) 2002, 2004 Free Software
3     * Foundation, Inc.
4  This file is part of GNU Classpath.   *
5     * This file is part of GNU Classpath.
6  GNU Classpath is free software; you can redistribute it and/or modify   *
7  it under the terms of the GNU General Public License as published by   * GNU Classpath is free software; you can redistribute it and/or modify it
8  the Free Software Foundation; either version 2, or (at your option)   * under the terms of the GNU General Public License as published by the Free
9  any later version.   * Software Foundation; either version 2, or (at your option) any later version.
10     *
11  GNU Classpath is distributed in the hope that it will be useful, but   * GNU Classpath is distributed in the hope that it will be useful, but WITHOUT
12  WITHOUT ANY WARRANTY; without even the implied warranty of   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  General Public License for more details.   * details.
15     *
16  You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License along with
17  along with GNU Classpath; see the file COPYING.  If not, write to the   * GNU Classpath; see the file COPYING. If not, write to the Free Software
18  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  02111-1307 USA.   *
20     * Linking this library statically or dynamically with other modules is making a
21  Linking this library statically or dynamically with other modules is   * combined work based on this library. Thus, the terms and conditions of the
22  making a combined work based on this library.  Thus, the terms and   * GNU General Public License cover the whole combination.
23  conditions of the GNU General Public License cover the whole   *
24  combination.   * As a special exception, the copyright holders of this library give you
25     * permission to link this library with independent modules to produce an
26  As a special exception, the copyright holders of this library give you   * executable, regardless of the license terms of these independent modules, and
27  permission to link this library with independent modules to produce an   * to copy and distribute the resulting executable under terms of your choice,
28  executable, regardless of the license terms of these independent   * provided that you also meet, for each linked independent module, the terms
29  modules, and to copy and distribute the resulting executable under   * and conditions of the license of that module. An independent module is a
30  terms of your choice, provided that you also meet, for each linked   * module which is not derived from or based on this library. If you modify this
31  independent module, the terms and conditions of the license of that   * library, you may extend this exception to your version of the library, but
32  module.  An independent module is a module which is not derived from   * you are not obligated to do so. If you do not wish to do so, delete this
33  or based on this library.  If you modify this library, you may extend   * exception statement from your version.
34  this exception to your version of the library, but you are not   */
 obligated to do so.  If you do not wish to do so, delete this  
 exception statement from your version. */  
   
35    
36  package javax.swing.tree;  package javax.swing.tree;
37    
# Line 54  import javax.swing.plaf.UIResource; Line 51  import javax.swing.plaf.UIResource;
51    
52  /**  /**
53   * DefaultTreeCellRenderer   * DefaultTreeCellRenderer
54     *
55   * @author Andrew Selkirk   * @author Andrew Selkirk
56   */   */
57  public class DefaultTreeCellRenderer  public class DefaultTreeCellRenderer
58    extends JLabel                  extends JLabel
59    implements TreeCellRenderer                  implements TreeCellRenderer
60  {  {
61          //-------------------------------------------------------------          // -------------------------------------------------------------
62          // Variables --------------------------------------------------          // Variables --------------------------------------------------
63          //-------------------------------------------------------------          // -------------------------------------------------------------
64    
65          /**          /**
66           * selected           * selected
# Line 119  public class DefaultTreeCellRenderer Line 117  public class DefaultTreeCellRenderer
117           */           */
118          protected Color borderSelectionColor;          protected Color borderSelectionColor;
119    
120            // -------------------------------------------------------------
         //-------------------------------------------------------------  
121          // Initialization ---------------------------------------------          // Initialization ---------------------------------------------
122          //-------------------------------------------------------------          // -------------------------------------------------------------
123    
124          /**          /**
125           * Constructor DefaultTreeCellRenderer           * Constructor DefaultTreeCellRenderer
126           */           */
127          public DefaultTreeCellRenderer() {          public DefaultTreeCellRenderer()
128            UIDefaults defaults = UIManager.getLookAndFeelDefaults();          {
129                                UIDefaults defaults = UIManager.getLookAndFeelDefaults();
130            setLeafIcon(getDefaultLeafIcon());  
131            setOpenIcon(getDefaultOpenIcon());                  setLeafIcon(getDefaultLeafIcon());
132            setClosedIcon(getDefaultClosedIcon());                  setOpenIcon(getDefaultOpenIcon());
133                    setClosedIcon(getDefaultClosedIcon());
134            setTextNonSelectionColor(defaults.getColor("Tree.textForeground"));  
135            setTextSelectionColor(defaults.getColor("Tree.selectionForeground"));                  setTextNonSelectionColor(defaults.getColor("Tree.textForeground"));
136            setBackgroundNonSelectionColor(defaults.getColor("Tree.textBackground"));                  setTextSelectionColor(defaults.getColor("Tree.selectionForeground"));
137            setBackgroundSelectionColor(defaults.getColor("Tree.selectionBackground"));                  setBackgroundNonSelectionColor(defaults
138            setBorderSelectionColor(defaults.getColor("Tree.selectionBorderColor"));                                  .getColor("Tree.textBackground"));
139                    setBackgroundSelectionColor(defaults
140                                    .getColor("Tree.selectionBackground"));
141                    setBorderSelectionColor(defaults
142                                    .getColor("Tree.selectionBorderColor"));
143          }          }
144    
145            // -------------------------------------------------------------
         //-------------------------------------------------------------  
146          // Methods ----------------------------------------------------          // Methods ----------------------------------------------------
147          //-------------------------------------------------------------          // -------------------------------------------------------------
148    
149          /**          /**
150           * getDefaultOpenIcon           * getDefaultOpenIcon
151             *
152           * @returns Icon           * @returns Icon
153           */           */
154          public Icon getDefaultOpenIcon() {          public Icon getDefaultOpenIcon()
155            return UIManager.getLookAndFeelDefaults().getIcon("Tree.openIcon");          {
156                    return UIManager.getLookAndFeelDefaults().getIcon("Tree.openIcon");
157          }          }
158    
159          /**          /**
160           * getDefaultClosedIcon           * getDefaultClosedIcon
161             *
162           * @returns Icon           * @returns Icon
163           */           */
164          public Icon getDefaultClosedIcon() {          public Icon getDefaultClosedIcon()
165            return UIManager.getLookAndFeelDefaults().getIcon("Tree.closedIcon");          {
166                    return UIManager.getLookAndFeelDefaults().getIcon("Tree.closedIcon");
167          }          }
168    
169          /**          /**
170           * getDefaultLeafIcon           * getDefaultLeafIcon
171             *
172           * @returns Icon           * @returns Icon
173           */           */
174          public Icon getDefaultLeafIcon() {          public Icon getDefaultLeafIcon()
175            return UIManager.getLookAndFeelDefaults().getIcon("Tree.leafIcon");          {
176                    return UIManager.getLookAndFeelDefaults().getIcon("Tree.leafIcon");
177          }          }
178    
179          /**          /**
180           * setOpenIcon           * setOpenIcon
181             *
182           * @param value0 TODO           * @param value0 TODO
183           */           */
184          public void setOpenIcon(Icon i) {          public void setOpenIcon(Icon i)
185            openIcon = i;          {
186                    openIcon = i;
187          }          }
188    
189          /**          /**
190           * getOpenIcon           * getOpenIcon
191             *
192           * @returns Icon           * @returns Icon
193           */           */
194          public Icon getOpenIcon() {          public Icon getOpenIcon()
195            return openIcon;          {
196          }                  return openIcon;
197            }
198    
199          /**          /**
200           * setClosedIcon           * setClosedIcon
201             *
202           * @param value0 TODO           * @param value0 TODO
203           */           */
204          public void setClosedIcon(Icon i) {          public void setClosedIcon(Icon i)
205            closedIcon = i;          {
206          }                  closedIcon = i;
207            }
208    
209          /**          /**
210           * getClosedIcon           * getClosedIcon
211             *
212           * @returns Icon           * @returns Icon
213           */           */
214          public Icon getClosedIcon() {          public Icon getClosedIcon()
215            return closedIcon;          {
216          }                  return closedIcon;
217            }
218    
219          /**          /**
220           * setLeafIcon           * setLeafIcon
221             *
222           * @param value0 TODO           * @param value0 TODO
223           */           */
224          public void setLeafIcon(Icon i) {          public void setLeafIcon(Icon i)
225            leafIcon = i;          {
226                    leafIcon = i;
227          }          }
228    
229          /**          /**
230           * getLeafIcon           * getLeafIcon
231             *
232           * @returns Icon           * @returns Icon
233           */           */
234          public Icon getLeafIcon() {          public Icon getLeafIcon()
235            return leafIcon;          {
236                    return leafIcon;
237          }          }
238    
239          /**          /**
240           * setTextSelectionColor           * setTextSelectionColor
241             *
242           * @param value0 TODO           * @param value0 TODO
243           */           */
244          public void setTextSelectionColor(Color c) {          public void setTextSelectionColor(Color c)
245            textSelectionColor = c;          {
246                    textSelectionColor = c;
247          }          }
248    
249          /**          /**
250           * getTextSelectionColor           * getTextSelectionColor
251             *
252           * @returns Color           * @returns Color
253           */           */
254          public Color getTextSelectionColor() {          public Color getTextSelectionColor()
255            return textSelectionColor;          {
256                    return textSelectionColor;
257          }          }
258    
259          /**          /**
260           * setTextNonSelectionColor           * setTextNonSelectionColor
261             *
262           * @param value0 TODO           * @param value0 TODO
263           */           */
264          public void setTextNonSelectionColor(Color c) {          public void setTextNonSelectionColor(Color c)
265            textNonSelectionColor = c;          {
266                    textNonSelectionColor = c;
267          }          }
268    
269          /**          /**
270           * getTextNonSelectionColor           * getTextNonSelectionColor
271             *
272           * @returns Color           * @returns Color
273           */           */
274          public Color getTextNonSelectionColor() {          public Color getTextNonSelectionColor()
275            return textNonSelectionColor;          {
276                    return textNonSelectionColor;
277          }          }
278    
279          /**          /**
280           * setBackgroundSelectionColor           * setBackgroundSelectionColor
281             *
282           * @param value0 TODO           * @param value0 TODO
283           */           */
284          public void setBackgroundSelectionColor(Color c) {          public void setBackgroundSelectionColor(Color c)
285            backgroundSelectionColor = c;          {
286                    backgroundSelectionColor = c;
287          }          }
288    
289          /**          /**
290           * getBackgroundSelectionColor           * getBackgroundSelectionColor
291             *
292           * @returns Color           * @returns Color
293           */           */
294          public Color getBackgroundSelectionColor() {          public Color getBackgroundSelectionColor()
295            return backgroundSelectionColor;                        {
296                    return backgroundSelectionColor;
297          }          }
298    
299          /**          /**
300           * setBackgroundNonSelectionColor           * setBackgroundNonSelectionColor
301             *
302           * @param value0 TODO           * @param value0 TODO
303           */           */
304          public void setBackgroundNonSelectionColor(Color c) {          public void setBackgroundNonSelectionColor(Color c)
305            backgroundNonSelectionColor = c;          {
306                    backgroundNonSelectionColor = c;
307          }          }
308    
309          /**          /**
310           * getBackgroundNonSelectionColor           * getBackgroundNonSelectionColor
311             *
312           * @returns Color           * @returns Color
313           */           */
314          public Color getBackgroundNonSelectionColor() {          public Color getBackgroundNonSelectionColor()
315            return backgroundNonSelectionColor;          {
316                    return backgroundNonSelectionColor;
317          }          }
318    
319          /**          /**
320           * setBorderSelectionColor           * setBorderSelectionColor
321             *
322           * @param value0 TODO           * @param value0 TODO
323           */           */
324          public void setBorderSelectionColor(Color c) {          public void setBorderSelectionColor(Color c)
325            borderSelectionColor = c;          {
326                    borderSelectionColor = c;
327          }          }
328    
329          /**          /**
330           * getBorderSelectionColor           * getBorderSelectionColor
331             *
332           * @returns Color           * @returns Color
333           */           */
334          public Color getBorderSelectionColor() {          public Color getBorderSelectionColor()
335            return borderSelectionColor;          {
336                    return borderSelectionColor;
337          }          }
338    
339          /**          /**
340           * setFont           * setFont
341             *
342           * @param value0 TODO           * @param value0 TODO
343           */           */
344          public void setFont(Font f) {          public void setFont(Font f)
345            if (f != null && f instanceof UIResource)          {
346              f = null;                  if (f != null && f instanceof UIResource)
347            super.setFont(f);                          f = null;
348                    super.setFont(f);
349          }          }
350    
351          /**          /**
352           * setBackground           * setBackground
353             *
354           * @param value0 TODO           * @param value0 TODO
355           */           */
356          public void setBackground(Color c) {          public void setBackground(Color c)
357            if (c != null && c instanceof UIResource)          {
358              c = null;                  if (c != null && c instanceof UIResource)
359            super.setBackground(c);                          c = null;
360                    super.setBackground(c);
361          }          }
362    
363          /**          /**
364           * getTreeCellRendererComponent           * getTreeCellRendererComponent
365             *
366           * @param value0 TODO           * @param value0 TODO
367           * @param value1 TODO           * @param value1 TODO
368           * @param value2 TODO           * @param value2 TODO
# Line 329  public class DefaultTreeCellRenderer Line 372  public class DefaultTreeCellRenderer
372           * @param value6 TODO           * @param value6 TODO
373           * @returns Component           * @returns Component
374           */           */
375          public Component getTreeCellRendererComponent(JTree tree,          public Component getTreeCellRendererComponent(JTree tree, Object val,
376                                                        Object val,                          boolean selected, boolean expanded, boolean leaf, int row,
377                                                        boolean selected,                          boolean hasFocus)
378                                                        boolean expanded,          {
379                                                        boolean leaf,                  this.selected = selected;
380                                                        int row,                  this.hasFocus = hasFocus;
381                                                        boolean hasFocus) {  
382            this.selected = selected;                  if (leaf)
383            this.hasFocus = hasFocus;                          setIcon(getLeafIcon());
384                    else if (expanded)
385            if (leaf)                          setIcon(getOpenIcon());
386              setIcon(getLeafIcon());                  else
387            else if (expanded)                          setIcon(getClosedIcon());
388              setIcon(getOpenIcon());  
389            else                  setText(val.toString());
390              setIcon(getClosedIcon());                  setHorizontalAlignment(LEFT);
391                    setVerticalAlignment(TOP);
           setText(val.toString());  
           setHorizontalAlignment(LEFT);  
           setVerticalAlignment(TOP);  
392    
393            return this;                  return this;
394          }          }
395    
396          /**          /**
397           * paint           * paint
398             *
399           * @param value0 TODO           * @param value0 TODO
400           */           */
401          public void paint(Graphics g) {          public void paint(Graphics g)
402            super.paint(g);          {
403                    super.paint(g);
404          }          }
405    
406          /**          /**
407           * getPreferredSize           * getPreferredSize
408             *
409           * @returns Dimension           * @returns Dimension
410           */           */
411          public Dimension getPreferredSize() {          public Dimension getPreferredSize()
412            {
413                  return null; // TODO                  return null; // TODO
414          } // getPreferredSize()          } // getPreferredSize()
415    
416          /**          /**
417           * validate           * validate
418           */           */
419          public void validate() {          public void validate()
420                  // TODO          {
421                    // Overridden for performance reasons.
422          } // validate()          } // validate()
423    
424          /**          /**
425           * revalidate           * revalidate
426           */           */
427          public void revalidate() {          public void revalidate()
428                  // TODO          {
429                    // Overridden for performance reasons.
430          } // revalidate()          } // revalidate()
431    
432          /**          /**
433           * repaint           * repaint
434             *
435           * @param value0 TODO           * @param value0 TODO
436           * @param value1 TODO           * @param value1 TODO
437           * @param value2 TODO           * @param value2 TODO
438           * @param value3 TODO           * @param value3 TODO
439           * @param value4 TODO           * @param value4 TODO
440           */           */
441          public void repaint(long value0, int value1, int value2, int value3, int value4) {          public void repaint(long value0, int value1, int value2, int value3,
442                  // TODO                          int value4)
443            {
444                    // Overridden for performance reasons.
445          } // repaint()          } // repaint()
446    
447          /**          /**
448           * repaint           * repaint
449             *
450           * @param value0 TODO           * @param value0 TODO
451           */           */
452          public void repaint(Rectangle value0) {          public void repaint(Rectangle value0)
453                  // TODO          {
454                    //  Overridden for performance reasons.
455          } // repaint()          } // repaint()
456    
457          /**          /**
458           * firePropertyChange           * firePropertyChange
459             *
460           * @param value0 TODO           * @param value0 TODO
461           * @param value1 TODO           * @param value1 TODO
462           * @param value2 TODO           * @param value2 TODO
463           */           */
464          protected void firePropertyChange(String value0, Object value1, Object value2) {          protected void firePropertyChange(String value0, Object value1,
465                  // TODO                          Object value2)
466            {
467                    //  Overridden for performance reasons.
468          } // firePropertyChange()          } // firePropertyChange()
469    
470          /**          /**
471           * firePropertyChange           * firePropertyChange
472             *
473           * @param value0 TODO           * @param value0 TODO
474           * @param value1 TODO           * @param value1 TODO
475           * @param value2 TODO           * @param value2 TODO
476           */           */
477          public void firePropertyChange(String value0, byte value1, byte value2) {          public void firePropertyChange(String value0, byte value1, byte value2)
478                  // TODO          {
479                    //  Overridden for performance reasons.
480          } // firePropertyChange()          } // firePropertyChange()
481    
482          /**          /**
483           * firePropertyChange           * firePropertyChange
484             *
485           * @param value0 TODO           * @param value0 TODO
486           * @param value1 TODO           * @param value1 TODO
487           * @param value2 TODO           * @param value2 TODO
488           */           */
489          public void firePropertyChange(String value0, char value1, char value2) {          public void firePropertyChange(String value0, char value1, char value2)
490                  // TODO          {
491                    // Overridden for performance reasons.
492          } // firePropertyChange()          } // firePropertyChange()
493    
494          /**          /**
495           * firePropertyChange           * firePropertyChange
496             *
497           * @param value0 TODO           * @param value0 TODO
498           * @param value1 TODO           * @param value1 TODO
499           * @param value2 TODO           * @param value2 TODO
500           */           */
501          public void firePropertyChange(String value0, short value1, short value2) {          public void firePropertyChange(String value0, short value1, short value2)
502                  // TODO          {
503                    //  Overridden for performance reasons.
504          } // firePropertyChange()          } // firePropertyChange()
505    
506          /**          /**
507           * firePropertyChange           * firePropertyChange
508             *
509           * @param value0 TODO           * @param value0 TODO
510           * @param value1 TODO           * @param value1 TODO
511           * @param value2 TODO           * @param value2 TODO
512           */           */
513          public void firePropertyChange(String value0, int value1, int value2) {          public void firePropertyChange(String value0, int value1, int value2)
514                  // TODO          {
515                    // Overridden for performance reasons.
516          } // firePropertyChange()          } // firePropertyChange()
517    
518          /**          /**
519           * firePropertyChange           * firePropertyChange
520             *
521           * @param value0 TODO           * @param value0 TODO
522           * @param value1 TODO           * @param value1 TODO
523           * @param value2 TODO           * @param value2 TODO
524           */           */
525          public void firePropertyChange(String value0, long value1, long value2) {          public void firePropertyChange(String value0, long value1, long value2)
526                  // TODO          {
527                    //  Overridden for performance reasons.
528          } // firePropertyChange()          } // firePropertyChange()
529    
530          /**          /**
531           * firePropertyChange           * firePropertyChange
532             *
533           * @param value0 TODO           * @param value0 TODO
534           * @param value1 TODO           * @param value1 TODO
535           * @param value2 TODO           * @param value2 TODO
536           */           */
537          public void firePropertyChange(String value0, float value1, float value2) {          public void firePropertyChange(String value0, float value1, float value2)
538                  // TODO          {
539                    //  Overridden for performance reasons.
540          } // firePropertyChange()          } // firePropertyChange()
541    
542          /**          /**
543           * firePropertyChange           * firePropertyChange
544             *
545           * @param value0 TODO           * @param value0 TODO
546           * @param value1 TODO           * @param value1 TODO
547           * @param value2 TODO           * @param value2 TODO
548           */           */
549          public void firePropertyChange(String value0, double value1, double value2) {          public void firePropertyChange(String value0, double value1, double value2)
550                  // TODO          {
551                    //  Overridden for performance reasons.
552          } // firePropertyChange()          } // firePropertyChange()
553    
554          /**          /**
555           * firePropertyChange           * firePropertyChange
556             *
557           * @param value0 TODO           * @param value0 TODO
558           * @param value1 TODO           * @param value1 TODO
559           * @param value2 TODO           * @param value2 TODO
560           */           */
561          public void firePropertyChange(String value0, boolean value1, boolean value2) {          public void firePropertyChange(String value0, boolean v1, boolean v2)
562                  // TODO          {
563                    //  Overridden for performance reasons.
564          } // firePropertyChange()          } // firePropertyChange()
565    
   
566  } // DefaultTreeCellRenderer  } // DefaultTreeCellRenderer

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26