2 // forester -- software libraries and applications
3 // for genomics and evolutionary biology research.
5 // Copyright (C) 2010 Christian M Zmasek
6 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.development;
28 import java.awt.Color;
29 import java.awt.Graphics;
30 import java.awt.Graphics2D;
31 import java.awt.RenderingHints;
33 public class ResidueRenderer extends AbstractRenderer {
35 static final Color EMPTY_COLOR = new Color( 250, 0, 250 );
36 static final Color POSITIVE_COLOR = new Color( 250, 0, 250 );
37 static final Color NEGATIVE_COLOR = new Color( 250, 0, 250 );
38 static final Color NULL_COLOR = new Color( 50, 50, 50 );
39 static final int DISTANCE_OVAL_BORDER = 1;
40 static final int SIZE_LIMIT = 7;
44 private static final long serialVersionUID = -2331160296913478874L;
45 private final char _value;
46 private Color _wellColor;
47 private boolean _isMarked;
48 private boolean _isSelected;
49 private final MsaRenderer _parentPlateRenderer;
51 public ResidueRenderer( final char value, final MsaRenderer parentPlateRenderer ) {
53 _parentPlateRenderer = parentPlateRenderer;
54 setIsSelected( false );
56 setStatus( ( byte ) 0 );
59 private double calcFactor( final double min, final double max ) {
60 return ( max - min ) / 255D;
63 private Color calcWellColor( double value,
67 final Color maxColor ) {
74 final double x = ( 255D * ( value - min ) ) / ( max - min );
75 final int red = ( int ) ( minColor.getRed() + ( x * calcFactor( minColor.getRed(), maxColor.getRed() ) ) );
76 final int green = ( int ) ( minColor.getGreen() + ( x * calcFactor( minColor.getGreen(), maxColor.getGreen() ) ) );
77 final int blue = ( int ) ( minColor.getBlue() + ( x * calcFactor( minColor.getBlue(), maxColor.getBlue() ) ) );
78 return new Color( red, green, blue );
81 private Color calcWellColor( double value,
87 final Color meanColor ) {
89 // return ResidueRenderer.NULL_COLOR;
91 if ( meanColor == null ) {
92 return calcWellColor( value, min, max, minColor, maxColor );
100 if ( value < mean ) {
101 final double x = ( 255D * ( value - min ) ) / ( mean - min );
102 final int red = ( int ) ( minColor.getRed() + ( x * calcFactor( minColor.getRed(), meanColor.getRed() ) ) );
103 final int green = ( int ) ( minColor.getGreen() + ( x * calcFactor( minColor.getGreen(),
104 meanColor.getGreen() ) ) );
105 final int blue = ( int ) ( minColor.getBlue() + ( x * calcFactor( minColor.getBlue(), meanColor.getBlue() ) ) );
106 return new Color( red, green, blue );
108 if ( value > mean ) {
109 final double x = ( 255D * ( value - mean ) ) / ( max - mean );
110 final int red = ( int ) ( meanColor.getRed() + ( x * calcFactor( meanColor.getRed(), maxColor.getRed() ) ) );
111 final int green = ( int ) ( meanColor.getGreen() + ( x * calcFactor( meanColor.getGreen(),
112 maxColor.getGreen() ) ) );
113 final int blue = ( int ) ( meanColor.getBlue() + ( x * calcFactor( meanColor.getBlue(), maxColor.getBlue() ) ) );
114 return new Color( red, green, blue );
121 public double getDataValue() {
126 public MsaRenderer getParentPlateRenderer() {
127 return _parentPlateRenderer;
130 public Color getWellColor() {
134 public boolean isMarked() {
139 public boolean isSelected() {
144 public void paint( final Graphics g ) {
145 final int width = getWellSize() - 1;
146 final int width_ = width - 1;
147 final int width__ = ( width_ - 1 ) + 1;
148 final int width__s = width__ - 2;
149 final int x_ = getX() + 1;
150 final int y_ = getY() + 1;
151 // final PlateDisplayPanel hmp = getParentPlateRenderer()
152 // .getPlateDisplayPanel();
153 // boolean draw_circle = hmp.isDrawCircle()
154 // || ( !hmp.isDrawCircle() && !hmp.isDrawSquare() && ( width > 7 ) );
155 // final boolean show_user_flags = _parentPlateRenderer
156 // .getPlateDisplayPanel().showUserFlagsCheckBox.isSelected();
157 // final boolean show_outlier_flags = _parentPlateRenderer
158 // .getPlateDisplayPanel().showOutliersCheckBox.isSelected();
159 // final boolean show_hit_picks = _parentPlateRenderer
160 // .getPlateDisplayPanel().showHitPicksCheckBox.isSelected();
161 // final boolean show_confirmed_hits = _parentPlateRenderer
162 // .getPlateDisplayPanel().showConfirmedHitsCheckBox.isSelected();
163 final Graphics2D g2 = ( Graphics2D ) g;
164 g2.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED );
166 g2.setColor( AbstractRenderer.MARKED_COLOR );
168 // else if ( !draw_circle && isSelected() ) {
169 // g2.setColor( AbstractRenderer.SELECTED_COLOR );
172 g2.setColor( AbstractRenderer.DEFAULT_COLOR );
174 g2.drawRect( getX(), getY(), width, width );
175 // if ( draw_circle ) {
176 // if ( isSelected() && isMarked() ) {
177 // g2.setColor( AbstractRenderer.MARKED_COLOR );
179 // else if ( isSelected() ) {
180 // g2.setColor( AbstractRenderer.SELECTED_COLOR );
183 // g2.setColor( AbstractRenderer.DEFAULT_COLOR );
185 // g2.fillRect( x_, y_, width_, width_ );
187 g2.setColor( getWellColor() );
188 // if ( draw_circle ) {
189 // g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
190 // RenderingHints.VALUE_ANTIALIAS_ON );
191 // if ( isSelected() && ( width > 6 ) ) {
192 // g2.fillOval( getX() + 2, getY() + 2, width__s, width__s );
194 // else if ( width < 5 ) {
195 // g2.fillOval( ( getX() + 1 ) - 1, ( getY() + 1 ) - 1,
196 // width__ + 2, width__ + 2 );
199 // g2.fillOval( getX() + 1, getY() + 1, width__, width__ );
202 if ( isMarked() || isSelected() ) {
203 g2.fillRect( getX() + 1, getY() + 1, width_, width_ );
206 g2.fillRect( ( getX() + 1 ) - 1, ( getY() + 1 ) - 1, width_ + 2, width_ + 2 );
210 public void resetWellColor( final double min, final double max, final Color minColor, final Color maxColor ) {
211 setWellColor( calcWellColor( getDataValue(), min, max, minColor, maxColor ) );
214 public void resetWellColor( final double min,
217 final Color minColor,
218 final Color maxColor,
219 final Color meanColor ) {
220 setWellColor( calcWellColor( getDataValue(), min, max, mean, minColor, maxColor, meanColor ) );
223 public void setIsMarked( final boolean isMarked ) {
224 _isMarked = isMarked;
228 public void setIsSelected( final boolean isSelected ) {
229 _isSelected = isSelected;
232 private void setWellColor( final Color wellColor ) {
233 _wellColor = wellColor;