List of usage examples for java.awt Graphics2D fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToColor.java
@Override public void renderCellHD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY, int cellWidth, int cellHeight) { if (v == null || v.isNaN()) { //System.out.println(v); _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight); } else {//from ww w. ja v a 2 s . co m try { int index = (int) ((v - _minValue) / (_maxValue - _minValue) * _gradientColors.length); if (index >= _gradientColors.length) { index = _gradientColors.length - 1; } if (index < 0) { index = 0; } Color c = _gradientColors[index]; //System.out.println(c); g2D.setColor(c); // System.out.println((int) cellWidth + " " + ((int) cellHeight)) ; g2D.fillRoundRect((int) anchorX + 1, (int) anchorY + 1, (int) cellWidth - 2, (int) cellHeight - 2, 4, 4); if (drawSubMap.isSelected()) { //paint the sub heatmap block // System.out.println("draw submap"); if (rowNode == null || columnNode == null || rowNode.isSingleNode() && columnNode.isSingleNode()) { return; } else { g2D.setStroke(UI.strokeDash1_5); //need to determine the number of cMatrices CoolMapObject object = getCoolMapObject(); List<CMatrix> matrices = object.getBaseCMatrices(); Double value; //row and column indices Integer[] rowIndices; Integer[] colIndices; //whether they are group node or node if (rowNode.isGroupNode()) { rowIndices = rowNode.getBaseIndicesFromCOntology( (CMatrix) object.getBaseCMatrices().get(0), COntology.ROW); } else { rowIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)) .getIndexOfRowName(rowNode.getName()) }; } if (columnNode.isGroupNode()) { colIndices = columnNode.getBaseIndicesFromCOntology( (CMatrix) object.getBaseCMatrices().get(0), COntology.COLUMN); } else { colIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)) .getIndexOfColName(columnNode.getName()) }; } //then determine the width int subMatrixWidth = Math.round(cellWidth * 1.0f / matrices.size()); int subAnchorX = anchorX; int subCellHeight = Math.round(cellHeight * 1.0f / rowIndices.length); int subCellWidth = Math.round(subMatrixWidth * 1.0f / colIndices.length); // System.out.println("CW:" + cellWidth + " " + colIndices.length + " " + subCellWidth); // System.out.println("CH:" + cellHeight + " " + rowIndices.length + " " + subCellHeight); if (subCellHeight < 1) { subCellHeight = 1; } if (subCellWidth < 1) { subCellWidth = 1; } int matrixIndex = 0; for (CMatrix matrix : matrices) { int rowIndex = 0; for (Integer i : rowIndices) { if (i == null || i < 0) { continue; } int columnIndex = 0; for (Integer j : colIndices) { if (j == null || j < 0) { continue; } try { value = (Double) matrix.getValue(i, j); index = (int) ((value - _minValue) / (_maxValue - _minValue) * _gradientColors.length); if (index >= _gradientColors.length) { index = _gradientColors.length - 1; } if (index < 0) { index = 0; } c = _gradientColors[index]; g2D.setColor(c); int subCellX = Math .round(subMatrixWidth * 1.0f * columnIndex / colIndices.length) + subAnchorX; int subCellY = Math.round(cellHeight * 1.0f * rowIndex / rowIndices.length) + anchorY; // System.out.println("WTF:" + columnIndex + " " + rowIndex + "----" + subCellX + " " + subCellY + " " + subCellWidth + " " + subCellHeight); g2D.fillRect(subCellX, subCellY, subCellWidth, subCellHeight); } catch (Exception e) { //draw it here e.printStackTrace(); } columnIndex++; } //end of column loop rowIndex++; } //end of row loop g2D.setColor(UI.colorBlack1); g2D.drawRect(subAnchorX, anchorY, subMatrixWidth, cellHeight); // // subAnchorX += subMatrixWidth; matrixIndex++; subAnchorX = anchorX + Math.round(cellWidth * 1.0f * matrixIndex / matrices.size()); } //end of matrix loop g2D.setStroke(UI.stroke2); g2D.setColor(Color.BLACK); g2D.drawRect(anchorX, anchorY, cellWidth, cellHeight); } } } catch (Exception e) { // System.out.println("Null pointer exception:" + v + "," + _minValue + "," + _maxValue + "," + _gradientColors + " " + getName() + "" + this); //e.printStackTrace(); } } }
From source file:org.forester.archaeopteryx.TreePanel.java
final private int paintTaxonomy(final Graphics2D g, final PhylogenyNode node, final boolean is_in_found_nodes, final boolean to_pdf, final boolean to_graphics_file) { final Taxonomy taxonomy = node.getNodeData().getTaxonomy(); g.setFont(getTreeFontSet().getLargeItalicFont()); if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK);/*from w w w .ja v a 2s . c o m*/ } else if (is_in_found_nodes) { g.setFont(getTreeFontSet().getLargeItalicFont().deriveFont(TreeFontSet.BOLD_AND_ITALIC)); g.setColor(getTreeColorSet().getFoundColor()); } else if (getControlPanel().isColorAccordingToTaxonomy()) { g.setColor(getTaxonomyBasedColor(node)); } else { g.setColor(getTreeColorSet().getTaxonomyColor()); } final double start_x = node.getXcoord() + 3 + TreePanel.HALF_BOX_SIZE; final double start_y = node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / (node.getNumberOfDescendants() == 1 ? 1 : 3.0)); _sb.setLength(0); if (_control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty(taxonomy.getTaxonomyCode())) { _sb.append(taxonomy.getTaxonomyCode()); _sb.append(" "); } if (_control_panel.isShowTaxonomyNames()) { if (!ForesterUtil.isEmpty(taxonomy.getScientificName()) && !ForesterUtil.isEmpty(taxonomy.getCommonName())) { _sb.append(taxonomy.getScientificName()); _sb.append(" ("); _sb.append(taxonomy.getCommonName()); _sb.append(") "); } else if (!ForesterUtil.isEmpty(taxonomy.getScientificName())) { _sb.append(taxonomy.getScientificName()); _sb.append(" "); } else if (!ForesterUtil.isEmpty(taxonomy.getCommonName())) { _sb.append(taxonomy.getCommonName()); _sb.append(" "); } } final String label = _sb.toString(); /* GUILHEM_BEG */ if ((label.length() > 0) && (node.getNodeData().isHasSequence()) && node.getNodeData().getSequence().equals(_query_sequence)) { // invert font color and background color to show that this is the query sequence final Rectangle2D nodeTextBounds = new TextLayout(label, g.getFont(), new FontRenderContext(null, false, false)).getBounds(); g.fillRect((int) start_x - 1, (int) start_y - 8, (int) nodeTextBounds.getWidth() + 4, 11); g.setColor(getTreeColorSet().getBackgroundColor()); } /* GUILHEM_END */ TreePanel.drawString(label, start_x, start_y, g); if (is_in_found_nodes) { return getTreeFontSet()._fm_large_italic_bold.stringWidth(label); } else { return getTreeFontSet()._fm_large_italic.stringWidth(label); } }
From source file:lu.fisch.unimozer.Diagram.java
@Override public void paint(Graphics graphics) { super.paint(graphics); Graphics2D g = (Graphics2D) graphics; // set anti-aliasing rendering ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setFont(new Font(g.getFont().getFontName(), Font.PLAIN, Unimozer.DRAW_FONT_SIZE)); // clear background g.setColor(Color.WHITE);//from w w w .ja va2 s. c o m g.fillRect(0, 0, getWidth() + 1, getHeight() + 1); g.setColor(Color.BLACK); /*Set<String> set; Iterator<String> itr; // draw classes a first time for(MyClass clas : classes.values()) { clas.setEnabled(this.isEnabled()); clas.draw(graphics,showFields,showMethods); }*/ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... MyClass clas = entry.getValue(); clas.setEnabled(this.isEnabled()); clas.draw(graphics, showFields, showMethods); } // draw packages packages.clear(); for (MyClass myClass : classes.values()) { if (myClass.isDisplayUML()) { Package myPackage = null; if (!packages.containsKey(myClass.getPackagename())) { myPackage = new Package(myClass.getPackagename(), myClass.getPosition().y, myClass.getPosition().x, myClass.getWidth(), myClass.getHeight()); packages.put(myPackage.getName(), myPackage); } else myPackage = packages.get(myClass.getPackagename()); if (myClass.getPosition().x + myClass.getWidth() > myPackage.getRight()) myPackage.setRight(myClass.getPosition().x + myClass.getWidth()); if (myClass.getPosition().y + myClass.getHeight() > myPackage.getBottom()) myPackage.setBottom(myClass.getPosition().y + myClass.getHeight()); if (myClass.getPosition().x < myPackage.getLeft()) myPackage.setLeft(myClass.getPosition().x); if (myClass.getPosition().y < myPackage.getTop()) myPackage.setTop(myClass.getPosition().y); } } // draw classes /* set = classes.keySet(); itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); classes.get(str).draw(graphics); }/**/ mostRight = 0; mostBottom = 0; // ?? /* set = classes.keySet(); itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); MyClass thisClass = classes.get(str); } */ // init topLeft & bottomRight topLeft = new Point(this.getWidth(), this.getHeight()); bottomRight = new Point(0, 0); // draw packages if (packages.size() > 0) if ((packages.size() == 1 && packages.get(Package.DEFAULT) == null) || packages.size() > 1) for (Package pack : packages.values()) { pack.draw(graphics); // push outer box if (pack.getTopAbs() < topLeft.y) topLeft.y = pack.getTopAbs(); if (pack.getLeftAbs() < topLeft.x) topLeft.x = pack.getLeftAbs(); if (pack.getBottomAbs() > bottomRight.y) bottomRight.y = pack.getBottomAbs(); if (pack.getRightAbs() > bottomRight.x) bottomRight.x = pack.getRightAbs(); } // draw implmementations if (isShowHeritage()) { Stroke oldStroke = g.getStroke(); g.setStroke(dashed); /*itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); if (thisClass.getPosition().x + thisClass.getWidth() > mostRight) mostRight = thisClass.getPosition().x + thisClass.getWidth(); if (thisClass.getPosition().y + thisClass.getHeight() > mostBottom) mostBottom = thisClass.getPosition().y + thisClass.getHeight(); if (thisClass.getImplements().size() > 0) for (String extendsClass : thisClass.getImplements()) { MyClass otherClass = classes.get(extendsClass); if (otherClass == null) otherClass = findByShortName(extendsClass); //if(otherClass==null) System.err.println(extendsClass+" not found (1)"); //if (otherClass==null) otherClass=findByShortName(extendsClass); //if(otherClass==null) System.err.println(extendsClass+" not found (2)"); if (otherClass != null && thisClass.isDisplayUML() && otherClass.isDisplayUML()) { thisClass.setExtendsMyClass(otherClass); // draw arrow from thisClass to otherClass // get the center point of each class Point fromP = new Point(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() / 2); Point toP = new Point(otherClass.getPosition().x + otherClass.getWidth() / 2, otherClass.getPosition().y + otherClass.getHeight() / 2); // get the corner 4 points of the desstination class // (outer margin = 4) Point toP1 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y - 4); Point toP2 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4, otherClass.getPosition().y - 4); Point toP3 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4, otherClass.getPosition().y + otherClass.getHeight() + 4); Point toP4 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y + otherClass.getHeight() + 4); // get the intersection with the center line an one of the // sedis of the destination class Point2D toDraw = getIntersection(fromP, toP, toP1, toP2); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP2, toP3); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP3, toP4); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP4, toP1); // draw the arrowed line if (toDraw != null) drawExtends(g, fromP, new Point((int) toDraw.getX(), (int) toDraw.getY())); } } } g.setStroke(oldStroke); } // draw inheritance if (isShowHeritage()) { /*itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); MyClass thisClass = classes.get(str); if (thisClass.getPosition().x + thisClass.getWidth() > mostRight) mostRight = thisClass.getPosition().x + thisClass.getWidth(); if (thisClass.getPosition().y + thisClass.getHeight() > mostBottom) mostBottom = thisClass.getPosition().y + thisClass.getHeight(); String extendsClass = thisClass.getExtendsClass(); //System.out.println(thisClass.getFullName()+" extends "+extendsClass); if (!extendsClass.equals("") && thisClass.isDisplayUML()) { MyClass otherClass = classes.get(extendsClass); if (otherClass == null) otherClass = findByShortName(extendsClass); //if(otherClass==null) System.err.println(extendsClass+" not found (1)"); //if (otherClass==null) otherClass=findByShortName(extendsClass); //if(otherClass==null) System.err.println(extendsClass+" not found (2)"); if (otherClass != null) { if (otherClass != thisClass) { thisClass.setExtendsMyClass(otherClass); // draw arrow from thisClass to otherClass // get the center point of each class Point fromP = new Point(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() / 2); Point toP = new Point(otherClass.getPosition().x + otherClass.getWidth() / 2, otherClass.getPosition().y + otherClass.getHeight() / 2); // get the corner 4 points of the desstination class // (outer margin = 4) Point toP1 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y - 4); Point toP2 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4, otherClass.getPosition().y - 4); Point toP3 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4, otherClass.getPosition().y + otherClass.getHeight() + 4); Point toP4 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y + otherClass.getHeight() + 4); // get the intersection with the center line an one of the // sedis of the destination class Point2D toDraw = getIntersection(fromP, toP, toP1, toP2); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP2, toP3); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP3, toP4); if (toDraw == null) toDraw = getIntersection(fromP, toP, toP4, toP1); // draw in red if there is a cclic inheritance problem if (thisClass.hasCyclicInheritance()) { ((Graphics2D) graphics).setStroke(new BasicStroke(2)); graphics.setColor(Color.RED); } // draw the arrowed line if (toDraw != null) drawExtends((Graphics2D) graphics, fromP, new Point((int) toDraw.getX(), (int) toDraw.getY())); } else { ((Graphics2D) graphics).setStroke(new BasicStroke(2)); graphics.setColor(Color.RED); // line graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y, thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y - 32); graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y - 32, thisClass.getPosition().x + thisClass.getWidth() + 32, thisClass.getPosition().y - 32); graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() + 32, thisClass.getPosition().y - 32, thisClass.getPosition().x + thisClass.getWidth() + 32, thisClass.getPosition().y + thisClass.getHeight() + 32); graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() + 32, thisClass.getPosition().y + thisClass.getHeight() + 32, thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() + 32); drawExtends((Graphics2D) graphics, new Point(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight() + 32), new Point(thisClass.getPosition().x + thisClass.getWidth() / 2, thisClass.getPosition().y + thisClass.getHeight())); } // reset the stroke and the color ((Graphics2D) graphics).setStroke(new BasicStroke(1)); graphics.setColor(Color.BLACK); } } } } // setup a hastable to store the relations //Hashtable<String,StringList> classUsage = new Hashtable<String,StringList>(); // store compositions Hashtable<MyClass, Vector<MyClass>> classCompositions = new Hashtable<MyClass, Vector<MyClass>>(); // store aggregations Hashtable<MyClass, Vector<MyClass>> classAggregations = new Hashtable<MyClass, Vector<MyClass>>(); // store all relations Hashtable<MyClass, Vector<MyClass>> classUsings = new Hashtable<MyClass, Vector<MyClass>>(); /* // iterate through all classes to find compositions itr = set.iterator(); while (itr.hasNext()) { // get the actual classname String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); // get the corresponding "MyClass" object MyClass thisClass = classes.get(str); // setup a list to store the relations with this class Vector<MyClass> theseCompositions = new Vector<MyClass>(); // get all fields of this class StringList uses = thisClass.getFieldTypes(); for (int u = 0; u < uses.count(); u++) { // try to find the other (used) class MyClass otherClass = classes.get(uses.get(u)); if (otherClass == null) otherClass = findByShortName(uses.get(u)); if (otherClass != null) // means this class uses the other ones { // add the other class to the list theseCompositions.add(otherClass); } } // add the list of used classes to the MyClass object thisClass.setUsesMyClass(theseCompositions); // store the composition in the general list classCompositions.put(thisClass, theseCompositions); // store the compositions int eh global relation list classUsings.put(thisClass, new Vector<MyClass>(theseCompositions)); // ^^^^^^^^^^^^^^^^^^^^ // important !! => create a new vector, otherwise the list // are the same ... } /* // iterate through all classes to find aggregations itr = set.iterator(); while (itr.hasNext()) { // get the actual class String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); // get the corresponding "MyClass" object MyClass thisClass = classes.get(str); // we need a list to store the aggragations with this class Vector<MyClass> theseAggregations = new Vector<MyClass>(); // try to get the list of compositions for this class // init if not present Vector<MyClass> theseCompositions = classCompositions.get(thisClass); if (theseCompositions == null) theseCompositions = new Vector<MyClass>(); // try to get the list of all relations for this class // init if not present Vector<MyClass> theseClasses = classUsings.get(thisClass); if (theseClasses == null) theseClasses = new Vector<MyClass>(); // get the names of the classes that thisclass uses StringList foundUsage = thisClass.getUsesWho(); // go through the list an check to find a corresponding MyClass for (int f = 0; f < foundUsage.count(); f++) { // get the name of the used class String usedClass = foundUsage.get(f); MyClass otherClass = classes.get(usedClass); if (otherClass == null) otherClass = findByShortName(usedClass); if (otherClass != null && thisClass != otherClass) // meanint "otherClass" is a class used by thisClass { if (!theseCompositions.contains(otherClass)) theseAggregations.add(otherClass); if (!theseClasses.contains(otherClass)) theseClasses.add(otherClass); } } // get all method types of this class StringList uses = thisClass.getMethodTypes(); for (int u = 0; u < uses.count(); u++) { // try to find the other (used) class MyClass otherClass = classes.get(uses.get(u)); if (otherClass == null) otherClass = findByShortName(uses.get(u)); if (otherClass != null) // means this class uses the other ones { // add the other class to the list theseAggregations.add(otherClass); } } // store the relations to the class thisClass.setUsesMyClass(theseClasses); // store the aggregation to the global list classAggregations.put(thisClass, theseAggregations); // store all relations to the global list classUsings.put(thisClass, theseClasses); } if (isShowComposition()) { /*Set<MyClass> set2 = classCompositions.keySet(); Iterator<MyClass> itr2 = set2.iterator(); while (itr2.hasNext()) { MyClass thisClass = itr2.next(); */ /* let's try this one ... */ for (Entry<MyClass, Vector<MyClass>> entry : classCompositions.entrySet()) { // get the actual class ... MyClass thisClass = entry.getKey(); if (thisClass.isDisplayUML()) { Vector<MyClass> otherClasses = classCompositions.get(thisClass); for (MyClass otherClass : otherClasses) drawComposition(g, thisClass, otherClass, classUsings); } } } if (isShowAggregation()) { /*Set<MyClass> set2 = classAggregations.keySet(); Iterator<MyClass> itr2 = set2.iterator(); while (itr2.hasNext()) { MyClass thisClass = itr2.next(); */ /* let's try this one ... */ for (Entry<MyClass, Vector<MyClass>> entry : classAggregations.entrySet()) { // get the actual class ... MyClass thisClass = entry.getKey(); if (thisClass.isDisplayUML()) { Vector<MyClass> otherClasses = classAggregations.get(thisClass); for (MyClass otherClass : otherClasses) drawAggregation(g, thisClass, otherClass, classUsings); } } } // draw classes again to put them on top // of the arrows /*set = classes.keySet(); itr = set.iterator(); while (itr.hasNext()) { String str = itr.next(); */ /* let's try this one ... */ for (Entry<String, MyClass> entry : classes.entrySet()) { // get the actual class ... String str = entry.getKey(); classes.get(str).setEnabled(this.isEnabled()); classes.get(str).draw(graphics, showFields, showMethods); // push outer box MyClass thisClass = classes.get(str); if (thisClass.getPosition().y < topLeft.y) topLeft.y = thisClass.getPosition().y; if (thisClass.getPosition().x < topLeft.x) topLeft.x = thisClass.getPosition().x; if (thisClass.getPosition().y + thisClass.getHeight() > bottomRight.y) bottomRight.y = thisClass.getPosition().y + thisClass.getHeight(); if (thisClass.getPosition().x + thisClass.getWidth() > bottomRight.x) bottomRight.x = thisClass.getPosition().x + thisClass.getWidth(); } // comments if (commentString != null) { String fontName = g.getFont().getName(); g.setFont(new Font("Courier", g.getFont().getStyle(), Unimozer.DRAW_FONT_SIZE)); if (!commentString.trim().equals("")) { String myCommentString = new String(commentString); Point myCommentPoint = new Point(commentPoint); //System.out.println(myCommentString); // adjust comment myCommentString = myCommentString.trim(); // adjust position myCommentPoint.y = myCommentPoint.y + 16; // explode comment StringList sl = StringList.explode(myCommentString, "\n"); // calculate totals int totalHeight = 0; int totalWidth = 0; for (int i = 0; i < sl.count(); i++) { String line = sl.get(i).trim(); int h = (int) g.getFont().getStringBounds(line, g.getFontRenderContext()).getHeight(); int w = (int) g.getFont().getStringBounds(line, g.getFontRenderContext()).getWidth(); totalHeight += h; totalWidth = Math.max(totalWidth, w); } // get comment size // draw background g.setColor(new Color(255, 255, 128, 255)); g.fillRoundRect(myCommentPoint.x, myCommentPoint.y, totalWidth + 8, totalHeight + 8, 4, 4); // draw border g.setColor(Color.BLACK); g.drawRoundRect(myCommentPoint.x, myCommentPoint.y, totalWidth + 8, totalHeight + 8, 4, 4); // draw text totalHeight = 0; for (int i = 0; i < sl.count(); i++) { String line = sl.get(i).trim(); int h = (int) g.getFont().getStringBounds(myCommentString, g.getFontRenderContext()) .getHeight(); g.drawString(line, myCommentPoint.x + 4, myCommentPoint.y + h + 2 + totalHeight); totalHeight += h; } } g.setFont(new Font(fontName, Font.PLAIN, Unimozer.DRAW_FONT_SIZE)); } /* if(!isEnabled()) { g.setColor(new Color(128,128,128,128)); g.fillRect(0,0,getWidth(),getHeight()); } */ this.setPreferredSize(new Dimension(mostRight + 32, mostBottom + 32)); // THE NEXT LINE MAKES ALL DIALOGUES DISAPEAR!! //this.setSize(mostRight+32, mostBottom+32); this.validate(); ((JScrollPane) this.getParent().getParent()).revalidate(); if (mode == MODE_EXTENDS && extendsFrom != null && extendsDragPoint != null) { graphics.setColor(Color.BLUE); ((Graphics2D) graphics).setStroke(new BasicStroke(2)); drawExtends(g, new Point(extendsFrom.getPosition().x + extendsFrom.getWidth() / 2, extendsFrom.getPosition().y + extendsFrom.getHeight() / 2), extendsDragPoint); graphics.setColor(Color.BLACK); ((Graphics2D) graphics).setStroke(new BasicStroke(1)); } }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Process the lat/lon labels tag// w w w .j a v a 2 s .co m * * @param child the XML * @param viewManager the associated view manager * @param image the image to draw on * @param imageProps the image properties * * @return a new image * * @throws Exception on badness */ public BufferedImage doLatLonLabels(Element child, ViewManager viewManager, BufferedImage image, Hashtable imageProps) throws Exception { if (viewManager == null) { throw new IllegalArgumentException("Tag " + TAG_LATLONLABELS + " requires a view"); } if (!(viewManager instanceof MapViewManager)) { throw new IllegalArgumentException("Tag " + TAG_LATLONLABELS + " requires a map view"); } MapViewManager mvm = (MapViewManager) viewManager; NavigatedDisplay display = (NavigatedDisplay) viewManager.getMaster(); DecimalFormat format = new DecimalFormat(applyMacros(child, ATTR_FORMAT, "##0.0")); Color color = applyMacros(child, ATTR_COLOR, Color.red); Color lineColor = applyMacros(child, ATTR_LINECOLOR, color); Color bg = applyMacros(child, ATTR_LABELBACKGROUND, (Color) null); double[] latValues = Misc.parseDoubles(applyMacros(child, ATTR_LAT_VALUES, "")); List<String> latLabels = StringUtil.split(applyMacros(child, ATTR_LAT_LABELS, ""), ",", true, true); double[] lonValues = Misc.parseDoubles(applyMacros(child, ATTR_LON_VALUES, "")); List<String> lonLabels = StringUtil.split(applyMacros(child, ATTR_LON_LABELS, ""), ",", true, true); boolean drawLonLines = applyMacros(child, ATTR_DRAWLONLINES, false); boolean drawLatLines = applyMacros(child, ATTR_DRAWLATLINES, false); boolean showTop = applyMacros(child, ATTR_SHOWTOP, false); boolean showBottom = applyMacros(child, ATTR_SHOWBOTTOM, true); boolean showLeft = applyMacros(child, ATTR_SHOWLEFT, true); boolean showRight = applyMacros(child, ATTR_SHOWRIGHT, false); int width = image.getWidth(null); int height = image.getHeight(null); int centerX = width / 2; int centerY = height / 2; EarthLocation nw, ne, se, sw; //don: this what I added Double north = (Double) imageProps.get(ATTR_NORTH); Double south = (Double) imageProps.get(ATTR_SOUTH); Double east = (Double) imageProps.get(ATTR_EAST); Double west = (Double) imageProps.get(ATTR_WEST); //Assume if we have one we have them all if (north != null) { nw = DisplayControlImpl.makeEarthLocation(north.doubleValue(), west.doubleValue(), 0); ne = DisplayControlImpl.makeEarthLocation(north.doubleValue(), east.doubleValue(), 0); sw = DisplayControlImpl.makeEarthLocation(south.doubleValue(), west.doubleValue(), 0); se = DisplayControlImpl.makeEarthLocation(south.doubleValue(), east.doubleValue(), 0); } else { nw = display.screenToEarthLocation(0, 0); ne = display.screenToEarthLocation(width, 0); se = display.screenToEarthLocation(0, height); sw = display.screenToEarthLocation(width, height); } double widthDegrees = ne.getLongitude().getValue() - nw.getLongitude().getValue(); double heightDegrees = ne.getLatitude().getValue() - se.getLatitude().getValue(); Insets insets = getInsets(child, 0); int delta = 2; int bgPad = 1; image = doMatte(image, child, 0); Graphics2D g = (Graphics2D) image.getGraphics(); g.setFont(getFont(child)); FontMetrics fm = g.getFontMetrics(); int lineOffsetRight = applyMacros(child, ATTR_LINEOFFSET_RIGHT, 0); int lineOffsetLeft = applyMacros(child, ATTR_LINEOFFSET_LEFT, 0); int lineOffsetTop = applyMacros(child, ATTR_LINEOFFSET_TOP, 0); int lineOffsetBottom = applyMacros(child, ATTR_LINEOFFSET_BOTTOM, 0); Stroke lineStroke; if (XmlUtil.hasAttribute(child, ATTR_DASHES)) { lineStroke = new BasicStroke((float) applyMacros(child, ATTR_LINEWIDTH, 1.0), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, Misc.parseFloats(applyMacros(child, ATTR_DASHES, "8")), 0.0f); } else { lineStroke = new BasicStroke((float) applyMacros(child, ATTR_LINEWIDTH, 1.0)); } g.setStroke(lineStroke); double leftLon = nw.getLongitude().getValue(CommonUnit.degree); double rightLon = ne.getLongitude().getValue(CommonUnit.degree); Range lonRange = new Range(leftLon, rightLon); for (int i = 0; i < lonValues.length; i++) { double lon = GeoUtils.normalizeLongitude(lonRange, lonValues[i]); double percent = (lon - nw.getLongitude().getValue()) / widthDegrees; // if(percent<0 || percent>1) continue; String label; if (i < lonLabels.size()) { label = lonLabels.get(i); } else { label = format.format(lonValues[i]); } Rectangle2D rect = fm.getStringBounds(label, g); int baseX = insets.left + (int) (percent * width); int x = baseX - (int) rect.getWidth() / 2; int topY; if (insets.top == 0) { topY = (int) rect.getHeight() + delta; } else { topY = insets.top - delta; } if (drawLonLines) { g.setColor(lineColor); g.drawLine(baseX, insets.top + lineOffsetTop, baseX, insets.top + height - lineOffsetBottom); } if (showTop) { if (bg != null) { g.setColor(bg); g.fillRect(x - bgPad, topY - (int) rect.getHeight() - bgPad, (int) rect.getWidth() + bgPad * 2, (int) rect.getHeight() + bgPad * 2); } g.setColor(color); g.drawString(label, x, topY); } int bottomY; if (insets.bottom == 0) { bottomY = insets.top + height - delta; } else { bottomY = insets.top + height + (int) rect.getHeight() + delta; } if (showBottom) { if (bg != null) { g.setColor(bg); g.fillRect(x - bgPad, bottomY - (int) rect.getHeight() - bgPad, (int) rect.getWidth() + bgPad * 2, (int) rect.getHeight() + bgPad * 2); } g.setColor(color); g.drawString(label, x, bottomY); } } for (int i = 0; i < latValues.length; i++) { double lat = latValues[i]; double percent = 1.0 - (lat - se.getLatitude().getValue()) / heightDegrees; int baseY = insets.top + (int) (percent * height); // if(percent<0 || percent>1) continue; String label; if (i < latLabels.size()) { label = latLabels.get(i); } else { label = format.format(lat); } Rectangle2D rect = fm.getStringBounds(label, g); int y = baseY + (int) rect.getHeight() / 2; int leftX; if (insets.left == 0) { leftX = 0 + delta; } else { leftX = insets.left - (int) rect.getWidth() - delta; } if (drawLonLines) { g.setColor(lineColor); g.drawLine(insets.left + lineOffsetRight, baseY, insets.left + width - lineOffsetRight, baseY); } if (showLeft) { if (bg != null) { g.setColor(bg); g.fillRect(leftX - bgPad, y - (int) rect.getHeight() - bgPad, (int) rect.getWidth() + bgPad * 2, (int) rect.getHeight() + bgPad * 2); } g.setColor(color); g.drawString(label, leftX, y); } if (insets.right == 0) { leftX = insets.left + width - (int) rect.getWidth() - delta; } else { leftX = insets.left + width + delta; } if (showRight) { if (bg != null) { g.setColor(bg); g.fillRect(leftX - bgPad, y - (int) rect.getHeight() - bgPad, (int) rect.getWidth() + bgPad * 2, (int) rect.getHeight() + bgPad * 2); } g.setColor(color); g.drawString(label, leftX, y); } } return image; }
From source file:org.simmi.GeneSetHead.java
License:asdf
public void repaintGCSkew(List<Sequence> selclist, Graphics2D g2, int size, GeneGroup gg, String selspec) { g2.setColor(Color.white);/*from ww w .j a v a 2s. co m*/ g2.fillRect(0, 0, 1024, 1024); g2.setFont(g2.getFont().deriveFont(10.0f)); int total = 0; int g = 0; int c = 0; double gcstotal = 0.0; for (Sequence ctg : selclist) { //Sequence ctg = clist.get( u ); if (gg != null) { for (Tegeval tv : gg.getTegevals()) { if (tv.getContshort() == ctg) { int i = tv.start; int x1 = (int) (512.0 + (384.0 - 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); int y1 = (int) (512.0 + (384.0 - 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); int x2 = (int) (512.0 + (384.0 + 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); int y2 = (int) (512.0 + (384.0 + 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); g2.setColor(Color.green); g2.drawLine(x1, y1, x2, y2); } } } double horn = total * 2.0 * Math.PI / size; double horn2 = (total + ctg.length()) * 2.0 * Math.PI / size; int x1 = (int) (512.0 + (384.0 - 100.0) * Math.cos(horn)); int y1 = (int) (512.0 + (384.0 - 100.0) * Math.sin(horn)); int x2 = (int) (512.0 + (384.0 + 100.0) * Math.cos(horn)); int y2 = (int) (512.0 + (384.0 + 100.0) * Math.sin(horn)); g2.setColor(Color.black); g2.drawLine(x1, y1, x2, y2); int xoff = (int) (512.0 + (384.0 + 100.0) * Math.cos(horn2)); int yoff = (int) (512.0 + (384.0 + 100.0) * Math.sin(horn2)); if (horn < Math.PI) { g2.translate(x2, y2); g2.rotate(horn + Math.PI / 2.0); g2.drawString(ctg.getName(), 0, 0); g2.rotate(-horn - Math.PI / 2.0); g2.translate(-x2, -y2); } else { g2.translate(xoff, yoff); g2.rotate(horn2 + Math.PI / 2.0); g2.drawString(ctg.getName(), -g2.getFontMetrics().stringWidth(ctg.getName()), 0); g2.rotate(-horn2 - Math.PI / 2.0); g2.translate(-xoff, -yoff); } for (int i = 0; i < ctg.length(); i += 500) { for (int k = i; k < Math.min(ctg.length(), i + 500); k++) { char chr = ctg.charAt(k); if (chr == 'g' || chr == 'G') { g++; } else if (chr == 'c' || chr == 'C') { c++; } } int gcount = 0; int ccount = 0; int acount = 0; int tcount = 0; for (int k = i; k < Math.min(ctg.length(), i + 10000); k++) { char chr = k - 5000 < 0 ? ctg.charAt(ctg.length() + (k - 5000)) : ctg.charAt(k - 5000); if (chr == 'g' || chr == 'G') { gcount++; } else if (chr == 'c' || chr == 'C') { ccount++; } else if (chr == 'a' || chr == 'A') acount++; else if (chr == 't' || chr == 'T') tcount++; } if (gcount > 0 || ccount > 0) { double gcskew = (gcount - ccount) / (double) (gcount + ccount); gcstotal += gcskew; x1 = (int) (512.0 + (384.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); y1 = (int) (512.0 + (384.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); x2 = (int) (512.0 + (384.0 + gcskew * 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); y2 = (int) (512.0 + (384.0 + gcskew * 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); if (gcskew >= 0) g2.setColor(Color.blue); else g2.setColor(Color.red); g2.drawLine(x1, y1, x2, y2); } if (acount > 0 || tcount > 0) { double atskew = (acount - tcount) / (double) (acount + tcount); x1 = (int) (512.0 + (300.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); y1 = (int) (512.0 + (300.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); x2 = (int) (512.0 + (300.0 + atskew * 100.0) * Math.cos((i + total) * 2.0 * Math.PI / size)); y2 = (int) (512.0 + (300.0 + atskew * 100.0) * Math.sin((i + total) * 2.0 * Math.PI / size)); if (atskew >= 0) g2.setColor(Color.blue); else g2.setColor(Color.red); g2.drawLine(x1, y1, x2, y2); } } total += ctg.length(); } g2.setColor(Color.black); g2.setFont(g2.getFont().deriveFont(java.awt.Font.ITALIC).deriveFont(32.0f)); String[] specsplit; // = selspec.split("_"); if (selspec.contains("hermus")) specsplit = selspec.split("_"); else { Matcher m = Pattern.compile("\\d").matcher(selspec); int firstDigitLocation = m.find() ? m.start() : 0; if (firstDigitLocation == 0) specsplit = new String[] { "Thermus", selspec }; else specsplit = new String[] { "Thermus", selspec.substring(0, firstDigitLocation), selspec.substring(firstDigitLocation) }; } int k = 0; for (String spec : specsplit) { int strw = g2.getFontMetrics().stringWidth(spec); g2.drawString(spec, (1024 - strw) / 2, 1024 / 2 - specsplit.length * 32 / 2 + 32 + k * 32); k++; } /*double gcs = gcstotal/total; //(g-c)/(g+c); String gcstr = Double.toString( Math.round( gcs*1000000.0 ) ); g2.drawString( gcstr+"ppm", 768, 512 );*/ }
From source file:tufts.vue.LWComponent.java
/** * Useful for drawing drag images into an existing graphics buffer, or drawing exportable images. * * @param alpha 0.0 (invisible) to 1.0 (no alpha -- completely opaque) * @param maxSize max dimensions for image. May be null. Image may be smaller than maxSize. * @param fillColor -- if non-null, will be rendered as background for image. * @param zoomRequest -- desired zoom; ignored if maxSize is non-null * also set, background fill will have transparency of alpha^3 to enhance contrast. *//* www . j a va2 s . c om*/ public void drawImage(Graphics2D g, double alpha, Dimension maxSize, Color fillColor, double zoomRequest) { //if (DEBUG.IMAGE) out("drawImage; size " + maxSize); final boolean drawBorder = false;// this instanceof LWMap; // hack for dragged images of LWMaps final Rectangle2D.Float bounds = getImageBounds(); final Rectangle clip = g.getClipBounds(); final Size fillSize = new Size(bounds); final double zoom = computeZoomAndSize(bounds, maxSize, zoomRequest, fillSize); if (DEBUG.IMAGE) out(TERM_GREEN + "drawImage:" + "\n\t mapBounds: " + fmt(bounds) + "\n\t fill: " + fillColor + "\n\t maxSize: " + maxSize + "\n\t zoomRequest: " + zoomRequest + "\n\t fitZoom: " + zoom + "\n\t fillSize: " + fillSize + "\n\t gc: " + g + "\n\t clip: " + fmt(clip) + "\n\t alpha: " + alpha + TERM_CLEAR); final int width = fillSize.pixelWidth(); final int height = fillSize.pixelHeight(); final DrawContext dc = new DrawContext(g, this); dc.setInteractive(false); if (alpha == OPAQUE) { dc.setPrintQuality(); } else { // if alpha, assume drag image (todo: better specified as an argument) dc.setDraftQuality(); } dc.setBackgroundFill(getRenderFillColor(null)); // sure we want null here? dc.setClipOptimized(false); // always draw all children -- don't bother to check bounds if (DEBUG.IMAGE) out(TERM_GREEN + "drawImage: " + dc + TERM_CLEAR); if (fillColor != null) { // if (false && alpha != OPAQUE) { // Color c = fillColor; // // if we have an alpha and a fill, amplify the alpha on the background fill // // by changing the fill to one that has alpha*alpha, for a total of // // alpha*alpha*alpha given our GC already has an alpha set. // fillColor = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (alpha*alpha*255+0.5)); // } if (alpha != OPAQUE) dc.setAlpha(alpha, AlphaComposite.SRC); // erase any underlying in cache if (DEBUG.IMAGE) out("drawImage: fill=" + fillColor); g.setColor(fillColor); g.fillRect(0, 0, width, height); } else { //if (alpha != OPAQUE) { // we didn't have a fill, but we have an alpha: make sure any cached data is cleared // todo?: if fill is null, we need to clear as well -- it means we have implied alpha on any non-drawn bits // TODO: if this is a selection drag, we usually want to fill with the map color (or ideally, the color // of the common parent, e.g., a slide, if there's one common parent) dc.g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, width, height); } //if (alpha != OPAQUE) dc.setAlpha(alpha, AlphaComposite.SRC); if (DEBUG.IMAGE && DEBUG.META) { // Fill the entire imageable area g.setColor(Color.green); g.fillRect(0, 0, Short.MAX_VALUE, Short.MAX_VALUE); } final AffineTransform rawTransform = g.getTransform(); if (zoom != 1.0) dc.g.scale(zoom, zoom); // translate so that the upper left corner of the map region // we're drawing is at 0,0 on the underlying image g.translate(-bounds.getX(), -bounds.getY()); // GC *must* have a bounds set or we get NPE's in JComponent (textBox) rendering dc.setMasterClip(bounds); if (DEBUG.IMAGE && DEBUG.META) { // fill the clipped area so we can check our clip bounds dc.g.setColor(Color.red); dc.g.fillRect(-Short.MAX_VALUE / 2, -Short.MAX_VALUE / 2, // larger values than this can blow out internal GC code and we get nothing Short.MAX_VALUE, Short.MAX_VALUE); } if (this instanceof LWImage) { // for some reason, raw images don't seem to want to draw unless we fill first dc.g.setColor(Color.white); dc.g.fill(bounds); } // render to the image through the DrawContext/GC pointing to it draw(dc); if (drawBorder) { g.setTransform(rawTransform); //g.setColor(Color.red); //g.fillRect(0,0, Short.MAX_VALUE, Short.MAX_VALUE); if (DEBUG.IMAGE) { g.setColor(Color.black); dc.setAntiAlias(false); } else g.setColor(Color.darkGray); g.drawRect(0, 0, width - 1, height - 1); } if (DEBUG.IMAGE) out(TERM_GREEN + "drawImage: completed\n" + TERM_CLEAR); }
From source file:org.forester.archaeopteryx.TreePanel.java
final private void paintNodeData(final Graphics2D g, final PhylogenyNode node, final boolean to_graphics_file, final boolean to_pdf, final boolean is_in_found_nodes) { if (isNodeDataInvisible(node) && !to_graphics_file && !to_pdf) { return;/*from ww w. ja v a2 s . c o m*/ } if (getOptions().isShowBranchLengthValues() && ((getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE)) && (!node.isRoot()) && (node.getDistanceToParent() != PhylogenyNode.DISTANCE_DEFAULT)) { paintBranchLength(g, node, to_pdf, to_graphics_file); } if (!getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse()) { return; } int x = 0; if (node.getNodeData().isHasTaxonomy() && (getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyNames())) { x = paintTaxonomy(g, node, is_in_found_nodes, to_pdf, to_graphics_file); } if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK); } else if (is_in_found_nodes) { g.setColor(getTreeColorSet().getFoundColor()); } else if (getControlPanel().isColorAccordingToTaxonomy()) { g.setColor(getTaxonomyBasedColor(node)); } else { g.setColor(getTreeColorSet().getSequenceColor()); } _sb.setLength(0); if (node.isCollapse() && ((!node.isRoot() && !node.getParent().isCollapse()) || node.isRoot())) { _sb.append(" ["); _sb.append(node.getAllExternalDescendants().size()); _sb.append("]"); } if (getControlPanel().isShowNodeNames() && (node.getNodeName().length() > 0)) { if (_sb.length() > 0) { _sb.append(" "); } _sb.append(node.getNodeName()); } if (node.getNodeData().isHasSequence()) { if (getControlPanel().isShowGeneSymbols() && (node.getNodeData().getSequence().getSymbol().length() > 0)) { if (_sb.length() > 0) { _sb.append(" "); } _sb.append(node.getNodeData().getSequence().getSymbol()); } if (getControlPanel().isShowGeneNames() && (node.getNodeData().getSequence().getName().length() > 0)) { // if ( _sb.length() > 0 ) { // _sb.append( " " ); // } // _sb.append( node.getNodeData().getSequence().getName() ); PhylogenyNode parent = node.getParent(); double x1 = parent.getXcoord(); double y1 = parent.getYcoord(); double x2 = node.getXcoord(); double y2 = node.getYcoord(); double above_the_line = 1.0; if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR) { double center_of_branch_x = Math.abs(x1 + x2) / 2.0; double center_of_branch_y = Math.abs(y1 + y2) / 2.0; TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x, center_of_branch_y - above_the_line, g); } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR) { double center_of_branch_x = Math.abs(x1 + x2) / 2.0; double center_of_branch_y = y2; TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x, center_of_branch_y - above_the_line, g); } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED) { double center_of_branch_x = Math.abs(x1 + x2) / 2.0; double center_of_branch_y = y2; TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x, center_of_branch_y - above_the_line, g); } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE) { double center_of_branch_x = Math.abs(x1 + x2) / 2.0 + EURO_D; double center_of_branch_y = y2; TreePanel.drawString(node.getNodeData().getSequence().getName(), center_of_branch_x, center_of_branch_y - above_the_line, g); } } if (getControlPanel().isShowSequenceAcc() && (node.getNodeData().getSequence().getAccession() != null)) { if (_sb.length() > 0) { _sb.append(" "); } if (!ForesterUtil.isEmpty(node.getNodeData().getSequence().getAccession().getSource())) { _sb.append(node.getNodeData().getSequence().getAccession().getSource()); _sb.append(":"); } _sb.append(node.getNodeData().getSequence().getAccession().getValue()); } } g.setFont(getTreeFontSet().getLargeFont()); if (is_in_found_nodes) { g.setFont(getTreeFontSet().getLargeFont().deriveFont(Font.BOLD)); } double down_shift_factor = 3.0; if (!node.isExternal() && (node.getNumberOfDescendants() == 1)) { down_shift_factor = 1; } // GUILHEM_BEG ______________ final double posX = node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE; final double posY = (node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor)); final int CONFIDENCE_LEFT_MARGIN = 4; final String sNodeText = _sb.toString(); if (_control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence() && (_query_sequence != null)) { int nodeTextBoundsWidth = 0; if (sNodeText.length() > 0) { final Rectangle2D node_text_bounds = new TextLayout(sNodeText, g.getFont(), _frc).getBounds(); //would like to remove this 'new', but how... nodeTextBoundsWidth = (int) node_text_bounds.getWidth(); } if (node.getNodeData().getSequence().equals(_query_sequence)) { if (nodeTextBoundsWidth > 0) { // invert font color and background color to show that this is the query sequence g.fillRect((int) posX - 1, (int) posY - 8, nodeTextBoundsWidth + 5, 11); g.setColor(getTreeColorSet().getBackgroundColor()); } } else { final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations(); for (final SequenceRelation seqRelation : seqRelations) { final boolean fGotRelationWithQuery = (seqRelation.getRef0().isEqual(_query_sequence) || seqRelation.getRef1().isEqual(_query_sequence)) && seqRelation.getType() .equals(getControlPanel().getSequenceRelationTypeBox().getSelectedItem()); if (fGotRelationWithQuery) { // we will underline the text to show that this sequence is ortholog to the query final double linePosX = node.getXcoord() + 2 + TreePanel.HALF_BOX_SIZE; final String sConfidence = (!getControlPanel().isShowSequenceRelationConfidence() || (seqRelation.getConfidence() == null)) ? null : " (" + seqRelation.getConfidence().getValue() + ")"; if (sConfidence != null) { double confidenceX = posX; if (sNodeText.length() > 0) { confidenceX += new TextLayout(sNodeText, g.getFont(), _frc).getBounds().getWidth() + CONFIDENCE_LEFT_MARGIN; } if (confidenceX > linePosX) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code final int confidenceWidth = (int) new TextLayout(sConfidence, g.getFont(), _frc) .getBounds().getWidth(); TreePanel.drawString(sConfidence, confidenceX, posY, g); x += CONFIDENCE_LEFT_MARGIN + confidenceWidth; } } if (x + nodeTextBoundsWidth > 0) /* we only underline if there is something displayed */ { if (nodeTextBoundsWidth == 0) { nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */ } else { nodeTextBoundsWidth += 2; } g.drawLine((int) linePosX + 1, 3 + (int) posY, (int) linePosX + x + nodeTextBoundsWidth, 3 + (int) posY); break; } } } } } if (sNodeText.length() > 0) { TreePanel.drawString(sNodeText, posX, posY, g); } // GUILHEM_END _____________ // COMMENTED_OUT_BY_GUILHEM_BEG _______________ // TODO FIXME need to check this one! //if ( _sb.length() > 0 ) { // TreePanel.drawString( _sb.toString(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord() // + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ), g ); //} // COMMENTED_OUT_BY_GUILHEM_END ________________ if (getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence() && (node.getNodeData().getSequence().getAnnotations() != null) && (!node.getNodeData().getSequence().getAnnotations().isEmpty())) { if (_sb.length() > 0) { x += getTreeFontSet()._fm_large.stringWidth(_sb.toString()) + 5; } final Annotation ann = (Annotation) node.getNodeData().getSequence().getAnnotations().get(0); if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK); } else { g.setColor(calculateColorForAnnotation(ann)); } final String ann_str = ann.asSimpleText().toString(); TreePanel.drawString(ann_str, node.getXcoord() + x + 3 + TreePanel.HALF_BOX_SIZE, node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor), g); _sb.setLength(0); _sb.append(ann_str); } if ((getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE) || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED)) { if ((getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts()) && node.getNodeData().isHasBinaryCharacters()) { if (_sb.length() > 0) { x += getTreeFontSet()._fm_large.stringWidth(_sb.toString()) + 5; } if ((to_pdf || to_graphics_file) && getOptions().isPrintBlackAndWhite()) { g.setColor(Color.BLACK); } else { g.setColor(getTreeColorSet().getBinaryDomainCombinationsColor()); } if (getControlPanel().isShowBinaryCharacters()) { TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer() .toString(), node.getXcoord() + x + 1 + TreePanel.HALF_BOX_SIZE, node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor), g); paintGainedAndLostCharacters(g, node, node.getNodeData().getBinaryCharacters().getGainedCharactersAsStringBuffer().toString(), node.getNodeData().getBinaryCharacters().getLostCharactersAsStringBuffer().toString()); } else { if (DRAW_MEAN_COUNTS && node.isInternal()) { final List<PhylogenyNode> ec = node.getAllExternalDescendants(); double sum = 0; int count = 0; for (final PhylogenyNode phylogenyNode : ec) { count++; if (phylogenyNode.getNodeData().getBinaryCharacters() != null) { sum += phylogenyNode.getNodeData().getBinaryCharacters().getPresentCount(); } } final double mean = ForesterUtil.round(sum / count, 1); TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCount() + " [" + mean + "]", node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor), g); } else { TreePanel.drawString(node.getNodeData().getBinaryCharacters().getPresentCount(), node.getXcoord() + x + 2 + TreePanel.HALF_BOX_SIZE, node.getYcoord() + (getTreeFontSet()._fm_large.getAscent() / down_shift_factor), g); } paintGainedAndLostCharacters(g, node, "+" + node.getNodeData().getBinaryCharacters().getGainedCount(), "-" + node.getNodeData().getBinaryCharacters().getLostCount()); } } } }