PageRenderTime 2819ms CodeModel.GetById 31ms RepoModel.GetById 10ms app.codeStats 0ms

/src/org/openzoom/flash/components/MultiScaleImageBase.as

http://github.com/openzoom/sdk
ActionScript | 565 lines | 218 code | 83 blank | 264 comment | 8 complexity | 95eeaf4bb52ebb60201cd3a7b7fcf3c1 MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // OpenZoom SDK
  4. //
  5. // Version: MPL 1.1/GPL 3/LGPL 3
  6. //
  7. // The contents of this file are subject to the Mozilla Public License Version
  8. // 1.1 (the "License"); you may not use this file except in compliance with
  9. // the License. You may obtain a copy of the License at
  10. // http://www.mozilla.org/MPL/
  11. //
  12. // Software distributed under the License is distributed on an "AS IS" basis,
  13. // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. // for the specific language governing rights and limitations under the
  15. // License.
  16. //
  17. // The Original Code is the OpenZoom SDK.
  18. //
  19. // The Initial Developer of the Original Code is Daniel Gasienica.
  20. // Portions created by the Initial Developer are Copyright (c) 2007-2010
  21. // the Initial Developer. All Rights Reserved.
  22. //
  23. // Contributor(s):
  24. // Daniel Gasienica <daniel@gasienica.ch>
  25. //
  26. // Alternatively, the contents of this file may be used under the terms of
  27. // either the GNU General Public License Version 3 or later (the "GPL"), or
  28. // the GNU Lesser General Public License Version 3 or later (the "LGPL"),
  29. // in which case the provisions of the GPL or the LGPL are applicable instead
  30. // of those above. If you wish to allow use of your version of this file only
  31. // under the terms of either the GPL or the LGPL, and not to allow others to
  32. // use your version of this file under the terms of the MPL, indicate your
  33. // decision by deleting the provisions above and replace them with the notice
  34. // and other provisions required by the GPL or the LGPL. If you do not delete
  35. // the provisions above, a recipient may use your version of this file under
  36. // the terms of any one of the MPL, the GPL or the LGPL.
  37. //
  38. ////////////////////////////////////////////////////////////////////////////////
  39. package org.openzoom.flash.components
  40. {
  41. import flash.display.DisplayObject;
  42. import flash.display.Sprite;
  43. import flash.geom.Point;
  44. import flash.geom.Rectangle;
  45. import flash.ui.ContextMenu;
  46. import org.openzoom.flash.core.openzoom_internal;
  47. import org.openzoom.flash.net.ILoaderClient;
  48. import org.openzoom.flash.net.INetworkQueue;
  49. import org.openzoom.flash.utils.IDisposable;
  50. import org.openzoom.flash.viewport.INormalizedViewport;
  51. import org.openzoom.flash.viewport.IViewportConstraint;
  52. import org.openzoom.flash.viewport.IViewportTransformer;
  53. use namespace openzoom_internal;
  54. /**
  55. * @private
  56. *
  57. * Base class for MultiScaleImage and DeepZoomContainer.
  58. */
  59. internal class MultiScaleImageBase extends Sprite
  60. implements IMultiScaleContainer,
  61. ILoaderClient,
  62. IDisposable
  63. {
  64. include "../core/Version.as"
  65. //--------------------------------------------------------------------------
  66. //
  67. // Class constants
  68. //
  69. //--------------------------------------------------------------------------
  70. protected static const DEFAULT_SCENE_DIMENSION:Number = 16384 // 2^14
  71. private static const DEFAULT_VIEWPORT_WIDTH:Number = 800
  72. private static const DEFAULT_VIEWPORT_HEIGHT:Number = 600
  73. //--------------------------------------------------------------------------
  74. //
  75. // Constructor
  76. //
  77. //--------------------------------------------------------------------------
  78. /**
  79. * Constructor.
  80. */
  81. public function MultiScaleImageBase()
  82. {
  83. createChildren()
  84. }
  85. //--------------------------------------------------------------------------
  86. //
  87. // Variables
  88. //
  89. //--------------------------------------------------------------------------
  90. protected var container:MultiScaleContainer
  91. //--------------------------------------------------------------------------
  92. //
  93. // Properties: ILoaderClient
  94. //
  95. //--------------------------------------------------------------------------
  96. //----------------------------------
  97. // loader
  98. //----------------------------------
  99. public function get loader():INetworkQueue
  100. {
  101. return container ? container.loader : null
  102. }
  103. public function set loader(value:INetworkQueue):void
  104. {
  105. if (container)
  106. container.loader = value
  107. }
  108. //--------------------------------------------------------------------------
  109. //
  110. // Properties: Scene
  111. //
  112. //--------------------------------------------------------------------------
  113. //----------------------------------
  114. // sceneWidth
  115. //----------------------------------
  116. /**
  117. * @copy org.openzoom.flash.scene.IMultiScaleScene#sceneWidth
  118. */
  119. public function get sceneWidth():Number
  120. {
  121. return container ? container.scene.sceneWidth : NaN
  122. }
  123. //----------------------------------
  124. // sceneHeight
  125. //----------------------------------
  126. /**
  127. * @copy org.openzoom.flash.scene.IMultiScaleScene#sceneHeight
  128. */
  129. public function get sceneHeight():Number
  130. {
  131. return container ? container.scene.sceneHeight : NaN
  132. }
  133. //--------------------------------------------------------------------------
  134. //
  135. // Properties: Viewport
  136. //
  137. //--------------------------------------------------------------------------
  138. //----------------------------------
  139. // viewport
  140. //----------------------------------
  141. /**
  142. * Viewport of this image.
  143. */
  144. public function get viewport():INormalizedViewport
  145. {
  146. return container.viewport
  147. }
  148. //----------------------------------
  149. // transformer
  150. //----------------------------------
  151. /**
  152. * Viewport transformer. Transformers are used to create the transitions
  153. * between transformations of the viewport.
  154. *
  155. * @see org.openzoom.flash.viewport.transformers.TweenerTransformer
  156. * @see org.openzoom.flash.viewport.transformers.NullTransformer
  157. */
  158. public function get transformer():IViewportTransformer
  159. {
  160. return viewport.transformer
  161. }
  162. public function set transformer(value:IViewportTransformer):void
  163. {
  164. if (transformer !== value)
  165. viewport.transformer = value
  166. }
  167. //----------------------------------
  168. // constraint
  169. //----------------------------------
  170. /**
  171. * Viewport transformer constraint. Constraints are used to control
  172. * the positions and zoom levels the viewport can reach.
  173. *
  174. * @see org.openzoom.flash.viewport.constraints.VisibilityConstraint
  175. * @see org.openzoom.flash.viewport.constraints.ZoomConstraint
  176. * @see org.openzoom.flash.viewport.constraints.ScaleConstraint
  177. * @see org.openzoom.flash.viewport.constraints.CompositeConstraint
  178. * @see org.openzoom.flash.viewport.constraints.NullConstraint
  179. */
  180. public function get constraint():IViewportConstraint
  181. {
  182. return viewport.transformer.constraint
  183. }
  184. public function set constraint(value:IViewportConstraint):void
  185. {
  186. if (constraint !== value)
  187. viewport.transformer.constraint = value
  188. }
  189. //----------------------------------
  190. // controllers
  191. //----------------------------------
  192. /**
  193. * Controllers of type IViewportController applied to this MultiScaleImage.
  194. * For example, viewport controllers are used to navigate the MultiScaleImage
  195. * by mouse or keyboard.
  196. *
  197. * @see org.openzoom.flash.viewport.controllers.MouseController
  198. * @see org.openzoom.flash.viewport.controllers.KeyboardController
  199. * @see org.openzoom.flash.viewport.controllers.ContextMenuController
  200. */
  201. public function get controllers():Array
  202. {
  203. return container.controllers
  204. }
  205. public function set controllers(value:Array):void
  206. {
  207. container.controllers = value
  208. }
  209. //--------------------------------------------------------------------------
  210. //
  211. // Methods: Internal
  212. //
  213. //--------------------------------------------------------------------------
  214. /**
  215. * @private
  216. */
  217. private function createChildren():void
  218. {
  219. if (!container)
  220. createContainer()
  221. }
  222. /**
  223. * @private
  224. */
  225. private function createContainer():void
  226. {
  227. container = new MultiScaleContainer()
  228. super.addChild(container)
  229. }
  230. //--------------------------------------------------------------------------
  231. //
  232. // Overridden properties: DisplayObject
  233. //
  234. //--------------------------------------------------------------------------
  235. //----------------------------------
  236. // width
  237. //----------------------------------
  238. override public function get width():Number
  239. {
  240. return container.width
  241. }
  242. override public function set width(value:Number):void
  243. {
  244. setActualSize(value, height)
  245. }
  246. //----------------------------------
  247. // height
  248. //----------------------------------
  249. override public function get height():Number
  250. {
  251. return container.height
  252. }
  253. override public function set height(value:Number):void
  254. {
  255. setActualSize(width, value)
  256. }
  257. //----------------------------------
  258. // contextMenu
  259. //----------------------------------
  260. //
  261. // override public function get contextMenu():NativeMenu
  262. // {
  263. // return container.contextMenu
  264. // }
  265. //
  266. // override public function set contextMenu(value:NativeMenu):void
  267. // {
  268. // container.contextMenu = value
  269. // }
  270. //--------------------------------------------------------------------------
  271. //
  272. // Methods
  273. //
  274. //--------------------------------------------------------------------------
  275. /**
  276. * @private
  277. */
  278. public function setActualSize(width:Number, height:Number):void
  279. {
  280. if (this.width == width && this.height == height)
  281. return
  282. container.setActualSize(width, height)
  283. }
  284. //--------------------------------------------------------------------------
  285. //
  286. // Properties: IMultiScaleImage
  287. //
  288. //--------------------------------------------------------------------------
  289. //----------------------------------
  290. // zoom
  291. //----------------------------------
  292. /**
  293. * @copy org.openzoom.flash.viewport.IViewport#zoom
  294. */
  295. public function get zoom():Number
  296. {
  297. return viewport.zoom
  298. }
  299. public function set zoom(value:Number):void
  300. {
  301. viewport.zoom = value
  302. }
  303. //----------------------------------
  304. // scale
  305. //----------------------------------
  306. /**
  307. * @copy org.openzoom.flash.viewport.IViewport#scale
  308. */
  309. public function get scale():Number
  310. {
  311. return viewport.scale
  312. }
  313. public function set scale(value:Number):void
  314. {
  315. viewport.scale = value
  316. }
  317. //----------------------------------
  318. // viewportX
  319. //----------------------------------
  320. /**
  321. * @copy org.openzoom.flash.viewport.IViewport#x
  322. */
  323. public function get viewportX():Number
  324. {
  325. return viewport.x
  326. }
  327. public function set viewportX(value:Number):void
  328. {
  329. viewport.x = value
  330. }
  331. //----------------------------------
  332. // viewportY
  333. //----------------------------------
  334. /**
  335. * @copy org.openzoom.flash.viewport.IViewport#y
  336. */
  337. public function get viewportY():Number
  338. {
  339. return viewport.y
  340. }
  341. public function set viewportY(value:Number):void
  342. {
  343. viewport.y = value
  344. }
  345. //----------------------------------
  346. // viewportWidth
  347. //----------------------------------
  348. /**
  349. * @copy org.openzoom.flash.viewport.IViewport#width
  350. */
  351. public function get viewportWidth():Number
  352. {
  353. return viewport.width
  354. }
  355. public function set viewportWidth(value:Number):void
  356. {
  357. viewport.width = value
  358. }
  359. //----------------------------------
  360. // viewportHeight
  361. //----------------------------------
  362. /**
  363. * @copy org.openzoom.flash.viewport.IViewport#height
  364. */
  365. public function get viewportHeight():Number
  366. {
  367. return viewport.height
  368. }
  369. public function set viewportHeight(value:Number):void
  370. {
  371. viewport.height = value
  372. }
  373. //--------------------------------------------------------------------------
  374. //
  375. // Methods: IMultiScaleImage
  376. //
  377. //--------------------------------------------------------------------------
  378. /**
  379. * @copy org.openzoom.flash.viewport.IViewport#zoomTo()
  380. */
  381. public function zoomTo(zoom:Number,
  382. transformX:Number=0.5,
  383. transformY:Number=0.5,
  384. immediately:Boolean=false):void
  385. {
  386. viewport.zoomTo(zoom, transformX, transformY, immediately)
  387. }
  388. /**
  389. * @copy org.openzoom.flash.viewport.IViewport#zoomBy()
  390. */
  391. public function zoomBy(factor:Number,
  392. transformX:Number=0.5,
  393. transformY:Number=0.5,
  394. immediately:Boolean=false):void
  395. {
  396. viewport.zoomBy(factor, transformX, transformY, immediately)
  397. }
  398. /**
  399. * @copy org.openzoom.flash.viewport.IViewport#panTo()
  400. */
  401. public function panTo(x:Number, y:Number,
  402. immediately:Boolean=false):void
  403. {
  404. viewport.panTo(x, y, immediately)
  405. }
  406. /**
  407. * @copy org.openzoom.flash.viewport.IViewport#panBy()
  408. */
  409. public function panBy(deltaX:Number, deltaY:Number,
  410. immediately:Boolean=false):void
  411. {
  412. viewport.panBy(deltaX, deltaY, immediately)
  413. }
  414. /**
  415. * @copy org.openzoom.flash.viewport.IViewport#fitToBounds()
  416. */
  417. public function fitToBounds(bounds:Rectangle,
  418. scale:Number=1.0,
  419. immediately:Boolean=false):void
  420. {
  421. viewport.fitToBounds(bounds, scale, immediately)
  422. }
  423. /**
  424. * @copy org.openzoom.flash.viewport.IViewport#showAll()
  425. */
  426. public function showAll(immediately:Boolean=false):void
  427. {
  428. viewport.showAll(immediately)
  429. }
  430. /**
  431. * @copy org.openzoom.flash.viewport.IViewport#localToScene()
  432. */
  433. public function localToScene(point:Point):Point
  434. {
  435. return viewport.localToScene(point)
  436. }
  437. /**
  438. * @copy org.openzoom.flash.viewport.IViewport#sceneToLocal()
  439. */
  440. public function sceneToLocal(point:Point):Point
  441. {
  442. return viewport.sceneToLocal(point)
  443. }
  444. //--------------------------------------------------------------------------
  445. //
  446. // Overridden methods: UIComponent
  447. //
  448. //--------------------------------------------------------------------------
  449. /**
  450. * @inheritDoc
  451. */
  452. override public function addChild(child:DisplayObject):DisplayObject
  453. {
  454. return container.addChild(child)
  455. }
  456. /**
  457. * @inheritDoc
  458. */
  459. override public function removeChild(child:DisplayObject):DisplayObject
  460. {
  461. return container.removeChild(child)
  462. }
  463. /**
  464. * @inheritDoc
  465. */
  466. override public function get numChildren():int
  467. {
  468. return container ? container.numChildren : 0
  469. }
  470. //--------------------------------------------------------------------------
  471. //
  472. // Methods: IDisposable
  473. //
  474. //--------------------------------------------------------------------------
  475. public function dispose():void
  476. {
  477. container.dispose()
  478. container = null
  479. loader = null
  480. }
  481. }
  482. }