01: package org.romaframework.module.designer.view.domain.dnd.component;
02:
03: import nextapp.echo2.app.Color;
04: import nextapp.echo2.app.Grid;
05:
06: import org.romaframework.module.designer.view.domain.dnd.FieldPair;
07: import org.romaframework.module.designer.view.domain.radpage.aspect.FormAreaEditingPage;
08:
09: import echopointng.LabelEx;
10: import echopointng.TextFieldEx;
11:
12: public class GridArea extends ResizableArea {
13: private int width = 3;
14: private int height = 1;
15:
16: private static final String SECOND_DIMENSION_FIELD_TYPE = "secondDimension";
17:
18: public GridArea(FormAreaEditingPage iCaller) {
19: super (iCaller);
20: setBackground(Color.CYAN);
21: }
22:
23: protected int calculateSize(int iWidth, int iHeight) {
24: if (iWidth <= 0) {
25: iWidth = 2;
26: }
27: ((Grid) innerComponent).setSize(iWidth);
28: if (iHeight <= 0) {
29: iHeight = 1;
30: }
31: return iWidth * iHeight;
32: }
33:
34: @Override
35: public void createInnerComponent() {
36: innerComponent = new Grid(3);
37: areaSize = 3;
38: fill();
39: add(innerComponent);
40: }
41:
42: @Override
43: public void resize(int size) {
44: super .resize(size);
45: if (width > size)
46: width = size;
47: }
48:
49: @Override
50: protected String getExtraFieldLabel() {
51: // TODO Auto-generated method stub
52: return null;
53: }
54:
55: @Override
56: protected void getExtraFields() {
57: FieldPair widthField = new FieldPair();
58: widthField
59: .setFieldInput(new TextFieldEx(String.valueOf(width)));
60: widthField.setFieldLabel(new LabelEx("Area width :"));
61: fields.put(DIMENSION_FIELD_TYPE, widthField);
62: FieldPair heightField = new FieldPair();
63: heightField.setFieldInput(new TextFieldEx(String
64: .valueOf(height)));
65: heightField.setFieldLabel(new LabelEx("Area height :"));
66: fields.put(SECOND_DIMENSION_FIELD_TYPE, heightField);
67: }
68:
69: @Override
70: protected String processExtraFields() {
71: try {
72: int newWidth = Integer.parseInt(fields.get(
73: DIMENSION_FIELD_TYPE).getFieldInput().getText());
74: int newHeight = Integer.parseInt(fields.get(
75: SECOND_DIMENSION_FIELD_TYPE).getFieldInput()
76: .getText());
77: int newSize = calculateSize(newWidth, newHeight);
78: resize(newSize);
79: width = newWidth;
80: height = newHeight;
81: return null;
82: } catch (NumberFormatException nfe) {
83: return "There is one or more invalid numbers";
84: }
85: }
86:
87: @Override
88: public String getAreaType() {
89: return "grid";
90: }
91: }
|