001 /* JAPI - (Yet another (hopefully) useful) Java API 002 * 003 * Copyright (C) 2004-2006 Christian Hujer 004 * 005 * This program is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU General Public License as 007 * published by the Free Software Foundation; either version 2 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, but 011 * WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with this program; if not, write to the Free Software 017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 * 02111-1307, USA. 019 */ 020 021 package net.sf.japi.swing.bookmarks; 022 023 import java.awt.Component; 024 import javax.swing.JSeparator; 025 import javax.swing.JTree; 026 import javax.swing.tree.DefaultTreeCellRenderer; 027 028 /** Class for rendering TreeCells in JTrees which manage Bookmarks. 029 * @author <a href="mailto:chris@riedquat.de">Christian Hujer</a> 030 * @todo improve separator 031 */ 032 public class BookmarkTreeCellRenderer extends DefaultTreeCellRenderer { 033 034 /** Serial Version. */ 035 private static final long serialVersionUID = 1L; 036 037 /** JSeparator. 038 * @serial include 039 */ 040 private JSeparator sep = new JSeparator(); 041 042 /** {@inheritDoc} */ 043 @Override public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean sel, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) { 044 if (!(value instanceof BookmarkManager.Bookmark)) { 045 throw new IllegalArgumentException("Supplied value must be a bookmark but was " + value.getClass().getName()); 046 //return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 047 } 048 if (value instanceof BookmarkManager.BookmarkSeparator) { 049 return super.getTreeCellRendererComponent(tree, "----------------", sel, expanded, leaf, row, hasFocus); 050 //sep.setMinimumSize(new Dimension(tree.getWidth() / 2, 2)); 051 //sep.setPreferredSize(new Dimension(tree.getWidth(), 2)); 052 //sep.setSize(5, tree.getWidth()); 053 ////sep.setBorder(new ); 054 //return sep; 055 } else { 056 return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 057 } 058 } 059 060 } // class BookmarkTreeCellRenderer