KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > dods > InstructPanel


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common.dods;
24
25 // Standard imports
26
import java.awt.*;
27 import javax.swing.*;
28 import java.beans.*;
29
30 //
31
public class InstructPanel extends JPanel {
32     private GridBagLayout layoutMain = null;
33     private JPanel panelHelp = null;
34     private JPanel panelOptions = null;
35     private GridBagLayout layoutHelp = null;
36     private JLabel labelTitle = null;
37     private BorderLayout layoutOptions = null;
38     private JTextArea textInstruct = null;
39
40     public InstructPanel() {
41         try {
42             jbInit();
43             pmInit();
44         } catch (Exception JavaDoc ex) {
45             ex.printStackTrace();
46         }
47     }
48
49     //
50
protected String JavaDoc getInstruction() {
51         return textInstruct.getText();
52     }
53
54     protected void setInstructions(String JavaDoc text) {
55         textInstruct.setText(text);
56     }
57
58     protected void setTitle(String JavaDoc text) {
59         labelTitle.setText(text);
60     }
61
62     protected String JavaDoc getTitle() {
63         return labelTitle.getText();
64     }
65
66     protected void addInstuctor(Instructor i) {
67         if (i instanceof JPanel) {
68             panelOptions.removeAll();
69             panelOptions.add((JPanel) i, BorderLayout.CENTER);
70             setInstructions(i.getInstructions());
71             setTitle(i.getTitle());
72         } else {
73             throw new RuntimeException JavaDoc("Instructor not a JPanel "
74                                        + i.getTitle());
75         }
76     }
77
78     //
79
private void pmInit() {
80         Font font = labelTitle.getFont();
81
82         font = new Font(font.getName(), Font.BOLD, font.getSize());
83         labelTitle.setFont(font);
84         font = new Font(font.getName(), 0, font.getSize());
85         textInstruct.setFont(font);
86         textInstruct.setBackground(labelTitle.getBackground());
87     }
88
89     private void jbInit() throws Exception JavaDoc {
90         labelTitle = (JLabel) Beans.instantiate(getClass().getClassLoader(),
91                                                 JLabel.class.getName());
92         panelHelp = (JPanel) Beans.instantiate(getClass().getClassLoader(),
93                                                JPanel.class.getName());
94         panelOptions = (JPanel) Beans.instantiate(getClass().getClassLoader(),
95                                                   JPanel.class.getName());
96         layoutMain =
97             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
98                                               GridBagLayout.class.getName());
99         layoutHelp =
100             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
101                                               GridBagLayout.class.getName());
102         layoutOptions =
103             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
104                                              BorderLayout.class.getName());
105         textInstruct =
106             (JTextArea) Beans.instantiate(getClass().getClassLoader(),
107                                           JTextArea.class.getName());
108         labelTitle.setText("TITLE");
109         panelHelp.setLayout(layoutHelp);
110         textInstruct.setWrapStyleWord(true);
111         textInstruct.setLineWrap(true);
112         textInstruct.setEnabled(false);
113         textInstruct.setText("INSTRUCTIONS");
114         textInstruct.setDisabledTextColor(UIManager.getColor("textText"));
115         textInstruct.setBackground(UIManager.getColor("text"));
116         textInstruct.setEditable(false);
117         panelHelp.add(labelTitle,
118                       new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0,
119                                              GridBagConstraints.WEST,
120                                              GridBagConstraints.HORIZONTAL,
121                                              new Insets(3, 5, 1, 5), 0, 0));
122         panelHelp.add(textInstruct,
123                       new GridBagConstraints(0, 1, 1, 1, 0.1, 0.0,
124                                              GridBagConstraints.CENTER,
125                                              GridBagConstraints.HORIZONTAL,
126                                              new Insets(1, 5, 2, 5), 0, 0));
127         panelOptions.setLayout(layoutOptions);
128         this.setLayout(layoutMain);
129         this.add(panelHelp,
130                  new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0,
131                                         GridBagConstraints.NORTH,
132                                         GridBagConstraints.BOTH,
133                                         new Insets(5, 5, 5, 5), 0, 0));
134         this.add(panelOptions,
135                  new GridBagConstraints(0, 3, 1, 1, 0.1, 0.9,
136                                         GridBagConstraints.SOUTH,
137                                         GridBagConstraints.BOTH,
138                                         new Insets(2, 5, 2, 5), 0, 0));
139     }
140
141 }
142
Popular Tags