X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fui%2FUIUtils.java;h=5861d00fc3a6e3a254230c8bd5d43a17d26299db;hb=f19e3f13e1725ed77c423190c8f8ed4664e42188;hp=91a1f61b4b1bb02f7646c8f9910fb6b0140feeb7;hpb=136e0f9fd89bf7c72b60480c9bc9641f4bfb4faa;p=fanfix.git diff --git a/src/be/nikiroo/utils/ui/UIUtils.java b/src/be/nikiroo/utils/ui/UIUtils.java index 91a1f61..5861d00 100644 --- a/src/be/nikiroo/utils/ui/UIUtils.java +++ b/src/be/nikiroo/utils/ui/UIUtils.java @@ -8,6 +8,8 @@ import java.awt.Paint; import java.awt.RadialGradientPaint; import java.awt.RenderingHints; +import javax.swing.JComponent; +import javax.swing.JScrollPane; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; @@ -37,7 +39,7 @@ public class UIUtils { } catch (IllegalAccessException e) { } } - + /** * Draw a 3D-looking ellipse at the given location, if the given * {@link Graphics} object is compatible (with {@link Graphics2D}); draw a @@ -56,7 +58,8 @@ public class UIUtils { * @param height * the height radius */ - static public void drawEllipse3D(Graphics g, Color color, int x, int y, int width, int height) { + static public void drawEllipse3D(Graphics g, Color color, int x, int y, + int width, int height) { drawEllipse3D(g, color, x, y, width, height, true); } @@ -77,8 +80,8 @@ public class UIUtils { * the width radius * @param height * the height radius - * @param fill - * fill the content of the ellipse + * @param fill + * fill the content of the ellipse */ static public void drawEllipse3D(Graphics g, Color color, int x, int y, int width, int height, boolean fill) { @@ -97,7 +100,7 @@ public class UIUtils { } else { g2.drawOval(x, y, width, height); } - + // Compute dark/bright colours Paint p = null; Color dark = color.darker().darker(); @@ -125,7 +128,7 @@ public class UIUtils { } else { g2.drawOval(x, y, width, height); } - + // Darken the edges p = new RadialGradientPaint(x + width / 2f, y + height / 2f, Math.min(width / 2f, height / 2f), new float[] { 0f, 1f }, @@ -162,4 +165,52 @@ public class UIUtils { } } } + + /** + * Add a {@link JScrollPane} around the given panel and use a sensible (for + * me) increment for the mouse wheel. + * + * @param pane + * the panel to wrap in a {@link JScrollPane} + * @param allowHorizontal + * allow horizontal scrolling (not always desired) + * + * @return the {@link JScrollPane} + */ + static public JScrollPane scroll(JComponent pane, boolean allowHorizontal) { + return scroll(pane, allowHorizontal, true); + } + + /** + * Add a {@link JScrollPane} around the given panel and use a sensible (for + * me) increment for the mouse wheel. + * + * @param pane + * the panel to wrap in a {@link JScrollPane} + * @param allowHorizontal + * allow horizontal scrolling (not always desired) + * @param allowVertical + * allow vertical scrolling (usually yes, but sometimes you only + * want horizontal) + * + * @return the {@link JScrollPane} + */ + static public JScrollPane scroll(JComponent pane, boolean allowHorizontal, + boolean allowVertical) { + JScrollPane scroll = new JScrollPane(pane); + + scroll.getVerticalScrollBar().setUnitIncrement(16); + scroll.getHorizontalScrollBar().setUnitIncrement(16); + + if (!allowHorizontal) { + scroll.setHorizontalScrollBarPolicy( + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + } + if (!allowVertical) { + scroll.setVerticalScrollBarPolicy( + JScrollPane.VERTICAL_SCROLLBAR_NEVER); + } + + return scroll; + } }