20.08.2012 Aufrufe

8 Das SWT

8 Das SWT

8 Das SWT

MEHR ANZEIGEN
WENIGER ANZEIGEN

Erfolgreiche ePaper selbst erstellen

Machen Sie aus Ihren PDF Publikationen ein blätterbares Flipbook mit unserer einzigartigen Google optimierten e-Paper Software.

216<br />

8 <strong>Das</strong> <strong>SWT</strong><br />

public class ColorStore {<br />

}<br />

private static Map store = new HashMap();<br />

/**<br />

* Method getColor.<br />

* @param name some Color name<br />

* @param device Device instance<br />

* @param r red-value<br />

* @param g green-value<br />

* @param b blue-value<br />

* @return Color requested color<br />

*/<br />

public static Color getColor(String name,Device device,<br />

int r, int g, int b) {<br />

Object obj = store.get(name);<br />

if (obj == null) {<br />

Color newColor = new Color(device,r,g,b);<br />

store.put(name,newColor);<br />

return newColor;<br />

}<br />

return (Color) obj;<br />

}<br />

/**<br />

* Method dispose.<br />

*/<br />

public static void dispose() {<br />

Iterator iter = store.values().iterator();<br />

while (iter.hasNext()) {<br />

Color color = (Color) iter.next();<br />

color.dispose();<br />

}<br />

}<br />

Der Aufruf sieht dann z.B. so aus:<br />

Color green = ColorStore.getColor("green",display,0,255,0);<br />

Da alle Methoden der Klasse ColorStore statisch sind, kann Color-<br />

Store die Farben der gesamten Applikation verwalten. Erst wenn man<br />

keine Farben mehr braucht, entsorgt man alle Farben mit:<br />

ColorStore.dispose();<br />

In Abschnitt 9.1 werden wir einige vorgefertigte Registraturen für<br />

Schriftarten und Bilder diskutieren.

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!