SubstanceRootPaneUI's minimumLayoutSize

View: New views
13 Messages — Rating Filter:   Alert me  

SubstanceRootPaneUI's minimumLayoutSize

by Gábor Pápai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Kirill!

Why is "tpHeight" variable commented in SubstanceRootPaneUI's minimumLayoutSize ? It causes my dialogs to be too tall :(

public Dimension minimumLayoutSize(Container parent) {
...
// int tpHeight = 0;
....
// tpHeight = tpd.height;
....
return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth)+ i.left + i.right,
                     cpHeight + mbHeight + tpWidth + i.top + i.bottom);                  
}


Thx, Gábor Pápai


Parent Message unknown Re: SubstanceRootPaneUI's minimumLayoutSize

by Kirill Grouchnikov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
This code is the same as in MetalRootPaneUI - the tpHeight is computed there but never used. Would you mind creating a small complete example that is sized differently under Substance and Metal?

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Tuesday, July 15, 2008 5:20:20 AM
Subject: SubstanceRootPaneUI's minimumLayoutSize

Hi Kirill!

Why is "tpHeight" variable commented in SubstanceRootPaneUI's minimumLayoutSize ? It causes my dialogs to be too tall :(

public Dimension minimumLayoutSize(Container parent) {
...
// int tpHeight = 0;
....
// tpHeight = tpd.height;
....
return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth)+ i.left + i.right,
                     cpHeight + mbHeight + tpWidth + i.top + i.bottom);                  
}


Thx, Gábor Pápai



Re: SubstanceRootPaneUI's minimumLayoutSize

by Gábor Pápai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the quick reply, you're right, the MetalRootPaneUI uses the same code, and I assume it's ok, my problem should be somewhere else. I'd done some customization in the Substance laf (without touching the library's source), so I may have screwed something up possibly (mmmm, I use my own TitlePane...). Sorry for wasting your time.

Thanks
Gábor
 

On Tue, Jul 15, 2008 at 4:18 PM, Kirill Grouchnikov <kirillcool@...> wrote:
This code is the same as in MetalRootPaneUI - the tpHeight is computed there but never used. Would you mind creating a small complete example that is sized differently under Substance and Metal?

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Tuesday, July 15, 2008 5:20:20 AM
Subject: SubstanceRootPaneUI's minimumLayoutSize

Hi Kirill!

Why is "tpHeight" variable commented in SubstanceRootPaneUI's minimumLayoutSize ? It causes my dialogs to be too tall :(

public Dimension minimumLayoutSize(Container parent) {
...
// int tpHeight = 0;
....
// tpHeight = tpd.height;
....
return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth)+ i.left + i.right,
                     cpHeight + mbHeight + tpWidth + i.top + i.bottom);                  
}


Thx, Gábor Pápai




Parent Message unknown Re: SubstanceRootPaneUI's minimumLayoutSize

by Kirill Grouchnikov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
No problem, Gabor.

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Tuesday, July 15, 2008 7:31:19 AM
Subject: Re: SubstanceRootPaneUI's minimumLayoutSize

Thanks for the quick reply, you're right, the MetalRootPaneUI uses the same code, and I assume it's ok, my problem should be somewhere else. I'd done some customization in the Substance laf (without touching the library's source), so I may have screwed something up possibly (mmmm, I use my own TitlePane...). Sorry for wasting your time.

Thanks
Gábor
 

On Tue, Jul 15, 2008 at 4:18 PM, Kirill Grouchnikov <kirillcool@...> wrote:
This code is the same as in MetalRootPaneUI - the tpHeight is computed there but never used. Would you mind creating a small complete example that is sized differently under Substance and Metal?

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Tuesday, July 15, 2008 5:20:20 AM
Subject: SubstanceRootPaneUI's minimumLayoutSize

Hi Kirill!

Why is "tpHeight" variable commented in SubstanceRootPaneUI's minimumLayoutSize ? It causes my dialogs to be too tall :(

public Dimension minimumLayoutSize(Container parent) {
...
// int tpHeight = 0;
....
// tpHeight = tpd.height;
....
return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth)+ i.left + i.right,
                     cpHeight + mbHeight + tpWidth + i.top + i.bottom);                  
}


Thx, Gábor Pápai





Re: SubstanceRootPaneUI's minimumLayoutSize

by Gábor Pápai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Kirill!

Back to my minimum layout size problem. I've found my problem in Sun's bugzilla:
http://bugs.sun.com/view_bug.do?bug_id=4916923

A small test program (in case file attacment isn't working it's copied here). I use custom titlepane component.
The bugfix is in the FixedRootLayout class, preferredLayoutSize() and minimumLayoutSize() methods. Commented tpHeight is uncommented, and used.

(It tested against the last development version prior jul.20, because after that it doesn't work for me, and I don't have time for a correct bug report (it complains about null pointer exception at multiuidefaults or something like that).)

I hope it helps (and you fix that small problem :) ).

Thanks,
     Gábor

package test;

import java.awt.BorderLayout;
import java.awt.Window;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;

import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;

import de.coryx.cpt.swing.Dialog;

public class SmallDialogSubstance {

    public static final boolean FIX_MODE = false;
    public static final String  TITLE    = "This is a very-very long title, yep, very-very long title.";

    public SmallDialogSubstance() {

        try {
            UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
            JDialog.setDefaultLookAndFeelDecorated(true);
            JFrame.setDefaultLookAndFeelDecorated(true);

            UIDefaults uiDef = UIManager.getDefaults();
            uiDef.put("RootPaneUI", "test.RootPaneUI");

            Dialog dlgMain = new Dialog((Window) null, "this title isn't shown.");

            dlgMain.setCaptionComponent(new JLabel("Custom caption component"));

            dlgMain.setDefaultCloseOperation(Dialog.DISPOSE_ON_CLOSE);
            dlgMain.setLayout(new BorderLayout());
            dlgMain.add(new JLabel("Hello world!"), BorderLayout.CENTER);
            dlgMain.pack();
            dlgMain.setVisible(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                new SmallDialogSubstance();
            }
        });
    }
}

package test;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.LayoutManager2;
import java.awt.Rectangle;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.plaf.ComponentUI;

import org.jvnet.substance.SubstanceRootPaneUI;

public class RootPaneUI extends SubstanceRootPaneUI {

    public static ComponentUI createUI(JComponent c) {
        return new RootPaneUI();
    }

    public JComponent createTitlePane(JRootPane root) {
        // custom titlepane
        return new JLabel(SmallDialogSubstance.TITLE);
    }

    private LayoutManager createLayoutManager() {
        return new FixedRootLayout();
    }

    private void installLayout(JRootPane root) {
        root.setLayout(createLayoutManager());
    }

    public void installUI(JComponent c) {
        super.installUI(c);

        // whether use fix mode or not
        if (SmallDialogSubstance.FIX_MODE) {
            JRootPane root = (JRootPane) c;
            int style = root.getWindowDecorationStyle();
            if (style != JRootPane.NONE) {
                installLayout(root);
            }
        }
    }

    private static class FixedRootLayout implements LayoutManager2 {

        public Dimension preferredLayoutSize(Container parent) {
            Dimension cpd, mbd, tpd;
            int cpWidth = 0;
            int cpHeight = 0;
            int mbWidth = 0;
            int mbHeight = 0;
            int tpWidth = 0;
            int tpHeight = 0;
            Insets i = parent.getInsets();
            JRootPane root = (JRootPane) parent;

            if (root.getContentPane() != null) {
                cpd = root.getContentPane().getPreferredSize();
            } else {
                cpd = root.getSize();
            }
            if (cpd != null) {
                cpWidth = cpd.width;
                cpHeight = cpd.height;
            }

            if (root.getJMenuBar() != null) {
                mbd = root.getJMenuBar().getPreferredSize();
                if (mbd != null) {
                    mbWidth = mbd.width;
                    mbHeight = mbd.height;
                }
            }

            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    tpd = titlePane.getPreferredSize();
                    if (tpd != null) {
                        tpWidth = tpd.width;
                        tpHeight = tpd.height;
                    }
                }
            }

            return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpHeight + i.top + i.bottom);
        }

        public Dimension minimumLayoutSize(Container parent) {
            Dimension cpd, mbd, tpd;
            int cpWidth = 0;
            int cpHeight = 0;
            int mbWidth = 0;
            int mbHeight = 0;
            int tpWidth = 0;
            int tpHeight = 0;
            Insets i = parent.getInsets();
            JRootPane root = (JRootPane) parent;

            if (root.getContentPane() != null) {
                cpd = root.getContentPane().getMinimumSize();
            } else {
                cpd = root.getSize();
            }
            if (cpd != null) {
                cpWidth = cpd.width;
                cpHeight = cpd.height;
            }

            if (root.getJMenuBar() != null) {
                mbd = root.getJMenuBar().getMinimumSize();
                if (mbd != null) {
                    mbWidth = mbd.width;
                    mbHeight = mbd.height;
                }
            }
            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    tpd = titlePane.getMinimumSize();
                    if (tpd != null) {
                        tpWidth = tpd.width;
                        tpHeight = tpd.height;
                    }
                }
            }

            return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpHeight + i.top + i.bottom);
        }

        public Dimension maximumLayoutSize(Container target) {
            Dimension cpd, mbd, tpd;
            int cpWidth = Integer.MAX_VALUE;
            int cpHeight = Integer.MAX_VALUE;
            int mbWidth = Integer.MAX_VALUE;
            int mbHeight = Integer.MAX_VALUE;
            int tpWidth = Integer.MAX_VALUE;
            int tpHeight = Integer.MAX_VALUE;
            Insets i = target.getInsets();
            JRootPane root = (JRootPane) target;

            if (root.getContentPane() != null) {
                cpd = root.getContentPane().getMaximumSize();
                if (cpd != null) {
                    cpWidth = cpd.width;
                    cpHeight = cpd.height;
                }
            }

            if (root.getJMenuBar() != null) {
                mbd = root.getJMenuBar().getMaximumSize();
                if (mbd != null) {
                    mbWidth = mbd.width;
                    mbHeight = mbd.height;
                }
            }

            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    tpd = titlePane.getMaximumSize();
                    if (tpd != null) {
                        tpWidth = tpd.width;
                        tpHeight = tpd.height;
                    }
                }
            }

            int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
            // Only overflows if 3 real non-MAX_VALUE heights, sum to >
            // MAX_VALUE
            // Only will happen if sums to more than 2 billion units. Not
            // likely.
            if (maxHeight != Integer.MAX_VALUE) {
                maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
            }

            int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
            // Similar overflow comment as above
            if (maxWidth != Integer.MAX_VALUE) {
                maxWidth += i.left + i.right;
            }

            return new Dimension(maxWidth, maxHeight);
        }

        public void layoutContainer(Container parent) {
            JRootPane root = (JRootPane) parent;
            Rectangle b = root.getBounds();
            Insets i = root.getInsets();
            int nextY = 0;
            int w = b.width - i.right - i.left;
            int h = b.height - i.top - i.bottom;

            if (root.getLayeredPane() != null) {
                root.getLayeredPane().setBounds(i.left, i.top, w, h);
            }
            if (root.getGlassPane() != null) {
                root.getGlassPane().setBounds(i.left, i.top, w, h);
            }
            // Note: This is laying out the children in the layeredPane,
            // technically, these are not our children.
            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    Dimension tpd = titlePane.getPreferredSize();
                    if (tpd != null) {
                        int tpHeight = tpd.height;
                        titlePane.setBounds(0, 0, w, tpHeight);
                        nextY += tpHeight;
                    }
                }
            }
            if (root.getJMenuBar() != null) {
                Dimension mbd = root.getJMenuBar().getPreferredSize();
                root.getJMenuBar().setBounds(0, nextY, w, mbd.height);
                nextY += mbd.height;
            }
            if (root.getContentPane() != null) {
                // Dimension cpd = root.getContentPane().getPreferredSize();
                root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY);
            }
        }

        public void addLayoutComponent(String name, Component comp) {}

        public void removeLayoutComponent(Component comp) {}

        public void addLayoutComponent(Component comp, Object constraints) {}

        public float getLayoutAlignmentX(Container target) {
            return 0.0f;
        }

        public float getLayoutAlignmentY(Container target) {
            return 0.0f;
        }

        public void invalidateLayout(Container target) {}
    }

}






On Tue, Jul 15, 2008 at 6:01 PM, Kirill Grouchnikov <kirillcool@...> wrote:
No problem, Gabor.

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Tuesday, July 15, 2008 7:31:19 AM
Subject: Re: SubstanceRootPaneUI's minimumLayoutSize

Thanks for the quick reply, you're right, the MetalRootPaneUI uses the same code, and I assume it's ok, my problem should be somewhere else. I'd done some customization in the Substance laf (without touching the library's source), so I may have screwed something up possibly (mmmm, I use my own TitlePane...). Sorry for wasting your time.

Thanks
Gábor
 

On Tue, Jul 15, 2008 at 4:18 PM, Kirill Grouchnikov <kirillcool@...> wrote:
This code is the same as in MetalRootPaneUI - the tpHeight is computed there but never used. Would you mind creating a small complete example that is sized differently under Substance and Metal?

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Tuesday, July 15, 2008 5:20:20 AM
Subject: SubstanceRootPaneUI's minimumLayoutSize

Hi Kirill!

Why is "tpHeight" variable commented in SubstanceRootPaneUI's minimumLayoutSize ? It causes my dialogs to be too tall :(

public Dimension minimumLayoutSize(Container parent) {
...
// int tpHeight = 0;
....
// tpHeight = tpd.height;
....
return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth)+ i.left + i.right,
                     cpHeight + mbHeight + tpWidth + i.top + i.bottom);                  
}


Thx, Gábor Pápai








---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

SmallDialogSubstance.java (1K) Download Attachment
RootPaneUI.java (9K) Download Attachment

Parent Message unknown Re: SubstanceRootPaneUI's minimumLayoutSize

by Kirill Grouchnikov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi,

I can't run this code since it is using de.coryx.cpt.swing.Dialog class.

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Monday, August 4, 2008 3:14:51 AM
Subject: Re: SubstanceRootPaneUI's minimumLayoutSize

Hi Kirill!

Back to my minimum layout size problem. I've found my problem in Sun's bugzilla:
http://bugs.sun.com/view_bug.do?bug_id=4916923

A small test program (in case file attacment isn't working it's copied here). I use custom titlepane component.
The bugfix is in the FixedRootLayout class, preferredLayoutSize() and minimumLayoutSize() methods. Commented tpHeight is uncommented, and used.

(It tested against the last development version prior jul.20, because after that it doesn't work for me, and I don't have time for a correct bug report (it complains about null pointer exception at multiuidefaults or something like that).)

I hope it helps (and you fix that small problem :) ).

Thanks,
     Gábor

package test;

import java.awt.BorderLayout;
import java.awt.Window;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;

import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;

import de.coryx.cpt.swing.Dialog;

public class SmallDialogSubstance {

    public static final boolean FIX_MODE = false;
    public static final String  TITLE    = "This is a very-very long title, yep, very-very long title.";

    public SmallDialogSubstance() {

        try {
            UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
            JDialog.setDefaultLookAndFeelDecorated(true);
            JFrame.setDefaultLookAndFeelDecorated(true);

            UIDefaults uiDef = UIManager.getDefaults();
            uiDef.put("RootPaneUI", "test.RootPaneUI");

            Dialog dlgMain = new Dialog((Window) null, "this title isn't shown.");

            dlgMain.setCaptionComponent(new JLabel("Custom caption component"));

            dlgMain.setDefaultCloseOperation(Dialog.DISPOSE_ON_CLOSE);
            dlgMain.setLayout(new BorderLayout());
            dlgMain.add(new JLabel("Hello world!"), BorderLayout.CENTER);
            dlgMain.pack();
            dlgMain.setVisible(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                new SmallDialogSubstance();
            }
        });
    }
}

package test;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.LayoutManager2;
import java.awt.Rectangle;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.plaf.ComponentUI;

import org.jvnet.substance.SubstanceRootPaneUI;

public class RootPaneUI extends SubstanceRootPaneUI {

    public static ComponentUI createUI(JComponent c) {
        return new RootPaneUI();
    }

    public JComponent createTitlePane(JRootPane root) {
        // custom titlepane
        return new JLabel(SmallDialogSubstance.TITLE);
    }

    private LayoutManager createLayoutManager() {
        return new FixedRootLayout();
    }

    private void installLayout(JRootPane root) {
        root.setLayout(createLayoutManager());
    }

    public void installUI(JComponent c) {
        super.installUI(c);

        // whether use fix mode or not
        if (SmallDialogSubstance.FIX_MODE) {
            JRootPane root = (JRootPane) c;
            int style = root.getWindowDecorationStyle();
            if (style != JRootPane.NONE) {
                installLayout(root);
            }
        }
    }

    private static class FixedRootLayout implements LayoutManager2 {

        public Dimension preferredLayoutSize(Container parent) {
            Dimension cpd, mbd, tpd;
            int cpWidth = 0;
            int cpHeight = 0;
            int mbWidth = 0;
            int mbHeight = 0;
            int tpWidth = 0;
            int tpHeight = 0;
            Insets i = parent.getInsets();
            JRootPane root = (JRootPane) parent;

            if (root.getContentPane() != null) {
                cpd = root.getContentPane().getPreferredSize();
            } else {
                cpd = root.getSize();
            }
            if (cpd != null) {
                cpWidth = cpd.width;
                cpHeight = cpd.height;
            }

            if (root.getJMenuBar() != null) {
                mbd = root.getJMenuBar().getPreferredSize();
                if (mbd != null) {
                    mbWidth = mbd.width;
                    mbHeight = mbd.height;
                }
            }

            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    tpd = titlePane.getPreferredSize();
                    if (tpd != null) {
                        tpWidth = tpd.width;
                        tpHeight = tpd.height;
                    }
                }
            }

            return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpHeight + i.top + i.bottom);
        }

        public Dimension minimumLayoutSize(Container parent) {
            Dimension cpd, mbd, tpd;
            int cpWidth = 0;
            int cpHeight = 0;
            int mbWidth = 0;
            int mbHeight = 0;
            int tpWidth = 0;
            int tpHeight = 0;
            Insets i = parent.getInsets();
            JRootPane root = (JRootPane) parent;

            if (root.getContentPane() != null) {
                cpd = root.getContentPane().getMinimumSize();
            } else {
                cpd = root.getSize();
            }
            if (cpd != null) {
                cpWidth = cpd.width;
                cpHeight = cpd.height;
            }

            if (root.getJMenuBar() != null) {
                mbd = root.getJMenuBar().getMinimumSize();
                if (mbd != null) {
                    mbWidth = mbd.width;
                    mbHeight = mbd.height;
                }
            }
            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    tpd = titlePane.getMinimumSize();
                    if (tpd != null) {
                        tpWidth = tpd.width;
                        tpHeight = tpd.height;
                    }
                }
            }

            return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpHeight + i.top + i.bottom);
        }

        public Dimension maximumLayoutSize(Container target) {
            Dimension cpd, mbd, tpd;
            int cpWidth = Integer.MAX_VALUE;
            int cpHeight = Integer.MAX_VALUE;
            int mbWidth = Integer.MAX_VALUE;
            int mbHeight = Integer.MAX_VALUE;
            int tpWidth = Integer.MAX_VALUE;
            int tpHeight = Integer.MAX_VALUE;
            Insets i = target.getInsets();
            JRootPane root = (JRootPane) target;

            if (root.getContentPane() != null) {
                cpd = root.getContentPane().getMaximumSize();
                if (cpd != null) {
                    cpWidth = cpd.width;
                    cpHeight = cpd.height;
                }
            }

            if (root.getJMenuBar() != null) {
                mbd = root.getJMenuBar().getMaximumSize();
                if (mbd != null) {
                    mbWidth = mbd.width;
                    mbHeight = mbd.height;
                }
            }

            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    tpd = titlePane.getMaximumSize();
                    if (tpd != null) {
                        tpWidth = tpd.width;
                        tpHeight = tpd.height;
                    }
                }
            }

            int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
            // Only overflows if 3 real non-MAX_VALUE heights, sum to >
            // MAX_VALUE
            // Only will happen if sums to more than 2 billion units. Not
            // likely.
            if (maxHeight != Integer.MAX_VALUE) {
                maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
            }

            int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
            // Similar overflow comment as above
            if (maxWidth != Integer.MAX_VALUE) {
                maxWidth += i.left + i.right;
            }

            return new Dimension(maxWidth, maxHeight);
        }

        public void layoutContainer(Container parent) {
            JRootPane root = (JRootPane) parent;
            Rectangle b = root.getBounds();
            Insets i = root.getInsets();
            int nextY = 0;
            int w = b.width - i.right - i.left;
            int h = b.height - i.top - i.bottom;

            if (root.getLayeredPane() != null) {
                root.getLayeredPane().setBounds(i.left, i.top, w, h);
            }
            if (root.getGlassPane() != null) {
                root.getGlassPane().setBounds(i.left, i.top, w, h);
            }
            // Note: This is laying out the children in the layeredPane,
            // technically, these are not our children.
            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    Dimension tpd = titlePane.getPreferredSize();
                    if (tpd != null) {
                        int tpHeight = tpd.height;
                        titlePane.setBounds(0, 0, w, tpHeight);
                        nextY += tpHeight;
                    }
                }
            }
            if (root.getJMenuBar() != null) {
                Dimension mbd = root.getJMenuBar().getPreferredSize();
                root.getJMenuBar().setBounds(0, nextY, w, mbd.height);
                nextY += mbd.height;
            }
            if (root.getContentPane() != null) {
                // Dimension cpd = root.getContentPane().getPreferredSize();
                root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY);
            }
        }

        public void addLayoutComponent(String name, Component comp) {}

        public void removeLayoutComponent(Component comp) {}

        public void addLayoutComponent(Component comp, Object constraints) {}

        public float getLayoutAlignmentX(Container target) {
            return 0.0f;
        }

        public float getLayoutAlignmentY(Container target) {
            return 0.0f;
        }

        public void invalidateLayout(Container target) {}
    }

}






On Tue, Jul 15, 2008 at 6:01 PM, Kirill Grouchnikov <kirillcool@...> wrote:
No problem, Gabor.

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Tuesday, July 15, 2008 7:31:19 AM
Subject: Re: SubstanceRootPaneUI's minimumLayoutSize

Thanks for the quick reply, you're right, the MetalRootPaneUI uses the same code, and I assume it's ok, my problem should be somewhere else. I'd done some customization in the Substance laf (without touching the library's source), so I may have screwed something up possibly (mmmm, I use my own TitlePane...). Sorry for wasting your time.

Thanks
Gábor
 

On Tue, Jul 15, 2008 at 4:18 PM, Kirill Grouchnikov <kirillcool@...> wrote:
This code is the same as in MetalRootPaneUI - the tpHeight is computed there but never used. Would you mind creating a small complete example that is sized differently under Substance and Metal?

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Tuesday, July 15, 2008 5:20:20 AM
Subject: SubstanceRootPaneUI's minimumLayoutSize

Hi Kirill!

Why is "tpHeight" variable commented in SubstanceRootPaneUI's minimumLayoutSize ? It causes my dialogs to be too tall :(

public Dimension minimumLayoutSize(Container parent) {
...
// int tpHeight = 0;
....
// tpHeight = tpd.height;
....
return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth)+ i.left + i.right,
                     cpHeight + mbHeight + tpWidth + i.top + i.bottom);                  
}


Thx, Gábor Pápai





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: SubstanceRootPaneUI's minimumLayoutSize

by Gábor Pápai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Kirill!

Sorry, it's to hard to cut a small sample program from a big platform.

#1
I mentioned "it complains about null pointer exception at multiuidefaults", it was my fault of course, I created swing components out of EDT, the exact exception was:
UIDefaults.getUI() failed: createUI() failed for javax.swing.JPanel[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=] java.lang.reflect.InvocationTargetException
java.lang.Error
    at javax.swing.UIDefaults.getUIError(UIDefaults.java:711)
    at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:117)
    at javax.swing.UIDefaults.getUI(UIDefaults.java:757)
    at javax.swing.UIManager.getUI(UIManager.java:1012)
    at javax.swing.JPanel.updateUI(JPanel.java:109)
    at javax.swing.JPanel.<init>(JPanel.java:69)
    at javax.swing.JPanel.<init>(JPanel.java:92)
    at javax.swing.JPanel.<init>(JPanel.java:100)
    at javax.swing.JRootPane.createGlassPane(JRootPane.java:527)
    at javax.swing.JRootPane.<init>(JRootPane.java:347)
    at javax.swing.JDialog.createRootPane(JDialog.java:617)
    at javax.swing.JDialog.dialogInit(JDialog.java:599)
    at javax.swing.JDialog.<init>(JDialog.java:551)
    at javax.swing.JDialog.<init>(JDialog.java:521)

#2 The corrected sample program:
It shows only the wrong behavior, the supposed fix is described in http://bugs.sun.com/view_bug.do?bug_id=4916923 .
I hope this time it works.

package test;

import java.awt.BorderLayout;
import java.awt.Window;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;

import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;

public class SmallDialogSubstance {

    private JDialog dlgMain;

    public SmallDialogSubstance() {
        try {
            UIManager
                    .setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());

            JDialog.setDefaultLookAndFeelDecorated(true);
            JFrame.setDefaultLookAndFeelDecorated(true);

            UIDefaults uiDef = UIManager.getDefaults();
            uiDef.put("RootPaneUI", "test.RootPaneUI");

            dlgMain = new JDialog((Window) null, "this title isn't shown.");

            dlgMain.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dlgMain.setLayout(new BorderLayout());
            dlgMain.add(new JLabel("Hello world!"), BorderLayout.CENTER);
            dlgMain.pack();
            dlgMain.setVisible(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                new SmallDialogSubstance();
            }
        });
    }
}

package test;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.plaf.ComponentUI;

import org.jvnet.substance.SubstanceRootPaneUI;

public class RootPaneUI extends SubstanceRootPaneUI {

    public static ComponentUI createUI(JComponent c) {
        return new RootPaneUI();
    }

    /**
     * custom titlepane
     */
    public JComponent createTitlePane(JRootPane root) {
        return new JLabel("This is a very-very-very-very-very-very-very wide title pane component.");
    }
}


On Tue, Aug 5, 2008 at 7:21 PM, Kirill Grouchnikov <kirillcool@...> wrote:
Hi,

I can't run this code since it is using de.coryx.cpt.swing.Dialog class.

Thanks
Kirill

----- Original Message ----
From: Gábor Pápai <gabor.papai@...>
To: users@...
Sent: Monday, August 4, 2008 3:14:51 AM
Subject: Re: SubstanceRootPaneUI's minimumLayoutSize

Hi Kirill!

Back to my minimum layout size problem. I've found my problem in Sun's bugzilla:
http://bugs.sun.com/view_bug.do?bug_id=4916923

A small test program (in case file attacment isn't working it's copied here). I use custom titlepane component.
The bugfix is in the FixedRootLayout class, preferredLayoutSize() and minimumLayoutSize() methods. Commented tpHeight is uncommented, and used.

(It tested against the last development version prior jul.20, because after that it doesn't work for me, and I don't have time for a correct bug report (it complains about null pointer exception at multiuidefaults or something like that).)

I hope it helps (and you fix that small problem :) ).

Thanks,
     Gábor

package test;

import java.awt.BorderLayout;
import java.awt.Window;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;

import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;

import de.coryx.cpt.swing.Dialog;

public class SmallDialogSubstance {

    public static final boolean FIX_MODE = false;
    public static final String  TITLE    = "This is a very-very long title, yep, very-very long title.";

    public SmallDialogSubstance() {

        try {
            UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
            JDialog.setDefaultLookAndFeelDecorated(true);
            JFrame.setDefaultLookAndFeelDecorated(true);

            UIDefaults uiDef = UIManager.getDefaults();
            uiDef.put("RootPaneUI", "test.RootPaneUI");

            Dialog dlgMain = new Dialog((Window) null, "this title isn't shown.");

            dlgMain.setCaptionComponent(new JLabel("Custom caption component"));

            dlgMain.setDefaultCloseOperation(Dialog.DISPOSE_ON_CLOSE);
            dlgMain.setLayout(new BorderLayout());
            dlgMain.add(new JLabel("Hello world!"), BorderLayout.CENTER);
            dlgMain.pack();
            dlgMain.setVisible(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                new SmallDialogSubstance();
            }
        });
    }
}

package test;

import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.LayoutManager2;
import java.awt.Rectangle;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.plaf.ComponentUI;

import org.jvnet.substance.SubstanceRootPaneUI;

public class RootPaneUI extends SubstanceRootPaneUI {

    public static ComponentUI createUI(JComponent c) {
        return new RootPaneUI();
    }

    public JComponent createTitlePane(JRootPane root) {
        // custom titlepane
        return new JLabel(SmallDialogSubstance.TITLE);
    }

    private LayoutManager createLayoutManager() {
        return new FixedRootLayout();
    }

    private void installLayout(JRootPane root) {
        root.setLayout(createLayoutManager());
    }

    public void installUI(JComponent c) {
        super.installUI(c);

        // whether use fix mode or not
        if (SmallDialogSubstance.FIX_MODE) {
            JRootPane root = (JRootPane) c;
            int style = root.getWindowDecorationStyle();
            if (style != JRootPane.NONE) {
                installLayout(root);
            }
        }
    }

    private static class FixedRootLayout implements LayoutManager2 {

        public Dimension preferredLayoutSize(Container parent) {
            Dimension cpd, mbd, tpd;
            int cpWidth = 0;
            int cpHeight = 0;
            int mbWidth = 0;
            int mbHeight = 0;
            int tpWidth = 0;
            int tpHeight = 0;
            Insets i = parent.getInsets();
            JRootPane root = (JRootPane) parent;

            if (root.getContentPane() != null) {
                cpd = root.getContentPane().getPreferredSize();
            } else {
                cpd = root.getSize();
            }
            if (cpd != null) {
                cpWidth = cpd.width;
                cpHeight = cpd.height;
            }

            if (root.getJMenuBar() != null) {
                mbd = root.getJMenuBar().getPreferredSize();
                if (mbd != null) {
                    mbWidth = mbd.width;
                    mbHeight = mbd.height;
                }
            }

            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    tpd = titlePane.getPreferredSize();
                    if (tpd != null) {
                        tpWidth = tpd.width;
                        tpHeight = tpd.height;
                    }
                }
            }

            return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpHeight + i.top + i.bottom);
        }

        public Dimension minimumLayoutSize(Container parent) {
            Dimension cpd, mbd, tpd;
            int cpWidth = 0;
            int cpHeight = 0;
            int mbWidth = 0;
            int mbHeight = 0;
            int tpWidth = 0;
            int tpHeight = 0;
            Insets i = parent.getInsets();
            JRootPane root = (JRootPane) parent;

            if (root.getContentPane() != null) {
                cpd = root.getContentPane().getMinimumSize();
            } else {
                cpd = root.getSize();
            }
            if (cpd != null) {
                cpWidth = cpd.width;
                cpHeight = cpd.height;
            }

            if (root.getJMenuBar() != null) {
                mbd = root.getJMenuBar().getMinimumSize();
                if (mbd != null) {
                    mbWidth = mbd.width;
                    mbHeight = mbd.height;
                }
            }
            if ((root.getWindowDecorationStyle() != JRootPane.NONE) && (root.getUI() instanceof SubstanceRootPaneUI)) {
                JComponent titlePane = ((SubstanceRootPaneUI) root.getUI()).getTitlePane();
                if (titlePane != null) {
                    tpd = titlePane.getMinimumSize();
                    if (tpd != null) {
                        tpWidth = tpd.width;
                        tpHeight = tpd.height;
                    }
                }
            }

            return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpHeight + i.top + i.bottom);
        }

        public Dimension maximumLayoutSize(Container target) {
            Dimension cpd, mbd, tpd;
            int cpWidth = Integer.MAX_VALUE;
            int cpHeight = Integer.MAX_VALUE;
            int mbWidth = Integer.MAX_VALUE;