01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13:
14: package wingset;
15:
16: import java.awt.Color;
17: import org.wings.SBorderLayout;
18: import org.wings.SComponent;
19: import org.wings.SContainer;
20: import org.wings.SDimension;
21: import org.wings.SGridLayout;
22: import org.wings.SIcon;
23: import org.wings.SPanel;
24: import org.wings.SPopup;
25: import org.wings.SLabel;
26: import org.wings.SURLIcon;
27: import org.wings.border.SLineBorder;
28: import org.wings.script.JavaScriptEvent;
29: import org.wings.script.PopupListener;
30:
31: /**
32: *
33: * @author Christian Schyma
34: */
35: public class PopupExample extends WingSetPane {
36:
37: private static final SIcon WINGS_IMAGE = new SURLIcon(
38: "../icons/wings-logo.png");
39: private static final String SOME_TEXT = "What is wingS? In a nutshell, wingS is a web application\n"
40: + "framework based on Java Servlets, resembling the Swing API with\n"
41: + "its MVC paradigm and event oriented design principles. It utilizes\n"
42: + "the models, events, and event listeners of Swing. Like in Swing,\n"
43: + "components are arranged in a hierarchy of containers, whose root\n"
44: + "container is hooked to a frame.";
45:
46: public SContainer createContent() {
47: SContainer content = new SContainer(new SBorderLayout());
48: content.setBorder(new SLineBorder(1));
49: content.setBackground(Color.WHITE);
50: content.setPreferredSize(new SDimension(200, 200));
51: content.add(new SLabel(WINGS_IMAGE), SBorderLayout.NORTH);
52: SLabel label = new SLabel(SOME_TEXT);
53: content.add(new SLabel(SOME_TEXT), SBorderLayout.SOUTH);
54:
55: return content;
56: }
57:
58: public SComponent createExample() {
59: SPanel panel = new SPanel(new SGridLayout(2, 1, 50, 50));
60:
61: SLabel mouseSensitiveLabel = new SLabel("mouse sensitive label");
62: SPopup popup = new SPopup(null, createContent(), 100, 100);
63:
64: mouseSensitiveLabel.addScriptListener(new PopupListener(
65: JavaScriptEvent.ON_MOUSE_OVER, popup,
66: PopupListener.SHOW, mouseSensitiveLabel));
67: mouseSensitiveLabel.addScriptListener(new PopupListener(
68: JavaScriptEvent.ON_MOUSE_OUT, popup,
69: PopupListener.HIDE, mouseSensitiveLabel));
70:
71: panel.add(mouseSensitiveLabel);
72:
73: SLabel mouseSensitiveLabel2 = new SLabel(
74: "mouse sensitive label, popup gets aligned");
75: SPopup popup2 = new SPopup(null, createContent(), 0, 0);
76: popup2.setContext(mouseSensitiveLabel2, SPopup.TOP_LEFT,
77: SPopup.BOTTOM_LEFT);
78:
79: mouseSensitiveLabel2.addScriptListener(new PopupListener(
80: JavaScriptEvent.ON_MOUSE_OVER, popup2,
81: PopupListener.SHOW, mouseSensitiveLabel2));
82: mouseSensitiveLabel2.addScriptListener(new PopupListener(
83: JavaScriptEvent.ON_MOUSE_OUT, popup2,
84: PopupListener.HIDE, mouseSensitiveLabel2));
85:
86: panel.add(mouseSensitiveLabel2);
87:
88: return panel;
89: }
90:
91: protected SComponent createControls() {
92: return null;
93: }
94:
95: }
|