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:
036: import javax.swing.*;
037:
038: import de.ug2t.kernel.*;
039: import de.ug2t.unifiedGui.interfaces.*;
040:
041: public class HoSwingLink extends HoSwingComponent implements IUnLink {
042: final class MyJButton extends JButton {
043: protected void paintBorder(Graphics g) {
044: if (this .isRolloverEnabled())
045: super .paintBorder(g);
046: };
047:
048: /**
049: *
050: */
051: public MyJButton() {
052: super ();
053: }
054:
055: /**
056: * @param text
057: */
058: public MyJButton(String text) {
059: super (text);
060: }
061:
062: /**
063: * @param a
064: */
065: public MyJButton(Action a) {
066: super (a);
067: }
068:
069: /**
070: * @param icon
071: */
072: public MyJButton(Icon icon) {
073: super (icon);
074: }
075:
076: /**
077: * @param text
078: * @param icon
079: */
080: public MyJButton(String text, Icon icon) {
081: super (text, icon);
082: }
083: }
084:
085: private MyJButton pem_swingButton = null;
086: private HoSwingImage pem_icon = null;
087:
088: public HoSwingLink(String xValue, IUnApplication xAppl)
089: throws Exception {
090: super (xValue, xAppl);
091: this .pcmf_setLocalValue(xValue);
092: this .pcmf_setEventOnChange(true);
093:
094: pem_swingButton = new MyJButton(xValue);
095: pem_swingButton.setMargin(new Insets(2, 2, 2, 2));
096:
097: super .pdm_realSwingCmp = this .pem_swingButton;
098: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
099:
100: ActionListener l = new ActionListener() {
101: public void actionPerformed(ActionEvent ev) {
102: try {
103: String l_objName = HoSwingLink.this
104: .pcmf_getObjName();
105:
106: // Lokale Listener aufrufen
107: HoSwingLink.this .pcmf_setValue(HoSwingLink.this
108: .pcmf_getValue());
109: HoSwingLink.this .pcmf_setRefresh();
110: HoSwingLink.this .pcmf_dispatchEvent();
111:
112: if (HoSwingLink.this .pem_session.pcmf_isDisabled())
113: return;
114:
115: // Werte setzen um diese zum Server zu übertragen
116: ((HoSwingPage) HoSwingLink.this .pcmf_getAppl()
117: .pcmf_getActive()).pcmf_setSubmitValue(
118: l_objName, HoSwingLink.this .pcmf_getValue()
119: .toString());
120: HoSwingLink.this .pcmf_addSyncedWidgets(
121: (HoSwingPage) HoSwingLink.this
122: .pcmf_getAppl().pcmf_getActive(),
123: HoSwingLink.this );
124: if (HoSwingLink.this .pcmf_getUnComponent()
125: .pcmf_isSubmit() == true)
126: ((HoSwingPage) HoSwingLink.this .pcmf_getAppl()
127: .pcmf_getActive()).pcmf_submit();
128: } catch (Exception e) {
129: KeLog.pcmf_logException("ug2t", this , e);
130: }
131: ;
132: };
133: };
134: this .pem_swingButton.addActionListener(l);
135:
136: MouseAdapter m = new HoMouseAdapter() {
137: public void mouseEntered(MouseEvent e) {
138: HoSwingLink.this .pem_swingButton
139: .setRolloverEnabled(true);
140: HoSwingLink.this .pem_swingButton.repaint();
141: }
142:
143: public void mouseExited(MouseEvent e) {
144: HoSwingLink.this .pem_swingButton
145: .setRolloverEnabled(false);
146: HoSwingLink.this .pem_swingButton.repaint();
147: }
148: };
149: this .pem_swingButton.addMouseListener(m);
150:
151: return;
152: };
153:
154: public void pcmf_setValue(Object xValue) {
155: if (xValue instanceof HoSwingImage) {
156: this .pem_swingButton
157: .setIcon(((JLabel) ((HoSwingImage) xValue)
158: .pcmf_getRealSwingObj()).getIcon());
159: this .pem_swingButton.setText(null);
160: }
161: ;
162:
163: super .pcmf_setValue(xValue);
164: };
165:
166: public void pcmf_setIcon(IUnImage xIcon) {
167: pem_icon = (HoSwingImage) xIcon;
168: this .pem_swingButton.setIcon(((JLabel) pem_icon
169: .pcmf_getRealSwingObj()).getIcon());
170: }
171:
172: public IUnImage pcmf_getIcon() {
173: return (pem_icon);
174: };
175:
176: public void pcmf_setKeyAccess(int xKey) {
177: this .pem_swingButton.setMnemonic(Character
178: .toString((char) xKey).toUpperCase().charAt(0));
179: };
180:
181: public int pcmf_getAccKey() {
182: return (this .pem_swingButton.getMnemonic());
183: }
184:
185: private int pem_talign = IUnInputField.TEXT_ALIGN_WEST;
186:
187: public void pcmf_setTextAlign(int xAlign) {
188: if (IUnInputField.TEXT_ALIGN_EAST == xAlign)
189: this .pem_swingButton
190: .setHorizontalAlignment(SwingConstants.RIGHT);
191: else if (IUnInputField.TEXT_ALIGN_CENTER == xAlign)
192: this .pem_swingButton
193: .setHorizontalAlignment(SwingConstants.CENTER);
194: else
195: this .pem_swingButton
196: .setHorizontalAlignment(SwingConstants.LEFT);
197:
198: this .pem_talign = xAlign;
199: }
200:
201: public int pcmf_getTextAlign() {
202: return (this.pem_talign);
203: }
204: }
|