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.demo;
022:
023: import java.awt.BorderLayout;
024: import java.awt.Color;
025: import java.awt.event.ActionListener;
026: import javax.swing.*;
027: import org.onemind.swingweb.Constants;
028: import org.onemind.swingweb.util.SwingWebUtils;
029:
030: public class TemplateDemo extends JFrame {
031:
032: private Object[][] nav = {
033: {
034: "Books",
035: new String[] { "Fiction", "Reference", "Biography" } },
036: {
037: "Music",
038: new String[] { "New releases", "Hip-hop", "Rock",
039: "Alternative" } },
040: { "Video", new String[] { "Comedy", "Action", "Sci-fi" } },
041: { "Electronics",
042: new String[] { "Computer", "Kitchen", "Consumer" } } };
043:
044: private JTabbedPane _nav;
045:
046: private JCheckBox _templateToggle;
047:
048: public TemplateDemo() {
049: getContentPane().setLayout(new BorderLayout());
050: _templateToggle = new JCheckBox("Toggle template");
051: _templateToggle.addActionListener(new ActionListener() {
052:
053: public void actionPerformed(java.awt.event.ActionEvent e) {
054: toggleTemplate();
055: }
056: });
057: getContentPane().add(BorderLayout.NORTH, _templateToggle);
058: _nav = new JTabbedPane();
059: _nav.setBackground(Color.WHITE);
060: for (int i = 0; i < nav.length; i++) {
061: JTabbedPane subNav = new JTabbedPane();
062: subNav.setBackground(Color.WHITE);
063: _nav.add((String) nav[i][0], subNav);
064: String[] subNavs = (String[]) nav[i][1];
065: for (int j = 0; j < subNavs.length; j++) {
066: subNav.add(subNavs[j], new JLabel("This is "
067: + subNavs[j] + " section "));
068: }
069: }
070: getContentPane().add(BorderLayout.CENTER, _nav);
071: }
072:
073: /**
074: *
075: */
076: private void toggleTemplate() {
077: if (_templateToggle.isSelected()) {
078: SwingWebUtils.putComponentProperty(this ,
079: Constants.SW_RENDER_TEMPLATE,
080: "org/onemind/swingweb/demo/MyFrame.template");
081: SwingWebUtils.putComponentProperty(this .getContentPane(),
082: Constants.SW_RENDER_TEMPLATE,
083: "org/onemind/swingweb/demo/MyPanel.template");
084: SwingWebUtils.putComponentProperty(_nav,
085: Constants.SW_RENDER_TEMPLATE,
086: "org/onemind/swingweb/demo/MyTabbedPane.template");
087: } else {
088: SwingWebUtils.removeComponentProperty(this ,
089: Constants.SW_RENDER_TEMPLATE);
090: SwingWebUtils
091: .removeComponentProperty(this .getContentPane(),
092: Constants.SW_RENDER_TEMPLATE);
093: SwingWebUtils.removeComponentProperty(_nav,
094: Constants.SW_RENDER_TEMPLATE);
095: }
096: }
097:
098: public static void main(String[] args) {
099: TemplateDemo demo = new TemplateDemo();
100: demo.pack();
101: demo.setSize(1024, 768);
102: demo.show();
103: }
104: }
|