1 
2 /*
3  * PanmirrorCommandIcons.java
4  *
5  * Copyright (C) 2021 by RStudio, PBC
6  *
7  * Unless you have received this program directly from RStudio pursuant
8  * to the terms of a commercial license agreement with RStudio, then
9  * this program is licensed to you under the terms of version 3 of the
10  * GNU Affero General Public License. This program is distributed WITHOUT
11  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
13  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
14  *
15  */
16 
17 
18 
19 package org.rstudio.studio.client.panmirror.command;
20 
21 import java.util.HashMap;
22 
23 import org.rstudio.core.client.resources.ImageResource2x;
24 import org.rstudio.studio.client.application.ui.RStudioThemes;
25 
26 import com.google.gwt.resources.client.ImageResource;
27 
28 public class PanmirrorCommandIcons
29 {
30    public final String BLOCKQUOTE = "blockquote";
31    public final String BOLD = "bold";
32    public final String BULLET_LIST = "bullet_list";
33    public final String CITATION = "citation";
34    public final String CODE = "code";
35    public final String IMAGE = "image";
36    public final String ITALIC = "italic";
37    public final String UNDERLINE = "underline";
38    public final String OMNI = "omni";
39    public final String LINK = "link";
40    public final String NUMBERED_LIST = "numbered_list";
41    public final String TABLE = "table";
42    public final String CLEAR_FORMATTING = "clear_formatting";
43    public final String COMMENT = "comment";
44 
PanmirrorCommandIcons()45    private PanmirrorCommandIcons()
46    {
47       PanmirrorToolbarResources res = PanmirrorToolbarResources.INSTANCE;
48       icons_.put(BLOCKQUOTE, res.blockquote());
49       icons_.put(BOLD, res.bold());
50       icons_.put(dm(BOLD), res.bold_dm());
51       icons_.put(BULLET_LIST, res.bullet_list());
52       icons_.put(dm(BULLET_LIST), res.bullet_list_dm());
53       icons_.put(CITATION, res.citation());
54       icons_.put(dm(CITATION), res.citation_dm());
55       icons_.put(CODE, res.code());
56       icons_.put(dm(CODE), res.code_dm());
57       icons_.put(IMAGE, res.image());
58       icons_.put(ITALIC, res.italic());
59       icons_.put(dm(ITALIC), res.italic_dm());
60       icons_.put(UNDERLINE, res.underline());
61       icons_.put(dm(UNDERLINE), res.underline_dm());
62       icons_.put(OMNI, res.omni());
63       icons_.put(LINK, res.link());
64       icons_.put(NUMBERED_LIST, res.numbered_list());
65       icons_.put(dm(NUMBERED_LIST), res.numbered_list_dm());
66       icons_.put(TABLE, res.table());
67       icons_.put(CLEAR_FORMATTING, res.clear_formatting());
68       icons_.put(dm(CLEAR_FORMATTING), res.clear_formatting_dm());
69       icons_.put(COMMENT, res.comment());
70    }
71 
get(String name)72    public ImageResource get(String name)
73    {
74       ImageResource icon = null;
75       if (RStudioThemes.isEditorDark())
76          icon = icons_.get(dm(name));
77       if (icon == null)
78          icon = icons_.get(name);
79       if (icon != null)
80          icon = new ImageResource2x(icon);
81       return icon;
82    }
83 
dm(String icon)84    private String dm(String icon)
85    {
86       return icon + "_dm";
87    }
88 
89    public static PanmirrorCommandIcons INSTANCE = new PanmirrorCommandIcons();
90 
91    private HashMap<String,ImageResource> icons_ = new HashMap<>();
92 
93 }
94