forked from john-bai/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxy.java
More file actions
54 lines (47 loc) · 1.05 KB
/
Copy pathProxy.java
File metadata and controls
54 lines (47 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package designpatterns;
import java.awt.Rectangle;
/**
*
* @author jtherrell
*/
abstract class VisualObject {
protected Rectangle extent;
abstract public void draw();
abstract public Rectangle getExtent();
}
class ImageProxy extends VisualObject {
private Image image;
private String filename;
public ImageProxy(String filename) {
this.filename = filename;
extent = null;
}
public void draw(){
getImage().draw();
}
public Rectangle getExtent() {
if (extent == null)
return getImage().getExtent();
return extent;
}
public boolean isImageLoaded() {
return image != null;
}
private Image getImage() {
image = new Image(filename);
return image;
}
}
class Image extends VisualObject {
public Image(String filename) {
// Load the file here using the filename
// get the extent of the loaded image and update extent
extent = new Rectangle(0,0,100,100);
}
public void draw(){}
public Rectangle getExtent(){ return extent; }
}