-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogoImage.java
executable file
·121 lines (109 loc) · 3.52 KB
/
LogoImage.java
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// LogoImage.java implements a class for handling the logo to show for
// the available sensors.
//
// TBD - do away with this and just load the logo in the Sensor class?
//------------------------------------------------------------------------
import java.awt.Image;
import java.awt.MediaTracker;
import java.net.URL;
public class LogoImage
{
private imgViewer applet;
private Image[] sensorLogos;
private Image currentLogo;
private int logoLocation;
// Constructor
//------------
LogoImage(imgViewer parent)
{
applet = parent; // Save ptr to parent
Sensor[] sensors = applet.getSensors();
sensorLogos = new Image[sensors.length];
MediaTracker mt = new MediaTracker(applet);
for (int i = 0; i < sensors.length; i++)
{
// Load the logo images from the server
sensorLogos[i] = applet.getImage(applet.getCodeBase(),
"graphics/" + sensors[i].logoName);
mt.addImage(sensorLogos[i],i);
}
// wait for all the logos to load so the size of the logo will be
// known for positioning it on the display
try
{
mt.waitForAll();
}
catch (Exception e)
{
e.printStackTrace();
}
// make sure all the images loaded correctly
for (int i = 0; i < sensors.length; i++)
{
if (mt.isErrorID(i))
{
// issue an error message to the console that the image load
// failed (result will be no logo displayed)
System.out.println("Error loading graphics/"
+ sensors[i].logoName);
}
}
setSensor(applet.sensorMenu.getCurrentSensor());
}
// set the current sensor logo to display
//---------------------------------------
public void setSensor(Sensor currentSensor)
{
Sensor[] sensors = applet.getSensors();
for (int i = 0; i < sensors.length; i++)
{
if (sensors[i] == currentSensor)
{
currentLogo = sensorLogos[i];
logoLocation = sensors[i].logoLocation;
break;
}
}
}
// method to return the current logo image for display
//----------------------------------------------------
public Image getLogo()
{
return currentLogo;
}
// method to return the current logo location (LOGO_LOWER_LEFT or
// LOGO_LOWER_RIGHT)
//---------------------------------------------------------------
public int getLocation()
{
return logoLocation;
}
// method to perform the correct action when a logo is clicked on
//---------------------------------------------------------------
public void clicked()
{
try
{
URL linkURL = new URL(applet.sensorMenu.getCurrentSensor().
logoLink);
applet.getAppletContext().showDocument(linkURL,"_blank");
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
// method to cleanup any resources when the applet is stopped
//-----------------------------------------------------------
public void cleanup()
{
for (int i = 0; i < sensorLogos.length; i++)
{
if (sensorLogos[i] != null)
{
sensorLogos[i].flush();
sensorLogos[i] = null;
}
}
}
}