List of usage examples for com.google.gwt.dom.client Style setWidth
public void setWidth(double value, Unit unit)
From source file:com.ksyzt.gwt.client.ui.richeditor.RichTextToolbar.java
License:Open Source License
/** * Show popup./*from w ww.ja v a 2 s .c o m*/ * * @param attacheElement the attache element * @param w the w */ private void showPopup(Widget attacheElement, Widget w) { back_widget = attacheElement; if (w == null) { w = new HTMLPanel(""); w.setSize("100px", "100px"); m_ap_content.clear(); m_ap_content.add(w); } else { m_ap_content.clear(); m_ap_content.add(w); } m_ap_content.setVisible(true); m_ap_shadow.setVisible(true); m_ap_line.setVisible(true); int aleft = attacheElement.getAbsoluteLeft(); int atop = attacheElement.getAbsoluteTop(); int aw = attacheElement.getOffsetWidth(); int ah = attacheElement.getOffsetHeight(); int width = m_ap_content.getOffsetWidth(); int height = m_ap_content.getOffsetHeight(); int lbx = aleft; int lby = atop + ah; int rbx = lbx + aw; int rby = lby; Style style = m_ap_content.getElement().getStyle(); style.setLeft(rbx - width, Unit.PX); style.setTop(lby - 1, Unit.PX); style = m_ap_shadow.getElement().getStyle(); style.setLeft(rbx - width + 3, Unit.PX); style.setTop(lby + 2, Unit.PX); style.setWidth(width, Unit.PX); style.setHeight(height, Unit.PX); style = m_ap_line.getElement().getStyle(); style.setLeft(lbx + 1, Unit.PX); style.setTop(lby - 1, Unit.PX); style.setWidth(aw - 2, Unit.PX); back_css = attacheElement.getStyleName(); attacheElement.setStyleName("toolbar_over"); m_ap_content.getElement().focus(); m_b_show_popup = true; }
From source file:com.sciencegadgets.client.algebra.AlgebraHistory.java
License:Open Source License
void reset() { expanded = false;// w w w .j av a 2 s . c o m setHeight("100%"); // Minimize overflow by fitting equation into row LinkedList<AlgebraHistoryRow> rows = getRows(); if (isAttached() && !rows.isEmpty()) { AlgebraHistoryRow lastRow = rows.getLast(); int leftWidthMin = 0, rightWidthMin = 0; for (AlgebraHistoryRow row : rows) { leftWidthMin = Math.max(leftWidthMin, row.leftCaseContent.getOffsetWidth()); rightWidthMin = Math.max(rightWidthMin, row.rightCaseContent.getOffsetWidth()); } double maxWidth = lastRow.leftCase.getParentElement().getOffsetWidth() * 0.9; double combinedWidthMin = leftWidthMin + rightWidthMin; double leftWidth = lastRow.leftCaseContent.getOffsetWidth(); double rightWidth = lastRow.rightCaseContent.getOffsetWidth(); if (combinedWidthMin < maxWidth) {// all rows fit // Weigh to center double exess = maxWidth - leftWidthMin - rightWidthMin; leftWidth = leftWidthMin + (exess / 2); rightWidth = rightWidthMin + (exess / 2); } else if (leftWidthMin <= rightWidthMin) { rightWidth = maxWidth - leftWidth; } else if (leftWidthMin > rightWidthMin) { leftWidth = maxWidth - rightWidth; } double combinedWidth = leftWidth + rightWidth; for (AlgebraHistoryRow row : rows) { Style leftStyle = row.leftCase.getStyle(); Style rightStyle = row.rightCase.getStyle(); leftStyle.setWidth((leftWidth / (combinedWidth)) * 90, Unit.PCT); rightStyle.setWidth((rightWidth / (combinedWidth)) * 90, Unit.PCT); } } scrollToBottom(); }
From source file:com.sciencegadgets.client.algebra.edit.LinkPrompt_Equation.java
License:Open Source License
public LinkPrompt_Equation(final AlgebraActivity algebraActivity, EquationTree initialEquation) { super();//from w ww. j av a 2 s . c o m this.initialEquation = initialEquation; this.algebraActivity = algebraActivity; // params.add(easyToggle); if (initialEquation == null) { LinkedList<EquationNode> variables = algebraActivity.getEquationTree() .getNodesByType(TypeSGET.Variable); int varCount = variables.size(); if (varCount == 0) { Window.alert("You should consider adding a variable in the equation"); } else { // final Button solveGoalButton = new Button("Solve Goal", // new ClickHandler() { // @Override // public void onClick(ClickEvent arg0) { // LinkPrompt_Equation.this.disappear(); // Moderator.switchToAlgebra( // algebraActivity.getEquationTree(), // ActivityType.editsolvegoal, true); // } // }); // solveGoalButton // .setTitle("Faster and more accurate but can't use with random numbers"); // solveGoalButton.addStyleName(CSS.CREATE_GOAL_BUTTON); // solveGoalButton.addStyleName(CSS.BORDER_RADIUS_SMALL); // upperArea.add(solveGoalButton); // // final Button createGoalButton = new Button("Edit Goal", // new ClickHandler() { // @Override // public void onClick(ClickEvent arg0) { // LinkPrompt_Equation.this.disappear(); // Moderator.switchToAlgebra( // algebraActivity.getEquationTree(), // ActivityType.editcreategoal, true); // } // }); // createGoalButton // .setTitle("Can use with random numbers but prone to error!"); // createGoalButton.addStyleName(CSS.CREATE_GOAL_BUTTON); // createGoalButton.addStyleName(CSS.BORDER_RADIUS_SMALL); // upperArea.add(createGoalButton); } Unit[] units = Unit.values(); ArrayList<String> unitStrings = new ArrayList<String>(); for (Unit u : units) { unitStrings.add(u.toString()); } widthUnits.setAcceptableValues(unitStrings); heightUnits.setAcceptableValues(unitStrings); SpecChangeHandler specChange = new SpecChangeHandler(); KeyUpToSpecChange keyUp = new KeyUpToSpecChange(); widthTextBox.addValueChangeHandler(specChange); widthUnits.addValueChangeHandler(specChange); heightTextBox.addValueChangeHandler(specChange); heightUnits.addValueChangeHandler(specChange); widthTextBox.addKeyUpHandler(keyUp); heightTextBox.addKeyUpHandler(keyUp); colorTextBox.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { setColor(colorTextBox.getValue()); } }); colorTextBox.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { setColor(colorTextBox.getValue()); } }); colorTextBox.getElement().setId("colorTextBox"); Element colorInput = DOM.createElement("input"); colorInput.setAttribute("type", "color"); colorInput.setAttribute("value", initialColor); colorInput.setAttribute("id", "colorInputElement"); colorInput.setAttribute("onchange", "colorTextBox.value=colorInputElement.value.replace('#', ''); colorTextBox.focus()"); Style colorInputStyle = colorInput.getStyle(); colorInputStyle.setProperty("border", "none"); colorInputStyle.setPadding(0, Unit.PX); colorInputStyle.setWidth(100, Unit.PCT); colorInputArea.getElement().appendChild(colorInput); } else { setModal(true); setAutoHideEnabled(false); upperArea.add(new Label("Goal: ")); upperArea.add(algebraActivity.getEquationTree().getDisplayClone()); addOkHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { Moderator.switchToAlgebra(algebraActivity.getEquationTree(), ActivityType.editequation, true); } }); } }
From source file:com.sciencegadgets.client.ui.LinkPrompt.java
License:Open Source License
protected void updateIframeCode() { Style iframeStyle = iframeDisplay.getStyle(); if (isValidSpec(widthLabel, widthTextBox, widthUnits)) { double value = Double.parseDouble(widthTextBox.getValue()); String unit = widthUnits.getValue(); iframeStyle.setWidth(value, Unit.valueOf(unit)); } else {//from w ww. j ava 2 s . co m iframeStyle.setWidth(100, Unit.PCT); } if (isValidSpec(heightLabel, heightTextBox, heightUnits)) { double value = Double.parseDouble(heightTextBox.getValue()); String unit = heightUnits.getValue(); iframeStyle.setHeight(value, Unit.valueOf(unit)); } else { iframeStyle.setHeight(100, Unit.PCT); } String iframeCode = JSNICalls.elementToString(iframeDisplay).replace("&", "&"); iframeHandler.revert(iframeCode); }
From source file:com.smartgwt.mobile.client.widgets.Progressbar.java
License:Open Source License
/** * Number from 0 to 100, inclusive, for the percentage to be displayed graphically in this progressbar. * Sets {@link #getPercentDone() percentDone} to <code>newPercentDone</code>. * * @param newPercentDone percent to show as done (0-100). Default value is 0 * @param duration in seconds for bar to reach this percent done *//*from w ww .java 2 s .com*/ public void setPercentDone(final int newPercentDone, int duration) { if (percentDone == newPercentDone) return; if (0 <= newPercentDone && newPercentDone <= 100) { percentDone = newPercentDone; final Style barStyle = bar.getStyle(); if (duration == 0 || !isAttached() || !isVisible()) { barStyle.setProperty(DOMConstants.INSTANCE.getTransformPropertyName(), "none"); barStyle.setWidth(newPercentDone, Style.Unit.PCT); PercentChangedEvent.fire(this, percentDone); } else { barStyle.setProperty(DOMConstants.INSTANCE.getTransformPropertyName(), "width"); barStyle.setProperty(DOMConstants.INSTANCE.getTransitionDurationPropertyName(), duration + "s"); new Timer() { @Override public void run() { barStyle.setWidth(newPercentDone, Style.Unit.PCT); } }.schedule(1); } } else { throw new RuntimeException(newPercentDone + " is out of bounds"); } }
From source file:com.vaadin.addon.charts.client.ui.ChartOptionsWidget.java
public ChartOptionsWidget() { HighchartsScriptLoader.ensureInjected(); setElement(Document.get().createDivElement()); Style style = getElement().getStyle(); style.setWidth(0, Unit.PX); style.setHeight(0, Unit.PX);//from ww w. j av a2 s .c o m style.setOverflow(Overflow.HIDDEN); }
From source file:com.vaadin.addon.spreadsheet.client.GroupingWidget.java
protected void copyfields(GroupingWidget newWidget) { newWidget.collapsed = collapsed;// w w w . j a v a 2 s . c o m newWidget.index = index; newWidget.inversed = inversed; newWidget.btn.setInnerText(btn.getInnerText()); Style style = newWidget.getElement().getStyle(); newWidget.setStyleName(getStyleName()); if (marginLeft > -1) { style.setMarginLeft(marginLeft, Unit.PX); } if (marginTop > -1) { style.setMarginTop(marginTop, Unit.PX); } if (height > -1) { style.setHeight(height, Unit.PX); } if (width > -1) { style.setWidth(width, Unit.PX); } if (top > -1) { style.setTop(top, Unit.PX); } if (left > -1) { style.setLeft(left, Unit.PX); } }
From source file:com.vaadin.addon.spreadsheet.client.SheetWidget.java
/** * Updates the left & top style property for sheet panes depending if * headers are shown or not.// w w w . ja v a2s . co m */ void updateSheetPanePositions() { int extraSize = horizontalSplitPosition > 0 ? 1 : 0; if (spreadsheet.getAttribute("class").contains("report")) { extraSize = 0; } int widthIncrease = 0; if (rowHeaders != null && !rowHeaders.isEmpty()) { widthIncrease = getRowHeaderSize(); } int heightIncrease = 0; if (colHeaders != null && !colHeaders.isEmpty()) { heightIncrease = getColHeaderSize(); } // Measure formula bar height int formulaBarHeight = 0; if (actionHandler.getFormulaBarWidget() != null) { MeasuredSize measuredSize = new MeasuredSize(); measuredSize.measure(actionHandler.getFormulaBarWidget().getElement()); formulaBarHeight = (int) measuredSize.getOuterHeight(); } int addedHeaderHeight = updateExtraColumnHeaderElements(formulaBarHeight); int addedHeaderWidth = updateExtraRowHeaderElements(formulaBarHeight); updateExtraCornerElements(formulaBarHeight, addedHeaderHeight, addedHeaderWidth); if (!displayRowColHeadings) { widthIncrease = 0; heightIncrease = 0; } topOffset = heightIncrease + formulaBarHeight + addedHeaderHeight; leftOffset = widthIncrease + addedHeaderWidth; Style style = topLeftPane.getStyle(); style.setWidth(leftFrozenPanelWidth + widthIncrease + 1, Unit.PX); style.setHeight(topFrozenPanelHeight + heightIncrease, Unit.PX); style.setTop(formulaBarHeight + addedHeaderHeight, Unit.PX); style.setLeft(addedHeaderWidth, Unit.PX); style = topRightPane.getStyle(); // left offset is the same as the width increase style.setLeft(leftFrozenPanelWidth + leftOffset + extraSize, Unit.PX); style.setHeight(topFrozenPanelHeight + heightIncrease, Unit.PX); style.setTop(formulaBarHeight + addedHeaderHeight, Unit.PX); style = bottomLeftPane.getStyle(); // The +1 is to accommodate the vertical border of the freeze pane style.setWidth(leftFrozenPanelWidth + widthIncrease + 1, Unit.PX); style.setTop(topFrozenPanelHeight + topOffset, Unit.PX); style.setLeft(addedHeaderWidth, Unit.PX); style = sheet.getStyle(); style.setLeft(leftFrozenPanelWidth + leftOffset + extraSize, Unit.PX); style.setTop(topFrozenPanelHeight + topOffset, Unit.PX); style = corner.getStyle(); style.setTop(formulaBarHeight + addedHeaderHeight, Unit.PX); style.setLeft(addedHeaderWidth, Unit.PX); }
From source file:com.vaadin.client.debug.internal.Highlight.java
License:Apache License
/** * Highlight the given {@link Element} using the given color. * <p>//from w w w.j a v a 2s . com * Pass the returned highlight {@link Element} to {@link #hide(Element)} to * remove this particular highlight. * </p> * * @param element * Element to highlight * @param color * Color of highlight * @return Highlight element */ static Element show(Element element, String color) { if (element != null) { if (highlights == null) { highlights = new HashSet<Element>(); } Element highlight = DOM.createDiv(); Style style = highlight.getStyle(); style.setTop(element.getAbsoluteTop(), Unit.PX); style.setLeft(element.getAbsoluteLeft(), Unit.PX); int width = element.getOffsetWidth(); if (width < MIN_WIDTH) { width = MIN_WIDTH; } style.setWidth(width, Unit.PX); int height = element.getOffsetHeight(); if (height < MIN_HEIGHT) { height = MIN_HEIGHT; } style.setHeight(height, Unit.PX); RootPanel.getBodyElement().appendChild(highlight); style.setPosition(Position.ABSOLUTE); style.setZIndex(VWindow.Z_INDEX + 1000); style.setBackgroundColor(color); style.setOpacity(DEFAULT_OPACITY); if (BrowserInfo.get().isIE()) { style.setProperty("filter", "alpha(opacity=" + (DEFAULT_OPACITY * 100) + ")"); } highlights.add(highlight); return highlight; } return null; }
From source file:com.vaadin.client.extensions.FileDownloaderConnector.java
License:Apache License
@Override public void onClick(ClickEvent event) { final String url = getResourceUrl("dl"); if (url != null && !url.isEmpty()) { BrowserInfo browser = BrowserInfo.get(); if (browser.isIOS()) { Window.open(url, "_blank", ""); } else {/*from www . jav a 2 s . c om*/ if (iframe != null) { // make sure it is not on dom tree already, might start // multiple downloads at once iframe.removeFromParent(); } iframe = Document.get().createIFrameElement(); Style style = iframe.getStyle(); style.setVisibility(Visibility.HIDDEN); style.setHeight(0, Unit.PX); style.setWidth(0, Unit.PX); iframe.setFrameBorder(0); iframe.setTabIndex(-1); iframe.setSrc(url); RootPanel.getBodyElement().appendChild(iframe); } } }