001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.examples.swinglets;
006:
007: import java.util.*;
008: import java.io.*;
009: import java.awt.*;
010: import java.awt.event.*;
011:
012: import javax.servlet.*;
013: import javax.servlet.http.*;
014:
015: import com.javelin.swinglets.*;
016: import com.javelin.swinglets.table.*;
017: import com.javelin.swinglets.border.*;
018:
019: import javax.swing.*;
020:
021: import com.javelin.swinglets.event.*;
022:
023: /**
024: * Form Panel for changing funds.
025: *
026: * @author Robin Sharp
027: */
028:
029: public class DemoFunds extends SForm implements FormListener {
030: public DemoFunds() {
031: setMethod(SForm.POST);
032:
033: //BODY TABLE
034: setLayoutManager(new SGridLayout(6, 1));
035:
036: SLabel headerLabel1 = new SLabel(
037: "Instruction to change investment funds");
038:
039: headerLabel1.setLink(new SLink()).addActionListener(
040: new ActionListener() {
041: public void actionPerformed(ActionEvent event) {
042: System.out.println("Instructions");
043: }
044: });
045:
046: SMatteBorder mb = new SMatteBorder(2, 2, 2, 1, SColor
047: .getColor("seagreen4"));
048: headerLabel1.setBorder(mb);
049:
050: headerLabel1.setFont("SansSerif", SFont.PLAIN, 24);
051: headerLabel1.setForeground(blue);
052: headerLabel1.setHorizontalAlignment(SConstants.CENTER);
053: headerLabel1.setSize(300, 0);
054:
055: SLabel headerLabel2 = new SLabel(
056: "These instructions to changes investment funds will "
057: + "take effect from 4:00pm GMT. ");
058:
059: headerLabel2.setFont("SansSerif", SFont.PLAIN, 12);
060: headerLabel2.setForeground(green);
061: headerLabel2.setHorizontalAlignment(SConstants.CENTER);
062: headerLabel2.setSize(100, 0);
063:
064: //FORM TABLE
065: STable formTable = new STable(3, 4);
066: formTable.setGridWidth(0);
067: formTable.setValueAt(new SLabel("Title").setForeground(blue),
068: 0, 0);
069: titleField.setToolTipText("Please select your title");
070: titleField.addItem("Mr");
071: titleField.addItem("Mrs");
072: titleField.addItem("Miss");
073: titleField.addItem("Ms");
074: formTable.setValueAt(titleField, 0, 1);
075:
076: formTable.setValueAt(new SLabel("Surname").setForeground(blue),
077: 0, 2);
078: formTable.setValueAt(surnameField, 0, 3);
079:
080: formTable.setValueAt(
081: new SLabel("Forename").setForeground(blue), 1, 0);
082: formTable.setValueAt(forenameField, 1, 1);
083: formTable.setValueAt(new SCheckBox("Life Style."), 1, 2);
084: formTable.setValueAt(membershipField.setToolTipText(
085: "Member Number").setToolTipText(
086: "This is a member number"), 1, 3);
087:
088: formTable.setValueAt(new SLabel(
089: "Enter the fund percentages to a total of 100%.")
090: .setFont("Arial,Helvetica", SFont.BOLD, 14)
091: .setForeground(SColor.black), 2, 0);
092: formTable.setCellSpanAt(new Dimension(2, 1), 2, 0);
093: formTable.setHorizontalAlignmentAt(SConstants.CENTER, 2, 0);
094:
095: //FUNDS
096: STable fundsTable = new STable(fundNames.length / 2, 6);
097:
098: SBorder[] borders = new SBorder[] { new SBevelBorder(2, true),
099: new SEmptyBorder(), new SBevelBorder(),
100: new SEmptyBorder() };
101: fundsTable.setBorder(new SCompoundBorder(borders));
102: fundsTable.setGridWidth(0);
103: for (int fund = 0, row = 0; fund < fundNames.length; fund += 2, row++) {
104: fundsTable.setValueAt(new SLabel(fundNames[fund])
105: .setForeground(green), row, 0);
106: fundsTable.setValueAt(funds[fund] = new STextField()
107: .setColumns(3).setMaxLength(4), row, 1);
108: fundsTable.setValueAt("%", row, 2);
109: fundsTable.setValueAt(new SLabel(fundNames[fund + 1])
110: .setForeground(green), row, 3);
111: fundsTable.setValueAt(funds[fund + 1] = new STextField()
112: .setColumns(3).setMaxLength(4), row, 4);
113: fundsTable.setValueAt("%", row, 5);
114: }
115:
116: STable buttonTable = (STable) new STable(2, 2).setGridWidth(0)
117: .setSize(300, 35);
118: buttonTable.setValueAt(totalLabel, 0, 0);
119: buttonTable.setValueAt(totalAmount, 0, 1);
120:
121: cancelButton = (SButton) new SButton("CANCEL")
122: .setToolTipText("Click here to cancel");
123: okButton = (SButton) new SButton("OK")
124: .setToolTipText("Click here to submit");
125:
126: buttonTable.setValueAt(cancelButton, 1, 0);
127: buttonTable.setValueAt(okButton, 1, 1);
128:
129: add(headerLabel1);
130: add(headerLabel2);
131: add(new SCharacter(SCharacter.PARAGRAPH));
132: add(formTable);
133: add(fundsTable);
134: add(buttonTable);
135:
136: addFormEventListener(this );
137:
138: }
139:
140: public void formSubmitted(FormEvent formEvent) {
141: if (formEvent.getParameter(okButton.getName()) != null) {
142: int total = 0;
143: int value = 0;
144: for (int index = 0; index < fundNames.length; index++) {
145: if (funds[index].getText() != null
146: && funds[index].getText().length() > 0) {
147: try {
148: total += Integer.parseInt(funds[index]
149: .getText());
150: fundValues[index] = funds[index].getText();
151: } catch (Exception e) {
152: funds[index].setText(null);
153: fundValues[index] = null;
154: }
155: }
156: }
157:
158: totalAmount.setText("" + total + "%");
159:
160: if (total == 100) {
161: totalLabel.setForeground(SColor.black);
162: totalLabel.setText("TOTAL ");
163: } else if (total < 100) {
164: totalLabel.setForeground(red);
165: totalLabel.setText("TOTAL TOO LOW ");
166: } else if (total > 100) {
167: totalLabel.setForeground(red);
168: totalLabel.setText("TOTAL TOO HIGH ");
169: }
170:
171: } else if (formEvent.getParameter(cancelButton.getName()) != null) {
172: for (int index = 0; index < fundNames.length; index++) {
173: funds[index].setText(fundValues[index]);
174: }
175: }
176:
177: }
178:
179: private static SColor blue = new SColor(0, 0, 100);
180: private static SColor green = new SColor(0, 100, 0);
181: private static SColor red = new SColor(100, 0, 0);
182:
183: private SComboBox titleField = new SComboBox();
184: private STextField surnameField = new STextField();
185: private STextField forenameField = new STextField();
186: private STextField membershipField = new STextField();
187:
188: private SButton cancelButton;
189: private SButton okButton;
190:
191: private String[] fundNames = new String[] { "Tracker", "Far East",
192: "Managed", "European", "Stock Exchange", "Fixed interest",
193: "International", "Property", "Equity", "Cash",
194: "North American", "Inflation" };
195:
196: private STextField funds[] = new STextField[fundNames.length];
197: private String[] fundValues = new String[fundNames.length];
198:
199: private SLabel totalLabel = (SLabel) new SLabel("TOTAL ").setFont(
200: "Arial,Helvetica", SFont.BOLD, 14);
201: private SLabel totalAmount = (SLabel) new SLabel().setFont(
202: "Arial,Helvetica", SFont.BOLD, 14);
203:
204: }
|