Updating DocumentComponent title based on its content

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Updating DocumentComponent title based on its content

Postby alf_cs » Wed Mar 02, 2011 1:03 am

Hi,

I am using JIDE DocumentComponent in the following way:
1) create instance of JTable
2) wrap the JTable instance in JScrollPane
3) wrap the JScrollPane in DocumentComponent
4) Add the DocumentComponent into DocumentPane.

I am aware of getDisplayTitle() method in DocumentComponent, which I can use to customized the DocumentComponent's title.
However, it seems that getDisplayTitle() method is called only when the DocumentPane is activated or de-activated.

Is there a way to update DocumentComponent title based on the content of JComponent (in this case, it is JTable) wrapped inside DocumentComponent?
For example: If the table is empty, i want to show the title in blue colour, but if the table contains at least 1 row, i want to show the title in red colour.

Cheers,
al
alf_cs
 
Posts: 4
Joined: Wed Mar 02, 2011 12:55 am

Re: Updating DocumentComponent title based on its content

Postby JIDE Support » Wed Mar 02, 2011 12:20 pm

Please try to add a table model listener to your table model. You could have your logic there to determine if it is an empty table or not. You then could invoke DocumentComponent#setBackground()/setTitle() then TdiGroup#updateTitle(DocumentComponent) to update the title as you wish.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Updating DocumentComponent title based on its content

Postby alf_cs » Tue Mar 08, 2011 7:12 am

Thanks Jide Support.

One question tho, when I setBackground(), the tab background changed to RED, however, the title bar's background colour did not change.

I read a jide component guide that overriding getDisplayTitle() to return HTML string like "<html><font bgcolor=red>title</font><html>" can do the trick.

I tried that, but it did not work. Can i call setTitle() and pass that html string as parameter?
alf_cs
 
Posts: 4
Joined: Wed Mar 02, 2011 12:55 am

Re: Updating DocumentComponent title based on its content

Postby JIDE Support » Tue Mar 08, 2011 12:42 pm

Can you please post an image so that I could better understand where you want to change the background?

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Updating DocumentComponent title based on its content

Postby alf_cs » Tue Mar 08, 2011 11:33 pm

Apology for the confusion.

I refer to http://www.jidesoft.com/products/JIDE_C ... _Guide.pdf page 8.
There is an example how to customized the title of DocumentComponent which is placed in DocumentPane.

The example shows how to change the title's font color and style.

What I want to change is the title's background. Expected result is as follows:
jide-colored-documentcomponent-title.JPG
jide-colored-documentcomponent-title.JPG (5.48 KiB) Viewed 24408 times


Hope this clarifies the confusion. Thanks.
alf_cs
 
Posts: 4
Joined: Wed Mar 02, 2011 12:55 am

Re: Updating DocumentComponent title based on its content

Postby JIDE Support » Wed Mar 09, 2011 1:41 pm

Sorry that I still cannot get what title bar is. DocumentComponent itself does not create any title bar. Tried to get the idea from JIDE DocumentPaneDemo and invoked JideTabbedPane#setBackgroundAt() for the child component of a DocumentComponent. Please give the attached test case a try and see if that's what you are looking for.

Thanks,
Attachments
DocumentPaneDemo.java
(16.16 KiB) Downloaded 1587 times
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Updating DocumentComponent title based on its content

Postby Walter Laan » Thu Mar 10, 2011 1:11 am

I think the OP is looking for something like this:
Code: Select all
    public static class CustomDocumentPane extends DocumentPane {

        private final Map<String, Color> bgcolors = new HashMap<String, Color>();
        private final Map<String, Color> fgcolors = new HashMap<String, Color>();

        private TabbedPaneCustomizer delegateCustomizer = null;
        private final TabbedPaneCustomizer customizer = new TabbedPaneCustomizer() {
            public void customize(final JideTabbedPane tabbedPane) {
                tabbedPane.setOpaque(true);

                if(delegateCustomizer != null) {
                    delegateCustomizer.customize(tabbedPane);
                }

                tabbedPane.setTabColorProvider(new ColorProvider() {
                    public Color getBackgroundAt(int tabIndex) {
                        Color color = findColor(bgcolors, tabIndex);
                        if(color == null && isXertoStyle()
                                && tabbedPane.getSelectedIndex() == tabIndex) {
                            return UIManager.getColor("JideTabbedPane.light");
                        }
                        return color;
                    }

                    public Color getForegroudAt(int tabIndex) {
                        Color color = findColor(fgcolors, tabIndex);
                        return color != null ? color : Color.BLACK;
                    }

                    public float getGradientRatio(int tabIndex) {
                        if(isXertoStyle()
                                && tabbedPane.getSelectedIndex() == tabIndex) {
                            return 1.0f;
                        }
                        return 0.9f;
                    }

                    private Color findColor(Map<String, Color> colors, int index) {
                        Component c = tabbedPane.getComponentAt(index);
                        if(c instanceof JComponent) {
                            return colors.get(((JComponent) c).getClientProperty("tabColorKey"));
                        }
                        else {
                            return null;
                        }
                    }
                });
            }
        };

        public CustomDocumentPane() {
            applyComponentOrientation(ComponentOrientation.getOrientation(getLocale()));

            super.setTabbedPaneCustomizer(customizer);
            super.setPopupMenuCustomizer(new PopupMenuCustomizer() {
                public void customizePopupMenu(JPopupMenu menu, final IDocumentPane pane, final String dragComponentName, IDocumentGroup dropGroup, boolean onTab) {
                    if(onTab) {
                        menu.addSeparator();

                        JideMenu m = new JideMenu("Color");

                        final ColorChooserPanel panel = new ColorChooserPanel(
                                ColorChooserPanel.PALETTE_COLOR_40);
                        panel.addItemListener(new ItemListener() {
                            public void itemStateChanged(ItemEvent e) {
                                String tabName = dragComponentName;
                                pane.getDocument(dragComponentName).getComponent().putClientProperty("tabColorKey", tabName);

                                Color color = panel.getSelectedColor();
                                bgcolors.put(tabName, color);

                                if(color != null) {
                                    double blackDiff = getColorDifference(color, Color.BLACK);
                                    double whiteDiff = getColorDifference(color, Color.WHITE);
                                    fgcolors.put(tabName, whiteDiff > blackDiff ? Color.WHITE : Color.BLACK);
                                }
                                else {
                                    fgcolors.remove(tabName);
                                }

                                CustomDocumentPane.this.repaint();
                            }
                        });
                        m.add(panel);

                        menu.add(m);
                    }
                }
            });
        }

        public static boolean isXertoStyle() {
            return LookAndFeelFactory.getStyle() == LookAndFeelFactory.XERTO_STYLE
                    || LookAndFeelFactory.getStyle() == LookAndFeelFactory.XERTO_STYLE_WITHOUT_MENU;
        }

        public static double getColorDifference(Color c1, Color c2) {
            int diffRed = c1.getRed() - c2.getRed();
            int diffGreen = c1.getGreen() - c2.getGreen();
            int diffBlue = c1.getBlue() - c2.getBlue();
            return Math.sqrt(diffRed * diffRed + diffGreen * diffGreen + diffBlue * diffBlue);
        }

        @Override
        public void setTabbedPaneCustomizer(TabbedPaneCustomizer customizer) {
            delegateCustomizer = customizer;
        }
    }
Walter Laan
 
Posts: 383
Joined: Mon May 01, 2006 12:13 am

Re: Updating DocumentComponent title based on its content

Postby alf_cs » Tue Mar 29, 2011 1:24 am

Thanks Jide Support for your help.
JideTabbedPane#setBackgroundAt() does the job.

It was not working previously, because other dev in my team did a custom implementation of tabbedpane UI which caused setBackgroundAt(Color) did not work as expected.

Thanks to Walter too for the code example.
alf_cs
 
Posts: 4
Joined: Wed Mar 02, 2011 12:55 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: Google [Bot] and 63 guests