branch feature/1119 created (now a1679da)
This is an automated email from the git hooks/post-receive script. New change to branch feature/1119 in repository lima. See http://git.chorem.org/lima.git at a1679da fixes #1119 : changement du layout pour les toolbar possiblement trop large This branch includes the following new commits: new a1679da fixes #1119 : changement du layout pour les toolbar possiblement trop large The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit a1679da0570380bdc0e3b1560c06e631dbe78baa Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Fri May 15 12:10:59 2015 +0200 fixes #1119 : changement du layout pour les toolbar possiblement trop large -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/1119 in repository lima. See http://git.chorem.org/lima.git commit a1679da0570380bdc0e3b1560c06e631dbe78baa Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Fri May 15 12:10:59 2015 +0200 fixes #1119 : changement du layout pour les toolbar possiblement trop large --- .../chorem/lima/ui/lettering/LetteringView.jaxx | 4 +- .../org/chorem/lima/util/WrapToolBarLayout.java | 107 +++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx b/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx index 7b7d935..6fdd8f1 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx +++ b/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx @@ -21,6 +21,7 @@ <JPanel layout="{new BorderLayout()}"> <import> + org.chorem.lima.util.WrapToolBarLayout org.chorem.lima.ui.common.AccountComboBoxModel org.chorem.lima.ui.common.FinancialPeriodComboBoxModel org.chorem.lima.util.BigDecimalToString @@ -44,7 +45,8 @@ </script> <JToolBar styleClass="toolbar" - constraints="BorderLayout.PAGE_START"> + constraints="BorderLayout.PAGE_START" + layout="{new WrapToolBarLayout()}"> <JButton id="lettered" onActionPerformed="handler.addLetter()"/> diff --git a/lima-swing/src/main/java/org/chorem/lima/util/WrapToolBarLayout.java b/lima-swing/src/main/java/org/chorem/lima/util/WrapToolBarLayout.java new file mode 100644 index 0000000..9da6e7b --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/util/WrapToolBarLayout.java @@ -0,0 +1,107 @@ +package org.chorem.lima.util; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Insets; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + * Ce layout permet de scinder en deux ligne les elements d'une toolbar pour que tousz les élément soit visible + * Code recupéré a partir de : + * http://stackoverflow.com/questions/3679886/how-can-i-let-jtoolbars-wrap-to-t... + * + */ +public class WrapToolBarLayout extends FlowLayout { + + public WrapToolBarLayout() { + super(FlowLayout.LEFT, 0, 0); + } + + public Dimension minimumLayoutSize(Container target) { + // Size of largest component, so we can resize it in + // either direction with something like a split-pane. + return computeMinSize(target); + } + + public Dimension preferredLayoutSize(Container target) { + return computeSize(target); + } + + private Dimension computeSize(Container target) { + synchronized (target.getTreeLock()) { + int hgap = getHgap(); + int vgap = getVgap(); + int w = target.getWidth(); + + // Let this behave like a regular FlowLayout (single row) + // if the container hasn't been assigned any size yet + if (w == 0) { + w = Integer.MAX_VALUE; + } + + Insets insets = target.getInsets(); + if (insets == null){ + insets = new Insets(0, 0, 0, 0); + } + int reqdWidth = 0; + + int maxwidth = w - (insets.left + insets.right + hgap * 2); + int n = target.getComponentCount(); + int x = 0; + int y = insets.top + vgap; // FlowLayout starts by adding vgap, so do that here too. + int rowHeight = 0; + + for (int i = 0; i < n; i++) { + Component c = target.getComponent(i); + if (c.isVisible()) { + Dimension d = c.getPreferredSize(); + if ((x == 0) || ((x + d.width) <= maxwidth)) { + // fits in current row. + if (x > 0) { + x += hgap; + } + x += d.width; + rowHeight = Math.max(rowHeight, d.height); + } + else { + // Start of new row + x = d.width; + y += vgap + rowHeight; + rowHeight = d.height; + } + reqdWidth = Math.max(reqdWidth, x); + } + } + y += rowHeight; + y += insets.bottom; + return new Dimension(reqdWidth+insets.left+insets.right, y); + } + } + + private Dimension computeMinSize(Container target) { + synchronized (target.getTreeLock()) { + int minx = Integer.MAX_VALUE; + int miny = Integer.MIN_VALUE; + boolean found_one = false; + int n = target.getComponentCount(); + + for (int i = 0; i < n; i++) { + Component c = target.getComponent(i); + if (c.isVisible()) { + found_one = true; + Dimension d = c.getPreferredSize(); + minx = Math.min(minx, d.width); + miny = Math.min(miny, d.height); + } + } + if (found_one) { + return new Dimension(minx, miny); + } + return new Dimension(0, 0); + } + } + + +} -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm