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.net.*;
035:
036: import javax.swing.*;
037:
038: import de.ug2t.kernel.*;
039: import de.ug2t.unifiedGui.interfaces.*;
040:
041: class MyImageIcon extends ImageIcon {
042: public volatile boolean pcm_isPainted = false;
043:
044: public MyImageIcon(URL location) {
045: super (location);
046: }
047:
048: public void pcmf_flushCache() {
049: ImageIcon.tracker.removeImage(this .getImage());
050: }
051:
052: public synchronized void paintIcon(Component c, Graphics g, int x,
053: int y) {
054: super .paintIcon(c, g, x, y);
055: this .pcm_isPainted = true;
056: }
057: }
058:
059: public final class HoSwingImage extends HoSwingComponent implements
060: IUnImage {
061: private JLabel pem_swingObj = null;
062:
063: public HoSwingImage(String xName, String xValue,
064: IUnApplication xAppl) throws Exception {
065: super (xName, xAppl);
066:
067: this .pem_swingObj = new JLabel(new MyImageIcon(new URL(xValue)));
068: this .pdm_realSwingCmp = this .pem_swingObj;
069: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
070:
071: return;
072: };
073:
074: public IUnImage pcmf_clone() {
075: try {
076: return (new HoSwingImage(this .pcmf_getName(), (String) this
077: .pcmf_getValue(), this .pcmf_getAppl()));
078: } catch (Exception e) {
079: return (null);
080: }
081: }
082:
083: public boolean pcmf_isPainted() {
084: return (((MyImageIcon) this .pem_swingObj.getIcon()).pcm_isPainted);
085: }
086:
087: public Icon pcmf_getIcon() {
088: return (this .pem_swingObj.getIcon());
089: }
090:
091: public void pcmf_setValue(Object xValue) {
092: try {
093: ((MyImageIcon) this .pem_swingObj.getIcon())
094: .pcmf_flushCache();
095: this .pem_swingObj.setIcon(new MyImageIcon(new URL(xValue
096: .toString())));
097: this .pcmf_setLocalValue(xValue);
098: } catch (Exception e) {
099: KeLog.pcmf_logException("ug2t", this , e);
100: }
101: ;
102:
103: return;
104: };
105:
106: private int pem_refcount = 0;
107:
108: public final void pcmf_attach() {
109: synchronized (this ) {
110: if (this .pdm_deleted)
111: KeLog
112: .pcmf_log(
113: "ug2t",
114: "attach a deleted ressource, error in synchronisation",
115: this , KeLog.FATAL);
116:
117: this .pem_refcount++;
118: }
119: }
120:
121: public void pcmf_forceDetach() {
122: synchronized (this ) {
123: this .pem_refcount = 0;
124: }
125: }
126:
127: public final void pcmf_detach() {
128: synchronized (this ) {
129: if (this .pem_refcount > 0)
130: this .pem_refcount--;
131: }
132: }
133:
134: public void pcmf_delete() throws Exception {
135: synchronized (this ) {
136: if (this .pdm_deleted == true || this .pem_refcount > 0)
137: return;
138:
139: super .pcmf_delete();
140: }
141: };
142:
143: public void pcmf_attachImage() {
144: this .pcmf_attach();
145: }
146:
147: public void pcmf_detachImage() {
148: this .pcmf_detach();
149: }
150:
151: /**
152: * <p>
153: * Releases an image for beeing deleted when not in use - delegate to fit
154: * interface
155: * </p>
156: * <p>
157: *
158: * </p>
159: * <p>
160: * </p>
161: */
162: public void pcmf_attachExtern() {
163: this .pcmf_attachImage();
164: }
165:
166: /**
167: * <p>
168: * Releases an image for beeing deleted when not in use - delegate to fit
169: * interface
170: * </p>
171: * <p>
172: *
173: * </p>
174: * <p>
175: * </p>
176: */
177: public void pcmf_detachExtern() {
178: this.pcmf_detachImage();
179: }
180: }
|