Example usage for com.google.gwt.user.client.ui Widget setWidth

List of usage examples for com.google.gwt.user.client.ui Widget setWidth

Introduction

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

Prototype

public void setWidth(String width) 

Source Link

Document

Sets the object's width.

Usage

From source file:org.uberfire.client.common.Popup.java

License:Apache License

private void addContent(final Widget content) {
    if (initialized) {
        return;//  w  w  w. java  2s  .c  o m
    }
    content.setWidth("100%");
    container.add(content);
    initialized = true;
}

From source file:org.unitime.timetable.gwt.client.sectioning.StudentSectioningWidget.java

License:Apache License

private void init() {
    if (CONSTANTS.allowCalendarExport()) {
        iCalendar = new ImageLink();
        iCalendar.setImage(new Image(RESOURCES.calendar()));
        iCalendar.setTarget(null);/*from w  w  w  .j  a  v a 2 s  . c o m*/
        iCalendar.setTitle(MESSAGES.exportICalendar());
        iCalendar.setAriaLabel(MESSAGES.exportICalendar());
    }

    iAssignments = new WebTable();
    iAssignments.setHeader(new WebTable.Row(new WebTable.Cell(MESSAGES.colLock(), 1, "15px"),
            new WebTable.Cell(MESSAGES.colSubject(), 1, "40px"),
            new WebTable.Cell(MESSAGES.colCourse(), 1, "40px"),
            new WebTable.Cell(MESSAGES.colSubpart(), 1, "30px"),
            new WebTable.Cell(MESSAGES.colClass(), 1, "50px"),
            new WebTable.Cell(MESSAGES.colLimit(), 1, "30px").aria(ARIA.colLimit()),
            new WebTable.Cell(MESSAGES.colDays(), 1, "30px"), new WebTable.Cell(MESSAGES.colStart(), 1, "40px"),
            new WebTable.Cell(MESSAGES.colEnd(), 1, "40px"), new WebTable.Cell(MESSAGES.colDate(), 1, "50px"),
            new WebTable.Cell(MESSAGES.colRoom(), 1, "80px"),
            new WebTable.Cell(MESSAGES.colInstructor(), 1, "80px"),
            new WebTable.Cell(MESSAGES.colParent(), 1, "80px"),
            new WebTable.Cell(MESSAGES.colNote(), 1, "50px"),
            new WebTable.Cell(MESSAGES.colCredit(), 1, "30px"),
            (iCalendar != null ? new WebTable.WidgetCell(iCalendar, MESSAGES.colIcons(), 1, "1px")
                    : new WebTable.Cell(MESSAGES.colIcons(), 1, "1px"))));
    iAssignments.setWidth("100%");
    iAssignments.setEmptyMessage(MESSAGES.emptySchedule());

    final FlexTable vp = new FlexTable();
    vp.setCellPadding(0);
    vp.setCellSpacing(0);
    vp.setWidget(0, 0, iAssignments);
    vp.getFlexCellFormatter().setColSpan(0, 0, 3);

    iTotalCredit = new Label();
    iTotalCredit.getElement().getStyle().setMarginTop(2, Unit.PX);
    vp.setWidget(1, 0, iQuickAdd);
    vp.setWidget(1, 1, iTotalCredit);
    iShowUnassignments = new CheckBox(MESSAGES.showUnassignments());
    iShowUnassignments.getElement().getStyle().setMarginTop(2, Unit.PX);
    vp.setWidget(1, 2, iShowUnassignments);
    vp.getFlexCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);
    vp.getFlexCellFormatter().setHorizontalAlignment(1, 2, HasHorizontalAlignment.ALIGN_RIGHT);
    for (int i = 0; i < 3; i++)
        vp.getFlexCellFormatter().getElement(1, i).getStyle().setWidth(33, Unit.PCT);
    iShowUnassignments.setVisible(false);
    String showUnassignments = Cookies.getCookie("UniTime:Unassignments");
    iShowUnassignments.setValue(showUnassignments == null || "1".equals(showUnassignments));

    iAssignmentGrid = new TimeGrid();
    iGridMessage = new P("unitime-TimeGridMessage");
    iGridMessage.setVisible(false);
    final P gridPanel = new P("unitime-TimeGridPanel");
    gridPanel.add(iGridMessage);
    gridPanel.add(iAssignmentGrid);

    iAssignmentTab = new AriaTabBar();
    iAssignmentTab.addTab(MESSAGES.tabClasses(), true);
    iAssignmentTab.addTab(MESSAGES.tabTimetable(), true);
    iAssignmentTab.selectTab(0);
    iAssignmentTab.addSelectionHandler(new SelectionHandler<Integer>() {
        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (event.getSelectedItem() == 0) {
                iAssignmentPanel.setWidget(vp);
                AriaStatus.getInstance().setHTML(ARIA.listOfClasses());
            } else {
                iAssignmentPanel.setWidget(gridPanel);
                iAssignmentGrid.scrollDown();
                AriaStatus.getInstance().setHTML(ARIA.timetable());
            }
            addHistory();
            ResizeEvent.fire(StudentSectioningWidget.this, StudentSectioningWidget.this.getOffsetWidth(),
                    StudentSectioningWidget.this.getOffsetHeight());
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    iAssignmentPanel.setFocus(true);
                }
            });
        }
    });
    iAssignmentPanel = new FocusPanel(vp);
    iAssignmentPanel.setStyleName("unitime-ClassScheduleTabPanel");
    iAssignmentPanel.addStyleName("unitime-FocusPanel");

    final Character classesAccessKey = UniTimeHeaderPanel.guessAccessKey(MESSAGES.tabClasses());
    final Character timetableAccessKey = UniTimeHeaderPanel.guessAccessKey(MESSAGES.tabTimetable());
    iAssignmentPanel.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (iAssignmentTab.getSelectedTab() == 0) {
                if (event.getNativeKeyCode() == KeyCodes.KEY_DOWN) {
                    do {
                        iAssignments.setSelectedRow(iAssignments.getSelectedRow() + 1);
                    } while (iAssignments.getRows()[iAssignments.getSelectedRow()] != null
                            && !iAssignments.getRows()[iAssignments.getSelectedRow()].isSelectable());

                    if (iAssignments.getSelectedRow() >= 0
                            && iAssignments.getSelectedRow() < iAssignments.getRows().length
                            && iAssignments.getRows()[iAssignments.getSelectedRow()] != null)
                        AriaStatus.getInstance()
                                .setHTML(ARIA.classSelected(1 + iAssignments.getSelectedRow(),
                                        iAssignments.getRowsCount(),
                                        iAssignments.getRows()[iAssignments.getSelectedRow()].getAriaLabel()));
                }
                if (event.getNativeKeyCode() == KeyCodes.KEY_UP) {
                    do {
                        iAssignments.setSelectedRow(
                                iAssignments.getSelectedRow() == 0 ? iAssignments.getRowsCount() - 1
                                        : iAssignments.getSelectedRow() - 1);
                    } while (iAssignments.getRows()[iAssignments.getSelectedRow()] != null
                            && !iAssignments.getRows()[iAssignments.getSelectedRow()].isSelectable());

                    if (iAssignments.getSelectedRow() >= 0
                            && iAssignments.getSelectedRow() < iAssignments.getRows().length
                            && iAssignments.getRows()[iAssignments.getSelectedRow()] != null)
                        AriaStatus.getInstance()
                                .setHTML(ARIA.classSelected(1 + iAssignments.getSelectedRow(),
                                        iAssignments.getRowsCount(),
                                        iAssignments.getRows()[iAssignments.getSelectedRow()].getAriaLabel()));
                }
                if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                    updateHistory();
                    showSuggestionsAsync(iAssignments.getSelectedRow());
                }
            }
            int tab = -1;
            if (classesAccessKey != null && event.getNativeEvent().getCtrlKey()
                    && (event.getNativeKeyCode() == classesAccessKey
                            || event.getNativeKeyCode() == Character.toUpperCase(classesAccessKey))) {
                tab = 0;
            }
            if (timetableAccessKey != null && event.getNativeEvent().getCtrlKey()
                    && (event.getNativeKeyCode() == timetableAccessKey
                            || event.getNativeKeyCode() == Character.toUpperCase(timetableAccessKey))) {
                tab = 1;
            }
            if (tab >= 0) {
                iAssignmentTab.selectTab(tab);
                event.preventDefault();
            }
        }
    });

    iAssignmentDock = new DockPanel();
    iAssignmentDock.setStyleName("unitime-ClassSchedulePanel");
    iAssignmentDock.setSpacing(0);
    iAssignmentDock.add(iAssignmentPanel, DockPanel.SOUTH);
    iAssignmentDock.add(iAssignmentTab, DockPanel.WEST);
    iAssignmentDock.setCellWidth(iAssignmentTab, "33%");
    iAssignmentDock.setCellVerticalAlignment(iAssignmentTab, HasVerticalAlignment.ALIGN_BOTTOM);
    iAssignmentDock.setCellHorizontalAlignment(iAssignmentTab, HasHorizontalAlignment.ALIGN_LEFT);
    Roles.getTabpanelRole().set(iAssignmentDock.getElement());
    Roles.getTabpanelRole().setAriaOwnsProperty(iAssignmentDock.getElement(),
            Id.of(iAssignmentTab.getElement()));

    P header = new P("unitime-MainHeader");
    header.setHTML(MESSAGES.headerClassSchedule());
    header.getElement().getStyle().setTextAlign(TextAlign.CENTER);
    iAssignmentDock.add(header, DockPanel.CENTER);
    iAssignmentDock.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER);
    iAssignmentDock.setCellWidth(header, "34%");

    P padding = new P("unitime-HeaderPadding");
    padding.setHTML("&nbsp;");
    iAssignmentDock.add(padding, DockPanel.EAST);
    iAssignmentDock.setCellWidth(padding, "33%");

    iRequests.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            prev();
            addHistory();
        }
    });

    iReset.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            clearMessage();
            LoadingWidget.getInstance().show(MESSAGES.courseRequestsScheduling());
            iSectioningService.section(iOnline, iCourseRequests.getRequest(), null,
                    new AsyncCallback<ClassAssignmentInterface>() {
                        public void onFailure(Throwable caught) {
                            iStatus.error(MESSAGES.exceptionSectioningFailed(caught.getMessage()), caught);
                            LoadingWidget.getInstance().hide();
                            updateHistory();
                        }

                        public void onSuccess(ClassAssignmentInterface result) {
                            fillIn(result);
                            addHistory();
                        }
                    });
        }
    });

    iSchedule.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            iCourseRequests.changeTip();
            clearMessage();
            iCourseRequests.validate(new AsyncCallback<Boolean>() {
                public void onSuccess(Boolean result) {
                    updateHistory();
                    if (result) {
                        if (iOnline) {
                            iSectioningService.saveRequest(iCourseRequests.getRequest(),
                                    new AsyncCallback<Boolean>() {
                                        public void onSuccess(Boolean result) {
                                            if (result) {
                                                iStatus.info(MESSAGES.saveRequestsOK());
                                            }
                                        }

                                        public void onFailure(Throwable caught) {
                                            iStatus.error(MESSAGES.saveRequestsFail(caught.getMessage()),
                                                    caught);
                                        }
                                    });
                        }
                        LoadingWidget.getInstance().show(MESSAGES.courseRequestsScheduling());
                        iSectioningService.section(iOnline, iCourseRequests.getRequest(), iLastResult,
                                new AsyncCallback<ClassAssignmentInterface>() {
                                    public void onFailure(Throwable caught) {
                                        iStatus.error(MESSAGES.exceptionSectioningFailed(caught.getMessage()),
                                                caught);
                                        LoadingWidget.getInstance().hide();
                                        updateHistory();
                                    }

                                    public void onSuccess(ClassAssignmentInterface result) {
                                        fillIn(result);
                                        addHistory();
                                    }
                                });
                    } else {
                        String error = iCourseRequests.getFirstError();
                        iStatus.error(error == null ? MESSAGES.validationFailed()
                                : MESSAGES.validationFailedWithMessage(error));
                        LoadingWidget.getInstance().hide();
                        updateHistory();
                    }
                }

                public void onFailure(Throwable caught) {
                    iStatus.error(MESSAGES.validationFailedWithMessage(caught.getMessage()), caught);
                    LoadingWidget.getInstance().hide();
                    updateHistory();
                }
            });
        }
    });

    iStartOver.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (isChanged()) {
                UniTimeConfirmationDialog.confirm(useDefaultConfirmDialog(), MESSAGES.queryLeaveChanges(),
                        new Command() {
                            @Override
                            public void execute() {
                                clearMessage();
                                clear(false);
                                iStartOver.setVisible(false);
                                iStartOver.setEnabled(false);
                                addHistory();
                                lastRequest(iSessionSelector.getAcademicSessionId(), null, true, false);
                            }
                        });
            } else {
                clearMessage();
                clear(false);
                iStartOver.setVisible(false);
                iStartOver.setEnabled(false);
                addHistory();
                lastRequest(iSessionSelector.getAcademicSessionId(), null, true, false);
            }
        }
    });

    iAssignments.addRowClickHandler(new WebTable.RowClickHandler() {
        public void onRowClick(WebTable.RowClickEvent event) {
            if (iLastResult.get(event.getRowIdx()) == null)
                return;
            updateHistory();
            showSuggestionsAsync(event.getRowIdx());
        }
    });

    iAssignmentGrid.addMeetingClickHandler(new TimeGrid.MeetingClickHandler() {
        public void onMeetingClick(TimeGrid.MeetingClickEvent event) {
            updateHistory();
            showSuggestionsAsync(event.getRowIndex());
        }
    });

    iAssignmentGrid.addPinClickHandler(new TimeGrid.PinClickHandler() {
        public void onPinClick(TimeGrid.PinClickEvent event) {
            ((HasValue<Boolean>) iAssignments.getRows()[event.getRowIndex()].getCell(0).getWidget())
                    .setValue(event.isPinChecked(), false);
            iLastResult.get(event.getRowIndex()).setPinned(event.isPinChecked());
            updateHistory();
        }
    });

    iEnroll.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            Command enroll = new Command() {
                @Override
                public void execute() {
                    clearMessage();
                    LoadingWidget.getInstance().show(MESSAGES.waitEnroll());
                    iSectioningService.enroll(iOnline, iCourseRequests.getRequest(), iLastResult,
                            new AsyncCallback<ClassAssignmentInterface>() {
                                public void onSuccess(ClassAssignmentInterface result) {
                                    LoadingWidget.getInstance().hide();
                                    iSavedAssignment = result;
                                    iStartOver.setVisible(iSavedAssignment != null
                                            && !iSavedAssignment.getCourseAssignments().isEmpty());
                                    iStartOver.setEnabled(iSavedAssignment != null
                                            && !iSavedAssignment.getCourseAssignments().isEmpty());
                                    fillIn(result);
                                    if (result.hasRequest())
                                        iCourseRequests.setRequest(result.getRequest());
                                    if (!result.hasMessages())
                                        iStatus.info(MESSAGES.enrollOK());
                                    updateHistory();
                                    if (iEligibilityCheck != null && iEligibilityCheck
                                            .hasFlag(EligibilityFlag.RECHECK_AFTER_ENROLLMENT)) {
                                        iSectioningService.checkEligibility(iOnline,
                                                iSessionSelector.getAcademicSessionId(),
                                                iEligibilityCheck.getStudentId(), (String) null,
                                                new AsyncCallback<OnlineSectioningInterface.EligibilityCheck>() {
                                                    @Override
                                                    public void onFailure(Throwable caught) {
                                                    }

                                                    @Override
                                                    public void onSuccess(
                                                            OnlineSectioningInterface.EligibilityCheck result) {
                                                        setElibibilityCheckDuringEnrollment(result);
                                                    }
                                                });
                                    }
                                }

                                public void onFailure(Throwable caught) {
                                    LoadingWidget.getInstance().hide();
                                    iStatus.error(MESSAGES.enrollFailed(caught.getMessage()), caught);
                                    updateHistory();
                                    if (caught instanceof SectioningException) {
                                        SectioningException se = (SectioningException) caught;
                                        EligibilityCheck check = se.getEligibilityCheck();
                                        if (check != null) {
                                            setElibibilityCheckDuringEnrollment(check);
                                            if (check.hasFlag(EligibilityFlag.PIN_REQUIRED)) {
                                                if (iPinDialog == null)
                                                    iPinDialog = new PinDialog();
                                                PinDialog.PinCallback callback = new PinDialog.PinCallback() {
                                                    @Override
                                                    public void onFailure(Throwable caught) {
                                                        iStatus.error(MESSAGES.exceptionFailedEligibilityCheck(
                                                                caught.getMessage()), caught);
                                                    }

                                                    @Override
                                                    public void onSuccess(
                                                            OnlineSectioningInterface.EligibilityCheck result) {
                                                        setElibibilityCheckDuringEnrollment(result);
                                                        if (result.hasFlag(EligibilityFlag.CAN_ENROLL)
                                                                && !result.hasFlag(
                                                                        EligibilityFlag.RECHECK_BEFORE_ENROLLMENT))
                                                            iEnroll.click();
                                                    }

                                                    @Override
                                                    public void onMessage(
                                                            OnlineSectioningInterface.EligibilityCheck result) {
                                                        if (result.hasMessage()) {
                                                            iStatus.error(result.getMessage());
                                                        } else if (result.hasFlag(
                                                                OnlineSectioningInterface.EligibilityCheck.EligibilityFlag.PIN_REQUIRED)) {
                                                            iStatus.warning(MESSAGES
                                                                    .exceptionAuthenticationPinRequired());
                                                        } else {
                                                            clearMessage(false);
                                                        }
                                                    }
                                                };
                                                iPinDialog.checkEligibility(iOnline,
                                                        iSessionSelector.getAcademicSessionId(), null,
                                                        callback);
                                            }
                                        }
                                        if (se.hasSectionMessages()) {
                                            for (CourseAssignment ca : iLastAssignment.getCourseAssignments()) {
                                                for (ClassAssignment c : ca.getClassAssignments()) {
                                                    c.setError(se.getSectionMessage(c.getClassId()));
                                                }
                                            }
                                            fillIn(iLastAssignment);
                                            iStatus.error(caught.getMessage(), false);
                                        }
                                    }
                                }
                            });
                }
            };
            enroll = confirmEnrollment(enroll);
            enroll.execute();
        }
    });

    iPrint.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            boolean allSaved = true;
            for (ClassAssignmentInterface.ClassAssignment clazz : iLastResult) {
                if (clazz != null && !clazz.isFreeTime() && !clazz.isSaved())
                    allSaved = false;
            }
            Widget w = iAssignments.getPrintWidget(0, 5, 15);
            w.setWidth("100%");
            ToolBox.print(
                    (allSaved && !isChanged() ? MESSAGES.studentSchedule()
                            : MESSAGES.studentScheduleNotEnrolled()),
                    (CONSTANTS.printReportShowUserName() ? iUserAuthentication.getUser() : ""),
                    iSessionSelector.getAcademicSessionName(), iAssignmentGrid.getPrintWidget(), w, iStatus);
        }
    });

    if (iExport != null)
        iExport.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                ToolBox.open(iCalendar.getUrl());
            }
        });

    if (iTrackHistory) {
        History.addValueChangeHandler(new ValueChangeHandler<String>() {
            public void onValueChange(ValueChangeEvent<String> event) {
                if (!event.getValue().isEmpty()) {
                    int item = iHistory.size() - 1;
                    try {
                        item = Integer.parseInt(event.getValue());
                    } catch (NumberFormatException e) {
                    }
                    if (item < 0)
                        item = 0;
                    if (item >= iHistory.size())
                        item = iHistory.size() - 1;
                    if (item >= 0)
                        iHistory.get(item).restore();
                } else if (isChanged()) {
                    UniTimeConfirmationDialog.confirm(useDefaultConfirmDialog(), MESSAGES.queryLeaveChanges(),
                            new Command() {
                                @Override
                                public void execute() {
                                    iCourseRequests.clear();
                                    if (!iSchedule.isVisible())
                                        prev();
                                }
                            });
                }
            }
        });
    }

    iSessionSelector
            .addAcademicSessionChangeHandler(new AcademicSessionSelector.AcademicSessionChangeHandler() {
                public void onAcademicSessionChange(AcademicSessionChangeEvent event) {
                    addHistory();
                }
            });

    iSave.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            iCourseRequests.changeTip();
            clearMessage();
            iCourseRequests.validate(new AsyncCallback<Boolean>() {
                public void onSuccess(Boolean result) {
                    updateHistory();
                    if (result) {
                        LoadingWidget.getInstance().show(MESSAGES.courseRequestsSaving());
                        iSectioningService.saveRequest(iCourseRequests.getRequest(),
                                new AsyncCallback<Boolean>() {
                                    public void onSuccess(Boolean result) {
                                        if (result) {
                                            iStatus.info(MESSAGES.saveRequestsOK());
                                        }
                                        LoadingWidget.getInstance().hide();
                                    }

                                    public void onFailure(Throwable caught) {
                                        iStatus.error(MESSAGES.saveRequestsFail(caught.getMessage()), caught);
                                        LoadingWidget.getInstance().hide();
                                    }
                                });
                    } else {
                        String error = iCourseRequests.getFirstError();
                        iStatus.error(error == null ? MESSAGES.validationFailed()
                                : MESSAGES.validationFailedWithMessage(error));
                        LoadingWidget.getInstance().hide();
                        updateHistory();
                    }
                }

                public void onFailure(Throwable caught) {
                    iStatus.error(MESSAGES.validationFailedWithMessage(caught.getMessage()), caught);
                    LoadingWidget.getInstance().hide();
                    updateHistory();
                }
            });
        }
    });

    iShowUnassignments.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            Cookies.setCookie("UniTime:Unassignments", "1");
            fillIn(iLastAssignment);
        }
    });
}

From source file:org.utgenome.gwt.widget.client.Style.java

License:Apache License

public static void fullWidth(Widget w) {
    w.setWidth("100%");
}

From source file:org.vaadin.addons.portallayout.gwt.client.portal.connection.StackPortalLayoutConnector.java

License:Apache License

@Override
public void postLayout() {
    final Iterator<Widget> it = getWidget().iterator();
    while (it.hasNext()) {
        final Widget w = it.next();
        w.setWidth("100%");
    }//from w  ww.  ja v a 2s  .co  m
}

From source file:org.xmlsh.jsonxmlspeed.client.DataFilePanel.java

License:BSD License

private void addColumn(String columnHeading) {
    Widget widget = new Label(columnHeading);
    int cell = documents.getCellCount(0);

    widget.setWidth("100%");
    widget.addStyleName("FlexTable-ColumnLabel");

    documents.setWidget(0, cell, widget);

    documents.getCellFormatter().addStyleName(0, cell, "FlexTable-ColumnLabelCell");
}

From source file:rocket.widget.client.splitter.HorizontalSplitterPanel.java

License:Apache License

/**
 * This is the most important event handler that takes care of adjusting the
 * widths of the widgets before and after the splitter being moved.
 * //ww w .  java 2  s.  co  m
 * @param event
 */
protected void onMouseMove(final MouseMoveEvent event) {
    Checker.notNull("parameter:event", event);

    while (true) {
        final Splitter splitter = (Splitter) event.getWidget();

        // need to figure out if mouse has moved to the right or left...
        final int mouseX = event.getPageX();
        final int splitterX = splitter.getElement().getAbsoluteLeft();

        // if the mouse has not moved horizontally but vertically so exit...
        int delta = mouseX - splitterX;
        if (0 == delta) {
            break;
        }

        // grab the widgets before and after the splitter being dragged...
        final InternalPanel panel = this.getPanel();
        final int panelIndex = panel.indexOf(splitter);
        final Widget beforeWidget = panel.get(panelIndex - 1);
        int beforeWidgetWidth = beforeWidget.getOffsetWidth() + delta;

        final Widget afterWidget = panel.get(panelIndex + 1);
        int afterWidgetWidth = afterWidget.getOffsetWidth() - delta;

        final int widthSum = beforeWidgetWidth + afterWidgetWidth;

        final List<SplitterItem> items = this.getItems();

        // if the mouse moved left make sure the beforeWidget width is not
        // less than its minimumWidth.
        if (delta < 0) {
            final SplitterItem beforeWidgetItem = items.get(panelIndex / 2);
            final int minimumWidth = beforeWidgetItem.getMinimumSize();

            if (beforeWidgetWidth < minimumWidth) {
                delta = minimumWidth - (beforeWidgetWidth - delta);
                beforeWidgetWidth = minimumWidth;
                afterWidgetWidth = widthSum - beforeWidgetWidth;
            }
        }

        // since the mouse moved right make sure the afterWidget width is
        // not less than its minimumWidth
        if (delta > 0) {
            final SplitterItem afterWidgetItem = items.get(panelIndex / 2 + 1);
            final int minimumWidth = afterWidgetItem.getMinimumSize();
            if (afterWidgetWidth < minimumWidth) {
                delta = afterWidgetWidth + delta - minimumWidth;
                afterWidgetWidth = minimumWidth;
                beforeWidgetWidth = widthSum - afterWidgetWidth;
            }
        }

        // save!
        beforeWidget.setWidth(beforeWidgetWidth + "px");
        afterWidget.setWidth(afterWidgetWidth + "px");

        // update the coordinates of both the splitter and after widget...
        adjustXCoordinate(splitter, delta);
        adjustXCoordinate(afterWidget, delta);

        beforeWidget.setHeight("100%");
        splitter.setHeight("100%");
        afterWidget.setHeight("100%");

        // its necessary to prevent the event to stop text selection in
        // opera.
        event.stop();
        break;
    }
}

From source file:rocket.widget.client.splitter.HorizontalSplitterPanel.java

License:Apache License

/**
 * Lays out all added widgets summing their individual weights and then
 * assigns widths to each.//from w  w  w.j av a  2  s .  c  om
 */
protected void redraw0() {
    final int weightSum = this.sumWeights();
    final InternalPanel panel = this.getPanel();
    final int availableWidth = panel.getParentElement().getOffsetWidth();

    final int splitterCount = (panel.getWidgetCount() - 1) / 2;
    final int splitterWidth = this.getSplitterSize();
    final int allocatedWidgetWidth = availableWidth - splitterCount * splitterWidth;
    final float ratio = (float) allocatedWidgetWidth / weightSum;

    int left = 0;
    final Iterator<SplitterItem> items = this.getItems().iterator();
    final Iterator<Widget> widgets = panel.iterator();

    boolean more = widgets.hasNext();

    while (more) {
        final Widget widget = widgets.next();
        final SplitterItem item = items.next();

        // set the widget position...
        final Element widgetElement = widget.getElement();
        final InlineStyle widgetInlineStyle = InlineStyle.getInlineStyle(widgetElement);
        widgetInlineStyle.setString(Css.POSITION, "absolute");
        widgetInlineStyle.setInteger(Css.LEFT, left, CssUnit.PX);
        widgetInlineStyle.setInteger(Css.TOP, 0, CssUnit.PX);
        widgetInlineStyle.setString(Css.OVERFLOW, "hidden");

        // set the size(width/height)...
        widget.setHeight("100%");

        // is the last widget ???
        if (false == widgets.hasNext()) {
            widget.setWidth((availableWidth - left) + "px");
            break;
        }

        // calculate the new width...
        final int weight = item.getSizeShare();
        final int width = (int) (ratio * weight);
        widget.setWidth(width + "px");

        left = left + width;

        final Widget splitter = (Widget) widgets.next();

        // set the splitter position...
        final InlineStyle splitterInlineStyle = InlineStyle.getInlineStyle(splitter.getElement());
        splitterInlineStyle.setString(Css.POSITION, "absolute");
        splitterInlineStyle.setInteger(Css.LEFT, left, CssUnit.PX);
        splitterInlineStyle.setInteger(Css.TOP, 0, CssUnit.PX);
        splitterInlineStyle.setString(Css.OVERFLOW, "hidden");

        // set the splitters size...
        splitter.setWidth(splitterWidth + "px");
        splitter.setHeight("100%");

        left = left + splitterWidth;

        more = widgets.hasNext();
    }
}

From source file:rocket.widget.client.splitter.VerticalSplitterPanel.java

License:Apache License

/**
 * This is the most important event handler that takes care of adjusting the
 * widths of the widgets before and after the splitter being moved.
 * //w  w w .j av a 2  s.  c  o m
 * @param splitter
 * @param event
 */
protected void onMouseMove(final MouseMoveEvent event) {
    Checker.notNull("parameter:event", event);

    while (true) {
        final Splitter splitter = (Splitter) event.getWidget();

        // need to figure out if mouse has moved to the right or left...
        final int mouseY = event.getPageY();
        final int splitterY = DOM.getAbsoluteTop(splitter.getElement());

        // if the mouse has not moved vertically but vertically so exit...
        int delta = mouseY - splitterY;
        if (0 == delta) {
            break;
        }

        // grab the widgets before and after the splitter being dragged...
        final InternalPanel panel = this.getPanel();
        final int panelIndex = panel.indexOf(splitter);
        final Widget beforeWidget = panel.get(panelIndex - 1);
        int beforeWidgetHeight = beforeWidget.getOffsetHeight() + delta;

        final Widget afterWidget = panel.get(panelIndex + 1);
        int afterWidgetHeight = afterWidget.getOffsetHeight() - delta;

        final int heightSum = beforeWidgetHeight + afterWidgetHeight;

        final List<SplitterItem> items = this.getItems();

        // if the mouse moved left make sure the beforeWidget width is not
        // less than its minimumHeight.
        if (delta < 0) {
            final SplitterItem beforeWidgetItem = items.get(panelIndex / 2);
            final int minimumHeight = beforeWidgetItem.getMinimumSize();

            if (beforeWidgetHeight < minimumHeight) {
                delta = minimumHeight - (beforeWidgetHeight - delta);
                beforeWidgetHeight = minimumHeight;
                afterWidgetHeight = heightSum - beforeWidgetHeight;
            }
        }

        // since the mouse moved right make sure the afterWidget width is
        // not less than its minimumHeight
        if (delta > 0) {
            final SplitterItem afterWidgetItem = items.get(panelIndex / 2 + 1);
            final int minimumHeight = afterWidgetItem.getMinimumSize();
            if (afterWidgetHeight < minimumHeight) {
                delta = afterWidgetHeight + delta - minimumHeight;
                afterWidgetHeight = minimumHeight;
                beforeWidgetHeight = heightSum - afterWidgetHeight;
            }
        }

        // save!
        beforeWidget.setHeight(beforeWidgetHeight + "px");
        afterWidget.setHeight(afterWidgetHeight + "px");

        // update the coordinates of both the splitter and after widget...
        adjustYCoordinate(splitter, delta);
        adjustYCoordinate(afterWidget, delta);

        beforeWidget.setWidth("100%");
        splitter.setWidth("100%");
        afterWidget.setWidth("100%");

        // its necessary to prevent the event to stop text selection in
        // opera.
        break;
    }
}

From source file:rocket.widget.client.splitter.VerticalSplitterPanel.java

License:Apache License

/**
 * Lays out all added widgets summing their individual weights and then
 * assigns widths to each./*from  w w  w. ja  va  2s .  c o  m*/
 */
protected void redraw0() {
    final int weightSum = this.sumWeights();
    final InternalPanel panel = this.getPanel();
    final int availableHeight = DOM.getElementPropertyInt(panel.getParentElement(), "offsetHeight");

    final int splitterCount = (panel.getWidgetCount() - 1) / 2;
    final int splitterHeight = this.getSplitterSize();
    final int allocatedWidgetHeight = availableHeight - splitterCount * splitterHeight;
    final float ratio = (float) allocatedWidgetHeight / weightSum;

    int top = 0;
    final Iterator<SplitterItem> items = this.getItems().iterator();
    final Iterator<Widget> widgets = panel.iterator();

    boolean more = widgets.hasNext();

    while (more) {
        final Widget widget = widgets.next();
        final SplitterItem item = items.next();

        // set the widget position...
        final InlineStyle widgetInlineStyle = InlineStyle.getInlineStyle(widget.getElement());

        widgetInlineStyle.setString(Css.POSITION, "absolute");
        widgetInlineStyle.setInteger(Css.LEFT, 0, CssUnit.PX);
        widgetInlineStyle.setInteger(Css.TOP, top, CssUnit.PX);
        widgetInlineStyle.setString(Css.OVERFLOW, "hidden");

        // set the size(width/height)...
        widget.setWidth("100%");

        // is the last widget ???
        if (false == widgets.hasNext()) {
            widget.setHeight((availableHeight - top) + "px");
            break;
        }

        // calculate the new width...
        final int weight = item.getSizeShare();
        final int height = (int) (ratio * weight);
        widget.setHeight(height + "px");

        top = top + height;

        final Widget splitter = (Widget) widgets.next();

        // set the splitter position...
        final InlineStyle splitterInlineStyle = InlineStyle.getInlineStyle(splitter.getElement());
        splitterInlineStyle.setString(Css.POSITION, "absolute");
        splitterInlineStyle.setInteger(Css.LEFT, 0, CssUnit.PX);
        splitterInlineStyle.setInteger(Css.TOP, top, CssUnit.PX);
        splitterInlineStyle.setString(Css.OVERFLOW, "hidden");

        // set the splitters size...
        splitter.setWidth("100%");
        splitter.setHeight(splitterHeight + "px");

        top = top + splitterHeight;

        more = widgets.hasNext();
    }
}

From source file:scrum.client.project.EstimationBarWidget.java

License:Open Source License

@Override
protected void onUpdate() {
    EstimationBar bar = requirement == null ? null : requirement.getEstimationBar();
    if (bar == null)
        bar = new EstimationBar(0, new ArrayList<Float>());
    flowPanel.clear();/* w  w  w.  ja v  a  2 s .  co  m*/
    List<Float> estimations = bar.getWorkPerSprint();
    int sprintOffset = bar.getSprintOffset();

    for (int i = 0; i < estimations.size(); i++) {

        int barIndex;
        if ((i + sprintOffset) % 2 == 0) {
            barIndex = 0;
        } else {
            barIndex = 1;
        }
        Widget w = Gwt.createEmptyDiv("EstimationBarWidget-bar" + barIndex);
        w.setHeight("6px");
        w.setWidth((factor * estimations.get(i)) + "px");
        flowPanel.add(w);
    }

    String tip;

    int requiredSprints = estimations.size() <= 1 ? sprintOffset + 1 : sprintOffset + estimations.size();
    tip = "Expected  to be completed after " + requiredSprints + " sprint"
            + (requiredSprints == 1 ? "." : "s.");

    flowPanel.getElement().setTitle(tip);
}