001: /*
002: * Copyright (C) 2004 Giuseppe MANNA
003: *
004: * This file is part of FreeReportBuilder
005: *
006: * FreeReportBuilder is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package it.frb.tree;
023:
024: import java.net.URL;
025: import javax.swing.ImageIcon;
026:
027: /** Oggetto costruito ereditando da CellRender.
028: */
029: public class CustomCellRender extends
030: javax.swing.tree.DefaultTreeCellRenderer {
031: ImageIcon openIcon;
032: ImageIcon closeIcon;
033: ImageIcon leafIcon;
034: ImageIcon keyIcon;
035: ImageIcon foreignKeyIcon;
036: ImageIcon keyExportedIcon;
037: ImageIcon columnIcon;
038:
039: /** Creates new CustomCellRender */
040: public CustomCellRender() {
041: openIcon = new ImageIcon(CustomCellRender.class
042: .getResource("img/folder_open.png"));
043: closedIcon = new ImageIcon(CustomCellRender.class
044: .getResource("img/folder_closed.png"));
045: keyIcon = new ImageIcon(CustomCellRender.class
046: .getResource("img/key.gif"));
047: foreignKeyIcon = new ImageIcon(CustomCellRender.class
048: .getResource("img/foreignkey.gif"));
049: keyExportedIcon = new ImageIcon(CustomCellRender.class
050: .getResource("img/keyexported.gif"));
051: columnIcon = new ImageIcon(CustomCellRender.class
052: .getResource("img/column.gif"));
053: }
054:
055: public java.awt.Component getTreeCellRendererComponent(
056: javax.swing.JTree asTree, Object aoValue, boolean abSel,
057: boolean abExpanded, boolean abLeaf, int anRow,
058: boolean abHasFocus) {
059: super .getTreeCellRendererComponent(asTree, aoValue, abSel,
060: abExpanded, abLeaf, anRow, abHasFocus);
061:
062: if (aoValue instanceof javax.swing.tree.DefaultMutableTreeNode) {
063: int depth = ((javax.swing.tree.DefaultMutableTreeNode) aoValue)
064: .getDepth();
065:
066: switch (depth) {
067: case 1:
068: if (abExpanded) {
069: this .setIcon(openIcon);
070: } else {
071: this .setIcon(closedIcon);
072: }
073: break;
074: case 2:
075: if (abExpanded) {
076: this .setIcon(openIcon);
077: } else {
078: this .setIcon(closedIcon);
079: }
080: break;
081: case 3:
082: if (abExpanded) {
083: this .setIcon(openIcon);
084: } else {
085: this .setIcon(closedIcon);
086: }
087: break;
088: }
089:
090: if (abLeaf && depth == 0) {
091: String label = (((javax.swing.tree.DefaultMutableTreeNode) aoValue)
092: .getParent()).toString();
093:
094: if (label.equalsIgnoreCase("Primary Key")) {
095: this .setIcon(keyIcon);
096:
097: } else if (label.equalsIgnoreCase("Foreign Key")) {
098: this .setIcon(foreignKeyIcon);
099:
100: } else if (label.equalsIgnoreCase("Primary Exported")) {
101: this .setIcon(keyExportedIcon);
102:
103: } else if (label.equalsIgnoreCase("Colonne")) {
104: this.setIcon(columnIcon);
105: }
106: } else {
107: if (abExpanded) {
108: this.setIcon(openIcon);
109: } else {
110: this.setIcon(closedIcon);
111: }
112: }
113: }
114:
115: return this;
116: }
117: }
|