Search in sources :

Example 1 with CollapsiblePanel

use of com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel in project cuba by cuba-platform.

the class DesktopComponentsHelper method focusProblemComponent.

public static void focusProblemComponent(ValidationErrors errors) {
    Component component = null;
    if (!errors.getAll().isEmpty()) {
        component = errors.getAll().iterator().next().component;
    }
    if (component != null) {
        try {
            final JComponent jComponent = DesktopComponentsHelper.unwrap(component);
            java.awt.Component c = jComponent;
            java.awt.Component prevC = null;
            while (c != null) {
                if (c instanceof JTabbedPane && !((JTabbedPane) c).getSelectedComponent().equals(prevC)) {
                    final JTabbedPane tabbedPane = (JTabbedPane) c;
                    // do not focus tabbed pane on programmaticaly selection change
                    JTabbedPaneExt.setFocusOnSelectionChange(false);
                    tabbedPane.setSelectedComponent(prevC);
                    break;
                }
                if (c instanceof CollapsiblePanel && !((CollapsiblePanel) c).isExpanded()) {
                    ((CollapsiblePanel) c).setExpanded(true);
                    break;
                }
                prevC = c;
                c = c.getParent();
            }
            if (!JTabbedPaneExt.isFocusOnSelectionChange()) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        JTabbedPaneExt.setFocusOnSelectionChange(true);
                    }
                });
            }
            if (jComponent instanceof FocusableComponent) {
                ((FocusableComponent) jComponent).focus();
            } else {
                // focus first up component
                c = jComponent;
                while (c != null) {
                    if (c.isFocusable()) {
                        c.requestFocus();
                        break;
                    }
                    c = c.getParent();
                }
            }
        } catch (Exception e) {
            LoggerFactory.getLogger(DesktopComponentsHelper.class).warn("Error while problem component focusing", e);
        }
    }
}
Also used : FocusableComponent(com.haulmont.cuba.desktop.sys.vcl.FocusableComponent) FocusableComponent(com.haulmont.cuba.desktop.sys.vcl.FocusableComponent) Component(com.haulmont.cuba.gui.components.Component) CollapsiblePanel(com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel) java.awt(java.awt)

Example 2 with CollapsiblePanel

use of com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel 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)

Aggregations

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