]>
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 standard web CSS. */
23 Set
<String
> getWebCssPaths();
25 /** Relative paths to RAP specific CSS. */
26 Set
<String
> getRapCssPaths();
28 /** Relative paths to SWT specific CSS. */
29 Set
<String
> getSwtCssPaths();
31 /** Relative paths to images such as icons. */
32 Set
<String
> getImagesPaths();
34 /** Relative paths to fonts. */
35 Set
<String
> getFontsPaths();
37 /** Tags to be added to the header section of the HTML page. */
38 String
getHtmlHeaders();
40 /** The image registered at this path, or <code>null</code> if not found. */
41 Image
getImage(String path
);
43 /** The default icon size (typically the smallest). */
44 Integer
getDefaultIconSize();
46 /** Loads one of the relative path provided by the other methods. */
47 InputStream
loadPath(String path
) throws IOException
;
50 * And icon with this file name (without the extension), with a best effort to
51 * find the appropriate size, or <code>null</code> if not found.
53 * @param name An icon file name without path and extension.
54 * @param preferredSize the preferred size, if <code>null</code>,
55 * {@link #getDefaultIconSize()} will be tried.
57 Image
getIcon(String name
, Integer preferredSize
);
59 static CmsTheme
getCmsTheme(Composite parent
) {
60 CmsTheme theme
= (CmsTheme
) parent
.getData(CmsTheme
.class.getName());
63 Shell topShell
= parent
.getShell();
64 while (topShell
.getParent() != null)
65 topShell
= (Shell
) topShell
.getParent();
66 theme
= (CmsTheme
) topShell
.getData(CmsTheme
.class.getName());
67 parent
.setData(CmsTheme
.class.getName(), theme
);
72 static void registerCmsTheme(Shell shell
, CmsTheme theme
) {
74 Shell topShell
= shell
;
75 while (topShell
.getParent() != null)
76 topShell
= (Shell
) topShell
.getParent();
77 // check if already set
78 if (topShell
.getData(CmsTheme
.class.getName()) != null) {
79 CmsTheme registeredTheme
= (CmsTheme
) topShell
.getData(CmsTheme
.class.getName());
80 throw new IllegalArgumentException(
81 "Theme " + registeredTheme
.getThemeId() + " already registered in this shell");
83 topShell
.setData(CmsTheme
.class.getName(), theme
);