2 |
26 Feb 07 |
jari |
1 |
|
2 |
26 Feb 07 |
jari |
2 |
package org.tigr.microarray.mev.cgh.CGHGuiObj.CGHPositionGraph; |
2 |
26 Feb 07 |
jari |
3 |
|
2 |
26 Feb 07 |
jari |
4 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
5 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
6 |
import java.awt.Font; |
2 |
26 Feb 07 |
jari |
7 |
import java.awt.FontMetrics; |
2 |
26 Feb 07 |
jari |
8 |
import java.awt.Graphics2D; |
2 |
26 Feb 07 |
jari |
9 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
10 |
import java.awt.RenderingHints; |
2 |
26 Feb 07 |
jari |
11 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
12 |
|
2 |
26 Feb 07 |
jari |
13 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
14 |
|
2 |
26 Feb 07 |
jari |
15 |
import org.tigr.microarray.mev.cgh.CGHDataModel.CGHPositionGraphDataModel; |
2 |
26 Feb 07 |
jari |
16 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
17 |
|
2 |
26 Feb 07 |
jari |
18 |
/* |
2 |
26 Feb 07 |
jari |
19 |
* |
2 |
26 Feb 07 |
jari |
* @author Adam Margolin |
2 |
26 Feb 07 |
jari |
* @author Raktim Sinha |
2 |
26 Feb 07 |
jari |
22 |
*/ |
2 |
26 Feb 07 |
jari |
23 |
|
2 |
26 Feb 07 |
jari |
24 |
public class CGHPositionGraphHeader extends JPanel { |
2 |
26 Feb 07 |
jari |
25 |
|
2 |
26 Feb 07 |
jari |
26 |
protected Insets insets; |
2 |
26 Feb 07 |
jari |
27 |
protected int contentWidth; |
2 |
26 Feb 07 |
jari |
28 |
protected int elementWidth; |
2 |
26 Feb 07 |
jari |
29 |
protected boolean isAntiAliasing = true; |
2 |
26 Feb 07 |
jari |
30 |
protected boolean isTracing = false; |
2 |
26 Feb 07 |
jari |
31 |
protected int tracespace; |
2 |
26 Feb 07 |
jari |
32 |
protected final int RECT_HEIGHT = 15; |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
BufferedImage negColorImage; |
2 |
26 Feb 07 |
jari |
35 |
BufferedImage posColorImage; |
2 |
26 Feb 07 |
jari |
36 |
protected float maxValue; |
2 |
26 Feb 07 |
jari |
37 |
protected float minValue; |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
CGHPositionGraphDataModel model; |
2 |
26 Feb 07 |
jari |
40 |
|
2 |
26 Feb 07 |
jari |
41 |
int rectSpacing = 5; |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>MultipleArrayHeader</code> with specified |
2 |
26 Feb 07 |
jari |
* insets and trace space. |
2 |
26 Feb 07 |
jari |
46 |
*/ |
2 |
26 Feb 07 |
jari |
47 |
public CGHPositionGraphHeader(Insets insets) { |
2 |
26 Feb 07 |
jari |
48 |
setBackground(Color.black); |
2 |
26 Feb 07 |
jari |
49 |
setSize(200,200); |
2 |
26 Feb 07 |
jari |
50 |
setPreferredSize(new Dimension(200,200)); |
2 |
26 Feb 07 |
jari |
51 |
this.insets = insets; |
2 |
26 Feb 07 |
jari |
//this.tracespace = tracespace; |
2 |
26 Feb 07 |
jari |
53 |
this.maxValue = 3.0f; |
2 |
26 Feb 07 |
jari |
54 |
this.minValue = 0.0f; |
2 |
26 Feb 07 |
jari |
55 |
} |
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the anti-aliasing attribute. |
2 |
26 Feb 07 |
jari |
59 |
*/ |
2 |
26 Feb 07 |
jari |
60 |
public void setAntiAliasing(boolean isAntiAliasing) { |
2 |
26 Feb 07 |
jari |
61 |
this.isAntiAliasing = isAntiAliasing; |
2 |
26 Feb 07 |
jari |
62 |
} |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the element width attribute. |
2 |
26 Feb 07 |
jari |
66 |
*/ |
2 |
26 Feb 07 |
jari |
67 |
void setElementWidth(int width) { |
2 |
26 Feb 07 |
jari |
68 |
this.elementWidth = width; |
2 |
26 Feb 07 |
jari |
69 |
setFontSize(width); |
2 |
26 Feb 07 |
jari |
70 |
updateSize(); |
2 |
26 Feb 07 |
jari |
71 |
this.repaint(); |
2 |
26 Feb 07 |
jari |
72 |
} |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the content width attribute. |
2 |
26 Feb 07 |
jari |
76 |
*/ |
2 |
26 Feb 07 |
jari |
77 |
void setContentWidth(int width) { |
2 |
26 Feb 07 |
jari |
78 |
this.contentWidth = width; |
2 |
26 Feb 07 |
jari |
79 |
this.repaint(); |
2 |
26 Feb 07 |
jari |
80 |
} |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
/** |
2 |
26 Feb 07 |
jari |
* Sets min and max ratio values |
2 |
26 Feb 07 |
jari |
84 |
*/ |
2 |
26 Feb 07 |
jari |
85 |
public void setMinAndMaxRatios(float min, float max){ |
2 |
26 Feb 07 |
jari |
86 |
this.minValue = min; |
2 |
26 Feb 07 |
jari |
87 |
this.maxValue = max; |
2 |
26 Feb 07 |
jari |
88 |
this.repaint(); |
2 |
26 Feb 07 |
jari |
89 |
} |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
/** |
2 |
26 Feb 07 |
jari |
* Sets positive and negative color images |
2 |
26 Feb 07 |
jari |
93 |
*/ |
2 |
26 Feb 07 |
jari |
//public void setNegativeAndPositiveColorImages(BufferedImage neg, BufferedImage pos){ |
2 |
26 Feb 07 |
jari |
// this.negColorImage = neg; |
2 |
26 Feb 07 |
jari |
// this.posColorImage = pos; |
2 |
26 Feb 07 |
jari |
97 |
//} |
2 |
26 Feb 07 |
jari |
98 |
|
2 |
26 Feb 07 |
jari |
99 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the isTracing attribute. |
2 |
26 Feb 07 |
jari |
101 |
*/ |
2 |
26 Feb 07 |
jari |
102 |
void setTracing(boolean isTracing) { |
2 |
26 Feb 07 |
jari |
103 |
this.isTracing = isTracing; |
2 |
26 Feb 07 |
jari |
104 |
} |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
106 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a trace space value. |
2 |
26 Feb 07 |
jari |
108 |
*/ |
2 |
26 Feb 07 |
jari |
109 |
private int getSpacing() { |
2 |
26 Feb 07 |
jari |
110 |
/* |
2 |
26 Feb 07 |
jari |
if (isTracing) { |
2 |
26 Feb 07 |
jari |
return tracespace; |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
return 0; |
2 |
26 Feb 07 |
jari |
115 |
*/ |
2 |
26 Feb 07 |
jari |
116 |
return rectSpacing; |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
/** |
2 |
26 Feb 07 |
jari |
* Sets the component font size. |
2 |
26 Feb 07 |
jari |
121 |
*/ |
2 |
26 Feb 07 |
jari |
122 |
private void setFontSize(int width) { |
2 |
26 Feb 07 |
jari |
123 |
if (width > 12) { |
2 |
26 Feb 07 |
jari |
124 |
width = 12; |
2 |
26 Feb 07 |
jari |
125 |
} |
2 |
26 Feb 07 |
jari |
126 |
setFont(new Font("monospaced", Font.PLAIN, width)); |
2 |
26 Feb 07 |
jari |
127 |
} |
2 |
26 Feb 07 |
jari |
128 |
|
2 |
26 Feb 07 |
jari |
129 |
/** |
2 |
26 Feb 07 |
jari |
* Updates the header size. |
2 |
26 Feb 07 |
jari |
131 |
*/ |
2 |
26 Feb 07 |
jari |
132 |
void updateSize() { |
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
Graphics2D g = (Graphics2D)getGraphics(); |
2 |
26 Feb 07 |
jari |
135 |
if (g == null) { |
2 |
26 Feb 07 |
jari |
136 |
return; |
2 |
26 Feb 07 |
jari |
137 |
} |
2 |
26 Feb 07 |
jari |
138 |
if (isAntiAliasing) { |
2 |
26 Feb 07 |
jari |
139 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF); |
2 |
26 Feb 07 |
jari |
140 |
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
2 |
26 Feb 07 |
jari |
141 |
} |
2 |
26 Feb 07 |
jari |
142 |
FontMetrics hfm = g.getFontMetrics(); |
2 |
26 Feb 07 |
jari |
143 |
int maxHeight = 0; |
2 |
26 Feb 07 |
jari |
144 |
String name; |
2 |
26 Feb 07 |
jari |
//final int size = model.getNumExperiments(); |
2 |
26 Feb 07 |
jari |
146 |
final int size = model.getNumExperiments(); |
2 |
26 Feb 07 |
jari |
147 |
for (int feature = 0; feature < size; feature++) { |
2 |
26 Feb 07 |
jari |
148 |
name = model.getExperimentName(feature); |
2 |
26 Feb 07 |
jari |
149 |
if(name == null){ |
2 |
26 Feb 07 |
jari |
150 |
maxHeight = 1; |
2 |
26 Feb 07 |
jari |
151 |
}else{ |
2 |
26 Feb 07 |
jari |
152 |
maxHeight = Math.max(maxHeight, hfm.stringWidth(name)); |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
} |
2 |
26 Feb 07 |
jari |
155 |
|
2 |
26 Feb 07 |
jari |
/* if(!this.isTracing) |
2 |
26 Feb 07 |
jari |
contentWidth = this.model.getNumExperiments() * this.elementWidth; |
2 |
26 Feb 07 |
jari |
else |
2 |
26 Feb 07 |
jari |
contentWidth = (this.model.getNumExperiments() - 1) * (this.elementWidth + getSpacing()) + this.elementWidth ; |
2 |
26 Feb 07 |
jari |
160 |
*/ |
2 |
26 Feb 07 |
jari |
161 |
setSize(contentWidth, maxHeight+10+this.RECT_HEIGHT+hfm.getHeight()); |
2 |
26 Feb 07 |
jari |
162 |
setPreferredSize(new Dimension(contentWidth, maxHeight+10+this.RECT_HEIGHT+hfm.getHeight())); |
2 |
26 Feb 07 |
jari |
163 |
} |
2 |
26 Feb 07 |
jari |
164 |
|
2 |
26 Feb 07 |
jari |
/** Getter for property model. |
2 |
26 Feb 07 |
jari |
* @return Value of property model. |
2 |
26 Feb 07 |
jari |
167 |
*/ |
2 |
26 Feb 07 |
jari |
168 |
public CGHPositionGraphDataModel getModel() { |
2 |
26 Feb 07 |
jari |
169 |
return model; |
2 |
26 Feb 07 |
jari |
170 |
} |
2 |
26 Feb 07 |
jari |
171 |
|
2 |
26 Feb 07 |
jari |
/** Setter for property model. |
2 |
26 Feb 07 |
jari |
* @param model New value of property model. |
2 |
26 Feb 07 |
jari |
174 |
*/ |
2 |
26 Feb 07 |
jari |
175 |
public void setModel(CGHPositionGraphDataModel model) { |
2 |
26 Feb 07 |
jari |
176 |
this.model = model; |
2 |
26 Feb 07 |
jari |
177 |
this.negColorImage = model.getNegColorImage(); |
2 |
26 Feb 07 |
jari |
178 |
this.posColorImage = model.getPosColorImage(); |
2 |
26 Feb 07 |
jari |
179 |
} |
2 |
26 Feb 07 |
jari |
180 |
|
2 |
26 Feb 07 |
jari |
/** Getter for property insets. |
2 |
26 Feb 07 |
jari |
* @return Value of property insets. |
2 |
26 Feb 07 |
jari |
183 |
*/ |
2 |
26 Feb 07 |
jari |
184 |
public java.awt.Insets getInsets() { |
2 |
26 Feb 07 |
jari |
185 |
return insets; |
2 |
26 Feb 07 |
jari |
186 |
} |
2 |
26 Feb 07 |
jari |
187 |
|
2 |
26 Feb 07 |
jari |
/** Setter for property insets. |
2 |
26 Feb 07 |
jari |
* @param insets New value of property insets. |
2 |
26 Feb 07 |
jari |
190 |
*/ |
2 |
26 Feb 07 |
jari |
191 |
public void setInsets(java.awt.Insets insets) { |
2 |
26 Feb 07 |
jari |
192 |
this.insets = insets; |
2 |
26 Feb 07 |
jari |
193 |
} |
2 |
26 Feb 07 |
jari |
194 |
|
2 |
26 Feb 07 |
jari |
195 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
//this.negColorImage = menu.getNegativeGradientImage(); |
2 |
26 Feb 07 |
jari |
//this.posColorImage = menu.getPositiveGradientImage(); |
2 |
26 Feb 07 |
jari |
198 |
model.setNegColorImage(menu.getNegativeGradientImage()); |
2 |
26 Feb 07 |
jari |
199 |
model.setPosColorImage(menu.getPositiveGradientImage()); |
2 |
26 Feb 07 |
jari |
200 |
|
2 |
26 Feb 07 |
jari |
201 |
setMinAndMaxRatios(menu.getMinRatioScale(), menu.getMaxRatioScale()); |
2 |
26 Feb 07 |
jari |
202 |
} |
2 |
26 Feb 07 |
jari |
203 |
|
2 |
26 Feb 07 |
jari |
204 |
} |