001: /*
002: * $Id: GeneralXMLListCommand.java,v 1.5 2002/07/15 22:39:32 skavish Exp $
003: *
004: * ===========================================================================
005: *
006: * The JGenerator Software License, Version 1.0
007: *
008: * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * 2. Redistributions in binary form must reproduce the above copyright
017: * notice, this list of conditions and the following disclaimer in
018: * the documentation and/or other materials provided with the
019: * distribution.
020: *
021: * 3. The end-user documentation included with the redistribution, if
022: * any, must include the following acknowlegement:
023: * "This product includes software developed by Dmitry Skavish
024: * (skavish@usa.net, http://www.flashgap.com/)."
025: * Alternately, this acknowlegement may appear in the software itself,
026: * if and wherever such third-party acknowlegements normally appear.
027: *
028: * 4. The name "The JGenerator" must not be used to endorse or promote
029: * products derived from this software without prior written permission.
030: * For written permission, please contact skavish@usa.net.
031: *
032: * 5. Products derived from this software may not be called "The JGenerator"
033: * nor may "The JGenerator" appear in their names without prior written
034: * permission of Dmitry Skavish.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: */
050:
051: /*
052: * 12/11/2001 fixed alignment problems, bounds now taken into account
053: *
054: */
055:
056: package org.openlaszlo.iv.flash.commands;
057:
058: import org.openlaszlo.iv.flash.parser.*;
059: import org.openlaszlo.iv.flash.api.*;
060: import org.openlaszlo.iv.flash.util.*;
061:
062: import org.openlaszlo.iv.flash.context.*;
063:
064: import java.io.*;
065: import java.util.*;
066: import java.awt.geom.*;
067:
068: public class GeneralXMLListCommand extends GenericXMLCommand {
069:
070: public static final int STARTX = 0; // 20
071: public static final int STARTY = 0; // 20
072:
073: protected boolean mask;
074: protected String instancename;
075: protected boolean isFixed;
076:
077: protected int orient;
078:
079: protected static final int ORIENT_HORIZ = 0;
080: protected static final int ORIENT_VERT = 1;
081: protected static final int ORIENT_TEMPORAL = 2;
082:
083: protected int order;
084:
085: protected static final int ASCENDING_ORDER = 1;
086: protected static final int DESCENDING_ORDER = -1;
087: protected static final int NO_ORDER = 0;
088:
089: protected int listSize; // in twips
090: protected int winWidth;
091: protected int winHeight;
092:
093: protected String halign;
094: protected String valign;
095: protected String itemspace;
096: protected String clip;
097: protected String sortby;
098: protected String itemname;
099:
100: protected String scrollPaneName;
101:
102: protected boolean isSetFileSize;
103: protected int fileWidthAdd;
104: protected int fileHeightAdd;
105:
106: protected void initParms(Context context) throws IVException {
107: super .initParms(context);
108:
109: mask = getBoolParameter(context, "mask", true);
110: instancename = getParameter(context, "instancename");
111:
112: // mx stuff
113: scrollPaneName = getParameter(context, "scrollpanename");
114: if (scrollPaneName != null && scrollPaneName.length() == 0)
115: scrollPaneName = null;
116:
117: String sorient = getParameter(context, "orient", "horizontal");
118:
119: if (sorient.equalsIgnoreCase("vertical")) {
120: orient = ORIENT_VERT;
121: } else if (sorient.equalsIgnoreCase("temporal")) {
122: orient = ORIENT_TEMPORAL;
123: } else // default to horizontal
124: {
125: orient = ORIENT_HORIZ;
126: }
127:
128: String spacing = getParameter(context, "spacing", "auto");
129:
130: isFixed = spacing.equalsIgnoreCase("fixed");
131:
132: String sorder = getParameter(context, "order", "none");
133:
134: if (sorder.equalsIgnoreCase("descending")) {
135: order = DESCENDING_ORDER;
136: } else if (sorder.equalsIgnoreCase("ascending")) {
137: order = ASCENDING_ORDER;
138: } else {
139: order = NO_ORDER;
140: }
141:
142: halign = getParameter(context, "halign", "'left'");
143: valign = getParameter(context, "valign", "'top'");
144: itemspace = getParameter(context, "itemspace", "0");
145: clip = getParameter(context, "clip", "name()");
146: sortby = getParameter(context, "sortby", "'none'");
147: itemname = getParameter(context, "itemname", null);
148:
149: if ((isSetFileSize = getBoolParameter(context, "setfilesize",
150: false))) {
151: fileWidthAdd = getIntParameter(context, "filewidthadd", 0) * 20;
152: fileHeightAdd = getIntParameter(context, "fileheightadd", 0) * 20;
153: }
154: }
155:
156: protected Script makeList(FlashFile file, Context context,
157: Script parent, int frameNum) throws IVException {
158: GraphContext gc = getGraphContext(file, context);
159:
160: if (gc == null) {
161: throw new IVException(Resource.NOGRAPHCONTEXT);
162: }
163:
164: List contextList = gc.getValueList(select);
165:
166: if (contextList == null) {
167: throw new IVException(Resource.NOMATCHINGCONTEXTS,
168: new Object[] { select });
169: }
170:
171: Instance mainInst = getInstance();
172: Rectangle2D winBounds = GeomHelper.getTransformedSize(
173: mainInst.matrix, GeomHelper.newRectangle(-1024, -1024,
174: 2048, 2048)); // mask of the list
175: winWidth = (int) winBounds.getWidth();
176: winHeight = (int) winBounds.getHeight();
177:
178: Script listScript = new Script(1);
179: Frame frame = listScript.newFrame();
180:
181: if (orient == ORIENT_TEMPORAL) {
182: frame.addStopAction();
183: }
184:
185: int x = STARTX, y = STARTY;
186:
187: // sort items
188:
189: if (order != NO_ORDER) {
190: contextList = GraphContext.sortValueList(contextList,
191: sortby, order == ASCENDING_ORDER);
192: }
193:
194: // process datasource
195:
196: Context myContext;
197: ListIterator iter = contextList.listIterator();
198: int i = 1;
199:
200: while (iter.hasNext()) {
201: myContext = (Context) iter.next();
202:
203: String clipName = evalStringParameter(myContext, clip, "");
204:
205: Script template = file.getScript(clipName);
206:
207: if (template == null) {
208: Log.logRB(Resource.CMDSCRIPTNOTFOUND, new Object[] {
209: clipName, getCommandName() });
210: } else {
211: Script script = template.copyScript();
212:
213: file.processScript(script, myContext);
214:
215: int delta = 0;
216:
217: if (itemspace != null) {
218: delta = getIntParameter(myContext, "itemspace", 0) * 20;
219: }
220:
221: // we will set matrix later
222: Instance scInst = frame.addInstance(script, i, null,
223: null);
224:
225: if (itemname != null) {
226: scInst.name = evalStringParameter(myContext,
227: itemname, "item" + i);
228: }
229:
230: Rectangle2D bounds = script.getBounds();
231: int myX = (int) bounds.getX();
232: int myY = (int) bounds.getY();
233: int myWidth = (int) bounds.getWidth();
234: int myHeight = (int) bounds.getHeight();
235:
236: int dx = x;
237: int dy = y;
238:
239: if (orient == ORIENT_VERT) {
240: if (!isFixed) {
241: delta += myHeight;
242: }
243: y += delta;
244: } else if (orient == ORIENT_HORIZ) {
245: if (!isFixed) {
246: delta += myWidth;
247: }
248: x += delta;
249: } else if (orient == ORIENT_TEMPORAL) {
250: frame = listScript.newFrame();
251: }
252:
253: String s_halign = getParameter(myContext, halign,
254: "left");
255: String s_valign = getParameter(myContext, valign, "top");
256:
257: // alignment
258:
259: double shiftX, shiftY;
260:
261: if (orient == ORIENT_VERT) {
262: shiftX = winWidth;
263: shiftY = myHeight;
264: } else if (orient == ORIENT_HORIZ) {
265: shiftX = myWidth;
266: shiftY = winHeight;
267: } else {
268: shiftX = 0;
269: shiftY = 0;
270: }
271:
272: if (s_halign.equalsIgnoreCase("right")) {
273: dx += shiftX;
274: } else if (s_halign.equalsIgnoreCase("center")) {
275: dx += shiftX / 2;
276: }
277:
278: if (s_valign.equalsIgnoreCase("bottom")) {
279: dy += shiftY;
280: } else if (s_valign.equalsIgnoreCase("center")) {
281: dy += shiftY / 2;
282: }
283:
284: // set matrix
285: AffineTransform matrix = AffineTransform
286: .getTranslateInstance(dx - myX, dy - myY);
287: scInst.matrix = matrix;
288: }
289:
290: i++;
291: }
292:
293: // calculate list size in twips
294:
295: if (orient == ORIENT_VERT) {
296: listSize = y - STARTY;
297: } else if (orient == ORIENT_HORIZ) {
298: listSize = x - STARTX;
299: }
300:
301: GeomHelper.deScaleMatrix(mainInst.matrix);
302: mainInst.matrix.translate(-winWidth / 2, -winHeight / 2);
303:
304: if (instancename != null) {
305: mainInst.name = instancename;
306: }
307:
308: if (isSetFileSize) {
309: int width = fileWidthAdd, height = fileHeightAdd;
310: if (orient == ORIENT_VERT) {
311: height += listSize;
312: width += winWidth;
313: } else {
314: width += listSize;
315: height += winHeight;
316: }
317: file.setFrameSize(GeomHelper.newRectangle(0, 0, width,
318: height));
319: }
320:
321: return listScript;
322: }
323:
324: protected void addMask(Script parent, int frameNum) {
325: addMask(parent, frameNum, getInstance());
326: }
327:
328: protected void addMask(Script parent, int frameNum, Instance inst) {
329: if (mask) {
330: addMask(parent, frameNum, inst, winWidth, winHeight);
331: }
332: }
333: }
|