01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.swingweb.demo;
22:
23: import java.awt.BorderLayout;
24: import java.awt.event.ActionEvent;
25: import java.awt.event.ActionListener;
26: import java.util.HashMap;
27: import java.util.Map;
28: import javax.swing.*;
29: import org.onemind.swingweb.component.shareapp.ViewComponent;
30: import org.onemind.swingweb.session.URLLocal;
31: import org.onemind.swingweb.util.SwingWebUtils;
32:
33: public class URLDemo extends JFrame implements ActionListener {
34:
35: private final String KEY_SECTION1 = "App1";
36:
37: private final String KEY_SECTION2 = "App2";
38:
39: private final String KEY_SECTION3 = "App3";
40:
41: private Map mappedSection = new HashMap();
42:
43: URLLocal viewValue = new URLLocal("section", KEY_SECTION1, 0, true);
44:
45: public URLDemo() {
46: JPanel main = new JPanel();
47: main.setLayout(new BorderLayout());
48: SwingWebUtils.registerURLLocal(viewValue);
49: ViewComponent com = new ViewComponent(viewValue);
50: com.addView(KEY_SECTION1, new JLabel("This is section 1"));
51: com.addView(KEY_SECTION2, new JLabel("This is section 2"));
52: com.addView(KEY_SECTION3, new JLabel("This is section 3"));
53: JPanel buttons = new JPanel();
54: buttons.add(createButton("Section 1", KEY_SECTION1));
55: buttons.add(createButton("Section 2", KEY_SECTION2));
56: buttons.add(createButton("Section 3", KEY_SECTION3));
57: main.add(buttons, BorderLayout.NORTH);
58: main.add(com, BorderLayout.CENTER);
59: getContentPane().add(main);
60: }
61:
62: private JButton createButton(String name, String section) {
63: JButton button = new JButton(name);
64: button.addActionListener(this );
65: mappedSection.put(button, section);
66: return button;
67: }
68:
69: public void actionPerformed(ActionEvent e) {
70: String section = (String) mappedSection.get(e.getSource());
71: if (section != null) {
72: viewValue.setValue(section);
73: }
74: }
75: }
|