Search in sources :

Example 56 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class ShinyGadgetDialog method addCaptionWithCloseButton.

private void addCaptionWithCloseButton(String caption) {
    final Image closeIcon = new Image(new ImageResource2x(ThemeResources.INSTANCE.closeDialog2x()));
    Style closeIconStyle = closeIcon.getElement().getStyle();
    closeIconStyle.setCursor(Style.Cursor.POINTER);
    closeIconStyle.setMarginTop(2, Unit.PX);
    FlexTable captionLayoutTable = new FlexTable();
    captionLayoutTable.setWidth("100%");
    captionLayoutTable.setText(0, 0, caption);
    captionLayoutTable.setWidget(0, 1, closeIcon);
    captionLayoutTable.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.HorizontalAlignmentConstant.endOf(Direction.LTR));
    HTML captionWidget = (HTML) getCaption();
    captionWidget.getElement().appendChild(captionLayoutTable.getElement());
    captionWidget.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            EventTarget target = event.getNativeEvent().getEventTarget();
            Element targetElement = (Element) target.cast();
            if (targetElement == closeIcon.getElement()) {
                closeIcon.fireEvent(event);
            }
        }
    });
    closeIcon.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            performClose();
        }
    });
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Element(com.google.gwt.dom.client.Element) FlexTable(com.google.gwt.user.client.ui.FlexTable) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x) Style(com.google.gwt.dom.client.Style) HTML(com.google.gwt.user.client.ui.HTML) Image(com.google.gwt.user.client.ui.Image) EventTarget(com.google.gwt.dom.client.EventTarget)

Example 57 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class AceEditorBackgroundLinkHighlighter method beginDetectClickTarget.

private void beginDetectClickTarget(int pageX, int pageY, int modifier) {
    if (!isRequiredClickModifier(modifier))
        return;
    MarkerRegistration activeMarker = getTargetedMarker(pageX, pageY);
    if (activeMarker == null)
        return;
    Element el = DomUtils.elementFromPoint(pageX, pageY);
    if (el == null)
        return;
    // the element might itself be the marker we want to update, or
    // it may be the editor instance. handle each case
    String id = activeMarker.getId();
    Element markerEl = el.hasClassName(id) ? el : DomUtils.getFirstElementWithClassName(el, id);
    if (markerEl == null)
        return;
    if (activeHighlightMarkerEl_ != null && activeHighlightMarkerEl_ != markerEl) {
        activeHighlightMarkerEl_.addClassName(RES.styles().highlight());
        activeHighlightMarkerEl_.removeClassName(RES.styles().hover());
    }
    markerEl.removeClassName(RES.styles().highlight());
    markerEl.addClassName(RES.styles().hover());
    activeHighlightMarkerEl_ = markerEl;
}
Also used : Element(com.google.gwt.dom.client.Element)

Example 58 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class PdfJsWindow method navigateTo.

public static void navigateTo(final PdfJsWindow win, final PdfLocation pdfLocation) {
    double factor = win.getCurrentScale() * 96 / 72;
    final double x = pdfLocation.getX() * factor;
    final double y = pdfLocation.getY() * factor;
    final double w = pdfLocation.getWidth() * factor;
    final double h = pdfLocation.getHeight() * factor;
    final Value<Integer> retries = new Value<Integer>(0);
    // Sometimes pageContainer is null during load, so retry every 100ms
    // until it's not, or we've tried 40 times.
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

        @Override
        public boolean execute() {
            Element pageContainer = win.getDocument().getElementById("pageContainer" + pdfLocation.getPage());
            if (pageContainer == null) {
                retries.setValue(retries.getValue() + 1);
                return retries.getValue() < 40;
            }
            if (pdfLocation.isFromClick()) {
                final DivElement div = win.getDocument().createDivElement();
                div.getStyle().setPosition(Style.Position.ABSOLUTE);
                div.getStyle().setTop(y, Unit.PX);
                div.getStyle().setLeft(x, Unit.PX);
                div.getStyle().setWidth(w, Unit.PX);
                div.getStyle().setHeight(h, Unit.PX);
                div.getStyle().setBackgroundColor("rgba(0, 126, 246, 0.1)");
                div.getStyle().setProperty("transition", "opacity 4s");
                // use DomUtils to set transition styles so gwt doesn't assert
                // an invalid style name (no camelCase) in debug mode
                DomUtils.setStyle(div, "-moz-transition", "opacity 4s");
                DomUtils.setStyle(div, "-webkit-transition", "opacity 4s");
                pageContainer.appendChild(div);
                Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {

                    @Override
                    public boolean execute() {
                        div.getStyle().setOpacity(0.0);
                        return false;
                    }
                }, 2000);
            }
            // scroll to the page
            win.goToPage(pdfLocation.getPage());
            // if the target isn't on-screen then scroll to it
            SyncTexCoordinates boundary = getBoundaryCoordinates(win, false);
            if (boundary != null && pdfLocation.getY() > boundary.getY()) {
                Element container = getViewerContainer(win);
                container.setScrollTop(Math.max(0, DomUtils.topRelativeTo(getViewerContainer(win), pageContainer) + (int) y - 180));
            }
            win.focus();
            return false;
        }
    }, 100);
}
Also used : DivElement(com.google.gwt.dom.client.DivElement) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) DivElement(com.google.gwt.dom.client.DivElement) Element(com.google.gwt.dom.client.Element) Value(org.rstudio.studio.client.common.Value)

Example 59 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class PdfJsWindow method firePageClickEvent.

private static void firePageClickEvent(PdfJsWindow win, NativeEvent nativeEvent, Element el) {
    if (!DomUtils.isCommandClick(nativeEvent))
        return;
    Element pageEl = el;
    while (pageEl != null) {
        if (pageEl.getId().matches("^pageContainer([\\d]+)$")) {
            break;
        }
        pageEl = pageEl.getParentElement();
    }
    if (pageEl == null)
        return;
    int page = getContainerPageNum(pageEl);
    int pageX = nativeEvent.getClientX() + win.getDocument().getScrollLeft() + win.getDocument().getBody().getScrollLeft() - pageEl.getAbsoluteLeft();
    int pageY = nativeEvent.getClientY() + win.getDocument().getDocumentElement().getScrollTop() + win.getDocument().getBody().getScrollTop() - pageEl.getAbsoluteTop();
    handlers_.fireEvent(new LookupSynctexSourceEvent(new SyncTexCoordinates(page, (int) ((pageX / win.getCurrentScale() / 96) * 72), (int) ((pageY / win.getCurrentScale() / 96) * 72)), true));
}
Also used : LookupSynctexSourceEvent(org.rstudio.studio.client.pdfviewer.events.LookupSynctexSourceEvent) DivElement(com.google.gwt.dom.client.DivElement) Element(com.google.gwt.dom.client.Element)

Example 60 with Element

use of com.google.gwt.dom.client.Element in project rstudio by rstudio.

the class ModifyKeyboardShortcutsWidget method editableTextColumn.

private Column<KeyboardShortcutEntry, String> editableTextColumn(String name, final ValueGetter<KeyboardShortcutEntry> getter) {
    EditTextCell editTextCell = new EditTextCell() {

        @Override
        public void onBrowserEvent(final Context context, final Element parent, final String value, final NativeEvent event, final ValueUpdater<String> updater) {
            // handler.
            if (event.getType().equals("keyup") && event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
                parent.getFirstChildElement().blur();
                return;
            }
            super.onBrowserEvent(context, parent, value, event, updater);
        }
    };
    Column<KeyboardShortcutEntry, String> column = new Column<KeyboardShortcutEntry, String>(editTextCell) {

        @Override
        public String getValue(KeyboardShortcutEntry binding) {
            return getter.getValue(binding);
        }
    };
    column.setFieldUpdater(new FieldUpdater<KeyboardShortcutEntry, String>() {

        @Override
        public void update(int index, KeyboardShortcutEntry binding, String value) {
            KeySequence keys = KeySequence.fromShortcutString(value);
            // adding a new key sequence.
            if (keys.equals(binding.getOriginalKeySequence())) {
                changes_.remove(binding);
                binding.restoreOriginalKeySequence();
            } else {
                KeyboardShortcutEntry newBinding = new KeyboardShortcutEntry(binding.getId(), binding.getName(), keys, binding.getCommandType(), true, binding.getContext());
                changes_.put(binding, newBinding);
                binding.setKeySequence(keys);
            }
            table_.setKeyboardSelectedColumn(0);
            updateData(dataProvider_.getList());
        }
    });
    column.setSortable(true);
    table_.addColumn(column, new TextHeader(name));
    return column;
}
Also used : EditTextCell(com.google.gwt.cell.client.EditTextCell) Element(com.google.gwt.dom.client.Element) TableRowElement(com.google.gwt.dom.client.TableRowElement) TextHeader(com.google.gwt.user.cellview.client.TextHeader) JsArrayString(com.google.gwt.core.client.JsArrayString) ValueUpdater(com.google.gwt.cell.client.ValueUpdater) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

Element (com.google.gwt.dom.client.Element)340 DivElement (com.google.gwt.dom.client.DivElement)19 TableRowElement (com.google.gwt.dom.client.TableRowElement)19 NativeEvent (com.google.gwt.dom.client.NativeEvent)16 Test (org.junit.Test)14 EventTarget (com.google.gwt.dom.client.EventTarget)11 SVGSVGElement (elemental.svg.SVGSVGElement)11 InputElement (com.google.gwt.dom.client.InputElement)10 Node (com.google.gwt.dom.client.Node)9 TableCellElement (com.google.gwt.dom.client.TableCellElement)9 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)8 AnchorElement (com.google.gwt.dom.client.AnchorElement)8 ImageElement (com.google.gwt.dom.client.ImageElement)8 LabelElement (com.google.gwt.dom.client.LabelElement)8 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)8 Image (com.google.gwt.user.client.ui.Image)8 SpanElement (com.google.gwt.dom.client.SpanElement)7 Style (com.google.gwt.dom.client.Style)7 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)7 Widget (com.google.gwt.user.client.ui.Widget)7