1 50 51 55 56 package org.openlaszlo.iv.flash.commands; 57 58 import org.openlaszlo.iv.flash.parser.*; 59 import org.openlaszlo.iv.flash.api.*; 60 import org.openlaszlo.iv.flash.util.*; 61 62 import org.openlaszlo.iv.flash.context.*; 63 64 import java.io.*; 65 import java.util.*; 66 import java.awt.geom.*; 67 68 public class GeneralXMLListCommand extends GenericXMLCommand { 69 70 public static final int STARTX = 0; public static final int STARTY = 0; 73 protected boolean mask; 74 protected String instancename; 75 protected boolean isFixed; 76 77 protected int orient; 78 79 protected static final int ORIENT_HORIZ = 0; 80 protected static final int ORIENT_VERT = 1; 81 protected static final int ORIENT_TEMPORAL = 2; 82 83 protected int order; 84 85 protected static final int ASCENDING_ORDER = 1; 86 protected static final int DESCENDING_ORDER = -1; 87 protected static final int NO_ORDER = 0; 88 89 protected int listSize; protected int winWidth; 91 protected int winHeight; 92 93 protected String halign; 94 protected String valign; 95 protected String itemspace; 96 protected String clip; 97 protected String sortby; 98 protected String itemname; 99 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 { 108 super.initParms( context ); 109 110 mask = getBoolParameter( context, "mask", true ); 111 instancename = getParameter( context, "instancename" ); 112 113 scrollPaneName = getParameter( context, "scrollpanename" ); 115 if( scrollPaneName != null && scrollPaneName.length() == 0 ) scrollPaneName = null; 116 117 String sorient = getParameter( context, "orient", "horizontal" ); 118 119 if ( sorient.equalsIgnoreCase( "vertical" ) ) 120 { 121 orient = ORIENT_VERT; 122 } 123 else if ( sorient.equalsIgnoreCase( "temporal" ) ) 124 { 125 orient = ORIENT_TEMPORAL; 126 } 127 else { 129 orient = ORIENT_HORIZ; 130 } 131 132 String spacing = getParameter( context, "spacing", "auto" ); 133 134 isFixed = spacing.equalsIgnoreCase("fixed"); 135 136 String sorder = getParameter( context, "order", "none" ); 137 138 if ( sorder.equalsIgnoreCase("descending") ) 139 { 140 order = DESCENDING_ORDER; 141 } 142 else if ( sorder.equalsIgnoreCase("ascending") ) 143 { 144 order = ASCENDING_ORDER; 145 } 146 else 147 { 148 order = NO_ORDER; 149 } 150 151 halign = getParameter( context, "halign", "'left'" ); 152 valign = getParameter( context, "valign", "'top'" ); 153 itemspace = getParameter( context, "itemspace", "0" ); 154 clip = getParameter( context, "clip", "name()" ); 155 sortby = getParameter( context, "sortby", "'none'" ); 156 itemname = getParameter( context, "itemname", null ); 157 158 if( (isSetFileSize=getBoolParameter(context, "setfilesize", false)) ) { 159 fileWidthAdd = getIntParameter(context, "filewidthadd", 0)*20; 160 fileHeightAdd = getIntParameter(context, "fileheightadd", 0)*20; 161 } 162 } 163 164 protected Script makeList( FlashFile file, Context context, Script parent, int frameNum ) throws IVException 165 { 166 GraphContext gc = getGraphContext( file, context ); 167 168 if ( gc == null ) 169 { 170 throw new IVException( Resource.NOGRAPHCONTEXT ); 171 } 172 173 List contextList = gc.getValueList( select ); 174 175 if ( contextList == null ) 176 { 177 throw new IVException( Resource.NOMATCHINGCONTEXTS, new Object [] {select} ); 178 } 179 180 Instance mainInst = getInstance(); 181 Rectangle2D winBounds = GeomHelper.getTransformedSize( mainInst.matrix, 182 GeomHelper.newRectangle(-1024, -1024, 2048, 2048) ); winWidth = (int) winBounds.getWidth(); 184 winHeight = (int) winBounds.getHeight(); 185 186 Script listScript = new Script(1); 187 Frame frame = listScript.newFrame(); 188 189 if ( orient == ORIENT_TEMPORAL ) 190 { 191 frame.addStopAction(); 192 } 193 194 int x = STARTX, y = STARTY; 195 196 198 if ( order != NO_ORDER ) 199 { 200 contextList = GraphContext.sortValueList( contextList, sortby, order == ASCENDING_ORDER ); 201 } 202 203 205 Context myContext; 206 ListIterator iter = contextList.listIterator(); 207 int i = 1; 208 209 while( iter.hasNext() ) 210 { 211 myContext = ( Context ) iter.next(); 212 213 String clipName = evalStringParameter( myContext, clip, "" ); 214 215 Script template = file.getScript( clipName ); 216 217 if( template == null ) 218 { 219 Log.logRB( Resource.CMDSCRIPTNOTFOUND, new Object [] {clipName, getCommandName()} ); 220 } 221 else 222 { 223 Script script = template.copyScript(); 224 225 file.processScript( script, myContext ); 226 227 int delta = 0; 228 229 if( itemspace != null ) 230 { 231 delta = getIntParameter( myContext, "itemspace", 0 ) * 20; 232 } 233 234 Instance scInst = frame.addInstance( script, i, null, null ); 236 237 if( itemname != null ) 238 { 239 scInst.name = evalStringParameter( myContext, itemname, "item"+i ); 240 } 241 242 Rectangle2D bounds = script.getBounds(); 243 int myX = (int) bounds.getX(); 244 int myY = (int) bounds.getY(); 245 int myWidth = (int) bounds.getWidth(); 246 int myHeight = (int) bounds.getHeight(); 247 248 int dx = x; 249 int dy = y; 250 251 if ( orient == ORIENT_VERT ) 252 { 253 if ( ! isFixed ) { delta += myHeight; } 254 y += delta; 255 } 256 else if ( orient == ORIENT_HORIZ ) 257 { 258 if ( ! isFixed ) { delta += myWidth; } 259 x += delta; 260 } 261 else if ( orient == ORIENT_TEMPORAL ) 262 { 263 frame = listScript.newFrame(); 264 } 265 266 String s_halign = getParameter( myContext, halign, "left" ); 267 String s_valign = getParameter( myContext, valign, "top" ); 268 269 271 double shiftX, shiftY; 272 273 if ( orient == ORIENT_VERT ) 274 { 275 shiftX = winWidth; 276 shiftY = myHeight; 277 } 278 else if ( orient == ORIENT_HORIZ ) 279 { 280 shiftX = myWidth; 281 shiftY = winHeight; 282 } 283 else 284 { 285 shiftX = 0; 286 shiftY = 0; 287 } 288 289 if ( s_halign.equalsIgnoreCase( "right" ) ) 290 { 291 dx += shiftX; 292 } 293 else if ( s_halign.equalsIgnoreCase("center") ) 294 { 295 dx += shiftX / 2; 296 } 297 298 if ( s_valign.equalsIgnoreCase("bottom") ) 299 { 300 dy += shiftY; 301 } 302 else if ( s_valign.equalsIgnoreCase("center") ) 303 { 304 dy += shiftY / 2; 305 } 306 307 AffineTransform matrix = AffineTransform.getTranslateInstance(dx-myX,dy-myY); 309 scInst.matrix = matrix; 310 } 311 312 i++; 313 } 314 315 317 if( orient == ORIENT_VERT ) 318 { 319 listSize = y - STARTY; 320 } 321 else if ( orient == ORIENT_HORIZ ) 322 { 323 listSize = x - STARTX; 324 } 325 326 GeomHelper.deScaleMatrix( mainInst.matrix ); 327 mainInst.matrix.translate( -winWidth/2, -winHeight/2 ); 328 329 if ( instancename != null ) 330 { 331 mainInst.name = instancename; 332 } 333 334 if( isSetFileSize ) { 335 int width = fileWidthAdd, height = fileHeightAdd; 336 if( orient == ORIENT_VERT ) { 337 height += listSize; 338 width += winWidth; 339 } else { 340 width += listSize; 341 height += winHeight; 342 } 343 file.setFrameSize(GeomHelper.newRectangle(0, 0, width, height)); 344 } 345 346 return listScript; 347 } 348 349 protected void addMask( Script parent, int frameNum ) { 350 addMask(parent, frameNum, getInstance()); 351 } 352 353 protected void addMask( Script parent, int frameNum, Instance inst ) { 354 if( mask ) { 355 addMask(parent, frameNum, inst, winWidth, winHeight); 356 } 357 } 358 } 359 | Popular Tags |