Example usage for java.awt Graphics drawImage

List of usage examples for java.awt Graphics drawImage

Introduction

In this page you can find the example usage for java.awt Graphics drawImage.

Prototype

public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer);

Source Link

Document

Draws as much of the specified image as is currently available.

Usage

From source file:com.lfv.lanzius.server.WorkspaceView.java

@Override
protected void paintComponent(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    Document doc = server.getDocument();

    Color storedCol = g.getColor();
    Font storedFont = g.getFont();

    // Fill workspace area
    g.setColor(getBackground());/*from www  .  j av a2  s  .c o  m*/
    g.fillRect(0, 0, w, h);

    // Should the cached version be updated?
    int updateDocumentVersion = server.getDocumentVersion();
    boolean update = (documentVersion != updateDocumentVersion);

    // Check if we have cached the latest document version, otherwise cache the terminals
    if (update) {
        log.debug("Updating view to version " + updateDocumentVersion);
        terminalMap.clear();
        groupList.clear();
        if (doc != null) {
            synchronized (doc) {

                // Clear the visible attribute on all groups
                // except the started or paused ones
                Element egd = doc.getRootElement().getChild("GroupDefs");
                Iterator iter = egd.getChildren().iterator();
                while (iter.hasNext()) {
                    Element eg = (Element) iter.next();
                    boolean isVisible = !DomTools.getAttributeString(eg, "state", "stopped", false)
                            .equals("stopped");
                    eg.setAttribute("visible", String.valueOf(isVisible));
                }

                // Gather information about terminals and cache it
                Element etd = doc.getRootElement().getChild("TerminalDefs");
                iter = etd.getChildren().iterator();
                while (iter.hasNext()) {
                    Element et = (Element) iter.next();
                    int tid = DomTools.getAttributeInt(et, "id", 0, false);
                    if (tid > 0) {
                        // Create terminal and add it to list
                        Terminal t = new Terminal(tid, DomTools.getAttributeInt(et, "x", 0, false),
                                DomTools.getAttributeInt(et, "y", 0, false),
                                DomTools.getChildText(et, "Name", "T/" + tid, false),
                                DomTools.getAttributeBoolean(et, "online", false, false),
                                DomTools.getAttributeBoolean(et, "selected", false, false));
                        terminalMap.put(tid, t);

                        // Is the terminal monitored?
                        t.isMonitored = DomTools.getAttributeBoolean(et, "monitored", false, false);

                        // Examine the Player element under PlayerSetup
                        t.groupColor = null;
                        Element ep = DomTools.getElementFromSection(doc, "PlayerSetup", "terminalid",
                                String.valueOf(tid));

                        // Has linked player for this terminal
                        if (ep != null) {
                            StringBuffer sb = new StringBuffer();

                            // Append player name
                            sb.append(DomTools.getChildText(ep, "Name", "P/?", true));
                            sb.append(" (");

                            // Append role list
                            boolean hasRoles = false;
                            Element ers = ep.getChild("RoleSetup");
                            if (ers != null) {
                                Iterator iterr = ers.getChildren().iterator();

                                while (iterr.hasNext()) {
                                    Element er = (Element) iterr.next();
                                    String id = er.getAttributeValue("id");
                                    er = DomTools.getElementFromSection(doc, "RoleDefs", "id", id);
                                    if (er != null) {
                                        sb.append(DomTools.getChildText(er, "Name", "R/" + id, false));
                                        sb.append(", ");
                                        hasRoles = true;
                                    }
                                }
                                if (hasRoles) {
                                    // Trim last comma
                                    int len = sb.length();
                                    sb.setLength(Math.max(len - 2, 0));
                                }
                                sb.append(")");
                            }
                            t.roles = sb.toString();

                            // Is the player relocated?
                            t.isRelocated = DomTools.getAttributeBoolean(ep, "relocated", false, false);

                            // Get group name and color
                            Element eg = DomTools.getElementFromSection(doc, "GroupDefs", "id",
                                    DomTools.getAttributeString(ep, "groupid", "0", true));
                            t.groupColor = Color.lightGray;
                            if (eg != null) {
                                String sc = DomTools.getChildText(eg, "Color", null, false);
                                if (sc != null) {
                                    try {
                                        t.groupColor = Color.decode(sc);
                                    } catch (NumberFormatException ex) {
                                        log.warn("Invalid color attribute on Group node, defaulting to grey");
                                    }
                                }
                                //t.name += "  "+DomTools.getChildText(eg, "Name", "G/"+eg.getAttributeValue("id"), false);
                                t.groupName = DomTools.getChildText(eg, "Name",
                                        "G/" + eg.getAttributeValue("id"), false);

                                // This group should now be visible
                                eg.setAttribute("visible", "true");
                            } else
                                log.warn("Invalid groupid attribute on Player node, defaulting to grey");
                        }
                    } else
                        log.error("Invalid id attribute on Terminal node, skipping");
                }

                // Gather information about groups and cache it
                iter = egd.getChildren().iterator();
                while (iter.hasNext()) {
                    Element eg = (Element) iter.next();
                    if (DomTools.getAttributeBoolean(eg, "visible", false, false)) {
                        int gid = DomTools.getAttributeInt(eg, "id", 0, true);
                        if (gid > 0) {
                            Group grp = new Group(gid, DomTools.getChildText(eg, "Name", "G/" + gid, false),
                                    DomTools.getAttributeBoolean(eg, "selected", false, false));
                            groupList.add(grp);

                            // group color
                            String sc = DomTools.getChildText(eg, "Color", null, false);
                            if (sc != null) {
                                try {
                                    grp.color = Color.decode(sc);
                                } catch (NumberFormatException ex) {
                                    log.warn("Invalid color attribute on Group node, defaulting to grey");
                                }
                            }

                            // state color
                            grp.stateColor = Color.red;
                            String state = DomTools.getAttributeString(eg, "state", "stopped", false);
                            if (state.equals("started"))
                                grp.stateColor = Color.green;
                            else if (state.equals("paused"))
                                grp.stateColor = Color.orange;
                        }
                    }
                }
            }
        }
    }

    if (doc == null) {
        g.setColor(Color.black);
        String text = "No configuration loaded. Select 'Load configuration...' from the file menu.";
        g.drawString(text, (w - SwingUtilities.computeStringWidth(g.getFontMetrics(), text)) / 2, h * 5 / 12);
    } else {
        g.setFont(new Font("Dialog", Font.BOLD, 13));

        Iterator<Terminal> itert = terminalMap.values().iterator();
        while (itert.hasNext()) {
            Terminal t = itert.next();

            // Draw box
            int b = t.isSelected ? SERVERVIEW_SELECTION_BORDER : 1;
            g.setColor(Color.black);
            g.fillRect(t.x + SERVERVIEW_SELECTION_BORDER - b, t.y + SERVERVIEW_SELECTION_BORDER - b,
                    SERVERVIEW_TERMINAL_WIDTH + 2 * b, SERVERVIEW_TERMINAL_HEIGHT + 2 * b);
            g.setColor(t.groupColor == null ? Color.white : t.groupColor);
            g.fillRect(t.x + SERVERVIEW_SELECTION_BORDER, t.y + SERVERVIEW_SELECTION_BORDER,
                    SERVERVIEW_TERMINAL_WIDTH, SERVERVIEW_TERMINAL_HEIGHT);

            // Inner areas
            Rectangle r = new Rectangle(t.x + SERVERVIEW_SELECTION_BORDER + SERVERVIEW_TERMINAL_BORDER,
                    t.y + SERVERVIEW_SELECTION_BORDER + SERVERVIEW_TERMINAL_BORDER,
                    SERVERVIEW_TERMINAL_WIDTH - 2 * SERVERVIEW_TERMINAL_BORDER,
                    g.getFontMetrics().getHeight() + 4);

            g.setColor(Color.white);
            g.fillRect(r.x, r.y, r.width, r.height);
            g.fillRect(r.x, r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 2, r.width,
                    SERVERVIEW_TERMINAL_HEIGHT - 3 * SERVERVIEW_TERMINAL_BORDER - r.height - 2);
            g.setColor(Color.black);
            g.drawRect(r.x, r.y, r.width, r.height);
            g.drawRect(r.x, r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 2, r.width,
                    SERVERVIEW_TERMINAL_HEIGHT - 3 * SERVERVIEW_TERMINAL_BORDER - r.height - 2);

            // Name of terminal and group
            if (server.isaClient(t.tid)) {
                g.drawImage(indicatorIsa.getImage(), r.x + r.width - 20, r.y + SERVERVIEW_TERMINAL_HEIGHT - 26,
                        null);
            }
            g.drawString(t.name + " " + t.groupName, r.x + 4, r.y + r.height - 4);

            double px = r.x + 4;
            double py = r.y + r.height + SERVERVIEW_TERMINAL_BORDER + 5;

            // Draw monitored indicator
            if (t.isMonitored) {
                g.drawImage(indicatorMonitored.getImage(), r.x + r.width - 9, r.y + 3, null);
            }

            // Draw relocated indicator
            if (t.isRelocated) {
                g.drawImage(indicatorRelocated.getImage(), r.x + r.width - 9, r.y + 13, null);
            }

            // Draw online indicator
            r.setBounds(r.x, r.y + r.height, r.width, 3);
            g.setColor(t.isOnline ? Color.green : Color.red);
            g.fillRect(r.x, r.y, r.width, r.height);
            g.setColor(Color.black);
            g.drawRect(r.x, r.y, r.width, r.height);

            // Roles
            if (t.roles.length() > 0) {
                LineBreakMeasurer lbm = new LineBreakMeasurer(new AttributedString(t.roles).getIterator(),
                        new FontRenderContext(null, false, true));

                TextLayout layout;
                while ((layout = lbm
                        .nextLayout(SERVERVIEW_TERMINAL_WIDTH - 2 * SERVERVIEW_TERMINAL_BORDER)) != null) {
                    if (py < t.y + SERVERVIEW_TERMINAL_HEIGHT) {
                        py += layout.getAscent();
                        layout.draw((Graphics2D) g, (int) px, (int) py);
                        py += layout.getDescent() + layout.getLeading();
                    }
                }
            }
        }

        // Draw group indicators
        int nbrGroupsInRow = w
                / (2 * Constants.SERVERVIEW_SELECTION_BORDER + 2 + Constants.SERVERVIEW_GROUP_WIDTH);
        if (nbrGroupsInRow < 1)
            nbrGroupsInRow = 1;
        int nbrGroupRows = (groupList.size() + nbrGroupsInRow - 1) / nbrGroupsInRow;

        int innerWidth = Constants.SERVERVIEW_GROUP_WIDTH;
        int innerHeight = g.getFontMetrics().getHeight() + 5;

        int outerWidth = innerWidth + 2 * Constants.SERVERVIEW_SELECTION_BORDER + 2;
        int outerHeight = innerHeight + 2 * Constants.SERVERVIEW_SELECTION_BORDER + 2;

        int x = 0;
        int y = h - outerHeight * nbrGroupRows;

        g.setColor(Color.white);
        g.fillRect(0, y, w, h - y);
        g.setColor(Color.black);
        g.drawLine(0, y - 1, w - 1, y - 1);

        Iterator<Group> iterg = groupList.iterator();
        while (iterg.hasNext()) {
            Group grp = iterg.next();

            // Group box
            grp.boundingRect.setBounds(x, y, outerWidth, outerHeight);
            int b = grp.isSelected ? Constants.SERVERVIEW_SELECTION_BORDER : 1;
            g.setColor(Color.black);
            g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER - b + 1,
                    y + Constants.SERVERVIEW_SELECTION_BORDER - b + 1, innerWidth + 2 * b, innerHeight + 2 * b);
            g.setColor(grp.color);
            g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER + 1,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + 1, innerWidth, innerHeight);

            g.setColor(Color.black);
            g.drawString(grp.name, x + Constants.SERVERVIEW_SELECTION_BORDER + 4,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + innerHeight - 4 + 1);

            // Draw started indicator
            g.setColor(grp.stateColor);
            g.fillRect(x + Constants.SERVERVIEW_SELECTION_BORDER + 1,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + 1, innerWidth, 2);
            g.setColor(Color.black);
            g.drawLine(x + Constants.SERVERVIEW_SELECTION_BORDER + 1,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + 3,
                    x + Constants.SERVERVIEW_SELECTION_BORDER + 1 + innerWidth,
                    y + Constants.SERVERVIEW_SELECTION_BORDER + 3);

            x += outerWidth;
            if ((x + outerWidth) > w) {
                x = 0;
                y += outerHeight;
            }
        }
    }

    // Store cached version
    documentVersion = updateDocumentVersion;

    g.setColor(storedCol);
    g.setFont(storedFont);
}

From source file:ucar.unidata.idv.ui.ImageGenerator.java

/**
 * Process the image/*www  .  jav a  2  s  .co  m*/
 *
 * @param image The image
 * @param filename File to write the image to
 * @param node Node to process
 * @param props Extra properties
 * @param viewManager The viewmanager this image came from
 * @param imageProps  the image properties
 *
 *
 * @return The processed image
 * @throws Throwable On badness
 */
protected BufferedImage processImage(BufferedImage image, String filename, Element node, Hashtable props,
        ViewManager viewManager, Hashtable imageProps) throws Throwable {

    if (node == null) {
        return image;
    }

    if (props == null) {
        props = new Hashtable();
    }
    if (viewManager != null) {
        Animation animation = viewManager.getAnimation();
        props.put(PROP_ANIMATIONTIME, "");
        if (animation != null) {
            if (animation.getAniValue() != null) {
                props.put(PROP_ANIMATIONTIME, animation.getAniValue());
            }
        }
    }
    getProperties().putAll(props);

    NodeList elements = XmlUtil.getElements(node);
    Hashtable seenColorTable = new Hashtable();
    for (int childIdx = 0; childIdx < elements.getLength(); childIdx++) {
        boolean shouldIterateChildren = true;
        BufferedImage newImage = null;
        int imageWidth = image.getWidth(null);
        int imageHeight = image.getHeight(null);
        Element child = (Element) elements.item(childIdx);
        String tagName = child.getTagName();

        if (tagName.equals(TAG_RESIZE)) {
            newImage = ImageUtils.toBufferedImage(resize(image, child));
        } else if (tagName.equals(TAG_FILESET)) {
            //ignore
        } else if (tagName.equals(TAG_OUTPUT)) {
            processTagOutput(child);
        } else if (tagName.equals(TAG_DISPLAYLIST)) {
            if (viewManager != null) {
                newImage = ImageUtils.toBufferedImage(image, true);
                Graphics g = newImage.getGraphics();
                String valign = applyMacros(child, ATTR_VALIGN, VALUE_BOTTOM);
                Font font = getFont(child);
                if (XmlUtil.hasAttribute(child, ATTR_MATTEBG)) {
                    int height = viewManager.paintDisplayList((Graphics2D) g, null, imageWidth, imageHeight,
                            valign.equals(VALUE_BOTTOM), null, font);

                    int top = (valign.equals(VALUE_TOP) ? height : 0);
                    int bottom = (valign.equals(VALUE_BOTTOM) ? height : 0);
                    newImage = ImageUtils.matte(image, top, bottom, 0, 0,
                            applyMacros(child, ATTR_MATTEBG, Color.white));
                    g = newImage.getGraphics();
                    imageHeight += height;
                }

                Color c = applyMacros(child, ATTR_COLOR, (Color) null);
                viewManager.paintDisplayList((Graphics2D) g, null, imageWidth, imageHeight,
                        valign.equals(VALUE_BOTTOM), c, font);
            }
        } else if (tagName.equals(TAG_COLORBAR) || tagName.equals(TAG_KML_COLORBAR)) {
            // only do one colorbar if we are writing to kml
            Integer index = (Integer) props.get(PROP_IMAGEINDEX);
            if ((index != null) && (index.intValue() > 0) && tagName.equals(TAG_KML_COLORBAR)) {
                continue;
            }

            boolean showLines = applyMacros(child, ATTR_SHOWLINES, false);

            List<DisplayControlImpl> controls = (List<DisplayControlImpl>) ((viewManager != null)
                    ? viewManager.getControls()
                    : new ArrayList());

            if (XmlUtil.hasAttribute(child, ATTR_DISPLAY)) {
                DisplayControlImpl display = ((controls.size() > 0)
                        ? findDisplayControl(XmlUtil.getAttribute(child, ATTR_DISPLAY), controls)
                        : findDisplayControl(child));
                if (display == null) {
                    error("Could not find display:" + XmlUtil.toString(node));
                    return null;
                }
                controls = Misc.newList(display);
            }

            int width = applyMacros(child, ATTR_WIDTH, 150);
            int height = applyMacros(child, ATTR_HEIGHT, 20);
            int ticks = applyMacros(child, ATTR_TICKMARKS, 0);
            double interval = applyMacros(child, ATTR_INTERVAL, -1.0);
            String valuesStr = applyMacros(child, ATTR_VALUES, (String) null);
            Color c = applyMacros(child, ATTR_COLOR, Color.black);

            Color lineColor = applyMacros(child, ATTR_LINECOLOR, c);

            Rectangle imageRect = new Rectangle(0, 0, imageWidth, imageHeight);

            Point pp = ImageUtils.parsePoint(applyMacros(child, ATTR_PLACE, "ll,10,-10"), imageRect);
            Point ap = ImageUtils.parsePoint(applyMacros(child, ATTR_ANCHOR, "ll"),
                    new Rectangle(0, 0, width, height));

            String orientation = applyMacros(child, ATTR_ORIENTATION, VALUE_BOTTOM);
            boolean vertical = orientation.equals(VALUE_RIGHT) || orientation.equals(VALUE_LEFT);
            int baseY = pp.y - ap.y + (vertical ? 0 : height);
            int baseX = pp.x - ap.x;

            List colorTables = new ArrayList();
            List ranges = new ArrayList();
            List units = new ArrayList();

            boolean forKml = tagName.equals(TAG_KML_COLORBAR);

            for (int i = 0; i < controls.size(); i++) {
                DisplayControlImpl control = (DisplayControlImpl) controls.get(i);
                ColorTable colorTable = control.getColorTable();
                if (colorTable == null) {
                    continue;
                }
                Range range = control.getRangeForColorTable();
                //only do unique color tables
                Object[] key = { colorTable, range };
                if (seenColorTable.get(key) != null) {
                    continue;
                }
                seenColorTable.put(key, key);
                colorTables.add(colorTable);
                ranges.add(range);
                units.add(control.getDisplayUnit());
            }

            for (int i = 0; i < colorTables.size(); i++) {
                ColorTable colorTable = (ColorTable) colorTables.get(i);
                Range range = (Range) ranges.get(i);
                Unit unit = (Unit) units.get(i);
                Image imageToDrawIn;
                if (forKml) {
                    if (vertical) {
                        baseX = 0;
                        baseY = 0;
                    } else {
                        baseX = 0;
                        baseY = height;
                    }
                    int space = applyMacros(child, ATTR_SPACE, (vertical ? width : height));
                    imageToDrawIn = new BufferedImage(width + (vertical ? space : 0),
                            height + (vertical ? 0 : space), BufferedImage.TYPE_INT_RGB);
                } else {
                    imageToDrawIn = newImage = ImageUtils.toBufferedImage(image);
                }
                Graphics g = imageToDrawIn.getGraphics();
                if (forKml) {
                    Color bgColor = applyMacros(child, ATTR_BACKGROUND, Color.white);
                    g.setColor(bgColor);
                    g.fillRect(0, 0, imageToDrawIn.getWidth(null), imageToDrawIn.getHeight(null));
                }
                boolean includeAlpha = applyMacros(child, ATTR_TRANSPARENCY, true);

                float[][] ctValues;

                if (includeAlpha) {
                    ctValues = colorTable.getAlphaTable();
                } else {
                    ctValues = colorTable.getNonAlphaTable();
                }
                ColorMap colorMap = new BaseRGBMap(ctValues);
                ColorPreview preview = new ColorPreview(colorMap, (vertical ? width : height));
                if (vertical) {
                    preview.setSize(new Dimension(height, width));
                } else {
                    preview.setSize(new Dimension(width, height));
                }
                Image previewImage = ColorTableCanvas.getImage(colorTable, (vertical ? height : width),
                        (vertical ? width : height), includeAlpha);

                if (vertical) {
                    int imageType = includeAlpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;

                    BufferedImage tmpImage = new BufferedImage(width, height, imageType);

                    Graphics2D tmpG = (Graphics2D) tmpImage.getGraphics();
                    tmpG.rotate(Math.toRadians(90.0));
                    tmpG.drawImage(previewImage, 0, 0 - width, null);
                    previewImage = tmpImage;
                }
                if (forKml) {
                    g.drawImage(previewImage, 0, 0, null);
                } else {
                    g.drawImage(previewImage, baseX, (vertical ? baseY : baseY - height), null);
                }
                if (showLines) {
                    g.setColor(lineColor);
                    g.drawRect(baseX, (vertical ? baseY : baseY - height), width - 1,
                            height - (vertical ? 1 : 0));
                }
                setFont(g, child);
                FontMetrics fm = g.getFontMetrics();
                List values = new ArrayList();
                String suffixFrequency = XmlUtil.getAttribute(child, ATTR_SUFFIXFREQUENCY,
                        XmlUtil.getAttribute(child, ATTR_SHOWUNIT, "false")).toLowerCase();
                String unitDefault = (!suffixFrequency.equals("false")) ? " %unit%" : "";
                String labelSuffix = applyMacros(child, ATTR_SUFFIX, unitDefault);
                if (unit != null) {
                    labelSuffix = labelSuffix.replace("%unit%", "" + unit);
                } else {
                    labelSuffix = labelSuffix.replace("%unit%", "");
                }
                if (valuesStr != null) {
                    double[] valueArray = Misc.parseDoubles(valuesStr, ",");
                    for (int valueIdx = 0; valueIdx < valueArray.length; valueIdx++) {
                        values.add(new Double(valueArray[valueIdx]));
                    }
                } else if (ticks > 0) {
                    int spacing = ((ticks == 1) ? 0 : (vertical ? height : width) / (ticks - 1));
                    for (int tickIdx = 0; tickIdx < ticks; tickIdx++) {
                        double percent = ((ticks > 1) ? (double) tickIdx / (double) (ticks - 1) : 0.0);
                        values.add(new Double(range.getValueOfPercent(percent)));
                    }
                } else if (interval > 0) {
                    double value = range.getMin();
                    double max = range.getMax();
                    while (value <= max) {
                        values.add(new Double(value));
                        value += interval;
                    }
                }
                for (int valueIdx = 0; valueIdx < values.size(); valueIdx++) {
                    double value = ((Double) values.get(valueIdx)).doubleValue();
                    int x;
                    int y;
                    if (vertical) {
                        if (orientation.equals(VALUE_RIGHT)) {
                            x = baseX + width;
                        } else {
                            x = baseX;
                        }
                        y = baseY + (int) (range.getPercent(value) * height);
                        if (y > baseY + height) {
                            break;
                        }
                    } else {
                        if (orientation.equals(VALUE_BOTTOM)) {
                            y = baseY;
                        } else {
                            y = baseY - height;
                        }

                        if (range != null) {
                            x = baseX + (int) (range.getPercent(value) * width);
                        } else {
                            x = baseX;
                        }

                        if (x > baseX + width) {
                            break;
                        }
                    }
                    String tickLabel = getIdv().getDisplayConventions().format(value);
                    if (suffixFrequency.equals(VALUE_LAST) && (valueIdx == values.size() - 1)) {
                        tickLabel += labelSuffix;
                    } else if (suffixFrequency.equals(VALUE_FIRST) && (valueIdx == 0)) {
                        tickLabel += labelSuffix;
                    } else if (suffixFrequency.equals(VALUE_ALL) || suffixFrequency.equals("true")) {
                        tickLabel += labelSuffix;
                    }

                    Rectangle2D rect = fm.getStringBounds(tickLabel, g);
                    g.setColor(lineColor);
                    if (orientation.equals(VALUE_RIGHT)) {
                        g.drawLine(x + 1, y, x, y);
                        if (showLines) {
                            g.drawLine(x, y, x - width, y);
                        }
                    } else if (orientation.equals(VALUE_LEFT)) {
                        g.drawLine(x - 1, y, x, y);
                        if (showLines) {
                            g.drawLine(x, y, x + width, y);
                        }
                    } else if (orientation.equals(VALUE_BOTTOM)) {
                        g.drawLine(x, y + 1, x, y);
                        if (showLines) {
                            g.drawLine(x, y, x, y - height);
                        }
                    } else {
                        g.drawLine(x, y - 1, x, y);
                        if (showLines) {
                            g.drawLine(x, y, x, y + height);
                        }
                    }
                    g.setColor(c);
                    if (orientation.equals(VALUE_RIGHT)) {
                        int yLoc = y + (int) (rect.getHeight() / 2) - 2;
                        if (forKml) {
                            if (valueIdx == 0) {
                                yLoc = y + (int) (rect.getHeight()) - 2;
                            } else if (valueIdx == values.size() - 1) {
                                yLoc = y - (int) (rect.getHeight()) + 6;
                            }
                        }
                        g.drawString(tickLabel, x + 2, yLoc);
                    } else if (orientation.equals(VALUE_LEFT)) {
                        int xLoc = x - 2 - (int) rect.getWidth();
                        g.drawString(tickLabel, xLoc, y + (int) (rect.getHeight() / 2) - 2);
                    } else if (orientation.equals(VALUE_BOTTOM)) {
                        int xLoc = x - (int) (rect.getWidth() / 2);
                        if (forKml) {
                            if (valueIdx == 0) {
                                xLoc = x + 2;
                            } else if (valueIdx == values.size() - 1) {
                                xLoc = x - (int) rect.getWidth() + 2;
                            }
                        }
                        g.drawString(tickLabel, xLoc, y + (int) rect.getHeight() + 2);
                    } else {
                        g.drawString(tickLabel, x - (int) (rect.getWidth() / 2), y - 2);
                    }
                }
                if (vertical) {
                    baseX += width + 30;
                } else {
                    baseY += height + 30;
                }
                if (forKml) {
                    String tmpImageFile = applyMacros(child, ATTR_FILE,
                            getIdv().getStore().getTmpFile("testcolorbar${viewindex}.png"));
                    String template = "<ScreenOverlay><name>${kml.name}</name><Icon><href>${icon}</href></Icon>\n"
                            + "<overlayXY x=\"${kml.overlayXY.x}\" y=\"${kml.overlayXY.y}\" xunits=\"${kml.overlayXY.xunits}\" yunits=\"${kml.overlayXY.yunits}\"/>\n"
                            + "<screenXY x=\"${kml.screenXY.x}\" y=\"${kml.screenXY.y}\" xunits=\"${kml.screenXY.xunits}\" yunits=\"${kml.screenXY.yunits}\"/>\n"
                            + "<size x=\"${kml.size.x}\" y=\"${kml.size.y}\" xunits=\"${kml.size.xunits}\" yunits=\"${kml.size.yunits}\"/>\n"
                            + "</ScreenOverlay>\n";
                    String[] macros = { "kml.name", "kml.overlayXY.x", "kml.overlayXY.y",
                            "kml.overlayXY.xunits", "kml.overlayXY.yunits", "kml.screenXY.x", "kml.screenXY.y",
                            "kml.screenXY.xunits", "kml.screenXY.yunits", "kml.size.x", "kml.size.y",
                            "kml.size.xunits", "kml.size.yunits" };
                    String[] macroValues = { "", "0", "1", "fraction", "fraction", "0", "1", "fraction",
                            "fraction", "-1", "-1", "pixels", "pixels" };

                    for (int macroIdx = 0; macroIdx < macros.length; macroIdx++) {
                        template = template.replace("${" + macros[macroIdx] + "}",
                                applyMacros(child, macros[macroIdx], macroValues[macroIdx]));
                    }
                    template = template.replace("${icon}", IOUtil.getFileTail(tmpImageFile));
                    imageProps.put("kml", template);
                    List kmlFiles = (List) imageProps.get("kmlfiles");
                    //TODO: Only do the first one for now
                    if (kmlFiles == null) {
                        kmlFiles = new ArrayList();
                        imageProps.put("kmlfiles", kmlFiles);
                    }
                    kmlFiles.add(tmpImageFile);

                    //                        System.out.println(template);
                    ImageUtils.writeImageToFile(imageToDrawIn, tmpImageFile);
                }
            }

        } else if (tagName.equals(TAG_TRANSPARENT) || tagName.equals(TAG_BGTRANSPARENT)) {
            Color c = null;
            if (tagName.equals(TAG_BGTRANSPARENT)) {
                c = viewManager.getBackground();
            } else {
                c = applyMacros(child, ATTR_COLOR, (Color) null);
            }
            //                System.err.println ("c:" + c);
            int[] redRange = { 0, 0 };
            int[] greenRange = { 0, 0 };
            int[] blueRange = { 0, 0 };
            if (c != null) {
                //                    System.err.println("got color");
                redRange[0] = redRange[1] = c.getRed();
                greenRange[0] = greenRange[1] = c.getGreen();
                blueRange[0] = blueRange[1] = c.getBlue();
            } else {
            }
            newImage = ImageUtils.makeColorTransparent(image, redRange, greenRange, blueRange);
        } else if (tagName.equals(TAG_SHOW)) {
            JComponent contents = new JLabel(new ImageIcon(image));
            String message = applyMacros(child, ATTR_MESSAGE, (String) null);
            if (message != null) {
                contents = GuiUtils.topCenter(new JLabel(message), contents);
            }
            if (!GuiUtils.askOkCancel("Continue?", contents)) {
                throw new MyQuitException();
            }
        } else if (tagName.equals(TAG_MATTE)) {
            newImage = doMatte(image, child, 0);
        } else if (tagName.equals(TAG_LATLONLABELS)) {
            newImage = doLatLonLabels(child, viewManager, image, imageProps);
        } else if (tagName.equals(TAG_WRITE)) {
            ImageUtils.writeImageToFile(image, getImageFileName(applyMacros(child, ATTR_FILE)));

        } else if (tagName.equals(TAG_PUBLISH)) {
            getIdv().getPublishManager().publishIslImage(this, node, image);
        } else if (tagName.equals(TAG_CLIP)) {
            int[] ul;
            int[] lr;
            if (XmlUtil.hasAttribute(child, ATTR_DISPLAY)) {
                //                    System.err.println("Clipping from display");
                DisplayControlImpl dc = findDisplayControl(child);
                if (dc == null) {
                    throw new IllegalArgumentException("Could not find display:" + XmlUtil.toString(node));
                }
                NavigatedDisplay display = (NavigatedDisplay) viewManager.getMaster();
                MapProjection mapProjection = dc.getDataProjection();
                java.awt.geom.Rectangle2D rect = mapProjection.getDefaultMapArea();
                LatLonPoint llplr = mapProjection.getLatLon(new double[][] { { rect.getX() + rect.getWidth() },
                        { rect.getY() + rect.getHeight() } });
                LatLonPoint llpul = mapProjection
                        .getLatLon(new double[][] { { rect.getX() }, { rect.getY() } });
                EarthLocation ulEl = new EarthLocationTuple(llpul, new Real(RealType.Altitude, 0));
                EarthLocation lrEl = new EarthLocationTuple(llplr, new Real(RealType.Altitude, 0));
                ul = display.getScreenCoordinates(display.getSpatialCoordinates(ulEl, null));
                lr = display.getScreenCoordinates(display.getSpatialCoordinates(lrEl, null));
                //System.err.println("ul:" + ulEl + " lr:" + lrEl);
                if (ul[0] > lr[0]) {
                    int tmp = ul[0];
                    ul[0] = lr[0];
                    lr[0] = tmp;
                }
                if (ul[1] > lr[1]) {
                    int tmp = ul[1];
                    ul[1] = lr[1];
                    lr[1] = tmp;
                }
                imageProps.put(ATTR_NORTH, new Double(ulEl.getLatitude().getValue()));
                imageProps.put(ATTR_WEST, new Double(ulEl.getLongitude().getValue()));
                imageProps.put(ATTR_SOUTH, new Double(lrEl.getLatitude().getValue()));
                imageProps.put(ATTR_EAST, new Double(lrEl.getLongitude().getValue()));
            } else if ((viewManager != null) && XmlUtil.hasAttribute(child, ATTR_NORTH)) {
                NavigatedDisplay display = (NavigatedDisplay) viewManager.getMaster();
                EarthLocation el1 = DisplayControlImpl.makeEarthLocation(toDouble(child, ATTR_NORTH),
                        toDouble(child, ATTR_WEST), 0);
                EarthLocation el2 = DisplayControlImpl.makeEarthLocation(toDouble(child, ATTR_SOUTH),
                        toDouble(child, ATTR_EAST), 0);
                ul = display.getScreenCoordinates(display.getSpatialCoordinates(el1, null));
                lr = display.getScreenCoordinates(display.getSpatialCoordinates(el2, null));
                imageProps.put(ATTR_NORTH, new Double(el1.getLatitude().getValue()));
                imageProps.put(ATTR_WEST, new Double(el1.getLongitude().getValue()));
                imageProps.put(ATTR_SOUTH, new Double(el2.getLatitude().getValue()));
                imageProps.put(ATTR_EAST, new Double(el2.getLongitude().getValue()));
            } else if (XmlUtil.hasAttribute(child, ATTR_LEFT)) {
                ul = new int[] { (int) toDouble(child, ATTR_LEFT, imageWidth),
                        (int) toDouble(child, ATTR_TOP, imageHeight) };
                lr = new int[] { (int) toDouble(child, ATTR_RIGHT, imageWidth),
                        (int) toDouble(child, ATTR_BOTTOM, imageHeight) };
            } else if (viewManager != null) {
                //TODO: Clip on visad coordinates
                NavigatedDisplay display = (NavigatedDisplay) viewManager.getMaster();
                ul = display.getScreenCoordinates(new double[] { -1, 1, 0 });
                lr = display.getScreenCoordinates(new double[] { 1, -1, 0 });
                int space = applyMacros(child, ATTR_SPACE, 0);
                int hspace = applyMacros(child, ATTR_HSPACE, space);
                int vspace = applyMacros(child, ATTR_VSPACE, space);
                ul[0] -= applyMacros(child, ATTR_SPACE_LEFT, hspace);
                ul[1] -= applyMacros(child, ATTR_SPACE_TOP, vspace);
                lr[0] += applyMacros(child, ATTR_SPACE_RIGHT, hspace);
                lr[1] += applyMacros(child, ATTR_SPACE_BOTTOM, vspace);
            } else {
                continue;
            }

            for (String attr : (List<String>) Misc.newList(ATTR_NORTH, ATTR_SOUTH, ATTR_EAST, ATTR_WEST)) {
                String kmlAttr = "kml." + attr;
                if (XmlUtil.hasAttribute(child, kmlAttr)) {
                    imageProps.put(attr, new Double(applyMacros(child, kmlAttr, 0.0)));
                }
            }

            ul[0] = Math.max(0, ul[0]);
            ul[1] = Math.max(0, ul[1]);

            lr[0] = Math.min(lr[0], imageWidth);
            lr[1] = Math.min(lr[1], imageHeight);

            newImage = ImageUtils.clip(image, ul, lr);
        } else if (tagName.equals(TAG_SPLIT)) {
            shouldIterateChildren = false;
            int width = image.getWidth(null);
            int height = image.getHeight(null);
            int cols = applyMacros(child, ATTR_COLUMNS, 2);
            int rows = applyMacros(child, ATTR_ROWS, 2);
            String file = applyMacros(child, ATTR_FILE);
            int cnt = 0;
            int hSpace = width / cols;
            int vSpace = height / rows;
            for (int row = 0; row < rows; row++) {
                for (int col = 0; col < cols; col++) {
                    pushProperties();
                    Hashtable myprops = new Hashtable();
                    putProperty("row", new Integer(row));
                    putProperty("column", new Integer(col));
                    putProperty("count", new Integer(++cnt));
                    String realFile = applyMacros(file, myprops);
                    Image splitImage = image.getSubimage(hSpace * col, vSpace * row, hSpace, vSpace);
                    processImage(ImageUtils.toBufferedImage(splitImage), realFile, child, myprops, viewManager,
                            new Hashtable());
                    popProperties();
                }
            }
        } else if (tagName.equals(TAG_THUMBNAIL)) {
            shouldIterateChildren = false;
            BufferedImage thumbImage = ImageUtils.toBufferedImage(resize(image, child));
            String thumbFile = applyMacros(child, ATTR_FILE, (String) null);
            if (thumbFile == null) {
                thumbFile = IOUtil.stripExtension(filename) + "_thumb" + IOUtil.getFileExtension(filename);
            }
            processImage(thumbImage, thumbFile, child, null, viewManager, new Hashtable());
        } else if (tagName.equals(TAG_KML)) {
            //NOOP
        } else if (tagName.equals(TAG_KMZFILE)) {
            //NOOP
        } else if (tagName.equals(TAG_OVERLAY)) {
            double transparency = applyMacros(child, ATTR_TRANSPARENCY, 0.0);
            Graphics2D g = image.createGraphics();
            String imagePath = applyMacros(child, ATTR_IMAGE, (String) null);

            float scale = (float) applyMacros(child, ATTR_SCALE, 1.0);

            Rectangle imageRect = new Rectangle(0, 0, imageWidth, imageHeight);
            Point pp = ImageUtils.parsePoint(applyMacros(child, ATTR_PLACE, "lr,-10,-10"), imageRect);
            String text = applyMacros(child, ATTR_TEXT, (String) null);
            Color bg = applyMacros(child, ATTR_BACKGROUND, (Color) null);
            if (text != null) {
                double angle = Math.toRadians(applyMacros(child, ATTR_ANGLE, 0.0));
                text = applyMacros(text);
                Color c = applyMacros(child, ATTR_COLOR, Color.white);
                if ((c != null) && (transparency > 0)) {
                    c = new Color(c.getRed(), c.getGreen(), c.getBlue(), ImageUtils.toAlpha(transparency));
                }
                //Color bg = applyMacros(child, ATTR_BACKGROUND,
                //                       (Color) null);
                if ((bg != null) && (transparency > 0)) {
                    bg = new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), ImageUtils.toAlpha(transparency));
                }
                setFont(g, child);
                FontMetrics fm = g.getFontMetrics();
                Rectangle2D rect = fm.getStringBounds(text, g);
                int width = (int) rect.getWidth();
                int height = (int) (rect.getHeight());

                Point ap = ImageUtils.parsePoint(applyMacros(child, ATTR_ANCHOR, "lr,-10,-10"),
                        new Rectangle(0, 0, width, height));

                g.rotate(angle);

                if (bg != null) {
                    g.setColor(bg);
                    g.fillRect(pp.x - ap.x - 1, pp.y - ap.y - 1, (int) width + 2, (int) height + 2);
                }
                g.setColor(c);
                g.drawString(text, pp.x - ap.x, pp.y - ap.y + height);
            }

            if (imagePath != null) {
                Image overlay = ImageUtils.readImage(imagePath);
                if (overlay != null) {
                    if (transparency > 0) {
                        overlay = ImageUtils.setAlpha(overlay, transparency);
                    }

                    int width = overlay.getWidth(null);
                    int height = overlay.getHeight(null);
                    int scaledWidth = Math.round(width * scale);
                    int scaledHeight = Math.round(height * scale);

                    Image scaled = getScaledImage(overlay, scaledWidth, scaledHeight);
                    Rectangle overlayRect = new Rectangle(0, 0, scaledWidth, scaledHeight);
                    Point ap = ImageUtils.parsePoint(applyMacros(child, ATTR_ANCHOR, "lr,-10,-10"),
                            overlayRect);
                    g.drawImage(scaled, pp.x - ap.x, pp.y - ap.y, bg, null);
                }
            }
        } else {
            error("Unknown tag:" + tagName);
        }
        if (newImage != null) {
            String newFileName = applyMacros(child, ATTR_FILE, (String) null);
            if (shouldIterateChildren) {
                logger.trace("newFileName='{}' viewManager={} newImage={}", newFileName, viewManager, newImage);
                newImage = processImage(newImage, newFileName, child, null, viewManager, new Hashtable());
                logger.trace("finished processImage; result: {}", newImage);
            }
            if (newFileName != null) {
                logger.trace("calling writeImageToFile...");
                ImageUtils.writeImageToFile(newImage, getImageFileName(newFileName));
                logger.trace("finished writeImageToFile");
                debug("Writing image:" + newFileName);
            }
            if (!applyMacros(child, ATTR_COPY, false)) {
                image = newImage;
            }
        }
    }

    if (filename != null) {
        float quality = (float) applyMacros(node, ATTR_QUALITY, 1.0);
        List<String> fileToks = StringUtil.split(filename, ",", true, true);
        for (String file : fileToks) {
            file = getImageFileName(file);
            debug("Writing image:" + file);
            if (file.endsWith(FileManager.SUFFIX_KMZ) || file.endsWith(FileManager.SUFFIX_KML)) {
                GeoLocationInfo bounds = null;
                if (viewManager != null) {
                    bounds = viewManager.getVisibleGeoBounds();
                    ImageSequenceGrabber.subsetBounds(bounds, imageProps);
                    String tmpImageFile = getOutputPath(file);
                    ImageUtils.writeImageToFile(image, tmpImageFile, quality);
                    ImageWrapper imageWrapper = new ImageWrapper(tmpImageFile, null, bounds, null);
                    imageWrapper.setProperties(imageProps);
                    new ImageSequenceGrabber(file, getIdv(), this, node,
                            (List<ImageWrapper>) Misc.newList(imageWrapper), null, 1);
                }
            } else {
                logger.trace("another writeImageToFile call...");
                ImageUtils.writeImageToFile(image, file, quality);
                logger.trace("and it's done.");
            }
        }
    }
    logger.trace("result: {}", image);
    return image;
}

From source file:base.BasePlayer.ClusterTable.java

void drawScreen(Graphics g) {
    try {// ww w .  j a va  2 s  .  c o m

        buf.setColor(Color.black);
        buf.fillRect(0, 0, this.getWidth(), tablescroll.getViewport().getHeight());
        genemutcount = 0;
        hoverVar = null;
        hoverSample = -1;
        headerHover = -1;
        geneHeaderHover = -1;

        if (!mouseDrag) {
            resizeColumn = -1;
        }
        if (Main.drawCanvas.clusterNodes != null) {
            firstrow = tablescroll.getVerticalScrollBar().getValue() / rowHeight - 1
                    - Main.drawCanvas.clusterNodes.size();

            if (firstrow < 0) {
                firstrow = 0;
            }
            for (int i = 0; i < Main.drawCanvas.clusterNodes.size(); i++) {
                dot = false;

                if ((i + 1 + samplecount + Main.drawCanvas.clusterNodes.size()) * rowHeight < tablescroll
                        .getVerticalScrollBar().getValue()) {
                    continue;
                }

                if (i * rowHeight > tablescroll.getVerticalScrollBar().getValue()
                        + tablescroll.getViewport().getHeight()) {
                    break;
                }

                if (mouseY >= (rowHeight * (i + genemutcount + 1))
                        && mouseY < (rowHeight * (i + genemutcount + 2))) {
                    hoverNode = Main.drawCanvas.clusterNodes.get(i);
                }
                try {
                    buf.setColor(Color.darkGray);
                    buf.drawLine(4,
                            (rowHeight * (i + genemutcount + 1)) - tablescroll.getVerticalScrollBar().getValue()
                                    + 3,
                            this.getWidth(), (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 3);

                    buf.setColor(linecolor);
                    cluster = Main.drawCanvas.clusterNodes.get(i);
                    if (cluster.varnodes.get(0).getTranscripts() != null) {
                        if (!chrom.equals(cluster.varnodes.get(0).getTranscripts().get(0).getChrom())) {
                            chrom = cluster.varnodes.get(0).getTranscripts().get(0).getChrom();
                        }
                    } else {
                        if (!chrom.equals(cluster.varnodes.get(0).getExons().get(0).transcript.getChrom())) {
                            chrom = cluster.varnodes.get(0).getExons().get(0).transcript.getChrom();
                        }
                    }

                    for (int c = 0; c < header.size(); c++) {

                        if (Main.drawCanvas.clusterNodes.get(i).equals(hoverNode)
                                || Main.drawCanvas.clusterNodes.get(i).equals(selectedNode)) {

                            buf.setColor(Color.yellow);
                        } else {
                            buf.setColor(Color.white);
                        }

                        if (c == 0) {

                            buf.drawString("" + cluster.ID, (int) header.get(c)[1] + 5,
                                    (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 1) {
                            buf.drawString("" + cluster.nodecount, (int) header.get(c)[1] + 5,
                                    (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 2) {
                            buf.drawString("" + cluster.width, (int) header.get(c)[1] + 5,
                                    (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 3) {
                            buf.drawString(
                                    chrom + ":"
                                            + MethodLibrary.formatNumber(cluster.varnodes.get(0).getPosition()),
                                    (int) header.get(c)[1] + 5, (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 4) {
                            buf.drawString(
                                    "" + MethodLibrary.round((cluster.nodecount / (double) cluster.width), 4),
                                    (int) header.get(c)[1] + 5, (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 5) {
                            if (cluster.varnodes.get(0).getExons() != null) {

                                if (cluster.varnodes.get(0).coding) {
                                    buf.setColor(Color.red);
                                    buf.drawString(
                                            cluster.varnodes.get(0).getExons().get(0).getTranscript()
                                                    .getGenename() + " (Coding)",
                                            (int) header.get(c)[1] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);

                                } else {
                                    buf.setColor(Color.lightGray);
                                    buf.drawString(
                                            cluster.varnodes.get(0).getExons().get(0).getTranscript()
                                                    .getGenename() + " (UTR)",
                                            (int) header.get(c)[1] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);

                                }
                            } else if (cluster.varnodes.get(0).isInGene()) {
                                buf.setColor(Color.lightGray);
                                buf.drawString(
                                        cluster.varnodes.get(0).getTranscripts().get(0).getGenename()
                                                + " (Intronic)",
                                        (int) header.get(c)[1] + 5, (rowHeight * (i + 1 + genemutcount))
                                                - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            } else {
                                buf.setColor(Color.gray);
                                if (!cluster.varnodes.get(0).getTranscripts().get(0)
                                        .equals(cluster.varnodes.get(0).getTranscripts().get(1))) {
                                    buf.drawString(
                                            cluster.varnodes.get(0).getTranscripts().get(0).getGenename()
                                                    + " ... "
                                                    + cluster.varnodes
                                                            .get(0).getTranscripts().get(1).getGenename(),
                                            (int) header.get(c)[1] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);

                                } else {
                                    if (cluster.varnodes.get(0).getTranscripts().get(0)
                                            .getEnd() > cluster.varnodes.get(0).getPosition()) {
                                        buf.drawString(
                                                " ... " + cluster.varnodes
                                                        .get(0).getTranscripts().get(0).getGenename(),
                                                (int) header.get(c)[1] + 5,
                                                (rowHeight * (i + 1 + genemutcount))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);
                                    } else {
                                        buf.drawString(
                                                cluster.varnodes.get(0).getTranscripts().get(0).getGenename()
                                                        + " ... ",
                                                (int) header.get(c)[1] + 5,
                                                (rowHeight * (i + 1 + genemutcount))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);

                                    }
                                }
                            }
                        } else if (c == 6) {

                            if (cluster.varnodes.get(0).getBedHits() != null) {
                                bedarray = MethodLibrary.makeTrackArray(cluster.varnodes.get(0), null);
                                for (int b = 0; b < bedarray.length; b++) {
                                    buf.setColor(Color.black);
                                    if (b == bedarray.length - 1) {
                                        buf.fillRect((int) header.get(c + b)[1] + 1,
                                                (rowHeight * (i + genemutcount + 1))
                                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                this.getWidth() - (int) header.get(c + b)[1], rowHeight - 1);
                                    } else {
                                        buf.fillRect((int) header.get(c + b)[1] + 1,
                                                (rowHeight * (i + genemutcount + 1))
                                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                (int) header.get(c + b)[2], rowHeight - 1);

                                    }
                                    buf.setColor(Color.white);
                                    if (bedarray[b] != null) {
                                        buf.drawString(bedarray[b].toString(), (int) header.get(c + b)[1] + 5,
                                                (rowHeight * (i + 1 + genemutcount))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);

                                    }
                                }
                            }
                        }
                        if (c < header.size() - 1 - Main.bedCanvas.bedTrack.size()) {
                            buf.setColor(Color.black);
                            buf.fillRect((int) header.get(c + 1)[1] + 1,
                                    (rowHeight * (i + genemutcount + 1))
                                            - tablescroll.getVerticalScrollBar().getValue() + 4,
                                    (int) header.get(c + 1)[2], rowHeight - 1);

                        }
                    }
                    buf.setColor(Color.darkGray);
                    buf.drawLine(3, rowHeight + 3, 3, (rowHeight * (i + genemutcount + 2))
                            - tablescroll.getVerticalScrollBar().getValue() + 3);

                    for (int r = 0; r < header.size(); r++) {
                        buf.drawLine((int) header.get(r)[1],
                                (rowHeight * (i + genemutcount + 1))
                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                (int) header.get(r)[1], (rowHeight * (i + genemutcount + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + 3);
                    }
                    if (selectedNode != null && selectedNode.equals(cluster)) {

                        hoverSample = -1;
                        genemutcount = aminoarray.size() + 1;
                        listAdd = 1;
                        buf.drawLine(20,
                                (rowHeight * (i + listAdd + 2)) - tablescroll.getVerticalScrollBar().getValue()
                                        + 3,
                                this.getWidth(), (rowHeight * (i + listAdd + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + 3);
                        drawGeneheader((rowHeight * (i + listAdd + 1))
                                - tablescroll.getVerticalScrollBar().getValue() + 3);

                        for (int s = 0; s < aminoarray.size(); s++) {

                            buf.setColor(Color.darkGray);
                            buf.drawLine(21,
                                    (rowHeight * (i + s + listAdd + 3))
                                            - tablescroll.getVerticalScrollBar().getValue() + 3,
                                    this.getWidth(), (rowHeight * (i + s + listAdd + 3))
                                            - tablescroll.getVerticalScrollBar().getValue() + 3);

                            if (mouseY >= (rowHeight * (i + s + listAdd + 2))
                                    && mouseY < (rowHeight * (i + s + listAdd + 3))) {
                                hoverNode = null;
                                hoverVar = aminoarray.get(s).getNode();
                                hoverString = aminoarray.get(s).getRow();
                                buf.setColor(Color.white);

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        hoverSample = aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                .getSample().getIndex();
                                        break;
                                    }
                                }
                            } else {
                                if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("nonsense")) {
                                    buf.setColor(Color.red);
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("missense")) {
                                    buf.setColor(Color.yellow);
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("synonymous")) {
                                    buf.setColor(Color.green);
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("UTR")) {
                                    buf.setColor(Color.lightGray);
                                } else {
                                    buf.setColor(Color.gray);
                                }
                            }
                            if (!aminoarray.get(s).getRow()[1].equals("1")) {

                                buf.drawString("Multiple", 24, (rowHeight * (i + s + listAdd + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                            } else {
                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {

                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {

                                        buf.drawString(
                                                aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                        .getSample().getName(),
                                                24,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);
                                        break;
                                    }
                                }

                            }

                            if (hoverVar != null && hoverString.equals(aminoarray.get(s).getRow())) {
                                //TODO
                                textcolor = Color.white;

                            } else {
                                if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("nonsense")) {
                                    textcolor = Color.red;
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("missense")) {
                                    textcolor = Color.yellow;
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("synonymous")) {
                                    textcolor = Color.green;
                                } else if (aminoarray.get(s).getRow()[3].contains("UTR")) {
                                    textcolor = Color.lightGray;
                                } else {
                                    textcolor = Color.gray;
                                }
                            }
                            for (int h = 1; h < 4; h++) {
                                buf.setColor(Color.black);
                                buf.fillRect((int) geneheader.get(h)[1] + 10,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + 4,
                                        (int) geneheader.get(h)[2], rowHeight - 1);
                                buf.setColor(textcolor);
                                buf.drawString(aminoarray.get(s).getRow()[h], (int) geneheader.get(h)[1] + 14,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            }

                            if (aminoarray.get(s).getRow()[1].equals("1")) {
                                buf.setColor(Color.black);
                                buf.fillRect((int) geneheader.get(4)[1] + 10,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + 4,
                                        this.getWidth(), rowHeight - 1);
                                buf.setColor(textcolor);

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        if (aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                .isHomozygous()) {
                                            buf.drawString(
                                                    "Hom (" + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                            .get(0).getCalls() + "/"
                                                            + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                                    .get(0).getCoverage()
                                                            + ")",
                                                    (int) geneheader.get(4)[1] + 14,
                                                    (rowHeight * (i + s + listAdd + 2))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            if (Control.controlData.controlsOn) {
                                                cases = 2;
                                                casefreq = 2 / (double) (Main.varsamples * 2);
                                            }
                                        } else {
                                            buf.drawString(
                                                    "Het (" + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                            .get(0).getCalls() + "/"
                                                            + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                                    .get(0).getCoverage()
                                                            + ")",
                                                    (int) geneheader.get(4)[1] + 14,
                                                    (rowHeight * (i + s + listAdd + 2))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            if (Control.controlData.controlsOn) {
                                                cases = 1;
                                                casefreq = 1 / (double) (Main.varsamples * 2);
                                            }

                                        }
                                        buf.setColor(Color.black);
                                        buf.fillRect((int) geneheader.get(5)[1] + 1,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                this.getWidth(), rowHeight - 1);
                                        buf.setColor(textcolor);
                                        buf.drawString(
                                                "" + aminoarray.get(s).getNode().vars
                                                        .get(v).getValue().get(0).getQuality(),
                                                (int) geneheader.get(5)[1] + 14,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);

                                    }
                                }
                            }

                            if (Control.controlData.controlsOn) {
                                cases = 0;
                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        if (aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                .isHomozygous()) {
                                            cases += Integer.parseInt(aminoarray.get(s).getRow()[1]) * 2;
                                        } else {
                                            cases += Integer.parseInt(aminoarray.get(s).getRow()[1]);
                                        }
                                    }
                                }
                                casefreq = cases / (double) (Main.varsamples * 2);
                            }

                            buf.setColor(textcolor);
                            buf.drawString(aminoarray.get(s).getRow()[4], (int) geneheader.get(6)[1] + 14,
                                    (rowHeight * (i + s + listAdd + 2))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            if (Control.controlData.controlsOn) {
                                buf.setColor(textcolor);

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        vararray = aminoarray.get(s).getNode().vars.get(v).getValue();
                                        controlarray = new SampleNode[Control.controlData.fileArray.size()];
                                        if (vararray.get(vararray.size() - 1).alleles != null) {

                                            for (int e = vararray.size() - 1; e > 0; e--) {

                                                if (vararray.get(e).alleles == null) {
                                                    break;
                                                }
                                                controlarray[vararray.get(e).getControlSample()
                                                        .getIndex()] = vararray.get(e);

                                            }
                                        }
                                        for (int e = 0; e < controlarray.length; e++) {
                                            if (Control.controlData.fileArray.get(e).controlOn) {
                                                if (controlarray[e] == null) {
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString("0",
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString("-",
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);

                                                } else {
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString(
                                                            "" + MethodLibrary.round(controlarray[e].alleles
                                                                    / (double) controlarray[e].allelenumber, 2),
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString("" + MethodLibrary
                                                            .round(casefreq / (controlarray[e].alleles
                                                                    / (double) controlarray[e].allelenumber), 2)
                                                            + " (p="
                                                            + MethodLibrary.round(
                                                                    VariantHandler.table.fe.getRightTailedP(
                                                                            cases, Main.varsamples * 2 - cases,
                                                                            controlarray[e].alleles,
                                                                            controlarray[e].allelenumber
                                                                                    - controlarray[e].alleles),
                                                                    2)
                                                            + ")",
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);
                                                }
                                            } else {
                                                buf.setColor(Color.black);
                                                buf.fillRect(
                                                        (int) geneheader.get(this.geneheaderlength + e * 2)[1]
                                                                + 11,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth(), rowHeight - 1);
                                                buf.setColor(Color.darkGray);
                                                buf.drawString("Apply controls",
                                                        (int) geneheader.get(this.geneheaderlength + e * 2)[1]
                                                                + 14,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);
                                                buf.setColor(Color.black);
                                                buf.fillRect(
                                                        (int) geneheader
                                                                .get(this.geneheaderlength + e * 2 + 1)[1] + 11,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth(), rowHeight - 1);
                                                buf.setColor(Color.darkGray);
                                                buf.drawString("-",
                                                        (int) geneheader
                                                                .get(this.geneheaderlength + e * 2 + 1)[1] + 14,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            }
                                        }
                                    }
                                }
                            } else {
                                buf.setColor(Color.darkGray);

                                for (int e = geneheaderlength; e < geneheader.size(); e++) {
                                    if (geneheader.get(e)[0] instanceof ControlFile) {
                                        buf.drawString("Apply controls", (int) geneheader.get(e)[1] + 14,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);
                                    }
                                }
                                buf.setColor(Color.lightGray);
                            }
                            vararray = null;
                            if (Main.bedCanvas.bedOn) {
                                for (int a = 0; a < aminoarray.size(); a++) {
                                    bedarray = MethodLibrary.makeTrackArray(aminoarray.get(a).getNode(),
                                            aminoarray.get(a).getRow()[5]);
                                    if (bedarray != null) {
                                        for (int b = 0; b < bedarray.length; b++) {
                                            buf.setColor(Color.black);
                                            if (b == bedarray.length - 1) {
                                                buf.fillRect(
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[1] + 12,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth() - (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[1],
                                                        rowHeight - 1);
                                            } else {
                                                buf.fillRect(
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[1] + 12,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[2],
                                                        rowHeight - 1);
                                            }
                                            buf.setColor(Color.white);
                                            if (bedarray[b] != null) {
                                                buf.drawString(bedarray[b].toString(),
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[1] + 14,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            }
                                        }
                                    }
                                }
                            }
                            buf.setColor(Color.darkGray);
                            for (int j = 0; j < geneheader.size(); j++) {

                                buf.drawLine((int) geneheader.get(j)[1] + 11,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + 4,
                                        (int) geneheader.get(j)[1] + 11, (rowHeight * (i + s + listAdd + 3))
                                                - tablescroll.getVerticalScrollBar().getValue() + 3);
                            }
                            if (selectedVar != null && selectedString.equals(aminoarray.get(s).getRow())
                                    && Integer.parseInt(selectedString[1]) > 1) {
                                //hoverSample = -1;
                                pointer = 0;
                                //TODO

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(selectedString[5])) {

                                        for (int l = 0; l < aminoarray.get(s).getNode().vars.get(v).getValue()
                                                .size(); l++) {
                                            if (aminoarray.get(s).getNode().vars.get(v).getValue()
                                                    .get(l).alleles != null) {
                                                break;
                                            }
                                            if (mouseY > (rowHeight * (i + s + pointer + 4))
                                                    && mouseY < (rowHeight * (i + s + pointer + 5))) {
                                                textcolor = Color.white;

                                                hoverVar = aminoarray.get(s).getNode();
                                                hoverString = aminoarray.get(s).getRow();
                                                hoverSample = aminoarray.get(s).getNode().vars.get(v).getValue()
                                                        .get(l).getSample().getIndex();
                                            } else {
                                                textcolor = Color.lightGray;
                                            }

                                            //   if(aminoarray.get(s).getNode().getSamples().get(l).getVariation().equals(selectedString[5])) {                           
                                            buf.setColor(textcolor);
                                            buf.drawString(
                                                    aminoarray.get(s).getNode().vars.get(v).getValue().get(l)
                                                            .getSample().getName(),
                                                    30,
                                                    (rowHeight * (i + s + pointer + 4))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            pointer++;
                                            //   }   

                                            buf.setColor(Color.black);
                                            buf.fillRect((int) geneheader.get(4)[1] + 10,
                                                    (rowHeight * (i + s + pointer + 3))
                                                            - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                    this.getWidth(), rowHeight - 1);
                                            buf.setColor(textcolor);
                                            if (aminoarray.get(s).getNode().vars.get(v).getValue().get(l)
                                                    .isHomozygous()) {
                                                buf.drawString(
                                                        "Hom (" + aminoarray.get(s).getNode().vars.get(v)
                                                                .getValue().get(l).getCalls() + "/"
                                                                + aminoarray.get(s).getNode().vars.get(v)
                                                                        .getValue().get(l).getCoverage()
                                                                + ")",
                                                        (int) geneheader.get(4)[1] + 14,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            } else {
                                                buf.drawString(
                                                        "Het (" + aminoarray.get(s).getNode().vars.get(v)
                                                                .getValue().get(l).getCalls() + "/"
                                                                + aminoarray.get(s).getNode().vars.get(v)
                                                                        .getValue().get(l).getCoverage()
                                                                + ")",
                                                        (int) geneheader.get(4)[1] + 14,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);
                                            }

                                            buf.setColor(Color.black);
                                            buf.fillRect((int) geneheader.get(5)[1] + 10,
                                                    (rowHeight * (i + s + pointer + 3))
                                                            - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                    this.getWidth(), rowHeight - 1);
                                            buf.setColor(textcolor);
                                            buf.drawString(
                                                    "" + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                            .get(l).getQuality(),
                                                    (int) geneheader.get(5)[1] + 14,
                                                    (rowHeight * (i + s + pointer + 3))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            buf.setColor(Color.darkGray);
                                            for (int j = 4; j < 7; j++) {

                                                buf.drawLine((int) geneheader.get(j)[1] + 11,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue(),
                                                        (int) geneheader.get(j)[1] + 11,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight + 2);
                                            }

                                        }
                                    }
                                }
                                listAdd = Integer.parseInt(selectedString[1]) + 1;
                                genemutcount = aminoarray.size() + listAdd;
                                buf.setColor(Color.darkGray);
                                buf.drawLine(21,
                                        (rowHeight * (i + s + listAdd + 3))
                                                - tablescroll.getVerticalScrollBar().getValue() + 3,
                                        this.getWidth(), (rowHeight * (i + s + listAdd + 3))
                                                - tablescroll.getVerticalScrollBar().getValue() + 3);

                            }

                        }
                    }

                } catch (Exception e) {
                    ErrorLog.addError(e.getStackTrace());
                    e.printStackTrace();
                }

            }
            buf.setColor(Color.darkGray);
            buf.drawLine(4,
                    (rowHeight * (Main.drawCanvas.clusterNodes.size() + genemutcount + 1))
                            - tablescroll.getVerticalScrollBar().getValue() + 3,
                    this.getWidth(), (rowHeight * (Main.drawCanvas.clusterNodes.size() + genemutcount + 1))
                            - tablescroll.getVerticalScrollBar().getValue() + 3);

        }
        drawHeader();

        if (headerHover == -1 && geneHeaderHover == -1) {

            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        } else {
            if (resizeColumn == -1) {
                setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            } else {
                setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
            }
        }

        g.drawImage(bufImage, 0, tablescroll.getVerticalScrollBar().getValue(), null);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:base.BasePlayer.BedTable.java

void drawScreen(Graphics g) {
    try {/*from  ww  w.  java 2 s.c  o m*/
        buf.setColor(Color.black);

        buf.fillRect(0, 0, this.getWidth(), this.getHeight());
        if (width != this.getWidth()) {
            width = this.getWidth();
            createPolygon();
            resizeTable();
        }

        genemutcount = 0;
        if (!bedtrack.intersect) {
            buf.setColor(Color.white);
            buf.drawString("Press play on bed track to annotate variants", 5, 40);
        } else if (getTableSize() > 0) {

            hoverVar = null;
            hoverSample = -1;
            headerHover = -1;
            geneHeaderHover = -1;
            if (!mouseDrag) {
                resizeColumn = -1;
            }

            if (aminoarray == null) {
                aminoarray = new ArrayList<AminoEntry>();
            }

            firstrow = tablescroll.getVerticalScrollBar().getValue() / rowHeight - samplecount - listAdd
                    - aminoarray.size();

            if (firstrow < 0) {
                firstrow = 0;
            }
            for (int i = firstrow; i < bedarray.size(); i++) {
                dot = false;

                if ((i + 1 + samplecount + listAdd + aminoarray.size()) * rowHeight < tablescroll
                        .getVerticalScrollBar().getValue()) {

                    continue;
                }

                if (i * rowHeight > tablescroll.getVerticalScrollBar().getValue()
                        + tablescroll.getViewport().getHeight()) {

                    break;
                }

                if (mouseY >= (rowHeight * (i + genemutcount + 1))
                        && mouseY < (rowHeight * (i + genemutcount + 2))) {
                    hoverNode = bedarray.get(i);
                }

                try {
                    buf.setColor(Color.darkGray);
                    buf.drawLine(4,
                            (rowHeight * (i + genemutcount + 1)) - tablescroll.getVerticalScrollBar().getValue()
                                    + 3,
                            this.getWidth(), (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 3);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {
                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }

                    if (bedarray.get(i).getTrack().hasvalues) {
                        buf.drawString(
                                (i + 1) + ".  " + MethodLibrary.shortString(bedarray.get(i).name, 10) + "="
                                        + MethodLibrary.round(bedarray.get(i).value, 3),
                                5, (rowHeight * (i + 1 + genemutcount))
                                        - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                    } else {
                        buf.drawString((i + 1) + ".  " + MethodLibrary.shortString(bedarray.get(i).name, 10), 5,
                                (rowHeight * (i + 1 + genemutcount))
                                        - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                    }
                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[1][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            headerlengths[1][1], rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {
                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }
                    mutcountbuffer = new StringBuffer("" + bedarray.get(i).mutations + " ");
                    buf.drawString(mutcountbuffer.toString(), headerlengths[1][0] + 5,
                            (rowHeight * (i + 1 + genemutcount)) - tablescroll.getVerticalScrollBar().getValue()
                                    + rowHeight);
                    //      lastpos = Integer.toString(bedarray.get(i).mutations).length() +2;
                    //TODO      textWidth = (int)fm.getStringBounds("", buf).getWidth();

                    //   textWidth = (int)fm.getStringBounds(mutcountbuffer.toString(), buf).getWidth();
                    //   buf.drawString("  ", headerlengths[1][0]+5+textWidth, (rowHeight*(i+1+genemutcount))-tablescroll.getVerticalScrollBar().getValue()+rowHeight);      

                    //   buf.setColor(Color.gray);
                    //   textWidth = (int)fm.getStringBounds(mutcountbuffer.toString() , buf).getWidth();
                    //   buf.drawString(" " +bedarray.get(i).varnodes.size() +" samples",  headerlengths[1][0]+5+textWidth, (rowHeight*(i+1+genemutcount))-tablescroll.getVerticalScrollBar().getValue()+rowHeight);      

                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[2][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            this.getWidth(), rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {
                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }

                    buf.drawString(
                            bedarray.get(i).getChrom() + ":"
                                    + MethodLibrary.formatNumber(bedarray.get(i).getPosition() + 1) + "-"
                                    + MethodLibrary.formatNumber(
                                            bedarray.get(i).getPosition() + 1 + bedarray.get(i).getLength()),
                            headerlengths[2][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                    - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[3][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            this.getWidth(), rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {

                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }

                    buf.drawString(MethodLibrary.formatNumber(bedarray.get(i).getLength()),
                            headerlengths[3][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                    - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[4][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            this.getWidth(), rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {

                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }

                    buf.drawString("" + MethodLibrary
                            .round((bedarray.get(i).mutations / (double) bedarray.get(i).getLength()) * 100, 4),
                            headerlengths[4][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                    - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[5][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            this.getWidth(), rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {

                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }
                    firstvisible = 0;
                    if (bedarray.get(i).varnodes != null) {

                        for (int f = 0; f < bedarray.get(i).varnodes.size(); f++) {
                            if (!Main.drawCanvas.hideNode(bedarray.get(i).varnodes.get(f))) {
                                firstvisible = f;
                                break;
                            }
                        }
                        if (bedarray.get(i).varnodes.get(firstvisible).getExons() != null) {

                            if (bedarray.get(i).varnodes.get(firstvisible).coding) {
                                buf.setColor(Color.red);
                                buf.drawString(
                                        bedarray.get(i).varnodes.get(firstvisible).getExons().get(0)
                                                .getTranscript().getGenename() + " (Coding)",
                                        headerlengths[5][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                                - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            } else {
                                buf.setColor(Color.lightGray);
                                buf.drawString(
                                        bedarray.get(i).varnodes.get(firstvisible).getExons().get(0)
                                                .getTranscript().getGenename() + " (UTR)",
                                        headerlengths[5][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                                - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            }
                        } else if (bedarray.get(i).varnodes.get(firstvisible).isInGene()) {

                            buf.setColor(Color.lightGray);
                            buf.drawString(
                                    bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0)
                                            .getGenename() + " (Intronic)",
                                    headerlengths[5][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                        } else {
                            buf.setColor(Color.gray);

                            if (!bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0).equals(
                                    bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(1))) {

                                buf.drawString(
                                        bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0)
                                                .getGenename()
                                                + " ... "
                                                + bedarray.get(i).varnodes.get(firstvisible).getTranscripts()
                                                        .get(1).getGenename(),
                                        headerlengths[5][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                                - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            } else {
                                if (bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0)
                                        .getEnd() > bedarray.get(i).varnodes.get(firstvisible).getPosition()) {

                                    buf.drawString(
                                            " ... " + bedarray.get(i).varnodes.get(firstvisible)
                                                    .getTranscripts().get(0).getGenename(),
                                            headerlengths[5][0] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);
                                } else {
                                    buf.drawString(
                                            bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0)
                                                    .getGenename() + " ... ",
                                            headerlengths[5][0] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);

                                }
                            }
                        }
                    }

                    buf.setColor(Color.darkGray);
                    buf.drawLine(3, rowHeight + 3, 3, (rowHeight * (i + genemutcount + 2))
                            - tablescroll.getVerticalScrollBar().getValue() + 3);

                    for (int r = 0; r < headerlengths.length; r++) {
                        buf.drawLine(headerlengths[r][0],
                                (rowHeight * (i + genemutcount + 1))
                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                headerlengths[r][0], (rowHeight * (i + genemutcount + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + 3);
                    }

                    if (selectedNode != null && selectedNode.equals(bedarray.get(i))) {

                        hoverSample = -1;
                        genemutcount = aminoarray.size() + 1;
                        listAdd = 1;
                        buf.drawLine(20,
                                (rowHeight * (i + listAdd + 2)) - tablescroll.getVerticalScrollBar().getValue()
                                        + 3,
                                this.getWidth(), (rowHeight * (i + listAdd + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + 3);
                        drawGeneheader((rowHeight * (i + listAdd + 1))
                                - tablescroll.getVerticalScrollBar().getValue() + 3);

                        for (int s = 0; s < aminoarray.size(); s++) {

                            buf.setColor(Color.darkGray);
                            buf.drawLine(21,
                                    (rowHeight * (i + s + listAdd + 3))
                                            - tablescroll.getVerticalScrollBar().getValue() + 3,
                                    this.getWidth(), (rowHeight * (i + s + listAdd + 3))
                                            - tablescroll.getVerticalScrollBar().getValue() + 3);

                            if (mouseY >= (rowHeight * (i + s + listAdd + 2))
                                    && mouseY < (rowHeight * (i + s + listAdd + 3))) {
                                hoverNode = null;
                                hoverVar = aminoarray.get(s).getNode();
                                hoverString = aminoarray.get(s).getRow();
                                buf.setColor(Color.white);

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        hoverSample = aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                .getSample().getIndex();
                                        break;
                                    }
                                }

                            } else {
                                if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("nonsense")) {
                                    buf.setColor(Color.red);
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("missense")) {
                                    buf.setColor(Color.yellow);
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("synonymous")) {
                                    buf.setColor(Color.green);
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("UTR")) {
                                    buf.setColor(Color.lightGray);
                                } else {
                                    buf.setColor(Color.gray);
                                }
                            }
                            if (!aminoarray.get(s).getRow()[1].equals("1")) {

                                buf.drawString("Multiple", 24, (rowHeight * (i + s + listAdd + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                            } else {
                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {

                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {

                                        buf.drawString(
                                                aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                        .getSample().getName(),
                                                24,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);
                                        break;
                                    }
                                }

                            }

                            if (hoverVar != null && hoverString.equals(aminoarray.get(s).getRow())) {
                                //TODO
                                textcolor = Color.white;

                            } else {
                                if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("nonsense")) {
                                    textcolor = Color.red;
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("missense")) {
                                    textcolor = Color.yellow;
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("synonymous")) {
                                    textcolor = Color.green;
                                } else if (aminoarray.get(s).getRow()[3].contains("UTR")) {
                                    textcolor = Color.lightGray;
                                } else {
                                    textcolor = Color.gray;
                                }
                            }
                            for (int h = 1; h < 4; h++) {
                                buf.setColor(Color.black);
                                buf.fillRect((int) geneheader.get(h)[1] + 10,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + 4,
                                        (int) geneheader.get(h)[2], rowHeight - 1);
                                buf.setColor(textcolor);
                                buf.drawString(aminoarray.get(s).getRow()[h], (int) geneheader.get(h)[1] + 14,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            }

                            if (aminoarray.get(s).getRow()[1].equals("1")) {
                                buf.setColor(Color.black);
                                buf.fillRect((int) geneheader.get(4)[1] + 10,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + 4,
                                        this.getWidth(), rowHeight - 1);
                                buf.setColor(textcolor);

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        if (aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                .isHomozygous()) {
                                            buf.drawString(
                                                    "Hom (" + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                            .get(0).getCalls() + "/"
                                                            + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                                    .get(0).getCoverage()
                                                            + ")",
                                                    (int) geneheader.get(4)[1] + 14,
                                                    (rowHeight * (i + s + listAdd + 2))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            if (Control.controlData.controlsOn) {
                                                cases = 2;
                                                casefreq = 2 / (double) (Main.varsamples * 2);
                                            }
                                        } else {
                                            buf.drawString(
                                                    "Het (" + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                            .get(0).getCalls() + "/"
                                                            + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                                    .get(0).getCoverage()
                                                            + ")",
                                                    (int) geneheader.get(4)[1] + 14,
                                                    (rowHeight * (i + s + listAdd + 2))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            if (Control.controlData.controlsOn) {
                                                cases = 1;
                                                casefreq = 1 / (double) (Main.varsamples * 2);
                                            }

                                        }
                                        buf.setColor(Color.black);
                                        buf.fillRect((int) geneheader.get(5)[1] + 1,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                this.getWidth(), rowHeight - 1);
                                        buf.setColor(textcolor);
                                        buf.drawString(
                                                "" + aminoarray.get(s).getNode().vars
                                                        .get(v).getValue().get(0).getQuality(),
                                                (int) geneheader.get(5)[1] + 14,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);

                                    }
                                }
                            }

                            if (Control.controlData.controlsOn) {
                                cases = 0;
                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        if (aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                .isHomozygous()) {
                                            cases += Integer.parseInt(aminoarray.get(s).getRow()[1]) * 2;
                                        } else {
                                            cases += Integer.parseInt(aminoarray.get(s).getRow()[1]);
                                        }
                                    }
                                }
                                casefreq = cases / (double) (Main.varsamples * 2);
                            }

                            buf.setColor(textcolor);
                            buf.drawString(aminoarray.get(s).getRow()[4], (int) geneheader.get(6)[1] + 14,
                                    (rowHeight * (i + s + listAdd + 2))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            if (Control.controlData.controlsOn) {
                                buf.setColor(textcolor);

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        vararray = aminoarray.get(s).getNode().vars.get(v).getValue();
                                        controlarray = new SampleNode[Control.controlData.fileArray.size()];
                                        if (vararray.get(vararray.size() - 1).alleles != null) {

                                            for (int e = vararray.size() - 1; e > 0; e--) {

                                                if (vararray.get(e).alleles == null) {
                                                    break;
                                                }
                                                controlarray[vararray.get(e).getControlSample()
                                                        .getIndex()] = vararray.get(e);

                                            }
                                        }
                                        for (int e = 0; e < controlarray.length; e++) {
                                            if (Control.controlData.fileArray.get(e).controlOn) {
                                                if (controlarray[e] == null) {
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString("0",
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString("-",
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);

                                                } else {
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString(
                                                            "" + MethodLibrary.round(controlarray[e].alleles
                                                                    / (double) controlarray[e].allelenumber, 2),
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString("" + MethodLibrary
                                                            .round(casefreq / (controlarray[e].alleles
                                                                    / (double) controlarray[e].allelenumber), 2)
                                                            + " (p="
                                                            + MethodLibrary.round(
                                                                    VariantHandler.table.fe.getRightTailedP(
                                                                            cases, Main.varsamples * 2 - cases,
                                                                            controlarray[e].alleles,
                                                                            controlarray[e].allelenumber
                                                                                    - controlarray[e].alleles),
                                                                    2)
                                                            + ")",
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);

                                                }
                                            } else {
                                                buf.setColor(Color.black);
                                                buf.fillRect(
                                                        (int) geneheader.get(this.geneheaderlength + e * 2)[1]
                                                                + 11,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth(), rowHeight - 1);
                                                buf.setColor(Color.darkGray);
                                                buf.drawString("Apply controls",
                                                        (int) geneheader.get(this.geneheaderlength + e * 2)[1]
                                                                + 14,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);
                                                buf.setColor(Color.black);
                                                buf.fillRect(
                                                        (int) geneheader
                                                                .get(this.geneheaderlength + e * 2 + 1)[1] + 11,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth(), rowHeight - 1);
                                                buf.setColor(Color.darkGray);
                                                buf.drawString("-",
                                                        (int) geneheader
                                                                .get(this.geneheaderlength + e * 2 + 1)[1] + 14,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            }

                                        }

                                    }
                                }

                            } else {
                                buf.setColor(Color.darkGray);

                                for (int e = geneheaderlength; e < geneheader.size(); e++) {
                                    if (geneheader.get(e)[0] instanceof ControlFile) {
                                        buf.drawString("Apply controls", (int) geneheader.get(e)[1] + 14,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);
                                    }
                                }
                                buf.setColor(Color.lightGray);
                            }
                            vararray = null;
                            if (Main.bedCanvas.bedOn) {

                                for (int a = 0; a < aminoarray.size(); a++) {

                                    StringBuffer[] bedarraytemp = MethodLibrary.makeTrackArray(
                                            aminoarray.get(a).getNode(), aminoarray.get(a).getRow()[5]);
                                    if (bedarraytemp != null) {
                                        int h = 0;
                                        for (int b = 0; b < bedarraytemp.length; b++) {
                                            if (b == bedtrack.trackIndex) {
                                                continue;
                                            }
                                            buf.setColor(Color.black);
                                            if (b == bedarraytemp.length - 1) {
                                                buf.fillRect(
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[1] + 12,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth() - (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[1],
                                                        rowHeight - 1);
                                            } else {
                                                buf.fillRect(
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[1] + 12,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[2],
                                                        rowHeight - 1);
                                            }
                                            buf.setColor(Color.white);
                                            if (bedarraytemp[b] != null) {
                                                buf.drawString(bedarraytemp[b].toString(),
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[1] + 14,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            }
                                            h++;

                                            //   buf.drawLine((int)geneheader.get(geneheaderlength+Control.controlData.fileArray.size()*2+h)[1], (rowHeight*(i+a+listAdd+2))-tablescroll.getVerticalScrollBar().getValue()+4, (int)geneheader.get(geneheaderlength+Control.controlData.fileArray.size()*2+h)[1], (rowHeight*(i+a+listAdd+2))-tablescroll.getVerticalScrollBar().getValue()+10);   

                                        }
                                    }
                                }
                            }

                            buf.setColor(Color.darkGray);
                            for (int j = 0; j < geneheader.size(); j++) {
                                buf.drawLine((int) geneheader.get(j)[1] + 11,
                                        (rowHeight * (i + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + 4,
                                        (int) geneheader.get(j)[1] + 11, (rowHeight * (i + s + listAdd + 3))
                                                - tablescroll.getVerticalScrollBar().getValue() + 3);
                            }
                            if (selectedVar != null && selectedString.equals(aminoarray.get(s).getRow())
                                    && Integer.parseInt(selectedString[1]) > 1) {
                                //hoverSample = -1;
                                pointer = 0;
                                //TODO

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(selectedString[5])) {

                                        for (int l = 0; l < aminoarray.get(s).getNode().vars.get(v).getValue()
                                                .size(); l++) {
                                            if (aminoarray.get(s).getNode().vars.get(v).getValue()
                                                    .get(l).alleles != null) {
                                                break;
                                            }
                                            if (mouseY > (rowHeight * (i + s + pointer + 4))
                                                    && mouseY < (rowHeight * (i + s + pointer + 5))) {
                                                textcolor = Color.white;

                                                hoverVar = aminoarray.get(s).getNode();
                                                hoverString = aminoarray.get(s).getRow();
                                                hoverSample = aminoarray.get(s).getNode().vars.get(v).getValue()
                                                        .get(l).getSample().getIndex();
                                            } else {
                                                textcolor = Color.lightGray;
                                            }

                                            //   if(aminoarray.get(s).getNode().getSamples().get(l).getVariation().equals(selectedString[5])) {                           
                                            buf.setColor(textcolor);
                                            buf.drawString(
                                                    aminoarray.get(s).getNode().vars.get(v).getValue().get(l)
                                                            .getSample().getName(),
                                                    30,
                                                    (rowHeight * (i + s + pointer + 4))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            pointer++;
                                            //   }   

                                            buf.setColor(Color.black);
                                            buf.fillRect((int) geneheader.get(4)[1] + 10,
                                                    (rowHeight * (i + s + pointer + 3))
                                                            - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                    this.getWidth(), rowHeight - 1);
                                            buf.setColor(textcolor);
                                            if (aminoarray.get(s).getNode().vars.get(v).getValue().get(l)
                                                    .isHomozygous()) {
                                                buf.drawString(
                                                        "Hom (" + aminoarray.get(s).getNode().vars.get(v)
                                                                .getValue().get(l).getCalls() + "/"
                                                                + aminoarray.get(s).getNode().vars.get(v)
                                                                        .getValue().get(l).getCoverage()
                                                                + ")",
                                                        (int) geneheader.get(4)[1] + 14,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            } else {
                                                buf.drawString(
                                                        "Het (" + aminoarray.get(s).getNode().vars.get(v)
                                                                .getValue().get(l).getCalls() + "/"
                                                                + aminoarray.get(s).getNode().vars.get(v)
                                                                        .getValue().get(l).getCoverage()
                                                                + ")",
                                                        (int) geneheader.get(4)[1] + 14,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);
                                            }

                                            buf.setColor(Color.black);
                                            buf.fillRect((int) geneheader.get(5)[1] + 10,
                                                    (rowHeight * (i + s + pointer + 3))
                                                            - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                    this.getWidth(), rowHeight - 1);
                                            buf.setColor(textcolor);
                                            buf.drawString(
                                                    "" + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                            .get(l).getQuality(),
                                                    (int) geneheader.get(5)[1] + 14,
                                                    (rowHeight * (i + s + pointer + 3))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            buf.setColor(Color.darkGray);
                                            for (int j = 4; j < 7; j++) {

                                                buf.drawLine((int) geneheader.get(j)[1] + 11,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue(),
                                                        (int) geneheader.get(j)[1] + 11,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight + 2);
                                            }

                                        }
                                    }
                                }
                                listAdd = Integer.parseInt(selectedString[1]) + 1;
                                genemutcount = aminoarray.size() + listAdd;
                                buf.setColor(Color.darkGray);
                                buf.drawLine(21,
                                        (rowHeight * (i + s + listAdd + 3))
                                                - tablescroll.getVerticalScrollBar().getValue() + 3,
                                        this.getWidth(), (rowHeight * (i + s + listAdd + 3))
                                                - tablescroll.getVerticalScrollBar().getValue() + 3);

                            }

                        }
                    }
                } catch (Exception e) {
                    ErrorLog.addError(e.getStackTrace());
                    e.printStackTrace();
                }

            }
            buf.setColor(Color.darkGray);
            buf.drawLine(4,
                    (rowHeight * (bedarray.size() + genemutcount + 1))
                            - tablescroll.getVerticalScrollBar().getValue() + 3,
                    this.getWidth(), (rowHeight * (bedarray.size() + genemutcount + 1))
                            - tablescroll.getVerticalScrollBar().getValue() + 3);

        }
        drawHeader();

        if (headerHover == -1 && geneHeaderHover == -1) {

            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        } else {
            if (resizeColumn == -1) {
                setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            } else {
                setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
            }
        }
        g.drawImage(bufImage, 0, tablescroll.getVerticalScrollBar().getValue(), null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}