use of com.haulmont.cuba.desktop.DesktopResources in project cuba by cuba-platform.
the class DesktopThemeLoaderImpl method loadTheme.
@Override
public DesktopTheme loadTheme(String themeName) {
String themeLocations = config.getResourceLocations();
StrTokenizer tokenizer = new StrTokenizer(themeLocations);
String[] locationList = tokenizer.getTokenArray();
List<String> resourceLocationList = new ArrayList<>();
DesktopThemeImpl theme = createTheme(themeName, locationList);
theme.setName(themeName);
for (String location : locationList) {
resourceLocationList.add(getResourcesDir(themeName, location));
String xmlLocation = getConfigFileName(themeName, location);
Resource resource = resources.getResource(xmlLocation);
if (resource.exists()) {
try {
loadThemeFromXml(theme, resource);
} catch (IOException e) {
log.error("Error", e);
}
} else {
log.warn("Resource " + location + " not found, ignore it");
}
}
DesktopResources desktopResources = new DesktopResources(resourceLocationList, resources);
theme.setResources(desktopResources);
return theme;
}
use of com.haulmont.cuba.desktop.DesktopResources in project cuba by cuba-platform.
the class FontDialog method initUI.
private void initUI() {
Configuration configuration = AppBeans.get(Configuration.NAME);
DesktopConfig desktopConfig = configuration.getConfig(DesktopConfig.class);
setIconImage(null);
setIconImages(null);
setPreferredSize(new Dimension(400, 220));
setSize(new Dimension(400, 220));
setMinimumSize(new Dimension(380, 200));
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout(0, 5));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
// font properties panel
JPanel fontPrefsPanel = new JPanel();
fontPrefsPanel.setLayout(new BoxLayout(fontPrefsPanel, BoxLayout.X_AXIS));
fontFamilyBox = new JComboBox();
fontFamilyBox.setPreferredSize(new Dimension(160, -1));
String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
fontFamilyBox.setModel(new DefaultComboBoxModel<>(availableFonts));
fontSizeBox = new JComboBox();
fontSizeBox.setPreferredSize(new Dimension(60, -1));
fontSizeBox.setMaximumSize(new Dimension(60, Integer.MAX_VALUE));
fontSizeBox.setMinimumSize(new Dimension(60, 0));
fontSizeBox.setModel(new ListComboBoxModel<>(desktopConfig.getAvailableFontSizes()));
DesktopResources resources = App.getInstance().getResources();
boldToggle = new JToggleButton(resources.getIcon("font/bold.png"));
italicToggle = new JToggleButton(resources.getIcon("font/italic.png"));
underlineToggle = new JToggleButton(resources.getIcon("font/underline.png"));
fontPrefsPanel.add(fontFamilyBox);
fontPrefsPanel.add(fontSizeBox);
fontPrefsPanel.add(boldToggle);
fontPrefsPanel.add(italicToggle);
fontPrefsPanel.add(underlineToggle);
if (editFont != null) {
fontFamilyBox.setSelectedItem(editFont.getFamily());
fontSizeBox.setSelectedItem(editFont.getSize());
// toggle buttons
Map<TextAttribute, ?> attributes = editFont.getAttributes();
boldToggle.setSelected((editFont.getStyle() & Font.BOLD) == Font.BOLD);
italicToggle.setSelected((editFont.getStyle() & Font.ITALIC) == Font.ITALIC);
underlineToggle.setSelected(attributes.get(TextAttribute.UNDERLINE) == TextAttribute.UNDERLINE_ON);
} else {
fontFamilyBox.setSelectedIndex(0);
fontSizeBox.setSelectedIndex(0);
}
initListeners();
contentPane.add(fontPrefsPanel, BorderLayout.NORTH);
// preview panel
JPanel previewPanel = new JPanel();
previewPanel.setLayout(new GridBagLayout());
previewPanel.setPreferredSize(new Dimension(-1, 120));
previewPanel.setMinimumSize(new Dimension(0, 120));
previewPanel.setSize(-1, 120);
previewLabel = new JLabel("ABCDEFG abcdefg");
previewPanel.add(previewLabel);
previewLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
if (editFont != null)
previewLabel.setFont(editFont);
CollapsiblePanel groupBox = new CollapsiblePanel(previewPanel);
groupBox.setCollapsible(false);
groupBox.setCaption(messages.getMessage(getClass(), "FontDialog.preview"));
contentPane.add(groupBox, BorderLayout.CENTER);
// buttons panel
JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
JButton okBtn = new JButton(new AbstractAction(messages.getMessage(getClass(), "actions.Ok"), resources.getIcon("icons/ok.png")) {
@Override
public void actionPerformed(ActionEvent e) {
result = compileFont();
closeDialog();
}
});
okBtn.setPreferredSize(new Dimension(0, DesktopComponentsHelper.BUTTON_HEIGHT));
JButton cancelBtn = new JButton(new AbstractAction(messages.getMessage(getClass(), "actions.Cancel"), resources.getIcon("icons/cancel.png")) {
@Override
public void actionPerformed(ActionEvent e) {
closeDialog();
}
});
cancelBtn.setPreferredSize(new Dimension(0, DesktopComponentsHelper.BUTTON_HEIGHT));
buttonsPanel.add(okBtn);
buttonsPanel.add(cancelBtn);
contentPane.add(buttonsPanel, BorderLayout.SOUTH);
initToolTips();
setContentPane(contentPane);
pack();
applyLocation();
}
Aggregations