List of usage examples for com.google.gwt.dom.client NodeList getLength
public int getLength()
From source file:org.rstudio.studio.client.workbench.exportplot.clipboard.CopyPlotToClipboardDesktopDialog.java
License:Open Source License
protected void copyAsBitmap(final Operation onCompleted) { final ExportPlotSizeEditor sizeEditor = getSizeEditor(); sizeEditor.prepareForExport(new Command() { @Override/* w ww .j a v a2 s . co m*/ public void execute() { if (BrowseCap.isCocoaDesktop()) { clipboard_.copyPlotToCocoaPasteboard(sizeEditor.getImageWidth(), sizeEditor.getImageHeight(), new Command() { @Override public void execute() { onCompleted.execute(); } }); } else { WindowEx win = sizeEditor.getPreviewIFrame().getContentWindow(); Document doc = win.getDocument(); NodeList<Element> images = doc.getElementsByTagName("img"); if (images.getLength() > 0) { ElementEx img = images.getItem(0).cast(); DesktopFrame frame = Desktop.getFrame(); frame.copyImageToClipboard(img.getClientLeft(), img.getClientTop(), img.getClientWidth(), img.getClientHeight()); } onCompleted.execute(); } } }); }
From source file:org.rstudio.studio.client.workbench.views.console.shell.impl.PlainTextEditorImplFirefox.java
License:Open Source License
private void stripZwsp(Node node) { if (node.getNodeType() == Node.TEXT_NODE) { while (true) { String text = node.getNodeValue(); int index = text.indexOf('\u200B'); if (index >= 0) DomUtils.deleteTextData((Text) node, index, 1); else// w w w.java2 s .c o m break; } } else if (node.getNodeType() == Node.ELEMENT_NODE) { NodeList<Node> nodes = node.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) stripZwsp(nodes.getItem(i)); } }
From source file:org.rstudio.studio.client.workbench.views.help.HelpPane.java
License:Open Source License
private void helpNavigated(Document doc) { NodeList<Element> elements = doc.getElementsByTagName("a"); for (int i = 0; i < elements.getLength(); i++) { ElementEx a = (ElementEx) elements.getItem(i); String href = a.getAttribute("href", 2); if (href == null) continue; if (href.contains(":") || href.endsWith(".pdf")) { // external links AnchorElement aElement = a.cast(); aElement.setTarget("_blank"); } else {/*from w w w . j ava2 s .com*/ // Internal links need to be handled in JavaScript so that // they can participate in virtual session history. This // won't have any effect for right-click > Show in New Window // but that's a good thing. a.setAttribute("onclick", "window.parent.helpNavigate(this.href, " + (BrowseCap.isLinuxDesktop() || BrowseCap.isWindowsDesktop() ? "true" : "false") + "); return false"); } } String effectiveTitle = getDocTitle(doc); title_.setText(effectiveTitle); this.fireEvent(new HelpNavigateEvent(doc.getURL(), effectiveTitle)); }
From source file:org.rstudio.studio.client.workbench.views.help.model.HelpInfo.java
License:Open Source License
public final ParsedInfo parse(String defaultSignature) { HashMap<String, String> values = new HashMap<String, String>(); HashMap<String, String> args = new HashMap<String, String>(); HashMap<String, String> slots = new HashMap<String, String>(); String html = getHTML();//from ww w .ja v a 2 s. co m if (html != null) { DivElement div = Document.get().createDivElement(); div.setInnerHTML(html); // disable all links NodeList<Element> anchors = div.getElementsByTagName("a"); for (int i = 0; i < anchors.getLength(); i++) { Element anchor = anchors.getItem(i); Element parent = anchor.getParentElement(); Node child = anchor.getFirstChild(); while (child != null) { parent.insertBefore(child, anchor); child = child.getNextSibling(); } } // parse all description lists NodeList<Element> descriptionLists = div.getElementsByTagName("dl"); for (int i = 0; i < descriptionLists.getLength(); i++) parseDescriptionList(args, descriptionLists.getItem(i)); // get all h2 and h3 headings NodeList<Element> h2headings = div.getElementsByTagName("h2"); NodeList<Element> h3headings = div.getElementsByTagName("h3"); ArrayList<Element> headings = new ArrayList<Element>(); for (int i = 0; i < h2headings.getLength(); i++) headings.add(h2headings.getItem(i)); for (int i = 0; i < h3headings.getLength(); i++) headings.add(h3headings.getItem(i)); // the first h2 heading is the title -- handle that specially if (headings.size() > 0) { Element titleElement = headings.get(0); String title = titleElement.getInnerText(); values.put("Title", title); } // iterate through them for (int i = 1; i < headings.size(); i++) { Element heading = headings.get(i); String name = heading.getInnerText(); if (name.equals("Arguments")) { parseArguments(args, heading); } if (name.equals("Slots")) { parseDescriptionList(slots, heading); } StringBuffer value = new StringBuffer(); Node sibling = heading.getNextSibling(); while (sibling != null && !sibling.getNodeName().toLowerCase().equals("h2") && !sibling.getNodeName().toLowerCase().equals("h3")) { value.append(DomUtils.getHtml(sibling)); sibling = sibling.getNextSibling(); } values.put(name, value.toString()); } } String signature = getSignature(); if (signature == null) signature = defaultSignature; return new ParsedInfo(getPackageName(), signature, values, args, slots); }
From source file:org.rstudio.studio.client.workbench.views.help.model.HelpInfo.java
License:Open Source License
private void parseDescriptionList(HashMap<String, String> args, Element heading) { Element table = (Element) DomUtils.findNode(heading, true, true, new NodePredicate() { public boolean test(Node n) { if (n.getNodeType() != Node.ELEMENT_NODE) return false; Element el = (Element) n; return el.getTagName().toUpperCase().equals("DL"); }/*from www . ja v a 2 s. c o m*/ }); if (table == null) { assert false : "Unexpected slots format: no <dl> entry found"; return; } NodeList<Node> children = table.getChildNodes(); int nChildren = children.getLength(); for (int i = 0; i < nChildren; i++) { Element child = (Element) children.getItem(i); if (child.getNodeName().toUpperCase().equals("DT")) { String argName = child.getInnerText().replaceAll(":", ""); Element nextChild = (Element) children.getItem(i + 1); if (nextChild.getNodeName().toUpperCase().equals("DD")) { String value = nextChild.getInnerHTML(); args.put(argName, value); } } } }
From source file:org.rstudio.studio.client.workbench.views.help.model.HelpInfo.java
License:Open Source License
private void parseArguments(HashMap<String, String> args, Element heading) { Element table = (Element) DomUtils.findNode(heading, true, true, new NodePredicate() { public boolean test(Node n) { if (n.getNodeType() != Node.ELEMENT_NODE) return false; Element el = (Element) n; return el.getTagName().toUpperCase().equals("TABLE") && "R argblock".equals(el.getAttribute("summary")); }/* www .ja v a 2 s. c o m*/ }); if (table == null) { assert false : "Unexpected help format, no argblock table found"; return; } TableElement t = (TableElement) table; NodeList<TableRowElement> rows = t.getRows(); for (int i = 0; i < rows.getLength(); i++) { TableRowElement row = rows.getItem(i); NodeList<TableCellElement> cells = row.getCells(); TableCellElement argNameCell = cells.getItem(0); TableCellElement argValueCell = cells.getItem(1); String argNameText = argNameCell.getInnerText(); String argValueHtml = argValueCell.getInnerHTML(); // argNameCell may be multiple comma-delimited arguments; // split them up if necessary (duplicate the help across args) String[] argNameTextSplat = argNameText.split("\\s*,\\s*"); for (int j = 0; j < argNameTextSplat.length; j++) args.put(argNameTextSplat[j], argValueHtml); } }
From source file:org.rstudio.studio.client.workbench.views.plots.ui.export.impl.CopyPlotToClipboardDesktopDialog.java
License:Open Source License
protected void copyAsBitmap(Operation onCompleted) { ImageFrame imageFrame = getSizeEditor().getImageFrame(); final WindowEx win = imageFrame.getElement().<IFrameElementEx>cast().getContentWindow(); Document doc = win.getDocument(); NodeList<Element> images = doc.getElementsByTagName("img"); if (images.getLength() > 0) { ElementEx img = images.getItem(0).cast(); Desktop.getFrame().copyImageToClipboard(img.getClientLeft(), img.getClientTop(), img.getClientWidth(), img.getClientHeight());// w w w . java 2 s . c o m } onCompleted.execute(); }
From source file:org.rstudio.studio.client.workbench.views.plots.ui.export.PlotsPanePreviewer.java
License:Open Source License
public Rectangle getPreviewClientRect() { WindowEx win = imageFrame_.getElement().<IFrameElementEx>cast().getContentWindow(); Document doc = win.getDocument(); NodeList<Element> images = doc.getElementsByTagName("img"); if (images.getLength() > 0) { ElementEx img = images.getItem(0).cast(); return new Rectangle(img.getClientLeft(), img.getClientTop(), img.getClientWidth(), img.getClientHeight());//from w ww . j a v a 2s. c om } else { return new Rectangle(0, 0, 0, 0); } }
From source file:org.sakaiproject.sgs2.client.Sgs2.java
License:Educational Community License
private void configureSakaiParentIframe(int setHeight) { // Resize parent Sakai iframe Document doc = getWindowParentDocument(); NodeList<Element> nodeList = doc.getElementsByTagName("iframe"); for (int i = 0; i < nodeList.getLength(); i++) { IFrameElement iframe = (IFrameElement) nodeList.getItem(i); if (iframe.getId().startsWith("Main")) { iframe.setAttribute("height", setHeight + "px"); iframe.setAttribute("style", "height: " + setHeight + "px;"); // IE Fix iframe.getStyle().setPropertyPx("height", setHeight); break; }/*from w w w . j a v a 2s. com*/ } }
From source file:org.silverpeas.mobile.client.components.base.PageContent.java
License:Open Source License
protected void setViewport() { NodeList<Element> metas = Document.get().getHead().getElementsByTagName("meta"); for (int i = 0; i < metas.getLength(); i++) { if (metas.getItem(i).getAttribute("name").equals("viewport")) { metas.getItem(i).setAttribute("content", "width=device-width, target-densitydpi=device-dpi, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"); }//from w w w . jav a 2s. co m } }