From 5cae3a8141d042c8ff7daaf8066b7d03d412422f Mon Sep 17 00:00:00 2001 From: mmatessi <17149962+basix86@users.noreply.github.com> Date: Wed, 11 Nov 2020 16:57:40 +0100 Subject: [PATCH 1/4] add RangeSlider support --- .../com/formdev/flatlaf/ui/FlatSliderUI.java | 14 +- .../jideoss/FlatJideOssDefaultsAddon.java | 7 +- .../flatlaf/jideoss/ui/FlatRangeSliderUI.java | 606 ++++++++++++++++++ .../flatlaf/jideoss/FlatLaf.properties | 9 + .../testing/jideoss/FlatJideOssTest.java | 392 +++++------ .../testing/jideoss/FlatRangeSliderTest.java | 158 +++++ .../testing/jideoss/FlatRangeSliderTest.jfd | 94 +++ 7 files changed, 1080 insertions(+), 200 deletions(-) create mode 100644 flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java create mode 100644 flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.java create mode 100644 flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.jfd diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java index 9115a87e..35b93faa 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java @@ -61,14 +61,14 @@ import com.formdev.flatlaf.util.UIScale; public class FlatSliderUI extends BasicSliderUI { - private int trackWidth; - private int thumbWidth; + protected int trackWidth; + protected int thumbWidth; - private Color trackColor; - private Color thumbColor; - private Color focusColor; - private Color hoverColor; - private Color disabledForeground; + protected Color trackColor; + protected Color thumbColor; + protected Color focusColor; + protected Color hoverColor; + protected Color disabledForeground; private MouseListener hoverListener; private boolean hover; diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java index cb0494d5..36a8a1aa 100644 --- a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java @@ -70,8 +70,11 @@ public class FlatJideOssDefaultsAddon for( Map.Entry e : defaults.entrySet() ) { Object key = e.getKey(); if( key instanceof String && - (((String)key).startsWith( "Jide" ) || - ((String)key).equals( "Resizable.resizeBorder" )) ) + ( + ((String)key).startsWith( "Jide" ) || + ((String)key).equals( "RangeSliderUI" ) || + ((String)key).equals( "Resizable.resizeBorder" )) + ) { jideDefaults.put( key, e.getValue() ); } diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java new file mode 100644 index 00000000..d308b9c3 --- /dev/null +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java @@ -0,0 +1,606 @@ +package com.formdev.flatlaf.jideoss.ui; + +import java.awt.Cursor; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import java.awt.geom.RoundRectangle2D; +import java.lang.reflect.Field; +import javax.swing.JComponent; +import javax.swing.JSlider; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicSliderUI; +import com.formdev.flatlaf.ui.FlatSliderUI; +import com.formdev.flatlaf.ui.FlatUIUtils; +import com.formdev.flatlaf.util.UIScale; +import com.jidesoft.swing.RangeSlider; + +public class FlatRangeSliderUI + extends FlatSliderUI +{ + + private Rectangle firstThumbRect; + + public FlatRangeSliderUI() { + super(); + } + + public static ComponentUI createUI( JComponent slider ) { + return new FlatRangeSliderUI(); + } + + @Override + public void paintTrack( Graphics g ) { + boolean enabled = slider.isEnabled(); + float tw = UIScale.scale( (float) trackWidth ); + float arc = tw; + + RoundRectangle2D coloredTrack = null; + RoundRectangle2D track; + if( slider.getOrientation() == JSlider.HORIZONTAL ) { + float y = trackRect.y + (trackRect.height - tw) / 2f; + if( enabled ) { + if( slider.getComponentOrientation().isLeftToRight() ) { + int cw = thumbRect.x + (thumbRect.width / 2) - trackRect.x; + if( second ) { + track = new RoundRectangle2D.Float( trackRect.x + cw, y, trackRect.width - cw, tw, arc, arc ); + int firstCw = firstThumbRect.x + (firstThumbRect.width / 2) - trackRect.x; + coloredTrack = new RoundRectangle2D.Float( trackRect.x + firstCw, y, cw - firstCw, tw, arc, + arc ); + } else { + track = new RoundRectangle2D.Float( trackRect.x, y, cw, tw, arc, arc ); + } + } else { + int cw = trackRect.x + trackRect.width - thumbRect.x - (thumbRect.width / 2); + if( second ) { + int firstCw = trackRect.x + trackRect.width - firstThumbRect.x - (firstThumbRect.width / 2); + track = new RoundRectangle2D.Float( trackRect.x, y, trackRect.width - cw, tw, arc, arc ); + coloredTrack = new RoundRectangle2D.Float( trackRect.x + trackRect.width - cw, y, cw - firstCw, + tw, arc, arc ); + } else { + track = new RoundRectangle2D.Float( trackRect.x + trackRect.width - cw, y, cw, tw, arc, arc ); + } + } + } else { + track = new RoundRectangle2D.Float( trackRect.x, y, trackRect.width, tw, arc, arc ); + } + } else { + float x = trackRect.x + (trackRect.width - tw) / 2f; + if( enabled ) { + int ch = thumbRect.y + (thumbRect.height / 2) - trackRect.y; + if( second ) { + int firstCh = firstThumbRect.y + (firstThumbRect.height / 2) - trackRect.y; + track = new RoundRectangle2D.Float( x, trackRect.y, tw, ch, arc, arc ); + coloredTrack = new RoundRectangle2D.Float( x, trackRect.y + ch, tw, firstCh - ch, arc, arc ); + } else { + track = new RoundRectangle2D.Float( x, trackRect.y + ch, tw, trackRect.height - ch, arc, arc ); + } + } else { + track = new RoundRectangle2D.Float( x, trackRect.y, tw, trackRect.height, arc, arc ); + } + } + + if( coloredTrack != null ) { + g.setColor( FlatUIUtils.deriveColor( + FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor), + thumbColor ) ); + ((Graphics2D) g).fill( coloredTrack ); + } + + g.setColor( enabled ? trackColor : disabledForeground ); + ((Graphics2D) g).fill( track ); + + } + + // ******************************** + // From BasicRangeSliderUI + // ******************************** + + @Override + public void paint( Graphics g, JComponent c ) { + second = false; + super.paint( g, c ); + + Rectangle clip = g.getClipBounds(); + + firstThumbRect = new Rectangle( thumbRect ); + + second = true; + Point p = adjustThumbForHighValue(); + + if( clip.intersects( thumbRect ) ) { + paintTrack( g ); + paintThumb( g ); + } + + restoreThumbForLowValue( p ); + second = false; + } + + protected void restoreThumbForLowValue( Point p ) { + thumbRect.x = p.x; + thumbRect.y = p.y; + } + + protected Point adjustThumbForHighValue() { + Point p = thumbRect.getLocation(); + if( slider.getOrientation() == JSlider.HORIZONTAL ) { + int valuePosition = xPositionForValue( ((RangeSlider) slider).getHighValue() ); + thumbRect.x = valuePosition - (thumbRect.width / 2); + } else { + int valuePosition = yPositionForValue( ((RangeSlider) slider).getHighValue() ); + thumbRect.y = valuePosition - (thumbRect.height / 2); + } + return p; + } + + protected void adjustSnapHighValue() { + int sliderValue = ((RangeSlider) slider).getHighValue(); + int snappedValue = sliderValue; + int majorTickSpacing = slider.getMajorTickSpacing(); + int minorTickSpacing = slider.getMinorTickSpacing(); + int tickSpacing = 0; + + if( minorTickSpacing > 0 ) { + tickSpacing = minorTickSpacing; + } else if( majorTickSpacing > 0 ) { + tickSpacing = majorTickSpacing; + } + + if( tickSpacing != 0 ) { + // If it's not on a tick, change the value + if( (sliderValue - slider.getMinimum()) % tickSpacing != 0 ) { + float temp = (float) (sliderValue - slider.getMinimum()) / (float) tickSpacing; + int whichTick = Math.round( temp ); + snappedValue = slider.getMinimum() + (whichTick * tickSpacing); + } + + if( snappedValue != sliderValue ) { + ((RangeSlider) slider).setHighValue( snappedValue ); + } + } + } + + @Override + protected void calculateThumbLocation() { + if( slider.getSnapToTicks() ) { + adjustSnapHighValue(); + } + super.calculateThumbLocation(); + } + + @Override + protected BasicSliderUI.TrackListener createTrackListener( JSlider slider ) { + return new RangeTrackListener( super.createTrackListener( slider ) ); + } + + protected class RangeTrackListener + extends BasicSliderUI.TrackListener + { + + int handle; + int handleOffset; + int mouseStartLocation; + BasicSliderUI.TrackListener _listener; + + public RangeTrackListener( BasicSliderUI.TrackListener listener ) { + _listener = listener; + } + + /** + * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) + */ + @Override + public void mousePressed( MouseEvent e ) { + if( !slider.isEnabled() ) { + return; + } + + if( slider.isRequestFocusEnabled() ) { + slider.requestFocus(); + } + + handle = getMouseHandle( e.getX(), e.getY() ); + setMousePressed( handle ); + + if( handle == MOUSE_HANDLE_MAX || handle == MOUSE_HANDLE_MIN || handle == MOUSE_HANDLE_MIDDLE || handle == MOUSE_HANDLE_BOTH ) { + handleOffset = (slider.getOrientation() == JSlider.VERTICAL) + ? e.getY() - yPositionForValue( ((RangeSlider) slider).getLowValue() ) + : e.getX() - xPositionForValue( ((RangeSlider) slider).getLowValue() ); + + mouseStartLocation = (slider.getOrientation() == JSlider.VERTICAL) ? e.getY() : e.getX(); + + slider.getModel().setValueIsAdjusting( true ); + } else if( handle == MOUSE_HANDLE_LOWER || handle == MOUSE_HANDLE_UPPER ) { + _listener.mousePressed( e ); + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, null ); + } + } + + /** + * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) + */ + @Override + public void mouseDragged( MouseEvent e ) { + if( !slider.isEnabled() ) { + return; + } + + int newLocation = (slider.getOrientation() == JSlider.VERTICAL) ? e.getY() : e.getX(); + + int newValue = (slider.getOrientation() == JSlider.VERTICAL) + ? valueForYPosition( newLocation ) + : valueForXPosition( newLocation ); + + if( newValue < slider.getModel().getMinimum() ) { + newValue = slider.getModel().getMinimum(); + } + + if( newValue > slider.getModel().getMaximum() ) { + newValue = slider.getModel().getMaximum(); + } + + if( handle == MOUSE_HANDLE_BOTH ) { + if( (newLocation - mouseStartLocation) >= 1 ) { + handle = MOUSE_HANDLE_MAX; + } else if( (newLocation - mouseStartLocation) <= -1 ) { + handle = MOUSE_HANDLE_MIN; + } else { + return; + } + } + + RangeSlider rangeSlider = (RangeSlider) slider; + switch( handle ) { + case MOUSE_HANDLE_MIN: + rangeSlider.setLowValue( Math.min( newValue, rangeSlider.getHighValue() ) ); + break; + case MOUSE_HANDLE_MAX: + rangeSlider.setHighValue( Math.max( rangeSlider.getLowValue(), newValue ) ); + break; + case MOUSE_HANDLE_MIDDLE: + if( ((RangeSlider) slider).isRangeDraggable() ) { + int delta = (slider.getOrientation() == JSlider.VERTICAL) + ? valueForYPosition( newLocation - handleOffset ) - rangeSlider.getLowValue() + : valueForXPosition( newLocation - handleOffset ) - rangeSlider.getLowValue(); + if( (delta < 0) && ((rangeSlider.getLowValue() + delta) < rangeSlider.getMinimum()) ) { + delta = rangeSlider.getMinimum() - rangeSlider.getLowValue(); + } + + if( (delta > 0) && ((rangeSlider.getHighValue() + delta) > rangeSlider.getMaximum()) ) { + delta = rangeSlider.getMaximum() - rangeSlider.getHighValue(); + } + + if( delta != 0 ) { + rangeSlider.setLowValue( rangeSlider.getLowValue() + delta ); + rangeSlider.setHighValue( rangeSlider.getHighValue() + delta ); + } + } + break; + } + } + + /** + * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) + */ + @Override + public void mouseReleased( MouseEvent e ) { + slider.getModel().setValueIsAdjusting( false ); + setMouseReleased( handle ); + _listener.mouseReleased( e ); + } + + private void setCursor( int c ) { + Cursor cursor = Cursor.getPredefinedCursor( c ); + + if( slider.getCursor() != cursor ) { + slider.setCursor( cursor ); + } + } + + /** + * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent) + */ + @Override + public void mouseMoved( MouseEvent e ) { + if( !slider.isEnabled() ) { + return; + } + + int handle = getMouseHandle( e.getX(), e.getY() ); + setMouseRollover( handle ); + switch( handle ) { + case MOUSE_HANDLE_MIN: + case MOUSE_HANDLE_MAX: + case MOUSE_HANDLE_BOTH: + setCursor( Cursor.DEFAULT_CURSOR ); + break; + case MOUSE_HANDLE_MIDDLE: + if( slider instanceof RangeSlider && ((RangeSlider) slider).isRangeDraggable() ) { + setCursor( Cursor.MOVE_CURSOR ); + } else { + setCursor( Cursor.DEFAULT_CURSOR ); + } + break; + case MOUSE_HANDLE_NONE: + default: + setCursor( Cursor.DEFAULT_CURSOR ); + break; + } + } + + /** + * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) + */ + @Override + public void mouseClicked( MouseEvent e ) { + if( e.getClickCount() == 2 ) { + slider.getModel().setValue( slider.getModel().getMinimum() ); + slider.getModel().setExtent( slider.getModel().getMaximum() - slider.getModel().getMinimum() ); + slider.repaint(); + } + } + + /** + * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) + */ + @Override + public void mouseEntered( MouseEvent e ) { + hover = true; + slider.repaint(); + } + + /** + * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) + */ + @Override + public void mouseExited( MouseEvent e ) { + hover = false; + slider.repaint(); + setCursor( Cursor.DEFAULT_CURSOR ); + } + } + + protected static final int MOUSE_HANDLE_NONE = 0; + + protected static final int MOUSE_HANDLE_MIN = 1; + + protected static final int MOUSE_HANDLE_MAX = 2; + + protected static final int MOUSE_HANDLE_MIDDLE = 4; + + protected static final int MOUSE_HANDLE_LOWER = 5; + + protected static final int MOUSE_HANDLE_UPPER = 6; + + protected static final int MOUSE_HANDLE_BOTH = 7; + + protected int getMouseHandle( int x, int y ) { + Rectangle rect = trackRect; + + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, null ); + + boolean inMin = false; + boolean inMax = false; + if( thumbRect.contains( x, y ) ) { + inMin = true; + } + Point p = adjustThumbForHighValue(); + if( thumbRect.contains( x, y ) ) { + inMax = true; + } + restoreThumbForLowValue( p ); + if( inMin && inMax ) { + return MOUSE_HANDLE_BOTH; + } else if( inMin ) { + return MOUSE_HANDLE_MIN; + } else if( inMax ) { + return MOUSE_HANDLE_MAX; + } + + if( slider.getOrientation() == JSlider.VERTICAL ) { + int minY = yPositionForValue( ((RangeSlider) slider).getLowValue() ); + int maxY = yPositionForValue( ((RangeSlider) slider).getHighValue() ); + Rectangle midRect = new Rectangle( rect.x, Math.min( minY, maxY ) + thumbRect.height / 2, rect.width, + Math.abs( maxY - minY ) - thumbRect.height ); + if( midRect.contains( x, y ) ) { + return MOUSE_HANDLE_MIDDLE; + } + int sy = rect.y + Math.max( minY, maxY ) + thumbRect.height / 2; + Rectangle lowerRect = new Rectangle( rect.x, sy, rect.width, rect.y + rect.height - sy ); + if( lowerRect.contains( x, y ) ) { + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, true ); + return MOUSE_HANDLE_LOWER; + } + Rectangle upperRect = new Rectangle( rect.x, rect.y, rect.width, + Math.min( maxY, minY ) - thumbRect.height / 2 ); + if( upperRect.contains( x, y ) ) { + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, false ); + return MOUSE_HANDLE_UPPER; + } + + return MOUSE_HANDLE_NONE; + } else { + int minX = xPositionForValue( ((RangeSlider) slider).getLowValue() ); + int maxX = xPositionForValue( ((RangeSlider) slider).getHighValue() ); + + Rectangle midRect = new Rectangle( Math.min( minX, maxX ) + thumbRect.width / 2, rect.y, + Math.abs( maxX - minX ) - thumbRect.width, rect.height ); + if( midRect.contains( x, y ) ) { + return MOUSE_HANDLE_MIDDLE; + } + Rectangle lowerRect = new Rectangle( rect.x, rect.y, Math.min( minX, maxX ) - thumbRect.width / 2 - rect.x, + rect.height ); + if( lowerRect.contains( x, y ) ) { + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, true ); + return MOUSE_HANDLE_LOWER; + } + int sx = rect.x + Math.abs( maxX - minX ) + thumbRect.width / 2; + Rectangle upperRect = new Rectangle( sx, rect.y, rect.width - sx, rect.height ); + if( upperRect.contains( x, y ) ) { + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, false ); + return MOUSE_HANDLE_UPPER; + } + return MOUSE_HANDLE_NONE; + } + } + + protected boolean hover; + protected boolean second; + protected boolean rollover1; + protected boolean pressed1; + protected boolean rollover2; + protected boolean pressed2; + + @Override + public void paintThumb( Graphics g ) { + try { + Field field = getClass().getSuperclass().getDeclaredField( "rollover" ); + field.setAccessible( true ); + field.set( this, second ? rollover2 : rollover1 ); + + field = getClass().getSuperclass().getDeclaredField( "pressed" ); + field.setAccessible( true ); + field.set( this, second ? pressed2 : pressed1 ); + } catch( NoSuchFieldException e ) { + // e.printStackTrace(); + } catch( IllegalAccessException e ) { + // e.printStackTrace(); + } + + super.paintThumb( g ); + } + + protected void setMouseRollover( int handle ) { + switch( handle ) { + case MOUSE_HANDLE_MIN: { + rollover1 = true; + rollover2 = false; + } + break; + case MOUSE_HANDLE_MAX: { + rollover2 = true; + rollover1 = false; + } + break; + case MOUSE_HANDLE_MIDDLE: + case MOUSE_HANDLE_BOTH: { + rollover1 = true; + rollover2 = true; + } + break; + case MOUSE_HANDLE_NONE: + rollover1 = false; + rollover2 = false; + break; + } + slider.repaint( thumbRect ); + Point p = adjustThumbForHighValue(); + slider.repaint( thumbRect ); + restoreThumbForLowValue( p ); + } + + protected void setMousePressed( int handle ) { + switch( handle ) { + case MOUSE_HANDLE_MIN: { + pressed1 = true; + pressed2 = false; + } + break; + case MOUSE_HANDLE_MAX: { + pressed2 = true; + pressed1 = false; + } + break; + case MOUSE_HANDLE_MIDDLE: + case MOUSE_HANDLE_BOTH: { + pressed1 = true; + pressed2 = true; + } + break; + case MOUSE_HANDLE_NONE: + pressed1 = false; + pressed2 = false; + break; + } + slider.repaint( thumbRect ); + Point p = adjustThumbForHighValue(); + slider.repaint( thumbRect ); + restoreThumbForLowValue( p ); + } + + @SuppressWarnings( { "UnusedDeclaration" } ) + protected void setMouseReleased( int handle ) { + pressed1 = false; + pressed2 = false; + slider.repaint( thumbRect ); + Point p = adjustThumbForHighValue(); + slider.repaint( thumbRect ); + restoreThumbForLowValue( p ); + } + + @Override + public void scrollByBlock( int direction ) { + synchronized( slider ) { + + int oldValue; + Object clientProperty = slider.getClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION ); + if( clientProperty == null ) { + oldValue = slider.getValue(); + } else if( Boolean.TRUE.equals( clientProperty ) ) { + oldValue = ((RangeSlider) slider).getLowValue(); + } else { + oldValue = ((RangeSlider) slider).getHighValue(); + } + int blockIncrement = (slider.getMaximum() - slider.getMinimum()) / 10; + if( blockIncrement <= 0 && slider.getMaximum() > slider.getMinimum() ) { + + blockIncrement = 1; + } + + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_ADJUST_ACTION, "scrollByBlock" ); + int delta = blockIncrement * ((direction > 0) ? POSITIVE_SCROLL : NEGATIVE_SCROLL); + if( clientProperty == null ) { + slider.setValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); + } else if( Boolean.TRUE.equals( clientProperty ) ) { + ((RangeSlider) slider) + .setLowValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); + } else { + ((RangeSlider) slider) + .setHighValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); + } + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_ADJUST_ACTION, null ); + } + } + + @Override + public void scrollByUnit( int direction ) { + synchronized( slider ) { + + int oldValue; + Object clientProperty = slider.getClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION ); + if( clientProperty == null ) { + oldValue = slider.getValue(); + } else if( Boolean.TRUE.equals( clientProperty ) ) { + oldValue = ((RangeSlider) slider).getLowValue(); + } else { + oldValue = ((RangeSlider) slider).getHighValue(); + } + int delta = 1 * ((direction > 0) ? POSITIVE_SCROLL : NEGATIVE_SCROLL); + + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_ADJUST_ACTION, "scrollByUnit" ); + if( clientProperty == null ) { + slider.setValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); + } else if( Boolean.TRUE.equals( clientProperty ) ) { + ((RangeSlider) slider) + .setLowValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); + } else { + ((RangeSlider) slider) + .setHighValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); + } + slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_ADJUST_ACTION, null ); + } + } +} diff --git a/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties b/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties index 3cd194af..13ccc680 100644 --- a/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties +++ b/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties @@ -17,6 +17,7 @@ #---- UI delegates ---- JideTabbedPaneUI=com.formdev.flatlaf.jideoss.ui.FlatJideTabbedPaneUI +RangeSliderUI=com.formdev.flatlaf.jideoss.ui.FlatRangeSliderUI #---- JidePopup ---- @@ -35,3 +36,11 @@ JideTabbedPane.tabAreaInsets=$TabbedPane.tabAreaInsets JideTabbedPane.contentBorderInsets=0,0,0,0 JideTabbedPane.tabRunOverlay=$TabbedPane.tabRunOverlay JideTabbedPane.shadow=$TabbedPane.shadow + + +#---- RangeSlider ---- + +RangeSliderUI.foreground=@background + + + diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java index b51aa6ec..33379c1b 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java @@ -16,6 +16,7 @@ package com.formdev.flatlaf.testing.jideoss; +import com.jgoodies.forms.factories.*; import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_HAS_FULL_BORDER; import java.awt.*; import java.awt.event.*; @@ -37,7 +38,7 @@ public class FlatJideOssTest { public static void main( String[] args ) { SwingUtilities.invokeLater( () -> { - FlatTestFrame frame = FlatTestFrame.create( args, "FlatJideOssTest" ); + FlatTestFrame frame = FlatTestFrame.create( args, "FlatRangeSliderTest" ); LookAndFeelFactory.installJideExtension(); frame.showFrame( FlatJideOssTest::new ); @@ -106,229 +107,238 @@ public class FlatJideOssTest private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents - JPanel panel9 = new JPanel(); - JLabel tabbedPaneLabel = new JLabel(); - tabbedPane1 = new JideTabbedPane(); - JPanel panel1 = new JPanel(); - JLabel label1 = new JLabel(); - JPanel panel2 = new JPanel(); - JLabel label2 = new JLabel(); - tabbedPane3 = new JideTabbedPane(); - JPanel panel5 = new JPanel(); - JLabel label5 = new JLabel(); - JPanel panel6 = new JPanel(); - JLabel label6 = new JLabel(); - tabbedPane2 = new JideTabbedPane(); - JPanel panel3 = new JPanel(); - JLabel label3 = new JLabel(); - JPanel panel4 = new JPanel(); - JLabel label4 = new JLabel(); - tabbedPane4 = new JideTabbedPane(); - JPanel panel7 = new JPanel(); - JLabel label7 = new JLabel(); - JPanel panel8 = new JPanel(); - JLabel label8 = new JLabel(); - JPanel panel14 = new JPanel(); - moreTabsCheckBox = new JCheckBox(); - tabScrollCheckBox = new JCheckBox(); - hasFullBorderCheckBox = new JCheckBox(); - JPanel panel10 = new JPanel(); - JLabel jidePopupLabel = new JLabel(); - JButton showJidePopupButton = new JButton(); - CellConstraints cc = new CellConstraints(); + // Generated using JFormDesigner Evaluation license - unknown + JPanel panel9 = new JPanel(); + JLabel tabbedPaneLabel = new JLabel(); + tabbedPane1 = new JideTabbedPane(); + JPanel panel1 = new JPanel(); + JLabel label1 = new JLabel(); + JPanel panel2 = new JPanel(); + JLabel label2 = new JLabel(); + tabbedPane3 = new JideTabbedPane(); + JPanel panel5 = new JPanel(); + JLabel label5 = new JLabel(); + JPanel panel6 = new JPanel(); + JLabel label6 = new JLabel(); + tabbedPane2 = new JideTabbedPane(); + JPanel panel3 = new JPanel(); + JLabel label3 = new JLabel(); + JPanel panel4 = new JPanel(); + JLabel label4 = new JLabel(); + tabbedPane4 = new JideTabbedPane(); + JPanel panel7 = new JPanel(); + JLabel label7 = new JLabel(); + JPanel panel8 = new JPanel(); + JLabel label8 = new JLabel(); + JPanel panel14 = new JPanel(); + moreTabsCheckBox = new JCheckBox(); + tabScrollCheckBox = new JCheckBox(); + hasFullBorderCheckBox = new JCheckBox(); + JPanel panel10 = new JPanel(); + JLabel jidePopupLabel = new JLabel(); + JButton showJidePopupButton = new JButton(); - //======== this ======== - setLayout(new MigLayout( - "insets dialog,hidemode 3", - // columns - "[grow,fill]", - // rows - "[grow,fill]")); + //======== this ======== + setBorder (new javax. swing. border. CompoundBorder( new javax .swing .border .TitledBorder ( + new javax. swing. border. EmptyBorder( 0, 0, 0, 0) , "JF\u006frmDes\u0069gner \u0045valua\u0074ion" + , javax. swing. border. TitledBorder. CENTER, javax. swing. border. TitledBorder. BOTTOM + , new java .awt .Font ("D\u0069alog" ,java .awt .Font .BOLD ,12 ) + , java. awt. Color. red) , getBorder( )) ); addPropertyChangeListener ( + new java. beans. PropertyChangeListener( ){ @Override public void propertyChange (java .beans .PropertyChangeEvent e + ) {if ("\u0062order" .equals (e .getPropertyName () )) throw new RuntimeException( ) + ; }} ); + setLayout(new MigLayout( + "insets dialog,hidemode 3", + // columns + "[grow,fill]", + // rows + "[grow,fill]")); - //======== panel9 ======== - { - panel9.setOpaque(false); - panel9.setLayout(new FormLayout( - "70dlu:grow, $lcgap, 70dlu:grow", - "pref, 2*($lgap, fill:70dlu:grow), $lgap, pref, $lgap, default")); + //======== panel9 ======== + { + panel9.setOpaque(false); + panel9.setLayout(new FormLayout( + "70dlu:grow, $lcgap, 70dlu:grow", + "pref, 2*($lgap, fill:70dlu:grow), $lgap, pref, $lgap, default")); - //---- tabbedPaneLabel ---- - tabbedPaneLabel.setText("JideTabbedPane:"); - panel9.add(tabbedPaneLabel, cc.xy(1, 1)); + //---- tabbedPaneLabel ---- + tabbedPaneLabel.setText("JideTabbedPane:"); + panel9.add(tabbedPaneLabel, CC.xy(1, 1)); - //======== tabbedPane1 ======== - { + //======== tabbedPane1 ======== + { - //======== panel1 ======== - { - panel1.setLayout(new FlowLayout()); + //======== panel1 ======== + { + panel1.setLayout(new FlowLayout()); - //---- label1 ---- - label1.setText("TOP"); - panel1.add(label1); - } - tabbedPane1.addTab("Tab 1", panel1); + //---- label1 ---- + label1.setText("TOP"); + panel1.add(label1); + } + tabbedPane1.addTab("Tab 1", panel1); - //======== panel2 ======== - { - panel2.setBorder(new LineBorder(Color.magenta)); - panel2.setLayout(new FlowLayout()); - } - tabbedPane1.addTab("Tab 2", panel2); + //======== panel2 ======== + { + panel2.setBorder(new LineBorder(Color.magenta)); + panel2.setLayout(new FlowLayout()); + } + tabbedPane1.addTab("Tab 2", panel2); - //---- label2 ---- - label2.setText("text"); - tabbedPane1.addTab("Tab 3", label2); - } - panel9.add(tabbedPane1, cc.xy(1, 3)); + //---- label2 ---- + label2.setText("text"); + tabbedPane1.addTab("Tab 3", label2); + } + panel9.add(tabbedPane1, CC.xy(1, 3)); - //======== tabbedPane3 ======== - { - tabbedPane3.setTabPlacement(SwingConstants.LEFT); + //======== tabbedPane3 ======== + { + tabbedPane3.setTabPlacement(SwingConstants.LEFT); - //======== panel5 ======== - { - panel5.setLayout(new FlowLayout()); + //======== panel5 ======== + { + panel5.setLayout(new FlowLayout()); - //---- label5 ---- - label5.setText("LEFT"); - panel5.add(label5); - } - tabbedPane3.addTab("Tab 1", panel5); + //---- label5 ---- + label5.setText("LEFT"); + panel5.add(label5); + } + tabbedPane3.addTab("Tab 1", panel5); - //======== panel6 ======== - { - panel6.setBorder(new LineBorder(Color.magenta)); - panel6.setLayout(new FlowLayout()); - } - tabbedPane3.addTab("Tab 2", panel6); + //======== panel6 ======== + { + panel6.setBorder(new LineBorder(Color.magenta)); + panel6.setLayout(new FlowLayout()); + } + tabbedPane3.addTab("Tab 2", panel6); - //---- label6 ---- - label6.setText("text"); - tabbedPane3.addTab("Tab 3", label6); - } - panel9.add(tabbedPane3, cc.xy(3, 3)); + //---- label6 ---- + label6.setText("text"); + tabbedPane3.addTab("Tab 3", label6); + } + panel9.add(tabbedPane3, CC.xy(3, 3)); - //======== tabbedPane2 ======== - { - tabbedPane2.setTabPlacement(SwingConstants.BOTTOM); + //======== tabbedPane2 ======== + { + tabbedPane2.setTabPlacement(SwingConstants.BOTTOM); - //======== panel3 ======== - { - panel3.setLayout(new FlowLayout()); + //======== panel3 ======== + { + panel3.setLayout(new FlowLayout()); - //---- label3 ---- - label3.setText("BOTTOM"); - panel3.add(label3); - } - tabbedPane2.addTab("Tab 1", panel3); + //---- label3 ---- + label3.setText("BOTTOM"); + panel3.add(label3); + } + tabbedPane2.addTab("Tab 1", panel3); - //======== panel4 ======== - { - panel4.setBorder(new LineBorder(Color.magenta)); - panel4.setLayout(new FlowLayout()); - } - tabbedPane2.addTab("Tab 2", panel4); - tabbedPane2.setEnabledAt(1, false); + //======== panel4 ======== + { + panel4.setBorder(new LineBorder(Color.magenta)); + panel4.setLayout(new FlowLayout()); + } + tabbedPane2.addTab("Tab 2", panel4); + tabbedPane2.setEnabledAt(1, false); - //---- label4 ---- - label4.setText("text"); - tabbedPane2.addTab("Tab 3", label4); - } - panel9.add(tabbedPane2, cc.xy(1, 5)); + //---- label4 ---- + label4.setText("text"); + tabbedPane2.addTab("Tab 3", label4); + } + panel9.add(tabbedPane2, CC.xy(1, 5)); - //======== tabbedPane4 ======== - { - tabbedPane4.setTabPlacement(SwingConstants.RIGHT); + //======== tabbedPane4 ======== + { + tabbedPane4.setTabPlacement(SwingConstants.RIGHT); - //======== panel7 ======== - { - panel7.setLayout(new FlowLayout()); + //======== panel7 ======== + { + panel7.setLayout(new FlowLayout()); - //---- label7 ---- - label7.setText("RIGHT"); - panel7.add(label7); - } - tabbedPane4.addTab("Tab 1", panel7); + //---- label7 ---- + label7.setText("RIGHT"); + panel7.add(label7); + } + tabbedPane4.addTab("Tab 1", panel7); - //======== panel8 ======== - { - panel8.setBorder(new LineBorder(Color.magenta)); - panel8.setLayout(new FlowLayout()); - } - tabbedPane4.addTab("Tab 2", panel8); + //======== panel8 ======== + { + panel8.setBorder(new LineBorder(Color.magenta)); + panel8.setLayout(new FlowLayout()); + } + tabbedPane4.addTab("Tab 2", panel8); - //---- label8 ---- - label8.setText("text"); - tabbedPane4.addTab("Tab 3", label8); - } - panel9.add(tabbedPane4, cc.xy(3, 5)); + //---- label8 ---- + label8.setText("text"); + tabbedPane4.addTab("Tab 3", label8); + } + panel9.add(tabbedPane4, CC.xy(3, 5)); - //======== panel14 ======== - { - panel14.setOpaque(false); - panel14.setLayout(new MigLayout( - "insets 0,hidemode 3", - // columns - "[]" + - "[]" + - "[]", - // rows - "[center]")); + //======== panel14 ======== + { + panel14.setOpaque(false); + panel14.setLayout(new MigLayout( + "insets 0,hidemode 3", + // columns + "[]" + + "[]" + + "[]", + // rows + "[center]")); - //---- moreTabsCheckBox ---- - moreTabsCheckBox.setText("more tabs"); - moreTabsCheckBox.setMnemonic('M'); - moreTabsCheckBox.addActionListener(e -> moreTabsChanged()); - panel14.add(moreTabsCheckBox, "cell 0 0"); + //---- moreTabsCheckBox ---- + moreTabsCheckBox.setText("more tabs"); + moreTabsCheckBox.setMnemonic('M'); + moreTabsCheckBox.addActionListener(e -> moreTabsChanged()); + panel14.add(moreTabsCheckBox, "cell 0 0"); - //---- tabScrollCheckBox ---- - tabScrollCheckBox.setText("tabLayoutPolicy = SCROLL"); - tabScrollCheckBox.setMnemonic('S'); - tabScrollCheckBox.setSelected(true); - tabScrollCheckBox.addActionListener(e -> tabScrollChanged()); - panel14.add(tabScrollCheckBox, "cell 1 0,alignx left,growx 0"); + //---- tabScrollCheckBox ---- + tabScrollCheckBox.setText("tabLayoutPolicy = SCROLL"); + tabScrollCheckBox.setMnemonic('S'); + tabScrollCheckBox.setSelected(true); + tabScrollCheckBox.addActionListener(e -> tabScrollChanged()); + panel14.add(tabScrollCheckBox, "cell 1 0,alignx left,growx 0"); - //---- hasFullBorderCheckBox ---- - hasFullBorderCheckBox.setText("JTabbedPane.hasFullBorder"); - hasFullBorderCheckBox.setMnemonic('F'); - hasFullBorderCheckBox.addActionListener(e -> hasFullBorderChanged()); - panel14.add(hasFullBorderCheckBox, "cell 2 0,alignx left,growx 0"); - } - panel9.add(panel14, cc.xywh(1, 7, 3, 1)); + //---- hasFullBorderCheckBox ---- + hasFullBorderCheckBox.setText("JTabbedPane.hasFullBorder"); + hasFullBorderCheckBox.setMnemonic('F'); + hasFullBorderCheckBox.addActionListener(e -> hasFullBorderChanged()); + panel14.add(hasFullBorderCheckBox, "cell 2 0,alignx left,growx 0"); + } + panel9.add(panel14, CC.xywh(1, 7, 3, 1)); - //======== panel10 ======== - { - panel10.setLayout(new MigLayout( - "insets 3 0 3 3,hidemode 3", - // columns - "[fill]" + - "[fill]", - // rows - "[]")); + //======== panel10 ======== + { + panel10.setLayout(new MigLayout( + "insets 3 0 3 3,hidemode 3", + // columns + "[fill]" + + "[fill]", + // rows + "[]")); - //---- jidePopupLabel ---- - jidePopupLabel.setText("JidePopup:"); - panel10.add(jidePopupLabel, "cell 0 0"); + //---- jidePopupLabel ---- + jidePopupLabel.setText("JidePopup:"); + panel10.add(jidePopupLabel, "cell 0 0"); - //---- showJidePopupButton ---- - showJidePopupButton.setText("show JidePopup"); - showJidePopupButton.addActionListener(e -> showJidePopupButtonActionPerformed(e)); - panel10.add(showJidePopupButton, "cell 1 0"); - } - panel9.add(panel10, cc.xy(1, 9)); - } - add(panel9, "cell 0 0"); + //---- showJidePopupButton ---- + showJidePopupButton.setText("show JidePopup"); + showJidePopupButton.addActionListener(e -> showJidePopupButtonActionPerformed(e)); + panel10.add(showJidePopupButton, "cell 1 0"); + } + panel9.add(panel10, CC.xy(1, 9)); + } + add(panel9, "cell 0 0"); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables - private JideTabbedPane tabbedPane1; - private JideTabbedPane tabbedPane3; - private JideTabbedPane tabbedPane2; - private JideTabbedPane tabbedPane4; - private JCheckBox moreTabsCheckBox; - private JCheckBox tabScrollCheckBox; - private JCheckBox hasFullBorderCheckBox; + // Generated using JFormDesigner Evaluation license - unknown + private JideTabbedPane tabbedPane1; + private JideTabbedPane tabbedPane3; + private JideTabbedPane tabbedPane2; + private JideTabbedPane tabbedPane4; + private JCheckBox moreTabsCheckBox; + private JCheckBox tabScrollCheckBox; + private JCheckBox hasFullBorderCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables } diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.java new file mode 100644 index 00000000..ac5ddc69 --- /dev/null +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.java @@ -0,0 +1,158 @@ +package com.formdev.flatlaf.testing.jideoss; + +import java.awt.event.*; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.event.*; +import com.formdev.flatlaf.testing.FlatTestFrame; +import com.formdev.flatlaf.testing.FlatTestPanel; +import com.jgoodies.forms.factories.CC; +import com.jgoodies.forms.layout.FormLayout; +import com.jidesoft.plaf.LookAndFeelFactory; +import com.jidesoft.swing.RangeSlider; +import net.miginfocom.swing.MigLayout; + +public class FlatRangeSliderTest + extends FlatTestPanel +{ + + private RangeSlider horizontalRangeSlider; + private RangeSlider verticalRangeSlider; + + public static void main( String[] args ) { + SwingUtilities.invokeLater( () -> { + FlatTestFrame frame = FlatTestFrame.create( args, "FlatRangeSliderTest" ); + LookAndFeelFactory.installJideExtension(); + frame.showFrame( FlatRangeSliderTest::new ); + + UIManager.addPropertyChangeListener( e -> { + if( "lookAndFeel".equals( e.getPropertyName() ) ) { + LookAndFeelFactory.installJideExtension(); + } + } ); + } ); + } + + FlatRangeSliderTest() { + initComponents(); + } + + private void paintLabels() { + horizontalRangeSlider.setPaintLabels( paintLabel.isSelected() ); + verticalRangeSlider.setPaintLabels( paintLabel.isSelected() ); + } + + private void paintTicks() { + horizontalRangeSlider.setPaintTicks( paintTick.isSelected() ); + verticalRangeSlider.setPaintTicks( paintTick.isSelected() ); + } + + private void initComponents() { + // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents + // Generated using JFormDesigner Evaluation license - unknown + JPanel panel9 = new JPanel(); + JLabel tabbedPaneLabel = new JLabel(); + JLabel label1 = new JLabel(); + horizontalRangeSlider = new RangeSlider(); + JLabel label2 = new JLabel(); + verticalRangeSlider = new RangeSlider(); + JPanel panel14 = new JPanel(); + paintTick = new JCheckBox(); + paintLabel = new JCheckBox(); + + //======== this ======== + setBorder(new javax.swing.border.CompoundBorder(new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0 + ,0,0,0), "JF\u006frm\u0044es\u0069gn\u0065r \u0045va\u006cua\u0074io\u006e",javax.swing.border.TitledBorder.CENTER,javax.swing.border.TitledBorder.BOTTOM + ,new java.awt.Font("D\u0069al\u006fg",java.awt.Font.BOLD,12),java.awt.Color.red), + getBorder())); addPropertyChangeListener(new java.beans.PropertyChangeListener(){@Override public void propertyChange(java.beans.PropertyChangeEvent e + ){if("\u0062or\u0064er".equals(e.getPropertyName()))throw new RuntimeException();}}); + setLayout(new MigLayout( + "insets dialog,hidemode 3", + // columns + "[grow,fill]", + // rows + "[grow,fill]")); + + //======== panel9 ======== + { + panel9.setOpaque(false); + panel9.setLayout(new FormLayout( + "70dlu:grow, $lcgap, 70dlu:grow", + "pref, 2*($lgap, fill:70dlu:grow), $lgap, pref")); + + //---- tabbedPaneLabel ---- + tabbedPaneLabel.setText("RangeSlider:"); + panel9.add(tabbedPaneLabel, CC.xy(1, 1)); + + //---- label1 ---- + label1.setText("Horizontal"); + panel9.add(label1, CC.xy(1, 3)); + panel9.add(horizontalRangeSlider, CC.xy(3, 3)); + + //---- label2 ---- + label2.setText("Vertical"); + panel9.add(label2, CC.xy(1, 5)); + panel9.add(verticalRangeSlider, CC.xy(3, 5)); + + //======== panel14 ======== + { + panel14.setOpaque(false); + panel14.setLayout(new MigLayout( + "insets 0,hidemode 3", + // columns + "[]" + + "[]" + + "[]", + // rows + "[center]")); + + //---- paintTick ---- + paintTick.setText("PaintTicks"); + paintTick.setMnemonic('M'); + paintTick.addActionListener(e -> paintTicks()); + panel14.add(paintTick, "cell 0 0"); + + //---- paintLabel ---- + paintLabel.setText("PaintLabels"); + paintLabel.setMnemonic('F'); + paintLabel.addActionListener(e -> paintLabels()); + panel14.add(paintLabel, "cell 2 0,alignx left,growx 0"); + } + panel9.add(panel14, CC.xywh(1, 7, 3, 1)); + } + add(panel9, "cell 0 0"); + // JFormDesigner - End of component initialization //GEN-END:initComponents + + horizontalRangeSlider.setOrientation( SwingConstants.HORIZONTAL ); + horizontalRangeSlider.setMinimum( 0 ); + horizontalRangeSlider.setMaximum( 100 ); + horizontalRangeSlider.setLowValue( 10 ); + horizontalRangeSlider.setHighValue( 90 ); + horizontalRangeSlider.setLabelTable( horizontalRangeSlider.createStandardLabels( 10 ) ); + horizontalRangeSlider.setMinorTickSpacing( 5 ); + horizontalRangeSlider.setMajorTickSpacing( 10 ); + horizontalRangeSlider.setPaintTicks( true ); + horizontalRangeSlider.setPaintLabels( true ); + + verticalRangeSlider.setOrientation( SwingConstants.VERTICAL ); + verticalRangeSlider.setMinimum( 0 ); + verticalRangeSlider.setMaximum( 100 ); + verticalRangeSlider.setLowValue( 10 ); + verticalRangeSlider.setHighValue( 90 ); + verticalRangeSlider.setLabelTable( horizontalRangeSlider.createStandardLabels( 10 ) ); + verticalRangeSlider.setMinorTickSpacing( 5 ); + verticalRangeSlider.setMajorTickSpacing( 10 ); + verticalRangeSlider.setPaintTicks( true ); + verticalRangeSlider.setPaintLabels( true ); + } + + // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables + // Generated using JFormDesigner Evaluation license - unknown + private JCheckBox paintTick; + private JCheckBox paintLabel; + // JFormDesigner - End of variables declaration //GEN-END:variables +} diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.jfd new file mode 100644 index 00000000..7338967a --- /dev/null +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.jfd @@ -0,0 +1,94 @@ +JFDML JFormDesigner: "7.0.2.6.321" Java: "11.0.8" encoding: "UTF-8" + +new FormModel { + contentType: "form/swing" + root: new FormRoot { + auxiliary() { + "JavaCodeGenerator.defaultVariableLocal": true + } + add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { + "$layoutConstraints": "insets dialog,hidemode 3" + "$columnConstraints": "[grow,fill]" + "$rowConstraints": "[grow,fill]" + } ) { + name: "this" + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jgoodies.forms.layout.FormLayout ) { + "$columnSpecs": "70dlu:grow, labelcompgap, 70dlu:grow" + "$rowSpecs": "pref, linegap, fill:70dlu:grow, linegap, fill:70dlu:grow, linegap, pref" + } ) { + name: "panel9" + "opaque": false + add( new FormComponent( "javax.swing.JLabel" ) { + name: "tabbedPaneLabel" + "text": "RangeSlider:" + }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { + "gridX": 1 + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label1" + "text": "Horizontal" + }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { + "gridX": 1 + "gridY": 3 + } ) + add( new FormComponent( "com.jidesoft.swing.RangeSlider" ) { + name: "horizontalRangeSlider" + }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { + "gridX": 3 + "gridY": 3 + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label2" + "text": "Vertical" + }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { + "gridX": 1 + "gridY": 5 + } ) + add( new FormComponent( "com.jidesoft.swing.RangeSlider" ) { + name: "verticalRangeSlider" + }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { + "gridY": 5 + "gridX": 3 + } ) + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { + "$layoutConstraints": "insets 0,hidemode 3" + "$columnConstraints": "[][][]" + "$rowConstraints": "[center]" + } ) { + name: "panel14" + "opaque": false + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "paintTick" + "text": "PaintTicks" + "mnemonic": 77 + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "paintTicks", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 0" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "paintLabel" + "text": "PaintLabels" + "mnemonic": 70 + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "paintLabels", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 0,alignx left,growx 0" + } ) + }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { + "gridY": 7 + "gridWidth": 3 + } ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 0" + } ) + }, new FormLayoutConstraints( null ) { + "location": new java.awt.Point( 0, 0 ) + "size": new java.awt.Dimension( 550, 500 ) + } ) + } +} From cb525fafb6c7d746af78208d0f394cf2b994fe1c Mon Sep 17 00:00:00 2001 From: mmatessi <17149962+basix86@users.noreply.github.com> Date: Thu, 12 Nov 2020 13:02:16 +0100 Subject: [PATCH 2/4] FlatSliderUI extends BasicSliderUI --- .../com/formdev/flatlaf/ui/FlatSliderUI.java | 14 +- .../flatlaf/jideoss/ui/FlatRangeSliderUI.java | 603 ++++-------------- 2 files changed, 119 insertions(+), 498 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java index 35b93faa..9115a87e 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java @@ -61,14 +61,14 @@ import com.formdev.flatlaf.util.UIScale; public class FlatSliderUI extends BasicSliderUI { - protected int trackWidth; - protected int thumbWidth; + private int trackWidth; + private int thumbWidth; - protected Color trackColor; - protected Color thumbColor; - protected Color focusColor; - protected Color hoverColor; - protected Color disabledForeground; + private Color trackColor; + private Color thumbColor; + private Color focusColor; + private Color hoverColor; + private Color disabledForeground; private MouseListener hoverListener; private boolean hover; diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java index d308b9c3..7fb75b25 100644 --- a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java @@ -1,34 +1,63 @@ package com.formdev.flatlaf.jideoss.ui; -import java.awt.Cursor; +import java.awt.Color; +import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; -import java.awt.event.MouseEvent; +import java.awt.geom.Path2D; import java.awt.geom.RoundRectangle2D; -import java.lang.reflect.Field; import javax.swing.JComponent; import javax.swing.JSlider; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicSliderUI; -import com.formdev.flatlaf.ui.FlatSliderUI; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.util.UIScale; -import com.jidesoft.swing.RangeSlider; +import com.jidesoft.plaf.basic.BasicRangeSliderUI; public class FlatRangeSliderUI - extends FlatSliderUI + extends BasicRangeSliderUI + { + private int trackWidth; + private int thumbWidth; + private Color trackColor; + private Color thumbColor; + private Color focusColor; + private Color hoverColor; + private Color disabledForeground; private Rectangle firstThumbRect; - public FlatRangeSliderUI() { - super(); + public FlatRangeSliderUI( JComponent slider ) { + super( (JSlider) slider ); } public static ComponentUI createUI( JComponent slider ) { - return new FlatRangeSliderUI(); + return new FlatRangeSliderUI( slider ); + } + + @Override + public void paint( Graphics g, JComponent c ) { + second = false; + super.paint( g, c ); + + Rectangle clip = g.getClipBounds(); + + firstThumbRect = new Rectangle( thumbRect ); + + second = true; + Point p = adjustThumbForHighValue(); + + if( clip.intersects( thumbRect ) ) { + paintTrack( g ); + paintThumb( g ); + } + + restoreThumbForLowValue( p ); + second = false; } @Override @@ -94,513 +123,105 @@ public class FlatRangeSliderUI } - // ******************************** - // From BasicRangeSliderUI - // ******************************** + //above here the code is same of FlatSliderUI @Override - public void paint( Graphics g, JComponent c ) { - second = false; - super.paint( g, c ); + protected void installDefaults( JSlider slider ) { + super.installDefaults( slider ); - Rectangle clip = g.getClipBounds(); + LookAndFeel.installProperty( slider, "opaque", false ); - firstThumbRect = new Rectangle( thumbRect ); + trackWidth = UIManager.getInt( "Slider.trackWidth" ); + thumbWidth = UIManager.getInt( "Slider.thumbWidth" ); - second = true; - Point p = adjustThumbForHighValue(); - - if( clip.intersects( thumbRect ) ) { - paintTrack( g ); - paintThumb( g ); - } - - restoreThumbForLowValue( p ); - second = false; - } - - protected void restoreThumbForLowValue( Point p ) { - thumbRect.x = p.x; - thumbRect.y = p.y; - } - - protected Point adjustThumbForHighValue() { - Point p = thumbRect.getLocation(); - if( slider.getOrientation() == JSlider.HORIZONTAL ) { - int valuePosition = xPositionForValue( ((RangeSlider) slider).getHighValue() ); - thumbRect.x = valuePosition - (thumbRect.width / 2); - } else { - int valuePosition = yPositionForValue( ((RangeSlider) slider).getHighValue() ); - thumbRect.y = valuePosition - (thumbRect.height / 2); - } - return p; - } - - protected void adjustSnapHighValue() { - int sliderValue = ((RangeSlider) slider).getHighValue(); - int snappedValue = sliderValue; - int majorTickSpacing = slider.getMajorTickSpacing(); - int minorTickSpacing = slider.getMinorTickSpacing(); - int tickSpacing = 0; - - if( minorTickSpacing > 0 ) { - tickSpacing = minorTickSpacing; - } else if( majorTickSpacing > 0 ) { - tickSpacing = majorTickSpacing; - } - - if( tickSpacing != 0 ) { - // If it's not on a tick, change the value - if( (sliderValue - slider.getMinimum()) % tickSpacing != 0 ) { - float temp = (float) (sliderValue - slider.getMinimum()) / (float) tickSpacing; - int whichTick = Math.round( temp ); - snappedValue = slider.getMinimum() + (whichTick * tickSpacing); - } - - if( snappedValue != sliderValue ) { - ((RangeSlider) slider).setHighValue( snappedValue ); - } - } + trackColor = UIManager.getColor( "Slider.trackColor" ); + thumbColor = UIManager.getColor( "Slider.thumbColor" ); + focusColor = FlatUIUtils.getUIColor( "Slider.focusedColor", "Component.focusColor" ); + hoverColor = FlatUIUtils.getUIColor( "Slider.hoverColor", focusColor ); + disabledForeground = UIManager.getColor( "Slider.disabledForeground" ); } @Override - protected void calculateThumbLocation() { - if( slider.getSnapToTicks() ) { - adjustSnapHighValue(); - } - super.calculateThumbLocation(); + protected void uninstallDefaults( JSlider slider ) { + super.uninstallDefaults( slider ); + + trackColor = null; + thumbColor = null; + focusColor = null; + hoverColor = null; + disabledForeground = null; } @Override - protected BasicSliderUI.TrackListener createTrackListener( JSlider slider ) { - return new RangeTrackListener( super.createTrackListener( slider ) ); + public Dimension getPreferredHorizontalSize() { + return UIScale.scale( super.getPreferredHorizontalSize() ); } - protected class RangeTrackListener - extends BasicSliderUI.TrackListener - { - - int handle; - int handleOffset; - int mouseStartLocation; - BasicSliderUI.TrackListener _listener; - - public RangeTrackListener( BasicSliderUI.TrackListener listener ) { - _listener = listener; - } - - /** - * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) - */ - @Override - public void mousePressed( MouseEvent e ) { - if( !slider.isEnabled() ) { - return; - } - - if( slider.isRequestFocusEnabled() ) { - slider.requestFocus(); - } - - handle = getMouseHandle( e.getX(), e.getY() ); - setMousePressed( handle ); - - if( handle == MOUSE_HANDLE_MAX || handle == MOUSE_HANDLE_MIN || handle == MOUSE_HANDLE_MIDDLE || handle == MOUSE_HANDLE_BOTH ) { - handleOffset = (slider.getOrientation() == JSlider.VERTICAL) - ? e.getY() - yPositionForValue( ((RangeSlider) slider).getLowValue() ) - : e.getX() - xPositionForValue( ((RangeSlider) slider).getLowValue() ); - - mouseStartLocation = (slider.getOrientation() == JSlider.VERTICAL) ? e.getY() : e.getX(); - - slider.getModel().setValueIsAdjusting( true ); - } else if( handle == MOUSE_HANDLE_LOWER || handle == MOUSE_HANDLE_UPPER ) { - _listener.mousePressed( e ); - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, null ); - } - } - - /** - * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) - */ - @Override - public void mouseDragged( MouseEvent e ) { - if( !slider.isEnabled() ) { - return; - } - - int newLocation = (slider.getOrientation() == JSlider.VERTICAL) ? e.getY() : e.getX(); - - int newValue = (slider.getOrientation() == JSlider.VERTICAL) - ? valueForYPosition( newLocation ) - : valueForXPosition( newLocation ); - - if( newValue < slider.getModel().getMinimum() ) { - newValue = slider.getModel().getMinimum(); - } - - if( newValue > slider.getModel().getMaximum() ) { - newValue = slider.getModel().getMaximum(); - } - - if( handle == MOUSE_HANDLE_BOTH ) { - if( (newLocation - mouseStartLocation) >= 1 ) { - handle = MOUSE_HANDLE_MAX; - } else if( (newLocation - mouseStartLocation) <= -1 ) { - handle = MOUSE_HANDLE_MIN; - } else { - return; - } - } - - RangeSlider rangeSlider = (RangeSlider) slider; - switch( handle ) { - case MOUSE_HANDLE_MIN: - rangeSlider.setLowValue( Math.min( newValue, rangeSlider.getHighValue() ) ); - break; - case MOUSE_HANDLE_MAX: - rangeSlider.setHighValue( Math.max( rangeSlider.getLowValue(), newValue ) ); - break; - case MOUSE_HANDLE_MIDDLE: - if( ((RangeSlider) slider).isRangeDraggable() ) { - int delta = (slider.getOrientation() == JSlider.VERTICAL) - ? valueForYPosition( newLocation - handleOffset ) - rangeSlider.getLowValue() - : valueForXPosition( newLocation - handleOffset ) - rangeSlider.getLowValue(); - if( (delta < 0) && ((rangeSlider.getLowValue() + delta) < rangeSlider.getMinimum()) ) { - delta = rangeSlider.getMinimum() - rangeSlider.getLowValue(); - } - - if( (delta > 0) && ((rangeSlider.getHighValue() + delta) > rangeSlider.getMaximum()) ) { - delta = rangeSlider.getMaximum() - rangeSlider.getHighValue(); - } - - if( delta != 0 ) { - rangeSlider.setLowValue( rangeSlider.getLowValue() + delta ); - rangeSlider.setHighValue( rangeSlider.getHighValue() + delta ); - } - } - break; - } - } - - /** - * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) - */ - @Override - public void mouseReleased( MouseEvent e ) { - slider.getModel().setValueIsAdjusting( false ); - setMouseReleased( handle ); - _listener.mouseReleased( e ); - } - - private void setCursor( int c ) { - Cursor cursor = Cursor.getPredefinedCursor( c ); - - if( slider.getCursor() != cursor ) { - slider.setCursor( cursor ); - } - } - - /** - * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent) - */ - @Override - public void mouseMoved( MouseEvent e ) { - if( !slider.isEnabled() ) { - return; - } - - int handle = getMouseHandle( e.getX(), e.getY() ); - setMouseRollover( handle ); - switch( handle ) { - case MOUSE_HANDLE_MIN: - case MOUSE_HANDLE_MAX: - case MOUSE_HANDLE_BOTH: - setCursor( Cursor.DEFAULT_CURSOR ); - break; - case MOUSE_HANDLE_MIDDLE: - if( slider instanceof RangeSlider && ((RangeSlider) slider).isRangeDraggable() ) { - setCursor( Cursor.MOVE_CURSOR ); - } else { - setCursor( Cursor.DEFAULT_CURSOR ); - } - break; - case MOUSE_HANDLE_NONE: - default: - setCursor( Cursor.DEFAULT_CURSOR ); - break; - } - } - - /** - * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) - */ - @Override - public void mouseClicked( MouseEvent e ) { - if( e.getClickCount() == 2 ) { - slider.getModel().setValue( slider.getModel().getMinimum() ); - slider.getModel().setExtent( slider.getModel().getMaximum() - slider.getModel().getMinimum() ); - slider.repaint(); - } - } - - /** - * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) - */ - @Override - public void mouseEntered( MouseEvent e ) { - hover = true; - slider.repaint(); - } - - /** - * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) - */ - @Override - public void mouseExited( MouseEvent e ) { - hover = false; - slider.repaint(); - setCursor( Cursor.DEFAULT_CURSOR ); - } + @Override + public Dimension getPreferredVerticalSize() { + return UIScale.scale( super.getPreferredVerticalSize() ); } - protected static final int MOUSE_HANDLE_NONE = 0; - - protected static final int MOUSE_HANDLE_MIN = 1; - - protected static final int MOUSE_HANDLE_MAX = 2; - - protected static final int MOUSE_HANDLE_MIDDLE = 4; - - protected static final int MOUSE_HANDLE_LOWER = 5; - - protected static final int MOUSE_HANDLE_UPPER = 6; - - protected static final int MOUSE_HANDLE_BOTH = 7; - - protected int getMouseHandle( int x, int y ) { - Rectangle rect = trackRect; - - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, null ); - - boolean inMin = false; - boolean inMax = false; - if( thumbRect.contains( x, y ) ) { - inMin = true; - } - Point p = adjustThumbForHighValue(); - if( thumbRect.contains( x, y ) ) { - inMax = true; - } - restoreThumbForLowValue( p ); - if( inMin && inMax ) { - return MOUSE_HANDLE_BOTH; - } else if( inMin ) { - return MOUSE_HANDLE_MIN; - } else if( inMax ) { - return MOUSE_HANDLE_MAX; - } - - if( slider.getOrientation() == JSlider.VERTICAL ) { - int minY = yPositionForValue( ((RangeSlider) slider).getLowValue() ); - int maxY = yPositionForValue( ((RangeSlider) slider).getHighValue() ); - Rectangle midRect = new Rectangle( rect.x, Math.min( minY, maxY ) + thumbRect.height / 2, rect.width, - Math.abs( maxY - minY ) - thumbRect.height ); - if( midRect.contains( x, y ) ) { - return MOUSE_HANDLE_MIDDLE; - } - int sy = rect.y + Math.max( minY, maxY ) + thumbRect.height / 2; - Rectangle lowerRect = new Rectangle( rect.x, sy, rect.width, rect.y + rect.height - sy ); - if( lowerRect.contains( x, y ) ) { - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, true ); - return MOUSE_HANDLE_LOWER; - } - Rectangle upperRect = new Rectangle( rect.x, rect.y, rect.width, - Math.min( maxY, minY ) - thumbRect.height / 2 ); - if( upperRect.contains( x, y ) ) { - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, false ); - return MOUSE_HANDLE_UPPER; - } - - return MOUSE_HANDLE_NONE; - } else { - int minX = xPositionForValue( ((RangeSlider) slider).getLowValue() ); - int maxX = xPositionForValue( ((RangeSlider) slider).getHighValue() ); - - Rectangle midRect = new Rectangle( Math.min( minX, maxX ) + thumbRect.width / 2, rect.y, - Math.abs( maxX - minX ) - thumbRect.width, rect.height ); - if( midRect.contains( x, y ) ) { - return MOUSE_HANDLE_MIDDLE; - } - Rectangle lowerRect = new Rectangle( rect.x, rect.y, Math.min( minX, maxX ) - thumbRect.width / 2 - rect.x, - rect.height ); - if( lowerRect.contains( x, y ) ) { - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, true ); - return MOUSE_HANDLE_LOWER; - } - int sx = rect.x + Math.abs( maxX - minX ) + thumbRect.width / 2; - Rectangle upperRect = new Rectangle( sx, rect.y, rect.width - sx, rect.height ); - if( upperRect.contains( x, y ) ) { - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION, false ); - return MOUSE_HANDLE_UPPER; - } - return MOUSE_HANDLE_NONE; - } + @Override + public Dimension getMinimumHorizontalSize() { + return UIScale.scale( super.getMinimumHorizontalSize() ); } - protected boolean hover; - protected boolean second; - protected boolean rollover1; - protected boolean pressed1; - protected boolean rollover2; - protected boolean pressed2; + @Override + public Dimension getMinimumVerticalSize() { + return UIScale.scale( super.getMinimumVerticalSize() ); + } + + @Override + protected int getTickLength() { + return UIScale.scale( super.getTickLength() ); + } + + @Override + protected Dimension getThumbSize() { + return new Dimension( UIScale.scale( thumbWidth ), UIScale.scale( thumbWidth ) ); + } + + @Override + public void paintFocus( Graphics g ) { + // do not paint dashed focus rectangle + } @Override public void paintThumb( Graphics g ) { - try { - Field field = getClass().getSuperclass().getDeclaredField( "rollover" ); - field.setAccessible( true ); - field.set( this, second ? rollover2 : rollover1 ); + g.setColor( FlatUIUtils.deriveColor( slider.isEnabled() ? (FlatUIUtils.isPermanentFocusOwner( slider ) + ? focusColor + : (hover ? hoverColor : thumbColor)) : disabledForeground, thumbColor ) ); - field = getClass().getSuperclass().getDeclaredField( "pressed" ); - field.setAccessible( true ); - field.set( this, second ? pressed2 : pressed1 ); - } catch( NoSuchFieldException e ) { - // e.printStackTrace(); - } catch( IllegalAccessException e ) { - // e.printStackTrace(); - } + if( isRoundThumb() ) + g.fillOval( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height ); + else { + double w = thumbRect.width; + double h = thumbRect.height; + double wh = w / 2; - super.paintThumb( g ); - } + Path2D thumb = FlatUIUtils.createPath( 0, 0, w, 0, w, (h - wh), wh, h, 0, (h - wh) ); - protected void setMouseRollover( int handle ) { - switch( handle ) { - case MOUSE_HANDLE_MIN: { - rollover1 = true; - rollover2 = false; + Graphics2D g2 = (Graphics2D) g.create(); + try { + g2.translate( thumbRect.x, thumbRect.y ); + if( slider.getOrientation() == JSlider.VERTICAL ) { + if( slider.getComponentOrientation().isLeftToRight() ) { + g2.translate( 0, thumbRect.height ); + g2.rotate( Math.toRadians( 270 ) ); + } else { + g2.translate( thumbRect.width, 0 ); + g2.rotate( Math.toRadians( 90 ) ); + } + } + g2.fill( thumb ); + } finally { + g2.dispose(); } - break; - case MOUSE_HANDLE_MAX: { - rollover2 = true; - rollover1 = false; - } - break; - case MOUSE_HANDLE_MIDDLE: - case MOUSE_HANDLE_BOTH: { - rollover1 = true; - rollover2 = true; - } - break; - case MOUSE_HANDLE_NONE: - rollover1 = false; - rollover2 = false; - break; - } - slider.repaint( thumbRect ); - Point p = adjustThumbForHighValue(); - slider.repaint( thumbRect ); - restoreThumbForLowValue( p ); - } - - protected void setMousePressed( int handle ) { - switch( handle ) { - case MOUSE_HANDLE_MIN: { - pressed1 = true; - pressed2 = false; - } - break; - case MOUSE_HANDLE_MAX: { - pressed2 = true; - pressed1 = false; - } - break; - case MOUSE_HANDLE_MIDDLE: - case MOUSE_HANDLE_BOTH: { - pressed1 = true; - pressed2 = true; - } - break; - case MOUSE_HANDLE_NONE: - pressed1 = false; - pressed2 = false; - break; - } - slider.repaint( thumbRect ); - Point p = adjustThumbForHighValue(); - slider.repaint( thumbRect ); - restoreThumbForLowValue( p ); - } - - @SuppressWarnings( { "UnusedDeclaration" } ) - protected void setMouseReleased( int handle ) { - pressed1 = false; - pressed2 = false; - slider.repaint( thumbRect ); - Point p = adjustThumbForHighValue(); - slider.repaint( thumbRect ); - restoreThumbForLowValue( p ); - } - - @Override - public void scrollByBlock( int direction ) { - synchronized( slider ) { - - int oldValue; - Object clientProperty = slider.getClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION ); - if( clientProperty == null ) { - oldValue = slider.getValue(); - } else if( Boolean.TRUE.equals( clientProperty ) ) { - oldValue = ((RangeSlider) slider).getLowValue(); - } else { - oldValue = ((RangeSlider) slider).getHighValue(); - } - int blockIncrement = (slider.getMaximum() - slider.getMinimum()) / 10; - if( blockIncrement <= 0 && slider.getMaximum() > slider.getMinimum() ) { - - blockIncrement = 1; - } - - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_ADJUST_ACTION, "scrollByBlock" ); - int delta = blockIncrement * ((direction > 0) ? POSITIVE_SCROLL : NEGATIVE_SCROLL); - if( clientProperty == null ) { - slider.setValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); - } else if( Boolean.TRUE.equals( clientProperty ) ) { - ((RangeSlider) slider) - .setLowValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); - } else { - ((RangeSlider) slider) - .setHighValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); - } - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_ADJUST_ACTION, null ); } } - @Override - public void scrollByUnit( int direction ) { - synchronized( slider ) { - - int oldValue; - Object clientProperty = slider.getClientProperty( RangeSlider.CLIENT_PROPERTY_MOUSE_POSITION ); - if( clientProperty == null ) { - oldValue = slider.getValue(); - } else if( Boolean.TRUE.equals( clientProperty ) ) { - oldValue = ((RangeSlider) slider).getLowValue(); - } else { - oldValue = ((RangeSlider) slider).getHighValue(); - } - int delta = 1 * ((direction > 0) ? POSITIVE_SCROLL : NEGATIVE_SCROLL); - - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_ADJUST_ACTION, "scrollByUnit" ); - if( clientProperty == null ) { - slider.setValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); - } else if( Boolean.TRUE.equals( clientProperty ) ) { - ((RangeSlider) slider) - .setLowValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); - } else { - ((RangeSlider) slider) - .setHighValue( Math.max( Math.min( oldValue + delta, slider.getMaximum() ), slider.getMinimum() ) ); - } - slider.putClientProperty( RangeSlider.CLIENT_PROPERTY_ADJUST_ACTION, null ); - } + private boolean isRoundThumb() { + return !slider.getPaintTicks() && !slider.getPaintLabels(); } } From c0f15d2e6f7954e35c79300e5b3efe3dc5656304 Mon Sep 17 00:00:00 2001 From: mmatessi <17149962+basix86@users.noreply.github.com> Date: Fri, 13 Nov 2020 09:42:26 +0100 Subject: [PATCH 3/4] FlatRangeSliderUI fix change label foreground --- .../flatlaf/jideoss/ui/FlatRangeSliderUI.java | 34 ++ .../flatlaf/jideoss/FlatLaf.properties | 8 - .../testing/jideoss/FlatJideOssTest.java | 392 +++++++++--------- .../testing/jideoss/FlatRangeSliderTest.java | 71 ++-- .../testing/jideoss/FlatRangeSliderTest.jfd | 20 +- 5 files changed, 275 insertions(+), 250 deletions(-) diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java index 7fb75b25..6302c13d 100644 --- a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java @@ -8,6 +8,8 @@ import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.Path2D; import java.awt.geom.RoundRectangle2D; +import java.util.Dictionary; +import java.util.Enumeration; import javax.swing.JComponent; import javax.swing.JSlider; import javax.swing.LookAndFeel; @@ -39,8 +41,40 @@ public class FlatRangeSliderUI return new FlatRangeSliderUI( slider ); } + @Override + public void installUI( JComponent c ) { + super.installUI( c ); + + // update label UIs, which is necessary because RangeSlider does not invoke JSlider.updateLabelUIs() + updateLabelUIs( c ); + } + + @Override + public void uninstallUI( JComponent c ) { + // update label UIs also on uninstall to avoid light labels when switching + // from dark FlatLaf theme to another Laf + updateLabelUIs( c ); + + super.uninstallUI( c ); + } + + protected void updateLabelUIs( JComponent c ) { + Dictionary labelTable = ((JSlider)c).getLabelTable(); + if( labelTable == null ) + return; + + Enumeration e = labelTable.elements(); + while( e.hasMoreElements() ) { + JComponent label = (JComponent) e.nextElement(); + label.updateUI(); + label.setSize( label.getPreferredSize() ); + } + } + @Override public void paint( Graphics g, JComponent c ) { + FlatUIUtils.setRenderingHints( (Graphics2D) g ); + second = false; super.paint( g, c ); diff --git a/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties b/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties index 13ccc680..af28ab79 100644 --- a/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties +++ b/flatlaf-jide-oss/src/main/resources/com/formdev/flatlaf/jideoss/FlatLaf.properties @@ -36,11 +36,3 @@ JideTabbedPane.tabAreaInsets=$TabbedPane.tabAreaInsets JideTabbedPane.contentBorderInsets=0,0,0,0 JideTabbedPane.tabRunOverlay=$TabbedPane.tabRunOverlay JideTabbedPane.shadow=$TabbedPane.shadow - - -#---- RangeSlider ---- - -RangeSliderUI.foreground=@background - - - diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java index 33379c1b..b51aa6ec 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssTest.java @@ -16,7 +16,6 @@ package com.formdev.flatlaf.testing.jideoss; -import com.jgoodies.forms.factories.*; import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_HAS_FULL_BORDER; import java.awt.*; import java.awt.event.*; @@ -38,7 +37,7 @@ public class FlatJideOssTest { public static void main( String[] args ) { SwingUtilities.invokeLater( () -> { - FlatTestFrame frame = FlatTestFrame.create( args, "FlatRangeSliderTest" ); + FlatTestFrame frame = FlatTestFrame.create( args, "FlatJideOssTest" ); LookAndFeelFactory.installJideExtension(); frame.showFrame( FlatJideOssTest::new ); @@ -107,238 +106,229 @@ public class FlatJideOssTest private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents - // Generated using JFormDesigner Evaluation license - unknown - JPanel panel9 = new JPanel(); - JLabel tabbedPaneLabel = new JLabel(); - tabbedPane1 = new JideTabbedPane(); - JPanel panel1 = new JPanel(); - JLabel label1 = new JLabel(); - JPanel panel2 = new JPanel(); - JLabel label2 = new JLabel(); - tabbedPane3 = new JideTabbedPane(); - JPanel panel5 = new JPanel(); - JLabel label5 = new JLabel(); - JPanel panel6 = new JPanel(); - JLabel label6 = new JLabel(); - tabbedPane2 = new JideTabbedPane(); - JPanel panel3 = new JPanel(); - JLabel label3 = new JLabel(); - JPanel panel4 = new JPanel(); - JLabel label4 = new JLabel(); - tabbedPane4 = new JideTabbedPane(); - JPanel panel7 = new JPanel(); - JLabel label7 = new JLabel(); - JPanel panel8 = new JPanel(); - JLabel label8 = new JLabel(); - JPanel panel14 = new JPanel(); - moreTabsCheckBox = new JCheckBox(); - tabScrollCheckBox = new JCheckBox(); - hasFullBorderCheckBox = new JCheckBox(); - JPanel panel10 = new JPanel(); - JLabel jidePopupLabel = new JLabel(); - JButton showJidePopupButton = new JButton(); + JPanel panel9 = new JPanel(); + JLabel tabbedPaneLabel = new JLabel(); + tabbedPane1 = new JideTabbedPane(); + JPanel panel1 = new JPanel(); + JLabel label1 = new JLabel(); + JPanel panel2 = new JPanel(); + JLabel label2 = new JLabel(); + tabbedPane3 = new JideTabbedPane(); + JPanel panel5 = new JPanel(); + JLabel label5 = new JLabel(); + JPanel panel6 = new JPanel(); + JLabel label6 = new JLabel(); + tabbedPane2 = new JideTabbedPane(); + JPanel panel3 = new JPanel(); + JLabel label3 = new JLabel(); + JPanel panel4 = new JPanel(); + JLabel label4 = new JLabel(); + tabbedPane4 = new JideTabbedPane(); + JPanel panel7 = new JPanel(); + JLabel label7 = new JLabel(); + JPanel panel8 = new JPanel(); + JLabel label8 = new JLabel(); + JPanel panel14 = new JPanel(); + moreTabsCheckBox = new JCheckBox(); + tabScrollCheckBox = new JCheckBox(); + hasFullBorderCheckBox = new JCheckBox(); + JPanel panel10 = new JPanel(); + JLabel jidePopupLabel = new JLabel(); + JButton showJidePopupButton = new JButton(); + CellConstraints cc = new CellConstraints(); - //======== this ======== - setBorder (new javax. swing. border. CompoundBorder( new javax .swing .border .TitledBorder ( - new javax. swing. border. EmptyBorder( 0, 0, 0, 0) , "JF\u006frmDes\u0069gner \u0045valua\u0074ion" - , javax. swing. border. TitledBorder. CENTER, javax. swing. border. TitledBorder. BOTTOM - , new java .awt .Font ("D\u0069alog" ,java .awt .Font .BOLD ,12 ) - , java. awt. Color. red) , getBorder( )) ); addPropertyChangeListener ( - new java. beans. PropertyChangeListener( ){ @Override public void propertyChange (java .beans .PropertyChangeEvent e - ) {if ("\u0062order" .equals (e .getPropertyName () )) throw new RuntimeException( ) - ; }} ); - setLayout(new MigLayout( - "insets dialog,hidemode 3", - // columns - "[grow,fill]", - // rows - "[grow,fill]")); + //======== this ======== + setLayout(new MigLayout( + "insets dialog,hidemode 3", + // columns + "[grow,fill]", + // rows + "[grow,fill]")); - //======== panel9 ======== - { - panel9.setOpaque(false); - panel9.setLayout(new FormLayout( - "70dlu:grow, $lcgap, 70dlu:grow", - "pref, 2*($lgap, fill:70dlu:grow), $lgap, pref, $lgap, default")); + //======== panel9 ======== + { + panel9.setOpaque(false); + panel9.setLayout(new FormLayout( + "70dlu:grow, $lcgap, 70dlu:grow", + "pref, 2*($lgap, fill:70dlu:grow), $lgap, pref, $lgap, default")); - //---- tabbedPaneLabel ---- - tabbedPaneLabel.setText("JideTabbedPane:"); - panel9.add(tabbedPaneLabel, CC.xy(1, 1)); + //---- tabbedPaneLabel ---- + tabbedPaneLabel.setText("JideTabbedPane:"); + panel9.add(tabbedPaneLabel, cc.xy(1, 1)); - //======== tabbedPane1 ======== - { + //======== tabbedPane1 ======== + { - //======== panel1 ======== - { - panel1.setLayout(new FlowLayout()); + //======== panel1 ======== + { + panel1.setLayout(new FlowLayout()); - //---- label1 ---- - label1.setText("TOP"); - panel1.add(label1); - } - tabbedPane1.addTab("Tab 1", panel1); + //---- label1 ---- + label1.setText("TOP"); + panel1.add(label1); + } + tabbedPane1.addTab("Tab 1", panel1); - //======== panel2 ======== - { - panel2.setBorder(new LineBorder(Color.magenta)); - panel2.setLayout(new FlowLayout()); - } - tabbedPane1.addTab("Tab 2", panel2); + //======== panel2 ======== + { + panel2.setBorder(new LineBorder(Color.magenta)); + panel2.setLayout(new FlowLayout()); + } + tabbedPane1.addTab("Tab 2", panel2); - //---- label2 ---- - label2.setText("text"); - tabbedPane1.addTab("Tab 3", label2); - } - panel9.add(tabbedPane1, CC.xy(1, 3)); + //---- label2 ---- + label2.setText("text"); + tabbedPane1.addTab("Tab 3", label2); + } + panel9.add(tabbedPane1, cc.xy(1, 3)); - //======== tabbedPane3 ======== - { - tabbedPane3.setTabPlacement(SwingConstants.LEFT); + //======== tabbedPane3 ======== + { + tabbedPane3.setTabPlacement(SwingConstants.LEFT); - //======== panel5 ======== - { - panel5.setLayout(new FlowLayout()); + //======== panel5 ======== + { + panel5.setLayout(new FlowLayout()); - //---- label5 ---- - label5.setText("LEFT"); - panel5.add(label5); - } - tabbedPane3.addTab("Tab 1", panel5); + //---- label5 ---- + label5.setText("LEFT"); + panel5.add(label5); + } + tabbedPane3.addTab("Tab 1", panel5); - //======== panel6 ======== - { - panel6.setBorder(new LineBorder(Color.magenta)); - panel6.setLayout(new FlowLayout()); - } - tabbedPane3.addTab("Tab 2", panel6); + //======== panel6 ======== + { + panel6.setBorder(new LineBorder(Color.magenta)); + panel6.setLayout(new FlowLayout()); + } + tabbedPane3.addTab("Tab 2", panel6); - //---- label6 ---- - label6.setText("text"); - tabbedPane3.addTab("Tab 3", label6); - } - panel9.add(tabbedPane3, CC.xy(3, 3)); + //---- label6 ---- + label6.setText("text"); + tabbedPane3.addTab("Tab 3", label6); + } + panel9.add(tabbedPane3, cc.xy(3, 3)); - //======== tabbedPane2 ======== - { - tabbedPane2.setTabPlacement(SwingConstants.BOTTOM); + //======== tabbedPane2 ======== + { + tabbedPane2.setTabPlacement(SwingConstants.BOTTOM); - //======== panel3 ======== - { - panel3.setLayout(new FlowLayout()); + //======== panel3 ======== + { + panel3.setLayout(new FlowLayout()); - //---- label3 ---- - label3.setText("BOTTOM"); - panel3.add(label3); - } - tabbedPane2.addTab("Tab 1", panel3); + //---- label3 ---- + label3.setText("BOTTOM"); + panel3.add(label3); + } + tabbedPane2.addTab("Tab 1", panel3); - //======== panel4 ======== - { - panel4.setBorder(new LineBorder(Color.magenta)); - panel4.setLayout(new FlowLayout()); - } - tabbedPane2.addTab("Tab 2", panel4); - tabbedPane2.setEnabledAt(1, false); + //======== panel4 ======== + { + panel4.setBorder(new LineBorder(Color.magenta)); + panel4.setLayout(new FlowLayout()); + } + tabbedPane2.addTab("Tab 2", panel4); + tabbedPane2.setEnabledAt(1, false); - //---- label4 ---- - label4.setText("text"); - tabbedPane2.addTab("Tab 3", label4); - } - panel9.add(tabbedPane2, CC.xy(1, 5)); + //---- label4 ---- + label4.setText("text"); + tabbedPane2.addTab("Tab 3", label4); + } + panel9.add(tabbedPane2, cc.xy(1, 5)); - //======== tabbedPane4 ======== - { - tabbedPane4.setTabPlacement(SwingConstants.RIGHT); + //======== tabbedPane4 ======== + { + tabbedPane4.setTabPlacement(SwingConstants.RIGHT); - //======== panel7 ======== - { - panel7.setLayout(new FlowLayout()); + //======== panel7 ======== + { + panel7.setLayout(new FlowLayout()); - //---- label7 ---- - label7.setText("RIGHT"); - panel7.add(label7); - } - tabbedPane4.addTab("Tab 1", panel7); + //---- label7 ---- + label7.setText("RIGHT"); + panel7.add(label7); + } + tabbedPane4.addTab("Tab 1", panel7); - //======== panel8 ======== - { - panel8.setBorder(new LineBorder(Color.magenta)); - panel8.setLayout(new FlowLayout()); - } - tabbedPane4.addTab("Tab 2", panel8); + //======== panel8 ======== + { + panel8.setBorder(new LineBorder(Color.magenta)); + panel8.setLayout(new FlowLayout()); + } + tabbedPane4.addTab("Tab 2", panel8); - //---- label8 ---- - label8.setText("text"); - tabbedPane4.addTab("Tab 3", label8); - } - panel9.add(tabbedPane4, CC.xy(3, 5)); + //---- label8 ---- + label8.setText("text"); + tabbedPane4.addTab("Tab 3", label8); + } + panel9.add(tabbedPane4, cc.xy(3, 5)); - //======== panel14 ======== - { - panel14.setOpaque(false); - panel14.setLayout(new MigLayout( - "insets 0,hidemode 3", - // columns - "[]" + - "[]" + - "[]", - // rows - "[center]")); + //======== panel14 ======== + { + panel14.setOpaque(false); + panel14.setLayout(new MigLayout( + "insets 0,hidemode 3", + // columns + "[]" + + "[]" + + "[]", + // rows + "[center]")); - //---- moreTabsCheckBox ---- - moreTabsCheckBox.setText("more tabs"); - moreTabsCheckBox.setMnemonic('M'); - moreTabsCheckBox.addActionListener(e -> moreTabsChanged()); - panel14.add(moreTabsCheckBox, "cell 0 0"); + //---- moreTabsCheckBox ---- + moreTabsCheckBox.setText("more tabs"); + moreTabsCheckBox.setMnemonic('M'); + moreTabsCheckBox.addActionListener(e -> moreTabsChanged()); + panel14.add(moreTabsCheckBox, "cell 0 0"); - //---- tabScrollCheckBox ---- - tabScrollCheckBox.setText("tabLayoutPolicy = SCROLL"); - tabScrollCheckBox.setMnemonic('S'); - tabScrollCheckBox.setSelected(true); - tabScrollCheckBox.addActionListener(e -> tabScrollChanged()); - panel14.add(tabScrollCheckBox, "cell 1 0,alignx left,growx 0"); + //---- tabScrollCheckBox ---- + tabScrollCheckBox.setText("tabLayoutPolicy = SCROLL"); + tabScrollCheckBox.setMnemonic('S'); + tabScrollCheckBox.setSelected(true); + tabScrollCheckBox.addActionListener(e -> tabScrollChanged()); + panel14.add(tabScrollCheckBox, "cell 1 0,alignx left,growx 0"); - //---- hasFullBorderCheckBox ---- - hasFullBorderCheckBox.setText("JTabbedPane.hasFullBorder"); - hasFullBorderCheckBox.setMnemonic('F'); - hasFullBorderCheckBox.addActionListener(e -> hasFullBorderChanged()); - panel14.add(hasFullBorderCheckBox, "cell 2 0,alignx left,growx 0"); - } - panel9.add(panel14, CC.xywh(1, 7, 3, 1)); + //---- hasFullBorderCheckBox ---- + hasFullBorderCheckBox.setText("JTabbedPane.hasFullBorder"); + hasFullBorderCheckBox.setMnemonic('F'); + hasFullBorderCheckBox.addActionListener(e -> hasFullBorderChanged()); + panel14.add(hasFullBorderCheckBox, "cell 2 0,alignx left,growx 0"); + } + panel9.add(panel14, cc.xywh(1, 7, 3, 1)); - //======== panel10 ======== - { - panel10.setLayout(new MigLayout( - "insets 3 0 3 3,hidemode 3", - // columns - "[fill]" + - "[fill]", - // rows - "[]")); + //======== panel10 ======== + { + panel10.setLayout(new MigLayout( + "insets 3 0 3 3,hidemode 3", + // columns + "[fill]" + + "[fill]", + // rows + "[]")); - //---- jidePopupLabel ---- - jidePopupLabel.setText("JidePopup:"); - panel10.add(jidePopupLabel, "cell 0 0"); + //---- jidePopupLabel ---- + jidePopupLabel.setText("JidePopup:"); + panel10.add(jidePopupLabel, "cell 0 0"); - //---- showJidePopupButton ---- - showJidePopupButton.setText("show JidePopup"); - showJidePopupButton.addActionListener(e -> showJidePopupButtonActionPerformed(e)); - panel10.add(showJidePopupButton, "cell 1 0"); - } - panel9.add(panel10, CC.xy(1, 9)); - } - add(panel9, "cell 0 0"); + //---- showJidePopupButton ---- + showJidePopupButton.setText("show JidePopup"); + showJidePopupButton.addActionListener(e -> showJidePopupButtonActionPerformed(e)); + panel10.add(showJidePopupButton, "cell 1 0"); + } + panel9.add(panel10, cc.xy(1, 9)); + } + add(panel9, "cell 0 0"); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables - // Generated using JFormDesigner Evaluation license - unknown - private JideTabbedPane tabbedPane1; - private JideTabbedPane tabbedPane3; - private JideTabbedPane tabbedPane2; - private JideTabbedPane tabbedPane4; - private JCheckBox moreTabsCheckBox; - private JCheckBox tabScrollCheckBox; - private JCheckBox hasFullBorderCheckBox; + private JideTabbedPane tabbedPane1; + private JideTabbedPane tabbedPane3; + private JideTabbedPane tabbedPane2; + private JideTabbedPane tabbedPane4; + private JCheckBox moreTabsCheckBox; + private JCheckBox tabScrollCheckBox; + private JCheckBox hasFullBorderCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables } diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.java index ac5ddc69..896ba05b 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.java @@ -1,13 +1,11 @@ package com.formdev.flatlaf.testing.jideoss; -import java.awt.event.*; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.UIManager; -import javax.swing.event.*; import com.formdev.flatlaf.testing.FlatTestFrame; import com.formdev.flatlaf.testing.FlatTestPanel; import com.jgoodies.forms.factories.CC; @@ -20,9 +18,6 @@ public class FlatRangeSliderTest extends FlatTestPanel { - private RangeSlider horizontalRangeSlider; - private RangeSlider verticalRangeSlider; - public static void main( String[] args ) { SwingUtilities.invokeLater( () -> { FlatTestFrame frame = FlatTestFrame.create( args, "FlatRangeSliderTest" ); @@ -54,22 +49,24 @@ public class FlatRangeSliderTest private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner Evaluation license - unknown - JPanel panel9 = new JPanel(); + JPanel mainPanel = new JPanel(); JLabel tabbedPaneLabel = new JLabel(); - JLabel label1 = new JLabel(); + JLabel horizontalLabel = new JLabel(); horizontalRangeSlider = new RangeSlider(); - JLabel label2 = new JLabel(); + JLabel verticalLabel = new JLabel(); verticalRangeSlider = new RangeSlider(); - JPanel panel14 = new JPanel(); + JPanel configurationPanel = new JPanel(); paintTick = new JCheckBox(); paintLabel = new JCheckBox(); //======== this ======== - setBorder(new javax.swing.border.CompoundBorder(new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0 - ,0,0,0), "JF\u006frm\u0044es\u0069gn\u0065r \u0045va\u006cua\u0074io\u006e",javax.swing.border.TitledBorder.CENTER,javax.swing.border.TitledBorder.BOTTOM - ,new java.awt.Font("D\u0069al\u006fg",java.awt.Font.BOLD,12),java.awt.Color.red), - getBorder())); addPropertyChangeListener(new java.beans.PropertyChangeListener(){@Override public void propertyChange(java.beans.PropertyChangeEvent e - ){if("\u0062or\u0064er".equals(e.getPropertyName()))throw new RuntimeException();}}); + setBorder (new javax. swing. border. CompoundBorder( new javax .swing .border .TitledBorder (new javax + . swing. border. EmptyBorder( 0, 0, 0, 0) , "JF\u006frmD\u0065sig\u006eer \u0045val\u0075ati\u006fn", javax. swing + . border. TitledBorder. CENTER, javax. swing. border. TitledBorder. BOTTOM, new java .awt . + Font ("Dia\u006cog" ,java .awt .Font .BOLD ,12 ), java. awt. Color. red + ) , getBorder( )) ); addPropertyChangeListener (new java. beans. PropertyChangeListener( ){ @Override + public void propertyChange (java .beans .PropertyChangeEvent e) {if ("\u0062ord\u0065r" .equals (e .getPropertyName ( + ) )) throw new RuntimeException( ); }} ); setLayout(new MigLayout( "insets dialog,hidemode 3", // columns @@ -77,31 +74,31 @@ public class FlatRangeSliderTest // rows "[grow,fill]")); - //======== panel9 ======== + //======== mainPanel ======== { - panel9.setOpaque(false); - panel9.setLayout(new FormLayout( + mainPanel.setOpaque(false); + mainPanel.setLayout(new FormLayout( "70dlu:grow, $lcgap, 70dlu:grow", "pref, 2*($lgap, fill:70dlu:grow), $lgap, pref")); //---- tabbedPaneLabel ---- tabbedPaneLabel.setText("RangeSlider:"); - panel9.add(tabbedPaneLabel, CC.xy(1, 1)); + mainPanel.add(tabbedPaneLabel, CC.xy(1, 1)); - //---- label1 ---- - label1.setText("Horizontal"); - panel9.add(label1, CC.xy(1, 3)); - panel9.add(horizontalRangeSlider, CC.xy(3, 3)); + //---- horizontalLabel ---- + horizontalLabel.setText("Horizontal"); + mainPanel.add(horizontalLabel, CC.xy(1, 3)); + mainPanel.add(horizontalRangeSlider, CC.xy(3, 3)); - //---- label2 ---- - label2.setText("Vertical"); - panel9.add(label2, CC.xy(1, 5)); - panel9.add(verticalRangeSlider, CC.xy(3, 5)); + //---- verticalLabel ---- + verticalLabel.setText("Vertical"); + mainPanel.add(verticalLabel, CC.xy(1, 5)); + mainPanel.add(verticalRangeSlider, CC.xy(3, 5)); - //======== panel14 ======== + //======== configurationPanel ======== { - panel14.setOpaque(false); - panel14.setLayout(new MigLayout( + configurationPanel.setOpaque(false); + configurationPanel.setLayout(new MigLayout( "insets 0,hidemode 3", // columns "[]" + @@ -112,19 +109,21 @@ public class FlatRangeSliderTest //---- paintTick ---- paintTick.setText("PaintTicks"); - paintTick.setMnemonic('M'); + paintTick.setMnemonic('T'); + paintTick.setSelected(true); paintTick.addActionListener(e -> paintTicks()); - panel14.add(paintTick, "cell 0 0"); + configurationPanel.add(paintTick, "cell 0 0"); //---- paintLabel ---- paintLabel.setText("PaintLabels"); - paintLabel.setMnemonic('F'); + paintLabel.setMnemonic('L'); + paintLabel.setSelected(true); paintLabel.addActionListener(e -> paintLabels()); - panel14.add(paintLabel, "cell 2 0,alignx left,growx 0"); + configurationPanel.add(paintLabel, "cell 2 0,alignx left,growx 0"); } - panel9.add(panel14, CC.xywh(1, 7, 3, 1)); + mainPanel.add(configurationPanel, CC.xywh(1, 7, 3, 1)); } - add(panel9, "cell 0 0"); + add(mainPanel, "cell 0 0"); // JFormDesigner - End of component initialization //GEN-END:initComponents horizontalRangeSlider.setOrientation( SwingConstants.HORIZONTAL ); @@ -152,6 +151,8 @@ public class FlatRangeSliderTest // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // Generated using JFormDesigner Evaluation license - unknown + private RangeSlider horizontalRangeSlider; + private RangeSlider verticalRangeSlider; private JCheckBox paintTick; private JCheckBox paintLabel; // JFormDesigner - End of variables declaration //GEN-END:variables diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.jfd index 7338967a..58fe9188 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatRangeSliderTest.jfd @@ -16,7 +16,7 @@ new FormModel { "$columnSpecs": "70dlu:grow, labelcompgap, 70dlu:grow" "$rowSpecs": "pref, linegap, fill:70dlu:grow, linegap, fill:70dlu:grow, linegap, pref" } ) { - name: "panel9" + name: "mainPanel" "opaque": false add( new FormComponent( "javax.swing.JLabel" ) { name: "tabbedPaneLabel" @@ -25,7 +25,7 @@ new FormModel { "gridX": 1 } ) add( new FormComponent( "javax.swing.JLabel" ) { - name: "label1" + name: "horizontalLabel" "text": "Horizontal" }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { "gridX": 1 @@ -33,12 +33,15 @@ new FormModel { } ) add( new FormComponent( "com.jidesoft.swing.RangeSlider" ) { name: "horizontalRangeSlider" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { "gridX": 3 "gridY": 3 } ) add( new FormComponent( "javax.swing.JLabel" ) { - name: "label2" + name: "verticalLabel" "text": "Vertical" }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { "gridX": 1 @@ -46,6 +49,9 @@ new FormModel { } ) add( new FormComponent( "com.jidesoft.swing.RangeSlider" ) { name: "verticalRangeSlider" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } }, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) { "gridY": 5 "gridX": 3 @@ -55,12 +61,13 @@ new FormModel { "$columnConstraints": "[][][]" "$rowConstraints": "[center]" } ) { - name: "panel14" + name: "configurationPanel" "opaque": false add( new FormComponent( "javax.swing.JCheckBox" ) { name: "paintTick" "text": "PaintTicks" - "mnemonic": 77 + "mnemonic": 84 + "selected": true auxiliary() { "JavaCodeGenerator.variableLocal": false } @@ -71,7 +78,8 @@ new FormModel { add( new FormComponent( "javax.swing.JCheckBox" ) { name: "paintLabel" "text": "PaintLabels" - "mnemonic": 70 + "mnemonic": 76 + "selected": true auxiliary() { "JavaCodeGenerator.variableLocal": false } From f57dbf94c8a942f6694fb0898802f68144bd0ca6 Mon Sep 17 00:00:00 2001 From: mmatessi <17149962+basix86@users.noreply.github.com> Date: Fri, 13 Nov 2020 09:47:32 +0100 Subject: [PATCH 4/4] FlatJideOssDefaultsAddon reformat --- .../com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java index 36a8a1aa..ee4f611f 100644 --- a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/FlatJideOssDefaultsAddon.java @@ -72,8 +72,8 @@ public class FlatJideOssDefaultsAddon if( key instanceof String && ( ((String)key).startsWith( "Jide" ) || - ((String)key).equals( "RangeSliderUI" ) || - ((String)key).equals( "Resizable.resizeBorder" )) + key.equals( "RangeSliderUI" ) || + key.equals( "Resizable.resizeBorder" )) ) { jideDefaults.put( key, e.getValue() );