001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the 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, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * JBGList.java
028: *
029: * Created on March 22, 2006, 4:27 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.style;
034:
035: import java.awt.Color;
036: import java.awt.Graphics;
037: import java.awt.Image;
038: import java.awt.Rectangle;
039: import javax.swing.DefaultListCellRenderer;
040: import javax.swing.JList;
041: import javax.swing.JTree;
042: import javax.swing.tree.DefaultMutableTreeNode;
043:
044: /**
045: *
046: * @author gtoffoli
047: */
048: public class JBGTree extends JTree {
049:
050: private boolean showLibrary = true;
051: /**
052: * 109 x 106
053: */
054: public static Image backGround = (new javax.swing.ImageIcon(
055: JBGTree.class
056: .getResource("/it/businesslogic/ireport/icons/styles/library.png")))
057: .getImage();
058: public static Image backGroundDocument = (new javax.swing.ImageIcon(
059: JBGTree.class
060: .getResource("/it/businesslogic/ireport/icons/styles/document.png")))
061: .getImage();
062:
063: /** Creates a new instance of JBGList */
064: public JBGTree() {
065: super ();
066: setOpaque(false);
067: this .setCellRenderer(new StyleCellRenderer());
068:
069: }
070:
071: public Object getSelectedItem() {
072: if (getSelectionPath() != null
073: && getSelectionPath().getLastPathComponent() instanceof DefaultMutableTreeNode) {
074: DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) getSelectionPath()
075: .getLastPathComponent();
076: return selectedNode.getUserObject();
077: }
078:
079: return null;
080: }
081:
082: public void paint(Graphics g) {
083:
084: Rectangle r = this .getVisibleRect();
085: g.setColor(Color.WHITE);
086: g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
087: (int) r.getHeight());
088: g.drawImage(
089: (isShowLibrary()) ? backGround : backGroundDocument,
090: (int) r.getX() + (int) r.getWidth() - 109, (int) r
091: .getY()
092: + (int) r.getHeight() - 106, 109, 106, this );
093: super .paint(g);
094:
095: }
096:
097: public boolean isShowLibrary() {
098: return showLibrary;
099: }
100:
101: public void setShowLibrary(boolean newShowLibrary) {
102: if (showLibrary == newShowLibrary)
103: return;
104: this.showLibrary = newShowLibrary;
105: this.repaint();
106: }
107:
108: }
|