001: /*
002: * Copyright (C) 2004 TiongHiang Lee
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Email: thlee@onemindsoft.org
019: */
020:
021: package org.onemind.swingweb.client.gwt.widget;
022:
023: import com.google.gwt.user.client.DOM;
024: import com.google.gwt.user.client.ui.*;
025:
026: public class TitleBar extends MousePanel implements MouseListener {
027:
028: private Label _title;
029:
030: private MoveableWindow _window;
031:
032: private int dragStartX, dragStartY;
033:
034: private boolean selected = false;
035:
036: private class Control extends FocusPanel implements MouseListener {
037:
038: private Image _img;
039:
040: public Control(String imgUrl) {
041: setStyleName("WindowControl");
042: _img = new Image(imgUrl);
043: add(_img);
044: DOM.setStyleAttribute(getElement(), "borderWidth", "1px");
045: DOM.setStyleAttribute(getElement(), "borderStyle", "solid");
046: DOM.setStyleAttribute(getElement(), "borderColor",
047: "white black black white");
048: addMouseListener(this );
049: }
050:
051: public void onMouseDown(Widget sender, int x, int y) {
052: DOM.setStyleAttribute(getElement(), "borderColor",
053: "black white white black");
054: }
055:
056: public void onMouseEnter(Widget sender) {
057: // TODO Auto-generated method stub
058: }
059:
060: public void onMouseLeave(Widget sender) {
061: DOM.setStyleAttribute(getElement(), "borderColor",
062: "white black black white");
063: }
064:
065: public void onMouseMove(Widget sender, int x, int y) {
066: // TODO Auto-generated method stub
067: }
068:
069: public void onMouseUp(Widget sender, int x, int y) {
070: DOM.setStyleAttribute(getElement(), "borderColor",
071: "white black black white");
072: }
073: }
074:
075: boolean dragging;
076:
077: public TitleBar(String title) {
078: setStyleName("TitleBar");
079: HorizontalPanel main = new HorizontalPanel();
080: DOM.setAttribute(main.getElement(), "width", "100%");
081: _title = new Label(title);
082: main.add(_title);
083: DOM.setAttribute(_title.getElement(), "width", "100%");
084: HorizontalPanel controls = new HorizontalPanel();
085: Control min = new Control("images/minimize.gif");
086: min.addClickListener(new ClickListener() {
087:
088: public void onClick(Widget sender) {
089: _window.fireMinimizeEvent();
090: }
091: });
092: controls.add(min);
093: Control max = new Control("images/maximize.gif");
094: max.addClickListener(new ClickListener() {
095:
096: public void onClick(Widget sender) {
097: _window.fireMaximizeEvent();
098: }
099: });
100: controls.add(max);
101: Control close = new Control("images/close.gif");
102: close.addClickListener(new ClickListener() {
103:
104: public void onClick(Widget sender) {
105: _window.fireCloseEvent();
106: }
107: });
108: controls.add(close);
109: HorizontalPanel controlArea = new HorizontalPanel();
110: controlArea.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
111: DOM.setAttribute(controlArea.getElement(), "width", "100%");
112: controlArea.add(controls);
113: main.add(controlArea);
114: setWidget(main);
115: addMouseListener(this );
116: }
117:
118: public void setTitleText(String title) {
119: _title.setText(title);
120: }
121:
122: public String getTitleText() {
123: return _title.getText();
124: }
125:
126: public void setWindow(MoveableWindow window) {
127: _window = window;
128: }
129:
130: public void onMouseDown(Widget sender, int x, int y) {
131: if (!(sender instanceof Control)) {//not clicking on buttons
132: dragging = true;
133: DOM.setCapture(this .getElement());
134: dragStartX = x;
135: dragStartY = y;
136: }
137: }
138:
139: public void onMouseEnter(Widget sender) {
140: // TODO Auto-generated method stub
141: }
142:
143: public void onMouseLeave(Widget sender) {
144: // dragging = false;
145: // DOM.releaseCapture(this.getElement());
146: // DOM.setStyleAttribute(getElement(), "cursor", "default");
147: }
148:
149: public void onMouseMove(Widget sender, int x, int y) {
150: if (dragging) {
151: // int absX = x + _window.getAbsoluteLeft();
152: // int absY = y + _window.getAbsoluteTop();
153: int absX = x + _window.getPopupLeft();
154: int absY = y + _window.getPopupTop();
155: _window.setPopupPosition(absX - dragStartX, absY
156: - dragStartY);
157: DOM.setStyleAttribute(getElement(), "cursor", "move");
158: }
159: }
160:
161: public void onMouseUp(Widget sender, int x, int y) {
162: dragging = false;
163: DOM.releaseCapture(this .getElement());
164: DOM.setStyleAttribute(getElement(), "cursor", "default");
165: }
166:
167: public void setSelected(boolean selected) {
168: if (selected) {
169: String styleName = getStyleName();
170: if (!styleName.endsWith("-selected")) {
171: setStyleName(styleName + "-selected");
172: }
173: } else {
174: String styleName = getStyleName();
175: if (styleName.endsWith("-selected")) {
176: setStyleName(styleName.substring(0, styleName
177: .indexOf("-selected")));
178: }
179: }
180: }
181: }
|