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:
039: import de.ug2t.kernel.*;
040: import de.ug2t.unifiedGui.views.*;
041:
042: public final class HoSwingFlexListCellRenderer implements
043: ListCellRenderer {
044: /*
045: * (non-Javadoc)
046: *
047: * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList,
048: * java.lang.Object, int, boolean, boolean)
049: */
050:
051: private HashMap pem_colorBuffer = new HashMap();
052: private DefaultListCellRenderer pem_renderer = new DefaultListCellRenderer();
053: private int pem_inRender = 0;
054:
055: public Component getListCellRendererComponent(JList arg0,
056: Object arg1, int arg2, boolean arg3, boolean arg4) {
057: this .pem_inRender++;
058:
059: pem_renderer.setFont(null);
060: pem_renderer.setIcon(null);
061:
062: if (arg1 instanceof IKeViewable
063: && arg1 instanceof HoSwingComponent == false) {
064: IKeView l_view = ((IKeViewable) arg1).pcmf_getView();
065: if (l_view != null && l_view instanceof UnIconValueView) {
066: JLabel l_label = (JLabel) this .pem_renderer
067: .getListCellRendererComponent(arg0, arg1, arg2,
068: arg3, arg4);
069: ((UnIconValueView) l_view).pcmf_applyStdView(l_label);
070:
071: this .pem_inRender--;
072: return (l_label);
073: }
074: }
075:
076: if (arg1 == null || arg1 instanceof HoSwingComponent == false) {
077: this .pem_inRender--;
078: return (this .pem_renderer.getListCellRendererComponent(
079: arg0, arg1, arg2, arg3, arg4));
080: }
081:
082: if (arg3) {
083: if (this .pem_inRender < 10) {
084: Rectangle l_rect = arg0.getCellBounds(arg2, arg2);
085: if (l_rect != null) {
086: MouseListener[] l_listen = ((HoSwingComponent) arg1)
087: .pcmf_getRealSwingObj().getMouseListeners();
088: for (int i = 0; i < l_listen.length; i++)
089: if (l_listen[i] instanceof HoPopUpEventDispatcher)
090: ((HoSwingComponent) arg1)
091: .pcmf_getRealSwingObj()
092: .removeMouseListener(l_listen[i]);
093:
094: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
095: .addMouseListener(
096: new HoPopUpEventDispatcher(arg0,
097: l_rect.getLocation().y));
098: }
099: }
100:
101: // Selected
102: if ((HoSwingColorBuffer) this .pem_colorBuffer.get(arg1) == null) {
103: this .pem_colorBuffer.put(arg1,
104: new HoSwingColorBuffer(
105: ((HoSwingComponent) arg1)
106: .pcmf_getRealSwingObj()
107: .getForeground(),
108: ((HoSwingComponent) arg1)
109: .pcmf_getRealSwingObj()
110: .getBackground(),
111: ((JComponent) ((HoSwingComponent) arg1)
112: .pcmf_getRealSwingObj())
113: .isOpaque()));
114: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
115: .setBackground(arg0.getSelectionBackground());
116: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
117: .setForeground(arg0.getSelectionForeground());
118: ((JComponent) ((HoSwingComponent) arg1)
119: .pcmf_getRealSwingObj()).setOpaque(true);
120: }
121: } else if (!arg3) {
122: // Unselected
123: HoSwingColorBuffer l_cb = (HoSwingColorBuffer) this .pem_colorBuffer
124: .remove(arg1);
125: if (l_cb != null) {
126: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
127: .setBackground(l_cb.pcmf_getBg());
128: ((HoSwingComponent) arg1).pcmf_getRealSwingObj()
129: .setForeground(l_cb.pcmf_getFg());
130: ((JComponent) ((HoSwingComponent) arg1)
131: .pcmf_getRealSwingObj()).setOpaque(l_cb
132: .pcmf_getOp());
133: }
134: }
135:
136: this .pem_inRender--;
137: return (((HoSwingComponent) arg1).pcmf_getRealSwingObj());
138: }
139:
140: public void pcmf_resetAllColors() {
141: Iterator l_it = this .pem_colorBuffer.keySet().iterator();
142: while (l_it.hasNext()) {
143: HoSwingComponent l_obj = (HoSwingComponent) l_it.next();
144: HoSwingColorBuffer l_cb = (HoSwingColorBuffer) this .pem_colorBuffer
145: .get(l_obj);
146:
147: l_obj.pcmf_getRealSwingObj().setBackground(
148: l_cb.pcmf_getBg());
149: l_obj.pcmf_getRealSwingObj().setForeground(
150: l_cb.pcmf_getFg());
151: ((JComponent) l_obj.pcmf_getRealSwingObj()).setOpaque(l_cb
152: .pcmf_getOp());
153: }
154: }
155: }
|