下面列出了怎么用com.google.gwt.dom.client.Style.Unit的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void onUpdate(EditorUpdateEvent event) {
OffsetPosition p = NativeSelectionUtil.slowGetPosition();
if (p != null) {
EditorStaticDeps.logger.trace().log("x: " + p.left + "y: " + p.top);
if (p.offsetParent == null) {
// If offsetParent is null, interpret offsetX and offsetY as
// absolute positions
if (DEBUG_CURSOR.getParentElement() != Document.get().getBody()) {
Document.get().getBody().appendChild(DEBUG_CURSOR);
}
DEBUG_CURSOR.getStyle().setTop(p.top - Document.get().getBody().getAbsoluteTop(), Unit.PX);
DEBUG_CURSOR.getStyle().setLeft(p.left - Document.get().getBody().getAbsoluteLeft(),
Unit.PX);
} else {
if (editorImpl.getElement() != null
&& DEBUG_CURSOR.getParentElement() != editorImpl.getElement()) {
editorImpl.getElement().appendChild(DEBUG_CURSOR);
}
DEBUG_CURSOR.getStyle().setTop(p.top, Unit.PX);
DEBUG_CURSOR.getStyle().setLeft(p.left, Unit.PX);
}
}
}
public RegisterView() {
initWidget(ourUiBinder.createAndBindUi(this));
register.setText( Constants.registerUIMsg.register() );
registerUsr.setText( Constants.registerUIMsg.registerUsr() );
registerPwd.setText( Constants.registerUIMsg.registerPwd() );
registerVer.setText( Constants.registerUIMsg.registerVer() );
registerCmp.setText( Constants.registerUIMsg.registerCmp() );
registerPst.setText( Constants.registerUIMsg.registerPst() );
confirmBtn.removeStyleName("gwt-Button");
confirmBtn.setText( Constants.registerUIMsg.confirm() );
confirmBtn.getElement().getStyle().setMarginLeft(100, Unit.PX);
confirmBtn.getElement().getStyle().setMarginTop(50, Unit.PX);
confirmBtn.getElement().getStyle().setMarginBottom(100, Unit.PX);
}
public void updatePosition(long startFromMinutes, long durationInMinutes) {
if (startFromMinutes < 0) {
startFromMinutes = 0;
}
top = weekGrid.getPixelTopFor((int) startFromMinutes);
getElement().getStyle().setTop(top, Unit.PX);
if (durationInMinutes > 0) {
int heightMinutes = weekGrid.getPixelLengthFor(
(int) startFromMinutes, (int) durationInMinutes);
setHeight(heightMinutes);
} else {
setHeight(-1);
}
boolean multiRowCaption = (durationInMinutes > 30);
updateCaptions(multiRowCaption);
}
public void setToday(Date today, int width) {
this.today = today;
addStyleDependentName("today");
Element lastChild = (Element) getElement().getLastChild();
if (lastChild.getClassName().equals("v-calendar-current-time")) {
todaybar = lastChild;
} else {
todaybar = DOM.createDiv();
todaybar.setClassName("v-calendar-current-time");
getElement().appendChild(todaybar);
}
if (width != -1) {
todaybar.getStyle().setWidth(width, Unit.PX);
}
// position is calculated later, when we know the cell heights
}
private void updateSpacerBlocks(double dayWidthPx) {
double spaceLeft = getResolutionDivWidth() - (blocksInRange * dayWidthPx);
if (spaceLeft > 0) {
for (DivElement e : spacerBlocks) {
e.getStyle().clearDisplay();
e.getStyle().setWidth(spaceLeft, Unit.PX);
}
resSpacerDiv = createResolutionBlock();
resSpacerDiv.addClassName(STYLE_SPACER);
resSpacerDiv.getStyle().setWidth(spaceLeft, Unit.PX);
resSpacerDiv.setInnerText(" ");
resolutionDiv.appendChild(resSpacerDiv);
} else {
hideSpacerBlocks();
}
}
@Override
public void onModuleLoad() {
// Create the object graph - a real application would use Gin
SimpleEventBus eventBus = new SimpleEventBus();
SidebarPresenter sidebarPresenter = new SidebarPresenter(eventBus);
Button sidebarView = new Button("Contacts");
sidebarView.getElement().getStyle().setFloat(Style.Float.LEFT);
sidebarView.getElement().getStyle().setMarginRight(20, Unit.PX);
sidebarPresenter.setView(sidebarView);
RootPanel.get().add(sidebarView);
ContactsPresenter contactsPresenter = new ContactsPresenter(eventBus);
VerticalPanel contactsView = new VerticalPanel();
contactsPresenter.setView(contactsView);
RootPanel.get().add(contactsView);
// Start listening for events in the presenter
contactsPresenter.start();
// Eagerly bind the server proxy
ServerProxy server = new ServerProxy(eventBus);
}
/**
* HistorySearch
*/
public HistorySearch() {
stackPanel = new StackLayoutPanel(Unit.PX);
searchSaved = new SearchSaved();
userNews = new UserNews();
scrollSearchSavedPanel = new ScrollPanel();
scrollUserNewsSavedPanel = new ScrollPanel();
scrollSearchSavedPanel.addStyleName("okm-PanelSelected");
scrollUserNewsSavedPanel.addStyleName("okm-PanelSelected");
scrollSearchSavedPanel.add(searchSaved);
scrollSearchSavedPanel.setSize("100%", "100%");
scrollUserNewsSavedPanel.add(userNews);
scrollUserNewsSavedPanel.setSize("100%", "100%");
stackPanel.add(scrollSearchSavedPanel, Util.createHeaderHTML("img/icon/stackpanel/find.gif", Main.i18n("leftpanel.label.stored.search")), true, 22);
stackPanel.add(scrollUserNewsSavedPanel, Util.createHeaderHTML("img/icon/news.gif", Main.i18n("leftpanel.label.user.search")), true, 22);
stackPanel.showWidget(0);
stackPanel.setStyleName("okm-StackPanel");
stackPanel.addStyleName("okm-DisableSelect");
initWidget(stackPanel);
}
/**
* {@inheritDoc}
*/
@Override
public void setPopupPositionAndMakeVisible(Element relative, final Element p) {
ScheduleCommand.addCommand(new Scheduler.Task() {
@Override
public void execute() {
p.getStyle().setLeft((RootPanel.get().getOffsetWidth() - p.getOffsetWidth()) / 2, Unit.PX);
int height = PositionUtil.boundHeightToScreen(p.getOffsetHeight());
int top = (RootPanel.get().getOffsetHeight() - height) / 2;
// Prevent negative top position.
p.getStyle().setTop(Math.max(top, MIN_OFFSET_HEIGHT_DEFAULT), Unit.PX);
p.getStyle().setHeight(height, Unit.PX);
p.getStyle().setVisibility(Visibility.VISIBLE);
}
});
}
@Override
public Widget asWidget() {
if (widget == null) {
widget = new VerticalLayoutContainer();
widget.getElement().getStyle().setPosition(Position.ABSOLUTE);
widget.getElement().getStyle().setRight(5, Unit.PX);
widget.getElement().getStyle().setBottom(5, Unit.PX);
widget.setHeight("120px");
widget.setWidth("420px");
ScrollSupport scrollSupport = widget.getScrollSupport();
scrollSupport.setScrollMode(ScrollMode.AUTOX);
widget.add(w3wPanel);
widget.add(toolBar);
widget.setVisible(true);
}
return widget;
}
@Override
public Widget asWidget() {
if (widget == null) {
final String width = "60px";
final String height = "10px";
widget = new HorizontalLayoutContainer();
widget.getElement().getStyle().setPosition(Position.ABSOLUTE);
widget.getElement().getStyle().setLeft(10, Unit.PX);
widget.getElement().getStyle().setBottom(90, Unit.PX);
widget.setSize(width, height);
hp = new HorizontalPanel();
hp.setSpacing(2);
hp.getElement().getStyle().setBackgroundColor("#FFFFFF");
hp.setSize(width, height);
hp.add(getZoomLabel());
widget.add(hp);
}
return widget;
}
public void setContent(final String text, final boolean animate) {
// Bug out if the text to display is the same as the current text
if (text != null && text.equals(currentText)) {
return;
}
if(!animate) {
container.clear();
}
final Label lbl = new Label(text);
container.add(lbl);
if(animate) {
container.getElement().getStyle().setTop(- (container.getWidgetCount() - 1) * FIELD_HEIGHT, Unit.PX);
// This is gonna suck if there's more than a couple of these running, so thank god Mr Moore invented that law of his
cleanupTimer.cancel();
cleanupTimer.schedule(CLEAN_UP_DELAY);
} else {
container.getElement().getStyle().setTop(0, Unit.PX);
}
currentText = text;
}
@Override
public void run() {
// Make sure we're not animating
container.addStyleName(style.noAnimation());
// Remove all but the last widget
while(container.getWidgetCount() > 1) {
container.remove(0);
}
// Reset the 'top' attribute to 0, and enforce the DOM change
container.getElement().getStyle().setTop(0, Unit.PX);
ComputedStyle.getStyleProperty(container.getElement(), "top");
// Re-enable animation
container.removeStyleName(style.noAnimation());
}
@Override
public boolean remove(Widget w) {
if (!(w instanceof StepWidget)) {
return super.remove(w);
} else {
int startIndex = getWidgetIndex(w);
int height = getElementHeightWithMargin(w.getElement());
contentHeight -= height;
if ((startIndex = removeAndReturnIndex(w)) >= 0) {
updateTopForAllStepsBelow(startIndex, -height);
// update content height
content.getStyle().setHeight(contentHeight, Unit.PX);
return true;
}
return false;
}
}
public IconCell(ImageResource resource, final String title, String text) {
super(null);
iIcon = new Image(resource);
iIcon.setTitle(title);
iIcon.setAltText(title);
if (text != null && !text.isEmpty()) {
iLabel = new HTML(text, false);
iPanel = new HorizontalPanel();
iPanel.setStyleName("icon");
iPanel.add(iIcon);
iPanel.add(iLabel);
iIcon.getElement().getStyle().setPaddingRight(3, Unit.PX);
iPanel.setCellVerticalAlignment(iIcon, HasVerticalAlignment.ALIGN_MIDDLE);
}
if (title != null && !title.isEmpty()) {
iIcon.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
event.stopPropagation();
UniTimeConfirmationDialog.info(title);
}
});
}
}
public IconsCell add(ImageResource resource, final String title, final boolean html) {
if (resource == null) return this;
Image icon = new Image(resource);
String text = title;
if (html) { HTML h = new HTML(title); text = h.getText(); }
icon.setTitle(text);
icon.setAltText(text);
if (iPanel.getWidgetCount() > 0)
icon.getElement().getStyle().setMarginLeft(3, Unit.PX);
iPanel.add(icon);
iPanel.setCellVerticalAlignment(icon, HasVerticalAlignment.ALIGN_MIDDLE);
if (title != null && !title.isEmpty()) {
icon.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
event.stopPropagation();
UniTimeConfirmationDialog.info(title, html);
}
});
}
return this;
}
/**
* @param left position of page's left edge on the canvas
* @param top position of page's top edge on the canvas
*/
public void setViewPosition(int pageNum, int left, int top, double zoom) {
boolean pageChanged = currentPage != pageNum;
TextPage page = getPage(pageNum);
if (pageChanged) {
getPage(currentPage).removeStyleName(PAGE_STYLE_VISIBLE);
page.addStyleName(PAGE_STYLE_VISIBLE);
}
page.resize(zoom, pageChanged);
currentPage = pageNum;
Element layerElement = getElement();
Element pageElement = page.getElement();
pageElement.getStyle().setMarginLeft(Math.max(left, 0) + EXTRA_PAGE_MARGIN, Unit.PX);
int targetScrollLeft = Math.max(-left, 0) + EXTRA_PAGE_MARGIN;
if (layerElement.getScrollLeft() != targetScrollLeft)
layerElement.setScrollLeft(targetScrollLeft);
int targetScrollTop = pageElement.getOffsetTop() - top;
if (layerElement.getScrollTop() != targetScrollTop)
layerElement.setScrollTop(targetScrollTop);
}
public Arrow(final Orientation orientation, final int borderWidth) {
setElement(d);
this.orientation = orientation;
this.borderWidth = borderWidth;
d.appendChild(d1);
d.appendChild(d2);
d.getStyle().setPosition(Position.ABSOLUTE);
d1.getStyle().setPosition(Position.ABSOLUTE);
d1.getStyle().setHeight(0, Unit.PX);
d1.getStyle().setWidth(0, Unit.PX);
d1.getStyle().setPropertyPx(orientation.pos, 0);
d1.getStyle().setPropertyPx(orientation.altPos, 0);
d1.getStyle().setBorderStyle(BorderStyle.SOLID);
d2.getStyle().setPosition(Position.ABSOLUTE);
d2.getStyle().setHeight(0, Unit.PX);
d2.getStyle().setWidth(0, Unit.PX);
d2.getStyle().setPropertyPx(orientation.pos, borderWidth);
d2.getStyle().setPropertyPx(orientation.altPos, borderWidth);
d2.getStyle().setBorderStyle(BorderStyle.SOLID);
topBottom = orientation == Orientation.TOP || orientation == Orientation.BOTTOM;
}
public BusyPanel(String text, int dayOfWeek, int startSlot, int length) {
super();
iText = text;
iDayOfWeek = dayOfWeek;
iStartSlot = startSlot;
iLength = length;
if (iText != null || !iText.isEmpty()) {
setTitle(iText);
boolean empty = true;
for (int i = 0; i < 3; i++) {
if (iMeetingTable[iDayOfWeek].length <= iStartSlot + i) { empty = false; break; }
if (iMeetingTable[iDayOfWeek][iStartSlot + i] != null && !iMeetingTable[iDayOfWeek][iStartSlot + i].isEmpty()) {
empty = false; break;
}
}
if (empty) {
HTML widget = new HTML(text, false);
widget.setStyleName("text");
setWidget(widget);
}
}
setStyleName("busy");
getElement().getStyle().setWidth(iCellWidth + (iPrint ? 3 : iDayOfWeek + 1 < iNrDays ? 3 : 0), Unit.PX);
getElement().getStyle().setHeight(125 * iLength / 30, Unit.PX);
iGrid.insert(this, iCellWidth * iDayOfWeek, 125 * iStartSlot / 30 - 50 * iStart, 1);
}
private void updateDecoration() {
if (decoration != null) {
Segment decoratedSegment = segmentPath.getMiddleSegment();
Point decorationCenter = decoratedSegment.middle();
int width = decoration.getWidth();
int height = decoration.getHeight();
decoration.asWidget().getElement().getStyle().setTop(decorationCenter.getTop() - height / 2, Unit.PX);
decoration.asWidget().getElement().getStyle().setLeft(decorationCenter.getLeft() - width / 2, Unit.PX);
}
}
/**
* Initialize the widget panel according to the canvas.
*
* @param canvas
*/
protected void initWidgetPanel(final DiagramCanvas canvas) {
widgetPanel = new AbsolutePanel();
widgetPanel.getElement().getStyle().setWidth(canvas.getWidth(), Unit.PX);
widgetPanel.getElement().getStyle().setHeight(canvas.getHeight(), Unit.PX);
widgetPanel.add(canvas.asWidget());
this.svgPanel = new SVGPanel();
widgetPanel.add(svgPanel);
focusPanel.add(widgetPanel);
scrollPanel = new ScrollPanel(widgetPanel);
}
/**
* Clear the canvas in the diagram.
*/
public void clear() {
widgets.clear();
connDrawSet.clear();
widgetPanel.clear();
widgetPanel.getElement().getStyle().setWidth(topCanvas.getWidth(), Unit.PX);
widgetPanel.getElement().getStyle()
.setHeight(topCanvas.getHeight(), Unit.PX);
widgetPanel.add(topCanvas.asWidget());
svgPanel = new SVGPanel();
widgetPanel.add(svgPanel);
topCanvas.getElement().getStyle().setPosition(Position.ABSOLUTE);
showGrid(showGrid);
}
public ResetpwdView() {
initWidget(ourUiBinder.createAndBindUi(this));
resetpwd.setText( Constants.resetpwdUIMsg.resetpwd());
resetPwd.setText( Constants.resetpwdUIMsg.resetPwd());
resetVer.setText( Constants.resetpwdUIMsg.resetVer());
confirmBtn.removeStyleName("gwt-Button");
confirmBtn.setText( Constants.resetpwdUIMsg.confirm() );
confirmBtn.getElement().getStyle().setMarginTop(100, Unit.PX);
confirmBtn.getElement().getStyle().setMarginLeft(100, Unit.PX);
confirmBtn.getElement().getStyle().setMarginBottom(200, Unit.PX);
}
public void setValue(T value) {
this.value = value;
double val = 0;
if (value == null) {
val = this.min;
} else {
val = value.doubleValue();
}
if (val > this.max) {
val = this.max;
} else if (val < this.min) {
val = this.min;
}
this.progressBarElement.setAttribute(OutputProgressBar.ATT_ARIA_VALUE, value + "");
double percent = 100 * (val - this.min) / (this.max - this.min);
this.progressBarElement.getStyle().setProperty("width", percent, Unit.PCT);
NumberFormat formatter = NumberFormat.getFormat("#.##");
String stringToDisplay = this.format;
stringToDisplay = RegExp.compile("\\{0\\}").replace(stringToDisplay, formatter.format(val));
stringToDisplay = RegExp.compile("\\{1\\}").replace(stringToDisplay, formatter.format(percent));
stringToDisplay = RegExp.compile("\\{2\\}").replace(stringToDisplay, formatter.format(this.min));
stringToDisplay = RegExp.compile("\\{3\\}").replace(stringToDisplay, formatter.format(this.max));
this.progressBarElement.removeAllChildren();
if (this.displayValue) {
this.progressBarElement.setInnerText(stringToDisplay);
} else {
SpanElement reader = Document.get().createSpanElement();
reader.setInnerText(stringToDisplay);
reader.addClassName("sr-only");
this.progressBarElement.appendChild(reader);
}
}
public DeletePanel() {
title.setStyleName("alertTitle");
close.setStyleName("alertClose");
alertHeader.add(title);
alertHeader.add(close);
alertHeader.addStyleName("alertTitleBG");
content.removeStyleName("gwt-Label");
content.addStyleName("alertBody");
alertContent.add(content);
alertContent.addStyleName("alertBodyBG");
confirmBtn.removeStyleName("gwt-Button");
cancelBtn.removeStyleName("gwt-Button");
cancelBtn.getElement().getStyle().setMarginLeft(105, Unit.PX);
alertButton.add(confirmBtn);
alertButton.add(cancelBtn);
alertButton.addStyleName("alertButton2");
vPanel.add(alertHeader);
vPanel.add(alertContent);
vPanel.add(alertButton);
vPanel.addStyleName("alertBox");
mask.addStyleName("alertBack");
bind();
root.add(mask);
root.add(vPanel);
this.add(root);
this.removeStyleName("gwt-PopupPanel");
}
public CategoryPanel(String type) {
this.type = type;
HorizontalPanel alertHeader = new HorizontalPanel();
title.addStyleName("cateAddBoxTitle");
close.addStyleName("alertClose");
change.addStyleName("change");
change.setTitle( Constants.adminUIMsg.change());
alertHeader.add(title);
alertHeader.add(close);
alertHeader.addStyleName("alertTitleBG");
if(type.equals("data")){
dataTree = DatasetCateTreeLoader.load();
dataTree.getElement().getStyle().setMarginTop(10, Unit.PX);
dataTree.getElement().getStyle().setMarginLeft(20, Unit.PX);
sPanel.add(dataTree);
}else{
progTree = ProgramCateTreeLoader.load();
progTree.getElement().getStyle().setMarginTop(10, Unit.PX);
progTree.getElement().getStyle().setMarginLeft(20, Unit.PX);
sPanel.add(progTree);
}
vPanel.add(alertHeader);
vPanel.add(sPanel);
sPanel.addStyleName("min_height_250");
vPanel.addStyleName("alertBox");
mask.addStyleName("alertBack");
bind();
root.add(mask);
root.add(vPanel);
this.add(root);
this.removeStyleName("gwt-PopupPanel");
}
@Override
public void setPopupPositionAndMakeVisible(Element reference, final Element popup) {
Style popupStyle = popup.getStyle();
// TODO(danilatos): Do something more intelligent than arbitrary constants (which might be
// susceptible to font size changes, etc)
popupStyle.setLeft(popupAnchor.getAbsoluteLeft() - popup.getOffsetWidth() + 26, Unit.PX);
popupStyle.setTop(popupAnchor.getAbsoluteBottom() + 5, Unit.PX);
popupStyle.setVisibility(Visibility.VISIBLE);
}
public void setHeight(int h) {
if (h == -1) {
getElement().getStyle().setProperty("height", "");
eventContent.getStyle().setProperty("height", "");
} else {
getElement().getStyle().setHeight(h, Unit.PX);
// FIXME measure the border height (2px) from the DOM
eventContent.getStyle().setHeight(h - 2, Unit.PX);
}
}
private void updateTopForAllStepsBelow(int startIndex, int delta) {
GWT.log("Updating top for all steps below index " + startIndex + ". Delta y: " + delta + "px");
// update top for all elements below
Element elementBelow;
for (int i = startIndex; i < getChildren().size(); i++) {
elementBelow = getWidget(i).getElement();
double top = parseSize(elementBelow.getStyle().getTop(), "px");
elementBelow.getStyle().setTop(top + delta, Unit.PX);
}
}
private void updateBarResizingLeft(Element bar, double deltax) {
double newLeft = capturePointLeftPx + deltax;
double newWidth = capturePointWidthPx - deltax;
if (newWidth >= BAR_MIN_WIDTH) {
bar.getStyle().setLeft(newLeft, Unit.PX);
bar.getStyle().setWidth(newWidth, Unit.PX);
}
}
private void fillHourResolutionBlock(DivElement resBlock, Date date, int index, int hourCounter, boolean lastBlock,
int left, boolean even) {
resBlock.setInnerText(formatHourCaption(date));
if (showCurrentTime
&& getLocaleDataProvider().formatDate(date, HOUR_CHECK_FORMAT).equals(currentDate + currentHour)) {
resBlock.addClassName(STYLE_NOW);
} else {
resBlock.removeClassName(STYLE_NOW);
}
if (even) {
resBlock.addClassName(STYLE_EVEN);
} else {
resBlock.removeClassName(STYLE_EVEN);
}
if (firstDay && (hourCounter == 24 || lastBlock)) {
firstDay = false;
firstResBlockCount = index + 1;
} else if (lastBlock) {
lastResBlockCount = (index + 1 - firstResBlockCount) % 24;
}
if (styleElementForLeft == null && isTimelineOverflowingHorizontally()) {
resBlock.getStyle().setPosition(Position.RELATIVE);
resBlock.getStyle().setLeft(left, Unit.PX);
}
}