001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.codegen.builder.properties;
020:
021: import javax.swing.JScrollPane;
022:
023: import com.jeta.forms.gui.beans.JETAPropertyDescriptor;
024: import com.jeta.forms.store.properties.ScrollBarsProperty;
025: import com.jeta.swingbuilder.codegen.builder.BasicExpression;
026: import com.jeta.swingbuilder.codegen.builder.BeanWriter;
027: import com.jeta.swingbuilder.codegen.builder.DeclarationManager;
028: import com.jeta.swingbuilder.codegen.builder.LocalVariableDeclaration;
029: import com.jeta.swingbuilder.codegen.builder.MethodStatement;
030: import com.jeta.swingbuilder.codegen.builder.PropertyWriter;
031:
032: public class ScrollPaneWriter implements PropertyWriter {
033: /**
034: * PropertyWriter implementation
035: */
036: public void writeProperty(DeclarationManager declMgr,
037: BeanWriter writer, JETAPropertyDescriptor pd, Object value) {
038: try {
039: if (value instanceof ScrollBarsProperty) {
040: ScrollBarsProperty sbp = (ScrollBarsProperty) value;
041: if (sbp.isScrollable()) {
042: LocalVariableDeclaration ds = new LocalVariableDeclaration(
043: declMgr, javax.swing.JScrollPane.class);
044: writer.addStatement(ds);
045:
046: MethodStatement ss = new MethodStatement(ds
047: .getVariable(), "setViewportView");
048: ss.addParameter(new BasicExpression(writer
049: .getBeanVariable()));
050: writer.addStatement(ss);
051:
052: ss = new MethodStatement(ds.getVariable(),
053: "setVerticalScrollBarPolicy");
054: ss.addParameter(new BasicExpression(
055: getVerticalScrollBarPolicyString(sbp
056: .getVerticalScrollBarPolicy())));
057: writer.addStatement(ss);
058:
059: ss = new MethodStatement(ds.getVariable(),
060: "setHorizontalScrollBarPolicy");
061: ss.addParameter(new BasicExpression(
062: getHorizontalScrollBarPolicyString(sbp
063: .getHorizontalScrollBarPolicy())));
064: writer.addStatement(ss);
065:
066: writer.setResultVariable(ds.getVariable(),
067: javax.swing.JScrollPane.class);
068: }
069: }
070: } catch (Exception e) {
071: e.printStackTrace();
072: }
073: }
074:
075: private String getHorizontalScrollBarPolicyString(int policy) {
076: switch (policy) {
077: case JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED:
078: return "JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED";
079:
080: case JScrollPane.HORIZONTAL_SCROLLBAR_NEVER:
081: return "JScrollPane.HORIZONTAL_SCROLLBAR_NEVER";
082:
083: case JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS:
084: return "JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS";
085:
086: default:
087: return "JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED";
088: }
089: }
090:
091: private String getVerticalScrollBarPolicyString(int policy) {
092: switch (policy) {
093: case JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED:
094: return "JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED";
095:
096: case JScrollPane.VERTICAL_SCROLLBAR_NEVER:
097: return "JScrollPane.VERTICAL_SCROLLBAR_NEVER";
098:
099: case JScrollPane.VERTICAL_SCROLLBAR_ALWAYS:
100: return "JScrollPane.VERTICAL_SCROLLBAR_ALWAYS";
101:
102: default:
103: return "JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED";
104: }
105: }
106:
107: }
|