Example usage for com.google.gwt.user.client.ui AbsolutePanel add

List of usage examples for com.google.gwt.user.client.ui AbsolutePanel add

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui AbsolutePanel add.

Prototype

public void add(IsWidget w, int left, int top) 

Source Link

Document

Overloaded version for IsWidget.

Usage

From source file:ca.upei.ic.timetable.client.CalendarPanel.java

License:Apache License

/**
 * This method must be called after all settings done.
 *///from ww w.j a v a  2 s.c o m
void init() {

    calendarInnerHeight_ = Calendar.RESOLUTION * 14 * 4;
    calendarInnerWidth_ = width_ - 17;

    // create the horizontalPanel
    panel_ = GWT.create(HorizontalPanel.class);

    // add panels
    for (int i = 0; i < 7; i++) {
        panel_.add((Widget) GWT.create(AbsolutePanel.class));
    }

    // create the scroll panel
    outerPanel_ = GWT.create(ScrollPanel.class);

    // create the absolute wrapper
    AbsolutePanel wrapper = GWT.create(AbsolutePanel.class);
    wrapper.setPixelSize(calendarInnerWidth_, calendarInnerHeight_);

    // set the calendar width and height
    panel_.setPixelSize(calendarInnerWidth_ - calendarLeftDescriptionWidth_, calendarInnerHeight_);

    // add the sub panel and set size
    outerPanel_.add(wrapper);
    outerPanel_.setPixelSize(width_, height_);

    // deal with type
    switch (calendar_.getType()) {
    case Calendar.FIVE:
        panel_.getWidget(0).setSize("0px", "0px");

        courseWidth_ = (calendarInnerWidth_ - calendarLeftDescriptionWidth_) / 5; // minus
        // the
        // scroll
        // bar
        // width
        for (int i = 1; i < 6; i++) {
            panel_.getWidget(i).setPixelSize(courseWidth_, calendarInnerHeight_);
        }
        panel_.getWidget(6).setSize("0px", "0px");

        break;
    case Calendar.SEVEN:
        courseWidth_ = (calendarInnerWidth_ - calendarLeftDescriptionWidth_) / 7;
        for (int i = 0; i < 7; i++) {
            panel_.getWidget(i).setPixelSize(courseWidth_, calendarInnerHeight_);
        }
        break;
    default:
        throw new IllegalArgumentException("Calendar type is invalid.");
    }

    // add to observer list
    calendar_.addObserver("itemDidAdd", this);
    calendar_.addObserver("itemDidRemove", this);

    // create the grid
    HorizontalPanel grid = new HorizontalPanel();
    grid.setPixelSize(calendarInnerWidth_ - calendarLeftDescriptionWidth_, calendarInnerHeight_);
    grid.addStyleName("grid");

    // FIXME tricky part, needs to change
    for (int i = 0; i < 5; i++) {
        VerticalPanel gridColumn = GWT.create(VerticalPanel.class);
        gridColumn.addStyleName("gridColumn");
        gridColumn.setHeight(Integer.toString(calendarInnerHeight_) + "px");
        gridColumn.setWidth(Integer.toString(courseWidth_ - 1) + "px");

        for (int j = 0; j < 14 * 60 / Calendar.RESOLUTION / 2; j++) {
            SimplePanel cell = GWT.create(SimplePanel.class);
            cell.addStyleName("gridCell");
            cell.setHeight(Integer.toString(Calendar.RESOLUTION * 2 - 1) + "px");
            cell.setWidth(Integer.toString(courseWidth_ - 1) + "px");

            final int day = i;
            final int hour = j;

            gridColumn.add(PanelUtils.focusPanel(cell, new ClickListener() {

                public void onClick(Widget sender) {
                    if (cellClickListener_ != null) {
                        Map<String, Integer> params = new HashMap<String, Integer>();
                        params.put("day", day);
                        params.put("hour", hour);
                        cellClickListener_.setContext(params);
                        cellClickListener_.onClick(sender);
                    }
                }

            }, null, null, null));
        }
        grid.add(gridColumn);
    }

    // create the with description panel
    HorizontalPanel panelWithDescription = GWT.create(HorizontalPanel.class);
    VerticalPanel leftDescription = GWT.create(VerticalPanel.class);
    leftDescription.setPixelSize(calendarLeftDescriptionWidth_, calendarInnerHeight_);
    leftDescription.addStyleName("timeColumn");
    // first row
    SimplePanel firstTimeCell = GWT.create(SimplePanel.class);
    firstTimeCell.addStyleName("timeCell");
    firstTimeCell.setPixelSize(calendarLeftDescriptionWidth_ - 1, Calendar.RESOLUTION);
    leftDescription.add(firstTimeCell);

    for (int i = 0; i < 14 * 60 / Calendar.RESOLUTION / 2; i++) {
        SimplePanel cell = GWT.create(SimplePanel.class);
        cell.addStyleName("timeCell");
        cell.setPixelSize(calendarLeftDescriptionWidth_ - 1, Calendar.RESOLUTION * 2);

        String half;

        if (i % 2 == 0) {
            half = "30";
        } else {
            half = "00";
        }

        // half time adjustment
        int tp = i / 2 + 8;
        tp = tp + i % 2;

        String ampm = "am";

        if (tp >= 12) {
            ampm = "pm";
        }
        if (tp > 12) {
            tp -= 12;
        }

        cell.add(new HTML(Integer.toString(tp) + ":" + half + ampm + "&nbsp;"));

        leftDescription.add(cell);
    }

    panelWithDescription.add(leftDescription);
    panelWithDescription.add(panel_);

    // add the elements
    wrapper.add(grid, calendarLeftDescriptionWidth_, 0);
    wrapper.add(panelWithDescription, 0, 0);

    initWidget(outerPanel_);

    // set the style primary name
    outerPanel_.setStylePrimaryName("wi-CalendarPanel");
    // create the map
    itemWidgets_ = new HashMap<CalendarItem, Set<Widget>>();
}

From source file:ca.upei.ic.timetable.client.CalendarPanel.java

License:Apache License

protected void itemDidAdd(Calendar calendar, CalendarItem item) {
    // create the widget pool
    if (!itemWidgets_.containsKey(item)) {
        itemWidgets_.put(item, new HashSet<Widget>());
    }/*  w w  w .  ja  v  a2 s.c o m*/

    // iterate all entries in the item
    for (Map.Entry<Integer, Day> entry : item.getDays().entrySet()) {
        int day = entry.getKey();
        // get the parent panel
        AbsolutePanel parent = (AbsolutePanel) panel_.getWidget(day);

        // build the widgets
        Set<TimeInterval> intervals = entry.getValue().getTimeIntervals();
        // iterate all time intervals of a day.
        for (TimeInterval ti : intervals) {
            // create the widget
            SimplePanel widget = GWT.create(SimplePanel.class);

            HTML html = new HTML("<h3>" + item.getTitle() + "</h3><p>" + item.getContent() + "</p>");
            widget.setWidget(html);

            // set the style
            widget.setStylePrimaryName("wi-CalendarPanel");
            widget.addStyleDependentName("selectedCourse");

            int begin = 0;
            if (ti.begin() < 480 / Calendar.RESOLUTION) { // if it's an
                // afternoon
                // course
                begin = ti.begin() + 240 / Calendar.RESOLUTION;
            } else { // no it's a morning course.
                begin = ti.begin() - 480 / Calendar.RESOLUTION;
            }

            int end;
            if ((ti.end() <= 540 / Calendar.RESOLUTION) || (begin >= 600 / Calendar.RESOLUTION)) { // it it ends
                // before
                // 930 or
                // begin at
                // 600pm
                end = ti.end() + 240 / Calendar.RESOLUTION;
            } else {
                end = ti.end() - 480 / Calendar.RESOLUTION;
            }
            // set the size
            int height = (end - begin) * Calendar.RESOLUTION;
            widget.setPixelSize(courseWidth_ - 2, height - 2); // minus the
            // border
            // width

            parent.add(widget, 0, begin * Calendar.RESOLUTION);

            // add to widget pool
            itemWidgets_.get(item).add(widget);
        }
    }

    // reorganize all panels
    for (int i = 0; i < panel_.getWidgetCount(); i++) {
        AbsolutePanel panel = (AbsolutePanel) panel_.getWidget(i);
        reorganizePanel(panel);
    }
}

From source file:cc.kune.initials.ImagesHelper.java

License:GNU Affero Public License

public static IsWidget cropResize(final Image image, final int fullSize, final int newWidth,
        final int newHeight) {
    final AbsolutePanel panel = new AbsolutePanel();
    image.setSize(fullSize + "px", fullSize + "px");
    panel.add(image, -(fullSize - newWidth) / 4, -(fullSize - newHeight) / 4);
    panel.setPixelSize(newWidth, newHeight);
    return panel;
}

From source file:cl.uai.client.marks.Mark.java

License:Open Source License

public static void showIcons(Mark mark, int mouseLeft) {
    // Gets the absolute panel which contains the mark to calculate its coordinates
    AbsolutePanel abspanel = (AbsolutePanel) mark.getParent();

    int topdiff = -Mark.editIcon.getOffsetHeight();

    // Calculates basic left, top position for icons
    int top = mark.getAbsoluteTop() - abspanel.getAbsoluteTop() + (topdiff);
    int left = mouseLeft > 0 && mark instanceof HighlightMark ? mouseLeft : mark.getAbsoluteLeft();

    if (top < 0) {
        top += mark.getOffsetHeight();//from www. j  a va2  s .c  o  m
    }
    // Check if icons and popup are already added in the panel, if not adds them
    if (abspanel.getWidgetIndex(Mark.editIcon) < 0)
        abspanel.add(Mark.editIcon, left, top);

    if (abspanel.getWidgetIndex(Mark.deleteIcon) < 0)
        abspanel.add(Mark.deleteIcon, left, top);

    if (abspanel.getWidgetIndex(Mark.regradeIcon) < 0)
        abspanel.add(Mark.regradeIcon, left, top);

    if (abspanel.getWidgetIndex(Mark.minimizeIcon) < 0)
        abspanel.add(Mark.minimizeIcon, left, top);

    if (abspanel.getWidgetIndex(Mark.markPopup) < 0)
        abspanel.add(Mark.markPopup, left, top);

    // Make sure no other icons are left
    Mark.hideIcons();

    // If we are in grading mode, show delete and edit icons
    if (!EMarkingConfiguration.isReadonly()) {

        // Edit icon is only for comments and rubrics
        abspanel.setWidgetPosition(Mark.editIcon, left, top);
        Mark.editIcon.setVisible(true);
        Mark.editIcon.setMark(mark);
        left += Mark.editIcon.getOffsetWidth() + 5;
        top -= 1;

        // Delete icon
        abspanel.setWidgetPosition(Mark.deleteIcon, left, top);
        Mark.deleteIcon.setVisible(true);
        Mark.deleteIcon.setMark(mark);
    }

    // If the user owns the submission and the dates are ok we show the regrade icon
    if (EMarkingConfiguration.isOwnDraft() && MarkingInterface.submissionData.isRegradingAllowed()
            && !EMarkingConfiguration.isFormativeFeedbackOnly()) {
        // Edit icon is only for comments and rubrics
        if (mark instanceof RubricMark) {
            abspanel.setWidgetPosition(Mark.regradeIcon, left, top);
            Mark.regradeIcon.setVisible(true);
            Mark.regradeIcon.setMark(mark);
        }
    }

    // Highlight the rubric interface if the mark is a RubricMark
    if (EMarkingConfiguration.getRubricMarkType() != EMarkingConfiguration.EMARKING_RUBRICMARK_TEXTBOX) {
        Mark.markPopup.setHTML(mark.getMarkPopupHTML());
        Mark.markPopup.setVisible(true);
        top += 50;
        abspanel.setWidgetPosition(Mark.markPopup, left, top);
        EMarkingWeb.reloadMathJax();
    }
}

From source file:cl.uai.client.marks.RubricMark.java

License:Open Source License

public void addCollaborativesButtons() {

    if (collaborativeMarks == null)
        return;//from  ww  w  .j a  va 2  s  .  c om

    AbsolutePanel abspanel = (AbsolutePanel) this.getParent();
    int top = this.getAbsoluteTop();
    int left = this.getAbsoluteLeft();

    abspanel.add(collaborativeMarks, top, left);

    updatePositionCollaborativeButtons();
}

From source file:com.allen_sauer.gwt.dnd.client.PickupDragController.java

License:Apache License

@Override
public void dragStart() {
    super.dragStart();

    lastResetCacheTimeMillis = System.currentTimeMillis();
    WidgetLocation currentDraggableLocation = new WidgetLocation(context.draggable, context.boundaryPanel);
    if (getBehaviorDragProxy()) {
        movablePanel = newDragProxy(context);
        context.boundaryPanel.add(movablePanel, currentDraggableLocation.getLeft(),
                currentDraggableLocation.getTop());
        checkGWTIssue1813(movablePanel, context.boundaryPanel);
    } else {/*  w ww  .j  a  v a  2 s. c  om*/
        saveSelectedWidgetsLocationAndStyle();
        AbsolutePanel container = new AbsolutePanel();
        container.getElement().getStyle().setProperty("overflow", "visible");

        container.setPixelSize(context.draggable.getOffsetWidth(), context.draggable.getOffsetHeight());
        context.boundaryPanel.add(container, currentDraggableLocation.getLeft(),
                currentDraggableLocation.getTop());
        checkGWTIssue1813(container, context.boundaryPanel);

        int draggableAbsoluteLeft = context.draggable.getAbsoluteLeft();
        int draggableAbsoluteTop = context.draggable.getAbsoluteTop();
        HashMap<Widget, CoordinateLocation> widgetLocation = new HashMap<Widget, CoordinateLocation>();
        for (Widget widget : context.selectedWidgets) {
            widgetLocation.put(widget,
                    new CoordinateLocation(widget.getAbsoluteLeft(), widget.getAbsoluteTop()));
        }

        context.dropController = getIntersectDropController(context.mouseX, context.mouseY);
        if (context.dropController != null) {
            context.dropController.onEnter(context);
        }

        for (Widget widget : context.selectedWidgets) {
            Location location = widgetLocation.get(widget);
            int relativeX = location.getLeft() - draggableAbsoluteLeft;
            int relativeY = location.getTop() - draggableAbsoluteTop;
            container.add(widget, relativeX, relativeY);
        }
        movablePanel = container;
    }
    movablePanel.addStyleName(DragClientBundle.INSTANCE.css().movablePanel());
    calcBoundaryOffset();
    dropTargetClientWidth = DOMUtil.getClientWidth(boundaryPanel.getElement());
    dropTargetClientHeight = DOMUtil.getClientHeight(boundaryPanel.getElement());
}

From source file:com.allen_sauer.gwt.dnd.client.PickupDragController.java

License:Apache License

/**
 * Called by {@link PickupDragController#dragStart()} to allow subclasses to provide their own
 * drag proxies.//from  w w  w.  j av a 2  s. co m
 *
 * @param context the current drag context
 * @return a new drag proxy
 */
protected Widget newDragProxy(DragContext context) {
    AbsolutePanel container = new AbsolutePanel();
    container.getElement().getStyle().setProperty("overflow", "visible");

    WidgetArea draggableArea = new WidgetArea(context.draggable, null);
    for (Widget widget : context.selectedWidgets) {
        WidgetArea widgetArea = new WidgetArea(widget, null);
        Widget proxy = new SimplePanel();
        proxy.setPixelSize(widget.getOffsetWidth(), widget.getOffsetHeight());
        proxy.addStyleName(DragClientBundle.INSTANCE.css().proxy());
        container.add(proxy, widgetArea.getLeft() - draggableArea.getLeft(),
                widgetArea.getTop() - draggableArea.getTop());
    }

    return container;
}

From source file:com.allen_sauer.gwt.dnd.demo.client.DragDropDemo.java

License:Apache License

private void onModuleLoad2() {
    RootPanel mainPanel = RootPanel.get(DEMO_MAIN_PANEL);
    DOM.setInnerHTML(mainPanel.getElement(), "");

    // create the main common boundary panel to which drag operations will be restricted
    AbsolutePanel boundaryPanel = new AbsolutePanel();
    boundaryPanel.addStyleName(CSS_DEMO_MAIN_BOUNDARY_PANEL);
    boundaryPanel.setPixelSize(900, 600);

    // instantiate the common drag controller used the less specific examples
    dragController = new PickupDragController(boundaryPanel, true);
    dragController.setBehaviorMultipleSelection(false);

    mainPanel.add(new HTML(
            "<div style='font-weight: bold; font-size: 1.2em;'><a href='https://github.com/fredsa/gwt-dnd'>gwt-dnd</a>"
                    + " - Drag-and-Drop for your Google Web Toolkit projects.</div>"
                    + "<div style='font-style: italic; margin-bottom: 1em;'>by Fred Sauer</div>"));

    // Umbrella example illustrating basic drag and drop behavior
    HTML boundaryDescription = ExampleTabPanel.describe(
            new Class[] { DragDropDemo.class, PickupDragController.class, BoundaryDropController.class, },
            "Most of the example drag operations are constrained to the panel below."
                    + " Try to drag one of the widgets outside the area below.");
    boundaryDescription.addStyleName(CSS_DEMO_BOUNDARY);
    mainPanel.add(boundaryDescription);/*from   w ww  .j  av a 2 s. c  o  m*/
    mainPanel.add(boundaryPanel);

    // Add configuration panel for main drag controller
    VerticalPanel configurationPanel = new VerticalPanel();
    configurationPanel.setWidth("200px");
    configurationPanel.add(new MultipleSelectionBehaviorPanel(dragController));
    configurationPanel.add(new DragStartSensitivityBehaviorPanel(dragController));
    configurationPanel.add(new DragProxyBehaviorPanel(dragController));
    configurationPanel.add(new ConstrainedToBoundaryBehaviorPanel(dragController));
    configurationPanel.add(new BidiBehaviorPanel(dragController));
    boundaryPanel.add(configurationPanel, 10, 0);

    // Create some draggable widgets to play with
    boundaryPanel.add(createDraggable(), 20, 530);
    boundaryPanel.add(createDraggable(), 60, 510);
    boundaryPanel.add(createDraggable(), 100, 520);
    boundaryPanel.add(createDraggable(), 140, 530);

    // TabPanel to hold our examples
    final ExampleTabPanel examples = new ExampleTabPanel(7);
    examples.setWidth("650px");
    boundaryPanel.add(examples, 220, 10);

    // text area to log drag events as they are triggered
    final HTML eventTextArea = new HTML();
    eventTextArea.addStyleName(CSS_DEMO_EVENT_TEXT_AREA);
    eventTextArea.setSize(boundaryPanel.getOffsetWidth() + "px", "10em");

    // instantiate shared drag handler to listen for events
    final DemoDragHandler demoDragHandler = new DemoDragHandler(eventTextArea);
    dragController.addDragHandler(demoDragHandler);

    Button clearButton = new Button("clear");
    clearButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            demoDragHandler.clear();
        }
    });
    mainPanel.add(new HTML("<br>Events received by registered <code>DragHandler</code>s"));
    mainPanel.add(clearButton);
    mainPanel.add(eventTextArea);

    // add our individual examples
    examples.add(new BinExample(dragController));
    examples.add(new AbsolutePositionExample(dragController));
    examples.add(new GridConstrainedExample(dragController));
    examples.add(new FlowPanelExample(dragController));

    examples.add(new InsertPanelExample(demoDragHandler));
    examples.add(new FlexTableRowExample(demoDragHandler));
    examples.add(new WindowExample(demoDragHandler));
    examples.add(new DragHandleExample(demoDragHandler));

    examples.add(new DualListExample(demoDragHandler));
    examples.add(new PuzzleExample(demoDragHandler));
    examples.add(new MatryoshkaExample(demoDragHandler));
    examples.add(new ResetCacheExample(dragController));

    examples.add(new PaletteExample(demoDragHandler));
    examples.add(new ClickTouchExample(dragController, demoDragHandler));

    mainPanel.add(new HTML(
            "<div style='color: gray; margin-top: 1em;'>Demo created with gwt-dnd @GWT_DND_VERSION@ and GWT "
                    + GWT.getVersion() + "</div>"));

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            examples.selectTabByHistoryToken(History.getToken());
        }
    });
}

From source file:com.allen_sauer.gwt.dnd.demo.client.example.bin.BinExample.java

License:Apache License

/**
 * Constructor.//  ww  w . j  a v  a2s . c  o m
 * @param dragController the drag controller to use
 */
public BinExample(PickupDragController dragController) {
    super(dragController);
    addStyleName(CSS_DEMO_BIN_EXAMPLE);

    // use the containing panel as this composite's widget
    AbsolutePanel containingPanel = new AbsolutePanel();
    containingPanel.setPixelSize(500, 200);
    setWidget(containingPanel);

    // create a trash bin
    Bin trashBin = new TrashBin(120, 120);
    containingPanel.add(trashBin, 30, 30);

    // create a bin that won't accept trash
    Bin closedBin = new Bin(120, 120);
    containingPanel.add(closedBin, 350, 30);

    // add drop controller for trash bin
    DropController openTrashBinDropController = new BinDropController(trashBin);
    dragController.registerDropController(openTrashBinDropController);

    // add drop controller for closed bin
    DropController closedTrashBinDropController = new BinDropController(closedBin);
    dragController.registerDropController(closedTrashBinDropController);

    // create a drop controller for the containing panel
    dropController = new AbsolutePositionDropController(containingPanel);
    dragController.registerDropController(dropController);

    containingPanel.add(createDraggable(), 200, 20);
    containingPanel.add(createDraggable(), 240, 50);
    containingPanel.add(createDraggable(), 190, 100);
}

From source file:com.allen_sauer.gwt.dnd.demo.client.example.draghandle.DragHandleExample.java

License:Apache License

public DragHandleExample(DemoDragHandler demoDragHandler) {
    addStyleName(CSS_DEMO_DRAG_HANDLE_EXAMPLE);

    // use the boundary panel as this composite's widget
    final AbsolutePanel boundaryPanel = new AbsolutePanel();
    boundaryPanel.setPixelSize(600, 400);
    setWidget(boundaryPanel);/*  ww  w.  ja v  a2 s. c  o m*/

    // create the title bar
    HTML header = new HTML(
            "Title/Header (Drag Handle) with <a href='http://google.com/' target='_blank'>link</a>");
    header.addStyleName(CSS_DEMO_DRAG_HANDLE_EXAMPLE_HEADER);

    // add some text
    HTML content = new HTML("This is a <code>VerticalPanel</code> which can be dragged by its header,"
            + " i.e. the title/header widget.");

    // add an editable text area
    final TextArea textArea = new TextArea();
    textArea.addStyleName(CSS_DEMO_DRAG_HANDLE_EXAMPLE_TEXTAREA);
    // textArea.setSize("20em", "5em");
    textArea.setText("You can click in this TextArea to get focus without causing the panel to be dragged.");

    // add a clickable button
    Button button = new Button("Click me");
    button.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            textArea.setText(textArea.getText() + " Click!");
        }
    });

    // create a panel to hold all our widgets
    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.setSpacing(2);
    verticalPanel.addStyleName(CSS_DEMO_DRAG_HANDLE_EXAMPLE_PANEL);
    verticalPanel.add(header);
    verticalPanel.add(content);
    verticalPanel.add(textArea);
    verticalPanel.add(button);
    boundaryPanel.add(verticalPanel, 20, 20);

    // instantiate our drag controller
    dragController = new PickupDragController(boundaryPanel, true);
    dragController.addDragHandler(demoDragHandler);
    dragController.setBehaviorConstrainedToBoundaryPanel(true);
    dragController.setBehaviorMultipleSelection(false);
    dragController.setBehaviorDragStartSensitivity(5);

    // instantiate our drop controller
    AbsolutePositionDropController dropController = new AbsolutePositionDropController(boundaryPanel);
    dragController.registerDropController(dropController);

    // make the panel draggable by its header
    dragController.makeDraggable(verticalPanel, header);
}