1 /* 2 * LineActionButtonRenderer.java 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 package org.rstudio.studio.client.workbench.views.vcs.common.diff; 16 17 import com.google.gwt.core.client.GWT; 18 import com.google.gwt.resources.client.ClientBundle; 19 import com.google.gwt.resources.client.CssResource; 20 import com.google.gwt.resources.client.ImageResource; 21 import com.google.gwt.resources.client.ImageResource.ImageOptions; 22 import com.google.gwt.resources.client.ImageResource.RepeatStyle; 23 import com.google.gwt.safehtml.shared.SafeHtmlBuilder; 24 25 import org.rstudio.core.client.SafeHtmlUtil; 26 import org.rstudio.core.client.theme.res.ThemeStyles; 27 28 public class LineActionButtonRenderer 29 { 30 interface Resources 31 { buttonLeft()32 ImageResource buttonLeft(); 33 34 @ImageOptions(repeatStyle = ImageResource.RepeatStyle.Horizontal) buttonTile()35 ImageResource buttonTile(); 36 buttonRight()37 ImageResource buttonRight(); 38 styles()39 Styles styles(); 40 } 41 42 interface Styles extends CssResource 43 { button()44 String button(); left()45 String left(); center()46 String center(); right()47 String right(); 48 } 49 50 interface BlueResources extends Resources, ClientBundle 51 { 52 @Override 53 @Source("images/SmallBlueButtonLeft.png") buttonLeft()54 ImageResource buttonLeft(); 55 56 @Override 57 @ImageOptions(repeatStyle = RepeatStyle.Horizontal) 58 @Source("images/SmallBlueButtonTile.png") buttonTile()59 ImageResource buttonTile(); 60 61 @Override 62 @Source("images/SmallBlueButtonRight.png") buttonRight()63 ImageResource buttonRight(); 64 65 @Source("LineActionButton.css") styles()66 BlueStyles styles(); 67 } 68 69 interface BlueStyles extends Styles 70 {} 71 72 interface GrayResources extends Resources, ClientBundle 73 { 74 @Override 75 @Source("images/SmallGrayButtonLeft.png") buttonLeft()76 ImageResource buttonLeft(); 77 78 @Override 79 @ImageOptions(repeatStyle = RepeatStyle.Horizontal) 80 @Source("images/SmallGrayButtonTile.png") buttonTile()81 ImageResource buttonTile(); 82 83 @Override 84 @Source("images/SmallGrayButtonRight.png") buttonRight()85 ImageResource buttonRight(); 86 87 @Source("LineActionButton.css") styles()88 GrayStyles styles(); 89 } 90 91 interface GrayStyles extends Styles 92 {} 93 createBlue()94 public static LineActionButtonRenderer createBlue() 95 { 96 return new LineActionButtonRenderer(GWT.<Resources>create(BlueResources.class)); 97 } 98 createGray()99 public static LineActionButtonRenderer createGray() 100 { 101 return new LineActionButtonRenderer(GWT.<Resources>create(GrayResources.class)); 102 } 103 LineActionButtonRenderer(Resources resources)104 protected LineActionButtonRenderer(Resources resources) 105 { 106 resources_ = resources; 107 resources_.styles().ensureInjected(); 108 } 109 render(SafeHtmlBuilder builder, String text, String action)110 public void render(SafeHtmlBuilder builder, String text, String action) 111 { 112 { 113 builder.append(SafeHtmlUtil.createOpenTag( 114 "div", 115 "class", resources_.styles().button() + " " + 116 ThemeStyles.INSTANCE.handCursor(), 117 "data-action", action)); 118 { 119 builder.append(SafeHtmlUtil.createOpenTag( 120 "div", 121 "class", resources_.styles().left())); 122 builder.appendHtmlConstant("<br/></div>"); 123 124 builder.append(SafeHtmlUtil.createOpenTag( 125 "div", 126 "class", resources_.styles().center())); 127 { 128 builder.appendEscaped(text); 129 } 130 builder.appendHtmlConstant("</div>"); 131 132 builder.append(SafeHtmlUtil.createOpenTag( 133 "div", 134 "class", resources_.styles().right())); 135 builder.appendHtmlConstant("<br/></div>"); 136 } 137 builder.appendHtmlConstant("</div>"); 138 } 139 } 140 141 private final Resources resources_; 142 } 143