public DocTabLayoutPanel(boolean closeableTabs, int padding, int rightMargin) { super(BAR_HEIGHT, Style.Unit.PX); closeableTabs_ = closeableTabs; padding_ = padding; rightMargin_ = rightMargin; styles_ = ThemeResources.INSTANCE.themeStyles(); addStyleName(styles_.docTabPanel()); addStyleName(styles_.moduleTabPanel()); dragManager_ = new DragManager(); // listen for global drag events (these are broadcasted from other windows // to notify us of incoming drags) events_ = RStudioGinjector.INSTANCE.getEventBus(); events_.addHandler(DocTabDragStartedEvent.TYPE, dragManager_); // sink drag-related events on the tab bar element; unfortunately // GWT does not provide bits for the drag-related events, and Scheduler.get() .scheduleDeferred( new ScheduledCommand() { @Override public void execute() { Element tabBar = getTabBarElement(); DOM.sinkBitlessEvent(tabBar, "dragenter"); DOM.sinkBitlessEvent(tabBar, "dragover"); DOM.sinkBitlessEvent(tabBar, "dragend"); DOM.sinkBitlessEvent(tabBar, "dragleave"); DOM.sinkBitlessEvent(tabBar, "drop"); Event.setEventListener(tabBar, dragManager_); } }); }
private void ensureStylesInjected() { ThemeResources.INSTANCE.themeStyles().ensureInjected(); CoreResources.INSTANCE.styles().ensureInjected(); StudioResources.INSTANCE.styles().ensureInjected(); ConsoleResources.INSTANCE.consoleStyles().ensureInjected(); FileDialogResources.INSTANCE.styles().ensureInjected(); ManipulatorResources.INSTANCE.manipulatorStyles().ensureInjected(); PackagesCellTableResources.INSTANCE.cellTableStyle().ensureInjected(); FilesListCellTableResources.INSTANCE.cellTableStyle().ensureInjected(); ExportPlotResources.INSTANCE.styles().ensureInjected(); CodeSearchResources.INSTANCE.styles().ensureInjected(); ConsoleProgressDialog.ensureStylesInjected(); SupportPopupMenu.ensureStylesInjected(); SlideLabel.ensureStylesInjected(); ThemedButton.ensureStylesInjected(); ThemedPopupPanel.ensureStylesInjected(); InstallPackageDialog.ensureStylesInjected(); PublishPdfDialog.ensureStylesInjected(); ApplicationEndedPopupPanel.ensureStylesInjected(); ApplicationSerializationProgress.ensureStylesInjected(); HistoryPane.ensureStylesInjected(); Shelf.ensureStylesInjected(); ImportFileSettingsDialog.ensureStylesInjected(); ImportGoogleSpreadsheetDialog.ensureStylesInjected(); FindReplaceBar.ensureStylesInjected(); FontSizer.ensureStylesInjected(); PreferencesDialogBaseResources.INSTANCE.styles().ensureInjected(); PreferencesDialog.ensureStylesInjected(); ProjectPreferencesDialogResources.INSTANCE.styles().ensureInjected(); LinkColumn.ensureStylesInjected(); CaptionWithHelp.ensureStylesInjected(); CheckForUpdatesDialog.ensureStylesInjected(); UnsavedChangesDialog.ensureStylesInjected(); ChooseMirrorDialog.ensureStylesInjected(); ResizeGripper.ensureStylesInjected(); LineTableView.ensureStylesInjected(); ChangelistTable.ensureStylesInjected(); DiffFrame.ensureStylesInjected(); ViewFilePanel.ensureStylesInjected(); CodeBrowserEditingTargetWidget.ensureStylesInjected(); ShowPublicKeyDialog.ensureStylesInjected(); CreateKeyDialog.ensureStylesInjected(); SshKeyWidget.ensureStylesInjected(); IgnoreDialog.ensureStylesInjected(); WizardResources.INSTANCE.styles().ensureInjected(); NewProjectResources.INSTANCE.styles().ensureInjected(); StyleInjector.inject("button::-moz-focus-inner {border:0}"); }
public void addItem(final T item, boolean atEnd) { // wrap the widget in a panel that can receive click events, indicate // selection, etc. final ClickableHTMLPanel panel = new ClickableHTMLPanel(); panel.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { setSelectedIndex(panel_.getWidgetIndex(panel), true); } }); panel.addDomHandler( new DoubleClickHandler() { @Override public void onDoubleClick(DoubleClickEvent event) { SelectionCommitEvent.fire(WidgetListBox.this, item); } }, DoubleClickEvent.getType()); panel.add(item); // add the panel to our root layout panel if (!atEnd && panel_.getWidgetCount() > 0) { panel_.insert(panel, 0); items_.add(0, item); options_.add(0, panel); selectedIdx_++; } else { panel_.add(panel); items_.add(item); options_.add(panel); } panel.getElement().getStyle().setPadding(itemPaddingValue_, itemPaddingUnit_); panel.addStyleName(style_.anyItem()); panel.addStyleName(ThemeResources.INSTANCE.themeStyles().handCursor()); // if it's the first item, select it if (options_.size() == 1) setSelectedIndex(0); else if (!atEnd && getSelectedIndex() == 1 && options_.size() > 1) setSelectedIndex(0, true); updateEmptyText(); }
public ShadowBorder() { ThemeStyles styles = ThemeResources.INSTANCE.themeStyles(); layout_ = new LayoutPanel(); addPanel(styles.NW(), LEFT, TOP); addPanel(styles.N(), CENTER, TOP); addPanel(styles.NE(), RIGHT, TOP); addPanel(styles.W(), LEFT, MIDDLE); addPanel(styles.C(), CENTER, MIDDLE); addPanel(styles.E(), RIGHT, MIDDLE); addPanel(styles.SW(), LEFT, BOTTOM); addPanel(styles.S(), CENTER, BOTTOM); addPanel(styles.SE(), RIGHT, BOTTOM); initWidget(layout_); }
public ToolbarButton getToolbarButton() { if (toolbarButton_ == null) { String buttonText = activeProjectFile_ != null ? mruList_.getQualifiedLabel(activeProjectFile_) : "Project: (None)"; toolbarButton_ = new ToolbarButton(buttonText, RESOURCES.projectMenu(), this, true); if (activeProjectFile_ != null) { toolbarButton_.setTitle(activeProjectFile_); // also set the doc title so the browser tab carries the project if (!Desktop.isDesktop()) Document.get().setTitle("RStudio - " + buttonText); } if (activeProjectFile_ == null) { toolbarButton_.addStyleName(ThemeResources.INSTANCE.themeStyles().emptyProjectMenu()); } } return toolbarButton_; }
public class ToolbarButton extends FocusWidget { private class SimpleHasHandlers extends HandlerManager implements HasHandlers { private SimpleHasHandlers() { super(null); } } public <T extends EventHandler> ToolbarButton( String text, ImageResource leftImg, final HandlerManager eventBus, final GwtEvent<? extends T> targetEvent) { this( text, leftImg, new ClickHandler() { public void onClick(ClickEvent event) { eventBus.fireEvent(targetEvent); } }); } public <T extends EventHandler> ToolbarButton( ImageResource img, final HandlerManager eventBus, final GwtEvent<? extends T> targetEvent) { this(null, img, eventBus, targetEvent); } public ToolbarButton(String text, ImageResource leftImage, ClickHandler clickHandler) { this(text, leftImage, null, clickHandler); } public ToolbarButton(ImageResource image, ClickHandler clickHandler) { this(null, image, clickHandler); } public ToolbarButton(ToolbarPopupMenu menu, boolean rightAlignMenu) { this( (String) null, ThemeResources.INSTANCE.menuDownArrow(), (ImageResource) null, (ClickHandler) null); addMenuHandlers(menu, rightAlignMenu); addStyleName(styles_.toolbarButtonMenu()); addStyleName(styles_.toolbarButtonMenuOnly()); } public ToolbarButton(String text, ImageResource leftImage, ToolbarPopupMenu menu) { this(text, leftImage, menu, false); } public ToolbarButton( String text, ImageResource leftImage, ToolbarPopupMenu menu, boolean rightAlignMenu) { this(text, leftImage, ThemeResources.INSTANCE.menuDownArrow(), null); addMenuHandlers(menu, rightAlignMenu); addStyleName(styles_.toolbarButtonMenu()); } private void addMenuHandlers(final ToolbarPopupMenu menu, final boolean rightAlign) { menu_ = menu; /* * We want clicks on this button to toggle the visibility of the menu, * as well as having the menu auto-hide itself as it normally does. * It's necessary to manually track the visibility (menuShowing) because * in the case where the menu is showing, clicking on this button first * causes the menu to auto-hide and then our mouseDown handler is called * (so we can't rely on menu.isShowing(), it'll always be false by the * time you get into the mousedown handler). */ final boolean[] menuShowing = new boolean[1]; addMouseDownHandler( new MouseDownHandler() { public void onMouseDown(MouseDownEvent event) { event.preventDefault(); event.stopPropagation(); if (menuShowing[0]) menu.hide(); else { if (rightAlign) { menu.setPopupPositionAndShow( new PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { menu.setPopupPosition( (rightImageWidget_ != null ? rightImageWidget_.getAbsoluteLeft() : leftImageWidget_.getAbsoluteLeft()) + 20 - offsetWidth, ToolbarButton.this.getAbsoluteTop() + ToolbarButton.this.getOffsetHeight()); } }); } else { menu.showRelativeTo(ToolbarButton.this); } menuShowing[0] = true; addStyleName(styles_.toolbarButtonPushed()); } } }); menu.addCloseHandler( new CloseHandler<PopupPanel>() { public void onClose(CloseEvent<PopupPanel> popupPanelCloseEvent) { removeStyleName(styles_.toolbarButtonPushed()); Scheduler.get() .scheduleDeferred( new ScheduledCommand() { public void execute() { menuShowing[0] = false; } }); } }); } private ToolbarButton( String text, ImageResource leftImage, ImageResource rightImage, ClickHandler clickHandler) { super(); setElement(binder.createAndBindUi(this)); this.setStylePrimaryName(styles_.toolbarButton()); setText(text); if (leftImage != null) leftImageWidget_ = new Image(leftImage); else leftImageWidget_ = new Image(); leftImageWidget_.setStylePrimaryName(styles_.toolbarButtonLeftImage()); leftImageCell_.appendChild(leftImageWidget_.getElement()); if (rightImage != null) { rightImageWidget_ = new Image(rightImage); rightImageWidget_.setStylePrimaryName(styles_.toolbarButtonRightImage()); rightImageCell_.appendChild(rightImageWidget_.getElement()); } if (clickHandler != null) addClickHandler(clickHandler); } @Override public HandlerRegistration addClickHandler(ClickHandler clickHandler) { /* * When we directly subscribe to this widget's ClickEvent, sometimes the * click gets ignored (inconsistent repro but it happens enough to be * annoying). Doing it this way fixes it. */ hasHandlers_.addHandler(ClickEvent.getType(), clickHandler); final HandlerRegistration mouseDown = addMouseDownHandler( new MouseDownHandler() { public void onMouseDown(MouseDownEvent event) { event.preventDefault(); event.stopPropagation(); addStyleName(styles_.toolbarButtonPushed()); down_ = true; } }); final HandlerRegistration mouseOut = addMouseOutHandler( new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { event.preventDefault(); event.stopPropagation(); removeStyleName(styles_.toolbarButtonPushed()); down_ = false; } }); final HandlerRegistration mouseUp = addMouseUpHandler( new MouseUpHandler() { public void onMouseUp(MouseUpEvent event) { event.preventDefault(); event.stopPropagation(); if (down_) { down_ = false; removeStyleName(styles_.toolbarButtonPushed()); NativeEvent clickEvent = Document.get() .createClickEvent( 1, event.getScreenX(), event.getScreenY(), event.getClientX(), event.getClientY(), event.getNativeEvent().getCtrlKey(), event.getNativeEvent().getAltKey(), event.getNativeEvent().getShiftKey(), event.getNativeEvent().getMetaKey()); DomEvent.fireNativeEvent(clickEvent, hasHandlers_); } } }); return new HandlerRegistration() { public void removeHandler() { mouseDown.removeHandler(); mouseOut.removeHandler(); mouseUp.removeHandler(); } }; } public void click() { NativeEvent clickEvent = Document.get().createClickEvent(1, 0, 0, 0, 0, false, false, false, false); DomEvent.fireNativeEvent(clickEvent, hasHandlers_); } protected Toolbar getParentToolbar() { Widget parent = getParent(); while (parent != null) { if (parent instanceof Toolbar) return (Toolbar) parent; parent = parent.getParent(); } return null; } public ToolbarPopupMenu getMenu() { return menu_; } public void setLeftImage(ImageResource imageResource) { leftImageWidget_.setResource(imageResource); } public void setText(String label) { if (!StringUtil.isNullOrEmpty(label)) { label_.setInnerText(label); label_.getStyle().setDisplay(Display.BLOCK); removeStyleName(styles_.noLabel()); } else { label_.getStyle().setDisplay(Display.NONE); addStyleName(styles_.noLabel()); } } public String getText() { return StringUtil.notNull(label_.getInnerText()); } private boolean down_; private SimpleHasHandlers hasHandlers_ = new SimpleHasHandlers(); interface Binder extends UiBinder<Element, ToolbarButton> {} private ToolbarPopupMenu menu_; private static final Binder binder = GWT.create(Binder.class); private static final ThemeStyles styles_ = ThemeResources.INSTANCE.themeStyles(); @UiField TableCellElement leftImageCell_; @UiField TableCellElement rightImageCell_; @UiField DivElement label_; private Image leftImageWidget_; private Image rightImageWidget_; }
public class Toolbar extends Composite { private static class ChildWidgetList extends AbstractList<Widget> { private ChildWidgetList(ComplexPanel panel) { panel_ = panel; } @Override public Widget get(int index) { return panel_.getWidget(index); } @Override public int size() { return panel_.getWidgetCount(); } private ComplexPanel panel_; } private class ToolbarSeparatorManager extends SeparatorManager<Widget> { @Override protected boolean isSeparator(Widget item) { return styles_.toolbarSeparator().equals(item.getStylePrimaryName()); } @Override protected boolean isVisible(Widget item) { return item.isVisible(); } @Override protected void setVisible(Widget item, boolean visible) { item.setVisible(visible); } } public Toolbar(Widget[] leftWidgets, Widget[] rightWidgets) { this(); if (leftWidgets != null) { for (int i = 0; i < leftWidgets.length; i++) { if (i > 0) addLeftSeparator(); addLeftWidget(leftWidgets[i]); } } if (rightWidgets != null) { for (int i = 0; i < rightWidgets.length; i++) { if (i > 0) addRightSeparator(); addRightWidget(rightWidgets[i]); } } } public Toolbar() { super(); horizontalPanel_ = new HorizontalPanel(); horizontalPanel_.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); leftToolbarPanel_ = new HorizontalPanel(); leftToolbarPanel_.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); horizontalPanel_.add(leftToolbarPanel_); horizontalPanel_.setCellHorizontalAlignment( leftToolbarPanel_, HasHorizontalAlignment.ALIGN_LEFT); rightToolbarPanel_ = new HorizontalPanel(); rightToolbarPanel_.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); horizontalPanel_.add(rightToolbarPanel_); horizontalPanel_.setCellHorizontalAlignment( rightToolbarPanel_, HasHorizontalAlignment.ALIGN_RIGHT); initWidget(horizontalPanel_); setStyleName(styles_.toolbar()); } protected void manageSeparators() { separatorsInvalidated_ = false; new ToolbarSeparatorManager().manageSeparators(new ChildWidgetList(leftToolbarPanel_)); new ToolbarSeparatorManager().manageSeparators(new ChildWidgetList(rightToolbarPanel_)); } public void invalidateSeparators() { if (!separatorsInvalidated_) { separatorsInvalidated_ = true; Scheduler.get() .scheduleFinally( new ScheduledCommand() { public void execute() { manageSeparators(); } }); } } public <TWidget extends Widget> TWidget addLeftWidget(TWidget widget) { leftToolbarPanel_.add(widget); invalidateSeparators(); return widget; } public <TWidget extends Widget> TWidget addLeftWidget( TWidget widget, VerticalAlignmentConstant alignment) { addLeftWidget(widget); leftToolbarPanel_.setCellVerticalAlignment(widget, alignment); invalidateSeparators(); return widget; } public interface MenuSource { ToolbarPopupMenu getMenu(); } public Widget addLeftPopupMenu(Label label, final ToolbarPopupMenu menu) { return addToolbarPopupMenu(new SimpleMenuLabel(label), menu, true); } public Widget addLeftPopupMenu(MenuLabel label, final ToolbarPopupMenu menu) { return addToolbarPopupMenu(label, menu, true); } public Widget addRightPopupMenu(MenuLabel label, final ToolbarPopupMenu menu) { return addToolbarPopupMenu(label, menu, false); } public static Widget getSeparator() { Image sep = new Image(ThemeResources.INSTANCE.toolbarSeparator()); return sep; } public Widget addLeftSeparator() { Image sep = new ToolbarSeparator(); leftToolbarPanel_.add(sep); invalidateSeparators(); return sep; } public Widget addRightSeparator() { Image sep = new ToolbarSeparator(); rightToolbarPanel_.add(sep); invalidateSeparators(); return sep; } public <TWidget extends Widget> TWidget addRightWidget(TWidget widget) { rightToolbarPanel_.add(widget); invalidateSeparators(); return widget; } public void removeLeftWidget(Widget widget) { leftToolbarPanel_.remove(widget); } public void removeLeftWidgets() { removeAllWidgets(leftToolbarPanel_); } public void removeRightWidget(Widget widget) { rightToolbarPanel_.remove(widget); } public void removeRightWidgets() { removeAllWidgets(rightToolbarPanel_); } public void removeAllWidgets() { removeLeftWidgets(); removeRightWidgets(); } public int getHeight() { int offsetHeight = getOffsetHeight(); if (offsetHeight != 0) return offsetHeight; else return DEFAULT_HEIGHT; } private void removeAllWidgets(HorizontalPanel panel) { for (int i = panel.getWidgetCount() - 1; i >= 0; i--) panel.remove(i); } private Widget addToolbarPopupMenu(MenuLabel label, final ToolbarPopupMenu menu, boolean left) { return addPopupMenu( label, new MenuSource() { @Override public ToolbarPopupMenu getMenu() { return menu; } }, left); } private Widget addPopupMenu( final MenuLabel menuLabel, final MenuSource menuSource, boolean left) { final Widget label = menuLabel.asWidget(); label.setStylePrimaryName("rstudio-StrongLabel"); label.getElement().getStyle().setCursor(Style.Cursor.DEFAULT); label.getElement().getStyle().setOverflow(Overflow.HIDDEN); if (left) addLeftWidget(label); else addRightWidget(label); Image image = new Image(ThemeResources.INSTANCE.menuDownArrow()); image.getElement().getStyle().setMarginLeft(5, Unit.PX); image.getElement().getStyle().setMarginRight(8, Unit.PX); image.getElement().getStyle().setMarginBottom(2, Unit.PX); if (left) addLeftWidget(image); else addRightWidget(image); final ClickHandler clickHandler = new ClickHandler() { public void onClick(ClickEvent event) { ToolbarPopupMenu menu = menuSource.getMenu(); menu.showRelativeTo(label); menu.getElement().getStyle().setPaddingTop(3, Style.Unit.PX); } }; menuLabel.addClickHandler(clickHandler); image.addClickHandler(clickHandler); return image; } private HorizontalPanel horizontalPanel_; private HorizontalPanel leftToolbarPanel_; private HorizontalPanel rightToolbarPanel_; protected final ThemeStyles styles_ = ThemeResources.INSTANCE.themeStyles(); private boolean separatorsInvalidated_ = false; public static final int DEFAULT_HEIGHT = 22; }