KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > images > LazyDimension


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.util.images;
11
12 import org.mmbase.bridge.Node;
13 import java.util.*;
14
15 /**
16  * A 'lazy' dimension is a Dimension object which depends on an image-node and conversion
17  * template. The actual dimension will only be requested from this node, as soon as {@link
18  * #getWidth} or {@link #getHeight} are called for the first time.
19  *
20  * @author Michiel Meeuwissen
21  * @since MMBase-1.7.4
22  */

23
24
25 public class LazyDimension extends Dimension {
26
27     protected Node node;
28     protected String JavaDoc template;
29     private boolean loaded = false;
30     public LazyDimension(Node n, String JavaDoc t) {
31         node = n;
32         template = t;
33     }
34     
35     private void getDimension() {
36         if (loaded) return;
37         List args = new ArrayList();
38         if (template != null) {
39             args.add(template);
40         }
41         Dimension dim = (Dimension) node.getFunctionValue("dimension", args).get();
42         x = dim.getWidth();
43         y = dim.getHeight();
44         loaded = true;
45     }
46
47     public int getWidth() {
48         getDimension();
49         return super.getWidth();
50     }
51     public int getHeight() {
52         getDimension();
53         return super.getHeight();
54     }
55
56     public int getArea() {
57         getDimension();
58         return super.getArea();
59     }
60
61 }
62
Popular Tags