diff --git a/README.md b/README.md index a7a1213a8..08e65007b 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,12 @@ https://github.com/mgarin/weblaf/releases Here are the direct links for the latest release: -1. [**weblaf-1.25.jar**](https://github.com/mgarin/weblaf/releases/download/v1.25/weblaf-1.25.jar) - library jar -2. [**weblaf-simple-1.25.jar**](https://github.com/mgarin/weblaf/releases/download/v1.25/weblaf-simple-1.25.jar) - library jar without dependencies -3. [**weblaf-src-1.25.zip**](https://github.com/mgarin/weblaf/releases/download/v1.25/weblaf-src-1.25.zip) - project sources zip -4. [**weblaf-demo-1.25.jar**](https://github.com/mgarin/weblaf/releases/download/v1.25/weblaf-demo-1.25.jar) - executable demo jar -5. [**weblaf-javadoc-1.25.zip**](https://github.com/mgarin/weblaf/releases/download/v1.25/weblaf-javadoc-1.25.zip) - JavaDoc zip -6. [**ninepatch-editor-1.25.jar**](https://github.com/mgarin/weblaf/releases/download/v1.25/ninepatch-editor-1.25.jar) - executable 9-patch editor jar +1. [**weblaf-1.26.jar**](https://github.com/mgarin/weblaf/releases/download/v1.26/weblaf-1.26.jar) - library jar +2. [**weblaf-simple-1.26.jar**](https://github.com/mgarin/weblaf/releases/download/v1.26/weblaf-simple-1.26.jar) - library jar without dependencies +3. [**weblaf-src-1.26.zip**](https://github.com/mgarin/weblaf/releases/download/v1.26/weblaf-src-1.26.zip) - project sources zip +4. [**weblaf-demo-1.26.jar**](https://github.com/mgarin/weblaf/releases/download/v1.26/weblaf-demo-1.26.jar) - executable demo jar +5. [**weblaf-javadoc-1.26.zip**](https://github.com/mgarin/weblaf/releases/download/v1.26/weblaf-javadoc-1.26.zip) - JavaDoc zip +6. [**ninepatch-editor-1.26.jar**](https://github.com/mgarin/weblaf/releases/download/v1.26/ninepatch-editor-1.26.jar) - executable 9-patch editor jar Roadmap diff --git a/build/version.properties b/build/version.properties index de3253354..99e6bd442 100644 --- a/build/version.properties +++ b/build/version.properties @@ -1,3 +1,3 @@ -#Mon Oct 28 20:49:53 MSK 2013 -build.number=26 +#Wed Jan 29 16:43:10 MSK 2014 +build.number=27 version.number=1 diff --git a/src/com/alee/extended/breadcrumb/BreadcrumbElementPainter.java b/src/com/alee/extended/breadcrumb/BreadcrumbElementPainter.java index 8b1e9a1f4..8af04e9f9 100644 --- a/src/com/alee/extended/breadcrumb/BreadcrumbElementPainter.java +++ b/src/com/alee/extended/breadcrumb/BreadcrumbElementPainter.java @@ -81,11 +81,11 @@ public int getOverlap () return overlap; } - public void setOverlap ( int overlap ) + public void setOverlap ( final int overlap ) { this.overlap = overlap; borderShapeCache.clear (); - fireUpdate (); + updateAll (); } public BreadcrumbElementType getType () @@ -93,11 +93,11 @@ public BreadcrumbElementType getType () return type; } - public void setType ( BreadcrumbElementType type ) + public void setType ( final BreadcrumbElementType type ) { this.type = type; borderShapeCache.clear (); - fireUpdate (); + updateAll (); } public boolean isShowProgress () @@ -105,10 +105,10 @@ public boolean isShowProgress () return showProgress; } - public void setShowProgress ( boolean showProgress ) + public void setShowProgress ( final boolean showProgress ) { this.showProgress = showProgress; - fireRepaint (); + repaint (); } public float getProgress () @@ -116,19 +116,19 @@ public float getProgress () return progress; } - public void setProgress ( float progress ) + public void setProgress ( final float progress ) { this.progress = Math.min ( 1f, progress ); - fireRepaint (); + repaint (); } /** * {@inheritDoc} */ @Override - public Insets getMargin ( E c ) + public Insets getMargin ( final E c ) { - int left; + final int left; if ( type.equals ( BreadcrumbElementType.none ) ) { left = 0; @@ -137,7 +137,7 @@ public Insets getMargin ( E c ) { left = type.equals ( BreadcrumbElementType.start ) ? 0 : overlap; } - int right; + final int right; if ( type.equals ( BreadcrumbElementType.none ) ) { right = 0; @@ -153,7 +153,7 @@ public Insets getMargin ( E c ) * {@inheritDoc} */ @Override - public void paint ( Graphics2D g2d, Rectangle bounds, E c ) + public void paint ( final Graphics2D g2d, final Rectangle bounds, final E c ) { final int br = BreadcrumbUtils.getRound ( c ); final boolean ltr = c.getComponentOrientation ().isLeftToRight (); @@ -165,8 +165,8 @@ public void paint ( Graphics2D g2d, Rectangle bounds, E c ) boolean selected = false; if ( c instanceof AbstractButton ) { - AbstractButton ab = ( AbstractButton ) c; - ButtonModel bm = ab.getModel (); + final AbstractButton ab = ( AbstractButton ) c; + final ButtonModel bm = ab.getModel (); selected = bm.isPressed () || bm.isSelected (); } @@ -215,15 +215,15 @@ public void paint ( Graphics2D g2d, Rectangle bounds, E c ) // Progress background if ( showProgress && progress > 0f ) { - Shape progressFillShape = getProgressFillShape ( c, fs ); - Rectangle pb = progressFillShape.getBounds (); + final Shape progressFillShape = getProgressFillShape ( c, fs ); + final Rectangle pb = progressFillShape.getBounds (); // Background fill g2d.setPaint ( getProgressPaint ( c ) ); g2d.fill ( progressFillShape ); // Line with proper background-shaped clipping - Shape oldClip = LafUtils.intersectClip ( g2d, fs ); + final Shape oldClip = LafUtils.intersectClip ( g2d, fs ); g2d.setPaint ( getProgressLinePaint ( c ) ); g2d.drawLine ( ltr ? pb.x + pb.width : pb.x, pb.y, ltr ? pb.x + pb.width : pb.x, pb.y + pb.height ); LafUtils.restoreClip ( g2d, oldClip ); @@ -233,26 +233,26 @@ public void paint ( Graphics2D g2d, Rectangle bounds, E c ) LafUtils.restoreAntialias ( g2d, old ); } - protected LinearGradientPaint getProgressPaint ( E c ) + protected LinearGradientPaint getProgressPaint ( final E c ) { boolean pressed = false; if ( c instanceof AbstractButton ) { - ButtonModel bm = ( ( AbstractButton ) c ).getModel (); + final ButtonModel bm = ( ( AbstractButton ) c ).getModel (); pressed = bm.isPressed () || bm.isSelected (); } return new LinearGradientPaint ( 0, 0, 0, c.getHeight (), progressFractions, pressed ? selectedProgressFillColors : progressFillColors ); } - protected LinearGradientPaint getProgressLinePaint ( E c ) + protected LinearGradientPaint getProgressLinePaint ( final E c ) { return new LinearGradientPaint ( 0, 0, 0, c.getHeight (), progressFractions, progressLineColors ); } - public GeneralPath getBorderShape ( E c, boolean ltr ) + public GeneralPath getBorderShape ( final E c, final boolean ltr ) { - String key = ltr + ":" + c.getWidth () + "," + c.getHeight (); + final String key = ltr + ":" + c.getWidth () + "," + c.getHeight (); GeneralPath bs = borderShapeCache.get ( key ); if ( bs == null ) { @@ -263,9 +263,9 @@ public GeneralPath getBorderShape ( E c, boolean ltr ) return bs; } - protected GeneralPath getBorderShapeImpl ( E c, boolean ltr ) + protected GeneralPath getBorderShapeImpl ( final E c, final boolean ltr ) { - GeneralPath gp = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); + final GeneralPath gp = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); if ( ltr ) { gp.moveTo ( c.getWidth () - overlap - shadeWidth - 1, -1 ); @@ -281,9 +281,9 @@ protected GeneralPath getBorderShapeImpl ( E c, boolean ltr ) return gp; } - public Shape getFillShape ( E c, boolean ltr, int round ) + public Shape getFillShape ( final E c, final boolean ltr, final int round ) { - String key = ltr + ":" + round + ":" + c.getWidth () + "," + c.getHeight (); + final String key = ltr + ":" + round + ":" + c.getWidth () + "," + c.getHeight (); Shape fs = fillShapeCache.get ( key ); if ( fs == null ) { @@ -294,11 +294,11 @@ public Shape getFillShape ( E c, boolean ltr, int round ) return fs; } - protected Shape getFillShapeImpl ( E c, boolean ltr, int round ) + protected Shape getFillShapeImpl ( final E c, final boolean ltr, final int round ) { final int width = c.getWidth (); final int height = c.getHeight (); - boolean encloseLast = isEncloseLastElement ( c ); + final boolean encloseLast = isEncloseLastElement ( c ); if ( c.getParent () != null && c.getParent ().getComponentCount () == 1 && !encloseLast ) { if ( round > 0 ) @@ -312,7 +312,7 @@ protected Shape getFillShapeImpl ( E c, boolean ltr, int round ) } else if ( !type.equals ( BreadcrumbElementType.end ) ) { - GeneralPath gp = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); + final GeneralPath gp = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); if ( ltr ) { gp.moveTo ( width - overlap - shadeWidth - 1, 0 ); @@ -357,7 +357,7 @@ else if ( !type.equals ( BreadcrumbElementType.end ) ) { if ( round > 0 ) { - GeneralPath gp = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); + final GeneralPath gp = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); if ( ltr ) { gp.moveTo ( 0, 0 ); @@ -386,19 +386,19 @@ else if ( !type.equals ( BreadcrumbElementType.end ) ) } } - protected boolean isEncloseLastElement ( E c ) + protected boolean isEncloseLastElement ( final E c ) { return c.getParent () != null && c.getParent () instanceof WebBreadcrumb && ( ( WebBreadcrumb ) c.getParent () ).isEncloseLastElement (); } - public Shape getProgressFillShape ( E c, Shape fillShape ) + public Shape getProgressFillShape ( final E c, final Shape fillShape ) { - boolean ltr = c.getComponentOrientation ().isLeftToRight (); - Area fill = new Area ( fillShape ); + final boolean ltr = c.getComponentOrientation ().isLeftToRight (); + final Area fill = new Area ( fillShape ); - Rectangle bounds = fill.getBounds (); - int oldWidth = bounds.width; + final Rectangle bounds = fill.getBounds (); + final int oldWidth = bounds.width; bounds.width = Math.round ( oldWidth * progress ); bounds.x = ltr ? bounds.x : bounds.x + oldWidth - bounds.width; fill.intersect ( new Area ( bounds ) ); diff --git a/src/com/alee/extended/button/WebSplitButton.java b/src/com/alee/extended/button/WebSplitButton.java index aac2d0261..03914dea4 100644 --- a/src/com/alee/extended/button/WebSplitButton.java +++ b/src/com/alee/extended/button/WebSplitButton.java @@ -45,7 +45,7 @@ public class WebSplitButton extends WebButton implements MouseMotionListener, Mo * * @see #getUIClassID */ - private static final String uiClassID = "TristateCheckBoxUI"; + private static final String uiClassID = "SplitButtonUI"; /** * Whether should always display popup menu when button is clicked or not. @@ -231,9 +231,9 @@ public PopupMenuWay getPopupMenuWay () * * @param way approximate popup menu display way */ - public void setPopupMenuWay ( final PopupMenuWay popupMenuWay ) + public void setPopupMenuWay ( final PopupMenuWay way ) { - this.popupMenuWay = popupMenuWay; + this.popupMenuWay = way; } /** @@ -449,7 +449,7 @@ public void mouseExited ( final MouseEvent e ) * parameter. * * @param event the ActionEvent object - * @see EventListenerList + * @see javax.swing.event.EventListenerList */ protected void fireButtonClicked ( final ActionEvent event ) { @@ -485,7 +485,7 @@ protected void fireButtonClicked ( final ActionEvent event ) * parameter. * * @param event the ActionEvent object - * @see EventListenerList + * @see javax.swing.event.EventListenerList */ protected void fireSplitbuttonClicked ( final ActionEvent event ) { diff --git a/src/com/alee/extended/image/WebImageGallery.java b/src/com/alee/extended/image/WebImageGallery.java index 96df2c766..fdad28680 100644 --- a/src/com/alee/extended/image/WebImageGallery.java +++ b/src/com/alee/extended/image/WebImageGallery.java @@ -18,7 +18,6 @@ package com.alee.extended.image; import com.alee.laf.StyleConstants; -import com.alee.laf.scroll.WebScrollBarUI; import com.alee.laf.scroll.WebScrollPane; import com.alee.managers.hotkey.Hotkey; import com.alee.utils.ImageUtils; @@ -41,22 +40,22 @@ public class WebImageGallery extends JComponent { - private int spacing = 20; + private final int spacing = 20; private int imageLength = 200; - private int borderWidth = 3; - private float fadeHeight = 0.7f; - private int opacity = 125; + private final int borderWidth = 3; + private final float fadeHeight = 0.7f; + private final int opacity = 125; - private Color light = new Color ( 128, 128, 128 ); - private Color selectedLight = new Color ( 255, 255, 255 ); - private Color transparent = new Color ( 128, 128, 128, 0 ); - private Color selectedTransparent = new Color ( 255, 255, 255, 0 ); + private final Color light = new Color ( 128, 128, 128 ); + private final Color selectedLight = new Color ( 255, 255, 255 ); + private final Color transparent = new Color ( 128, 128, 128, 0 ); + private final Color selectedTransparent = new Color ( 255, 255, 255, 0 ); private int maxWidth = 0; private int maxHeight = 0; - private List images = new ArrayList (); - private List reflections = new ArrayList (); - private List descriptions = new ArrayList (); + private final List images = new ArrayList (); + private final List reflections = new ArrayList (); + private final List descriptions = new ArrayList (); // private List sizes = new ArrayList ( ); private int preferredColumnCount = 4; @@ -77,10 +76,10 @@ public WebImageGallery () setFocusable ( true ); setFont ( new JLabel ().getFont ().deriveFont ( Font.BOLD ) ); - MouseAdapter mouseAdapter = new MouseAdapter () + final MouseAdapter mouseAdapter = new MouseAdapter () { @Override - public void mousePressed ( MouseEvent e ) + public void mousePressed ( final MouseEvent e ) { if ( SwingUtilities.isLeftMouseButton ( e ) ) { @@ -97,11 +96,11 @@ public void mousePressed ( MouseEvent e ) } @Override - public void mouseWheelMoved ( MouseWheelEvent e ) + public void mouseWheelMoved ( final MouseWheelEvent e ) { - int index = getSelectedIndex (); - int maxIndex = images.size () - 1; - int wheelRotation = e.getWheelRotation (); + final int index = getSelectedIndex (); + final int maxIndex = images.size () - 1; + final int wheelRotation = e.getWheelRotation (); int newIndex; if ( wheelRotation > 0 ) { @@ -128,11 +127,11 @@ public void mouseWheelMoved ( MouseWheelEvent e ) addKeyListener ( new KeyAdapter () { @Override - public void keyPressed ( KeyEvent e ) + public void keyPressed ( final KeyEvent e ) { if ( images.size () > 0 ) { - int si = getSelectedIndex (); + final int si = getSelectedIndex (); if ( Hotkey.LEFT.isTriggered ( e ) ) { setSelectedIndex ( si == -1 || si == 0 ? images.size () - 1 : si - 1 ); @@ -164,7 +163,7 @@ public int getPreferredColumnCount () return preferredColumnCount; } - public void setPreferredColumnCount ( int preferredColumnCount ) + public void setPreferredColumnCount ( final int preferredColumnCount ) { this.preferredColumnCount = preferredColumnCount; } @@ -174,7 +173,7 @@ public WebScrollPane getView () return getView ( true ); } - public WebScrollPane getView ( boolean withBorder ) + public WebScrollPane getView ( final boolean withBorder ) { if ( view == null ) { @@ -183,15 +182,17 @@ public WebScrollPane getView ( boolean withBorder ) @Override public Dimension getPreferredSize () { - int columns = Math.min ( images.size (), preferredColumnCount ); + final int columns = Math.min ( images.size (), preferredColumnCount ); + final JScrollBar hsb = getHorizontalScrollBar (); + final int sbh = hsb != null && hsb.isShowing () ? hsb.getPreferredSize ().height : 0; return new Dimension ( spacing * ( columns + 1 ) + columns * maxWidth, - WebImageGallery.this.getPreferredSize ().height + WebScrollBarUI.LENGTH ); + WebImageGallery.this.getPreferredSize ().height + sbh ); } }; view.setHorizontalScrollBarPolicy ( WebScrollPane.HORIZONTAL_SCROLLBAR_NEVER ); view.setVerticalScrollBarPolicy ( WebScrollPane.VERTICAL_SCROLLBAR_NEVER ); - InputMap im = view.getInputMap ( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); + final InputMap im = view.getInputMap ( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); im.put ( KeyStroke.getKeyStroke ( "UP" ), "none" ); im.put ( KeyStroke.getKeyStroke ( "DOWN" ), "none" ); im.put ( KeyStroke.getKeyStroke ( "LEFT" ), "none" ); @@ -205,7 +206,7 @@ public int getImageLength () return imageLength; } - public void setImageLength ( int imageLength ) + public void setImageLength ( final int imageLength ) { this.imageLength = imageLength; } @@ -215,7 +216,7 @@ public boolean isScrollOnSelection () return scrollOnSelection; } - public void setScrollOnSelection ( boolean scrollOnSelection ) + public void setScrollOnSelection ( final boolean scrollOnSelection ) { this.scrollOnSelection = scrollOnSelection; } @@ -225,7 +226,7 @@ public int getSelectedIndex () return selectedIndex; } - public void setSelectedIndex ( int selectedIndex ) + public void setSelectedIndex ( final int selectedIndex ) { if ( this.selectedIndex == selectedIndex ) { @@ -237,7 +238,7 @@ public void setSelectedIndex ( int selectedIndex ) repaint (); if ( scrollOnSelection ) { - Rectangle rect = getImageRect ( selectedIndex ); + final Rectangle rect = getImageRect ( selectedIndex ); SwingUtils.scrollSmoothly ( getView (), rect.x + rect.width / 2 - WebImageGallery.this.getVisibleRect ().width / 2, rect.y ); } moveReflection (); @@ -254,7 +255,7 @@ private void moveReflection () reflectionMover = new WebTimer ( "WebImageGallery.reflectionMoveTimer", StyleConstants.fastAnimationDelay, new ActionListener () { @Override - public void actionPerformed ( ActionEvent e ) + public void actionPerformed ( final ActionEvent e ) { if ( progress < 1f ) { @@ -271,32 +272,32 @@ public void actionPerformed ( ActionEvent e ) reflectionMover.start (); } - public Rectangle getImageRect ( int index ) + public Rectangle getImageRect ( final int index ) { - int iconWidth = images.get ( index ).getIconWidth (); - int iconHeight = images.get ( index ).getIconHeight (); - Dimension ps = getPreferredSize (); - int x = ( getWidth () > ps.width ? ( getWidth () - ps.width ) / 2 : 0 ) + spacing + + final int iconWidth = images.get ( index ).getIconWidth (); + final int iconHeight = images.get ( index ).getIconHeight (); + final Dimension ps = getPreferredSize (); + final int x = ( getWidth () > ps.width ? ( getWidth () - ps.width ) / 2 : 0 ) + spacing + ( maxWidth + spacing ) * index + maxWidth / 2; - int y = getHeight () / 2 - spacing / 2 - iconHeight / 2; + final int y = getHeight () / 2 - spacing / 2 - iconHeight / 2; return new Rectangle ( x - iconWidth / 2, y - iconHeight / 2, iconWidth, iconHeight ); } - public void addImage ( ImageIcon image ) + public void addImage ( final ImageIcon image ) { addImage ( 0, image ); } - public void addImage ( int index, ImageIcon image ) + public void addImage ( final int index, final ImageIcon image ) { try { - ImageIcon previewIcon = ImageUtils.createPreviewIcon ( image, imageLength ); - int rwidth = previewIcon.getIconWidth (); - int rheight = previewIcon.getIconHeight (); + final ImageIcon previewIcon = ImageUtils.createPreviewIcon ( image, imageLength ); + final int rwidth = previewIcon.getIconWidth (); + final int rheight = previewIcon.getIconHeight (); - BufferedImage reflection = ImageUtils.createCompatibleImage ( rwidth, rheight, Transparency.TRANSLUCENT ); - Graphics2D g2d = reflection.createGraphics (); + final BufferedImage reflection = ImageUtils.createCompatibleImage ( rwidth, rheight, Transparency.TRANSLUCENT ); + final Graphics2D g2d = reflection.createGraphics (); LafUtils.setupAntialias ( g2d ); g2d.drawImage ( previewIcon.getImage (), 0, 0, null ); g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.DST_IN ) ); @@ -318,7 +319,7 @@ public void addImage ( int index, ImageIcon image ) updateContainer (); } - public void removeImage ( ImageIcon image ) + public void removeImage ( final ImageIcon image ) { if ( images.contains ( image ) ) { @@ -326,11 +327,11 @@ public void removeImage ( ImageIcon image ) } } - public void removeImage ( int index ) + public void removeImage ( final int index ) { if ( index >= 0 && index < images.size () ) { - boolean wasSelected = getSelectedIndex () == index; + final boolean wasSelected = getSelectedIndex () == index; images.remove ( index ); descriptions.remove ( index ); @@ -356,7 +357,7 @@ private void updateContainer () private void recalcualteMaxSizes () { - for ( ImageIcon icon : images ) + for ( final ImageIcon icon : images ) { maxWidth = Math.max ( maxWidth, icon.getIconWidth () ); maxHeight = Math.max ( maxHeight, icon.getIconHeight () ); @@ -399,7 +400,7 @@ protected void paintComponent ( final Graphics g ) // Initial image - float add = selectedIndex == i ? progress * 0.4f : ( oldSelectedIndex == i ? 0.4f - progress * 0.4f : 0 ); + final float add = selectedIndex == i ? progress * 0.4f : ( oldSelectedIndex == i ? 0.4f - progress * 0.4f : 0 ); g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_OVER, 0.6f + add ) ); g2d.drawImage ( bi, x - imageWidth / 2, y - imageHeight / 2, null ); diff --git a/src/com/alee/extended/list/WebFileList.java b/src/com/alee/extended/list/WebFileList.java index 1a4495408..55843e554 100644 --- a/src/com/alee/extended/list/WebFileList.java +++ b/src/com/alee/extended/list/WebFileList.java @@ -19,7 +19,6 @@ import com.alee.laf.list.WebList; import com.alee.laf.list.editor.ListCellEditor; -import com.alee.laf.scroll.WebScrollBarUI; import com.alee.laf.scroll.WebScrollPane; import com.alee.utils.FileUtils; @@ -463,7 +462,9 @@ else if ( fch != -1 ) } } final Insets bi = getInsets (); - ps.width = oneCell.width * preferredColumnCount + bi.left + bi.right + WebScrollBarUI.LENGTH + 1; + final JScrollBar vsb = getVerticalScrollBar (); + final int sbw = vsb != null && vsb.isShowing () ? vsb.getPreferredSize ().width : 0; + ps.width = oneCell.width * preferredColumnCount + bi.left + bi.right + sbw + 1; ps.height = oneCell.height * preferredRowCount + bi.top + bi.bottom + 1; return ps; } diff --git a/src/com/alee/extended/painter/AbstractPainter.java b/src/com/alee/extended/painter/AbstractPainter.java index ea5b0da55..8171b70d7 100644 --- a/src/com/alee/extended/painter/AbstractPainter.java +++ b/src/com/alee/extended/painter/AbstractPainter.java @@ -24,8 +24,8 @@ import java.util.List; /** - * This abstract painter provides a few additional features. - * Usually this class is extended by various painters instead of Painter interface. + * This abstract painter provides a few additional useful features atop of the Painter interface. + * Usually this class is extended by various painters instead of implementing Painter interface directly. * * @param component type * @author Mikle Garin @@ -34,6 +34,10 @@ public abstract class AbstractPainter implements Painter { + /** + * todo 1. Additional "quick" methods for painting (setAA/setFont/setComposite/...) + */ + /** * Whether visual data is opaque or not. */ @@ -54,6 +58,24 @@ public abstract class AbstractPainter implements Painter */ protected List listeners = new ArrayList ( 1 ); + /** + * {@inheritDoc} + */ + @Override + public void install ( final E c ) + { + // Simply do nothing by default + } + + /** + * {@inheritDoc} + */ + @Override + public void uninstall ( final E c ) + { + // Simply do nothing by default + } + /** * {@inheritDoc} */ @@ -71,7 +93,7 @@ public boolean isOpaque ( final E c ) public void setOpaque ( final boolean opaque ) { this.opaque = opaque; - fireRepaint (); + repaint (); } /** @@ -91,7 +113,7 @@ public Dimension getPreferredSize ( final E c ) public void setPreferredSize ( final Dimension preferredSize ) { this.preferredSize = preferredSize; - fireRevalidate (); + revalidate (); } /** @@ -111,7 +133,7 @@ public Insets getMargin ( final E c ) public void setMargin ( final Insets margin ) { this.margin = margin; - fireRevalidate (); + revalidate (); } /** @@ -156,37 +178,75 @@ public void removePainterListener ( final PainterListener listener ) } /** - * Fired when painter size and visual representation changes. - * Calls both revalidate and update listener methods. + * Should be called when painter visual representation changes. */ - public void fireUpdate () + public void repaint () { for ( final PainterListener listener : CollectionUtils.copy ( listeners ) ) { - listener.revalidate (); listener.repaint (); } } /** - * Fired when painter visual representation changes. + * Should be called when part of painter visual representation changes. + * + * @param bounds part bounds + */ + public void repaint ( final Rectangle bounds ) + { + repaint ( bounds.x, bounds.y, bounds.width, bounds.height ); + } + + /** + * Should be called when part of painter visual representation changes. + * + * @param x part bounds X coordinate + * @param y part bounds Y coordinate + * @param width part bounds width + * @param height part bounds height + */ + public void repaint ( final int x, final int y, final int width, final int height ) + { + for ( final PainterListener listener : CollectionUtils.copy ( listeners ) ) + { + listener.repaint ( x, y, width, height ); + } + } + + /** + * Should be called when painter size or border changes. */ - public void fireRepaint () + public void revalidate () { for ( final PainterListener listener : CollectionUtils.copy ( listeners ) ) { - listener.repaint (); + listener.revalidate (); } } /** - * Fired when painter size changes. + * Should be called when painter opacity changes. */ - public void fireRevalidate () + public void updateOpacity () { for ( final PainterListener listener : CollectionUtils.copy ( listeners ) ) { + listener.updateOpacity (); + } + } + + /** + * Should be called when painter size, border and visual representation changes. + * Calls both revalidate and update listener methods. + */ + public void updateAll () + { + for ( final PainterListener listener : CollectionUtils.copy ( listeners ) ) + { + listener.updateOpacity (); listener.revalidate (); + listener.repaint (); } } } \ No newline at end of file diff --git a/src/com/alee/extended/painter/AlphaLayerPainter.java b/src/com/alee/extended/painter/AlphaLayerPainter.java index ccbe2a2d6..a4d6157b1 100644 --- a/src/com/alee/extended/painter/AlphaLayerPainter.java +++ b/src/com/alee/extended/painter/AlphaLayerPainter.java @@ -105,7 +105,7 @@ public int getSquareSize () public void setSquareSize ( final int squareSize ) { this.squareSize = squareSize; - fireRepaint (); + repaint (); } /** @@ -126,7 +126,7 @@ public Color getLightSquareColor () public void setLightSquareColor ( final Color lightSquareColor ) { this.lightSquareColor = lightSquareColor; - fireRepaint (); + repaint (); } /** @@ -147,7 +147,7 @@ public Color getDarkSquareColor () public void setDarkSquareColor ( final Color darkSquareColor ) { this.darkSquareColor = darkSquareColor; - fireRepaint (); + repaint (); } /** diff --git a/src/com/alee/extended/painter/BorderPainter.java b/src/com/alee/extended/painter/BorderPainter.java index f8849230f..a0a49ac87 100644 --- a/src/com/alee/extended/painter/BorderPainter.java +++ b/src/com/alee/extended/painter/BorderPainter.java @@ -122,7 +122,7 @@ public void setWidth ( final int width ) { this.width = width; updateStroke (); - fireUpdate (); + updateAll (); } /** @@ -145,7 +145,7 @@ public void setRound ( final int round ) { this.round = round; updateStroke (); - fireRepaint (); + repaint (); } /** @@ -166,7 +166,7 @@ public Color getColor () public void setColor ( final Color color ) { this.color = color; - fireRepaint (); + repaint (); } /** @@ -190,7 +190,7 @@ public Stroke getStroke () public void setStroke ( final Stroke stroke ) { this.stroke = stroke; - fireRepaint (); + repaint (); } /** @@ -224,7 +224,7 @@ public Dimension getPreferredSize ( final E c ) @Override public Insets getMargin ( final E c ) { - Insets m = super.getMargin ( c ); + final Insets m = super.getMargin ( c ); return new Insets ( m.top + width, m.left + width, m.bottom + width, m.right + width ); } diff --git a/src/com/alee/extended/painter/ColorPainter.java b/src/com/alee/extended/painter/ColorPainter.java index c7e0900cf..20280208e 100644 --- a/src/com/alee/extended/painter/ColorPainter.java +++ b/src/com/alee/extended/painter/ColorPainter.java @@ -66,7 +66,7 @@ public Color getColor () public void setColor ( final Color color ) { this.color = color; - fireRepaint (); + repaint (); } /** diff --git a/src/com/alee/extended/painter/DashedBorderPainter.java b/src/com/alee/extended/painter/DashedBorderPainter.java index 4c1d91476..8fdc429d7 100644 --- a/src/com/alee/extended/painter/DashedBorderPainter.java +++ b/src/com/alee/extended/painter/DashedBorderPainter.java @@ -56,7 +56,7 @@ public DashedBorderPainter () * * @param dash dashing pattern */ - public DashedBorderPainter ( float[] dash ) + public DashedBorderPainter ( final float[] dash ) { super (); setDash ( dash ); @@ -68,7 +68,7 @@ public DashedBorderPainter ( float[] dash ) * @param dash dashing pattern * @param dashPhase dashing pattern offset */ - public DashedBorderPainter ( float[] dash, float dashPhase ) + public DashedBorderPainter ( final float[] dash, final float dashPhase ) { super (); setDash ( dash ); @@ -91,11 +91,11 @@ public float[] getDash () * * @param dash new dashing pattern */ - public void setDash ( float[] dash ) + public void setDash ( final float[] dash ) { this.dash = dash; updateStroke (); - fireRepaint (); + repaint (); } /** @@ -114,11 +114,11 @@ public float getDashPhase () * * @param dashPhase new dashing pattern offset */ - public void setDashPhase ( float dashPhase ) + public void setDashPhase ( final float dashPhase ) { this.dashPhase = dashPhase; updateStroke (); - fireRepaint (); + repaint (); } /** diff --git a/src/com/alee/extended/painter/NinePatchIconPainter.java b/src/com/alee/extended/painter/NinePatchIconPainter.java index 2b06a3bf1..22a5a4ce2 100644 --- a/src/com/alee/extended/painter/NinePatchIconPainter.java +++ b/src/com/alee/extended/painter/NinePatchIconPainter.java @@ -130,7 +130,7 @@ public NinePatchIcon getNinePatchIcon () public void setNinePatchIcon ( final NinePatchIcon icon ) { this.icon = icon; - fireUpdate (); + updateAll (); } /** diff --git a/src/com/alee/extended/painter/NinePatchStatePainter.java b/src/com/alee/extended/painter/NinePatchStatePainter.java index 944904b35..88c5b047d 100644 --- a/src/com/alee/extended/painter/NinePatchStatePainter.java +++ b/src/com/alee/extended/painter/NinePatchStatePainter.java @@ -86,7 +86,7 @@ public Map getStateIcons () public void setStateIcons ( final Map stateIcons ) { this.stateIcons = stateIcons; - fireUpdate (); + updateAll (); } /** @@ -98,7 +98,7 @@ public void setStateIcons ( final Map stateIcons ) public void addStateIcon ( final String state, final NinePatchIcon ninePatchIcon ) { stateIcons.put ( state, ninePatchIcon ); - fireUpdate (); + updateAll (); } /** @@ -109,7 +109,7 @@ public void addStateIcon ( final String state, final NinePatchIcon ninePatchIcon public void removeStateIcon ( final String state ) { stateIcons.remove ( state ); - fireUpdate (); + updateAll (); } /** @@ -323,7 +323,7 @@ public Dimension getPreferredSize ( final E c ) if ( hasStateIcons () ) { Dimension maxDimension = new Dimension ( 0, 0 ); - for ( NinePatchIcon npi : stateIcons.values () ) + for ( final NinePatchIcon npi : stateIcons.values () ) { npi.setComponent ( c ); maxDimension = SwingUtils.max ( maxDimension, npi.getPreferredSize () ); diff --git a/src/com/alee/extended/painter/Painter.java b/src/com/alee/extended/painter/Painter.java index 81a7eb04e..20eed3766 100644 --- a/src/com/alee/extended/painter/Painter.java +++ b/src/com/alee/extended/painter/Painter.java @@ -20,8 +20,12 @@ import java.awt.*; /** - * This interface provides basic methods for component background (or component parts) painting. - * It is supported in most of the Web-components and WebLaF UIs so that you can quickly and easily change any component view. + * This interface provides basic methods for component view painting. + * Using painters you can quickly and easily change Swing and WebLaF components view. + *

+ * You might want to use single painter for multiply components, but be aware that whether or not single painter can work with multiply + * components at once depends only on its own way of implementation. In most cases painters which does some animation won't work well with + * multiply components unless noted otherwise. * * @param component type * @author Mikle Garin @@ -31,9 +35,20 @@ public interface Painter { /** - * todo 1. Opacity change fired in listener - * todo 2. Additional "quick" methods for painting (setAA/setFont/setComposite/...) + * Called when painter is intalled into some component. + * You might want to use this method to add custom component listeners or modify component settings. + * + * @param c component to process + */ + public void install ( E c ); + + /** + * Called when painter is intalled into some component. + * You might want to use this method to add custom component listeners or modify component settings. + * + * @param c component to process */ + public void uninstall ( E c ); /** * Returns whether visual data provided by this painter is opaque or not. diff --git a/src/com/alee/extended/painter/PainterListener.java b/src/com/alee/extended/painter/PainterListener.java index 754424b81..7d9e9bdc0 100644 --- a/src/com/alee/extended/painter/PainterListener.java +++ b/src/com/alee/extended/painter/PainterListener.java @@ -30,9 +30,25 @@ public interface PainterListener */ public void repaint (); + /** + * Called when part of painter visual representation changes. + * + * @param x part bounds X coordinate + * @param y part bounds Y coordinate + * @param width part bounds width + * @param height part bounds height + */ + public void repaint ( int x, int y, int width, int height ); + /** * Called when painter preferred size or margin changes. * This call will usually cause component border update. */ public void revalidate (); + + /** + * Called when painter requires component opacity to be updated. + * Make sure you know what you are doing in case you are modifying opacity in runtime. + */ + public void updateOpacity (); } \ No newline at end of file diff --git a/src/com/alee/extended/painter/PainterSupport.java b/src/com/alee/extended/painter/PainterSupport.java index 4c5f0b067..8a2825925 100644 --- a/src/com/alee/extended/painter/PainterSupport.java +++ b/src/com/alee/extended/painter/PainterSupport.java @@ -17,8 +17,8 @@ package com.alee.extended.painter; +import com.alee.laf.WebLookAndFeel; import com.alee.utils.LafUtils; -import com.alee.utils.swing.BorderMethods; import javax.swing.*; import java.util.Map; @@ -40,16 +40,20 @@ public final class PainterSupport /** * Installs painter into the specified component. + * It is highly recommended to call this method only from EDT. * * @param component component painter is applied to * @param painter painter to install */ public static void installPainter ( final JComponent component, final Painter painter ) { + // Simply ignore this call if empty painter is set or component doesn't exist if ( component == null || painter == null ) { return; } + + // Installing painter Map listeners = installedPainters.get ( component ); if ( listeners == null ) { @@ -58,25 +62,49 @@ public static void installPainter ( final JComponent component, final Painter pa } if ( !installedPainters.containsKey ( painter ) ) { + // Installing painter + painter.install ( component ); + + // Applying initial component settings + LookAndFeel.installProperty ( component, WebLookAndFeel.OPAQUE_PROPERTY, painter.isOpaque ( component ) ); + + // Updating border + LafUtils.updateBorder ( component ); + + // Adding painter listener final PainterListener listener = new PainterListener () { @Override public void repaint () { + // Forcing component to be repainted component.repaint (); } + @Override + public void repaint ( final int x, final int y, final int width, final int height ) + { + // Forcing component to be repainted + component.repaint ( x, y, width, height ); + } + @Override public void revalidate () { - final BorderMethods borderMethods = LafUtils.getBorderMethods ( component ); - if ( borderMethods != null ) - { - // todo Move to separate "updateBorder" method in PainterListener - borderMethods.updateBorder (); - } + // todo Move to separate "updateBorder" method in PainterListener? + // Forcing border updates + LafUtils.updateBorder ( component ); + + // Forcing layout updates component.revalidate (); } + + @Override + public void updateOpacity () + { + // Updating component opacity according to painter + component.setOpaque ( painter.isOpaque ( component ) ); + } }; painter.addPainterListener ( listener ); listeners.put ( painter, listener ); @@ -85,6 +113,7 @@ public void revalidate () /** * Uninstalls painter from the specified component. + * It is highly recommended to call this method only from EDT. * * @param component component painter is uninstalled from * @param painter painter to uninstall @@ -98,6 +127,10 @@ public static void uninstallPainter ( final JComponent component, final Painter final Map listeners = installedPainters.get ( component ); if ( listeners != null ) { + // Uninstalling painter + painter.uninstall ( component ); + + // Removing painter listener listeners.remove ( painter ); } } diff --git a/src/com/alee/extended/painter/TexturePainter.java b/src/com/alee/extended/painter/TexturePainter.java index fe4d81b52..24708025c 100644 --- a/src/com/alee/extended/painter/TexturePainter.java +++ b/src/com/alee/extended/painter/TexturePainter.java @@ -140,7 +140,7 @@ public void setImage ( final BufferedImage image ) protected void updatePainter ( final BufferedImage image ) { this.paint = image != null ? new TexturePaint ( image, new Rectangle ( 0, 0, image.getWidth (), image.getHeight () ) ) : null; - fireRepaint (); + repaint (); } /** diff --git a/src/com/alee/extended/painter/TitledBorderPainter.java b/src/com/alee/extended/painter/TitledBorderPainter.java index 2e3fc1253..0bf723703 100644 --- a/src/com/alee/extended/painter/TitledBorderPainter.java +++ b/src/com/alee/extended/painter/TitledBorderPainter.java @@ -136,7 +136,7 @@ public int getTitleOffset () public void setTitleOffset ( final int titleOffset ) { this.titleOffset = titleOffset; - fireUpdate (); + updateAll (); } public int getTitleBorderGap () @@ -147,7 +147,7 @@ public int getTitleBorderGap () public void setTitleBorderGap ( final int titleBorderGap ) { this.titleBorderGap = titleBorderGap; - fireUpdate (); + updateAll (); } public int getTitleSide () @@ -158,7 +158,7 @@ public int getTitleSide () public void setTitleSide ( final int titleSide ) { this.titleSide = titleSide; - fireUpdate (); + updateAll (); } public int getTitleAlignment () @@ -169,7 +169,7 @@ public int getTitleAlignment () public void setTitleAlignment ( final int titleAlignment ) { this.titleAlignment = titleAlignment; - fireRepaint (); + repaint (); } public TitlePosition getTitlePosition () @@ -180,7 +180,7 @@ public TitlePosition getTitlePosition () public void setTitlePosition ( final TitlePosition titlePosition ) { this.titlePosition = titlePosition; - fireRepaint (); + repaint (); } public Color getForeground () @@ -191,7 +191,7 @@ public Color getForeground () public void setForeground ( final Color foreground ) { this.foreground = foreground; - fireRepaint (); + repaint (); } public Color getBackground () @@ -202,7 +202,7 @@ public Color getBackground () public void setBackground ( final Color background ) { this.background = background; - fireRepaint (); + repaint (); } public boolean isClipTitleBackground () @@ -213,7 +213,7 @@ public boolean isClipTitleBackground () public void setClipTitleBackground ( final boolean clipTitleBackground ) { this.clipTitleBackground = clipTitleBackground; - fireRepaint (); + repaint (); } public String getTitleText () @@ -224,7 +224,7 @@ public String getTitleText () public void setTitleText ( final String titleText ) { this.titleText = titleText; - fireUpdate (); + updateAll (); } @Override @@ -349,7 +349,7 @@ public void paint ( final Graphics2D g2d, final Rectangle bounds, final E c ) case TOP: case BOTTOM: { - Map hints = SwingUtils.setupTextAntialias ( g2d ); + final Map hints = SwingUtils.setupTextAntialias ( g2d ); g2d.drawString ( titleText, titleX, titleY ); SwingUtils.restoreTextAntialias ( g2d, hints ); break; @@ -443,7 +443,7 @@ protected int getTitleAreaHeight ( final E c ) } else { - int height = c.getFontMetrics ( c.getFont () ).getHeight (); + final int height = c.getFontMetrics ( c.getFont () ).getHeight (); return titlePosition.equals ( TitlePosition.onLine ) ? height : height + width; } } diff --git a/src/com/alee/extended/painter/WebStylePainter.java b/src/com/alee/extended/painter/WebStylePainter.java index a374506fc..8a84ac2c5 100644 --- a/src/com/alee/extended/painter/WebStylePainter.java +++ b/src/com/alee/extended/painter/WebStylePainter.java @@ -55,10 +55,10 @@ public boolean isDrawBackground () return drawBackground; } - public void setDrawBackground ( boolean drawBackground ) + public void setDrawBackground ( final boolean drawBackground ) { this.drawBackground = drawBackground; - fireRepaint (); + repaint (); } public int getRound () @@ -66,10 +66,10 @@ public int getRound () return round; } - public void setRound ( int round ) + public void setRound ( final int round ) { this.round = round; - fireRepaint (); + repaint (); } public boolean isDrawFocus () @@ -77,10 +77,10 @@ public boolean isDrawFocus () return drawFocus; } - public void setDrawFocus ( boolean drawFocus ) + public void setDrawFocus ( final boolean drawFocus ) { this.drawFocus = drawFocus; - fireRepaint (); + repaint (); } public int getShadeWidth () @@ -88,10 +88,10 @@ public int getShadeWidth () return shadeWidth; } - public void setShadeWidth ( int shadeWidth ) + public void setShadeWidth ( final int shadeWidth ) { this.shadeWidth = shadeWidth; - fireUpdate (); + updateAll (); } public boolean isFillBackground () @@ -99,10 +99,10 @@ public boolean isFillBackground () return fillBackground; } - public void setFillBackground ( boolean fillBackground ) + public void setFillBackground ( final boolean fillBackground ) { this.fillBackground = fillBackground; - fireRepaint (); + repaint (); } public boolean isWebColored () @@ -110,26 +110,17 @@ public boolean isWebColored () return webColored; } - public void setWebColored ( boolean webColored ) + public void setWebColored ( final boolean webColored ) { this.webColored = webColored; - fireRepaint (); + repaint (); } /** * {@inheritDoc} */ @Override - public boolean isOpaque ( E c ) - { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public Insets getMargin ( E c ) + public Insets getMargin ( final E c ) { return new Insets ( shadeWidth + 1, shadeWidth + 1, shadeWidth + 1, shadeWidth + 1 ); } @@ -138,7 +129,7 @@ public Insets getMargin ( E c ) * {@inheritDoc} */ @Override - public void paint ( Graphics2D g2d, Rectangle bounds, E c ) + public void paint ( final Graphics2D g2d, final Rectangle bounds, final E c ) { if ( drawBackground ) { diff --git a/src/com/alee/extended/tree/AsyncTreeDataUpdater.java b/src/com/alee/extended/tree/AsyncTreeDataUpdater.java index 66d632e49..3e4d5257b 100644 --- a/src/com/alee/extended/tree/AsyncTreeDataUpdater.java +++ b/src/com/alee/extended/tree/AsyncTreeDataUpdater.java @@ -54,10 +54,10 @@ public interface AsyncTreeDataUpdater * Called when node move (D&D or cut/paste) operation performed. * At this point node is already moved visually, but you can still cancel this action if you cannot update data properly. * - * @param node moved node - * @param oldParent old parent node - * @param newParent new parent node - * @param renameFailed runnable you should call in case data update failed, it will cancel changes + * @param node moved node + * @param oldParent old parent node + * @param newParent new parent node + * @param moveFailed runnable you should call in case data update failed, it will cancel changes */ public void nodeMoved ( E node, E oldParent, E newParent, Runnable moveFailed ); @@ -66,7 +66,7 @@ public interface AsyncTreeDataUpdater * At this point node is already removed visually, but you can still cancel this action if you cannot update data properly. * * @param node removed node - * @param renameFailed runnable you should call in case data update failed, it will cancel changes + * @param removeFailed runnable you should call in case data update failed, it will cancel changes */ public void nodeRemoved ( E node, Runnable removeFailed ); } \ No newline at end of file diff --git a/src/com/alee/extended/tree/AsyncTreeModel.java b/src/com/alee/extended/tree/AsyncTreeModel.java index 60264a7ca..959960b7b 100644 --- a/src/com/alee/extended/tree/AsyncTreeModel.java +++ b/src/com/alee/extended/tree/AsyncTreeModel.java @@ -1118,9 +1118,9 @@ protected void registerObservers ( final List nodes ) * * @param nodes nodes */ - protected void registerObservers ( final E[] children ) + protected void registerObservers ( final E[] nodes ) { - for ( final E newChild : children ) + for ( final E newChild : nodes ) { registerObserver ( newChild ); } diff --git a/src/com/alee/extended/tree/WebAsyncTree.java b/src/com/alee/extended/tree/WebAsyncTree.java index beb3da6df..ae66e1785 100644 --- a/src/com/alee/extended/tree/WebAsyncTree.java +++ b/src/com/alee/extended/tree/WebAsyncTree.java @@ -529,7 +529,7 @@ public E findNode ( final String nodeId ) /** * Forces tree node with the specified ID to be updated. * - * @param node ID of the tree node to be updated + * @param nodeId ID of the tree node to be updated */ public void updateNode ( final String nodeId ) { diff --git a/src/com/alee/extended/tree/WebAsyncTreeCellRenderer.java b/src/com/alee/extended/tree/WebAsyncTreeCellRenderer.java index 9e22ed305..546a17869 100644 --- a/src/com/alee/extended/tree/WebAsyncTreeCellRenderer.java +++ b/src/com/alee/extended/tree/WebAsyncTreeCellRenderer.java @@ -50,7 +50,6 @@ public class WebAsyncTreeCellRenderer extends WebTreeCellRenderer /** * Returns user failed state icon. * - * @param key icon key * @param icon base icon * @return user failed state icon */ diff --git a/src/com/alee/extended/window/WebPopOver.java b/src/com/alee/extended/window/WebPopOver.java index 8f67c8b8c..cb16d7027 100644 --- a/src/com/alee/extended/window/WebPopOver.java +++ b/src/com/alee/extended/window/WebPopOver.java @@ -229,7 +229,7 @@ public void mouseDragged ( final MouseEvent e ) attached = false; preferredDirection = null; painter.setPopupPainterStyle ( PopupPainterStyle.simple ); - painter.fireUpdate (); + painter.updateAll (); } super.mouseDragged ( e ); diff --git a/src/com/alee/laf/WebLookAndFeel.java b/src/com/alee/laf/WebLookAndFeel.java index 5f40d30e8..1ccbea8b8 100644 --- a/src/com/alee/laf/WebLookAndFeel.java +++ b/src/com/alee/laf/WebLookAndFeel.java @@ -504,6 +504,7 @@ protected void initComponentDefaults ( final UIDefaults table ) // Scroll bars minimum size table.put ( "ScrollBar.minimumThumbSize", new Dimension ( WebScrollBarStyle.minThumbWidth, WebScrollBarStyle.minThumbHeight ) ); + table.put ( "ScrollBar.width", new Integer ( 10 ) ); // Tree icons table.put ( "Tree.openIcon", WebTreeUI.OPEN_ICON ); diff --git a/src/com/alee/laf/button/WebButton.java b/src/com/alee/laf/button/WebButton.java index 8dfef9e8a..186c2cdfa 100644 --- a/src/com/alee/laf/button/WebButton.java +++ b/src/com/alee/laf/button/WebButton.java @@ -98,6 +98,12 @@ public WebButton ( final Action a ) super ( a ); } + public WebButton ( final Painter painter ) + { + super (); + setPainter ( painter ); + } + /** * Proxified kotkey manager methods */ diff --git a/src/com/alee/laf/button/WebButtonUI.java b/src/com/alee/laf/button/WebButtonUI.java index 1ade09352..82b63f6fd 100644 --- a/src/com/alee/laf/button/WebButtonUI.java +++ b/src/com/alee/laf/button/WebButtonUI.java @@ -785,6 +785,11 @@ public void setDrawLines ( final boolean top, final boolean left, final boolean updateBorder (); } + public boolean isRollover () + { + return rollover; + } + @Override public void paint ( final Graphics g, final JComponent c ) { diff --git a/src/com/alee/laf/button/WebToggleButtonUI.java b/src/com/alee/laf/button/WebToggleButtonUI.java index d33b3888d..03646e153 100644 --- a/src/com/alee/laf/button/WebToggleButtonUI.java +++ b/src/com/alee/laf/button/WebToggleButtonUI.java @@ -26,9 +26,17 @@ public class WebToggleButtonUI extends WebButtonUI { + private final static String propertyPrefix = "ToggleButton" + "."; + @SuppressWarnings ("UnusedParameters") - public static ComponentUI createUI ( JComponent c ) + public static ComponentUI createUI ( final JComponent c ) { return new WebToggleButtonUI (); } + + @Override + protected String getPropertyPrefix () + { + return propertyPrefix; + } } \ No newline at end of file diff --git a/src/com/alee/laf/combobox/WebComboBoxStyle.java b/src/com/alee/laf/combobox/WebComboBoxStyle.java index dca425b04..6d9e6be1b 100644 --- a/src/com/alee/laf/combobox/WebComboBoxStyle.java +++ b/src/com/alee/laf/combobox/WebComboBoxStyle.java @@ -21,50 +21,73 @@ import com.alee.utils.ImageUtils; import javax.swing.*; +import java.awt.*; /** - * User: mgarin Date: 31.10.12 Time: 17:07 + * WebComboBox style class. + * + * @author Mikle Garin */ public final class WebComboBoxStyle { /** - * Expand icon + * Expand icon. */ public static ImageIcon expandIcon = new ImageIcon ( WebComboBoxStyle.class.getResource ( "icons/arrow.png" ) ); /** - * Collapse icon + * Collapse icon. */ public static ImageIcon collapseIcon = ImageUtils.rotateImage180 ( expandIcon ); /** - * Icon side spacing + * Icon side spacing. */ public static int iconSpacing = 3; /** - * Draw combobox border + * Draw combobox border. */ public static boolean drawBorder = StyleConstants.drawBorder; /** - * Draw combobox focus + * Draw combobox focus. */ public static boolean drawFocus = true; /** - * Decoration rounding + * Decoration rounding. */ public static int round = StyleConstants.smallRound; /** - * Decoration shade width + * Decoration shade width. */ public static int shadeWidth = StyleConstants.shadeWidth; /** - * Values scrolling using mouse wheel enabled + * Values scrolling using mouse wheel enabled. */ public static boolean mouseWheelScrollingEnabled = true; -} + + /** + * Scroll bar thumb corners rounding. + */ + public static int scrollBarThumbRound = 4; + + /** + * Scroll bar margin. + */ + public static Insets scrollBarMargin = new Insets ( 0, 1, 0, 1 ); + + /** + * Whether should display scroll bar buttons or not. + */ + public static boolean scrollBarButtonsVisible = false; + + /** + * Whether should display scroll bar track or not. + */ + public static boolean scrollBarTrackVisible = false; +} \ No newline at end of file diff --git a/src/com/alee/laf/combobox/WebComboBoxUI.java b/src/com/alee/laf/combobox/WebComboBoxUI.java index fd8571b98..8da2fa35f 100644 --- a/src/com/alee/laf/combobox/WebComboBoxUI.java +++ b/src/com/alee/laf/combobox/WebComboBoxUI.java @@ -276,7 +276,10 @@ protected JScrollPane createScroller () if ( scrollBarUI instanceof WebScrollBarUI ) { final WebScrollBarUI webScrollBarUI = ( WebScrollBarUI ) scrollBarUI; - webScrollBarUI.setDrawBorder ( false ); + webScrollBarUI.setMargin ( WebComboBoxStyle.scrollBarMargin ); + webScrollBarUI.setThumbRound ( WebComboBoxStyle.scrollBarThumbRound ); + webScrollBarUI.setButtonsVisible ( WebComboBoxStyle.scrollBarButtonsVisible ); + webScrollBarUI.setDrawTrack ( WebComboBoxStyle.scrollBarTrackVisible ); } } diff --git a/src/com/alee/laf/desktoppane/WebDesktopIconUI.java b/src/com/alee/laf/desktoppane/WebDesktopIconUI.java index 6d36ee216..e76f31208 100644 --- a/src/com/alee/laf/desktoppane/WebDesktopIconUI.java +++ b/src/com/alee/laf/desktoppane/WebDesktopIconUI.java @@ -18,10 +18,10 @@ package com.alee.laf.desktoppane; import com.alee.laf.WebLookAndFeel; +import com.alee.utils.LafUtils; import com.alee.utils.SwingUtils; import javax.swing.*; -import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicDesktopIconUI; import java.awt.*; @@ -45,7 +45,7 @@ public void installUI ( final JComponent c ) // Default settings SwingUtils.setOrientation ( c ); - c.setBorder ( new BorderUIResource.EmptyBorderUIResource ( 0, 0, 0, 0 ) ); + c.setBorder ( LafUtils.createWebBorder ( 0, 0, 0, 0 ) ); LookAndFeel.installProperty ( c, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.FALSE ); } diff --git a/src/com/alee/laf/desktoppane/WebDesktopPaneUI.java b/src/com/alee/laf/desktoppane/WebDesktopPaneUI.java index 789520992..bc7b3a092 100644 --- a/src/com/alee/laf/desktoppane/WebDesktopPaneUI.java +++ b/src/com/alee/laf/desktoppane/WebDesktopPaneUI.java @@ -18,6 +18,8 @@ package com.alee.laf.desktoppane; import com.alee.laf.StyleConstants; +import com.alee.laf.WebLookAndFeel; +import com.alee.utils.LafUtils; import com.alee.utils.SwingUtils; import javax.swing.*; @@ -43,7 +45,8 @@ public void installUI ( final JComponent c ) // Default settings SwingUtils.setOrientation ( c ); - c.setOpaque ( true ); + LookAndFeel.installProperty ( c, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.TRUE ); + c.setBorder ( LafUtils.createWebBorder ( 0, 0, 0, 0 ) ); c.setBackground ( StyleConstants.backgroundColor ); } } \ No newline at end of file diff --git a/src/com/alee/laf/desktoppane/WebInternalFrameUI.java b/src/com/alee/laf/desktoppane/WebInternalFrameUI.java index 9ad484fdb..8864bec1f 100644 --- a/src/com/alee/laf/desktoppane/WebInternalFrameUI.java +++ b/src/com/alee/laf/desktoppane/WebInternalFrameUI.java @@ -18,6 +18,7 @@ package com.alee.laf.desktoppane; import com.alee.laf.StyleConstants; +import com.alee.laf.WebLookAndFeel; import com.alee.managers.focus.DefaultFocusTracker; import com.alee.managers.focus.FocusManager; import com.alee.managers.focus.FocusTracker; @@ -86,10 +87,10 @@ public void installUI ( final JComponent c ) super.installUI ( c ); // Default settings - SwingUtils.setOrientation ( c ); - c.setOpaque ( false ); - c.setBackground ( new Color ( 90, 90, 90, 220 ) ); - c.setBorder ( BorderFactory.createEmptyBorder () ); + SwingUtils.setOrientation ( frame ); + LookAndFeel.installProperty ( frame, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.FALSE ); + frame.setBackground ( new Color ( 90, 90, 90, 220 ) ); + frame.setBorder ( LafUtils.createWebBorder ( 0, 0, 0, 0 ) ); // Focus tracker for the panel content focusTracker = new DefaultFocusTracker () @@ -112,6 +113,7 @@ public void focusChanged ( final boolean focused ) @Override public void uninstallUI ( final JComponent c ) { + // Removing focus tracker FocusManager.removeFocusTracker ( focusTracker ); super.uninstallUI ( c ); diff --git a/src/com/alee/laf/filechooser/WebFileChooserPanel.java b/src/com/alee/laf/filechooser/WebFileChooserPanel.java index c748ee428..b4c79d205 100644 --- a/src/com/alee/laf/filechooser/WebFileChooserPanel.java +++ b/src/com/alee/laf/filechooser/WebFileChooserPanel.java @@ -38,6 +38,7 @@ import com.alee.laf.button.WebButton; import com.alee.laf.combobox.WebComboBox; import com.alee.laf.combobox.WebComboBoxCellRenderer; +import com.alee.laf.combobox.WebComboBoxStyle; import com.alee.laf.label.WebLabel; import com.alee.laf.list.WebList; import com.alee.laf.list.editor.ListEditAdapter; @@ -45,7 +46,7 @@ import com.alee.laf.menu.WebRadioButtonMenuItem; import com.alee.laf.optionpane.WebOptionPane; import com.alee.laf.panel.WebPanel; -import com.alee.laf.scroll.WebScrollBarUI; +import com.alee.laf.scroll.WebScrollBar; import com.alee.laf.scroll.WebScrollPane; import com.alee.laf.splitpane.WebSplitPane; import com.alee.laf.text.WebTextField; @@ -403,7 +404,7 @@ public Component getListCellRendererComponent ( final JList list, final Object v else { renderer.setIcon ( FileUtils.getFileIcon ( file ) ); - renderer.setText ( FileUtils.getDisplayFileName ( file ) ); + renderer.setText ( TextUtils.shortenText ( FileUtils.getDisplayFileName ( file ), 40, true ) ); } renderer.setBoldFont ( index == currentHistoryIndex ); @@ -419,10 +420,18 @@ public void mouseReleased ( final MouseEvent e ) historyPopup.setVisible ( false ); } } ); + final WebScrollPane scrollPane = new WebScrollPane ( historyList, false, false ); scrollPane.setOpaque ( false ); scrollPane.getViewport ().setOpaque ( false ); scrollPane.setShadeWidth ( 0 ); + + final WebScrollBar vsb = scrollPane.getWebVerticalScrollBar (); + vsb.setThumbRound ( WebComboBoxStyle.scrollBarThumbRound ); + vsb.setMargin ( WebComboBoxStyle.scrollBarMargin ); + vsb.setButtonsVisible ( WebComboBoxStyle.scrollBarButtonsVisible ); + vsb.setDrawTrack ( WebComboBoxStyle.scrollBarTrackVisible ); + historyPopup.add ( scrollPane ); historyPopup.showBelowMiddle ( history ); @@ -1528,8 +1537,15 @@ public void deleteSelectedFiles () public Dimension getPreferredSize () { final Dimension ps = super.getPreferredSize (); - ps.width = ps.width + WebScrollBarUI.LENGTH; + + final JScrollBar vsb = getVerticalScrollBar (); + if ( vsb != null && vsb.isShowing () ) + { + ps.width = ps.width + vsb.getPreferredSize ().width; + } + ps.height = Math.min ( ps.height, 100 ); + return ps; } }; diff --git a/src/com/alee/laf/filechooser/WebFileChooserUI.java b/src/com/alee/laf/filechooser/WebFileChooserUI.java index 8c2954e28..39741a448 100644 --- a/src/com/alee/laf/filechooser/WebFileChooserUI.java +++ b/src/com/alee/laf/filechooser/WebFileChooserUI.java @@ -22,6 +22,7 @@ import com.alee.laf.WebLookAndFeel; import com.alee.managers.language.LanguageManager; import com.alee.utils.FileUtils; +import com.alee.utils.LafUtils; import javax.swing.*; import javax.swing.filechooser.FileFilter; @@ -103,7 +104,7 @@ public void installUI ( final JComponent c ) fileView = new WebFileView (); fileChooser.setLayout ( new BorderLayout () ); - fileChooser.setBorder ( BorderFactory.createEmptyBorder ( 0, 0, 0, 0 ) ); + fileChooser.setBorder ( LafUtils.createWebBorder ( 0, 0, 0, 0 ) ); fileChooserPanel = new WebFileChooserPanel ( getFileChooserType (), fileChooser.getControlButtonsAreShown () ); fileChooserPanel.setMultiSelectionEnabled ( fileChooser.isMultiSelectionEnabled () ); diff --git a/src/com/alee/laf/list/WebListUI.java b/src/com/alee/laf/list/WebListUI.java index eb3ab873d..800b4431a 100644 --- a/src/com/alee/laf/list/WebListUI.java +++ b/src/com/alee/laf/list/WebListUI.java @@ -19,6 +19,7 @@ import com.alee.laf.StyleConstants; import com.alee.laf.WebLookAndFeel; +import com.alee.utils.GeometryUtils; import com.alee.utils.LafUtils; import com.alee.utils.SwingUtils; @@ -120,30 +121,30 @@ private void updateMouseover ( final MouseEvent e ) { final int oldIndex = rolloverIndex; rolloverIndex = index; - if ( rolloverIndex != -1 ) - { - final Rectangle cellBounds = list.getCellBounds ( rolloverIndex, rolloverIndex ); - if ( cellBounds != null ) - { - list.repaint ( cellBounds ); - } - else - { - list.repaint (); - } - } - if ( oldIndex != -1 ) - { - final Rectangle cellBounds = list.getCellBounds ( oldIndex, oldIndex ); - if ( cellBounds != null ) - { - list.repaint ( cellBounds ); - } - else - { - list.repaint (); - } - } + repaintChange ( oldIndex, rolloverIndex ); + } + } + + @Override + public void mouseExited ( final MouseEvent e ) + { + // Cleaning up rollover index + if ( rolloverIndex != -1 ) + { + final int oldIndex = rolloverIndex; + rolloverIndex = -1; + repaintChange ( oldIndex, rolloverIndex ); + } + } + + private void repaintChange ( final int oldIndex, final int newIndex ) + { + final Rectangle oldBounds = list.getCellBounds ( oldIndex, oldIndex ); + final Rectangle newBounds = list.getCellBounds ( newIndex, newIndex ); + final Rectangle rect = GeometryUtils.getContainingRect ( oldBounds, newBounds ); + if ( rect != null ) + { + list.repaint ( rect ); } } }; diff --git a/src/com/alee/laf/menu/PopupMenuPainter.java b/src/com/alee/laf/menu/PopupMenuPainter.java index 602670907..63bdfc6a7 100644 --- a/src/com/alee/laf/menu/PopupMenuPainter.java +++ b/src/com/alee/laf/menu/PopupMenuPainter.java @@ -21,7 +21,8 @@ import java.awt.*; /** - * Base painter for JPopupMenu component used as WebPopupMenuUI default styling. + * Base painter for JPopupMenu component. + * It is used as WebPopupMenuUI default styling. * * @author Mikle Garin */ diff --git a/src/com/alee/laf/menu/WebMenuBarUI.java b/src/com/alee/laf/menu/WebMenuBarUI.java index d5ce55e77..8876bd685 100644 --- a/src/com/alee/laf/menu/WebMenuBarUI.java +++ b/src/com/alee/laf/menu/WebMenuBarUI.java @@ -56,8 +56,8 @@ public void installUI ( final JComponent c ) // Default settings SwingUtils.setOrientation ( menuBar ); - menuBar.setLayout ( new ToolbarLayout ( 0 ) ); LookAndFeel.installProperty ( menuBar, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.FALSE ); + menuBar.setLayout ( new ToolbarLayout ( 0 ) ); // Updating border updateBorder (); diff --git a/src/com/alee/laf/menu/WebPopupMenuUI.java b/src/com/alee/laf/menu/WebPopupMenuUI.java index 7f6f52aa3..a91a3b9db 100644 --- a/src/com/alee/laf/menu/WebPopupMenuUI.java +++ b/src/com/alee/laf/menu/WebPopupMenuUI.java @@ -228,31 +228,6 @@ public void uninstallUI ( final JComponent c ) super.uninstallUI ( c ); } - /** - * Applies UI settings to this specific painter. - * - * @param painter popup menu painter - */ - protected void applyPainterSettings ( final PopupMenuPainter painter ) - { - if ( painter != null ) - { - // Style settings - painter.setPopupPainterStyle ( popupPainterStyle ); - painter.setBorderColor ( borderColor ); - painter.setRound ( round ); - painter.setShadeWidth ( shadeWidth ); - painter.setShadeOpacity ( shadeOpacity ); - painter.setCornerWidth ( cornerWidth ); - painter.setTransparency ( transparency ); - - // Runtime variables - painter.setTransparent ( transparent ); - painter.setCornerSide ( cornerSide ); - painter.setRelativeCorner ( relativeCorner ); - } - } - /** * {@inheritDoc} */ @@ -482,6 +457,7 @@ public Insets getMargin () public void setMargin ( final Insets margin ) { this.margin = margin; + updateBorder (); } /** @@ -506,7 +482,31 @@ public void setPainter ( final PopupMenuPainter painter ) this.painter = painter; applyPainterSettings ( painter ); PainterSupport.installPainter ( popupMenu, this.painter ); - updateBorder (); + } + + /** + * Applies UI settings to this specific painter. + * + * @param painter popup menu painter + */ + protected void applyPainterSettings ( final PopupMenuPainter painter ) + { + if ( painter != null ) + { + // Style settings + painter.setPopupPainterStyle ( popupPainterStyle ); + painter.setBorderColor ( borderColor ); + painter.setRound ( round ); + painter.setShadeWidth ( shadeWidth ); + painter.setShadeOpacity ( shadeOpacity ); + painter.setCornerWidth ( cornerWidth ); + painter.setTransparency ( transparency ); + + // Runtime variables + painter.setTransparent ( transparent ); + painter.setCornerSide ( cornerSide ); + painter.setRelativeCorner ( relativeCorner ); + } } /** @@ -726,7 +726,8 @@ else if ( !WebPopupMenuStyle.dropdownStyleForMenuBar ) } /** - * Paints popup menu decoration. + * Paints popup menu decorations. + * The whole painting process is delegated to installed painter class. * * @param g graphics context * @param c popup menu component @@ -736,7 +737,7 @@ public void paint ( final Graphics g, final JComponent c ) { if ( painter != null ) { - painter.paint ( ( Graphics2D ) g, SwingUtils.size ( c ), c ); + painter.paint ( ( Graphics2D ) g, SwingUtils.size ( popupMenu ), popupMenu ); } } } \ No newline at end of file diff --git a/src/com/alee/laf/menu/WebPopupPainter.java b/src/com/alee/laf/menu/WebPopupPainter.java index 9ebee6706..89805975c 100644 --- a/src/com/alee/laf/menu/WebPopupPainter.java +++ b/src/com/alee/laf/menu/WebPopupPainter.java @@ -38,9 +38,17 @@ * @author Mikle Garin */ -@SuppressWarnings ("UnusedParameters") +@SuppressWarnings ( "UnusedParameters" ) public class WebPopupPainter extends AbstractPainter implements PainterShapeProvider, SwingConstants { + /** + * Shape cache keys. + */ + protected static final String SIMPLE_FILL_SHAPE = "simple-fill"; + protected static final String SIMPLE_BORDER_SHAPE = "simple-border"; + protected static final String DROPDOWN_FILL_SHAPE = "dropdown-fill"; + protected static final String DROPDOWN_BORDER_SHAPE = "dropdown-border"; + /** * Style settings. */ @@ -82,7 +90,7 @@ public void setPopupPainterStyle ( final PopupPainterStyle style ) this.popupPainterStyle = style; if ( transparent ) { - fireUpdate (); + updateAll (); } } } @@ -109,7 +117,7 @@ public void setBorderColor ( final Color color ) this.borderColor = color; if ( transparent ) { - fireRepaint (); + repaint (); } } } @@ -136,7 +144,7 @@ public void setRound ( final int round ) this.round = round; if ( transparent ) { - fireRepaint (); + repaint (); } } } @@ -163,7 +171,7 @@ public void setShadeWidth ( final int width ) this.shadeWidth = width; if ( transparent ) { - fireUpdate (); + updateAll (); } } } @@ -190,7 +198,7 @@ public void setShadeOpacity ( final float opacity ) this.shadeOpacity = opacity; if ( transparent ) { - fireRepaint (); + repaint (); } } } @@ -217,7 +225,7 @@ public void setCornerWidth ( final int width ) this.cornerWidth = width; if ( transparent ) { - fireRepaint (); + repaint (); } } } @@ -244,7 +252,7 @@ public void setTransparency ( final float transparency ) this.transparency = transparency; if ( transparent ) { - fireRepaint (); + repaint (); } } } @@ -269,7 +277,7 @@ public void setTransparent ( final boolean transparent ) if ( this.transparent != transparent ) { this.transparent = transparent; - fireUpdate (); + updateAll (); } } @@ -295,7 +303,7 @@ public void setCornerSide ( final int cornerSide ) this.cornerSide = cornerSide; if ( transparent ) { - fireRepaint (); + repaint (); } } } @@ -322,7 +330,7 @@ public void setRelativeCorner ( final int relativeCorner ) this.relativeCorner = relativeCorner; if ( transparent ) { - fireRepaint (); + repaint (); } } } @@ -349,7 +357,7 @@ public void setCornerAlignment ( final int cornerAlignment ) this.cornerAlignment = cornerAlignment; if ( transparent ) { - fireRepaint (); + repaint (); } } } @@ -547,7 +555,7 @@ protected Shape getBorderShape ( final E popup, final Dimension popupSize, final { case simple: { - return ShapeCache.getShape ( popup, fill ? "simple-fill" : "simple-border", new DataProvider () + return ShapeCache.getShape ( popup, fill ? SIMPLE_FILL_SHAPE : SIMPLE_BORDER_SHAPE, new DataProvider () { @Override public Shape provide () @@ -558,7 +566,7 @@ public Shape provide () } case dropdown: { - return ShapeCache.getShape ( popup, fill ? "dropdown-fill" : "dropdown-border", new DataProvider () + return ShapeCache.getShape ( popup, fill ? DROPDOWN_FILL_SHAPE : DROPDOWN_BORDER_SHAPE, new DataProvider () { @Override public Shape provide () diff --git a/src/com/alee/laf/optionpane/WebOptionPaneUI.java b/src/com/alee/laf/optionpane/WebOptionPaneUI.java index e65dd2f9d..637057162 100644 --- a/src/com/alee/laf/optionpane/WebOptionPaneUI.java +++ b/src/com/alee/laf/optionpane/WebOptionPaneUI.java @@ -18,7 +18,9 @@ package com.alee.laf.optionpane; import com.alee.laf.StyleConstants; +import com.alee.laf.WebLookAndFeel; import com.alee.laf.button.WebButton; +import com.alee.utils.LafUtils; import com.alee.utils.SwingUtils; import javax.swing.*; @@ -53,16 +55,15 @@ public void installUI ( final JComponent c ) // Default settings SwingUtils.setOrientation ( optionPane ); - optionPane.setOpaque ( false ); + LookAndFeel.installProperty ( optionPane, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.FALSE ); optionPane.setBackground ( WebOptionPaneStyle.backgroundColor ); - - // Updating border - optionPane.setBorder ( BorderFactory.createEmptyBorder ( 15, 15, 15, 15 ) ); + optionPane.setBorder ( LafUtils.createWebBorder ( 15, 15, 15, 15 ) ); } @Override protected Container createMessageArea () { + // todo Really bad workaround final Container messageArea = super.createMessageArea (); SwingUtils.setOpaqueRecursively ( messageArea, false ); return messageArea; diff --git a/src/com/alee/laf/panel/WebPanelUI.java b/src/com/alee/laf/panel/WebPanelUI.java index 7aa99a773..9f08fc962 100644 --- a/src/com/alee/laf/panel/WebPanelUI.java +++ b/src/com/alee/laf/panel/WebPanelUI.java @@ -111,7 +111,7 @@ public void installUI ( final JComponent c ) // Default settings SwingUtils.setOrientation ( panel ); - panel.setOpaque ( true ); + LookAndFeel.installProperty ( panel, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.TRUE ); panel.setBackground ( WebPanelStyle.backgroundColor ); PainterSupport.installPainter ( panel, this.painter ); diff --git a/src/com/alee/laf/progressbar/WebProgressBarUI.java b/src/com/alee/laf/progressbar/WebProgressBarUI.java index 4ee96abde..b3899d5cd 100644 --- a/src/com/alee/laf/progressbar/WebProgressBarUI.java +++ b/src/com/alee/laf/progressbar/WebProgressBarUI.java @@ -18,6 +18,7 @@ package com.alee.laf.progressbar; import com.alee.laf.StyleConstants; +import com.alee.laf.WebLookAndFeel; import com.alee.utils.LafUtils; import com.alee.utils.SwingUtils; import com.alee.utils.ThreadUtils; @@ -78,7 +79,7 @@ public class WebProgressBarUI extends BasicProgressBarUI implements ShapeProvide private PropertyChangeListener propertyChangeListener; - @SuppressWarnings ( "UnusedParameters" ) + @SuppressWarnings ("UnusedParameters") public static ComponentUI createUI ( final JComponent c ) { return new WebProgressBarUI (); @@ -91,7 +92,7 @@ public void installUI ( final JComponent c ) // Default settings SwingUtils.setOrientation ( progressBar ); - progressBar.setOpaque ( false ); + LookAndFeel.installProperty ( progressBar, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.FALSE ); progressBar.setBorderPainted ( false ); progressBar.setForeground ( Color.DARK_GRAY ); diff --git a/src/com/alee/laf/resources/version.xml b/src/com/alee/laf/resources/version.xml index 34b29aa99..3d25a27f1 100644 --- a/src/com/alee/laf/resources/version.xml +++ b/src/com/alee/laf/resources/version.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/com/alee/laf/rootpane/WebRootPaneLayout.java b/src/com/alee/laf/rootpane/WebRootPaneLayout.java index 30058af5d..9838d6aae 100644 --- a/src/com/alee/laf/rootpane/WebRootPaneLayout.java +++ b/src/com/alee/laf/rootpane/WebRootPaneLayout.java @@ -340,6 +340,10 @@ else if ( showMenuBar ) } if ( showResizeCorner ) { + // Placing resize corner at the top of all other components within the root pane + // Called from here since root pane content might be changed and we have to keep this up-to-date + parent.setComponentZOrder ( resizeCorner, 0 ); + final Dimension rcd = resizeCorner.getPreferredSize (); if ( rcd != null ) { diff --git a/src/com/alee/laf/scroll/ScrollBarButtonPainter.java b/src/com/alee/laf/scroll/ScrollBarButtonPainter.java new file mode 100644 index 000000000..ad766c704 --- /dev/null +++ b/src/com/alee/laf/scroll/ScrollBarButtonPainter.java @@ -0,0 +1,423 @@ +/* + * This file is part of WebLookAndFeel library. + * + * WebLookAndFeel library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WebLookAndFeel library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WebLookAndFeel library. If not, see . + */ + +package com.alee.laf.scroll; + +import com.alee.extended.painter.AbstractPainter; +import com.alee.laf.button.WebButtonUI; +import com.alee.utils.ShapeCache; +import com.alee.utils.swing.DataProvider; + +import javax.swing.*; +import javax.swing.plaf.ButtonUI; +import java.awt.*; +import java.awt.geom.GeneralPath; + +/** + * Base painter for JScrollBar arrow buttons. + * + * @author Mikle Garin + */ + +public class ScrollBarButtonPainter extends AbstractPainter +{ + /** + * todo 1. On rollover=false make the same animation scroll bar thumb has -> requires WebButtonUI full painter support + */ + + /** + * Shape cache key. + */ + protected static final String ARROW_BUTTON_SHAPE = "arrow-button"; + + /** + * Style settings. + */ + protected Color borderColor = WebScrollBarStyle.thumbBorderColor; + protected Color backgroundColor = WebScrollBarStyle.thumbBackgroundColor; + protected Color disabledBorderColor = WebScrollBarStyle.thumbDisabledBorderColor; + protected Color disabledBackgroundColor = WebScrollBarStyle.thumbDisabledBackgroundColor; + protected Color rolloverBorderColor = WebScrollBarStyle.thumbRolloverBorderColor; + protected Color rolloverBackgroundColor = WebScrollBarStyle.thumbRolloverBackgroundColor; + protected Color pressedBorderColor = WebScrollBarStyle.thumbPressedBorderColor; + protected Color pressedBackgroundColor = WebScrollBarStyle.thumbPressedBackgroundColor; + + /** + * Runtime variables. + */ + protected final ScrollBarButtonType buttonType; + protected final JScrollBar scrollbar; + + /** + * Constructs new scroll bar button painter. + * + * @param scrollbar scroll bar which uses this button + * @param buttonType button type + */ + public ScrollBarButtonPainter ( final JScrollBar scrollbar, final ScrollBarButtonType buttonType ) + { + super (); + this.scrollbar = scrollbar; + this.buttonType = buttonType; + setPreferredSize ( new Dimension ( WebScrollBarStyle.buttonsSize ) ); + } + + /** + * Returns button border color. + * + * @return button border color + */ + public Color getBorderColor () + { + return borderColor; + } + + /** + * Sets button border color. + * + * @param color new button border color + */ + public void setBorderColor ( final Color color ) + { + if ( this.borderColor != color ) + { + this.borderColor = color; + repaint (); + } + } + + /** + * Returns button background color. + * + * @return button background color + */ + public Color getBackgroundColor () + { + return backgroundColor; + } + + /** + * Sets button background color. + * + * @param color new button background color + */ + public void setBackgroundColor ( final Color color ) + { + if ( this.backgroundColor != color ) + { + this.backgroundColor = color; + repaint (); + } + } + + /** + * Returns disabled button border color. + * + * @return disabled button border color + */ + public Color getDisabledBorderColor () + { + return disabledBorderColor; + } + + /** + * Sets disabled button border color. + * + * @param color new disabled button border color + */ + public void setDisabledBorderColor ( final Color color ) + { + if ( this.disabledBorderColor != color ) + { + this.disabledBorderColor = color; + repaint (); + } + } + + /** + * Returns disabled button background color. + * + * @return disabled button background color + */ + public Color getDisabledBackgroundColor () + { + return disabledBackgroundColor; + } + + /** + * Sets disabled button background color. + * + * @param color new disabled button background color + */ + public void setDisabledBackgroundColor ( final Color color ) + { + if ( this.disabledBackgroundColor != color ) + { + this.disabledBackgroundColor = color; + repaint (); + } + } + + /** + * Returns rollover button border color. + * + * @return rollover button border color + */ + public Color getRolloverBorderColor () + { + return rolloverBorderColor; + } + + /** + * Sets rollover button border color. + * + * @param color new rollover button border color + */ + public void setRolloverBorderColor ( final Color color ) + { + if ( this.rolloverBorderColor != color ) + { + this.rolloverBorderColor = color; + repaint (); + } + } + + /** + * Returns rollover button background color. + * + * @return rollover button background color + */ + public Color getRolloverBackgroundColor () + { + return rolloverBackgroundColor; + } + + /** + * Sets rollover button background color. + * + * @param color new rollover button background color + */ + public void setRolloverBackgroundColor ( final Color color ) + { + if ( this.rolloverBackgroundColor != color ) + { + this.rolloverBackgroundColor = color; + repaint (); + } + } + + /** + * Returns pressed button border color. + * + * @return pressed button border color + */ + public Color getPressedBorderColor () + { + return pressedBorderColor; + } + + /** + * Sets pressed button border color. + * + * @param color new pressed button border color + */ + public void setPressedBorderColor ( final Color color ) + { + if ( this.pressedBorderColor != color ) + { + this.pressedBorderColor = color; + repaint (); + } + } + + /** + * Returns pressed button background color. + * + * @return pressed button background color + */ + public Color getPressedBackgroundColor () + { + return pressedBackgroundColor; + } + + /** + * Sets pressed button background color. + * + * @param color new pressed button background color + */ + public void setPressedBackgroundColor ( final Color color ) + { + if ( this.pressedBackgroundColor != color ) + { + this.pressedBackgroundColor = color; + repaint (); + } + } + + /** + * Returns scroll bar button type. + * + * @return scroll bar button type + */ + public ScrollBarButtonType getButtonType () + { + return buttonType; + } + + /** + * Returns scroll bar which uses this button. + * + * @return scroll bar which uses this button + */ + public JScrollBar getScrollbar () + { + return scrollbar; + } + + /** + * {@inheritDoc} + */ + @Override + public Insets getMargin ( final E button ) + { + final boolean ver = scrollbar.getOrientation () == SwingConstants.VERTICAL; + final boolean decr = buttonType == ScrollBarButtonType.decrease; + if ( ver ) + { + return new Insets ( decr ? 1 : 0, 1, decr ? 0 : 1, 1 ); + } + else + { + return new Insets ( 1, decr ? 1 : 0, 1, decr ? 0 : 1 ); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void paint ( final Graphics2D g2d, final Rectangle bounds, final E button ) + { + // Button model state + final ButtonModel model = button.getModel (); + final ButtonUI ui = button.getUI (); + final boolean enabled = button.isEnabled (); + final boolean pressed = model.isPressed () || model.isSelected (); + final boolean rollover = ui instanceof WebButtonUI ? ( ( WebButtonUI ) ui ).isRollover () : model.isRollover (); + + // Retrieving button shape + final Shape shape = getArrowButtonShape ( bounds, button ); + + // Painting button + g2d.setPaint ( enabled ? ( pressed ? pressedBackgroundColor : ( rollover ? rolloverBackgroundColor : backgroundColor ) ) : + disabledBackgroundColor ); + g2d.fill ( shape ); + g2d.setPaint ( + enabled ? ( pressed ? pressedBorderColor : ( rollover ? rolloverBorderColor : borderColor ) ) : disabledBorderColor ); + g2d.draw ( shape ); + } + + /** + * Returns popup border shape. + * + * @param bounds button bounds + * @param button button component + * @return popup border shape + */ + protected Shape getArrowButtonShape ( final Rectangle bounds, final E button ) + { + return ShapeCache.getShape ( button, ARROW_BUTTON_SHAPE, new DataProvider () + { + @Override + public Shape provide () + { + return createArrowButtonShape ( bounds, button ); + } + }, getCachedShapeSettings ( button ) ); + } + + /** + * Returns an array of shape settings cached along with the shape. + * + * @param button button component + * @return an array of shape settings cached along with the shape + */ + protected Object[] getCachedShapeSettings ( final E button ) + { + return new Object[]{ button.getSize (), button.getInsets (), buttonType, button.getComponentOrientation ().isLeftToRight (), + scrollbar.getOrientation () }; + } + + /** + * Returns arrow button shape. + * + * @param bounds button bounds + * @param button button component + * @return arrow button shape + */ + protected Shape createArrowButtonShape ( final Rectangle bounds, final E button ) + { + final int orientation = scrollbar.getOrientation (); + final Insets i = button.getInsets (); + final int x = bounds.x + i.left; + final int y = bounds.y + i.top; + final int w = bounds.width - i.left - i.right - 1; + final int h = bounds.height - i.top - i.bottom - 1; + + final GeneralPath shape; + if ( orientation == SwingConstants.VERTICAL ) + { + if ( buttonType == ScrollBarButtonType.decrease ) + { + shape = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); + shape.moveTo ( x, y + h ); + shape.quadTo ( x + w / 2f, y + h * 2 / 3f, x + w, y + h ); + shape.lineTo ( x + w / 2f, y ); + shape.closePath (); + } + else + { + shape = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); + shape.moveTo ( x, y ); + shape.quadTo ( x + w / 2f, y + h / 3f, x + w, y ); + shape.lineTo ( x + w / 2f, y + h ); + shape.closePath (); + } + } + else + { + final boolean ltr = scrollbar.getComponentOrientation ().isLeftToRight (); + if ( ltr ? buttonType == ScrollBarButtonType.decrease : buttonType == ScrollBarButtonType.increase ) + { + shape = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); + shape.moveTo ( x + w, y ); + shape.quadTo ( x + w * 2 / 3f, y + h / 2f, x + w, y + h ); + shape.lineTo ( x, y + h / 2f ); + shape.closePath (); + } + else + { + shape = new GeneralPath ( GeneralPath.WIND_EVEN_ODD ); + shape.moveTo ( x, y ); + shape.quadTo ( x + w / 3f, y + h / 2f, x, y + h ); + shape.lineTo ( x + w, y + h / 2f ); + shape.closePath (); + } + } + return shape; + } +} \ No newline at end of file diff --git a/src/com/alee/laf/scroll/ScrollBarButtonType.java b/src/com/alee/laf/scroll/ScrollBarButtonType.java new file mode 100644 index 000000000..f0d549c34 --- /dev/null +++ b/src/com/alee/laf/scroll/ScrollBarButtonType.java @@ -0,0 +1,37 @@ +/* + * This file is part of WebLookAndFeel library. + * + * WebLookAndFeel library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WebLookAndFeel library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WebLookAndFeel library. If not, see . + */ + +package com.alee.laf.scroll; + +/** + * This enumeration represents two possible scroll bar button types. + * + * @author Mikle Garin + */ + +public enum ScrollBarButtonType +{ + /** + * Decrease button type. + */ + decrease, + + /** + * Increase button type. + */ + increase +} \ No newline at end of file diff --git a/src/com/alee/laf/scroll/ScrollBarPainter.java b/src/com/alee/laf/scroll/ScrollBarPainter.java new file mode 100644 index 000000000..96a2556e3 --- /dev/null +++ b/src/com/alee/laf/scroll/ScrollBarPainter.java @@ -0,0 +1,795 @@ +/* + * This file is part of WebLookAndFeel library. + * + * WebLookAndFeel library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WebLookAndFeel library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WebLookAndFeel library. If not, see . + */ + +package com.alee.laf.scroll; + +import com.alee.extended.painter.AbstractPainter; +import com.alee.laf.StyleConstants; +import com.alee.utils.ColorUtils; +import com.alee.utils.LafUtils; +import com.alee.utils.swing.WebTimer; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/** + * Base painter for JScrollBar component. + * It is used as WebScrollBarUI default styling. + * + * @author Mikle Garin + */ + +public class ScrollBarPainter extends AbstractPainter +{ + /** + * Style settings. + */ + protected boolean buttonsVisible = WebScrollBarStyle.buttonsVisible; + protected boolean drawTrack = WebScrollBarStyle.drawTrack; + protected Color trackBorderColor = WebScrollBarStyle.trackBorderColor; + protected Color trackBackgroundColor = WebScrollBarStyle.trackBackgroundColor; + protected Color thumbBorderColor = WebScrollBarStyle.thumbBorderColor; + protected Color thumbBackgroundColor = WebScrollBarStyle.thumbBackgroundColor; + protected Color thumbDisabledBorderColor = WebScrollBarStyle.thumbDisabledBorderColor; + protected Color thumbDisabledBackgroundColor = WebScrollBarStyle.thumbDisabledBackgroundColor; + protected Color thumbRolloverBorderColor = WebScrollBarStyle.thumbRolloverBorderColor; + protected Color thumbRolloverBackgroundColor = WebScrollBarStyle.thumbRolloverBackgroundColor; + protected Color thumbPressedBorderColor = WebScrollBarStyle.thumbPressedBorderColor; + protected Color thumbPressedBackgroundColor = WebScrollBarStyle.thumbPressedBackgroundColor; + protected int thumbRound = WebScrollBarStyle.thumbRound; + protected Insets thumbMargin = WebScrollBarStyle.thumbMargin; + + /** + * Runtime variables. + */ + protected WebTimer rolloverAnimator; + protected float rolloverState; + protected boolean rollover; + protected boolean pressed; + protected boolean dragged; + protected Rectangle trackBounds; + protected Rectangle thumbBounds; + protected Insets thumbMarginR; + protected Insets thumbMarginHL; + protected Insets thumbMarginHR; + + /** + * Listeners. + */ + protected MouseAdapter mouseAdapter; + + /** + * {@inheritDoc} + */ + @Override + public void install ( final E scrollbar ) + { + super.install ( scrollbar ); + + // Mouse listener + mouseAdapter = new MouseAdapter () + { + @Override + public void mousePressed ( final MouseEvent e ) + { + setPressed ( true ); + } + + @Override + public void mouseReleased ( final MouseEvent e ) + { + setPressed ( false ); + } + + @Override + public void mouseEntered ( final MouseEvent e ) + { + setRollover ( getThumbBounds ().contains ( e.getPoint () ) ); + } + + @Override + public void mouseMoved ( final MouseEvent e ) + { + setRollover ( getThumbBounds ().contains ( e.getPoint () ) ); + } + + @Override + public void mouseExited ( final MouseEvent e ) + { + setRollover ( false ); + } + }; + scrollbar.addMouseListener ( mouseAdapter ); + scrollbar.addMouseMotionListener ( mouseAdapter ); + } + + /** + * {@inheritDoc} + */ + @Override + public void uninstall ( final E scrollbar ) + { + // Removing listeners + scrollbar.removeMouseListener ( mouseAdapter ); + scrollbar.removeMouseMotionListener ( mouseAdapter ); + + super.uninstall ( scrollbar ); + } + + /** + * Returns whether scroll bar arrow buttons are visible or not. + * + * @return true if scroll bar arrow buttons are visible, false otherwise + */ + public boolean isButtonsVisible () + { + return buttonsVisible; + } + + /** + * Sets whether scroll bar arrow buttons are visible or not. + * + * @param visible whether scroll bar arrow buttons are visible or not + */ + public void setButtonsVisible ( final boolean visible ) + { + if ( this.buttonsVisible != visible ) + { + this.buttonsVisible = visible; + updateAll (); + } + } + + /** + * Returns whether scroll bar track should be painted or not. + * + * @return true if scroll bar track should be painted, false otherwise + */ + public boolean isDrawTrack () + { + return drawTrack; + } + + /** + * Sets whether scroll bar track should be painted or not. + * + * @param draw whether scroll bar track should be painted or not + */ + public void setDrawTrack ( final boolean draw ) + { + if ( this.drawTrack != draw ) + { + this.drawTrack = draw; + updateAll (); + } + } + + /** + * Returns scroll bar track border color. + * + * @return scroll bar track border color + */ + public Color getTrackBorderColor () + { + return trackBorderColor; + } + + /** + * Sets scroll bar track border color. + * + * @param color new scroll bar track border color + */ + public void setTrackBorderColor ( final Color color ) + { + if ( this.trackBorderColor != color ) + { + this.trackBorderColor = color; + repaint (); + } + } + + /** + * Returns scroll bar track background color. + * + * @return scroll bar track background color + */ + public Color getTrackBackgroundColor () + { + return trackBackgroundColor; + } + + /** + * Sets scroll bar track background color. + * + * @param color new scroll bar track background color + */ + public void setTrackBackgroundColor ( final Color color ) + { + if ( this.trackBackgroundColor != color ) + { + this.trackBackgroundColor = color; + repaint (); + } + } + + /** + * Returns scroll bar thumb border color. + * + * @return scroll bar thumb border color + */ + public Color getThumbBorderColor () + { + return thumbBorderColor; + } + + /** + * Sets scroll bar thumb border color. + * + * @param color new scroll bar thumb border color + */ + public void setThumbBorderColor ( final Color color ) + { + if ( this.thumbBorderColor != color ) + { + this.thumbBorderColor = color; + repaintThumb (); + } + } + + /** + * Returns scroll bar thumb background color. + * + * @return scroll bar thumb background color + */ + public Color getThumbBackgroundColor () + { + return thumbBackgroundColor; + } + + /** + * Sets scroll bar thumb background color. + * + * @param color new scroll bar thumb background color + */ + public void setThumbBackgroundColor ( final Color color ) + { + if ( this.thumbBackgroundColor != color ) + { + this.thumbBackgroundColor = color; + repaintThumb (); + } + } + + /** + * Returns disabled scroll bar thumb border color. + * + * @return disabled scroll bar thumb border color + */ + public Color getThumbDisabledBorderColor () + { + return thumbDisabledBorderColor; + } + + /** + * Sets disabled scroll bar thumb border color. + * + * @param color new disabled scroll bar thumb border color + */ + public void setThumbDisabledBorderColor ( final Color color ) + { + if ( this.thumbDisabledBorderColor != color ) + { + this.thumbDisabledBorderColor = color; + repaintThumb (); + } + } + + /** + * Returns disabled scroll bar thumb background color. + * + * @return disabled scroll bar thumb background color + */ + public Color getThumbDisabledBackgroundColor () + { + return thumbDisabledBackgroundColor; + } + + /** + * Sets disabled scroll bar thumb background color. + * + * @param color new disabled scroll bar thumb background color + */ + public void setThumbDisabledBackgroundColor ( final Color color ) + { + if ( this.thumbDisabledBackgroundColor != color ) + { + this.thumbDisabledBackgroundColor = color; + repaintThumb (); + } + } + + /** + * Returns scroll bar rollover thumb border color. + * + * @return scroll bar rollover thumb border color + */ + public Color getThumbRolloverBorderColor () + { + return thumbRolloverBorderColor; + } + + /** + * Sets scroll bar rollover thumb border color. + * + * @param color new scroll bar rollover thumb border color + */ + public void setThumbRolloverBorderColor ( final Color color ) + { + if ( this.thumbRolloverBorderColor != color ) + { + this.thumbRolloverBorderColor = color; + repaintThumb (); + } + } + + /** + * Returns scroll bar rollover thumb background color. + * + * @return scroll bar rollover thumb background color + */ + public Color getThumbRolloverBackgroundColor () + { + return thumbRolloverBackgroundColor; + } + + /** + * Sets scroll bar rollover thumb background color. + * + * @param color new scroll bar rollover thumb background color + */ + public void setThumbRolloverBackgroundColor ( final Color color ) + { + if ( this.thumbRolloverBackgroundColor != color ) + { + this.thumbRolloverBackgroundColor = color; + repaintThumb (); + } + } + + /** + * Returns scroll bar pressed thumb border color. + * + * @return scroll bar pressed thumb border color + */ + public Color getThumbPressedBorderColor () + { + return thumbPressedBorderColor; + } + + /** + * Returns scroll bar pressed thumb border color. + * + * @param color new scroll bar pressed thumb border color + */ + public void setThumbPressedBorderColor ( final Color color ) + { + if ( this.thumbPressedBorderColor != color ) + { + this.thumbPressedBorderColor = color; + repaintThumb (); + } + } + + /** + * Returns scroll bar pressed thumb background color. + * + * @return scroll bar pressed thumb background color + */ + public Color getThumbPressedBackgroundColor () + { + return thumbPressedBackgroundColor; + } + + /** + * Sets scroll bar pressed thumb background color. + * + * @param color new scroll bar pressed thumb background color + */ + public void setThumbPressedBackgroundColor ( final Color color ) + { + if ( this.thumbPressedBackgroundColor != color ) + { + this.thumbPressedBackgroundColor = color; + repaintThumb (); + } + } + + /** + * Returns scroll bar thumb corners rounding. + * + * @return scroll bar thumb corners rounding + */ + public int getThumbRound () + { + return thumbRound; + } + + /** + * Sets scroll bar thumb corners rounding. + * + * @param round new scroll bar thumb corners rounding + */ + public void setThumbRound ( final int round ) + { + if ( this.thumbRound != round ) + { + this.thumbRound = round; + repaintThumb (); + } + } + + /** + * Returns scroll bar thumb margin. + * + * @return scroll bar thumb margin + */ + public Insets getThumbMargin () + { + return thumbMargin; + } + + /** + * Sets scroll bar thumb margin. + * This value doesn't affect scroll bar size, just the visual representation of the thumb. + * + * @param margin new scroll bar thumb margin + */ + public void setThumbMargin ( final Insets margin ) + { + if ( this.thumbMargin != margin ) + { + this.thumbMargin = margin; + updateThumbMargins (); + repaintThumb (); + } + else if ( thumbMarginR == null ) + { + updateThumbMargins (); + } + } + + /** + * Updates cached thumb margins. + */ + protected void updateThumbMargins () + { + this.thumbMarginR = new Insets ( thumbMargin.top, thumbMargin.right, thumbMargin.bottom, thumbMargin.left ); + this.thumbMarginHL = new Insets ( thumbMargin.right, thumbMargin.top, thumbMargin.left, thumbMargin.bottom ); + this.thumbMarginHR = new Insets ( thumbMargin.left, thumbMargin.bottom, thumbMargin.right, thumbMargin.top ); + } + + /** + * Returns whether scroll bar thumb is in rollover state or not. + * + * @return true if scroll bar thumb is in rollover state, false otherwise + */ + public boolean isRollover () + { + return rollover; + } + + /** + * Sets whether scroll bar thumb is in rollover state or not. + * + * @param rollover whether scroll bar thumb is in rollover state or not + */ + public void setRollover ( final boolean rollover ) + { + if ( this.rollover != rollover ) + { + this.rollover = rollover; + if ( rollover ) + { + if ( rolloverAnimator != null ) + { + rolloverAnimator.stop (); + } + repaintThumb (); + } + else + { + if ( rolloverAnimator == null ) + { + rolloverAnimator = new WebTimer ( StyleConstants.avgAnimationDelay, new ActionListener () + { + @Override + public void actionPerformed ( final ActionEvent e ) + { + if ( rolloverState > 0f ) + { + rolloverState -= 0.1f; + repaintThumb (); + } + else + { + rolloverState = 0f; + rolloverAnimator.stop (); + } + } + } ); + } + rolloverState = 1f; + rolloverAnimator.start (); + } + } + } + + /** + * Returns whether scroll bar thumb is pressed or not. + * + * @return true if scroll bar thumb is pressed, false otherwise + */ + public boolean isPressed () + { + return pressed; + } + + /** + * Sets whether scroll bar thumb is pressed or not. + * + * @param pressed whether scroll bar thumb is pressed or not + */ + public void setPressed ( final boolean pressed ) + { + if ( this.pressed != pressed ) + { + this.pressed = pressed; + repaintThumb (); + } + } + + /** + * Returns whether scroll bar thumb is being dragged or not. + * This value is updated by WebScrollBarUI on each paint call to ensure that proper value presented. + * + * @return true if scroll bar thumb is being dragged, false otherwise + */ + public boolean isDragged () + { + return dragged; + } + + /** + * Sets whether scroll bar thumb is being dragged or not. + * + * @param dragged whether scroll bar thumb is being dragged or not + */ + public void setDragged ( final boolean dragged ) + { + this.dragged = dragged; + } + + /** + * Returns scroll bar track bounds. + * + * @return scroll bar track bounds + */ + public Rectangle getTrackBounds () + { + return trackBounds; + } + + /** + * Sets scroll bar track bounds. + * This value is updated by WebScrollBarUI on each paint call to ensure that proper bounds presented. + * + * @param bounds new scroll bar track bounds + */ + public void setTrackBounds ( final Rectangle bounds ) + { + this.trackBounds = bounds; + } + + /** + * Returns scroll bar thumb bounds. + * + * @return scroll bar thumb bounds + */ + public Rectangle getThumbBounds () + { + return thumbBounds; + } + + /** + * Sets scroll bar thumb bounds. + * This value is updated by WebScrollBarUI on each paint call to ensure that proper bounds presented. + * + * @param bounds new scroll bar thumb bounds + */ + public void setThumbBounds ( final Rectangle bounds ) + { + this.thumbBounds = bounds; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isOpaque ( final E scrollbar ) + { + return drawTrack; + } + + /** + * {@inheritDoc} + */ + @Override + public Insets getMargin ( final E scrollbar ) + { + if ( drawTrack ) + { + // Additional 1px border at scroll bar side + // Orientation will be taken into account by the UI itself + final boolean hor = scrollbar.getOrientation () == SwingConstants.HORIZONTAL; + return new Insets ( hor ? 1 : 0, hor ? 0 : 1, 0, 0 ); + } + else + { + return new Insets ( 0, 0, 0, 0 ); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void paint ( final Graphics2D g2d, final Rectangle bounds, final E scrollbar ) + { + final Object aa = LafUtils.setupAntialias ( g2d ); + paintBackground ( g2d, scrollbar, bounds ); + paintTrack ( g2d, scrollbar, trackBounds ); + paintThumb ( g2d, scrollbar, thumbBounds ); + LafUtils.restoreAntialias ( g2d, aa ); + } + + /** + * Paints scroll bar background. + * Background area includes the space under arrow buttons. + * + * @param g2d graphics context + * @param scrollbar scroll bar + * @param bounds scroll bar bounds + */ + @SuppressWarnings ( "UnusedParameters" ) + protected void paintBackground ( final Graphics2D g2d, final E scrollbar, final Rectangle bounds ) + { + if ( drawTrack ) + { + g2d.setPaint ( trackBackgroundColor ); + g2d.fillRect ( bounds.x, bounds.y, bounds.width, bounds.height ); + + if ( scrollbar.getOrientation () == JScrollBar.VERTICAL ) + { + final boolean ltr = scrollbar.getComponentOrientation ().isLeftToRight (); + final int x = ltr ? bounds.x : bounds.x + bounds.width - 1; + g2d.setColor ( trackBorderColor ); + g2d.drawLine ( x, bounds.y, x, bounds.height - 1 ); + } + else + { + g2d.setColor ( trackBorderColor ); + g2d.drawLine ( bounds.x, bounds.y, bounds.x + bounds.width - 1, bounds.y ); + } + } + } + + /** + * Paints scroll bar track. + * Track area only excludes the space under arrow buttons. + * + * @param g2d graphics context + * @param scrollbar scroll bar + * @param bounds track bounds + */ + @SuppressWarnings ( "UnusedParameters" ) + protected void paintTrack ( final Graphics2D g2d, final E scrollbar, final Rectangle bounds ) + { + // You can paint your own track decoration by overriding this method + } + + /** + * Paints scroll bar thumb. + * Thumb area is limited to thumb bounds and might be changed frequently. + * + * @param g2d graphics context + * @param scrollbar scroll bar component + * @param bounds thumb bounds + */ + @SuppressWarnings ( "UnusedParameters" ) + protected void paintThumb ( final Graphics2D g2d, final E scrollbar, final Rectangle bounds ) + { + final Insets m = getCurrentThumbMargin ( scrollbar ); + + // Painting thumb background + g2d.setPaint ( getCurrentThumbBackgroundColor ( scrollbar ) ); + g2d.fillRoundRect ( bounds.x + m.left, bounds.y + m.top, bounds.width - m.left - m.right, bounds.height - m.top - m.bottom, + thumbRound, thumbRound ); + + // Painting thumb border + g2d.setPaint ( getCurrentThumbBorderColor ( scrollbar ) ); + g2d.drawRoundRect ( bounds.x + m.left, bounds.y + m.top, bounds.width - m.left - m.right - 1, bounds.height - m.top - m.bottom - 1, + thumbRound, thumbRound ); + } + + /** + * Returns current thumb margin rotated into proper position. + * + * @param scrollbar scroll bar component + * @return current thumb margin rotated into proper position + */ + protected Insets getCurrentThumbMargin ( final E scrollbar ) + { + final boolean ver = scrollbar.getOrientation () == SwingConstants.VERTICAL; + final boolean ltr = scrollbar.getComponentOrientation ().isLeftToRight (); + return ver ? ( ltr ? thumbMargin : thumbMarginR ) : ( ltr ? thumbMarginHL : thumbMarginHR ); + } + + /** + * Returns current thumb border color. + * + * @param scrollbar scroll bar component + * @return current thumb border color + */ + protected Color getCurrentThumbBorderColor ( final E scrollbar ) + { + return scrollbar.isEnabled () ? ( pressed || dragged ? thumbPressedBorderColor : ( rollover ? thumbRolloverBorderColor : + ColorUtils.getIntermediateColor ( thumbBorderColor, thumbRolloverBorderColor, rolloverState ) ) ) : + thumbDisabledBorderColor; + } + + /** + * Returns current thumb background color. + * + * @param scrollbar scroll bar component + * @return current thumb background color + */ + protected Color getCurrentThumbBackgroundColor ( final E scrollbar ) + { + return scrollbar.isEnabled () ? ( pressed || dragged ? thumbPressedBackgroundColor : ( rollover ? thumbRolloverBackgroundColor : + ColorUtils.getIntermediateColor ( thumbBackgroundColor, thumbRolloverBackgroundColor, rolloverState ) ) ) : + thumbDisabledBackgroundColor; + } + + /** + * Forces scroll bar thumb to be repainted. + */ + public void repaintThumb () + { + if ( thumbBounds != null ) + { + repaint ( thumbBounds ); + } + else + { + repaint (); + } + } +} \ No newline at end of file diff --git a/src/com/alee/laf/scroll/WebScrollBar.java b/src/com/alee/laf/scroll/WebScrollBar.java index 8aaf97d94..d95629d2d 100644 --- a/src/com/alee/laf/scroll/WebScrollBar.java +++ b/src/com/alee/laf/scroll/WebScrollBar.java @@ -24,121 +24,484 @@ import java.awt.*; /** - * User: mgarin Date: 28.06.11 Time: 1:00 + * This JScrollBar extension class provides a direct access to WebScrollBarUI methods. + * + * @author Mikle Garin */ public class WebScrollBar extends JScrollBar { + /** + * Constructs new scroll bar. + */ public WebScrollBar () { super (); } - public WebScrollBar ( int orientation ) + /** + * Constructs new scroll bar with the specified orientation. + * + * @param orientation scroll bar orientation + */ + public WebScrollBar ( final int orientation ) { super ( orientation ); } - public WebScrollBar ( int orientation, int value, int extent, int min, int max ) + /** + * Constructs new scroll bar with the specified orientation and values. + * + * @param orientation scroll bar orientation + * @param value scroll bar value + * @param extent scroll bar extent + * @param min scroll bar minimum value + * @param max scroll bar maximum value + */ + public WebScrollBar ( final int orientation, final int value, final int extent, final int min, final int max ) { super ( orientation, value, extent, min, max ); } - public boolean isDrawBorder () + /** + * Returns whether scroll bar arrow buttons should be displayed or not. + * + * @return true if scroll bar arrow buttons should be displayed, false otherwise + */ + public boolean isButtonsVisible () + { + return getWebUI ().isButtonsVisible (); + } + + /** + * Sets whether scroll bar arrow buttons should be displayed or not. + * + * @param visible whether scroll bar arrow buttons should be displayed or not + * @return scroll bar + */ + public WebScrollBar setButtonsVisible ( final boolean visible ) + { + getWebUI ().setButtonsVisible ( visible ); + return this; + } + + /** + * Returns whether scroll bar track should be displayed or not. + * + * @return true if scroll bar track should be displayed, false otherwise + */ + public boolean isDrawTrack () + { + return getWebUI ().isDrawTrack (); + } + + /** + * Sets whether scroll bar track should be displayed or not. + * + * @param draw whether scroll bar track should be displayed or not + * @return scroll bar + */ + public WebScrollBar setDrawTrack ( final boolean draw ) + { + getWebUI ().setDrawTrack ( draw ); + return this; + } + + /** + * Returns scroll bar track border color. + * + * @return scroll bar track border color + */ + public Color getTrackBorderColor () + { + return getWebUI ().getTrackBorderColor (); + } + + /** + * Sets scroll bar track border color. + * + * @param color new scroll bar track border color + * @return scroll bar + */ + public WebScrollBar setTrackBorderColor ( final Color color ) + { + getWebUI ().setTrackBorderColor ( color ); + return this; + } + + /** + * Returns scroll bar track background color. + * + * @return scroll bar track background color + */ + public Color getTrackBackgroundColor () + { + return getWebUI ().getTrackBackgroundColor (); + } + + /** + * Sets scroll bar track background color. + * + * @param color new scroll bar track background color + * @return scroll bar + */ + public WebScrollBar setTrackBackgroundColor ( final Color color ) + { + getWebUI ().setTrackBackgroundColor ( color ); + return this; + } + + /** + * Returns scroll bar thumb border color. + * + * @return scroll bar thumb border color + */ + public Color getThumbBorderColor () + { + return getWebUI ().getThumbBorderColor (); + } + + /** + * Sets scroll bar thumb border color. + * + * @param color new scroll bar thumb border color + * @return scroll bar + */ + public WebScrollBar setThumbBorderColor ( final Color color ) + { + getWebUI ().setThumbBorderColor ( color ); + return this; + } + + /** + * Returns scroll bar thumb background color. + * + * @return scroll bar thumb background color + */ + public Color getThumbBackgroundColor () + { + return getWebUI ().getThumbBackgroundColor (); + } + + /** + * Sets scroll bar thumb background color. + * + * @param color new scroll bar thumb background color + * @return scroll bar + */ + public WebScrollBar setThumbBackgroundColor ( final Color color ) + { + getWebUI ().setThumbBackgroundColor ( color ); + return this; + } + + /** + * Returns scroll bar thumb disabled border color. + * + * @return scroll bar thumb disabled border color + */ + public Color getThumbDisabledBorderColor () + { + return getWebUI ().getThumbDisabledBorderColor (); + } + + /** + * Sets scroll bar thumb disabled border color. + * + * @param color new scroll bar thumb disabled border color + * @return scroll bar + */ + public WebScrollBar setThumbDisabledBorderColor ( final Color color ) + { + getWebUI ().setThumbDisabledBorderColor ( color ); + return this; + } + + /** + * Returns scroll bar thumb disabled background color. + * + * @return scroll bar thumb disabled background color + */ + public Color getThumbDisabledBackgroundColor () + { + return getWebUI ().getThumbDisabledBackgroundColor (); + } + + /** + * Sets scroll bar thumb disabled background color. + * + * @param color new scroll bar thumb disabled background color + * @return scroll bar + */ + public WebScrollBar setThumbDisabledBackgroundColor ( final Color color ) + { + getWebUI ().setThumbDisabledBackgroundColor ( color ); + return this; + } + + /** + * Returns scroll bar thumb rollover border color. + * + * @return scroll bar thumb rollover border color + */ + public Color getThumbRolloverBorderColor () + { + return getWebUI ().getThumbRolloverBorderColor (); + } + + /** + * Sets scroll bar thumb rollover border color. + * + * @param color new scroll bar thumb rollover border color + * @return scroll bar + */ + public WebScrollBar setThumbRolloverBorderColor ( final Color color ) + { + getWebUI ().setThumbRolloverBorderColor ( color ); + return this; + } + + /** + * Returns scroll bar thumb rollover background color. + * + * @return scroll bar thumb rollover background color + */ + public Color getThumbRolloverBackgroundColor () + { + return getWebUI ().getThumbRolloverBackgroundColor (); + } + + /** + * Sets scroll bar thumb rollover background color. + * + * @param color new scroll bar thumb rollover background color + * @return scroll bar + */ + public WebScrollBar setThumbRolloverBackgroundColor ( final Color color ) + { + getWebUI ().setThumbRolloverBackgroundColor ( color ); + return this; + } + + /** + * Returns scroll bar thumb pressed border color. + * + * @return scroll bar thumb pressed border color + */ + public Color getThumbPressedBorderColor () { - return getWebUI ().isDrawBorder (); + return getWebUI ().getThumbPressedBorderColor (); } - public void setDrawBorder ( boolean drawBorder ) + /** + * Sets scroll bar thumb pressed border color. + * + * @param color new scroll bar thumb pressed border color + * @return scroll bar + */ + public WebScrollBar setThumbPressedBorderColor ( final Color color ) { - getWebUI ().setDrawBorder ( drawBorder ); + getWebUI ().setThumbPressedBorderColor ( color ); + return this; } - public int getRound () + /** + * Returns scroll bar thumb pressed/dragged background color. + * + * @return scroll bar thumb pressed/dragged background color + */ + public Color getThumbPressedBackgroundColor () { - return getWebUI ().getRound (); + return getWebUI ().getThumbPressedBackgroundColor (); } - public void setRound ( int rounding ) + /** + * Sets scroll bar thumb pressed/dragged background color. + * + * @param color new scroll bar thumb pressed/dragged background color + * @return scroll bar + */ + public WebScrollBar setThumbPressedBackgroundColor ( final Color color ) { - getWebUI ().setRound ( rounding ); + getWebUI ().setThumbPressedBackgroundColor ( color ); + return this; } - public Color getScrollBg () + /** + * Returns scroll bar thumb corners rounding. + * + * @return scroll bar thumb corners rounding + */ + public int getThumbRound () { - return getWebUI ().getScrollBg (); + return getWebUI ().getThumbRound (); } - public void setScrollBg ( Color scrollBg ) + /** + * Sets scroll bar thumb corners rounding. + * + * @param round new scroll bar thumb corners rounding + * @return scroll bar + */ + public WebScrollBar setThumbRound ( final int round ) { - getWebUI ().setScrollBg ( scrollBg ); + getWebUI ().setThumbRound ( round ); + return this; } - public Color getScrollBorder () + /** + * Returns scroll bar thumb margin. + * + * @return scroll bar thumb margin + */ + public Insets getThumbMargin () { - return getWebUI ().getScrollBorder (); + return getWebUI ().getThumbMargin (); } - public void setScrollBorder ( Color scrollBorder ) + /** + * Sets scroll bar thumb margin. + * + * @param margin new scroll bar thumb margin + * @return scroll bar + */ + public WebScrollBar setThumbMargin ( final Insets margin ) { - getWebUI ().setScrollBorder ( scrollBorder ); + getWebUI ().setThumbMargin ( margin ); + return this; } - public Color getScrollBarBorder () + /** + * Returns scroll bar content margin. + * + * @return scroll bar content margin + */ + public Insets getMargin () { - return getWebUI ().getScrollBarBorder (); + return getWebUI ().getMargin (); } - public void setScrollBarBorder ( Color scrollBarBorder ) + /** + * Sets scroll bar content margin. + * + * @param margin new scroll bar content margin + * @return scroll bar + */ + public WebScrollBar setMargin ( final Insets margin ) { - getWebUI ().setScrollBarBorder ( scrollBarBorder ); + getWebUI ().setMargin ( margin ); + return this; } - public Color getScrollGradientLeft () + /** + * Sets scroll bar content margin. + * + * @param top new scroll bar content top margin + * @param left new scroll bar content left margin + * @param bottom new scroll bar content bottom margin + * @param right new scroll bar content right margin + * @return scroll bar + */ + public WebScrollBar setMargin ( final int top, final int left, final int bottom, final int right ) { - return getWebUI ().getScrollGradientLeft (); + return setMargin ( new Insets ( top, left, bottom, right ) ); } - public void setScrollGradientLeft ( Color scrollGradientLeft ) + /** + * Sets scroll bar content margin. + * + * @param spacing new scroll bar content margin + * @return scroll bar + */ + public WebScrollBar setMargin ( final int spacing ) { - getWebUI ().setScrollGradientLeft ( scrollGradientLeft ); + return setMargin ( spacing, spacing, spacing, spacing ); } - public Color getScrollGradientRight () + /** + * Returns scroll bar painter. + * + * @return scroll bar painter + */ + public ScrollBarPainter getPainter () { - return getWebUI ().getScrollGradientRight (); + return getWebUI ().getPainter (); } - public void setScrollGradientRight ( Color scrollGradientRight ) + /** + * Sets scroll bar painter. + * Pass null to remove scroll bar painter. + * + * @param painter new scroll bar painter + * @return scroll bar + */ + public WebScrollBar setPainter ( final ScrollBarPainter painter ) { - getWebUI ().setScrollGradientRight ( scrollGradientRight ); + getWebUI ().setPainter ( painter ); + return this; } - public Color getScrollSelGradientLeft () + /** + * Returns decrease button painter. + * This the button displayed at top or left side of the scroll bar. + * + * @return decrease button painter + */ + public ScrollBarButtonPainter getDecreaseButtonPainter () { - return getWebUI ().getScrollSelGradientLeft (); + return getWebUI ().getDecreaseButtonPainter (); } - public void setScrollSelGradientLeft ( Color scrollSelGradientLeft ) + /** + * Sets decrease button painter. + * This the button displayed at top or left side of the scroll bar. + * + * @param painter new decrease button painter + * @return scroll bar + */ + public WebScrollBar setDecreaseButtonPainter ( final ScrollBarButtonPainter painter ) { - getWebUI ().setScrollSelGradientLeft ( scrollSelGradientLeft ); + getWebUI ().setDecreaseButtonPainter ( painter ); + return this; } - public Color getScrollSelGradientRight () + /** + * Returns increase button painter. + * This the button displayed at bottom or right side of the scroll bar. + * + * @return increase button painter + */ + public ScrollBarButtonPainter getIncreaseButtonPainter () { - return getWebUI ().getScrollSelGradientRight (); + return getWebUI ().getIncreaseButtonPainter (); } - public void setScrollSelGradientRight ( Color scrollSelGradientRight ) + /** + * Sets increase button painter. + * This the button displayed at bottom or right side of the scroll bar. + * + * @param painter new increase button painter + * @return scroll bar + */ + public WebScrollBar setIncreaseButtonPainter ( final ScrollBarButtonPainter painter ) { - getWebUI ().setScrollSelGradientRight ( scrollSelGradientRight ); + getWebUI ().setIncreaseButtonPainter ( painter ); + return this; } + /** + * Returns Web-UI applied to this class. + * + * @return Web-UI applied to this class + */ public WebScrollBarUI getWebUI () { return ( WebScrollBarUI ) getUI (); } + /** + * Installs a Web-UI into this component. + */ @Override public void updateUI () { @@ -159,4 +522,4 @@ public void updateUI () setUI ( getUI () ); } } -} +} \ No newline at end of file diff --git a/src/com/alee/laf/scroll/WebScrollBarStyle.java b/src/com/alee/laf/scroll/WebScrollBarStyle.java index 1dec23647..94fb80b0a 100644 --- a/src/com/alee/laf/scroll/WebScrollBarStyle.java +++ b/src/com/alee/laf/scroll/WebScrollBarStyle.java @@ -17,68 +17,105 @@ package com.alee.laf.scroll; -import com.alee.laf.StyleConstants; - import java.awt.*; /** - * User: mgarin Date: 11/15/11 Time: 4:36 PM + * WebScrollBar style class. + * + * @author Mikle Garin */ public final class WebScrollBarStyle { /** - * Scroll bar background color + * Whether scroll bar arrow buttons should be displayed or not. + */ + public static boolean buttonsVisible = true; + + /** + * Whether scroll bar track should be displayed or not. + */ + public static boolean drawTrack = false; + + /** + * Scroll bar track border color. + */ + public static Color trackBorderColor = new Color ( 230, 230, 230 ); + + /** + * Scroll bar track background color. + */ + public static Color trackBackgroundColor = new Color ( 245, 245, 245 ); + + /** + * Scroll bar thumb border color. + */ + public static Color thumbBorderColor = new Color ( 189, 189, 189 ); + + /** + * Scroll bar thumb background color. + */ + public static Color thumbBackgroundColor = new Color ( 217, 217, 217 ); + + /** + * Scroll bar thumb disabled border color. + */ + public static Color thumbDisabledBorderColor = new Color ( 210, 210, 210 ); + + /** + * Scroll bar thumb disabled background color. */ - public static Color scrollBg = new Color ( 245, 245, 245 ); + public static Color thumbDisabledBackgroundColor = new Color ( 230, 230, 230 ); /** - * Scroll bar side border color + * Scroll bar thumb rollover border color. */ - public static Color scrollBorder = new Color ( 230, 230, 230 ); + public static Color thumbRolloverBorderColor = new Color ( 166, 166, 166 ); /** - * Scroll bar border color + * Scroll bar thumb rollover background color. */ - public static Color scrollBarBorder = new Color ( 201, 201, 201 ); + public static Color thumbRolloverBackgroundColor = new Color ( 194, 194, 194 ); /** - * Scroll bar top or left gradient + * Scroll bar thumb pressed/dragged border color. */ - public static Color scrollGradientLeft = new Color ( 239, 239, 239 ); + public static Color thumbPressedBorderColor = new Color ( 126, 126, 126 ); /** - * Scroll bar bottom or right gradient + * Scroll bar thumb pressed/dragged background color. */ - public static Color scrollGradientRight = new Color ( 211, 211, 211 ); + public static Color thumbPressedBackgroundColor = new Color ( 145, 145, 145 ); /** - * Dragged scroll bar top or left gradient + * Scroll bar thumb corners rounding. */ - public static Color scrollSelGradientLeft = new Color ( 203, 203, 203 ); + public static int thumbRound = 8; /** - * Dragged scroll bar bottom or right gradient + * Scroll bar margin. */ - public static Color scrollSelGradientRight = new Color ( 175, 175, 175 ); + public static Insets margin = new Insets ( 0, 0, 0, 0 ); /** - * Decoration rounding + * Scroll bar thumb margin. */ - public static int rounding = StyleConstants.smallRound; + public static Insets thumbMargin = new Insets ( 0, 2, 0, 2 ); /** - * Decoration shade width + * Scroll bar arrow buttons preferred size. + * Only odd values are recommended for default button representation. + * For custom implementations you may specify anything you like. */ - public static boolean drawBorder = StyleConstants.drawBorder; + public static Dimension buttonsSize = new Dimension ( 13, 13 ); /** - * Minimum horizontal scroll bar thumb width + * Minimum horizontal scroll bar thumb width. */ - public static int minThumbWidth = 30; + public static int minThumbWidth = 25; /** - * Minimum vertical scroll bar thumb height + * Minimum vertical scroll bar thumb height. */ - public static int minThumbHeight = 30; + public static int minThumbHeight = 25; } \ No newline at end of file diff --git a/src/com/alee/laf/scroll/WebScrollBarUI.java b/src/com/alee/laf/scroll/WebScrollBarUI.java index 0a8ffbdc8..af80ead9c 100644 --- a/src/com/alee/laf/scroll/WebScrollBarUI.java +++ b/src/com/alee/laf/scroll/WebScrollBarUI.java @@ -17,240 +17,728 @@ package com.alee.laf.scroll; +import com.alee.extended.painter.PainterSupport; +import com.alee.laf.WebLookAndFeel; +import com.alee.laf.button.WebButton; import com.alee.utils.LafUtils; import com.alee.utils.SwingUtils; +import com.alee.utils.swing.BorderMethods; import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollBarUI; import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; /** - * User: mgarin Date: 29.04.11 Time: 15:34 + * Custom UI for JScrollBar component. + * + * @author Mikle Garin */ -public class WebScrollBarUI extends BasicScrollBarUI +public class WebScrollBarUI extends BasicScrollBarUI implements BorderMethods { - public static final int LENGTH = 13; - - private Color scrollBg = WebScrollBarStyle.scrollBg; - private Color scrollBorder = WebScrollBarStyle.scrollBorder; - private Color scrollBarBorder = WebScrollBarStyle.scrollBarBorder; - private Color scrollGradientLeft = WebScrollBarStyle.scrollGradientLeft; - private Color scrollGradientRight = WebScrollBarStyle.scrollGradientRight; - private Color scrollSelGradientLeft = WebScrollBarStyle.scrollSelGradientLeft; - private Color scrollSelGradientRight = WebScrollBarStyle.scrollSelGradientRight; - - private int round = WebScrollBarStyle.rounding; - private boolean drawBorder = WebScrollBarStyle.drawBorder; - - private MouseAdapter mouseAdapter; - - @SuppressWarnings ("UnusedParameters") + /** + * Painter style settings. + */ + protected boolean buttonsVisible = WebScrollBarStyle.buttonsVisible; + protected boolean drawTrack = WebScrollBarStyle.drawTrack; + protected Color trackBorderColor = WebScrollBarStyle.trackBorderColor; + protected Color trackBackgroundColor = WebScrollBarStyle.trackBackgroundColor; + protected Color thumbBorderColor = WebScrollBarStyle.thumbBorderColor; + protected Color thumbBackgroundColor = WebScrollBarStyle.thumbBackgroundColor; + protected Color thumbDisabledBorderColor = WebScrollBarStyle.thumbDisabledBorderColor; + protected Color thumbDisabledBackgroundColor = WebScrollBarStyle.thumbDisabledBackgroundColor; + protected Color thumbRolloverBorderColor = WebScrollBarStyle.thumbRolloverBorderColor; + protected Color thumbRolloverBackgroundColor = WebScrollBarStyle.thumbRolloverBackgroundColor; + protected Color thumbPressedBorderColor = WebScrollBarStyle.thumbPressedBorderColor; + protected Color thumbPressedBackgroundColor = WebScrollBarStyle.thumbPressedBackgroundColor; + protected int thumbRound = WebScrollBarStyle.thumbRound; + protected Insets thumbMargin = WebScrollBarStyle.thumbMargin; + + /** + * Component style settings. + */ + protected Insets margin = WebScrollBarStyle.margin; + protected ScrollBarPainter painter; + protected ScrollBarButtonPainter decreaseButtonPainter; + protected ScrollBarButtonPainter increaseButtonPainter; + + /** + * Scroll bar listeners. + */ + protected PropertyChangeListener orientationChangeListener; + + /** + * Runtime variables. + */ + protected int scrollBarWidth; + + /** + * Returns an instance of the WebScrollBarUI for the specified component. + * This tricky method is used by UIManager to create component UIs when needed. + * + * @param c component that will use UI instance + * @return instance of the WebScrollBarUI + */ + @SuppressWarnings ( "UnusedParameters" ) public static ComponentUI createUI ( final JComponent c ) { return new WebScrollBarUI (); } + /** + * Installs UI in the specified component. + * + * @param c component for this UI + */ @Override public void installUI ( final JComponent c ) { super.installUI ( c ); + // Proper enabled state handling + scrollbar.putClientProperty ( SwingUtils.HANDLES_ENABLE_STATE, true ); + + // UI defaults + scrollBarWidth = UIManager.getInt ( "ScrollBar.width" ); + if ( scrollBarWidth <= 0 ) + { + scrollBarWidth = 16; + } + // Default settings SwingUtils.setOrientation ( scrollbar ); scrollbar.setUnitIncrement ( 4 ); scrollbar.setUnitIncrement ( 16 ); - mouseAdapter = new MouseAdapter () + // Installing default painters + setPainter ( new ScrollBarPainter () ); + setDecreaseButtonPainter ( new ScrollBarButtonPainter ( scrollbar, ScrollBarButtonType.decrease ) ); + setIncreaseButtonPainter ( new ScrollBarButtonPainter ( scrollbar, ScrollBarButtonType.increase ) ); + + // Orientation change listener + orientationChangeListener = new PropertyChangeListener () { @Override - public void mousePressed ( final MouseEvent e ) + public void propertyChange ( final PropertyChangeEvent evt ) { - scrollbar.repaint (); + updateBorder (); } }; - scrollbar.addMouseListener ( mouseAdapter ); + scrollbar.addPropertyChangeListener ( WebLookAndFeel.ORIENTATION_PROPERTY, orientationChangeListener ); } + /** + * Uninstalls UI from the specified component. + * + * @param c component with this UI + */ @Override public void uninstallUI ( final JComponent c ) { - scrollbar.removeMouseListener ( mouseAdapter ); + // Uninstalling painters + setPainter ( null ); + setDecreaseButtonPainter ( null ); + setIncreaseButtonPainter ( null ); + + // Removing listeners + scrollbar.removePropertyChangeListener ( WebLookAndFeel.ORIENTATION_PROPERTY, orientationChangeListener ); super.uninstallUI ( c ); } - public boolean isDrawBorder () + /** + * {@inheritDoc} + */ + @Override + public void updateBorder () { - return drawBorder; + if ( scrollbar != null ) + { + // Preserve old borders + if ( SwingUtils.isPreserveBorders ( scrollbar ) ) + { + return; + } + + // Actual margin + final boolean ltr = scrollbar.getComponentOrientation ().isLeftToRight (); + final Insets m = new Insets ( margin.top, ltr ? margin.left : margin.right, margin.bottom, ltr ? margin.right : margin.left ); + + // Calculating additional borders + if ( painter != null ) + { + // Painter borders + final Insets pi = painter.getMargin ( scrollbar ); + m.top += pi.top; + m.left += ltr ? pi.left : pi.right; + m.bottom += pi.bottom; + m.right += ltr ? pi.right : pi.left; + } + + // Installing border + scrollbar.setBorder ( LafUtils.createWebBorder ( m ) ); + } } - public void setDrawBorder ( final boolean drawBorder ) + /** + * Returns whether scroll bar arrow buttons should be displayed or not. + * + * @return true if scroll bar arrow buttons should be displayed, false otherwise + */ + public boolean isButtonsVisible () { - this.drawBorder = drawBorder; - scrollbar.setOpaque ( drawBorder ); + return buttonsVisible; } - public int getRound () + /** + * Sets whether scroll bar arrow buttons should be displayed or not. + * + * @param visible whether scroll bar arrow buttons should be displayed or not + */ + public void setButtonsVisible ( final boolean visible ) { - return round; + this.buttonsVisible = visible; + if ( painter != null ) + { + painter.setButtonsVisible ( visible ); + } } - public void setRound ( final int round ) + /** + * Returns whether scroll bar track should be displayed or not. + * + * @return true if scroll bar track should be displayed, false otherwise + */ + public boolean isDrawTrack () { - this.round = round; + return drawTrack; } - public Color getScrollBg () + /** + * Sets whether scroll bar track should be displayed or not. + * + * @param draw whether scroll bar track should be displayed or not + */ + public void setDrawTrack ( final boolean draw ) { - return scrollBg; + this.drawTrack = draw; + if ( painter != null ) + { + painter.setDrawTrack ( draw ); + } } - public void setScrollBg ( final Color scrollBg ) + /** + * Returns scroll bar track border color. + * + * @return scroll bar track border color + */ + public Color getTrackBorderColor () { - this.scrollBg = scrollBg; + return trackBorderColor; } - public Color getScrollBorder () + /** + * Sets scroll bar track border color. + * + * @param color new scroll bar track border color + */ + public void setTrackBorderColor ( final Color color ) { - return scrollBorder; + this.trackBorderColor = color; + if ( painter != null ) + { + painter.setTrackBorderColor ( color ); + } + } + + /** + * Returns scroll bar track background color. + * + * @return scroll bar track background color + */ + public Color getTrackBackgroundColor () + { + return trackBackgroundColor; } - public void setScrollBorder ( final Color scrollBorder ) + /** + * Sets scroll bar track background color. + * + * @param color new scroll bar track background color + */ + public void setTrackBackgroundColor ( final Color color ) { - this.scrollBorder = scrollBorder; + this.trackBackgroundColor = color; + if ( painter != null ) + { + painter.setTrackBackgroundColor ( color ); + } } - public Color getScrollBarBorder () + /** + * Returns scroll bar thumb border color. + * + * @return scroll bar thumb border color + */ + public Color getThumbBorderColor () { - return scrollBarBorder; + return thumbBorderColor; } - public void setScrollBarBorder ( final Color scrollBarBorder ) + /** + * Sets scroll bar thumb border color. + * + * @param color new scroll bar thumb border color + */ + public void setThumbBorderColor ( final Color color ) { - this.scrollBarBorder = scrollBarBorder; + this.thumbBorderColor = color; + if ( painter != null ) + { + painter.setThumbBorderColor ( color ); + } } - public Color getScrollGradientLeft () + /** + * Returns scroll bar thumb background color. + * + * @return scroll bar thumb background color + */ + public Color getThumbBackgroundColor () { - return scrollGradientLeft; + return thumbBackgroundColor; } - public void setScrollGradientLeft ( final Color scrollGradientLeft ) + /** + * Sets scroll bar thumb background color. + * + * @param color new scroll bar thumb background color + */ + public void setThumbBackgroundColor ( final Color color ) { - this.scrollGradientLeft = scrollGradientLeft; + this.thumbBackgroundColor = color; + if ( painter != null ) + { + painter.setThumbBackgroundColor ( color ); + } } - public Color getScrollGradientRight () + /** + * Returns scroll bar thumb disabled border color. + * + * @return scroll bar thumb disabled border color + */ + public Color getThumbDisabledBorderColor () { - return scrollGradientRight; + return thumbDisabledBorderColor; } - public void setScrollGradientRight ( final Color scrollGradientRight ) + /** + * Sets scroll bar thumb disabled border color. + * + * @param color new scroll bar thumb disabled border color + */ + public void setThumbDisabledBorderColor ( final Color color ) { - this.scrollGradientRight = scrollGradientRight; + this.thumbDisabledBorderColor = color; + if ( painter != null ) + { + painter.setThumbDisabledBorderColor ( color ); + } } - public Color getScrollSelGradientLeft () + /** + * Returns scroll bar thumb disabled background color. + * + * @return scroll bar thumb disabled background color + */ + public Color getThumbDisabledBackgroundColor () { - return scrollSelGradientLeft; + return thumbDisabledBackgroundColor; } - public void setScrollSelGradientLeft ( final Color scrollSelGradientLeft ) + /** + * Sets scroll bar thumb disabled background color. + * + * @param color new scroll bar thumb disabled background color + */ + public void setThumbDisabledBackgroundColor ( final Color color ) { - this.scrollSelGradientLeft = scrollSelGradientLeft; + this.thumbDisabledBackgroundColor = color; + if ( painter != null ) + { + painter.setThumbDisabledBackgroundColor ( color ); + } } - public Color getScrollSelGradientRight () + /** + * Returns scroll bar thumb rollover border color. + * + * @return scroll bar thumb rollover border color + */ + public Color getThumbRolloverBorderColor () { - return scrollSelGradientRight; + return thumbRolloverBorderColor; } - public void setScrollSelGradientRight ( final Color scrollSelGradientRight ) + /** + * Sets scroll bar thumb rollover border color. + * + * @param color new scroll bar thumb rollover border color + */ + public void setThumbRolloverBorderColor ( final Color color ) { - this.scrollSelGradientRight = scrollSelGradientRight; + this.thumbRolloverBorderColor = color; + if ( painter != null ) + { + painter.setThumbRolloverBorderColor ( color ); + } } - @Override - public void paint ( final Graphics g, final JComponent c ) + /** + * Returns scroll bar thumb rollover background color. + * + * @return scroll bar thumb rollover background color + */ + public Color getThumbRolloverBackgroundColor () { - final Object aa = LafUtils.disableAntialias ( g ); - super.paint ( g, c ); - LafUtils.restoreAntialias ( g, aa ); + return thumbRolloverBackgroundColor; } - @Override - protected void paintTrack ( final Graphics g, final JComponent c, final Rectangle trackBounds ) + /** + * Sets scroll bar thumb rollover background color. + * + * @param color new scroll bar thumb rollover background color + */ + public void setThumbRolloverBackgroundColor ( final Color color ) { - if ( drawBorder ) + this.thumbRolloverBackgroundColor = color; + if ( painter != null ) { - final Graphics2D g2d = ( Graphics2D ) g; + painter.setThumbRolloverBackgroundColor ( color ); + } + } - g2d.setPaint ( scrollBg ); - g2d.fillRect ( 0, 0, scrollbar.getWidth (), scrollbar.getHeight () ); + /** + * Returns scroll bar thumb pressed/dragged border color. + * + * @return scroll bar thumb pressed/dragged border color + */ + public Color getThumbPressedBorderColor () + { + return thumbPressedBorderColor; + } - if ( scrollbar.getOrientation () == JScrollBar.VERTICAL ) - { - final int vBorder = scrollbar.getComponentOrientation ().isLeftToRight () ? 0 : scrollbar.getWidth () - 1; - g2d.setColor ( scrollBorder ); - g2d.drawLine ( vBorder, 0, vBorder, scrollbar.getHeight () - 1 ); - } - else - { - g2d.setColor ( scrollBorder ); - g2d.drawLine ( 0, 0, scrollbar.getWidth (), 0 ); - } + /** + * Sets scroll bar thumb pressed/dragged border color. + * + * @param color new scroll bar thumb pressed/dragged border color1 + */ + public void setThumbPressedBorderColor ( final Color color ) + { + this.thumbPressedBorderColor = color; + if ( painter != null ) + { + painter.setThumbPressedBorderColor ( color ); } } - @Override - protected void paintThumb ( final Graphics g, final JComponent c, final Rectangle thumbBounds ) + /** + * Returns scroll bar thumb pressed/dragged background color. + * + * @return scroll bar thumb pressed/dragged background color + */ + public Color getThumbPressedBackgroundColor () { - final Graphics2D g2d = ( Graphics2D ) g; + return thumbPressedBackgroundColor; + } - final Color leftC = isDragging ? scrollSelGradientLeft : scrollGradientLeft; - final Color rightC = isDragging ? scrollSelGradientRight : scrollGradientRight; + /** + * Sets scroll bar thumb pressed/dragged background color. + * + * @param color new scroll bar thumb pressed/dragged background color + */ + public void setThumbPressedBackgroundColor ( final Color color ) + { + this.thumbPressedBackgroundColor = color; + if ( painter != null ) + { + painter.setThumbPressedBackgroundColor ( color ); + } + } + + /** + * Returns scroll bar thumb corners rounding. + * + * @return scroll bar thumb corners rounding + */ + public int getThumbRound () + { + return thumbRound; + } - if ( scrollbar.getOrientation () == JScrollBar.VERTICAL ) + /** + * Sets scroll bar thumb corners rounding. + * + * @param round new scroll bar thumb corners rounding + */ + public void setThumbRound ( final int round ) + { + this.thumbRound = round; + if ( painter != null ) { - final boolean ltr = scrollbar.getComponentOrientation ().isLeftToRight (); - final Color leftColor = ltr ? leftC : rightC; - final Color rightColor = ltr ? rightC : leftC; - final int x = ltr ? 2 : 1; + painter.setThumbRound ( round ); + } + } - g2d.setPaint ( new GradientPaint ( 3, 0, leftColor, scrollbar.getWidth () - 4, 0, rightColor ) ); - g2d.fillRoundRect ( thumbRect.x + x, thumbRect.y + 1, thumbRect.width - 4, thumbRect.height - 3, round, round ); + /** + * Returns scroll bar thumb margin. + * + * @return scroll bar thumb margin + */ + public Insets getThumbMargin () + { + return thumbMargin; + } - g2d.setPaint ( scrollBarBorder ); - g2d.drawRoundRect ( thumbRect.x + x, thumbRect.y + 1, thumbRect.width - 4, thumbRect.height - 3, round, round ); + /** + * Sets scroll bar thumb margin. + * + * @param margin new scroll bar thumb margin + */ + public void setThumbMargin ( final Insets margin ) + { + this.thumbMargin = margin; + if ( painter != null ) + { + painter.setThumbMargin ( margin ); } - else + } + + /** + * Returns scroll bar content margin. + * + * @return scroll bar content margin + */ + public Insets getMargin () + { + return margin; + } + + /** + * Sets scroll bar content margin. + * + * @param margin new scroll bar content margin + */ + public void setMargin ( final Insets margin ) + { + this.margin = margin; + updateBorder (); + } + + /** + * Returns scroll bar painter. + * + * @return scroll bar painter + */ + public ScrollBarPainter getPainter () + { + return painter; + } + + /** + * Sets scroll bar painter. + * Pass null to remove scroll bar painter. + * + * @param painter new scroll bar painter + */ + public void setPainter ( final ScrollBarPainter painter ) + { + PainterSupport.uninstallPainter ( scrollbar, this.painter ); + this.painter = painter; + applyPainterSettings ( painter ); + PainterSupport.installPainter ( scrollbar, this.painter ); + } + + /** + * Applies UI settings to this specific painter. + * + * @param painter popup menu painter + */ + protected void applyPainterSettings ( final ScrollBarPainter painter ) + { + if ( painter != null ) { - g2d.setPaint ( new GradientPaint ( 0, thumbRect.y + 2, leftC, 0, thumbRect.y + 2 + thumbRect.height - 4, rightC ) ); - g2d.fillRoundRect ( thumbRect.x + 1, thumbRect.y + 2, thumbRect.width - 3, thumbRect.height - 4, round, round ); + // Style settings + painter.setButtonsVisible ( buttonsVisible ); + painter.setDrawTrack ( drawTrack ); + painter.setTrackBorderColor ( trackBorderColor ); + painter.setTrackBackgroundColor ( trackBackgroundColor ); + painter.setThumbBorderColor ( thumbBorderColor ); + painter.setThumbBackgroundColor ( thumbBackgroundColor ); + painter.setThumbDisabledBorderColor ( thumbDisabledBorderColor ); + painter.setThumbDisabledBackgroundColor ( thumbDisabledBackgroundColor ); + painter.setThumbRolloverBorderColor ( thumbRolloverBorderColor ); + painter.setThumbRolloverBackgroundColor ( thumbRolloverBackgroundColor ); + painter.setThumbPressedBorderColor ( thumbPressedBorderColor ); + painter.setThumbPressedBackgroundColor ( thumbPressedBackgroundColor ); + painter.setThumbRound ( thumbRound ); + painter.setThumbMargin ( thumbMargin ); + } + } - g2d.setPaint ( scrollBarBorder ); - g2d.drawRoundRect ( thumbRect.x + 1, thumbRect.y + 2, thumbRect.width - 3, thumbRect.height - 4, round, round ); + /** + * Returns decrease button painter. + * This the button displayed at top or left side of the scroll bar. + * + * @return decrease button painter + */ + public ScrollBarButtonPainter getDecreaseButtonPainter () + { + return decreaseButtonPainter; + } + + /** + * Sets decrease button painter. + * This the button displayed at top or left side of the scroll bar. + * + * @param painter new decrease button painter + */ + public void setDecreaseButtonPainter ( final ScrollBarButtonPainter painter ) + { + this.decreaseButtonPainter = painter; + if ( decrButton != null ) + { + ( ( WebButton ) decrButton ).setPainter ( painter ); } } + /** + * Returns increase button painter. + * This the button displayed at bottom or right side of the scroll bar. + * + * @return increase button painter + */ + public ScrollBarButtonPainter getIncreaseButtonPainter () + { + return increaseButtonPainter; + } + + /** + * Sets increase button painter. + * This the button displayed at bottom or right side of the scroll bar. + * + * @param painter new increase button painter + */ + public void setIncreaseButtonPainter ( final ScrollBarButtonPainter painter ) + { + this.increaseButtonPainter = painter; + if ( incrButton != null ) + { + ( ( WebButton ) incrButton ).setPainter ( painter ); + } + } + + /** + * Paints scroll bar decorations. + * The whole painting process is delegated to installed painter class. + * + * @param g graphics context + * @param c scroll bar component + */ + @Override + public void paint ( final Graphics g, final JComponent c ) + { + if ( painter != null ) + { + painter.setDragged ( isDragging ); + painter.setTrackBounds ( getTrackBounds () ); + painter.setThumbBounds ( getThumbBounds () ); + painter.paint ( ( Graphics2D ) g, SwingUtils.size ( scrollbar ), scrollbar ); + } + } + + /** + * Installs additional scroll bar components. + */ @Override protected void installComponents () { - incrButton = new JButton (); - incrButton.setPreferredSize ( new Dimension ( 0, 0 ) ); - decrButton = new JButton (); - decrButton.setPreferredSize ( new Dimension ( 0, 0 ) ); + final WebButton db = new WebButton ( decreaseButtonPainter ) + { + @Override + public Dimension getPreferredSize () + { + // The best way (so far) to hide buttons without causing a serious mess in the code + return buttonsVisible ? super.getPreferredSize () : new Dimension ( 0, 0 ); + } + }; + db.setFocusable ( false ); + db.setLeftRightSpacing ( 0 ); + + decrButton = db; + scrollbar.add ( decrButton ); + + final WebButton ib = new WebButton ( increaseButtonPainter ) + { + @Override + public Dimension getPreferredSize () + { + // The best way (so far) to hide buttons without causing a serious mess in the code + return buttonsVisible ? super.getPreferredSize () : new Dimension ( 0, 0 ); + } + }; + ib.setFocusable ( false ); + ib.setLeftRightSpacing ( 0 ); + + incrButton = ib; + scrollbar.add ( incrButton ); + + // Force the children's enabled state to be updated. + scrollbar.setEnabled ( scrollbar.isEnabled () ); } + /** + * {@inheritDoc} + */ @Override public Dimension getPreferredSize ( final JComponent c ) { - final Dimension preferredSize = super.getPreferredSize ( c ); - return ( scrollbar.getOrientation () == JScrollBar.VERTICAL ) ? new Dimension ( LENGTH, preferredSize.height ) : - new Dimension ( preferredSize.width, LENGTH ); + final boolean ver = scrollbar.getOrientation () == JScrollBar.VERTICAL; + + // Simple scroll bar preferred size + Dimension ps = ver ? new Dimension ( scrollBarWidth, 48 ) : new Dimension ( 48, scrollBarWidth ); + + // Arrow button preferred sizes + if ( buttonsVisible && decrButton != null && incrButton != null ) + { + final Dimension dps = decrButton.getPreferredSize (); + final Dimension ips = decrButton.getPreferredSize (); + if ( ver ) + { + ps.width = Math.max ( ps.width, Math.max ( dps.width, ips.width ) ); + } + else + { + ps.height = Math.max ( ps.height, Math.max ( dps.height, ips.height ) ); + } + } + + // Insets + final Insets i = c.getInsets (); + ps.width += i.left + i.right; + ps.height += i.top + i.bottom; + + // Background painter preferred size + if ( painter != null ) + { + ps = SwingUtils.max ( ps, painter.getPreferredSize ( c ) ); + } + + return ps; } -} +} \ No newline at end of file diff --git a/src/com/alee/laf/scroll/WebScrollPane.java b/src/com/alee/laf/scroll/WebScrollPane.java index b64da90d1..3a3a393a0 100644 --- a/src/com/alee/laf/scroll/WebScrollPane.java +++ b/src/com/alee/laf/scroll/WebScrollPane.java @@ -41,15 +41,15 @@ public WebScrollPane ( final Component view ) public WebScrollPane ( final Component view, final boolean drawBorder ) { - this ( view, drawBorder, WebScrollBarStyle.drawBorder ); + this ( view, drawBorder, true ); } public WebScrollPane ( final Component view, final boolean drawBorder, final boolean drawInnerBorder ) { super ( view ); setDrawBorder ( drawBorder ); - getWebHorizontalScrollBar ().setDrawBorder ( drawInnerBorder ); - getWebVerticalScrollBar ().setDrawBorder ( drawInnerBorder ); + getWebHorizontalScrollBar ().setDrawTrack ( drawInnerBorder ); + getWebVerticalScrollBar ().setDrawTrack ( drawInnerBorder ); if ( !drawInnerBorder ) { setCorner ( JScrollPane.LOWER_RIGHT_CORNER, null ); diff --git a/src/com/alee/laf/scroll/WebScrollPaneCorner.java b/src/com/alee/laf/scroll/WebScrollPaneCorner.java index ab9035b9c..0b6a52cfb 100644 --- a/src/com/alee/laf/scroll/WebScrollPaneCorner.java +++ b/src/com/alee/laf/scroll/WebScrollPaneCorner.java @@ -37,15 +37,15 @@ public WebScrollPaneCorner () } @Override - protected void paintComponent ( Graphics g ) + protected void paintComponent ( final Graphics g ) { super.paintComponent ( g ); - int vBorder = getComponentOrientation ().isLeftToRight () ? 0 : getWidth () - 1; - g.setColor ( WebScrollBarStyle.scrollBg ); + final int vBorder = getComponentOrientation ().isLeftToRight () ? 0 : getWidth () - 1; + g.setColor ( WebScrollBarStyle.trackBackgroundColor ); g.fillRect ( 0, 0, getWidth (), getHeight () ); - g.setColor ( WebScrollBarStyle.scrollBorder ); + g.setColor ( WebScrollBarStyle.trackBorderColor ); g.drawLine ( 0, 0, getWidth () - 1, 0 ); g.drawLine ( vBorder, 0, vBorder, getHeight () - 1 ); } -} +} \ No newline at end of file diff --git a/src/com/alee/laf/scroll/WebScrollPaneLayout.java b/src/com/alee/laf/scroll/WebScrollPaneLayout.java new file mode 100644 index 000000000..6d037c95a --- /dev/null +++ b/src/com/alee/laf/scroll/WebScrollPaneLayout.java @@ -0,0 +1,69 @@ +/* + * This file is part of WebLookAndFeel library. + * + * WebLookAndFeel library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * WebLookAndFeel library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WebLookAndFeel library. If not, see . + */ + +package com.alee.laf.scroll; + +import javax.swing.*; +import java.awt.*; + +/** + * This is a ScrollPaneLayout extension that properly places scroll pane shade layer. + * + * @author Mikle Garin + */ + +public class WebScrollPaneLayout extends ScrollPaneLayout +{ + /** + * Shade layer component. + */ + private final JComponent shadeLayer; + + /** + * Constructs new WebScrollPaneLayout with the specified shade layer. + * + * @param shadeLayer + */ + public WebScrollPaneLayout ( final JComponent shadeLayer ) + { + super (); + this.shadeLayer = shadeLayer; + } + + /** + * {@inheritDoc} + */ + @Override + public void layoutContainer ( final Container parent ) + { + super.layoutContainer ( parent ); + + shadeLayer.setBounds ( new Rectangle ( viewport.getBounds () ) ); + parent.setComponentZOrder ( shadeLayer, 0 ); + } + + /** + * The UI resource version of WebScrollPaneLayout. + */ + public static class UIResource extends WebScrollPaneLayout implements javax.swing.plaf.UIResource + { + public UIResource ( final JComponent shadeLayer ) + { + super ( shadeLayer ); + } + } +} \ No newline at end of file diff --git a/src/com/alee/laf/scroll/WebScrollPaneStyle.java b/src/com/alee/laf/scroll/WebScrollPaneStyle.java index d124b7fd1..fc9a5df21 100644 --- a/src/com/alee/laf/scroll/WebScrollPaneStyle.java +++ b/src/com/alee/laf/scroll/WebScrollPaneStyle.java @@ -66,4 +66,4 @@ public final class WebScrollPaneStyle * Draw background */ public static boolean drawBackground = false; -} +} \ No newline at end of file diff --git a/src/com/alee/laf/scroll/WebScrollPaneUI.java b/src/com/alee/laf/scroll/WebScrollPaneUI.java index 7561cc70f..15a9fa344 100644 --- a/src/com/alee/laf/scroll/WebScrollPaneUI.java +++ b/src/com/alee/laf/scroll/WebScrollPaneUI.java @@ -28,6 +28,7 @@ import javax.swing.*; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ScrollBarUI; import javax.swing.plaf.basic.BasicScrollPaneUI; import java.awt.*; import java.beans.PropertyChangeEvent; @@ -39,6 +40,10 @@ public class WebScrollPaneUI extends BasicScrollPaneUI implements ShapeProvider { + /** + * todo 1. Implement optional shade layer + */ + private boolean drawBorder = WebScrollPaneStyle.drawBorder; private Color borderColor = WebScrollPaneStyle.borderColor; private Color darkBorder = WebScrollPaneStyle.darkBorder; @@ -60,7 +65,7 @@ public class WebScrollPaneUI extends BasicScrollPaneUI implements ShapeProvider private boolean focused = false; - @SuppressWarnings ("UnusedParameters") + @SuppressWarnings ( "UnusedParameters" ) public static ComponentUI createUI ( final JComponent c ) { return new WebScrollPaneUI (); @@ -76,6 +81,59 @@ public void installUI ( final JComponent c ) LookAndFeel.installProperty ( scrollpane, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.FALSE ); scrollpane.setBackground ( StyleConstants.backgroundColor ); + final ScrollBarUI vui = scrollpane.getVerticalScrollBar ().getUI (); + if ( vui instanceof WebScrollBarUI ) + { + ( ( WebScrollBarUI ) vui ).setDrawTrack ( drawBorder ); + } + final ScrollBarUI hui = scrollpane.getHorizontalScrollBar ().getUI (); + if ( hui instanceof WebScrollBarUI ) + { + ( ( WebScrollBarUI ) hui ).setDrawTrack ( drawBorder ); + } + + // // Shade layer + // final WebPanel shadeLayer = new WebPanel ( new AbstractPainter () + // { + // final int shadeWidth = 15; + // final float transparency = 0.7f; + // + // @Override + // public void paint ( final Graphics2D g2d, final Rectangle bounds, final Component c ) + // { + // final JViewport viewport = scrollpane.getViewport (); + // final Component vc = viewport.getView (); + // if ( vc != null && vc instanceof JComponent ) + // { + // final JComponent view = ( JComponent ) vc; + // final Rectangle vr = view.getVisibleRect (); + // + // final int topY = vr.y; + // if ( topY > 0 ) + // { + // final float max = topY / 2; + // final float opacity = ( shadeWidth < max ? 1f : ( 1f - ( shadeWidth - max ) / shadeWidth ) ) * transparency; + // final NinePatchIcon npi = NinePatchUtils.getShadeIcon ( shadeWidth, 0, opacity ); + // final Dimension ps = npi.getPreferredSize (); + // npi.paintIcon ( g2d, -shadeWidth * 2, shadeWidth - ps.height, vr.width + shadeWidth * 4, ps.height ); + // } + // + // final int bottomY = vr.y + vr.height; + // final int height = view.getHeight (); + // if ( bottomY < height ) + // { + // final float max = ( height - bottomY ) / 2; + // final float opacity = ( shadeWidth < max ? 1f : ( 1f - ( shadeWidth - max ) / shadeWidth ) ) * transparency; + // final NinePatchIcon npi = NinePatchUtils.getShadeIcon ( shadeWidth, 0, opacity ); + // final Dimension ps = npi.getPreferredSize (); + // npi.paintIcon ( g2d, -shadeWidth * 2, vr.height - shadeWidth, vr.width + shadeWidth * 4, ps.height ); + // } + // } + // } + // } ); + // scrollpane.add ( shadeLayer, scrollpane.getComponentCount () ); + // scrollpane.setLayout ( new WebScrollPaneLayout.UIResource ( shadeLayer ) ); + // Border updateBorder (); @@ -140,7 +198,6 @@ private void updateBorder () { if ( scrollpane != null ) { - // Must use a non-UIResource border otherwise tables don't look right (?) // Preserve old borders if ( SwingUtils.isPreserveBorders ( scrollpane ) ) { diff --git a/src/com/alee/laf/separator/WebSeparatorUI.java b/src/com/alee/laf/separator/WebSeparatorUI.java index 32b40da6c..0800f3409 100644 --- a/src/com/alee/laf/separator/WebSeparatorUI.java +++ b/src/com/alee/laf/separator/WebSeparatorUI.java @@ -59,7 +59,6 @@ public static ComponentUI createUI ( final JComponent c ) public void installUI ( final JComponent c ) { super.installUI ( c ); - this.separator = ( JSeparator ) c; // Default settings diff --git a/src/com/alee/laf/slider/WebSliderUI.java b/src/com/alee/laf/slider/WebSliderUI.java index 962c7d648..19ec3be3b 100644 --- a/src/com/alee/laf/slider/WebSliderUI.java +++ b/src/com/alee/laf/slider/WebSliderUI.java @@ -109,7 +109,7 @@ public void installUI ( final JComponent c ) // Default settings SwingUtils.setOrientation ( slider ); - slider.setOpaque ( false ); + LookAndFeel.installProperty ( slider, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.FALSE ); slider.setForeground ( StyleConstants.textColor ); PainterSupport.installPainter ( slider, this.painter ); updateBorder (); diff --git a/src/com/alee/laf/spinner/WebSpinnerUI.java b/src/com/alee/laf/spinner/WebSpinnerUI.java index 4442eefbb..0ddfa5b8f 100644 --- a/src/com/alee/laf/spinner/WebSpinnerUI.java +++ b/src/com/alee/laf/spinner/WebSpinnerUI.java @@ -18,6 +18,7 @@ package com.alee.laf.spinner; import com.alee.laf.StyleConstants; +import com.alee.laf.WebLookAndFeel; import com.alee.laf.button.WebButton; import com.alee.laf.text.WebTextFieldUI; import com.alee.utils.LafUtils; @@ -59,8 +60,8 @@ public void installUI ( final JComponent c ) // Default settings SwingUtils.setOrientation ( spinner ); + LookAndFeel.installProperty ( spinner, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.FALSE ); spinner.setBackground ( Color.WHITE ); - spinner.setOpaque ( false ); // Updating border updateBorder (); diff --git a/src/com/alee/laf/splitpane/WebSplitPaneUI.java b/src/com/alee/laf/splitpane/WebSplitPaneUI.java index 6be446901..65fbbf589 100644 --- a/src/com/alee/laf/splitpane/WebSplitPaneUI.java +++ b/src/com/alee/laf/splitpane/WebSplitPaneUI.java @@ -59,7 +59,7 @@ public class WebSplitPaneUI extends BasicSplitPaneUI implements BorderMethods * @param c component that will use UI instance * @return instance of the WebSplitPaneUI */ - @SuppressWarnings ( "UnusedParameters" ) + @SuppressWarnings ("UnusedParameters") public static ComponentUI createUI ( final JComponent c ) { return new WebSplitPaneUI (); @@ -77,8 +77,8 @@ public void installUI ( final JComponent c ) // Default settings SwingUtils.setOrientation ( splitPane ); - splitPane.setOpaque ( false ); - splitPane.setBorder ( null ); + LookAndFeel.installProperty ( splitPane, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.FALSE ); + splitPane.setBorder ( LafUtils.createWebBorder ( 0 ) ); splitPane.setDividerSize ( 6 ); // Updating border diff --git a/src/com/alee/laf/tabbedpane/NeoTabbedPaneUI.java b/src/com/alee/laf/tabbedpane/NeoTabbedPaneUI.java index c657ecdac..4b154e3c3 100644 --- a/src/com/alee/laf/tabbedpane/NeoTabbedPaneUI.java +++ b/src/com/alee/laf/tabbedpane/NeoTabbedPaneUI.java @@ -33,25 +33,25 @@ public class NeoTabbedPaneUI extends BasicTabbedPaneUI { - private Color borderColor = new Color ( 165, 165, 165 ); - private Color innerBorderColor = new Color ( 248, 248, 248 ); + private final Color borderColor = new Color ( 165, 165, 165 ); + private final Color innerBorderColor = new Color ( 248, 248, 248 ); - @SuppressWarnings ( "UnusedParameters" ) - public static ComponentUI createUI ( JComponent c ) + @SuppressWarnings ("UnusedParameters") + public static ComponentUI createUI ( final JComponent c ) { return new NeoTabbedPaneUI (); } @Override - protected void paintTabArea ( Graphics g, int tabPlacement, int selectedIndex ) + protected void paintTabArea ( final Graphics g, final int tabPlacement, final int selectedIndex ) { - Graphics2D g2d = ( Graphics2D ) g; + final Graphics2D g2d = ( Graphics2D ) g; - int tabCount = tabPane.getTabCount (); + final int tabCount = tabPane.getTabCount (); - Rectangle iconRect = new Rectangle (); - Rectangle textRect = new Rectangle (); - Rectangle clipRect = g.getClipBounds (); + final Rectangle iconRect = new Rectangle (); + final Rectangle textRect = new Rectangle (); + final Rectangle clipRect = g.getClipBounds (); // Paint tabRuns of tabs from back to front int sr = -1; @@ -60,10 +60,10 @@ protected void paintTabArea ( Graphics g, int tabPlacement, int selectedIndex ) for ( int i = runCount - 1; i >= 0; i-- ) { int col = 0; - int start = tabRuns[ i ]; - int next = tabRuns[ ( i == runCount - 1 ) ? 0 : i + 1 ]; - int end = ( next != 0 ? next - 1 : tabCount - 1 ); - int colsInRow = end - start + 1; + final int start = tabRuns[ i ]; + final int next = tabRuns[ ( i == runCount - 1 ) ? 0 : i + 1 ]; + final int end = ( next != 0 ? next - 1 : tabCount - 1 ); + final int colsInRow = end - start + 1; for ( int j = start; j <= end; j++ ) { if ( j != selectedIndex && rects[ j ].intersects ( clipRect ) ) @@ -105,20 +105,20 @@ protected void paintTabArea ( Graphics g, int tabPlacement, int selectedIndex ) // } } - protected void paintTab ( Graphics2D g2d, int tabPlacement, Rectangle[] rects, int row, int col, int colsInRow, int tabIndex, - Rectangle iconRect, Rectangle textRect ) + protected void paintTab ( final Graphics2D g2d, final int tabPlacement, final Rectangle[] rects, final int row, final int col, + final int colsInRow, final int tabIndex, final Rectangle iconRect, final Rectangle textRect ) { - Rectangle tabRect = rects[ tabIndex ]; - int selectedIndex = tabPane.getSelectedIndex (); - boolean isSelected = selectedIndex == tabIndex; + final Rectangle tabRect = rects[ tabIndex ]; + final int selectedIndex = tabPane.getSelectedIndex (); + final boolean isSelected = selectedIndex == tabIndex; paintTabBackground ( g2d, tabPlacement, row, col, colsInRow, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected ); - String title = tabPane.getTitleAt ( tabIndex ); - Font font = tabPane.getFont (); - FontMetrics metrics = SwingUtils.getFontMetrics ( tabPane, g2d, font ); - Icon icon = getIconForTab ( tabIndex ); + final String title = tabPane.getTitleAt ( tabIndex ); + final Font font = tabPane.getFont (); + final FontMetrics metrics = SwingUtils.getFontMetrics ( tabPane, g2d, font ); + final Icon icon = getIconForTab ( tabIndex ); layoutLabel ( tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected ); @@ -132,12 +132,12 @@ protected void paintTab ( Graphics2D g2d, int tabPlacement, Rectangle[] rects, i } @Override - protected void paintText ( Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, - boolean isSelected ) + protected void paintText ( final Graphics g, final int tabPlacement, final Font font, final FontMetrics metrics, final int tabIndex, + final String title, final Rectangle textRect, final boolean isSelected ) { - Map aa = SwingUtils.setupTextAntialias ( g ); + final Map aa = SwingUtils.setupTextAntialias ( g ); g.setFont ( font ); - View v = getTextViewForTab ( tabIndex ); + final View v = getTextViewForTab ( tabIndex ); if ( v != null ) { // html @@ -146,14 +146,14 @@ protected void paintText ( Graphics g, int tabPlacement, Font font, FontMetrics else { // plain text - int mnemIndex = tabPane.getDisplayedMnemonicIndexAt ( tabIndex ); + final int mnemIndex = tabPane.getDisplayedMnemonicIndexAt ( tabIndex ); if ( tabPane.isEnabled () && tabPane.isEnabledAt ( tabIndex ) ) { Color fg = tabPane.getForegroundAt ( tabIndex ); if ( isSelected && ( fg instanceof UIResource ) ) { - Color selectedFG = UIManager.getColor ( "TabbedPane.selectedForeground" ); + final Color selectedFG = UIManager.getColor ( "TabbedPane.selectedForeground" ); if ( selectedFG != null ) { fg = selectedFG; @@ -215,9 +215,9 @@ protected void paintText ( Graphics g, int tabPlacement, Font font, FontMetrics // } // } - @SuppressWarnings ( "UnusedParameters" ) - protected void paintTabBackground ( Graphics2D g2d, int tabPlacement, int row, int col, int colsInRow, int tabIndex, int x, int y, - int w, int h, boolean isSelected ) + @SuppressWarnings ("UnusedParameters") + protected void paintTabBackground ( final Graphics2D g2d, final int tabPlacement, final int row, final int col, final int colsInRow, + final int tabIndex, final int x, final int y, final int w, final int h, final boolean isSelected ) { // Background @@ -233,8 +233,8 @@ protected void paintTabBackground ( Graphics2D g2d, int tabPlacement, int row, i } // Border - boolean topBorder = row > 0; - boolean trailingBorder = runCount == 1 || col < colsInRow - 1; + final boolean topBorder = row > 0; + final boolean trailingBorder = runCount == 1 || col < colsInRow - 1; if ( isSelected ) { // Border @@ -290,11 +290,11 @@ protected void paintTabBackground ( Graphics2D g2d, int tabPlacement, int row, i } @Override - protected void paintContentBorder ( Graphics g, int tabPlacement, int selectedIndex ) + protected void paintContentBorder ( final Graphics g, final int tabPlacement, final int selectedIndex ) { - int width = tabPane.getWidth (); + final int width = tabPane.getWidth (); // int height = tabPane.getHeight (); - Insets insets = tabPane.getInsets (); + final Insets insets = tabPane.getInsets (); int x = insets.left; int y = insets.top; @@ -330,7 +330,7 @@ protected void paintContentBorder ( Graphics g, int tabPlacement, int selectedIn case TOP: default: { - Graphics2D g2d = ( Graphics2D ) g; + final Graphics2D g2d = ( Graphics2D ) g; g2d.setPaint ( new GradientPaint ( x, y + 1, new Color ( 232, 232, 232 ), x, y + 3, new Color ( 230, 230, 230 ) ) ); g2d.fillRect ( x, y + 1, w, 3 ); diff --git a/src/com/alee/laf/table/WebTable.java b/src/com/alee/laf/table/WebTable.java index 021557fd5..94d39af59 100644 --- a/src/com/alee/laf/table/WebTable.java +++ b/src/com/alee/laf/table/WebTable.java @@ -76,6 +76,7 @@ public WebTable ( final Object[][] rowData, final Object[] columnNames ) super ( rowData, columnNames ); } + public void setSelectedRow ( final int row ) { setSelectedRow ( row, true ); @@ -159,7 +160,10 @@ public void scrollToRow ( final int row ) final Rectangle firstCell = getCellRect ( row, 0, true ); final Rectangle lastCell = getCellRect ( row, getColumnCount () - 1, true ); final Rectangle rect = GeometryUtils.getContainingRect ( firstCell, lastCell ); - scrollRectToVisible ( rect ); + if ( rect != null ) + { + scrollRectToVisible ( rect ); + } } public void scrollToColumn ( final int column ) @@ -167,7 +171,10 @@ public void scrollToColumn ( final int column ) final Rectangle firstCell = getCellRect ( 0, column, true ); final Rectangle lastCell = getCellRect ( getRowCount () - 1, column, true ); final Rectangle rect = GeometryUtils.getContainingRect ( firstCell, lastCell ); - scrollRectToVisible ( rect ); + if ( rect != null ) + { + scrollRectToVisible ( rect ); + } } @Override diff --git a/src/com/alee/laf/table/WebTableHeaderUI.java b/src/com/alee/laf/table/WebTableHeaderUI.java index f662e5939..a3f8df4ab 100644 --- a/src/com/alee/laf/table/WebTableHeaderUI.java +++ b/src/com/alee/laf/table/WebTableHeaderUI.java @@ -18,6 +18,7 @@ package com.alee.laf.table; import com.alee.laf.StyleConstants; +import com.alee.laf.WebLookAndFeel; import com.alee.laf.table.renderers.WebTableHeaderCellRenderer; import com.alee.utils.SwingUtils; @@ -41,28 +42,28 @@ public class WebTableHeaderUI extends BasicTableHeaderUI public static final Color bottomLineColor = new Color ( 104, 104, 104 ); @SuppressWarnings ("UnusedParameters") - public static ComponentUI createUI ( JComponent c ) + public static ComponentUI createUI ( final JComponent c ) { return new WebTableHeaderUI (); } @Override - public void installUI ( JComponent c ) + public void installUI ( final JComponent c ) { super.installUI ( c ); // Default settings SwingUtils.setOrientation ( header ); - header.setOpaque ( true ); + LookAndFeel.installProperty ( header, WebLookAndFeel.OPAQUE_PROPERTY, Boolean.TRUE ); // Default renderer header.setDefaultRenderer ( new WebTableHeaderCellRenderer () { @Override - public Component getTableCellRendererComponent ( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, - int column ) + public Component getTableCellRendererComponent ( final JTable table, final Object value, final boolean isSelected, + final boolean hasFocus, final int row, final int column ) { - JLabel renderer = ( JLabel ) super.getTableCellRendererComponent ( table, value, isSelected, hasFocus, row, column ); + final JLabel renderer = ( JLabel ) super.getTableCellRendererComponent ( table, value, isSelected, hasFocus, row, column ); renderer.setHorizontalAlignment ( JLabel.CENTER ); return renderer; } @@ -70,12 +71,12 @@ public Component getTableCellRendererComponent ( JTable table, Object value, boo } @Override - public void paint ( Graphics g, JComponent c ) + public void paint ( final Graphics g, final JComponent c ) { - Graphics2D g2d = ( Graphics2D ) g; + final Graphics2D g2d = ( Graphics2D ) g; // Table header background - GradientPaint bgPaint = createBackgroundPaint ( 0, 1, 0, header.getHeight () - 1 ); + final GradientPaint bgPaint = createBackgroundPaint ( 0, 1, 0, header.getHeight () - 1 ); g2d.setPaint ( bgPaint ); g2d.fillRect ( 0, 1, header.getWidth (), header.getHeight () - 1 ); @@ -91,11 +92,11 @@ public void paint ( Graphics g, JComponent c ) } // Variables - boolean ltr = header.getComponentOrientation ().isLeftToRight (); - Rectangle clip = g.getClipBounds (); - Point left = clip.getLocation (); - Point right = new Point ( clip.x + clip.width - 1, clip.y ); - TableColumnModel cm = header.getColumnModel (); + final boolean ltr = header.getComponentOrientation ().isLeftToRight (); + final Rectangle clip = g.getClipBounds (); + final Point left = clip.getLocation (); + final Point right = new Point ( clip.x + clip.width - 1, clip.y ); + final TableColumnModel cm = header.getColumnModel (); int cMin = header.columnAtPoint ( ltr ? left : right ); int cMax = header.columnAtPoint ( ltr ? right : left ); @@ -113,9 +114,9 @@ public void paint ( Graphics g, JComponent c ) } // Table titles - TableColumn draggedColumn = header.getDraggedColumn (); + final TableColumn draggedColumn = header.getDraggedColumn (); int columnWidth; - Rectangle cellRect = header.getHeaderRect ( ltr ? cMin : cMax ); + final Rectangle cellRect = header.getHeaderRect ( ltr ? cMin : cMax ); TableColumn aColumn; if ( ltr ) { @@ -150,8 +151,8 @@ public void paint ( Graphics g, JComponent c ) if ( draggedColumn != null ) { // Calculating dragged cell rect - int draggedColumnIndex = viewIndexForColumn ( draggedColumn ); - Rectangle draggedCellRect = header.getHeaderRect ( draggedColumnIndex ); + final int draggedColumnIndex = viewIndexForColumn ( draggedColumn ); + final Rectangle draggedCellRect = header.getHeaderRect ( draggedColumnIndex ); draggedCellRect.x += header.getDraggedDistance (); // Background @@ -163,21 +164,22 @@ public void paint ( Graphics g, JComponent c ) } } - public static GradientPaint createBackgroundPaint ( int x1, int y1, int x2, int y2 ) + public static GradientPaint createBackgroundPaint ( final int x1, final int y1, final int x2, final int y2 ) { return new GradientPaint ( x1, y1, topBgColor, x2, y2, bottomBgColor ); } - private void paintCell ( Graphics g, Rectangle rect, int columnIndex, TableColumn tc, TableColumn dc, TableColumnModel cm ) + private void paintCell ( final Graphics g, final Rectangle rect, final int columnIndex, final TableColumn tc, final TableColumn dc, + final TableColumnModel cm ) { - boolean ltr = header.getComponentOrientation ().isLeftToRight (); + final boolean ltr = header.getComponentOrientation ().isLeftToRight (); // Left side border g.setColor ( StyleConstants.borderColor ); g.drawLine ( rect.x - 1, rect.y + 2, rect.x - 1, rect.y + rect.height - 4 ); // Painting dragged cell renderer - JComponent component = ( JComponent ) getHeaderRenderer ( columnIndex ); + final JComponent component = ( JComponent ) getHeaderRenderer ( columnIndex ); component.setOpaque ( false ); component.setEnabled ( header.getTable ().isEnabled () ); rendererPane.paintComponent ( g, component, header, rect.x, rect.y, rect.width, rect.height, true ); @@ -190,22 +192,22 @@ private void paintCell ( Graphics g, Rectangle rect, int columnIndex, TableColum } } - private Component getHeaderRenderer ( int columnIndex ) + private Component getHeaderRenderer ( final int columnIndex ) { - TableColumn aColumn = header.getColumnModel ().getColumn ( columnIndex ); + final TableColumn aColumn = header.getColumnModel ().getColumn ( columnIndex ); TableCellRenderer renderer = aColumn.getHeaderRenderer (); if ( renderer == null ) { renderer = header.getDefaultRenderer (); } - boolean hasFocus = !header.isPaintingForPrint () && header.hasFocus (); + final boolean hasFocus = !header.isPaintingForPrint () && header.hasFocus (); return renderer.getTableCellRendererComponent ( header.getTable (), aColumn.getHeaderValue (), false, hasFocus, -1, columnIndex ); } - private int viewIndexForColumn ( TableColumn aColumn ) + private int viewIndexForColumn ( final TableColumn aColumn ) { - TableColumnModel cm = header.getColumnModel (); + final TableColumnModel cm = header.getColumnModel (); for ( int column = 0; column < cm.getColumnCount (); column++ ) { if ( cm.getColumn ( column ) == aColumn ) @@ -217,9 +219,9 @@ private int viewIndexForColumn ( TableColumn aColumn ) } @Override - public Dimension getPreferredSize ( JComponent c ) + public Dimension getPreferredSize ( final JComponent c ) { - Dimension ps = super.getPreferredSize ( c ); + final Dimension ps = super.getPreferredSize ( c ); ps.height = Math.max ( ps.height, WebTableStyle.headerHeight ); return ps; } diff --git a/src/com/alee/laf/table/WebTableUI.java b/src/com/alee/laf/table/WebTableUI.java index 24e0a4585..2fe6b1685 100644 --- a/src/com/alee/laf/table/WebTableUI.java +++ b/src/com/alee/laf/table/WebTableUI.java @@ -80,6 +80,7 @@ public void installUI ( final JComponent c ) table.setShowVerticalLines ( WebTableStyle.showVerticalLines ); table.setIntercellSpacing ( WebTableStyle.cellsSpacing ); + // todo Save and restore old renderers/editors on uninstall // Configuring default renderers table.setDefaultRenderer ( Object.class, new WebTableCellRenderer () ); table.setDefaultRenderer ( Number.class, new WebNumberRenderer () ); diff --git a/src/com/alee/laf/toolbar/WebToolBarSeparatorUI.java b/src/com/alee/laf/toolbar/WebToolBarSeparatorUI.java index e971ac3cf..ce32b4d0e 100644 --- a/src/com/alee/laf/toolbar/WebToolBarSeparatorUI.java +++ b/src/com/alee/laf/toolbar/WebToolBarSeparatorUI.java @@ -28,8 +28,9 @@ public class WebToolBarSeparatorUI extends WebSeparatorUI { - public static ComponentUI createUI ( JComponent c ) + @SuppressWarnings ( "UnusedParameters" ) + public static ComponentUI createUI ( final JComponent c ) { return new WebToolBarSeparatorUI (); } -} +} \ No newline at end of file diff --git a/src/com/alee/laf/tree/WebTree.java b/src/com/alee/laf/tree/WebTree.java index 87fea35b9..8f808e358 100644 --- a/src/com/alee/laf/tree/WebTree.java +++ b/src/com/alee/laf/tree/WebTree.java @@ -981,7 +981,14 @@ public void repaint ( final int row ) */ public void repaint ( final int from, final int to ) { - repaint ( GeometryUtils.getContainingRect ( getWebUI ().getRowBounds ( from ), getWebUI ().getRowBounds ( to ) ) ); + final WebTreeUI webUI = getWebUI (); + final Rectangle fromBounds = webUI.getRowBounds ( from ); + final Rectangle toBounds = webUI.getRowBounds ( to ); + final Rectangle rect = GeometryUtils.getContainingRect ( fromBounds, toBounds ); + if ( rect != null ) + { + repaint ( rect ); + } } /** @@ -1009,11 +1016,7 @@ public void repaint ( final List nodes ) Rectangle summ = null; for ( final E node : nodes ) { - final Rectangle nodeBounds = getNodeBounds ( node ); - if ( nodeBounds != null ) - { - summ = GeometryUtils.getContainingRect ( summ, nodeBounds ); - } + summ = GeometryUtils.getContainingRect ( summ, getNodeBounds ( node ) ); } if ( summ != null ) { diff --git a/src/com/alee/laf/tree/WebTreeModel.java b/src/com/alee/laf/tree/WebTreeModel.java index 3e483fbc6..4bce17698 100644 --- a/src/com/alee/laf/tree/WebTreeModel.java +++ b/src/com/alee/laf/tree/WebTreeModel.java @@ -130,15 +130,15 @@ public void removeNodesFromParent ( final List nodes ) } /** - * Removes specified nodes from tree structure. + * Removes all child nodes under the specified node from tree structure. * - * @param nodes nodes to remove + * @param node node to remove childs from */ - public void removeNodesFromParent ( final E parentNode ) + public void removeNodesFromParent ( final E node ) { - for ( int i = 0; i < parentNode.getChildCount (); i++ ) + for ( int i = 0; i < node.getChildCount (); i++ ) { - removeNodeFromParent ( ( MutableTreeNode ) parentNode.getChildAt ( i ) ); + removeNodeFromParent ( ( MutableTreeNode ) node.getChildAt ( i ) ); } } diff --git a/src/com/alee/managers/version/VersionUpdater.java b/src/com/alee/managers/version/VersionUpdater.java index 6e2cab969..1ac27fbad 100644 --- a/src/com/alee/managers/version/VersionUpdater.java +++ b/src/com/alee/managers/version/VersionUpdater.java @@ -53,10 +53,18 @@ public class VersionUpdater * * @param args arguments */ - public static void main ( String[] args ) throws IOException + public static void main ( final String[] args ) throws IOException { VersionManager.initialize (); - updateVersion ( args.length == 0 || args[ 0 ].equals ( "increment" ) ? 1 : -1 ); + if ( args.length == 0 || args[ 0 ].equals ( "increment" ) || args[ 0 ].equals ( "decrement" ) ) + { + updateVersion ( args.length == 0 || args[ 0 ].equals ( "increment" ) ? 1 : -1 ); + } + else if ( args[ 0 ].equals ( "update" ) ) + { + updateVersion ( -1 ); + updateVersion ( +1 ); + } } /** @@ -65,7 +73,7 @@ public static void main ( String[] args ) throws IOException * @param change version change amount * @throws IOException */ - private static void updateVersion ( int change ) throws IOException + private static void updateVersion ( final int change ) throws IOException { // Updating version in properties final File propertiesFile = new File ( propertiesPath ); diff --git a/src/com/alee/utils/ColorUtils.java b/src/com/alee/utils/ColorUtils.java index 03999aeee..987a2a39d 100644 --- a/src/com/alee/utils/ColorUtils.java +++ b/src/com/alee/utils/ColorUtils.java @@ -69,10 +69,21 @@ public static Color getTransparentColor ( final Color color, final int alpha ) */ public static Color getIntermediateColor ( final Color color1, final Color color2, final float progress ) { - return new Color ( getIntermediateValue ( color1.getRed (), color2.getRed (), progress ), - getIntermediateValue ( color1.getGreen (), color2.getGreen (), progress ), - getIntermediateValue ( color1.getBlue (), color2.getBlue (), progress ), - getIntermediateValue ( color1.getAlpha (), color2.getAlpha (), progress ) ); + if ( progress <= 0f ) + { + return color1; + } + else if ( progress >= 1f ) + { + return color2; + } + else + { + return new Color ( getIntermediateValue ( color1.getRed (), color2.getRed (), progress ), + getIntermediateValue ( color1.getGreen (), color2.getGreen (), progress ), + getIntermediateValue ( color1.getBlue (), color2.getBlue (), progress ), + getIntermediateValue ( color1.getAlpha (), color2.getAlpha (), progress ) ); + } } /** diff --git a/src/com/alee/utils/GeometryUtils.java b/src/com/alee/utils/GeometryUtils.java index 91885ca52..293d5d476 100644 --- a/src/com/alee/utils/GeometryUtils.java +++ b/src/com/alee/utils/GeometryUtils.java @@ -34,7 +34,7 @@ public final class GeometryUtils * @param points points to process * @return rectangle containing all specified points */ - public static Rectangle getContainingRect ( List points ) + public static Rectangle getContainingRect ( final List points ) { return points != null && points.size () > 0 ? getContainingRect ( points.toArray ( new Point[ points.size () ] ) ) : null; } @@ -45,18 +45,18 @@ public static Rectangle getContainingRect ( List points ) * @param points points to process * @return rectangle containing all specified points */ - public static Rectangle getContainingRect ( Point... points ) + public static Rectangle getContainingRect ( final Point... points ) { if ( points != null && points.length > 0 ) { - Rectangle rect = new Rectangle ( points[ 0 ], new Dimension ( 0, 0 ) ); + final Rectangle rect = new Rectangle ( points[ 0 ], new Dimension ( 0, 0 ) ); int i = 1; while ( i < points.length ) { - Point p = points[ i ]; + final Point p = points[ i ]; if ( p.x < rect.x ) { - int diff = rect.x - p.x; + final int diff = rect.x - p.x; rect.x = p.x; rect.width += diff; } @@ -66,7 +66,7 @@ else if ( rect.x + rect.width < p.x ) } if ( p.y < rect.y ) { - int diff = rect.y - p.y; + final int diff = rect.y - p.y; rect.y = p.y; rect.height += diff; } @@ -98,7 +98,7 @@ else if ( rect.y + rect.height < p.y ) * @param rects rectangles to process * @return rectangle containing all specified rectangles */ - public static Rectangle getContainingRect ( Rectangle... rects ) + public static Rectangle getContainingRect ( final Rectangle... rects ) { if ( rects != null && rects.length > 0 ) { @@ -122,9 +122,9 @@ public static Rectangle getContainingRect ( Rectangle... rects ) * * @param r1 first rectangle * @param r2 second rectangle - * @return rectangle containing two others + * @return rectangle containing two others or null if both rectangles are null */ - public static Rectangle getContainingRect ( Rectangle r1, Rectangle r2 ) + public static Rectangle getContainingRect ( final Rectangle r1, final Rectangle r2 ) { if ( r1 == null && r2 != null ) { @@ -136,13 +136,13 @@ else if ( r2 == null && r1 != null ) } else if ( r1 == null && r2 == null ) { - return new Rectangle ( 0, 0, 0, 0 ); + return null; } - int minX = Math.min ( r1.x, r2.x ); - int minY = Math.min ( r1.y, r2.y ); - int maxX = Math.max ( r1.x + r1.width, r2.x + r2.width ); - int maxY = Math.max ( r1.y + r1.height, r2.y + r2.height ); + final int minX = Math.min ( r1.x, r2.x ); + final int minY = Math.min ( r1.y, r2.y ); + final int maxX = Math.max ( r1.x + r1.width, r2.x + r2.width ); + final int maxY = Math.max ( r1.y + r1.height, r2.y + r2.height ); return new Rectangle ( minX, minY, maxX - minX, maxY - minY ); } @@ -152,7 +152,7 @@ else if ( r1 == null && r2 == null ) * @param rect rectangle to validate * @return valid rectangle with non-negative width and height */ - public static Rectangle validateRect ( Rectangle rect ) + public static Rectangle validateRect ( final Rectangle rect ) { if ( rect.width >= 0 && rect.height >= 0 ) { @@ -161,13 +161,13 @@ public static Rectangle validateRect ( Rectangle rect ) else { int x = rect.x; - int width = Math.abs ( rect.width ); + final int width = Math.abs ( rect.width ); if ( rect.width < 0 ) { x = x - width; } int y = rect.y; - int height = Math.abs ( rect.height ); + final int height = Math.abs ( rect.height ); if ( rect.height < 0 ) { y = y - height; @@ -182,7 +182,7 @@ public static Rectangle validateRect ( Rectangle rect ) * @param rectangle rectangle to process * @return middle point for the specified rectangle */ - public static Point middle ( Rectangle rectangle ) + public static Point middle ( final Rectangle rectangle ) { return new Point ( rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height / 2 ); } @@ -194,7 +194,7 @@ public static Point middle ( Rectangle rectangle ) * @param p2 second point * @return middle point between the specified points */ - public static Point middle ( Point p1, Point p2 ) + public static Point middle ( final Point p1, final Point p2 ) { return new Point ( ( p1.x + p2.x ) / 2, ( p1.y + p2.y ) / 2 ); } @@ -208,7 +208,7 @@ public static Point middle ( Point p1, Point p2 ) * @param y2 second point Y coordinate * @return middle point between the specified points */ - public static Point middle ( int x1, int y1, int x2, int y2 ) + public static Point middle ( final int x1, final int y1, final int x2, final int y2 ) { return new Point ( ( x1 + x2 ) / 2, ( y1 + y2 ) / 2 ); } @@ -220,7 +220,7 @@ public static Point middle ( int x1, int y1, int x2, int y2 ) * @param expansion expansion * @return rectangle expanded in four directions for the specified values */ - public static Rectangle expand ( Rectangle rect, int expansion ) + public static Rectangle expand ( final Rectangle rect, final int expansion ) { return expand ( rect, expansion, expansion, expansion, expansion ); } @@ -235,7 +235,7 @@ public static Rectangle expand ( Rectangle rect, int expansion ) * @param right right expansion * @return rectangle expanded in four directions for the specified values */ - public static Rectangle expand ( Rectangle rect, int top, int left, int bottom, int right ) + public static Rectangle expand ( final Rectangle rect, final int top, final int left, final int bottom, final int right ) { return new Rectangle ( rect.x - left, rect.y - top, rect.width + left + right, rect.height + top + bottom ); } @@ -248,7 +248,7 @@ public static Rectangle expand ( Rectangle rect, int top, int left, int bottom, * @param yMod Y coordinate modifier * @return modified point */ - public static Point modify ( Point point, int xMod, int yMod ) + public static Point modify ( final Point point, final int xMod, final int yMod ) { return new Point ( point.x + xMod, point.y + yMod ); } @@ -260,7 +260,7 @@ public static Point modify ( Point point, int xMod, int yMod ) * @param p2 second line point * @return angle between the line specified by points and y=0 line */ - public static double getAngle ( Point p1, Point p2 ) + public static double getAngle ( final Point p1, final Point p2 ) { return getAngle ( p1.x, p1.y, p2.x, p2.y ); } @@ -274,9 +274,9 @@ public static double getAngle ( Point p1, Point p2 ) * @param y2 second point Y coordinate * @return angle between the line specified by points and y=0 line */ - public static double getAngle ( int x1, int y1, int x2, int y2 ) + public static double getAngle ( final int x1, final int y1, final int x2, final int y2 ) { - double angle = Math.asin ( ( y2 - y1 ) / Math.sqrt ( MathUtils.sqr ( x2 - x1 ) + MathUtils.sqr ( y2 - y1 ) ) ); + final double angle = Math.asin ( ( y2 - y1 ) / Math.sqrt ( MathUtils.sqr ( x2 - x1 ) + MathUtils.sqr ( y2 - y1 ) ) ); return x1 > x2 ? -angle - Math.PI : angle; } @@ -287,7 +287,7 @@ public static double getAngle ( int x1, int y1, int x2, int y2 ) * @param outer outer point to process * @return intersection point of the rectangle and the line goin from the middle of that rectangle to the outer point */ - private Point findMiddleLineIntersection ( Rectangle rect, Point outer ) + public static Point findMiddleLineIntersection ( final Rectangle rect, final Point outer ) { final Point middle = GeometryUtils.middle ( rect ); final int x1 = middle.x; @@ -296,8 +296,8 @@ private Point findMiddleLineIntersection ( Rectangle rect, Point outer ) final int y2 = outer.y; if ( x2 < rect.x ) { - int x = rect.x; - int y = ( x1 * ( y2 - y1 ) - y1 * ( x2 - x1 ) - x * ( y2 - y1 ) ) / ( x1 - x2 ); + final int x = rect.x; + final int y = ( x1 * ( y2 - y1 ) - y1 * ( x2 - x1 ) - x * ( y2 - y1 ) ) / ( x1 - x2 ); if ( y >= rect.y && y <= rect.y + rect.height ) { return new Point ( x, y ); @@ -305,8 +305,8 @@ private Point findMiddleLineIntersection ( Rectangle rect, Point outer ) } else if ( x2 > rect.x + rect.width ) { - int x = rect.x + rect.width; - int y = ( x1 * ( y2 - y1 ) - y1 * ( x2 - x1 ) - x * ( y2 - y1 ) ) / ( x1 - x2 ); + final int x = rect.x + rect.width; + final int y = ( x1 * ( y2 - y1 ) - y1 * ( x2 - x1 ) - x * ( y2 - y1 ) ) / ( x1 - x2 ); if ( y >= rect.y && y <= rect.y + rect.height ) { return new Point ( x, y ); @@ -314,8 +314,8 @@ else if ( x2 > rect.x + rect.width ) } if ( y2 < rect.y ) { - int y = rect.y; - int x = ( x1 * ( y2 - y1 ) - y1 * ( x2 - x1 ) - y * ( x1 - x2 ) ) / ( y2 - y1 ); + final int y = rect.y; + final int x = ( x1 * ( y2 - y1 ) - y1 * ( x2 - x1 ) - y * ( x1 - x2 ) ) / ( y2 - y1 ); if ( x >= rect.x && x <= rect.x + rect.width ) { return new Point ( x, y ); @@ -323,8 +323,8 @@ else if ( x2 > rect.x + rect.width ) } else if ( y2 > rect.y + rect.height ) { - int y = rect.y + rect.height; - int x = ( x1 * ( y2 - y1 ) - y1 * ( x2 - x1 ) - y * ( x1 - x2 ) ) / ( y2 - y1 ); + final int y = rect.y + rect.height; + final int x = ( x1 * ( y2 - y1 ) - y1 * ( x2 - x1 ) - y * ( x1 - x2 ) ) / ( y2 - y1 ); if ( x >= rect.x && x <= rect.x + rect.width ) { return new Point ( x, y ); diff --git a/src/com/alee/utils/LafUtils.java b/src/com/alee/utils/LafUtils.java index 744baa363..664d6968b 100644 --- a/src/com/alee/utils/LafUtils.java +++ b/src/com/alee/utils/LafUtils.java @@ -1531,6 +1531,27 @@ public static int getTextCenterShearY ( final FontMetrics fm ) return ( fm.getAscent () - fm.getLeading () - fm.getDescent () ) / 2; } + /** + * Attempts to update component border if border methods are available for it. + * Returns whether attempt has succeed or not. + * + * @param component component which border should be updated + * @return true if attempt has succeed, false otherwise + */ + public static boolean updateBorder ( final Component component ) + { + final BorderMethods borderMethods = LafUtils.getBorderMethods ( component ); + if ( borderMethods != null ) + { + borderMethods.updateBorder (); + return true; + } + else + { + return false; + } + } + /** * Returns border methods for the specified component or null if custom WebLaF border is not supported. * diff --git a/src/com/alee/utils/ShapeCache.java b/src/com/alee/utils/ShapeCache.java index dc5946504..dc79adbea 100644 --- a/src/com/alee/utils/ShapeCache.java +++ b/src/com/alee/utils/ShapeCache.java @@ -33,8 +33,28 @@ public class ShapeCache { + /** + * Separator for settings cached within single key. + */ + private static final String settingsSeparator = ";"; + + /** + * Shapes cache map. + */ private static final Map> shapeCache = new WeakHashMap> ( 10 ); + /** + * Returns cached component shape. + * If shape is not yet cached it will be created. + * If shape settings are changed from the last time it was queued it will be re-created. + * + * @param component component for which shape is cached + * @param shapeId unique shape ID + * @param shapeProvider shape provider + * @param settings shape settings used as a shape key + * @param shape type + * @return cached component shape + */ public static T getShape ( final Component component, final String shapeId, final DataProvider shapeProvider, final Object... settings ) { @@ -67,16 +87,58 @@ public static T getShape ( final Component component, final St } } + /** + * Combines shape settings into a single key for cache map and returns it. + * + * @param settings settings to combine + * @return key for the specified shape settings + */ private static String combineSettingsKey ( final Object... settings ) { final StringBuilder stringBuilder = new StringBuilder (); for ( final Object object : settings ) { - stringBuilder.append ( object.toString () ); + if ( stringBuilder.length () > 0 ) + { + stringBuilder.append ( settingsSeparator ); + } + stringBuilder.append ( getSettingKey ( object ) ); } return stringBuilder.toString (); } + /** + * Returns setting string representation. + * + * @param setting setting to be converted + * @return setting string representation + */ + private static String getSettingKey ( final Object setting ) + { + if ( setting instanceof Insets ) + { + final Insets i = ( Insets ) setting; + return i.top + "," + i.left + "," + i.bottom + "," + i.right; + } + else if ( setting instanceof Rectangle ) + { + final Rectangle r = ( Rectangle ) setting; + return r.x + "," + r.y + "," + r.width + "," + r.height; + } + else if ( setting instanceof Point ) + { + final Point p = ( Point ) setting; + return p.x + "," + p.y; + } + else + { + return setting.toString (); + } + } + + /** + * Cached shape class. + */ private static class CachedShape { private final String key;