Search in sources :

Example 6 with Thumb

use of org.jdesktop.swingx.multislider.Thumb in project cytoscape-impl by cytoscape.

the class DiscreteTrackRenderer method paintComponent.

@Override
protected void paintComponent(Graphics gfx) {
    // Turn AA on
    final Graphics2D g = (Graphics2D) gfx;
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    trackHeight = slider.getHeight() - 100;
    arrowBarYPosition = trackHeight + 50;
    final int trackWidth = slider.getWidth() - THUMB_WIDTH;
    g.translate(THUMB_WIDTH / 2, 12);
    final double minValue = tracer.getMin(vp);
    final double maxValue = tracer.getMax(vp);
    final double valueRange = tracer.getRange(vp);
    final List<Thumb<V>> stops = slider.getModel().getSortedThumbs();
    final int numPoints = stops.size();
    // set up the data for the gradient
    final float[] fractions = new float[numPoints];
    final Object[] objectValues = new Object[numPoints];
    int i = 0;
    for (Thumb<V> thumb : stops) {
        objectValues[i] = thumb.getObject();
        fractions[i] = thumb.getPosition();
        i++;
    }
    // Draw arrow
    g.setStroke(STROKE1);
    g.setColor(BORDER_COLOR);
    g.drawLine(0, arrowBarYPosition, trackWidth, arrowBarYPosition);
    final Polygon arrow = new Polygon();
    arrow.addPoint(trackWidth, arrowBarYPosition);
    arrow.addPoint(trackWidth - 20, arrowBarYPosition - 8);
    arrow.addPoint(trackWidth - 20, arrowBarYPosition);
    g.fill(arrow);
    g.setColor(LABEL_COLOR);
    g.drawLine(0, arrowBarYPosition, 15, arrowBarYPosition - 30);
    g.drawLine(15, arrowBarYPosition - 30, 25, arrowBarYPosition - 30);
    g.setFont(SMALL_FONT);
    g.drawString("Min=" + minValue, 28, arrowBarYPosition - 25);
    g.drawLine(trackWidth, arrowBarYPosition, trackWidth - 15, arrowBarYPosition + 30);
    g.drawLine(trackWidth - 15, arrowBarYPosition + 30, trackWidth - 25, arrowBarYPosition + 30);
    final String maxStr = "Max=" + maxValue;
    int strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), maxStr);
    g.drawString(maxStr, trackWidth - strWidth - 26, arrowBarYPosition + 35);
    g.setColor(LABEL_COLOR);
    strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), title);
    g.drawString(title, (trackWidth / 2) - (strWidth / 2), arrowBarYPosition + 35);
    if (numPoints == 0) {
        g.setColor(BORDER_COLOR);
        g.setStroke(new BasicStroke(1.5f));
        g.drawRect(0, 5, trackWidth, trackHeight);
        return;
    }
    g.setStroke(STROKE1);
    // Fill background
    g.setColor(BACKGROUND_COLOR);
    g.fillRect(0, 5, trackWidth, trackHeight);
    final Point2D p1 = new Point2D.Float(0, 5);
    final Point2D p2 = new Point2D.Float(0, 5);
    int iconLocX;
    int iconLocY;
    // Draw Icons
    for (i = 0; i < stops.size(); i++) {
        int newX = (int) (trackWidth * (fractions[i] / 100));
        p2.setLocation(newX, 5);
        g.setColor(LABEL_COLOR);
        g.setStroke(STROKE1);
        g.drawLine(newX, 5, newX, trackHeight + 4);
        g.setColor(LABEL_COLOR);
        g.setFont(SMALL_FONT);
        final Float curPositionValue = ((Number) (((fractions[i] / 100) * valueRange) + minValue)).floatValue();
        final String valueString = String.format("%.5f", curPositionValue);
        int flipLimit = 90;
        int borderVal = trackWidth - newX;
        if (((i % 2) == 0) && (flipLimit < borderVal)) {
            g.drawLine(newX, arrowBarYPosition, newX + 20, arrowBarYPosition - 15);
            g.drawLine(newX + 20, arrowBarYPosition - 15, newX + 30, arrowBarYPosition - 15);
            g.setColor(LABEL_COLOR);
            g.drawString(valueString, newX + 33, arrowBarYPosition - 11);
        } else if (((i % 2) == 1) && (flipLimit < borderVal)) {
            g.drawLine(newX, arrowBarYPosition, newX + 20, arrowBarYPosition + 15);
            g.drawLine(newX + 20, arrowBarYPosition + 15, newX + 30, arrowBarYPosition + 15);
            g.setColor(LABEL_COLOR);
            g.drawString(valueString, newX + 33, arrowBarYPosition + 19);
        } else if (((i % 2) == 0) && (flipLimit >= borderVal)) {
            g.drawLine(newX, arrowBarYPosition, newX - 20, arrowBarYPosition - 15);
            g.drawLine(newX - 20, arrowBarYPosition - 15, newX - 30, arrowBarYPosition - 15);
            g.setColor(LABEL_COLOR);
            g.drawString(valueString, newX - 90, arrowBarYPosition - 11);
        } else {
            g.drawLine(newX, arrowBarYPosition, newX - 20, arrowBarYPosition + 15);
            g.drawLine(newX - 20, arrowBarYPosition + 15, newX - 30, arrowBarYPosition + 15);
            g.setColor(LABEL_COLOR);
            g.drawString(valueString, newX - 90, arrowBarYPosition + 19);
        }
        g.setColor(LABEL_COLOR);
        g.fillOval(newX - 3, arrowBarYPosition - 3, 6, 6);
        iconLocX = (int) (p2.getX() - ((p2.getX() - p1.getX()) / 2 + ICON_SIZE / 2));
        iconLocY = (int) (trackHeight / 2 - ICON_SIZE / 2 + p2.getY());
        if (i == 0)
            drawIcon(below, g, iconLocX, iconLocY);
        else
            drawIcon((V) objectValues[i], g, iconLocX, iconLocY);
        p1.setLocation(p2);
    }
    // Draw last region (above region)
    p2.setLocation(trackWidth, 5);
    iconLocX = (int) (p2.getX() - ((p2.getX() - p1.getX()) / 2 + ICON_SIZE / 2));
    iconLocY = (int) (trackHeight / 2 - ICON_SIZE / 2 + p2.getY());
    drawIcon(above, g, iconLocX, iconLocY);
    /*
		 * Finally, draw border line (rectangle)
		 */
    g.setColor(BORDER_COLOR);
    g.setStroke(new BasicStroke(1.5f));
    g.drawRect(0, 5, trackWidth, trackHeight);
    g.translate(-THUMB_WIDTH / 2, -12);
}
Also used : BasicStroke(java.awt.BasicStroke) Thumb(org.jdesktop.swingx.multislider.Thumb) Graphics2D(java.awt.Graphics2D) Point2D(java.awt.geom.Point2D) Polygon(java.awt.Polygon)

Example 7 with Thumb

use of org.jdesktop.swingx.multislider.Thumb in project cytoscape-impl by cytoscape.

the class DiscreteTrackRenderer method createIcon.

private ImageIcon createIcon(int iconWidth, int iconHeight, final boolean detail) {
    if (slider == null)
        return null;
    final BufferedImage bi = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_RGB);
    final Graphics2D g = bi.createGraphics();
    // Turn AA on.
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Fill background
    g.setColor(BACKGROUND_COLOR);
    g.fillRect(0, 0, iconWidth, iconHeight);
    double minValue = tracer.getMin(vp);
    double maxValue = tracer.getMax(vp);
    double valueRange = tracer.getRange(vp);
    int track_width = iconWidth;
    int trackHeight = iconHeight - 8;
    if (detail) {
        trackHeight = iconHeight - 30;
    // smallIconSize = (int) (trackHeight * 0.5);
    } else {
        trackHeight = iconHeight - 8;
    }
    // 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];
    Object[] objectValues = new Object[numPoints];
    /*
		 * Find min, max, and ranges
		 */
    int i = 0;
    for (Thumb<V> thumb : stops) {
        objectValues[i] = thumb.getObject();
        fractions[i] = thumb.getPosition();
        i++;
    }
    /*
		 * If no points, just draw empty box.
		 */
    if (numPoints == 0) {
        g.setColor(BORDER_COLOR);
        g.setStroke(new BasicStroke(1.0f));
        g.drawRect(0, 0, track_width - 3, trackHeight);
        return new ImageIcon(bi);
    }
    int newX = 0;
    Point2D p1 = new Point2D.Float(0, 5);
    Point2D p2 = new Point2D.Float(0, 5);
    int iconLocX;
    int iconLocY;
    /*
		 * Draw separators and icons
		 */
    for (i = 0; i < stops.size(); i++) {
        newX = (int) (track_width * (fractions[i] / 100));
        p2.setLocation(newX, 0);
        iconLocX = newX - (((newX - (int) p1.getX()) / 2) + (ICON_SIZE / 2));
        iconLocY = ((trackHeight) / 2) - (ICON_SIZE / 2);
        if (i == 0)
            drawIcon(below, g, iconLocX, iconLocY);
        else
            drawIcon((V) objectValues[i], g, iconLocX, iconLocY);
        g.setColor(BORDER_COLOR);
        g.setStroke(STROKE1);
        g.drawLine(newX, 0, newX, trackHeight);
        p1.setLocation(p2);
    }
    /*
		 * Draw last region (above region)
		 */
    p2.setLocation(track_width, 0);
    iconLocX = track_width - (((track_width - (int) p1.getX()) / 2) + (ICON_SIZE / 2));
    iconLocY = ((trackHeight) / 2) - (ICON_SIZE / 2);
    drawIcon(above, g, iconLocX, iconLocY);
    /*
		 * Finally, draw border line (rectangle)
		 */
    g.setColor(BORDER_COLOR);
    g.setStroke(new BasicStroke(1.0f));
    g.drawRect(0, 0, track_width - 3, trackHeight);
    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) * iconWidth - strWidth / 2, iconHeight - 20);
        }
        g.drawString(minStr, 0, 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(0, iconHeight - 9, (iconWidth / 2) - (titleWidth / 2) - 3, iconHeight - 9);
        g.drawLine((iconWidth / 2) + (titleWidth / 2) + 3, iconHeight - 9, iconWidth, iconHeight - 9);
    } else {
        g.drawString(minStr, 0, iconHeight);
        strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), maxStr);
        g.drawString(maxStr, iconWidth - strWidth - 2, iconHeight);
    }
    return new ImageIcon(bi);
}
Also used : BasicStroke(java.awt.BasicStroke) ImageIcon(javax.swing.ImageIcon) Thumb(org.jdesktop.swingx.multislider.Thumb) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Point2D(java.awt.geom.Point2D) Polygon(java.awt.Polygon)

Example 8 with Thumb

use of org.jdesktop.swingx.multislider.Thumb in project cytoscape-impl by cytoscape.

the class CyGradientTrackRenderer method drawIcon.

public 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 g2 = bi.createGraphics();
    // Turn AA on.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    final double minValue = tracer.getMin(type);
    final double maxValue = tracer.getMax(type);
    final double range = tracer.getRange(type);
    /*
		 * Fill background
		 */
    g2.setColor(BACKGROUND_COLOR);
    g2.fillRect(0, 0, iconWidth, iconHeight);
    List<Thumb<Color>> stops = slider.getModel().getSortedThumbs();
    int len = stops.size();
    int strWidth;
    float[] fractions = null;
    Point2D start = new Point2D.Float(0, 0);
    Point2D end = null;
    if (detail) {
        end = new Point2D.Float(iconWidth - 3, iconHeight - 30);
    } else {
        end = new Point2D.Float(iconWidth - 3, iconHeight - 9);
    }
    if (len != 0) {
        // set up the data for the gradient
        fractions = new float[len + 2];
        Color[] colors = new Color[len + 2];
        int i = 1;
        colors[0] = below;
        fractions[0] = stops.get(0).getPosition() / 100;
        for (Thumb<Color> thumb : stops) {
            colors[i] = (Color) thumb.getObject();
            fractions[i] = thumb.getPosition() / 100;
            i++;
        }
        colors[colors.length - 1] = above;
        fractions[fractions.length - 1] = stops.get(stops.size() - 1).getPosition() / 100;
        // fill in the gradient
        drawGradient(g2, start, end, fractions, colors);
    }
    // Draw border line
    g2.setStroke(new BasicStroke(1.0f));
    g2.setColor(BORDER_COLOR);
    g2.drawRect(0, 0, ((Number) end.getX()).intValue(), ((Number) end.getY()).intValue());
    /*
		 * draw numbers
		 */
    g2.setFont(ICON_FONT);
    final String minStr = String.format("%.2f", minValue);
    final String maxStr = String.format("%.2f", maxValue);
    g2.setColor(LABEL_COLOR);
    if (detail && (fractions != null)) {
        String fNum = null;
        for (int i = 0; i < fractions.length; i++) {
            fNum = String.format("%.2f", (fractions[i] * range) + minValue);
            strWidth = SwingUtilities.computeStringWidth(g2.getFontMetrics(), fNum);
            g2.drawString(fNum, (fractions[i] * iconWidth) - (strWidth / 2), iconHeight - 20);
        }
        g2.drawString(minStr, 0, iconHeight);
        strWidth = SwingUtilities.computeStringWidth(g2.getFontMetrics(), maxStr);
        g2.drawString(maxStr, iconWidth - strWidth - 2, iconHeight);
        g2.setFont(TITLE_FONT);
        final int titleWidth = SwingUtilities.computeStringWidth(g2.getFontMetrics(), attrName);
        g2.setColor(LABEL_COLOR);
        g2.drawString(attrName, (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);
        g2.fillPolygon(p);
        g2.drawLine(0, iconHeight - 9, (iconWidth / 2) - (titleWidth / 2) - 3, iconHeight - 9);
        g2.drawLine((iconWidth / 2) + (titleWidth / 2) + 3, iconHeight - 9, iconWidth, iconHeight - 9);
    } else {
        g2.drawString(minStr, 0, iconHeight);
        strWidth = SwingUtilities.computeStringWidth(g2.getFontMetrics(), maxStr);
        g2.drawString(maxStr, iconWidth - strWidth - 2, iconHeight);
    }
    return new ImageIcon(bi);
}
Also used : BasicStroke(java.awt.BasicStroke) ImageIcon(javax.swing.ImageIcon) Thumb(org.jdesktop.swingx.multislider.Thumb) Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D) Point2D(java.awt.geom.Point2D) Polygon(java.awt.Polygon)

Example 9 with Thumb

use of org.jdesktop.swingx.multislider.Thumb in project cytoscape-impl by cytoscape.

the class CyGradientTrackRenderer method paintComponent.

@Override
protected void paintComponent(Graphics gfx) {
    final Graphics2D g = (Graphics2D) gfx;
    // Turn AA on
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    final double minValue = tracer.getMin(type);
    final double maxValue = tracer.getMax(type);
    final double range = tracer.getRange(type);
    // calculate the track area
    final int track_width = slider.getWidth() - THUMB_WIDTH;
    g.translate(THUMB_WIDTH / 2, 12);
    // get the list of colors
    List<Thumb<Color>> stops = slider.getModel().getSortedThumbs();
    int len = stops.size();
    if (len != 0) {
        // set up the data for the gradient
        float[] fractions = new float[len + 2];
        Color[] colors = new Color[len + 2];
        int i = 1;
        colors[0] = below;
        fractions[0] = stops.get(0).getPosition() / 100;
        for (Thumb<Color> thumb : stops) {
            colors[i] = (Color) thumb.getObject();
            fractions[i] = thumb.getPosition() / 100;
            String valueString;
            Double value = minValue + (fractions[i] * range);
            if ((Math.abs(minValue) < 3) || (Math.abs(maxValue) < 3))
                valueString = String.format("%.4f", value);
            else
                valueString = String.format("%.2f", value);
            final int stringWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), valueString);
            final int curPosition = (int) (track_width * fractions[i]);
            int x;
            int y;
            if (curPosition < (stringWidth / 2)) {
                x = curPosition;
                y = trackHeight + 15;
            } else if ((track_width - curPosition) < (stringWidth / 2)) {
                x = curPosition - stringWidth;
                y = trackHeight + 15;
            } else {
                x = curPosition - (stringWidth / 2);
                y = trackHeight + 15;
            }
            g.setFont(SMALL_FONT);
            g.setColor(LABEL_COLOR);
            g.drawString(valueString, x, y);
            i++;
        }
        colors[colors.length - 1] = above;
        fractions[fractions.length - 1] = stops.get(stops.size() - 1).getPosition() / 100;
        g.setStroke(new BasicStroke(1.0f));
        // fill in the gradient
        Point2D start = new Point2D.Float(0, 0);
        Point2D end = new Point2D.Float(track_width, trackHeight);
        drawGradient(g, start, end, fractions, colors);
    }
    // Define rectangle
    Rectangle2D rect = new Rectangle(0, 0, track_width, trackHeight);
    g.setColor(BORDER_COLOR);
    g.drawLine((int) rect.getBounds2D().getMinX(), (int) rect.getBounds2D().getMaxY(), 8, (int) rect.getBounds2D().getMaxY() + 25);
    g.setFont(SMALL_FONT);
    g.drawString("Min=" + minValue, (int) rect.getBounds2D().getMinX(), (int) rect.getBounds2D().getMaxY() + 38);
    g.drawLine((int) rect.getBounds2D().getMaxX(), (int) rect.getBounds2D().getMaxY(), (int) rect.getBounds2D().getMaxX() - 8, (int) rect.getBounds2D().getMaxY() + 25);
    g.setFont(SMALL_FONT);
    final String maxString = "Max=" + maxValue;
    g.drawString(maxString, (int) rect.getBounds2D().getMaxX() - SwingUtilities.computeStringWidth(g.getFontMetrics(), maxString), (int) rect.getBounds2D().getMaxY() + 38);
    g.setFont(TITLE_FONT);
    final int titleWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), attrName);
    g.setColor(LABEL_COLOR);
    g.drawString(attrName, ((int) rect.getBounds2D().getWidth() / 2) - (titleWidth / 2), (int) rect.getBounds2D().getMaxY() + 33);
    // draw a border
    g.draw(rect);
    g.translate(-THUMB_WIDTH / 2, -12);
}
Also used : BasicStroke(java.awt.BasicStroke) Thumb(org.jdesktop.swingx.multislider.Thumb) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D) Point2D(java.awt.geom.Point2D)

Aggregations

Thumb (org.jdesktop.swingx.multislider.Thumb)9 BasicStroke (java.awt.BasicStroke)6 Graphics2D (java.awt.Graphics2D)6 Point2D (java.awt.geom.Point2D)6 Polygon (java.awt.Polygon)5 BufferedImage (java.awt.image.BufferedImage)3 ImageIcon (javax.swing.ImageIcon)3 ContinuousMappingPoint (org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint)3 Color (java.awt.Color)2 GradientPaint (java.awt.GradientPaint)2 Paint (java.awt.Paint)2 Point (java.awt.Point)2 Rectangle (java.awt.Rectangle)1 AffineTransform (java.awt.geom.AffineTransform)1 Rectangle2D (java.awt.geom.Rectangle2D)1