001: // package
002: package com.javelin.examples.swinglets;
003:
004: // import
005: import java.awt.event.*;
006: import java.awt.*;
007: import javax.servlet.http.*;
008:
009: import com.javelin.swinglets.*;
010: import com.javelin.swinglets.event.*;
011: import com.javelin.swinglets.table.*;
012:
013: import javax.servlet.*;
014: import java.io.*;
015: import java.util.*;
016:
017: public class ShowLearningPlan extends HttpServlet {
018:
019: //=====================================================================================
020: // Static Variables (ordered by public, protected, <default>, private)
021: //=====================================================================================
022:
023: static String LEARNING_PLAN = "LearningPlan";
024:
025: private static final SColor PAGE_BKG_COLOR = SColor
026: .getColor("#9999cc");
027:
028: //=====================================================================================
029: // Instance Variables (ordered by public, protected, <default>, private)
030: //=====================================================================================
031:
032: private CurrentCoursesForm _currentCourses;
033: private RegisteredCoursesForm _registeredCourses;
034:
035: //=====================================================================================
036: // Static Methods (ordered by public, protected, <default>, private)
037: //=====================================================================================
038:
039: //=====================================================================================
040: // Instance Methods (ordered by public, protected, <default>, private)
041: //=====================================================================================
042:
043: public synchronized void init(ServletConfig config)
044: throws ServletException {
045: super .init(config);
046: SwingletManager.setDefaultRealPath(config.getServletContext()
047: .getRealPath(""));
048: SwingletManager.setDefaultImagePath("/images/");
049: }
050:
051: public synchronized void service(HttpServletRequest request,
052: HttpServletResponse response) throws IOException,
053: ServletException {
054: super .service(request, response);
055: }
056:
057: public synchronized void doPost(HttpServletRequest request,
058: HttpServletResponse response) throws IOException,
059: ServletException {
060: doGet(request, response);
061: }
062:
063: public synchronized void doGet(HttpServletRequest request,
064: HttpServletResponse response) throws IOException,
065: ServletException {
066: doGetFrame(request, response);
067: }
068:
069: private synchronized void doGetFrame(HttpServletRequest request,
070: HttpServletResponse response) throws IOException,
071: ServletException {
072: try {
073: ServletManager servletManager = ServletManager.getManager(
074: request, getServletConfig());
075:
076: if (servletManager.getValue(LEARNING_PLAN) == null) {
077: // Binds Swinglet to SwingletManager
078: SFrame defaultFrame = getFrame();
079:
080: try {
081: PrintWriter pw = new PrintWriter(
082: new FileOutputStream(
083: "C:/temp/swingletuser.txt", true));
084: pw.print(request.getRemoteHost());
085: pw.print(' ');
086: pw.print(request.getRemoteAddr());
087: pw.print(' ');
088: pw.println(new java.util.Date());
089: pw.close();
090: } catch (Exception e) {
091: System.out
092: .println("Exception occurred writing to swingletuser.txt file...");
093: e.printStackTrace();
094: response.sendError(
095: response.SC_INTERNAL_SERVER_ERROR, e
096: .getMessage());
097: }
098: }
099:
100: //System.out.println("SOURCE_COMPONENT=" + request.getParameter(SConstants.SOURCE_COMPONENT));
101: //System.out.println("SOURCE_CONTAINER=" + request.getParameter(SConstants.SOURCE_CONTAINER));
102: //System.out.println("TARGET_COMPONENT=" + request.getParameter(SConstants.TARGET_COMPONENT));
103:
104: //Get the frame and handle the response
105: SComponent component = servletManager.handle(request,
106: response, LEARNING_PLAN);
107:
108: response.setContentType(component.getContentType());
109: component.paint(ServletManager.getOutput(component,
110: response));
111: } catch (Throwable e) {
112: PrintWriter pw = new PrintWriter(new FileOutputStream(
113: "C:/temp/swinglet.txt"));
114: e.printStackTrace(pw);
115: pw.close();
116: e.printStackTrace();
117: response.sendError(response.SC_INTERNAL_SERVER_ERROR, e
118: .getMessage());
119: } finally {
120: //System.out.println("---------------------------------------------");
121: //System.out.println("== doGetFrame ==> default real path: " + SwingletManager.getDefaultRealPath());
122: }
123: }
124:
125: private SFrame getFrame() {
126: SFrame mainFrame = new SFrame(LEARNING_PLAN);
127: mainFrame.setLayoutManager(new SBorderLayout(15));
128:
129: SLabel headerLabel1 = new SLabel("My Learning");
130: headerLabel1.setFont("SansSerif", SFont.PLAIN, 24);
131: headerLabel1.setHorizontalAlignment(SConstants.CENTER);
132:
133: STable headerTable = new STable(1, 3);
134: headerTable.setSize(680, 0);
135: headerTable.setGridWidth(0);
136: headerTable.setValueAt(headerLabel1, 0, 1);
137:
138: SToolBar toolBar1 = new SToolBar();
139: toolBar1.setSize(680, 0);
140: toolBar1.setBorderPainted(false);
141: toolBar1.setBackground(PAGE_BKG_COLOR);
142: toolBar1.setMargin(new Dimension(0, 0));
143:
144: SToolBar toolBar2 = new SToolBar();
145: toolBar2.setSize(680, 0);
146: toolBar2.setBorderPainted(false);
147: toolBar2.setBackground(PAGE_BKG_COLOR);
148: toolBar2.setMargin(new Dimension(0, 0));
149:
150: SButton showAndHideButton1 = new SButton(new SIcon(
151: "icons/VCRBack.gif"));
152: showAndHideButton1.addActionListener(new ActionListener() {
153: public void actionPerformed(ActionEvent event) {
154: if (_currentCourses.isVisible()) {
155: _currentCourses.setVisible(false);
156: } else {
157: _currentCourses.setVisible(true);
158: }
159: }
160: });
161:
162: SButton showAndHideButton2 = new SButton(new SIcon(
163: "icons/VCRBack.gif"));
164: showAndHideButton2.addActionListener(new ActionListener() {
165: public void actionPerformed(ActionEvent event) {
166: if (_registeredCourses.isVisible()) {
167: _registeredCourses.setVisible(false);
168: } else {
169: _registeredCourses.setVisible(true);
170: }
171: }
172: });
173:
174: toolBar1.add(showAndHideButton1);
175: toolBar2.add(showAndHideButton2);
176:
177: _currentCourses = new CurrentCoursesForm();
178: _registeredCourses = new RegisteredCoursesForm();
179:
180: SPanel formPanel = new SPanel();
181: formPanel.setLayoutManager(new SGridLayout(0, 1));
182:
183: formPanel.add(toolBar1);
184: toolBar1.setParent(formPanel);
185:
186: formPanel.add(_currentCourses);
187: _currentCourses.setParent(formPanel);
188:
189: formPanel.add(toolBar2);
190: toolBar2.setParent(formPanel);
191:
192: formPanel.add(_registeredCourses);
193: _registeredCourses.setParent(formPanel);
194:
195: mainFrame.add(headerTable, SBorderLayout.NORTH);
196: mainFrame.add(formPanel, SBorderLayout.CENTER);
197: formPanel.setParent(mainFrame);
198:
199: return mainFrame;
200: }
201:
202: //=====================================================================================
203: // Static Inner Classes (ordered by public, protected, <default>, private)
204: //=====================================================================================
205:
206: //=====================================================================================
207: // Instance Inner Classes (ordered by public, protected, <default>, private)
208: //=====================================================================================
209:
210: //=====================================================================================
211: // main method
212: //=====================================================================================
213:
214: }
|