gt: 		if (upperThumbSelected) {
context: /*******************************************************************************
   * Debrief - the Open Source Maritime Analysis Application
   * http://debrief.info
   *
   * (C) 2000-2020, Deep Blue C Technology Ltd
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the Eclipse Public License v1.0
   * (http://www.eclipse.org/legal/epl-v10.html)
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   *******************************************************************************/
  package org.mwc.debrief.lite.gui.custom;
  
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.Rectangle;
  import java.awt.RenderingHints;
  import java.awt.Shape;
  import java.awt.event.MouseEvent;
  import java.awt.geom.Ellipse2D;
  
  import javax.swing.JComponent;
  import javax.swing.JSlider;
  import javax.swing.SwingConstants;
  import javax.swing.SwingUtilities;
  import javax.swing.event.ChangeEvent;
  import javax.swing.event.ChangeListener;
  import javax.swing.plaf.basic.BasicSliderUI;
  
  /**
   * UI delegate for the RangeSlider component. RangeSliderUI paints two thumbs,
   * one for the lower value and one for the upper value.
   */
  class RangeSliderUI extends BasicSliderUI {
  
  	/**
  	 * Listener to handle model change events. This calculates the thumb locations
  	 * and repaints the slider if the value change is not caused by dragging a
  	 * thumb.
  	 */
  	public class ChangeHandler implements ChangeListener {
  		@Override
  		public void stateChanged(final ChangeEvent arg0) {
  			if (!lowerDragging && !upperDragging) {
  				calculateThumbLocation();
  				slider.repaint();
  			}
  		}
  	}
  
  	/**
  	 * Listener to handle mouse movements in the slider track.
  	 */
  	public class RangeTrackListener extends TrackListener {
  
  		@Override
  		public void mouseDragged(final MouseEvent e) {
  			if (!slider.isEnabled()) {
  				return;
  			}
  
  			currentMouseX = e.getX();
  			currentMouseY = e.getY();
  
  			if (lowerDragging) {
  				slider.setValueIsAdjusting(true);
  				moveLowerThumb();
  
  			} else if (upperDragging) {
  				slider.setValueIsAdjusting(true);
  				moveUpperThumb();
  			}
  		}
  
  		@Override
  		public void mousePressed(final MouseEvent e) {
  			if (!slider.isEnabled()) {
  				return;
  			}
  
  			currentMouseX = e.getX();
  			currentMouseY = e.getY();
  
  			if (slider.isRequestFocusEnabled()) {
  				slider.requestFocus();
  			}
  
  			// Determine which thumb is pressed. If the upper thumb is
  			// selected (last one dragged), then check its position first;
  			// otherwise check the position of the lower thumb first.
  			boolean lowerPressed = false;
  			boolean upperPressed = false;
  			if (upperThumbSelected || slider.getMinimum() == slider.getValue()) {
  				if (upperThumbRect.contains(currentMouseX, currentMouseY)) {
  					upperPressed = true;
  				} else if (thumbRect.contains(currentMouseX, currentMouseY)) {
  					lowerPressed = true;
  				}
  			} else {
  				if (thumbRect.contains(currentMouseX, currentMouseY)) {
  					lowerPressed = true;
  				} else if (upperThumbRect.contains(currentMouseX, currentMouseY)) {
  					upperPressed = true;
  				}
  			}
  
  			// Handle lower thumb pressed.
  			if (lowerPressed) {
  				switch (slider.getOrientation()) {
  				case SwingConstants.VERTICAL:
  					offset = currentMouseY - thumbRect.y;
  					break;
  				case SwingConstants.HORIZONTAL:
  					offset = currentMouseX - thumbRect.x;
  					break;
  				}
  				upperThumbSelected = false;
  				lowerDragging = true;
  				return;
  			}
  			lowerDragging = false;
  
  			// Handle upper thumb pressed.
  			if (upperPressed) {
  				switch (slider.getOrientation()) {
  				case SwingConstants.VERTICAL:
  					offset = currentMouseY - upperThumbRect.y;
  					break;
  				case SwingConstants.HORIZONTAL:
  					offset = currentMouseX - upperThumbRect.x;
  					break;
  				}
  				upperThumbSelected = true;
  				upperDragging = true;
  				return;
  			}
  			upperDragging = false;
  		}
  
  		@Override
  		public void mouseReleased(final MouseEvent e) {
  			lowerDragging = false;
  			upperDragging = false;
  			slider.setValueIsAdjusting(false);
  			super.mouseReleased(e);
  		}
  
  		/**
  		 * Moves the location of the lower thumb, and sets its corresponding value in
  		 * the slider.
  		 */
  		private void moveLowerThumb() {
  			int thumbMiddle = 0;
  
  			switch (slider.getOrientation()) {
  			case SwingConstants.VERTICAL:
  				final int halfThumbHeight = thumbRect.height / 2;
  				int thumbTop = currentMouseY - offset;
  				int trackTop = trackRect.y;
  				int trackBottom = trackRect.y + (trackRect.height - 1);
  				final int vMax = yPositionForValue(slider.getValue() + slider.getExtent());
  
  				// Apply bounds to thumb position.
  				if (drawInverted()) {
  					trackBottom = vMax;
  				} else {
  					trackTop = vMax;
  				}
  				thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
  				thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);
  
  				setThumbLocation(thumbRect.x, thumbTop);
  
  				// Update slider value.
  				thumbMiddle = thumbTop + halfThumbHeight;
  				slider.setValue(valueForYPosition(thumbMiddle));
  				break;
  
  			case SwingConstants.HORIZONTAL:
  				final int halfThumbWidth = thumbRect.width / 2;
  				int thumbLeft = currentMouseX - offset;
  				int trackLeft = trackRect.x;
  				int trackRight = trackRect.x + (trackRect.width - 1);
  				final int hMax = xPositionForValue(slider.getValue() + slider.getExtent());
  
  				// Apply bounds to thumb position.
  				if (drawInverted()) {
  					trackLeft = hMax;
  				} else {
  					trackRight = hMax;
  				}
  				thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
  				thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);
  
  				setThumbLocation(thumbLeft, thumbRect.y);
  
  				// Update slider value.
  				thumbMiddle = thumbLeft + halfThumbWidth;
  				slider.setValue(valueForXPosition(thumbMiddle));
  				break;
  
  			default:
  				return;
  			}
  		}
  
  		/**
  		 * Moves the location of the upper thumb, and sets its corresponding value in
  		 * the slider.
  		 */
  		private void moveUpperThumb() {
  			int thumbMiddle = 0;
  
  			switch (slider.getOrientation()) {
  			case SwingConstants.VERTICAL:
  				final int halfThumbHeight = thumbRect.height / 2;
  				int thumbTop = currentMouseY - offset;
  				int trackTop = trackRect.y;
  				int trackBottom = trackRect.y + (trackRect.height - 1);
  				final int vMin = yPositionForValue(slider.getValue());
  
  				// Apply bounds to thumb position.
  				if (drawInverted()) {
  					trackTop = vMin;
  				} else {
  					trackBottom = vMin;
  				}
  				thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight);
  				thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight);
  
  				setUpperThumbLocation(thumbRect.x, thumbTop);
  
  				// Update slider extent.
  				thumbMiddle = thumbTop + halfThumbHeight;
  				slider.setExtent(valueForYPosition(thumbMiddle) - slider.getValue());
  				break;
  
  			case SwingConstants.HORIZONTAL:
  				final int halfThumbWidth = thumbRect.width / 2;
  				int thumbLeft = currentMouseX - offset;
  				int trackLeft = trackRect.x;
  				int trackRight = trackRect.x + (trackRect.width - 1);
  				final int hMin = xPositionForValue(slider.getValue());
  
  				// Apply bounds to thumb position.
  				if (drawInverted()) {
  					trackRight = hMin;
  				} else {
  					trackLeft = hMin;
  				}
  				thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth);
  				thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth);
  
  				setUpperThumbLocation(thumbLeft, thumbRect.y);
  
  				// Update slider extent.
  				thumbMiddle = thumbLeft + halfThumbWidth;
  				slider.setExtent(valueForXPosition(thumbMiddle) - slider.getValue());
  				break;
  
  			default:
  				return;
  			}
  		}
  
  		@Override
  		public boolean shouldScroll(final int direction) {
  			return false;
  		}
  	}
  
  	/** Color of selected range. */
  	private final Color rangeColor = Color.BLACK;
  
  	/** Location and size of thumb for upper value. */
  	private Rectangle upperThumbRect;
  	/** Indicator that determines whether upper thumb is selected. */
  	private boolean upperThumbSelected;
  
  	/** Indicator that determines whether lower thumb is being dragged. */
  	private transient boolean lowerDragging;
  
  	/** Indicator that determines whether upper thumb is being dragged. */
  	private transient boolean upperDragging;
  
  	/**
  	 * Constructs a RangeSliderUI for the specified slider component.
  	 *
  	 * @param b RangeSlider
  	 */
  	public RangeSliderUI(final RangeSlider b) {
  		super(b);
  	}
  
  	/**
  	 * Updates the locations for both thumbs.
  	 */
  	@Override
  	protected void calculateThumbLocation() {
  		// Call superclass method for lower thumb location.
  		super.calculateThumbLocation();
  
  		// Adjust upper value to snap to ticks if necessary.
  		if (slider.getSnapToTicks()) {
  			final int upperValue = slider.getValue() + slider.getExtent();
  			int snappedValue = upperValue;
  			final int majorTickSpacing = slider.getMajorTickSpacing();
  			final 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 ((upperValue - slider.getMinimum()) % tickSpacing != 0) {
  					final float temp = (float) (upperValue - slider.getMinimum()) / (float) tickSpacing;
  					final int whichTick = Math.round(temp);
  					snappedValue = slider.getMinimum() + (whichTick * tickSpacing);
  				}
  
  				if (snappedValue != upperValue) {
  					slider.setExtent(snappedValue - slider.getValue());
  				}
  			}
  		}
  
  		// Calculate upper thumb location. The thumb is centered over its
  		// value on the track.
  		if (slider.getOrientation() == SwingConstants.HORIZONTAL) {
  			final int upperPosition = xPositionForValue(slider.getValue() + slider.getExtent());
  			upperThumbRect.x = upperPosition - (upperThumbRect.width / 2);
  			upperThumbRect.y = trackRect.y;
  
  		} else {
  			final int upperPosition = yPositionForValue(slider.getValue() + slider.getExtent());
  			upperThumbRect.x = trackRect.x;
  			upperThumbRect.y = upperPosition - (upperThumbRect.height / 2);
  		}
  	}
  
  	/**
  	 * Updates the dimensions for both thumbs.
  	 */
  	@Override
  	protected void calculateThumbSize() {
  		// Call superclass method for lower thumb size.
  		super.calculateThumbSize();
  
  		// Set upper thumb size.
  		upperThumbRect.setSize(thumbRect.width, thumbRect.height);
  	}
  
  	/**
  	 * Creates a listener to handle change events in the specified slider.
  	 */
  	@Override
  	protected ChangeListener createChangeListener(final JSlider slider) {
  		return new ChangeHandler();
  	}
  
  	/**
  	 * Returns a Shape representing a thumb.
  	 */
  	private Shape createThumbShape(final int width, final int height) {
  		// Use circular shape.
  		final Ellipse2D shape = new Ellipse2D.Double(0, 0, width, height);
  		return shape;
  	}
  
  	/**
  	 * Creates a listener to handle track events in the specified slider.
  	 */
  	@Override
  	protected TrackListener createTrackListener(final JSlider slider) {
  		return new RangeTrackListener();
  	}
  
  	/**
  	 * Returns the size of a thumb.
  	 */
  	@Override
  	protected Dimension getThumbSize() {
  		return new Dimension(12, 12);
  	}
  
  	/**
  	 * Installs this UI delegate on the specified component.
  	 */
  	@Override
  	public void installUI(final JComponent c) {
  		upperThumbRect = new Rectangle();
  		super.installUI(c);
  	}
  
  	/**
  	 * Paints the slider. The selected thumb is always painted on top of the other
  	 * thumb.
  	 */
  	@Override
  	public void paint(final Graphics g, final JComponent c) {
  		super.paint(g, c);
  
  		final Rectangle clipRect = g.getClipBounds();
  