1 50 51 package org.openlaszlo.iv.flash.commands; 52 53 import java.awt.geom.*; 54 import java.io.*; 55 import java.util.*; 56 import org.openlaszlo.iv.flash.api.*; 57 import org.openlaszlo.iv.flash.api.action.*; 58 import org.openlaszlo.iv.flash.api.button.*; 59 import org.openlaszlo.iv.flash.api.shape.*; 60 import org.openlaszlo.iv.flash.context.*; 61 import org.openlaszlo.iv.flash.util.*; 62 63 71 public class MultipageListCommand extends GenericCommand { 72 73 protected int textColumn,clipColumn,urlColumn,windowColumn = -1; 74 protected Script externalMediaScript,prevSymbol,homeSymbol,nextSymbol,textSymbol,templateScript = null; 75 protected String dataSource,prevSymbolName,homeSymbolName,nextSymbolName,textSymbolName,instanceName,externalMediaName; 76 77 protected void initColumnIndexes(String [][] data) { 78 textColumn = findColumn("Text",data); 79 urlColumn = findColumn("Url",data); 80 windowColumn = findColumn("Window",data); 81 if (textColumn==-1) Log.error("MultipageListCommand Error\nA text column was not specified in the data source."); 82 if (urlColumn!=-1 && windowColumn==-1) Log.warn("MultipageListCommand Warning\nA url was specified but a window column was not specified in the data source. Will end up using default window, _blank"); 83 } 84 protected void initParams(Context context) { 85 dataSource = getParameter(context,"datasource",""); 86 prevSymbolName = getParameter(context,"prevsym",""); 87 homeSymbolName = getParameter(context,"homesym",""); 88 nextSymbolName = getParameter(context,"nextsym",""); 89 textSymbolName = getParameter(context,"textsym",""); 90 instanceName = getParameter(context,"instancename",""); 91 if (dataSource.equals("")) Log.error("MultipageListCommand Error\nA data source was not specified in authoring environment."); 92 if (prevSymbolName.equals("")) Log.error("MultipageListCommand Error\nA previous symbol was not specified in authoring environment."); 93 if (homeSymbolName.equals("")) Log.error("MultipageListCommand Error\nA home symbol was not specified in authoring environment."); 94 if (nextSymbolName.equals("")) Log.error("MultipageListCommand Error\nA next symbol was not specified in authoring environment."); 95 if (textSymbolName.equals("")) Log.error("MultipageListCommand Error\nA text symbol was not specified in authoring environment."); 96 if (instanceName.equals("")) Log.error("MultipageListCommand Error\nA instance name was not specified in authoring environment."); 97 } 98 protected void initSymbols(FlashFile flashFile) { 99 prevSymbol = flashFile.getScript(prevSymbolName); 100 homeSymbol = flashFile.getScript(homeSymbolName); 101 nextSymbol = flashFile.getScript(nextSymbolName); 102 textSymbol = flashFile.getScript(textSymbolName); 103 if (prevSymbol==null) Log.error("MultipageListCommand Warning\nCould not get previous symbol script specified."); 104 if (homeSymbol==null) Log.error("MultipageListCommand Warning\nCould not get home symbol script specified."); 105 if (nextSymbol==null) Log.error("MultipageListCommand Warning\nCould not get next symbol script specified."); 106 if (textSymbol==null) Log.error("MultipageListCommand Error\nCould not get text symbol script specified."); 107 } 108 public void doCommand(FlashFile flashFile,Context context,Script parentScript, int frames) { 109 initParams(context); 110 initSymbols(flashFile); 111 String [][] data = null; 112 try { 113 UrlDataSource urlDataSource = new UrlDataSource(dataSource,flashFile); 114 data = urlDataSource.getData(); 115 } 116 catch (IVException ive) { 117 Log.error("MultipageListCommand Error\nCould not Parse the datasource into a multi-dimensional array because :\n"+ive); 118 } 119 catch (IOException ioe) { 120 Log.error("MultipageListCommand Error\nCould not Parse the datasource into a multi-dimensional array because :\n"+ioe); 121 } 122 if (data!=null) { 123 initColumnIndexes(data); 124 makeLists(flashFile,data); } else { 126 Log.error("MultipageListCommand Error\nThe datasource it empty."); 127 } 128 } 129 protected void makeLists(FlashFile flashFile,String [][] data) { 130 Instance instance = getInstance(); instance.name = instanceName; double width = instance.matrix.getScaleX()*2048; double height = instance.matrix.getScaleY()*2048; GeomHelper.deScaleMatrix(instance.matrix); Script script = instance.copyScript(); 136 Frame frame = script.getFrameAt(0); 137 frame.addStopAction(); 138 double prevHeight = prevSymbol.getBounds().getHeight(); 139 double prevWidth = prevSymbol.getBounds().getWidth(); 140 Button2 prevButton = createButton(prevSymbol); 141 prevButton.addActionCondition(onReleasePrev()); 142 double homeHeight = homeSymbol.getBounds().getHeight(); 143 double homeWidth = homeSymbol.getBounds().getWidth(); 144 Button2 homeButton = createButton(homeSymbol); 145 homeButton.addActionCondition(onReleaseHome()); 146 double nextHeight = nextSymbol.getBounds().getHeight(); 147 double nextWidth = nextSymbol.getBounds().getWidth(); 148 Button2 nextButton = createButton(nextSymbol); 149 nextButton.addActionCondition(onReleaseNext()); 150 double symbolHeight = (prevHeight > nextHeight) ? prevHeight : nextHeight; 151 double y = -height/2+symbolHeight; 152 double x = -width/2; 153 double clipHeight = 0; 154 double newPageHeight = 0; double pageHeight = height-symbolHeight; int level = 1; 157 for (int row =1;row<data.length;row++) { 158 Script clipScript = textSymbol.copyScript(); 159 Context clipContext = null; 160 try { 161 clipContext = ContextFactory.createContext(data,row); } 163 catch (IVException ive) { 164 Log.error("MultipageListCommand Error\nCould not make new button context because :\n"+ive); 165 } 166 try { 167 flashFile.processScript(clipScript,clipContext); 168 } 169 catch (IVException ive) { 170 Log.error("MultipageListCommand Error\nCould not process new button context because :\n"+ive); 171 } 172 clipHeight = clipScript.getBounds().getHeight(); newPageHeight += clipHeight; if(newPageHeight>pageHeight) { frame = script.newFrame(); frame.addStopAction(); script.removeAllInstances(frame); y = -height/2+symbolHeight; newPageHeight = clipHeight; level = 1; } 182 if (urlColumn!=-1) { 183 Button2 button2 = createButton(data,row,clipScript); 184 frame.addInstance(button2,level,AffineTransform.getTranslateInstance(x,y),null); 185 } else { 186 frame.addInstance(clipScript,level,AffineTransform.getTranslateInstance(x,y),null); 187 } 188 y += clipHeight; level++; 190 } 191 int frameCount = script.getFrameCount(); 192 if(frameCount>1) { Frame tempFrame = script.getFrameAt(1); 194 double navY = -height/2; 195 tempFrame.addInstance(prevButton,100,AffineTransform.getTranslateInstance(x,navY),null); x += prevWidth+40; tempFrame.addInstance(homeButton,101,AffineTransform.getTranslateInstance(x,navY),null); x += homeWidth+40; script.getFrameAt(0).addInstance(nextButton,102,AffineTransform.getTranslateInstance(x,navY),null); script.getFrameAt(frameCount-1).removeInstance(102); } 202 } 203 protected ActionCondition onReleasePrev() { 204 Program program = new Program(); 205 program.prevFrame(); 206 return(ActionCondition.onRelease(program)); 207 } 208 protected ActionCondition onReleaseHome() { 209 Program homeProgram = new Program(); 210 homeProgram.gotoFrame(0); 211 return(ActionCondition.onRelease(homeProgram)); 212 } 213 protected ActionCondition onReleaseNext() { 214 Program nextProgram = new Program(); 215 nextProgram.nextFrame(); 216 return(ActionCondition.onRelease(nextProgram)); 217 } 218 protected Button2 createButton(Script symbol) { 219 Button2 button2 = new Button2(); 220 int states = ButtonRecord.Up|ButtonRecord.Over|ButtonRecord.Down; button2.addButtonRecord(new ButtonRecord(states,symbol,1,AffineTransform.getTranslateInstance(0,0),CXForm.newIdentity(true))); 222 Shape shape = new Shape(); 223 shape.setBounds(symbol.getBounds()); 224 shape.setFillStyle0(FillStyle.newSolid(new Color(0,0,0))); 225 shape.drawRectangle(symbol.getBounds()); 226 button2.addButtonRecord(new ButtonRecord(ButtonRecord.HitTest,shape,2,AffineTransform.getTranslateInstance(0,0),CXForm.newIdentity(true))); 227 button2.setTrackAs(Button2.TrackAsButton); 228 return (button2); 229 } 230 protected Button2 createButton(String [][] data,int row,Script clipScript) { 231 Button2 button2 = createButton(clipScript); 232 Program program = new Program(); 233 if (windowColumn==-1) program.getURL(data[row][urlColumn],"_blank"); 234 else program.getURL(data[row][urlColumn],data[row][windowColumn]); 235 button2.addActionCondition(ActionCondition.onPress(program)); 236 return(button2); 237 } 238 } 239 | Popular Tags |