001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 * Created on Aug 3, 2007 021 */ 022package org.biojava.nbio.structure.gui.util.color; 023 024import java.awt.*; 025 026 027/** 028 * Color Mapper which mimics the default coloring of JMatrixPanel pixels. 029 * 030 * Assumes inputs in the range [0,max]. These are mapped to HSB colors such 031 * that the hue and brightness are from [1,0]. 032 * @author Spencer Bliven 033 * 034 */ 035public class DefaultMatrixMapper implements ContinuousColorMapper { 036 037 private double scalevalue; 038 private float saturation; 039 040 public DefaultMatrixMapper(double scale, float saturation ) { 041 this.scalevalue = scale; 042 this.saturation = saturation; 043 } 044 /** 045 * @param value 046 * @return 047 * @see org.biojava.nbio.structure.gui.util.color.ContinuousColorMapper#getColor(double) 048 */ 049 @Override 050 public Color getColor(double value) { 051 float hue = 1.0f; 052 hue = (float)(1-(value/scalevalue)); 053 if (hue < 0) 054 hue = 0; 055 056 return Color.getHSBColor(hue,saturation,hue); 057 } 058 059 /** 060 * @return the scalevalue 061 */ 062 public double getScalevalue() { 063 return scalevalue; 064 } 065 /** 066 * @param scalevalue the scalevalue to set 067 */ 068 public void setScalevalue(double scalevalue) { 069 this.scalevalue = scalevalue; 070 } 071 /** 072 * @return the saturation 073 */ 074 public float getSaturation() { 075 return saturation; 076 } 077 /** 078 * @param saturation the saturation to set 079 */ 080 public void setSaturation(float saturation) { 081 this.saturation = saturation; 082 } 083}