001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.channel.ho.client.swing;
032:
033: import java.awt.*;
034: import java.awt.event.*;
035: import java.util.*;
036:
037: import javax.swing.*;
038: import javax.swing.table.*;
039:
040: import de.ug2t.kernel.*;
041: import de.ug2t.unifiedGui.views.*;
042:
043: public final class HoSwingFlexTableCellRenderer extends
044: DefaultTableCellRenderer {
045: private DefaultTableCellRenderer pem_renderer = new DefaultTableCellRenderer();
046: private HashMap pem_colorBuffer = new HashMap();
047: private int pem_inRender = 0;
048:
049: /*
050: * (non-Javadoc)
051: *
052: * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
053: * java.lang.Object, boolean, boolean, int, int)
054: */
055: public Component getTableCellRendererComponent(JTable arg0,
056: Object arg1, boolean arg2, boolean arg3, int arg4, int arg5) {
057: this .pem_inRender++;
058:
059: pem_renderer.setFont(null);
060: pem_renderer.setIcon(null);
061:
062: // Das ist der Header
063: if (arg1 instanceof String && arg4 == -1) {
064: arg1 = KeTools.pcmf_deRefObj(arg1.toString());
065: if (arg1 instanceof String) {
066: JButton l_but = new JButton(arg1.toString());
067: l_but.setHorizontalAlignment(SwingConstants.LEFT);
068: l_but.setVerticalTextPosition(0);
069: l_but.setHorizontalTextPosition(0);
070: l_but.setPreferredSize(new Dimension(0, arg0
071: .getRowHeight() + 4));
072:
073: ((HoSwingEnhJTable) arg0).pcmf_addPainter(l_but);
074:
075: this .pem_inRender--;
076: return (l_but);
077: } else if (arg1 instanceof HoSwingImage) {
078: Icon l_ico = ((JLabel) ((HoSwingImage) arg1)
079: .pcmf_getRealSwingObj()).getIcon();
080: JButton l_but = new JButton(l_ico);
081: int l_hi = l_ico.getIconHeight();
082: int l_wi = l_ico.getIconWidth();
083: l_but.setVerticalTextPosition(0);
084: l_but.setHorizontalTextPosition(0);
085: l_but
086: .setPreferredSize(new Dimension(l_wi + 4,
087: l_hi + 4));
088:
089: ((HoSwingEnhJTable) arg0).pcmf_addPainter(l_but);
090:
091: this .pem_inRender--;
092: return (l_but);
093: } else if (arg1 instanceof HoSwingComponent) {
094: this .pem_inRender--;
095: return (((HoSwingComponent) arg1)
096: .pcmf_getRealSwingObj());
097: }
098: }
099: if (arg1 instanceof IKeViewable
100: && arg1 instanceof HoSwingComponent == false) {
101: IKeView l_view = ((IKeViewable) arg1).pcmf_getView();
102: if (l_view != null && l_view instanceof UnIconValueView) {
103: JLabel l_label = (JLabel) this .pem_renderer
104: .getTableCellRendererComponent(arg0, arg1,
105: arg2, false, arg4, arg5);
106: JLabel l_retLabel = new JLabel();
107: l_retLabel.setForeground(l_label.getForeground());
108: l_retLabel.setBackground(l_label.getBackground());
109: l_retLabel.setText(l_label.getText());
110: l_retLabel.setFont(l_label.getFont());
111: l_retLabel.setOpaque(l_label.isOpaque());
112: ((UnIconValueView) l_view)
113: .pcmf_applyStdView(l_retLabel);
114: ((HoSwingEnhJTable) arg0).pcmf_addPainter(l_retLabel);
115:
116: this .pem_inRender--;
117: return (l_retLabel);
118: }
119: }
120:
121: if (arg1 == null || arg1 instanceof HoSwingComponent == false) {
122: this .pem_inRender--;
123: return (this .pem_renderer.getTableCellRendererComponent(
124: arg0, arg1, arg2, false, arg4, arg5));
125: }
126:
127: if (arg2 && arg4 != -1) {
128: if (this .pem_inRender < 10) {
129: Rectangle l_rect = arg0.getCellRect(arg4, arg5, true);
130: if (l_rect != null) {
131: MouseListener[] l_listen = ((HoSwingComponent) arg1)
132: .pcmf_getRealSwingObj().getMouseListeners();
133: for (int i = 0; i < l_listen.length; i++)
134: if (l_listen[i] instanceof HoPopUpEventDispatcher)
135: ((HoSwingComponent) arg1)
136: .pcmf_getRealSwingObj()
137: .removeMouseListener(l_listen[i]);
138:
139: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
140: .addMouseListener(
141: new HoPopUpEventDispatcher(arg0,
142: l_rect.getLocation().y));
143: }
144: }
145:
146: // Selected
147: if ((HoSwingColorBuffer) this .pem_colorBuffer.get(arg1) == null) {
148: this .pem_colorBuffer.put(arg1,
149: new HoSwingColorBuffer(
150: ((HoSwingComponent) arg1)
151: .pcmf_getRealSwingObj()
152: .getForeground(),
153: ((HoSwingComponent) arg1)
154: .pcmf_getRealSwingObj()
155: .getBackground(),
156: ((JComponent) ((HoSwingComponent) arg1)
157: .pcmf_getRealSwingObj())
158: .isOpaque()));
159: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
160: .setBackground(arg0.getSelectionBackground());
161: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
162: .setForeground(arg0.getSelectionForeground());
163: ((JComponent) ((HoSwingComponent) arg1)
164: .pcmf_getRealSwingObj()).setOpaque(true);
165: }
166: } else if (!arg2 && arg4 != -1) {
167: // Unselected
168: HoSwingColorBuffer l_cb = (HoSwingColorBuffer) this .pem_colorBuffer
169: .remove(arg1);
170: if (l_cb != null) {
171: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
172: .setBackground(l_cb.pcmf_getBg());
173: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
174: .setForeground(l_cb.pcmf_getFg());
175: ((JComponent) ((HoSwingComponent) arg1)
176: .pcmf_getRealSwingObj()).setOpaque(l_cb
177: .pcmf_getOp());
178: }
179: }
180: this .pem_inRender--;
181: return (((HoSwingComponent) arg1).pcmf_getRealSwingObj());
182: }
183:
184: public void pcmf_resetAllColors() {
185: Iterator l_it = this .pem_colorBuffer.keySet().iterator();
186: while (l_it.hasNext()) {
187: HoSwingComponent l_obj = (HoSwingComponent) l_it.next();
188: HoSwingColorBuffer l_cb = (HoSwingColorBuffer) this .pem_colorBuffer
189: .get(l_obj);
190:
191: l_obj.pcmf_getRealSwingObj().setBackground(
192: l_cb.pcmf_getBg());
193: l_obj.pcmf_getRealSwingObj().setForeground(
194: l_cb.pcmf_getFg());
195: ((JComponent) l_obj.pcmf_getRealSwingObj()).setOpaque(l_cb
196: .pcmf_getOp());
197: }
198: }
199: }
|