1 50 51 55 56 package org.openlaszlo.iv.flash.commands; 57 58 import java.io.*; 59 import java.awt.geom.*; 60 61 import org.openlaszlo.iv.flash.parser.*; 62 import org.openlaszlo.iv.flash.api.*; 63 import org.openlaszlo.iv.flash.util.*; 64 65 import org.openlaszlo.iv.flash.context.Context; 66 67 public class GeneralListCommand extends GenericCommand { 68 69 protected String datasource; 70 protected String halign; 71 protected String valign; 72 protected boolean mask; 73 protected int itemspace; 74 protected String instancename; 75 protected boolean isVertical; 76 protected boolean isFixed; 77 78 protected int listSize; protected int winWidth; 80 protected int winHeight; 81 82 protected boolean isSetFileSize; 83 protected int fileWidthAdd; 84 protected int fileHeightAdd; 85 86 protected String scrollPaneName; 87 88 protected void initParms( Context context ) throws IVException { 89 datasource = getParameter( context, "datasource", "" ); 90 halign = getParameter( context, "halign" ); 91 valign = getParameter( context, "valign" ); 92 mask = getBoolParameter( context, "mask", true ); 93 itemspace = getIntParameter( context, "itemspace", 0 ) * 20; 94 instancename = getParameter( context, "instancename" ); 95 96 scrollPaneName = getParameter( context, "scrollpanename" ); 98 if( scrollPaneName != null && scrollPaneName.length() == 0 ) scrollPaneName = null; 99 100 String orient = getParameter( context, "orient", "horizontal" ); 101 String spacing = getParameter( context, "spacing", "auto" ); 102 isVertical = orient.equalsIgnoreCase("vertical"); 103 isFixed = spacing.equalsIgnoreCase("fixed"); 104 105 if( (isSetFileSize=getBoolParameter(context, "setfilesize", false)) ) { 106 fileWidthAdd = getIntParameter(context, "filewidthadd", 0)*20; 107 fileHeightAdd = getIntParameter(context, "fileheightadd", 0)*20; 108 } 109 } 110 111 protected Script makeList( FlashFile file, Context context, Script parent, int frameNum ) throws IVException { 112 String [][] data; 113 try { 114 UrlDataSource ds = new UrlDataSource(datasource,file); 115 data = ds.getData(); 116 } catch( IOException e ) { 117 throw new IVException(Resource.ERRDATAREAD, new Object [] {datasource, getCommandName()}, e); 118 } 119 120 if( data.length < 1 ) { 121 throw new IVException(Resource.INVALDATASOURCE, new Object [] {datasource, getCommandName()}); 122 } 123 124 Instance mainInst = getInstance(); 125 Rectangle2D winBounds = GeomHelper.getTransformedSize( mainInst.matrix, 126 GeomHelper.newRectangle(-1024, -1024, 2048, 2048) ); winWidth = (int) winBounds.getWidth(); 128 winHeight = (int) winBounds.getHeight(); 129 130 int clipIdx = findColumn( "clip", data ); 131 int spaceIdx = findColumn( "space", data ); 132 int instancenameIdx = findColumn( "instancename", data ); 133 if( clipIdx == -1 ) { 134 throw new IVException(Resource.COLNOTFOUNDCMD, new Object [] {getCommandName(), "Clip", datasource}); 135 } 136 137 Script listScript = new Script(1); 138 Frame frame = listScript.newFrame(); 139 int x = 0, y = 0; 140 141 for( int row=1; row<data.length; row++ ) { 143 Context myContext = makeContext( context, data, row ); 144 String clipName = data[row][clipIdx]; 145 Script template = file.getScript(clipName); 146 if( template == null ) { 147 Log.logRB( Resource.CMDSCRIPTNOTFOUND, new Object [] {clipName, "List"} ); 148 } else { 149 Script myScript = template.copyScript(); 150 file.processScript( myScript, myContext ); 151 152 int delta = 0; 153 if( spaceIdx != -1 ) { 154 delta = Util.toInt( data[row][spaceIdx], 0 ) * 20; 155 } 156 Instance scInst = frame.addInstance(myScript, row, null, null); 157 if( instancenameIdx != -1 ) { 158 scInst.name = data[row][instancenameIdx]; 159 } 160 161 Rectangle2D bounds = myScript.getBounds(); 162 int myX = 0; int myY = 0; int myWidth = (int) bounds.getWidth(); 166 int myHeight = (int) bounds.getHeight(); 167 168 int dx = x; 169 int dy = y; 170 171 if( isVertical ) { 173 if( !isFixed ) { 174 delta += myHeight; 175 } 176 delta += itemspace; 177 y += delta; 178 } else { 179 if( !isFixed ) { 180 delta += myWidth; 181 } 182 delta += itemspace; 183 x += delta; 184 } 185 186 double shiftX, shiftY; 188 if( isVertical ) { 189 shiftX = winWidth; 190 shiftY = myHeight; 191 } else { 192 shiftX = myWidth; 193 shiftY = winHeight; 194 } 195 if( halign.equalsIgnoreCase("right") ) { 196 dx += shiftX; 197 } else if( halign.equalsIgnoreCase("center") ) { 198 dx += shiftX/2; 199 } 200 201 if( valign.equalsIgnoreCase("bottom") ) { 202 dy += shiftY; 203 } else if( valign.equalsIgnoreCase("center") ) { 204 dy += shiftY/2; 205 } 206 207 AffineTransform matrix = AffineTransform.getTranslateInstance(dx-myX,dy-myY); 209 scInst.matrix = matrix; 210 } 211 } 212 213 if( isVertical ) { 215 listSize = y; 216 } else { 217 listSize = x; 218 } 219 220 GeomHelper.deScaleMatrix( mainInst.matrix ); 221 mainInst.matrix.translate( -winWidth/2, -winHeight/2 ); 222 223 if( instancename != null ) { 224 mainInst.name = instancename; 225 } 226 227 if( isSetFileSize ) { 228 int width = fileWidthAdd, height = fileHeightAdd; 229 if( isVertical ) { 230 height += listSize; 231 width += winWidth; 232 } else { 233 width += listSize; 234 height += winHeight; 235 } 236 width = ((width + 19)/20)*20; 237 height = ((height + 19)/20)*20; 238 file.setFrameSize(GeomHelper.newRectangle(0, 0, width, height)); 239 } 240 241 return listScript; 242 } 243 244 protected void addMask( Script parent, int frameNum ) { 245 addMask(parent, frameNum, getInstance()); 246 } 247 248 protected void addMask( Script parent, int frameNum, Instance inst ) { 249 if( mask ) { 250 addMask(parent, frameNum, inst, winWidth, winHeight); 251 } 252 } 253 254 } 255 | Popular Tags |