]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/CmsTheme.java
1 package org
.argeo
.cms
.ui
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
7 import org
.eclipse
.swt
.graphics
.Image
;
8 import org
.eclipse
.swt
.widgets
.Composite
;
9 import org
.eclipse
.swt
.widgets
.Shell
;
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. */
17 * Load a resource as an input stream, base don its relative path, or
18 * <code>null</code> if not found
20 InputStream
getResourceAsStream(String resourceName
) throws IOException
;
22 /** Relative paths to RAP specific CSS. */
23 Set
<String
> getRapCssPaths();
25 /** Relative paths to images such as icons. */
26 Set
<String
> getImagesPaths();
28 /** Tags to be added to the header section of the HTML page. */
29 String
getHtmlHeaders();
31 /** The image registered at this path, or <code>null</code> if not found. */
32 Image
getImage(String path
);
34 /** The default icon size (typically the smallest). */
35 Integer
getDefaultIconSize();
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.
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.
45 Image
getIcon(String name
, Integer preferredSize
);
47 static CmsTheme
getCmsTheme(Composite parent
) {
48 CmsTheme theme
= (CmsTheme
) parent
.getData(CmsTheme
.class.getName());
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
);
60 static void registerCmsTheme(Shell shell
, CmsTheme theme
) {
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");
71 topShell
.setData(CmsTheme
.class.getName(), theme
);