Search in sources :

Example 1 with DesktopConfig

use of com.haulmont.cuba.desktop.DesktopConfig in project cuba by cuba-platform.

the class DesktopWindowManager method showNotification.

@Override
public void showNotification(String caption, String description, NotificationType type) {
    backgroundWorker.checkUIAccess();
    DesktopConfig config = configuration.getConfig(DesktopConfig.class);
    if (!NotificationType.isHTML(type)) {
        caption = preprocessHtmlMessage(escapeHtml(Strings.nullToEmpty(caption)));
        description = preprocessHtmlMessage(escapeHtml(Strings.nullToEmpty(description)));
    }
    String text = preparePopupText(caption, description);
    if (config.isDialogNotificationsEnabled() && type != NotificationType.TRAY && type != NotificationType.TRAY_HTML) {
        showNotificationDialog(text, type);
    } else {
        showNotificationPopup(text, type);
    }
}
Also used : DesktopConfig(com.haulmont.cuba.desktop.DesktopConfig)

Example 2 with DesktopConfig

use of com.haulmont.cuba.desktop.DesktopConfig in project cuba by cuba-platform.

the class DesktopWindow method formatTabCaption.

protected String formatTabCaption(final String caption, final String description) {
    DesktopConfig desktopConfig = configuration.getConfig(DesktopConfig.class);
    String tabCaption = formatTabDescription(caption, description);
    int maxLength = desktopConfig.getMainTabCaptionLength();
    if (tabCaption.length() > maxLength) {
        return tabCaption.substring(0, maxLength) + "...";
    } else {
        return tabCaption;
    }
}
Also used : DesktopConfig(com.haulmont.cuba.desktop.DesktopConfig)

Example 3 with DesktopConfig

use of com.haulmont.cuba.desktop.DesktopConfig 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();
}
Also used : Configuration(com.haulmont.cuba.core.global.Configuration) TextAttribute(java.awt.font.TextAttribute) DesktopConfig(com.haulmont.cuba.desktop.DesktopConfig) CollapsiblePanel(com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel) DesktopResources(com.haulmont.cuba.desktop.DesktopResources) EmptyBorder(javax.swing.border.EmptyBorder)

Example 4 with DesktopConfig

use of com.haulmont.cuba.desktop.DesktopConfig in project cuba by cuba-platform.

the class SwingXTableSettings method loadFontPreferences.

protected void loadFontPreferences(Element element) {
    // load font preferences
    String fontFamily = element.attributeValue("fontFamily");
    String fontSize = element.attributeValue("fontSize");
    String fontStyle = element.attributeValue("fontStyle");
    String fontUnderline = element.attributeValue("fontUnderline");
    if (!StringUtils.isBlank(fontFamily) && !StringUtils.isBlank(fontSize) && !StringUtils.isBlank(fontUnderline) && !StringUtils.isBlank(fontStyle)) {
        try {
            int size = Integer.parseInt(fontSize);
            int style = Integer.parseInt(fontStyle);
            String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
            int fontIndex = Arrays.asList(availableFonts).indexOf(fontFamily);
            if (fontIndex < 0) {
                log.debug("Unsupported font family, font settings not loaded");
                return;
            }
            Configuration configuration = AppBeans.get(Configuration.NAME);
            DesktopConfig desktopConfig = configuration.getConfig(DesktopConfig.class);
            int sizeIndex = desktopConfig.getAvailableFontSizes().indexOf(size);
            if (sizeIndex < 0) {
                log.debug("Unsupported font size, font settings not loaded");
                return;
            }
            Boolean underline = BooleanUtils.toBooleanObject(fontUnderline);
            @SuppressWarnings("MagicConstant") Font font = new Font(fontFamily, style, size);
            if (underline != null && Boolean.TRUE.equals(underline)) {
                Map<TextAttribute, Integer> attributes = new HashMap<>();
                attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
                font = font.deriveFont(attributes);
            }
            table.setFont(font);
        } catch (NumberFormatException ex) {
            log.debug("Broken font definition in user setting");
        }
    }
}
Also used : Configuration(com.haulmont.cuba.core.global.Configuration) TextAttribute(java.awt.font.TextAttribute) DesktopConfig(com.haulmont.cuba.desktop.DesktopConfig)

Aggregations

DesktopConfig (com.haulmont.cuba.desktop.DesktopConfig)4 Configuration (com.haulmont.cuba.core.global.Configuration)2 TextAttribute (java.awt.font.TextAttribute)2 DesktopResources (com.haulmont.cuba.desktop.DesktopResources)1 CollapsiblePanel (com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel)1 EmptyBorder (javax.swing.border.EmptyBorder)1