KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > WingSetPane


1 /*
2  * $Id: WingSetPane.java,v 1.10 2005/05/26 13:18:08 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package wingset;
15
16
17 import org.wings.*;
18 import org.wings.event.SComponentAdapter;
19 import org.wings.event.SComponentEvent;
20 import org.wings.session.SessionManager;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 /**
25  * A basic WingSet Pane, which implements some often needed functions.
26  *
27  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
28  * @version $Revision: 1.10 $
29  */

30 abstract public class WingSetPane extends SPanel implements SConstants {
31     protected final static transient Log log = LogFactory.getLog(WingSetPane.class);
32     private static final SResourceIcon SOURCE_LABEL_ICON = new SResourceIcon("org/wings/icons/File.gif");
33     private boolean initialized = false;
34
35     public WingSetPane() {
36         setLayout(createResourceTemplate("/templates/ContentLayout.thtml"));
37
38         SAnchor anchor = new SAnchor("../" + getClass().getName().substring(getClass().getName().indexOf('.') + 1) + ".java");
39         anchor.setTarget("sourceWindow");
40         anchor.add(new SLabel("view java source code", SOURCE_LABEL_ICON));
41         add(anchor, "viewSource");
42
43         addComponentListener(new SComponentAdapter() {
44             public void componentShown(SComponentEvent e) {
45                 initializePanel();
46             }
47         });
48     }
49
50     protected void initializePanel() {
51         if (!initialized) {
52             SComponent exampleComponent = createExample();
53             exampleComponent.setHorizontalAlignment(SConstants.CENTER);
54             add(exampleComponent, "content"); // content generated by example
55
initialized = true;
56         }
57     }
58
59     /**
60      * Override this.
61      */

62     protected abstract SComponent createExample();
63
64     protected static SLayoutManager createResourceTemplate(String JavaDoc name) {
65         try {
66             return new STemplateLayout(SessionManager.getSession().getServletContext().getRealPath(name));
67         } catch (Exception JavaDoc ex) {
68             log.error("Ex",ex);
69         }
70         return null;
71     }
72 }
73
Popular Tags