01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2006 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the
09: * Free Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15: * for more details.
16: *
17: * You should have received a copy of the GNU General Public License along with
18: * this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: *
21: *ExpandableLabel.java
22: *LPS
23: *Nov 9, 2007
24: */
25: package com.bostechcorp.cbesb.console.client;
26:
27: import com.google.gwt.user.client.Window;
28: import com.google.gwt.user.client.WindowResizeListener;
29: import com.google.gwt.user.client.ui.ChangeListener;
30: import com.google.gwt.user.client.ui.ClickListener;
31: import com.google.gwt.user.client.ui.Label;
32: import com.google.gwt.user.client.ui.PopupPanel;
33: import com.google.gwt.user.client.ui.TextBox;
34: import com.google.gwt.user.client.ui.Widget;
35:
36: /**
37: * @author LPS
38: *
39: */
40: public class ExpandableLabel extends TextBox implements ChangeListener,
41: WindowResizeListener, ClickListener {
42:
43: private String text;
44: private ThePopup popup = new ThePopup();
45:
46: public ExpandableLabel(String text) {
47: super ();
48: this .text = text;
49: setWidth("100%");
50: setReadOnly(true);
51: setStyleName("contentLabel");
52: // setText(text);
53: // setSelectionRange(0,0);
54: // setCursorPos(0);
55: setVisibleText();
56: popup = new ThePopup();
57: this .addChangeListener(this );
58: this .addClickListener(this );
59: // Window.addWindowResizeListener(this);
60: }
61:
62: public void onChange(Widget sender) {
63: setVisibleText();
64: }
65:
66: private void setVisibleText() {
67: if (this .getVisibleLength() <= text.length()) {
68: setText(text.substring(0, this .getVisibleLength()));
69: } else {
70: setText(text);
71: }
72: }
73:
74: public void onWindowResized(int width, int height) {
75: setVisibleText();
76: }
77:
78: public void onClick(Widget sender) {
79: popup.setPopupPosition(
80: getAbsoluteLeft() + getOffsetWidth() / 2,
81: getAbsoluteTop() + getOffsetHeight() / 2);
82: popup.setWidth(""
83: + (Window.getClientWidth() - popup.getAbsoluteLeft())
84: + "px");
85: popup.show();
86: }
87:
88: class ThePopup extends PopupPanel {
89: public ThePopup() {
90: super (true);
91: setStyleName("contentLabel-Popup");
92: Label l = new Label(text);
93: //l.setStyleName("contentLabel-Popup");
94: add(l);
95: }
96: }
97: }
|