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();
}
});
}
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;
}
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);
}
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));
}
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;
}
Aggregations