Example usage for java.awt Graphics2D setColor

List of usage examples for java.awt Graphics2D setColor

Introduction

In this page you can find the example usage for java.awt Graphics2D setColor.

Prototype

public abstract void setColor(Color c);

Source Link

Document

Sets this graphics context's current color to the specified color.

Usage

From source file:org.forester.archaeopteryx.TreePanel.java

final private void paintGainedAndLostCharacters(final Graphics2D g, final PhylogenyNode node,
        final String gained, final String lost) {
    if (node.getParent() != null) {
        final double parent_x = node.getParent().getXcoord();
        final double x = node.getXcoord();
        g.setFont(getTreeFontSet().getLargeFont());
        g.setColor(getTreeColorSet().getGainedCharactersColor());
        if (Constants.SPECIAL_CUSTOM) {
            g.setColor(Color.BLUE);
        }/* w  ww  .j  a v  a  2s . c o  m*/
        TreePanel.drawString(gained,
                parent_x + ((x - parent_x - getTreeFontSet()._fm_large.stringWidth(gained)) / 2),
                (node.getYcoord() - getTreeFontSet()._fm_large.getMaxDescent()) - 1, g);
        g.setColor(getTreeColorSet().getLostCharactersColor());
        TreePanel.drawString(lost,
                parent_x + ((x - parent_x - getTreeFontSet()._fm_large.stringWidth(lost)) / 2),
                (node.getYcoord() + getTreeFontSet()._fm_large.getMaxAscent()) + 1, g);
    }
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void paintNodeLite(final Graphics2D g, final PhylogenyNode node) {
    if (node.isCollapse()) {
        if ((!node.isRoot() && !node.getParent().isCollapse()) || node.isRoot()) {
            paintCollapsedNode(g, node, false, false, false);
        }/*from  w  w  w . ja v  a  2  s  . c  om*/
        return;
    }
    if (isInFoundNodes(node)) {
        g.setColor(getTreeColorSet().getFoundColor());
        drawRectFilled(node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g);
    }
    float new_x = 0;
    if (!node.isExternal() && !node.isCollapse()) {
        boolean first_child = true;
        float y2 = 0.0f;
        final int parent_max_branch_to_leaf = getMaxBranchesToLeaf(node);
        for (int i = 0; i < node.getNumberOfDescendants(); ++i) {
            final PhylogenyNode child_node = node.getChildNode(i);
            int factor_x;
            if (!isUniformBranchLengthsForCladogram()) {
                factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
            } else {
                factor_x = parent_max_branch_to_leaf - getMaxBranchesToLeaf(child_node);
            }
            if (first_child) {
                first_child = false;
                y2 = node.getYSecondary() - (getOvYDistance()
                        * (node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes()));
            } else {
                y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
            }
            final float x2 = calculateOvBranchLengthToParent(child_node, factor_x);
            new_x = x2 + node.getXSecondary();
            final float diff_y = node.getYSecondary() - y2;
            final float diff_x = node.getXSecondary() - new_x;
            if ((diff_y > 2) || (diff_y < -2) || (diff_x > 2) || (diff_x < -2)) {
                paintBranchLite(g, node.getXSecondary(), new_x, node.getYSecondary(), y2, child_node);
            }
            child_node.setXSecondary(new_x);
            child_node.setYSecondary(y2);
            y2 += getOvYDistance() * child_node.getNumberOfExternalNodes();
        }
    }
}

From source file:org.forester.archaeopteryx.TreePanel.java

/**
 * Draw a box at the indicated node./*from   ww  w.ja va 2 s  .  c o m*/
 * 
 * @param x
 * @param y
 * @param node
 * @param g
 */
final private void paintNodeBox(final double x, final double y, final PhylogenyNode node, final Graphics2D g,
        final boolean to_pdf, final boolean to_graphics_file, final boolean is_in_found_nodes) {
    if (node.isCollapse()) {
        return;
    }
    // if this node should be highlighted, do so
    if ((_highlight_node == node) && !to_pdf && !to_graphics_file) {
        g.setColor(getTreeColorSet().getFoundColor());

        drawOval(x - 8, y - 8, 16, 16, g);
        drawOval(x - 9, y - 8, 17, 17, g);
        drawOval(x - 9, y - 9, 18, 18, g);

        //            drawOval( x - 20, y - 8, 16, 16, g );
        //            drawOval( x - 21, y - 8, 17, 17, g );
        //            drawOval( x - 21, y - 9, 18, 18, g );

    }
    if (is_in_found_nodes) {
        paintFoundNode(ForesterUtil.roundToInt(x), ForesterUtil.roundToInt(y), g);
    } else {
        if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) {
            g.setColor(Color.BLACK);
        } else if (getControlPanel().isEvents() && Util.isHasAssignedEvent(node)) {
            final Event event = node.getNodeData().getEvent();
            if (event.isDuplication()) {
                g.setColor(getTreeColorSet().getDuplicationBoxColor());
            } else if (event.isSpeciation()) {
                g.setColor(getTreeColorSet().getSpecBoxColor());
            } else if (event.isSpeciationOrDuplication()) {
                g.setColor(getTreeColorSet().getDuplicationOrSpeciationColor());
            }
        } else {
            assignGraphicsForNodeBoxWithColorForParentBranch(node, g);
        }
        if ((getOptions().isShowNodeBoxes() && !to_pdf && !to_graphics_file)
                || (getControlPanel().isEvents() && node.isHasAssignedEvent())) {
            if (to_pdf || to_graphics_file) {
                if (node.isDuplication() || !getOptions().isPrintBlackAndWhite()) {
                    drawOvalFilled(x - HALF_BOX_SIZE, y - HALF_BOX_SIZE, BOX_SIZE, BOX_SIZE, g);
                }
            } else {
                // if the option show boxes is activated then draw boxes corresponding to the inserted reads below.
                if (node.getNodeData().isHasSequence()) {

                    double max_box_size = 20.0;
                    double most_inserts = Double
                            .valueOf(((Annotation) node.getNodeData().getSequences().get(0).getAnnotation(0))
                                    .getDesc().split(",")[0]);
                    List<PhylogenyNode> descendants = node.getAllExternalDescendants();
                    double inserts = 0.0;
                    for (int i = 1; i < descendants.size(); i++) { // first node does not get into account, because we want to only the branches after the node to count
                        inserts = inserts + ((double) descendants.get(i).getNodeData().getSequences().size())
                                - 1.0; //first sequence tag is always the histogram   
                    }

                    final double NODE_SIZE = 3.0 + max_box_size * inserts / most_inserts;
                    final double HALF_NODE_SIZE = NODE_SIZE / 2.0;
                    drawRectFilled(x - HALF_NODE_SIZE, y - HALF_NODE_SIZE, NODE_SIZE, NODE_SIZE, g);
                } else {
                    final double NODE_SIZE = 3.0;
                    final double HALF_NODE_SIZE = 1.5;
                    drawRectFilled(x - HALF_NODE_SIZE, y - HALF_NODE_SIZE, NODE_SIZE, NODE_SIZE, g);
                }
                //drawRectFilled( x - HALF_BOX_SIZE, y - HALF_BOX_SIZE, BOX_SIZE, BOX_SIZE, g );
            }
        }
    }
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private int paintTaxonomy(final Graphics2D g, final PhylogenyNode node, final boolean is_in_found_nodes,
        final boolean to_pdf, final boolean to_graphics_file) {
    final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
    g.setFont(getTreeFontSet().getLargeItalicFont());
    if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) {
        g.setColor(Color.BLACK);
    } else if (is_in_found_nodes) {
        g.setFont(getTreeFontSet().getLargeItalicFont().deriveFont(TreeFontSet.BOLD_AND_ITALIC));
        g.setColor(getTreeColorSet().getFoundColor());
    } else if (getControlPanel().isColorAccordingToTaxonomy()) {
        g.setColor(getTaxonomyBasedColor(node));
    } else {/*from  w w w  .  ja v  a  2s  .  c  om*/
        g.setColor(getTreeColorSet().getTaxonomyColor());
    }
    final double start_x = node.getXcoord() + 3 + TreePanel.HALF_BOX_SIZE;
    final double start_y = node.getYcoord()
            + (getTreeFontSet()._fm_large.getAscent() / (node.getNumberOfDescendants() == 1 ? 1 : 3.0));
    _sb.setLength(0);
    if (_control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty(taxonomy.getTaxonomyCode())) {
        _sb.append(taxonomy.getTaxonomyCode());
        _sb.append(" ");
    }
    if (_control_panel.isShowTaxonomyNames()) {
        if (!ForesterUtil.isEmpty(taxonomy.getScientificName())
                && !ForesterUtil.isEmpty(taxonomy.getCommonName())) {
            _sb.append(taxonomy.getScientificName());
            _sb.append(" (");
            _sb.append(taxonomy.getCommonName());
            _sb.append(") ");
        } else if (!ForesterUtil.isEmpty(taxonomy.getScientificName())) {
            _sb.append(taxonomy.getScientificName());
            _sb.append(" ");
        } else if (!ForesterUtil.isEmpty(taxonomy.getCommonName())) {
            _sb.append(taxonomy.getCommonName());
            _sb.append(" ");
        }
    }
    final String label = _sb.toString();
    /* GUILHEM_BEG */
    if ((label.length() > 0) && (node.getNodeData().isHasSequence())
            && node.getNodeData().getSequence().equals(_query_sequence)) {
        // invert font color and background color to show that this is the query sequence
        final Rectangle2D nodeTextBounds = new TextLayout(label, g.getFont(),
                new FontRenderContext(null, false, false)).getBounds();
        g.fillRect((int) start_x - 1, (int) start_y - 8, (int) nodeTextBounds.getWidth() + 4, 11);
        g.setColor(getTreeColorSet().getBackgroundColor());
    }
    /* GUILHEM_END */
    TreePanel.drawString(label, start_x, start_y, g);
    if (is_in_found_nodes) {
        return getTreeFontSet()._fm_large_italic_bold.stringWidth(label);
    } else {
        return getTreeFontSet()._fm_large_italic.stringWidth(label);
    }
}

From source file:de.tor.tribes.ui.panels.MinimapPanel.java

private boolean redraw() {
    Village[][] mVisibleVillages = DataHolder.getSingleton().getVillages();

    if (mVisibleVillages == null || mBuffer == null) {
        return false;
    }//from w ww.  ja  v  a2 s  .  c o  m

    Graphics2D g2d = (Graphics2D) mBuffer.getGraphics();
    Composite tempC = g2d.getComposite();
    //clear
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));
    g2d.fillRect(0, 0, mBuffer.getWidth(), mBuffer.getHeight());

    //reset composite
    g2d.setComposite(tempC);

    boolean markPlayer = GlobalOptions.getProperties().getBoolean("mark.villages.on.minimap");
    if (ServerSettings.getSingleton().getMapDimension() == null) {
        //could not draw minimap if dimensions are not loaded yet
        return false;
    }
    boolean showBarbarian = GlobalOptions.getProperties().getBoolean("show.barbarian");

    Color DEFAULT = Constants.DS_DEFAULT_MARKER;
    try {
        int mark = Integer.parseInt(GlobalOptions.getProperty("default.mark"));
        if (mark == 0) {
            DEFAULT = Constants.DS_DEFAULT_MARKER;
        } else if (mark == 1) {
            DEFAULT = Color.RED;
        } else if (mark == 2) {
            DEFAULT = Color.WHITE;
        }
    } catch (Exception e) {
        DEFAULT = Constants.DS_DEFAULT_MARKER;
    }

    Rectangle mapDim = ServerSettings.getSingleton().getMapDimension();
    double wField = mapDim.getWidth() / (double) visiblePart.width;
    double hField = mapDim.getHeight() / (double) visiblePart.height;

    UserProfile profile = GlobalOptions.getSelectedProfile();
    Tribe currentTribe = InvalidTribe.getSingleton();
    if (profile != null) {
        currentTribe = profile.getTribe();
    }

    for (int i = visiblePart.x; i < (visiblePart.width + visiblePart.x); i++) {
        for (int j = visiblePart.y; j < (visiblePart.height + visiblePart.y); j++) {
            Village v = mVisibleVillages[i][j];
            if (v != null) {
                Color markerColor = null;
                boolean isLeft = false;
                if (v.getTribe() == Barbarians.getSingleton()) {
                    isLeft = true;
                } else {
                    if ((currentTribe != null) && (v.getTribe().getId() == currentTribe.getId())) {
                        //village is owned by current player. mark it dependent on settings
                        if (markPlayer) {
                            markerColor = Color.YELLOW;
                        }
                    } else {
                        try {
                            Marker marker = MarkerManager.getSingleton().getMarker(v.getTribe());
                            if (marker != null && !marker.isShownOnMap()) {
                                marker = null;
                                markerColor = DEFAULT;
                            }

                            if (marker == null) {
                                marker = MarkerManager.getSingleton().getMarker(v.getTribe().getAlly());
                                if (marker != null && marker.isShownOnMap()) {
                                    markerColor = marker.getMarkerColor();
                                }
                            } else {
                                if (marker.isShownOnMap()) {
                                    markerColor = marker.getMarkerColor();
                                }
                            }
                        } catch (Exception e) {
                            markerColor = null;
                        }
                    }
                }

                if (!isLeft) {
                    if (markerColor != null) {
                        g2d.setColor(markerColor);
                    } else {
                        g2d.setColor(DEFAULT);
                    }
                    g2d.fillRect((int) Math.round((i - visiblePart.x) * wField),
                            (int) Math.round((j - visiblePart.y) * hField), (int) Math.floor(wField),
                            (int) Math.floor(hField));
                } else {
                    if (showBarbarian) {
                        g2d.setColor(Color.LIGHT_GRAY);
                        g2d.fillRect((int) Math.round((i - visiblePart.x) * wField),
                                (int) Math.round((j - visiblePart.y) * hField), (int) Math.floor(wField),
                                (int) Math.floor(hField));
                    }
                }
            }
        }
    }

    try {
        if (GlobalOptions.getProperties().getBoolean("map.showcontinents")) {
            g2d.setColor(Color.BLACK);
            Composite c = g2d.getComposite();
            Composite a = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
            Font f = g2d.getFont();
            Font t = new Font("Serif", Font.BOLD, (int) Math.round(30 * hField));
            g2d.setFont(t);
            int fact = 10;
            int mid = (int) Math.round(50 * wField);

            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    g2d.setComposite(a);

                    String conti = "K" + (j * 10 + i);
                    Rectangle2D bounds = g2d.getFontMetrics(t).getStringBounds(conti, g2d);
                    int cx = i * fact * 10 - visiblePart.x;
                    int cy = j * fact * 10 - visiblePart.y;
                    cx = (int) Math.round(cx * wField);
                    cy = (int) Math.round(cy * hField);
                    g2d.drawString(conti, (int) Math.rint(cx + mid - bounds.getWidth() / 2),
                            (int) Math.rint(cy + mid + bounds.getHeight() / 2));
                    g2d.setComposite(c);
                    int wk = 100;
                    int hk = 100;

                    if (i == 9) {
                        wk -= 1;
                    }
                    if (j == 9) {
                        hk -= 1;
                    }

                    g2d.drawRect(cx, cy, (int) Math.round(wk * wField), (int) Math.round(hk * hField));
                }
            }
            g2d.setFont(f);
        }
    } catch (Exception e) {
        logger.error("Creation of Minimap failed", e);
    }
    g2d.dispose();
    return true;
}

From source file:org.forester.archaeopteryx.TreePanel.java

final void paintBranchCircularLite(final PhylogenyNode p, final PhylogenyNode c, final Graphics2D g) {
    final double angle = _urt_nodeid_angle_map.get(c.getNodeId());
    final double root_x = _root.getXSecondary();
    final double root_y = _root.getYSecondary();
    final double dx = root_x - p.getXSecondary();
    final double dy = root_y - p.getYSecondary();
    final double arc = (_urt_nodeid_angle_map.get(p.getNodeId())) - angle;
    final double parent_radius = Math.sqrt(dx * dx + dy * dy);
    g.setColor(getTreeColorSet().getOvColor());
    if ((c.isFirstChildNode() || c.isLastChildNode()) && (Math.abs(arc) > 0.02)) {
        final double r2 = 2.0 * parent_radius;
        drawArc(root_x - parent_radius, root_y - parent_radius, r2, r2, (-angle - arc), arc, g);
    }/*w w  w  . jav  a2  s .c  om*/
    drawLine(c.getXSecondary(), c.getYSecondary(), root_x + (Math.cos(angle) * parent_radius),
            root_y + (Math.sin(angle) * parent_radius), g);
    if (isInFoundNodes(c)) {
        g.setColor(getTreeColorSet().getFoundColor());
        drawRectFilled(c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g);
    }
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void paintNodeDataUnrootedCirc(final Graphics2D g, final PhylogenyNode node, final boolean to_pdf,
        final boolean to_graphics_file, final boolean radial_labels, final double ur_angle,
        final boolean is_in_found_nodes) {
    if (isNodeDataInvisibleUnrootedCirc(node) && !to_graphics_file && !to_pdf) {
        return;//from   w w  w .j  av a  2 s  .c  om
    }
    if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) {
        g.setColor(Color.BLACK);
    } else if (is_in_found_nodes) {
        g.setColor(getTreeColorSet().getFoundColor());
    } else if (getControlPanel().isColorAccordingToTaxonomy()) {
        g.setColor(getTaxonomyBasedColor(node));
    } else {
        g.setColor(getTreeColorSet().getSequenceColor());
    }
    _sb.setLength(0);
    _sb.append(" ");
    if (node.getNodeData().isHasTaxonomy()
            && (getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyNames())) {
        final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
        if (_control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty(taxonomy.getTaxonomyCode())) {
            _sb.append(taxonomy.getTaxonomyCode());
            _sb.append(" ");
        }
        if (_control_panel.isShowTaxonomyNames()) {
            if (!ForesterUtil.isEmpty(taxonomy.getScientificName())
                    && !ForesterUtil.isEmpty(taxonomy.getCommonName())) {
                _sb.append(taxonomy.getScientificName());
                _sb.append(" (");
                _sb.append(taxonomy.getCommonName());
                _sb.append(") ");
            } else if (!ForesterUtil.isEmpty(taxonomy.getScientificName())) {
                _sb.append(taxonomy.getScientificName());
                _sb.append(" ");
            } else if (!ForesterUtil.isEmpty(taxonomy.getCommonName())) {
                _sb.append(taxonomy.getCommonName());
                _sb.append(" ");
            }
        }
    }
    if (node.isCollapse() && ((!node.isRoot() && !node.getParent().isCollapse()) || node.isRoot())) {
        _sb.append(" [");
        _sb.append(node.getAllExternalDescendants().size());
        _sb.append("]");
    }
    if (getControlPanel().isShowNodeNames() && (node.getNodeName().length() > 0)) {
        if (_sb.length() > 0) {
            _sb.append(" ");
        }
        _sb.append(node.getNodeName());
    }
    if (node.getNodeData().isHasSequence()) {
        if (getControlPanel().isShowSequenceAcc()
                && (node.getNodeData().getSequence().getAccession() != null)) {
            if (_sb.length() > 0) {
                _sb.append(" ");
            }
            if (!ForesterUtil.isEmpty(node.getNodeData().getSequence().getAccession().getSource())) {
                _sb.append(node.getNodeData().getSequence().getAccession().getSource());
                _sb.append(":");
            }
            _sb.append(node.getNodeData().getSequence().getAccession().getValue());
        }
        if (getControlPanel().isShowGeneNames() && (node.getNodeData().getSequence().getName().length() > 0)) {
            //                if ( _sb.length() > 0 ) {
            //                    _sb.append( " " );
            //                }
            //                _sb.append( node.getNodeData().getSequence().getName() );
            PhylogenyNode parent = node.getParent();
            double x1 = parent.getXcoord();
            double y1 = parent.getYcoord();
            double x2 = node.getXcoord();
            double y2 = node.getYcoord();
            double above_the_line = 1.0;

            if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) {
                double center_of_branch_x = Math.abs(x1 + x2) / 2.0;
                double center_of_branch_y = Math.abs(y1 + y2) / 2.0;
                TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x,
                        center_of_branch_y - above_the_line, g);
            }
        }
    }
    g.setFont(getTreeFontSet().getLargeFont());
    if (is_in_found_nodes) {
        g.setFont(getTreeFontSet().getLargeFont().deriveFont(Font.BOLD));
    }
    if (_sb.length() > 1) {
        final String sb_str = _sb.toString();
        double m = 0;
        if (_graphics_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR) {
            m = _urt_nodeid_angle_map.get(node.getNodeId()) % TWO_PI;
        } else {
            m = (float) (ur_angle % TWO_PI);
        }
        _at = g.getTransform();
        boolean need_to_reset = false;
        final float x_coord = node.getXcoord();
        final float y_coord = node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / 3.0f);
        if (radial_labels) {
            need_to_reset = true;
            boolean left = false;
            if ((m > HALF_PI) && (m < ONEHALF_PI)) {
                m -= PI;
                left = true;
            }
            g.rotate(m, x_coord, node.getYcoord());
            if (left) {
                g.translate(-(getTreeFontSet()._fm_large.getStringBounds(sb_str, g).getWidth()), 0);
            }
        } else {
            if ((m > HALF_PI) && (m < ONEHALF_PI)) {
                need_to_reset = true;
                g.translate(-getTreeFontSet()._fm_large.getStringBounds(sb_str, g).getWidth(), 0);
            }
        }
        TreePanel.drawString(sb_str, x_coord, y_coord, g);
        if (need_to_reset) {
            g.setTransform(_at);
        }
    }
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void paintScale(final Graphics2D g, int x1, int y1, final boolean to_pdf,
        final boolean to_graphics_file) {
    if (!getControlPanel().isDrawPhylogram() || (getScaleDistance() <= 0.0)) {
        return;//from w ww.jav  a  2  s . co  m
    }
    x1 += MOVE;
    final double x2 = x1 + (getScaleDistance() * getXcorrectionFactor());
    y1 -= 12;
    final int y2 = y1 - 8;
    final int y3 = y1 - 4;
    g.setFont(getTreeFontSet().getSmallFont());
    if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) {
        g.setColor(Color.BLACK);
    } else {
        g.setColor(getTreeColorSet().getBranchLengthColor());
    }
    drawLine(x1, y1, x1, y2, g);
    drawLine(x2, y1, x2, y2, g);
    drawLine(x1, y3, x2, y3, g);
    if (getScaleLabel() != null) {
        g.drawString(getScaleLabel(), (x1 + 2), y3 - 2);
    }
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void paintOvRectangle(final Graphics2D g) {
    final float w_ratio = (float) getWidth() / getVisibleRect().width;
    final float h_ratio = (float) getHeight() / getVisibleRect().height;
    final float x_ratio = (float) getWidth() / getVisibleRect().x;
    final float y_ratio = (float) getHeight() / getVisibleRect().y;
    final float width = getOvMaxWidth() / w_ratio;
    final float height = getOvMaxHeight() / h_ratio;
    final float x = getVisibleRect().x + getOvXPosition() + getOvMaxWidth() / x_ratio;
    final float y = getVisibleRect().y + getOvYPosition() + getOvMaxHeight() / y_ratio;
    g.setColor(getTreeColorSet().getFoundColor());
    getOvRectangle().setRect(x, y, width, height);
    if ((width < 6) && (height < 6)) {
        drawRectFilled(x, y, 6, 6, g);// ww w  .j  a  va2s . c o m
        getOvVirtualRectangle().setRect(x, y, 6, 6);
    } else if (width < 6) {
        drawRectFilled(x, y, 6, height, g);
        getOvVirtualRectangle().setRect(x, y, 6, height);
    } else if (height < 6) {
        drawRectFilled(x, y, width, 6, g);
        getOvVirtualRectangle().setRect(x, y, width, 6);
    } else {
        drawRect(x, y, width, height, g);
        if (isInOvRect()) {
            drawRect(x + 1, y + 1, width - 2, height - 2, g);
        }
        getOvVirtualRectangle().setRect(x, y, width, height);
    }
}

From source file:org.forester.archaeopteryx.TreePanel.java

final void paintPhylogeny(final Graphics2D g, final boolean to_pdf, final boolean to_graphics_file,
        final int graphics_file_width, final int graphics_file_height, final int graphics_file_x,
        final int graphics_file_y) {
    /* GUILHEM_BEG */
    _query_sequence = _control_panel.getSelectedQuerySequence();
    /* GUILHEM_END */
    // Color the background
    if (!to_pdf) {
        final Rectangle r = getVisibleRect();
        if (!getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite()) {
            g.setColor(getTreeColorSet().getBackgroundColor());
            if (!to_graphics_file) {
                g.fill(r);/*from   w ww .j av  a 2 s  .  c o  m*/
            } else {
                if (getOptions().isPrintBlackAndWhite()) {
                    g.setColor(Color.WHITE);
                }
                g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height);
            }
        } else {
            if (!to_graphics_file) {
                g.setPaint(new GradientPaint(r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x,
                        r.y + r.height, getTreeColorSet().getBackgroundColorGradientBottom()));
                g.fill(r);
            } else {
                g.setPaint(new GradientPaint(graphics_file_x, graphics_file_y,
                        getTreeColorSet().getBackgroundColor(), graphics_file_x,
                        graphics_file_y + graphics_file_height,
                        getTreeColorSet().getBackgroundColorGradientBottom()));
                g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height);
            }
        }
        g.setStroke(new BasicStroke(1));
    } else {
        g.setStroke(new BasicStroke(getOptions().getPrintLineWidth()));
    }
    if ((getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED)
            && (getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)) {
        _external_node_index = 0;
        // Position starting X of tree
        if (!_phylogeny.isRooted()) {
            _phylogeny.getRoot().setXcoord(TreePanel.MOVE);
        } else if ((_phylogeny.getRoot().getDistanceToParent() > 0.0) && getControlPanel().isDrawPhylogram()) {
            _phylogeny.getRoot().setXcoord((float) (TreePanel.MOVE
                    + (_phylogeny.getRoot().getDistanceToParent() * getXcorrectionFactor())));
        } else {
            _phylogeny.getRoot().setXcoord(TreePanel.MOVE + getXdistance());
        }
        // Position starting Y of tree
        _phylogeny.getRoot().setYcoord(
                (getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes()) + (TreePanel.MOVE / 2.0f));
        final int dynamic_hiding_factor = (int) (getTreeFontSet()._fm_large.getHeight()
                / (1.5 * getYdistance()));
        if (getControlPanel().isDynamicallyHideData()) {
            if (dynamic_hiding_factor > 1) {
                getControlPanel().setDynamicHidingIsOn(true);
            } else {
                getControlPanel().setDynamicHidingIsOn(false);
            }
        }
        final PhylogenyNodeIterator it;
        for (it = _phylogeny.iteratorPreorder(); it.hasNext();) {
            paintNodeRectangular(g, it.next(), to_pdf,
                    getControlPanel().isDynamicallyHideData() && (dynamic_hiding_factor > 1),
                    dynamic_hiding_factor, to_graphics_file);
        }
        if (getOptions().isShowScale()) {
            if (!(to_graphics_file || to_pdf)) {
                paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf,
                        to_graphics_file);
            } else {
                paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf,
                        to_graphics_file);
            }
        }
        if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) {
            paintPhylogenyLite(g);
        }
    } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) {
        if (getControlPanel().getDynamicallyHideData() != null) {
            getControlPanel().setDynamicHidingIsOn(false);
        }
        final double angle = getStartingAngle();
        final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL;
        _dynamic_hiding_factor = 0;
        if (getControlPanel().isDynamicallyHideData()) {
            _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5
                    * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * 10));
        }
        if (getControlPanel().getDynamicallyHideData() != null) {
            if (_dynamic_hiding_factor > 1) {
                getControlPanel().setDynamicHidingIsOn(true);
            } else {
                getControlPanel().setDynamicHidingIsOn(false);
            }
        }
        paintUnrooted(_phylogeny.getRoot(), angle, (float) (angle + 2 * Math.PI), radial_labels, g, to_pdf,
                to_graphics_file);
        if (getOptions().isShowScale()) {
            if (!(to_graphics_file || to_pdf)) {
                paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf,
                        to_graphics_file);
            } else {
                paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf,
                        to_graphics_file);
            }
        }
        if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) {
            g.setColor(getTreeColorSet().getOvColor());
            paintUnrootedLite(_phylogeny.getRoot(), angle, angle + 2 * Math.PI, g,
                    (getUrtFactorOv() / (getVisibleRect().width / getOvMaxWidth())));
            paintOvRectangle(g);
        }
    } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR) {
        final int radius = (int) ((Math.min(getPreferredSize().getWidth(), getPreferredSize().getHeight()) / 2)
                - (MOVE + getLongestExtNodeInfo()));
        final int d = radius + MOVE + getLongestExtNodeInfo();
        _dynamic_hiding_factor = 0;
        if (getControlPanel().isDynamicallyHideData() && (radius > 0)) {
            _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5
                    * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * radius));
        }
        if (getControlPanel().getDynamicallyHideData() != null) {
            if (_dynamic_hiding_factor > 1) {
                getControlPanel().setDynamicHidingIsOn(true);
            } else {
                getControlPanel().setDynamicHidingIsOn(false);
            }
        }
        paintCircular(_phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf,
                to_graphics_file);
        if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) {
            final int radius_ov = (int) (getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2
                    : getOvMaxWidth() / 2);
            double x_scale = 1.0;
            double y_scale = 1.0;
            int x_pos = getVisibleRect().x + getOvXPosition();
            int y_pos = getVisibleRect().y + getOvYPosition();
            if (getWidth() > getHeight()) {
                x_scale = (double) getHeight() / getWidth();
                x_pos = ForesterUtil.roundToInt(x_pos / x_scale);
            } else {
                y_scale = (double) getWidth() / getHeight();
                y_pos = ForesterUtil.roundToInt(y_pos / y_scale);
            }
            _at = g.getTransform();
            g.scale(x_scale, y_scale);
            paintCircularLite(_phylogeny, getStartingAngle(), x_pos + radius_ov, y_pos + radius_ov,
                    (int) (radius_ov - (getLongestExtNodeInfo()
                            / (getVisibleRect().width / getOvRectangle().getWidth()))),
                    g);
            g.setTransform(_at);
            paintOvRectangle(g);
        }
    }
}