KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > specifier > base > BasePanel


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.specifier.base;
31
32 import java.io.InputStream JavaDoc;
33
34 import javax.swing.JPanel JavaDoc;
35
36 import com.genimen.djeneric.repository.exceptions.DjenericException;
37 import com.genimen.djeneric.structure.EditorDefinition;
38 import com.genimen.djeneric.structure.ResourceDefinition;
39 import com.genimen.djeneric.tools.specifier.interfaces.SpecifierPanel;
40 import com.genimen.djeneric.tools.specifier.interfaces.SpecifierPanelContainer;
41
42 public abstract class BasePanel extends JPanel JavaDoc implements SpecifierPanel
43 {
44   /*
45    * cleanup is called when the panel is about to get closed
46    */

47   abstract protected void cleanup() throws DjenericException;
48
49   private SpecifierPanelContainer _panelContainer;
50
51   protected SpecifierPanelContainer getSpecifierPanelContainer()
52   {
53     return _panelContainer;
54   }
55
56   public void setSpecifierPanelContainer(SpecifierPanelContainer container)
57   {
58     _panelContainer = container;
59   }
60
61   public void setStatusMessage(String JavaDoc msg)
62   {
63     _panelContainer.setStatusMessage(msg, true);
64   }
65
66   public void setStatusMessage(Throwable JavaDoc t)
67   {
68     _panelContainer.setStatusMessage(t);
69   }
70
71   public void setStatusMessage(String JavaDoc msg, boolean isInformative)
72   {
73     _panelContainer.setStatusMessage(msg, isInformative);
74   }
75
76   public void setStatusMessageNow(String JavaDoc msg, boolean isInformative)
77   {
78     _panelContainer.setStatusMessageNow(msg, isInformative);
79   }
80
81   public ResourceDefinition getResourceDefinition(String JavaDoc name)
82   {
83     return _panelContainer.getResourceDefinition(name);
84   }
85
86   public InputStream JavaDoc getResourceAsStream(String JavaDoc name)
87   {
88     return _panelContainer.getResourceAsStream(name);
89   }
90
91   public Class JavaDoc loadClass(String JavaDoc name) throws ClassNotFoundException JavaDoc
92   {
93     return _panelContainer.loadClass(name);
94   }
95
96   public EditorDefinition getEditorDefinition(String JavaDoc editorName)
97   {
98     return _panelContainer.getEditorDefinition(editorName);
99   }
100
101   public boolean editorExists(String JavaDoc editorName)
102   {
103     return _panelContainer.getEditorDefinition(editorName) != null;
104   }
105
106   public boolean canClose()
107   {
108     return true;
109   }
110
111   public boolean close()
112   {
113     try
114     {
115       cleanup();
116       removeFromContainer();
117       return true;
118     }
119     catch (DjenericException x)
120     {
121       setStatusMessage(x.getMessage(), false);
122       return false;
123     }
124   }
125
126   public void removeFromContainer()
127   {
128     if (getSpecifierPanelContainer() == null)
129     {
130       System.err.println("Internal error: BasePanel.setSpecifierPanelContainer() not called. "
131                          + "Don't know how to remove panel");
132     }
133     else getSpecifierPanelContainer().notifyClosed(this);
134   }
135
136 }
Popular Tags