]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - eclipse/org.argeo.cms.swt/src/org/argeo/cms/swt/osgi/BundleCmsSwtTheme.java
Refactor CMS UX API
[lgpl/argeo-commons.git] / eclipse / org.argeo.cms.swt / src / org / argeo / cms / swt / osgi / BundleCmsSwtTheme.java
index b9b2751a7f55dd3772a1bf494a6cdd25ac897aff..b3fec78ecc88375914bb5bc8bdf3c47869ba0d6f 100644 (file)
@@ -5,6 +5,7 @@ import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.argeo.api.cms.ux.CmsIcon;
 import org.argeo.cms.osgi.BundleCmsTheme;
 import org.argeo.cms.swt.CmsSwtTheme;
 import org.eclipse.swt.graphics.Image;
@@ -17,7 +18,7 @@ public class BundleCmsSwtTheme extends BundleCmsTheme implements CmsSwtTheme {
 
        private Map<String, Map<Integer, String>> iconPaths = new HashMap<>();
 
-       public Image getImage(String path) {
+       protected Image getImage(String path) {
                if (!imageCache.containsKey(path)) {
                        try (InputStream in = getResourceAsStream(path)) {
                                if (in == null)
@@ -39,11 +40,11 @@ public class BundleCmsSwtTheme extends BundleCmsTheme implements CmsSwtTheme {
         * 
         * @param name          An icon file name without path and extension.
         * @param preferredSize the preferred size, if <code>null</code>,
-        *                      {@link #getDefaultIconSize()} will be tried.
+        *                      {@link #getSmallIconSize()} will be tried.
         */
        public Image getIcon(String name, Integer preferredSize) {
                if (preferredSize == null)
-                       preferredSize = getDefaultIconSize();
+                       preferredSize = getSmallIconSize();
                Map<Integer, String> subCache;
                if (!iconPaths.containsKey(name))
                        subCache = new HashMap<>();
@@ -55,11 +56,18 @@ public class BundleCmsSwtTheme extends BundleCmsTheme implements CmsSwtTheme {
                        paths: for (String p : getImagesPaths()) {
                                int lastSlash = p.lastIndexOf('/');
                                String fileName = p;
+                               String ext = "";
                                if (lastSlash >= 0)
                                        fileName = p.substring(lastSlash + 1);
                                int lastDot = fileName.lastIndexOf('.');
-                               if (lastDot >= 0)
+                               if (lastDot >= 0) {
+                                       ext = fileName.substring(lastDot + 1);
                                        fileName = fileName.substring(0, lastDot);
+                               }
+
+                               if ("svg".equals(ext))
+                                       continue paths;
+
                                if (fileName.equals(name)) {// matched
                                        Image img = getImage(p);
                                        int width = img.getBounds().width;
@@ -90,4 +98,14 @@ public class BundleCmsSwtTheme extends BundleCmsTheme implements CmsSwtTheme {
                return image;
        }
 
+       @Override
+       public Image getSmallIcon(CmsIcon icon) {
+               return getIcon(icon.name(), getSmallIconSize());
+       }
+
+       @Override
+       public Image getBigIcon(CmsIcon icon) {
+               return getIcon(icon.name(), getBigIconSize());
+       }
+
 }