001: // package
002: package com.javelin.examples.swinglets;
003:
004: // import
005: import com.javelin.swinglets.*;
006: import com.javelin.swinglets.border.*;
007: import com.javelin.swinglets.event.*;
008: import com.javelin.swinglets.table.*;
009:
010: import java.awt.*;
011: import java.awt.event.*;
012: import java.io.*;
013: import java.util.*;
014:
015: import javax.servlet.*;
016: import javax.servlet.http.*;
017: import javax.swing.*;
018:
019: public class CurrentCoursesForm extends SForm {
020:
021: //=====================================================================================
022: // Static Variables (ordered by public, protected, <default>, private)
023: //=====================================================================================
024:
025: //=====================================================================================
026: // Instance Variables (ordered by public, protected, <default>, private)
027: //=====================================================================================
028:
029: private ArrayList _goButtons;
030: private ArrayList _courses;
031: private ArrayList _actionBoxes;
032:
033: private String[] _courseActions = { "Register Course",
034: "Drop Course", "Course Information" };
035:
036: //=====================================================================================
037: // Static Methods (ordered by public, protected, <default>, private)
038: //=====================================================================================
039:
040: //=====================================================================================
041: // Instance Methods (ordered by public, protected, <default>, private)
042: //=====================================================================================
043:
044: public CurrentCoursesForm() {
045: setMethod(SForm.POST);
046: setLayoutManager(new SBorderLayout(15));
047:
048: SFrame currentCoursesFrame = new SFrame();
049: currentCoursesFrame.setLayoutManager(new SBorderLayout(5));
050:
051: SPanel findCoursesPanel = new SPanel();
052: findCoursesPanel.setLayoutManager(new SFlowLayout(
053: SConstants.RIGHT));
054:
055: SLabel findCoursesLabel = new SLabel("Find Courses", new SLink(
056: ExploreCoursesPlaceHolder.EXPLORE_COURSES));
057:
058: findCoursesPanel.add(findCoursesLabel);
059:
060: currentCoursesFrame.add(findCoursesPanel, SBorderLayout.NORTH);
061: currentCoursesFrame.add(createCourseTable(),
062: SBorderLayout.CENTER);
063:
064: add(currentCoursesFrame, SBorderLayout.CENTER);
065:
066: addFormEventListener(new CourseListener());
067: }
068:
069: private STable createCourseTable() {
070: int headerRow = 0;
071: int numCols = 3;
072: int courseNameCol = 0;
073: int courseActionCol = 1;
074: int goButtonCol = 2;
075:
076: String[] courses = { "LIT201 Eng. Lit 201",
077: "PHI283 Philosophy and Christian Thought, IWU",
078: "ART121 Drawing 1 First, DMU" };
079:
080: STable courseTable = new STable((courses.length + 1), numCols); // "+ 1" allows for header row
081: courseTable.setGridWidth(0);
082: courseTable.setBackground(SColor.getColor("white"));
083: courseTable.setIntercellSpacing(new Dimension(0, 0));
084:
085: // Header Row...
086: SLabel courseHeader = new SLabel("Courses");
087: SLabel actionHeader = new SLabel("Action");
088: SLabel holder = new SLabel(" ");
089:
090: courseTable.setValueAt(courseHeader, headerRow, courseNameCol);
091: courseTable
092: .setValueAt(actionHeader, headerRow, courseActionCol);
093: courseTable.setValueAt(holder, headerRow, goButtonCol);
094:
095: SColor headerBkgColor = SColor.getColor("gray");
096: setCellBackground(headerBkgColor, courseTable, courseHeader,
097: headerRow, courseNameCol);
098: setCellBackground(headerBkgColor, courseTable, actionHeader,
099: headerRow, courseActionCol);
100: setCellBackground(headerBkgColor, courseTable, holder,
101: headerRow, goButtonCol);
102:
103: // Course Rows...
104: SLabel courseLabel = null;
105: SComboBox actionBox = null;
106: SButton goButton = null;
107: int headerRowOffset = 1;
108: _goButtons = new ArrayList();
109: _courses = new ArrayList();
110: _actionBoxes = new ArrayList();
111:
112: for (int index = 0; index < courses.length; index++) {
113: courseLabel = new SLabel(courses[index]);
114: courseLabel.setSize(500, 0);
115: courseLabel.setFont("SansSerif", SFont.PLAIN, 10);
116: actionBox = new SComboBox(_courseActions);
117: goButton = new SButton("Go");
118:
119: _actionBoxes.add(actionBox);
120: _goButtons.add(goButton);
121: _courses.add(courses[index]);
122:
123: courseTable.setValueAt(courseLabel,
124: (index + headerRowOffset), courseNameCol);
125: courseTable.setValueAt(actionBox,
126: (index + headerRowOffset), courseActionCol);
127: courseTable.setValueAt(goButton, (index + headerRowOffset),
128: goButtonCol);
129:
130: System.out.println("GO BUTTON ADDED ");
131: //goButton.setParent( this );
132: }
133:
134: return courseTable;
135: }
136:
137: private void setCellBackground(SColor color, STable table,
138: Object cellValue, int cellRow, int cellColumn) {
139: STableCellRenderer renderer = table.getTableCellRenderer();
140: SComponent rendererComponent = renderer
141: .getTableCellRendererComponent(table, cellValue,
142: cellRow, cellColumn);
143:
144: rendererComponent.setBackground(color);
145: }
146:
147: //=====================================================================================
148: // Static Inner Classes (ordered by public, protected, <default>, private)
149: //=====================================================================================
150:
151: //=====================================================================================
152: // Instance Inner Classes (ordered by public, protected, <default>, private)
153: //=====================================================================================
154:
155: private class CourseListener implements FormListener {
156: public void formSubmitted(FormEvent formEvent) {
157: for (int index = 0; index < _goButtons.size(); index++) {
158: if (formEvent.getParameter(((SButton) _goButtons
159: .get(index)).getName()) != null) {
160: SComboBox actionBox = (SComboBox) _actionBoxes
161: .get(index);
162:
163: System.out
164: .println("= CurrentCoursesForm.formSubmitted => course: "
165: + _courses.get(index)
166: + " action: "
167: + actionBox.getSelectedItem());
168: break;
169: }
170: }
171: }
172: }
173:
174: //=====================================================================================
175: // main method
176: //=====================================================================================
177:
178: }
|