@@ -0,0 +1,2157 @@
+package de.toman.milight;%0A%0Aimport java.awt.Color;%0A%0Aimport de.toman.milight.events.ChangeBrightnessEvent;%0Aimport de.toman.milight.events.ChangeColorEvent;%0Aimport de.toman.milight.events.LightEvent;%0Aimport de.toman.milight.events.LightListener;%0A%0Apublic class LightObserver %7B%0A%09private Lights lights;%0A%0A%09private LightState currentState;%0A%0A%09private static final MilightColor INITIAL_COLOR = new MilightColor(%0A%09%09%09Color.WHITE);%0A%09private static final float INITIAL_BRIGHTNESS = 1f;%0A%09private static final boolean INITIAL_WHITE_MODE = true;%0A%0A%09public LightObserver(Lights lights) %7B%0A%09%09// call super constructor%0A%09%09super();%0A%0A%09%09// set attributes%0A%09%09this.lights = lights;%0A%09%09currentState = new LightState(INITIAL_COLOR, INITIAL_BRIGHTNESS,%0A%09%09%09%09INITIAL_WHITE_MODE);%0A%0A%09%09// add as listener%0A%09%09lights.addLightListener(new LightListener() %7B%0A%09%09%09public void lightsChanged(LightEvent event) %7B%0A%09%09%09%09// ChangeColorEvent%0A%09%09%09%09switch (event.getClass().getSimpleName()) %7B%0A%09%09%09%09case %22ChangeColorEvent%22:%0A%09%09%09%09%09setCurrentState(new LightState(((ChangeColorEvent) event)%0A%09%09%09%09%09%09%09.getColor(), currentState.getBrightness(),%0A%09%09%09%09%09%09%09currentState.isWhiteMode()));%0A%09%09%09%09%09break;%0A%09%09%09%09// ChangeBrightnessEvent%0A%09%09%09%09case %22ChangeBrightnessEvent%22:%0A%09%09%09%09%09setCurrentState(new LightState(currentState.getColor(),%0A%09%09%09%09%09%09%09((ChangeBrightnessEvent) event).getBrightness(),%0A%09%09%09%09%09%09%09currentState.isWhiteMode()));%0A%09%09%09%09%09break;%0A%09%09%09%09// TODO brightness should be handled different for white/colored%0A%09%09%09%09// mode%0A%09%09%09%09// ColoredModeEvent%0A%09%09%09%09case %22ColoredModeEvent%22:%0A%09%09%09%09%09setCurrentState(new LightState(currentState.getColor(),%0A%09%09%09%09%09%09%09currentState.getBrightness(), false));%0A%09%09%09%09%09break;%0A%09%09%09%09// WhiteModeEvent%0A%09%09%09%09case %22WhiteModeEvent%22:%0A%09%09%09%09%09setCurrentState(new LightState(currentState.getColor(),%0A%09%09%09%09%09%09%09currentState.getBrightness(), true));%0A%09%09%09%09%09break;%0A%09%09%09%09%7D%0A%0A%09%09%09%7D%0A%09%09%7D);%0A%09%7D%0A%0A%09/**%0A%09 * @return the currentState%0A%09 */%0A%09public LightState getCurrentState() %7B%0A%09%09return currentState;%0A%09%7D%0A%0A%09/**%0A%09 * @param currentState%0A%09 *            the currentState to set%0A%09 */%0A%09private void setCurrentState(LightState currentState) %7B%0A%09%09this.currentState = currentState;%0A%09%7D%0A%0A%09/**%0A%09 * @return the lights%0A%09 */%0A%09public Lights getLights() %7B%0A%09%09return lights;%0A%09%7D%0A%7D%0A

add LightOberver storing the lights' current state