/ftr-gwt-library-date/src/main/java/eu/future/earth/gwt/client/date/horizontal/HorizontalDayField.java
http://ftr-gwt-library.googlecode.com/ · Java · 263 lines · 164 code · 47 blank · 52 comment · 39 complexity · cbb315b5b68b2ff7f14ee8f0f1b20a86 MD5 · raw file
- /*
- * Copyright 2007 Future Earth, info@future-earth.eu
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
- package eu.future.earth.gwt.client.date.horizontal;
- import org.cobogw.gwt.user.client.CSS;
- import com.allen_sauer.gwt.dnd.client.util.Location;
- import com.allen_sauer.gwt.dnd.client.util.WidgetLocation;
- import com.google.gwt.user.client.ui.AbsolutePanel;
- import com.google.gwt.user.client.ui.FocusPanel;
- import com.google.gwt.user.client.ui.HorizontalPanel;
- import com.google.gwt.user.client.ui.SimplePanel;
- import com.google.gwt.user.client.ui.VerticalPanel;
- import com.google.gwt.user.client.ui.Widget;
- import eu.future.earth.gwt.client.FtrGwtDateCss;
- import eu.future.earth.gwt.client.date.EventPanel;
- public abstract class HorizontalDayField<T, M> extends EventPanel<T> {
- public static class DirectionConstant {
- public final int directionBits;
- public final String directionLetters;
- private DirectionConstant(int directionBits, String directionLetters) {
- this.directionBits = directionBits;
- this.directionLetters = directionLetters;
- }
- }
- /**
- * Specifies that resizing occur at the east edge.
- */
- public static final int DIRECTION_EAST = 0x0001;
- /**
- * Specifies that resizing occur at the both edge.
- */
- public static final int DIRECTION_NORTH = 0x0002;
- /**
- * Specifies that resizing occur at the south edge.
- */
- public static final int DIRECTION_SOUTH = 0x0004;
- /**
- * Specifies that resizing occur at the west edge.
- */
- public static final int DIRECTION_WEST = 0x0008;
- /**
- * Specifies that resizing occur at the east edge.
- */
- public static final DirectionConstant EAST = new DirectionConstant(DIRECTION_EAST, "e");
- /**
- * Specifies that resizing occur at the both edge.
- */
- public static final DirectionConstant NORTH = new DirectionConstant(DIRECTION_NORTH, "n");
- /**
- * Specifies that resizing occur at the north-east edge.
- */
- public static final DirectionConstant NORTH_EAST = new DirectionConstant(DIRECTION_NORTH | DIRECTION_EAST, "ne");
- /**
- * Specifies that resizing occur at the north-west edge.
- */
- public static final DirectionConstant NORTH_WEST = new DirectionConstant(DIRECTION_NORTH | DIRECTION_WEST, "nw");
- /**
- * Specifies that resizing occur at the south edge.
- */
- public static final DirectionConstant SOUTH = new DirectionConstant(DIRECTION_SOUTH, "s");
- /**
- * Specifies that resizing occur at the south-east edge.
- */
- public static final DirectionConstant SOUTH_EAST = new DirectionConstant(DIRECTION_SOUTH | DIRECTION_EAST, "se");
- /**
- * Specifies that resizing occur at the south-west edge.
- */
- public static final DirectionConstant SOUTH_WEST = new DirectionConstant(DIRECTION_SOUTH | DIRECTION_WEST, "sw");
- /**
- * Specifies that resizing occur at the west edge.
- */
- public static final DirectionConstant WEST = new DirectionConstant(DIRECTION_WEST, "w");
- private HorizontalItemResizeDragController<T, M> resizeDragController;
- private Widget eastWidget = null; // NOPMD;
- protected Widget dataWidget = null; // NOPMD;
- private HorizontalPanel holder = new HorizontalPanel();
- private HorizontalDateRenderer<T, M> horizontalDateRenderer = null;
- public HorizontalDayField(HorizontalDateRenderer<T, M> newRenderer, T data) {
- super(newRenderer, data);
- horizontalDateRenderer = newRenderer;
- setWidget(holder);
- holder.setSpacing(0);
- }
- private int width = 60;
- public int getWidth() {
- return width;
- }
- public void setWidth(int newWidth) {
- if (newWidth > 20) {
- width = newWidth;
- }
- holder.setWidth(width + "px");
- if (isDraggable()) {
- dataWidget.setWidth(width - 20 + "px");
- } else {
- dataWidget.setWidth(width + "px");
- }
- }
- public void setResizeDragController(HorizontalItemResizeDragController<T, M> newResizeDragController) {
- this.resizeDragController = newResizeDragController;
- if (eastWidget != null) {
- if (resizeDragController != null && isDraggable()) {
- resizeDragController.makeDraggable(eastWidget, direction);
- }
- }
- }
- private DirectionConstant direction = EAST;
- protected void setWidgetInsizeResize(Widget title, Widget newPanel) {
- SimplePanel wrap = new SimplePanel();
- wrap.setWidget(newPanel);
- wrap.setStyleName(FtrGwtDateCss.HOR_ITEM_CENTER_PANEL);
- dataWidget = wrap;
- if (super.getEventStyleName() == null) {
- holder.setStyleName(FtrGwtDateCss.HOR_ITEM_PANEL);
- } else {
- holder.setStyleName(getEventStyleName());
- }
- if (title != null) {
- holder.add(title);
- holder.setCellVerticalAlignment(title, VerticalPanel.ALIGN_TOP);
- }
- if (dataWidget != null) {
- holder.add(dataWidget);
- // holder.addStyleName(getEventStyleName());
- if (isDraggable()) {
- eastWidget = new FocusPanel();
- if (resizeDragController != null) {
- resizeDragController.makeDraggable(eastWidget, direction);
- }
- eastWidget.setSize("2px", "8px");
- eastWidget.addStyleName("eastDrag");
- holder.add(eastWidget);
- holder.setCellHorizontalAlignment(eastWidget, VerticalPanel.ALIGN_CENTER);
- holder.setCellVerticalAlignment(eastWidget, VerticalPanel.ALIGN_MIDDLE);
- }
- holder.setCellVerticalAlignment(dataWidget, VerticalPanel.ALIGN_MIDDLE);
- }
- }
- public void setEventStyleName(String newStyleName) {
- super.setEventStyleName(newStyleName);
- holder.setStyleName(getEventStyleName());
- if (dataWidget != null) {
- dataWidget.setStyleName(getEventStyleName());
- }
- if (eastWidget != null) {
- eastWidget.setStyleName(getEventStyleName());
- eastWidget.addStyleName("eastDrag");
- }
- }
- public void setBackGroundColor(String newColor) {
- CSS.setProperty(this, CSS.A.BACKGROUND_COLOR, newColor);
- CSS.setProperty(holder, CSS.A.BACKGROUND_COLOR, newColor);
- if (dataWidget != null) {
- CSS.setProperty(dataWidget, CSS.A.BACKGROUND_COLOR, newColor);
- }
- if (eastWidget != null) {
- CSS.setProperty(eastWidget, CSS.A.BACKGROUND_COLOR, newColor);
- }
- }
- public void setForeGroundColor(String newColor) {
- CSS.setProperty(this, CSS.A.COLOR, newColor);
- CSS.setProperty(holder, CSS.A.COLOR, newColor);
- if (dataWidget != null) {
- CSS.setProperty(dataWidget, CSS.A.COLOR, newColor);
- }
- if (eastWidget != null) {
- CSS.setProperty(eastWidget, CSS.A.COLOR, newColor);
- }
- }
-
- public abstract Widget getDraggableItem();
- public int getContentHeight() {
- return contentHeight;
- }
- private int contentHeight = 15;
- public void setContentHeight(int height) {
- super.setHeight(horizontalDateRenderer.getRowHeight() + "px");
- if (dataWidget != null) {
- dataWidget.setHeight((horizontalDateRenderer.getRowHeight() + 2) + "px");
- }
- contentHeight = height;
- if (dataWidget != null) {
- dataWidget.setVisible(true);
- }
- }
- public void moveBy(int right, int down) {
- final AbsolutePanel parent = getSizerPanel(this);
- final Location location = new WidgetLocation(this, parent);
- final int left = location.getLeft() + right;
- final int top = location.getTop() + down;
- parent.setWidgetPosition(this, left, top);
- }
- private AbsolutePanel getSizerPanel(Widget current) {
- Widget parent = current.getParent();
- if (parent instanceof AbsolutePanel) {
- return (AbsolutePanel) parent;
- } else {
- if (parent != null) {
- return getSizerPanel(parent);
- } else {
- return null;
- }
- }
- }
- }