package pl.onet.dreamcalc.client;
import com.allen_sauer.gwt.dnd.client.DragContext;
import com.allen_sauer.gwt.dnd.client.PickupDragController;
import com.allen_sauer.gwt.dnd.client.drop.SimpleDropController;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
public class ThemeManager {
private DreamCalc calc;
private HorizontalPanel mainPanel = new HorizontalPanel();
public ThemeManager(DreamCalc calc, String[] themes) {
this.calc = calc;
Button button;
PickupDragController dragController = new PickupDragController(
RootPanel.get(), false);
// themes buttons don't disappear
dragController.setBehaviorDragProxy(true);
for (String theme : themes) {
button = new Button(theme);
mainPanel.add(button);
dragController.makeDraggable(button);
}
SimpleDropController dropController = new SimpleDropController(calc
.getMainPanel()) {
public void onDrop(DragContext context) {
super.onDrop(context);
Button b = (Button) context.draggable;
setStyle(b.getText());
}
};
dragController.registerDropController(dropController);
}
public Panel getMainPanel() {
return mainPanel;
}
private void setStyle(String styleName) {
calc.setStyle("theme-" + styleName);
}
}