001: /*
002: * KeyCellRenderer.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program 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 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 org.executequery.gui.table;
023:
024: import java.awt.Color;
025: import java.awt.Component;
026:
027: import javax.swing.ImageIcon;
028: import javax.swing.JLabel;
029: import javax.swing.JTable;
030: import javax.swing.table.TableCellRenderer;
031: import org.executequery.GUIUtilities;
032: import org.executequery.gui.browser.ColumnData;
033:
034: /* ----------------------------------------------------------
035: * CVS NOTE: Changes to the CVS repository prior to the
036: * release of version 3.0.0beta1 has meant a
037: * resetting of CVS revision numbers.
038: * ----------------------------------------------------------
039: */
040:
041: /**
042: *
043: * @author Takis Diakoumis
044: * @version $Revision: 1.5 $
045: * @date $Date: 2006/09/06 09:30:58 $
046: */
047: public class KeyCellRenderer extends JLabel implements
048: TableCellRenderer {
049:
050: private static ImageIcon fkImage;
051: private static ImageIcon pkImage;
052: private static ImageIcon pkfkImage;
053: private static ImageIcon deleteImage;
054: private static ImageIcon newImage;
055:
056: private static final String PRIMARY = "PK";
057: private static final String FOREIGN = "FK";
058: private static final String PRIMARY_AND_FOREIGN = "PKFK";
059:
060: static {
061: deleteImage = GUIUtilities.loadIcon("MarkDeleted16.gif", true);
062: newImage = GUIUtilities.loadIcon("MarkNew16.gif", true);
063: fkImage = GUIUtilities.loadIcon("ForeignKeyImage.gif", true);
064: pkImage = GUIUtilities.loadIcon("PrimaryKeyImage.gif", true);
065: pkfkImage = GUIUtilities.loadIcon("PrimaryForeignKeyImage.gif",
066: true);
067: }
068:
069: public KeyCellRenderer() {
070: }
071:
072: public Component getTableCellRendererComponent(JTable table,
073: Object value, boolean isSelected, boolean hasFocus,
074: int row, int column) {
075:
076: if (value != null) {
077: ColumnData columnData = (ColumnData) value;
078: if (columnData.isMarkedDeleted()) {
079: setIcon(deleteImage);
080: setToolTipText("This column marked to be dropped");
081: } else if (columnData.isNewColumn()) {
082: setIcon(newImage);
083: setToolTipText("This column marked new");
084: } else if (columnData.isPrimaryKey()) {
085:
086: if (columnData.isForeignKey()) {
087: setIcon(pkfkImage);
088: setToolTipText("Primary Key/Foreign Key");
089: } else {
090: setIcon(pkImage);
091: setToolTipText("Primary Key");
092: }
093:
094: } else if (columnData.isForeignKey()) {
095: setIcon(fkImage);
096: setToolTipText("Foreign Key");
097: } else {
098: setIcon(null);
099: }
100: }
101:
102: setBackground(Color.WHITE);
103: setHorizontalAlignment(JLabel.CENTER);
104:
105: /*
106: if (keyValue.equals(PRIMARY_AND_FOREIGN)) {
107: setIcon(pkfkImage);
108: }
109: else if (keyValue.equals(FOREIGN)) {
110: setIcon(fkImage);
111: }
112: else if (keyValue.equals(PRIMARY)) {
113: setIcon(pkImage);
114: }
115: else {
116: setIcon(null);
117: }
118: */
119: return this;
120: }
121:
122: }
|