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 RegisteredCoursesForm 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 = { "Drop Course",
034: "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 RegisteredCoursesForm() {
045: setMethod(SForm.POST);
046: setLayoutManager(new SBorderLayout(15));
047:
048: SFrame registeredCoursesFrame = new SFrame();
049: registeredCoursesFrame.setLayoutManager(new SBorderLayout(5));
050:
051: registeredCoursesFrame.add(createCourseTable(),
052: SBorderLayout.CENTER);
053:
054: add(registeredCoursesFrame, SBorderLayout.CENTER);
055:
056: addFormEventListener(new CourseListener());
057: }
058:
059: private STable createCourseTable() {
060: int headerRow = 0;
061: int numCols = 3;
062: int courseNameCol = 0;
063: int courseActionCol = 1;
064: int goButtonCol = 2;
065:
066: String[] courses = { "ENG101 English 101",
067: "REL221 Ancient Religions, IWU" };
068:
069: STable courseTable = new STable((courses.length + 1), numCols); // "+ 1" allows for header row
070: courseTable.setGridWidth(0);
071: courseTable.setBackground(SColor.getColor("white"));
072: courseTable.setIntercellSpacing(new Dimension(0, 0));
073:
074: // Header Row...
075: SLabel courseHeader = new SLabel("Courses");
076: SLabel actionHeader = new SLabel("Action");
077: SLabel holder = new SLabel(" ");
078:
079: courseTable.setValueAt(courseHeader, headerRow, courseNameCol);
080: courseTable
081: .setValueAt(actionHeader, headerRow, courseActionCol);
082: courseTable.setValueAt(holder, headerRow, goButtonCol);
083:
084: SColor headerBkgColor = SColor.getColor("gray");
085: setCellBackground(headerBkgColor, courseTable, courseHeader,
086: headerRow, courseNameCol);
087: setCellBackground(headerBkgColor, courseTable, actionHeader,
088: headerRow, courseActionCol);
089: setCellBackground(headerBkgColor, courseTable, holder,
090: headerRow, goButtonCol);
091:
092: // Course Rows...
093: SLabel courseLabel = null;
094: SComboBox actionBox = null;
095: SButton goButton = null;
096: int headerRowOffset = 1;
097: _goButtons = new ArrayList();
098: _courses = new ArrayList();
099: _actionBoxes = new ArrayList();
100:
101: for (int index = 0; index < courses.length; index++) {
102: courseLabel = new SLabel(courses[index]);
103: courseLabel.setFont("SansSerif", SFont.PLAIN, 10);
104: courseLabel.setSize(500, 0);
105: actionBox = new SComboBox(_courseActions);
106: goButton = new SButton("Go");
107:
108: _actionBoxes.add(actionBox);
109: _goButtons.add(goButton);
110: _courses.add(courses[index]);
111:
112: courseTable.setValueAt(courseLabel,
113: (index + headerRowOffset), courseNameCol);
114: courseTable.setValueAt(actionBox,
115: (index + headerRowOffset), courseActionCol);
116: courseTable.setValueAt(goButton, (index + headerRowOffset),
117: goButtonCol);
118: }
119:
120: return courseTable;
121: }
122:
123: private void setCellBackground(SColor color, STable table,
124: Object cellValue, int cellRow, int cellColumn) {
125: STableCellRenderer renderer = table.getTableCellRenderer();
126: SComponent rendererComponent = renderer
127: .getTableCellRendererComponent(table, cellValue,
128: cellRow, cellColumn);
129:
130: rendererComponent.setBackground(color);
131: }
132:
133: //=====================================================================================
134: // Static Inner Classes (ordered by public, protected, <default>, private)
135: //=====================================================================================
136:
137: //=====================================================================================
138: // Instance Inner Classes (ordered by public, protected, <default>, private)
139: //=====================================================================================
140:
141: private class CourseListener implements FormListener {
142: public void formSubmitted(FormEvent formEvent) {
143: for (int index = 0; index < _goButtons.size(); index++) {
144: if (formEvent.getParameter(((SButton) _goButtons
145: .get(index)).getName()) != null) {
146: SComboBox actionBox = (SComboBox) _actionBoxes
147: .get(index);
148:
149: System.out
150: .println("= RegisteredCoursesForm.formSubmitted => course: "
151: + _courses.get(index)
152: + " action: "
153: + actionBox.getSelectedItem());
154: break;
155: }
156: }
157: }
158: }
159:
160: //=====================================================================================
161: // main method
162: //=====================================================================================
163:
164: }
|