use of org.jdesktop.swingx.multislider.Thumb in project cytoscape-impl by cytoscape.
the class ContinuousTrackRenderer method paintComponent.
@Override
protected void paintComponent(Graphics gfx) {
trackHeight = slider.getHeight() - 100;
arrowBarPosition = trackHeight + 50;
// AA on
Graphics2D g = (Graphics2D) gfx;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
double minValue = tracer.getMin(vp);
double maxValue = tracer.getMax(vp);
int thumb_width = 12;
int track_width = slider.getWidth() - thumb_width;
g.translate(thumb_width / 2, 12);
// get the list of tumbs
List<Thumb<V>> stops = slider.getModel().getSortedThumbs();
int numPoints = stops.size();
// set up the data for the gradient
float[] fractions = new float[numPoints];
final Double[] doubleValues = new Double[numPoints];
int i = 0;
values.clear();
values.add(below);
values.add(above);
for (Thumb<V> thumb : stops) {
doubleValues[i] = thumb.getObject().doubleValue();
fractions[i] = thumb.getPosition();
values.add(thumb.getObject());
i++;
}
for (V val : values) {
if (min >= val.floatValue())
min = val.floatValue();
if (max <= val.floatValue())
max = val.floatValue();
}
// Draw arrow bar
g.setStroke(new BasicStroke(1.0f));
g.setColor(LABEL_COLOR);
g.drawLine(0, arrowBarPosition, track_width, arrowBarPosition);
Polygon arrow = new Polygon();
arrow.addPoint(track_width, arrowBarPosition);
arrow.addPoint(track_width - 20, arrowBarPosition - 8);
arrow.addPoint(track_width - 20, arrowBarPosition);
g.fill(arrow);
g.setColor(DISABLED_LABEL_COLOR);
g.drawLine(0, arrowBarPosition, 15, arrowBarPosition - 30);
g.drawLine(15, arrowBarPosition - 30, 25, arrowBarPosition - 30);
g.setFont(SMALL_FONT);
g.drawString("Min=" + minValue, 28, arrowBarPosition - 25);
g.drawLine(track_width, arrowBarPosition, track_width - 15, arrowBarPosition + 30);
g.drawLine(track_width - 15, arrowBarPosition + 30, track_width - 25, arrowBarPosition + 30);
final String maxStr = "Max=" + maxValue;
int strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), maxStr);
g.drawString(maxStr, track_width - strWidth - 26, arrowBarPosition + 35);
g.setFont(DEF_FONT);
g.setColor(LABEL_COLOR);
strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), title);
g.drawString(title, (track_width / 2) - (strWidth / 2), arrowBarPosition + 35);
/*
* If no points, just draw empty box.
*/
if (numPoints == 0) {
g.setColor(BORDER_COLOR);
g.setStroke(new BasicStroke(1.5f));
g.drawRect(0, 5, track_width, trackHeight);
return;
}
g.setStroke(new BasicStroke(1.0f));
/*
* Fill background
*/
g.setColor(BACKGROUND_COLOR);
g.fillRect(0, 5, track_width, trackHeight);
int newX = 0;
int lastY = 0;
Point2D p1 = new Point2D.Float(0, 5);
Point2D p2 = new Point2D.Float(0, 5);
for (i = 0; i < doubleValues.length; i++) {
newX = (int) (track_width * (fractions[i] / 100));
p2.setLocation(newX, 5);
int newY = (5 + trackHeight) - (int) ((doubleValues[i].floatValue() / max) * trackHeight);
valueArea.reset();
g.setColor(VALUE_AREA_COLOR);
if (i == 0) {
int h = (5 + trackHeight) - (int) ((below.floatValue() / max) * trackHeight);
g.fillRect(0, h, newX, (int) ((below.floatValue() / max) * trackHeight));
g.setColor(TRACK_COLOR);
g.fillRect(-5, h - 5, 10, 10);
belowSquare = new Point(0, h);
} else {
valueArea.addPoint((int) p1.getX(), lastY);
valueArea.addPoint(newX, newY);
valueArea.addPoint(newX, trackHeight + 5);
valueArea.addPoint((int) p1.getX(), trackHeight + 5);
g.fill(valueArea);
}
for (int j = 0; j < stops.size(); j++) {
final V tValue = slider.getModel().getThumbAt(j).getObject();
if (tValue.doubleValue() == doubleValues[i].doubleValue()) {
Point newPoint = new Point(newX, newY);
if (verticesList.containsValue(newPoint) == false)
verticesList.put(j, new Point(newX, newY));
break;
}
}
lastY = newY;
g.setColor(LABEL_COLOR);
g.setStroke(new BasicStroke(1.5f));
g.setFont(SMALL_FONT);
int numberWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), doubleValues[i].toString());
g.setColor(LABEL_COLOR);
if (fractions[i] < 10) {
g.drawLine(newX, newY, newX + 15, newY - 35);
g.drawString(doubleValues[i].toString(), newX + numberWidth, newY - 48);
} else {
g.drawLine(newX, newY, newX - 15, newY + 35);
g.drawString(doubleValues[i].toString(), newX - (numberWidth + 5), newY + 48);
}
g.setColor(LABEL_COLOR);
g.setFont(SMALL_FONT);
Double curPositionValue = ((Double) (((fractions[i] / 100) * tracer.getRange(vp)) + minValue)).doubleValue();
String valueString = String.format("%.4f", curPositionValue);
int flipLimit = 90;
int borderVal = track_width - newX;
if (((i % 2) == 0) && (flipLimit < borderVal)) {
g.drawLine(newX, arrowBarPosition, newX + 20, arrowBarPosition - 15);
g.drawLine(newX + 20, arrowBarPosition - 15, newX + 30, arrowBarPosition - 15);
g.setColor(LABEL_COLOR);
g.drawString(valueString, newX + 33, arrowBarPosition - 11);
} else if (((i % 2) == 1) && (flipLimit < borderVal)) {
g.drawLine(newX, arrowBarPosition, newX + 20, arrowBarPosition + 15);
g.drawLine(newX + 20, arrowBarPosition + 15, newX + 30, arrowBarPosition + 15);
g.setColor(LABEL_COLOR);
g.drawString(valueString, newX + 33, arrowBarPosition + 19);
} else if (((i % 2) == 0) && (flipLimit >= borderVal)) {
g.drawLine(newX, arrowBarPosition, newX - 20, arrowBarPosition - 15);
g.drawLine(newX - 20, arrowBarPosition - 15, newX - 30, arrowBarPosition - 15);
g.setColor(LABEL_COLOR);
g.drawString(valueString, newX - 90, arrowBarPosition - 11);
} else {
g.drawLine(newX, arrowBarPosition, newX - 20, arrowBarPosition + 15);
g.drawLine(newX - 20, arrowBarPosition + 15, newX - 30, arrowBarPosition + 15);
g.setColor(LABEL_COLOR);
g.drawString(valueString, newX - 90, arrowBarPosition + 19);
}
g.setColor(LABEL_COLOR);
g.fillOval(newX - 3, arrowBarPosition - 3, 6, 6);
p1.setLocation(p2);
}
p2.setLocation(track_width, 5);
g.setColor(VALUE_AREA_COLOR);
int h = (5 + trackHeight) - (int) ((above.floatValue() / max) * trackHeight);
g.fillRect((int) p1.getX(), h, track_width - (int) p1.getX(), (int) ((above.floatValue() / max) * trackHeight));
g.setColor(TRACK_COLOR);
g.fillRect(track_width - 5, h - 5, 10, 10);
aboveSquare = new Point(track_width, h);
/*
* Finally, draw border line (rectangle)
*/
g.setColor(BORDER_COLOR);
g.setStroke(new BasicStroke(1.5f));
g.drawRect(0, 5, track_width, trackHeight);
g.setColor(TRACK_COLOR);
g.setStroke(new BasicStroke(1.5f));
for (Integer key : verticesList.keySet()) {
Point p = verticesList.get(key);
if (clickFlag) {
int diffX = Math.abs(p.x - (curPoint.x - 6));
int diffY = Math.abs(p.y - (curPoint.y - 12));
if (((diffX < 6) && (diffY < 6)) || (key == selectedIdx)) {
g.setColor(FOCUS_COLOR);
g.setStroke(new BasicStroke(2.5f));
} else {
g.setColor(TRACK_COLOR);
g.setStroke(new BasicStroke(1.5f));
}
}
g.drawRect(p.x - 5, p.y - 5, 10, 10);
}
/*
* Draw below & above
*/
g.translate(-THUMB_WIDTH / 2, -12);
}
use of org.jdesktop.swingx.multislider.Thumb in project cytoscape-impl by cytoscape.
the class ContinuousMappingEditorPanel method updateMap.
protected void updateMap() {
final List<Thumb<V>> thumbs = getSlider().getModel().getSortedThumbs();
final double min = tracer.getMin(type);
final double range = tracer.getRange(type);
// There is only one point.
if (thumbs.size() == 1) {
updateOnePoint(thumbs, min, range);
return;
}
// There are two or more points.
final int size = thumbs.size();
final int mappingPointCount = mapping.getPointCount();
// This should not happen!
if (size != mappingPointCount)
throw new IllegalStateException("Number of handles is not equal to mapping points.");
int i = 0;
for (final Thumb<V> handle : thumbs) {
final ContinuousMappingPoint<K, V> point = mapping.getPoint(i);
final Number handlePosition = ((handle.getPosition() / 100) * range) + min;
// Debug
// System.out.print("@@@@@@@ Index = " + i);
// System.out.print(", handle position = " + handlePosition);
// System.out.println(", handle Value = " + handle.getObject());
V lesserVal;
V equalVal = handle.getObject();
V greaterVal;
if (i == 0) {
// First handle. Use Below for lesser.
lesserVal = below;
greaterVal = handle.getObject();
} else if (i == (size - 1)) {
// Last handle. Use above.
greaterVal = above;
lesserVal = handle.getObject();
} else {
lesserVal = handle.getObject();
greaterVal = handle.getObject();
}
final BoundaryRangeValues<V> newRange;
if (equalVal instanceof Number) {
newRange = new BoundaryRangeValues<V>(NumberConverter.convert(vpValueType, (Number) lesserVal), NumberConverter.convert(vpValueType, (Number) equalVal), NumberConverter.convert(vpValueType, (Number) greaterVal));
} else {
newRange = new BoundaryRangeValues<V>(lesserVal, equalVal, greaterVal);
}
point.setRange(newRange);
point.setValue((K) handlePosition);
i++;
}
}
use of org.jdesktop.swingx.multislider.Thumb in project cytoscape-impl by cytoscape.
the class ContinuousMappingEditorPanel method getSelectedPoint.
protected int getSelectedPoint(int selectedIndex) {
final List<Thumb<V>> thumbs = getSlider().getModel().getSortedThumbs();
final Thumb<V> selected = getSlider().getModel().getThumbAt(selectedIndex);
for (int i = 0; i < thumbs.size(); i++) {
if (thumbs.get(i) == selected)
return i;
}
return -1;
}
use of org.jdesktop.swingx.multislider.Thumb in project cytoscape-impl by cytoscape.
the class C2DMappingEditorPanel method updateMap.
@Override
protected void updateMap() {
// FIXME
final List<Thumb<V>> thumbs = getSlider().getModel().getSortedThumbs();
final double minValue = tracer.getMin(type);
final double valRange = tracer.getRange(type);
Thumb<V> t;
Double newPosition;
if (thumbs.size() == 1) {
// Special case: only one handle.
mapping.getPoint(0).setRange(new BoundaryRangeValues<V>(below, below, above));
newPosition = ((thumbs.get(0).getPosition() / 100) * valRange) + minValue;
mapping.getPoint(0).setValue(newPosition);
return;
}
for (int i = 0; i < thumbs.size(); i++) {
t = thumbs.get(i);
V lesserVal;
V equalVal;
V greaterVal;
if (i == 0) {
// First thumb
lesserVal = below;
equalVal = below;
greaterVal = thumbs.get(i + 1).getObject();
} else if (i == (thumbs.size() - 1)) {
// Last thumb
greaterVal = above;
equalVal = t.getObject();
lesserVal = t.getObject();
} else {
// Others
lesserVal = t.getObject();
equalVal = t.getObject();
greaterVal = thumbs.get(i + 1).getObject();
}
mapping.getPoint(i).setRange(new BoundaryRangeValues<V>(lesserVal, equalVal, greaterVal));
newPosition = ((t.getPosition() / 100) * valRange) + minValue;
mapping.getPoint(i).setValue(newPosition);
}
}
use of org.jdesktop.swingx.multislider.Thumb in project cytoscape-impl by cytoscape.
the class ContinuousTrackRenderer method drawIcon.
private ImageIcon drawIcon(int iconWidth, int iconHeight, boolean detail) {
if (slider == null)
return null;
final BufferedImage bi = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_RGB);
final Graphics2D g = bi.createGraphics();
// Turn Anti-alias on
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
double minValue = tracer.getMin(vp);
double maxValue = tracer.getMax(vp);
double valueRange = tracer.getRange(vp);
/*
* Fill background
*/
g.setColor(BACKGROUND_COLOR);
g.fillRect(0, 0, iconWidth, iconHeight);
int leftSpace = 10;
int trackHeight = iconHeight - 9;
int trackWidth = iconWidth - leftSpace;
/*
* Compute fractions from mapping
*/
List<Thumb<V>> stops = slider.getModel().getSortedThumbs();
int numPoints = stops.size();
float[] fractions = new float[numPoints];
Float[] floatProperty = new Float[numPoints];
int i = 0;
values.clear();
values.add(below);
values.add(above);
for (Thumb<V> thumb : stops) {
floatProperty[i] = ((Number) thumb.getObject()).floatValue();
fractions[i] = thumb.getPosition();
values.add((V) thumb.getObject());
i++;
}
for (V val : values) {
if (min >= val.floatValue())
min = val.floatValue();
if (max <= val.floatValue())
max = val.floatValue();
}
// Draw min/max
g.setColor(LABEL_COLOR);
g.setFont(ICON_FONT);
int minWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), String.format("%.1f", min));
int maxWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), String.format("%.1f", max));
if (detail) {
leftSpace = LEFT_SPACE;
trackHeight = iconHeight - 30;
} else {
leftSpace = Math.max(minWidth, maxWidth) + 1;
}
trackWidth = iconWidth - leftSpace;
g.drawString(String.format("%.1f", min), 0, trackHeight);
g.drawString(String.format("%.1f", max), 0, 8);
/*
* If no points, just return empty rectangle.
*/
if (numPoints == 0) {
g.setStroke(new BasicStroke(1.0f));
g.setColor(LABEL_COLOR);
g.drawRect(leftSpace, 0, trackWidth - 3, trackHeight);
return new ImageIcon(bi);
}
g.translate(leftSpace, 0);
g.setStroke(new BasicStroke(1.0f));
int newX = 0;
int lastY = 0;
Point2D p1 = new Point2D.Float(0, 0);
Point2D p2 = new Point2D.Float(0, 0);
for (i = 0; i < floatProperty.length; i++) {
newX = (int) (trackWidth * (fractions[i] / 100)) - 3;
if (newX < 0) {
newX = 0;
}
p2.setLocation(newX, 0);
int newY = trackHeight - (int) ((floatProperty[i] / max) * trackHeight);
valueArea.reset();
g.setColor(VALUE_AREA_COLOR);
if (i == 0) {
int h = trackHeight - (int) ((below.floatValue() / max) * trackHeight);
g.fillRect(0, h, newX, (int) ((below.floatValue() / max) * trackHeight));
} else {
valueArea.addPoint((int) p1.getX(), lastY);
valueArea.addPoint(newX, newY);
valueArea.addPoint(newX, trackHeight);
valueArea.addPoint((int) p1.getX(), trackHeight);
g.fill(valueArea);
}
for (int j = 0; j < stops.size(); j++) {
if (slider.getModel().getThumbAt(j).getObject() == floatProperty[i]) {
Point newPoint = new Point(newX, newY);
if (verticesList.containsValue(newPoint) == false)
verticesList.put(j, new Point(newX, newY));
break;
}
}
lastY = newY;
p1.setLocation(p2);
}
p2.setLocation(trackWidth, 0);
g.setColor(VALUE_AREA_COLOR);
int h = trackHeight - (int) ((above.floatValue() / max) * trackHeight);
g.fillRect((int) p1.getX(), h, trackWidth - (int) p1.getX() - 3, (int) ((above.floatValue() / max) * trackHeight));
g.translate(-leftSpace, 0);
/*
* Draw border line (rectangle)
*/
g.setColor(BORDER_COLOR);
g.setStroke(new BasicStroke(1.0f));
g.drawRect(leftSpace, 0, trackWidth - 3, trackHeight);
/*
* Draw numbers and arrows
*/
g.setFont(ICON_FONT);
final String minStr = String.format("%.2f", minValue);
final String maxStr = String.format("%.2f", maxValue);
int strWidth;
g.setColor(LABEL_COLOR);
if (detail) {
String fNum = null;
for (int j = 0; j < fractions.length; j++) {
fNum = String.format("%.2f", ((fractions[j] / 100) * valueRange) + minValue);
strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), fNum);
g.drawString(fNum, ((fractions[j] / 100) * trackWidth) - (strWidth / 2) + leftSpace, iconHeight - 20);
}
g.drawString(minStr, leftSpace, iconHeight);
strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), maxStr);
g.drawString(maxStr, iconWidth - strWidth - 2, iconHeight);
g.setFont(TITLE_FONT);
final int titleWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), title);
g.setColor(LABEL_COLOR);
g.drawString(title, (iconWidth / 2) - (titleWidth / 2), iconHeight - 5);
Polygon p = new Polygon();
p.addPoint(iconWidth, iconHeight - 9);
p.addPoint(iconWidth - 15, iconHeight - 15);
p.addPoint(iconWidth - 15, iconHeight - 9);
g.fillPolygon(p);
g.drawLine(leftSpace, iconHeight - 9, ((iconWidth - leftSpace) / 2) - (titleWidth / 2) - 3, iconHeight - 9);
g.drawLine((iconWidth / 2) + (titleWidth / 2) + 3, iconHeight - 9, iconWidth, iconHeight - 9);
/*
* Draw vertical arrow
*/
int panelHeight = iconHeight - 30;
final Polygon poly = new Polygon();
int top = 0;
g.setStroke(new BasicStroke(1.0f));
int center = (leftSpace / 2) + 6;
poly.addPoint(center, top);
poly.addPoint(center - 6, top + 15);
poly.addPoint(center, top + 15);
g.fillPolygon(poly);
g.drawLine(center, top, center, panelHeight);
g.setColor(LABEL_COLOR);
g.setFont(SMALL_FONT);
final String label = vp.getDisplayName();
final int width = SwingUtilities.computeStringWidth(g.getFontMetrics(), label);
AffineTransform af = new AffineTransform();
af.rotate(Math.PI + (Math.PI / 2));
g.setTransform(af);
g.setColor(LABEL_COLOR);
g.drawString(vp.getDisplayName(), (-panelHeight / 2) - (width / 2), (leftSpace / 2) + 5);
} else {
g.drawString(minStr, 0, iconHeight);
strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), maxStr);
g.drawString(maxStr, iconWidth - strWidth - 2, iconHeight);
}
return new ImageIcon(bi);
}
Aggregations