]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ui/CmsTheme.java
Prepare next development cycle
[lgpl/argeo-commons.git] / ui / CmsTheme.java
1 package org.argeo.cms.ui;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.Set;
6
7 import org.eclipse.swt.graphics.Image;
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.swt.widgets.Shell;
10
11 /** A CMS theme which can be applied to web apps as well as desktop apps. */
12 public interface CmsTheme {
13 /** Unique ID of this theme. */
14 String getThemeId();
15
16 /**
17 * Load a resource as an input stream, base don its relative path, or
18 * <code>null</code> if not found
19 */
20 InputStream getResourceAsStream(String resourceName) throws IOException;
21
22 /** Relative paths to RAP specific CSS. */
23 Set<String> getRapCssPaths();
24
25 /** Relative paths to images such as icons. */
26 Set<String> getImagesPaths();
27
28 /** Tags to be added to the header section of the HTML page. */
29 String getHtmlHeaders();
30
31 /** The image registered at this path, or <code>null</code> if not found. */
32 Image getImage(String path);
33
34 /** The default icon size (typically the smallest). */
35 Integer getDefaultIconSize();
36
37 /**
38 * And icon with this file name (without the extension), with a best effort to
39 * find the appropriate size, or <code>null</code> if not found.
40 *
41 * @param name An icon file name without path and extension.
42 * @param preferredSize the preferred size, if <code>null</code>,
43 * {@link #getDefaultIconSize()} will be tried.
44 */
45 Image getIcon(String name, Integer preferredSize);
46
47 static CmsTheme getCmsTheme(Composite parent) {
48 CmsTheme theme = (CmsTheme) parent.getData(CmsTheme.class.getName());
49 if (theme == null) {
50 // find parent shell
51 Shell topShell = parent.getShell();
52 while (topShell.getParent() != null)
53 topShell = (Shell) topShell.getParent();
54 theme = (CmsTheme) topShell.getData(CmsTheme.class.getName());
55 parent.setData(CmsTheme.class.getName(), theme);
56 }
57 return theme;
58 }
59
60 static void registerCmsTheme(Shell shell, CmsTheme theme) {
61 // find parent shell
62 Shell topShell = shell;
63 while (topShell.getParent() != null)
64 topShell = (Shell) topShell.getParent();
65 // check if already set
66 if (topShell.getData(CmsTheme.class.getName()) != null) {
67 CmsTheme registeredTheme = (CmsTheme) topShell.getData(CmsTheme.class.getName());
68 throw new IllegalArgumentException(
69 "Theme " + registeredTheme.getThemeId() + " already registered in this shell");
70 }
71 topShell.setData(CmsTheme.class.getName(), theme);
72 }
73
74 }