001: /* *************************************************************************
002:
003: Millstone(TM)
004: Open Sourced User Interface Library for
005: Internet Development with Java
006:
007: Millstone is a registered trademark of IT Mill Ltd
008: Copyright (C) 2000-2005 IT Mill Ltd
009:
010: *************************************************************************
011:
012: This library is free software; you can redistribute it and/or
013: modify it under the terms of the GNU Lesser General Public
014: license version 2.1 as published by the Free Software Foundation.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: *************************************************************************
026:
027: For more information, contact:
028:
029: IT Mill Ltd phone: +358 2 4802 7180
030: Ruukinkatu 2-4 fax: +358 2 4802 7181
031: 20540, Turku email: info@itmill.com
032: Finland company www: www.itmill.com
033:
034: Primary source for MillStone information and releases: www.millstone.org
035:
036: ********************************************************************** */
037:
038: package org.millstone.examples.features;
039:
040: import java.util.HashMap;
041: import java.util.List;
042:
043: import org.millstone.base.ui.*;
044: import org.millstone.base.ui.Button.ClickEvent;
045:
046: public class FeatureFrameWindow extends Feature implements
047: Button.ClickListener {
048:
049: private Button addButton = new Button("Add to application", this ,
050: "addWin");
051: private Button removeButton = new Button("Remove from application",
052: this , "delWin");
053: private FrameWindow demoWindow;
054: private HashMap windowToFramesetMap = new HashMap();
055: private int count = 0;
056:
057: protected Component getDemoComponent() {
058: OrderedLayout l = new OrderedLayout();
059: demoWindow = new FrameWindow("Feature Test Window");
060: demoWindow.getFrameset().newFrame(
061: createFrame(demoWindow.getFrameset()));
062:
063: // Example panel
064: Panel show = new Panel("Test Window Control");
065: ((OrderedLayout) show.getLayout())
066: .setOrientation(OrderedLayout.ORIENTATION_HORIZONTAL);
067: show.addComponent(addButton);
068: show.addComponent(removeButton);
069: updateWinStatus();
070: l.addComponent(show);
071:
072: // Properties
073: PropertyPanel p = new PropertyPanel(demoWindow);
074: p.dependsOn(addButton);
075: p.dependsOn(removeButton);
076: Form ap = p.createBeanPropertySet(new String[] { "width",
077: "height", "name", "border", "theme" });
078: ap.replaceWithSelect("border", new Object[] {
079: new Integer(Window.BORDER_DEFAULT),
080: new Integer(Window.BORDER_NONE),
081: new Integer(Window.BORDER_MINIMAL) }, new Object[] {
082: "Default", "None", "Minimal" });
083:
084: p.addProperties("FrameWindow Properties", ap);
085: l.addComponent(p);
086:
087: return l;
088: }
089:
090: protected String getDescriptionXHTML() {
091: return "<p>This component implements a window that contains a hierarchical set of frames. "
092: + "Each frame can contain a web-page, window or a set of frames that divides the space "
093: + "horizontally or vertically.</p>";
094: }
095:
096: protected String getExampleSrc() {
097: return "FrameWindow f = new FrameWindow(\"Frame example\");\n"
098: + "f.getFrameset().newFrame(window);\n"
099: + "f.getFrameset().newFrame(resource,\"targetName\");\n";
100: }
101:
102: protected String getImage() {
103: return "framewindow.jpg";
104: }
105:
106: protected String getTitle() {
107: return "FrameWindow";
108: }
109:
110: public void addWin() {
111: getApplication().addWindow(demoWindow);
112: updateWinStatus();
113: }
114:
115: public void delWin() {
116: getApplication().removeWindow(demoWindow);
117: updateWinStatus();
118: }
119:
120: private void updateWinStatus() {
121: if (demoWindow.getApplication() == null) {
122: addButton.setEnabled(true);
123: removeButton.setEnabled(false);
124: } else {
125: addButton.setEnabled(false);
126: removeButton.setEnabled(true);
127: }
128: }
129:
130: public void buttonClick(ClickEvent event) {
131:
132: if (event.getButton().getCaption().equals("Remove")) {
133: Window w = event.getButton().getWindow();
134: FrameWindow.Frameset fs = (FrameWindow.Frameset) windowToFramesetMap
135: .get(w);
136: if (fs == demoWindow.getFrameset() && fs.size() <= 1) {
137: // Do not remove the last frame
138: } else if (fs.size() > 1) {
139: fs.removeFrame(fs.getFrame(w.getName()));
140: windowToFramesetMap.remove(w);
141: } else {
142: FrameWindow.Frameset p = fs.getParentFrameset();
143: if (p != demoWindow.getFrameset() || p.size() > 1)
144: p.removeFrame(fs);
145: if (p.size() == 0)
146: p.newFrame(createFrame(p));
147: }
148: }
149:
150: if (event.getButton().getCaption().equals("Split")) {
151: Window w = event.getButton().getWindow();
152: FrameWindow.Frameset fs = (FrameWindow.Frameset) windowToFramesetMap
153: .get(w);
154: int index = 0;
155: List l = fs.getFrames();
156: while (index < l.size()
157: && fs.getFrame(index).getWindow() != w)
158: index++;
159: fs.removeFrame(fs.getFrame(w.getName()));
160: windowToFramesetMap.remove(w);
161: if (index > fs.size())
162: index = fs.size();
163: fs = fs.newFrameset((Math.random() > 0.5), index);
164: for (int i = 2 + (int) (Math.random() * 2.0); i > 0; i--)
165: fs.newFrame(createFrame(fs));
166: }
167: }
168:
169: private Window createFrame(FrameWindow.Frameset fs) {
170: Window w = new Window();
171: w.addComponent(new Label("<b>Frame: " + (++count) + "</b>",
172: Label.CONTENT_UIDL));
173: w.addComponent(new Button("Split", this ));
174: w.addComponent(new Button("Remove", this));
175: windowToFramesetMap.put(w, fs);
176: return w;
177: }
178: }
|