Package pl.onet.dreamcalc.client

Source Code of pl.onet.dreamcalc.client.ThemeManager

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);
  }
}
TOP

Related Classes of pl.onet.dreamcalc.client.ThemeManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.