2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: Viewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.5 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/03/24 15:52:39 $ |
2 |
26 Feb 07 |
jari |
* $Author: eleanorahowe $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.util.awt; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Cursor; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Graphics; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.print.PageFormat; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.print.Printable; |
2 |
26 Feb 07 |
jari |
19 |
import java.io.Serializable; |
2 |
26 Feb 07 |
jari |
20 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
21 |
|
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
public abstract class Viewer extends JPanel implements Serializable, Printable { |
2 |
26 Feb 07 |
jari |
// public static final long serialVersionUID = 100010301010001L; |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
protected JFrame frame; |
2 |
26 Feb 07 |
jari |
29 |
protected Vector palette; |
2 |
26 Feb 07 |
jari |
30 |
protected int xOldEvent; |
2 |
26 Feb 07 |
jari |
31 |
protected int yOldEvent; |
2 |
26 Feb 07 |
jari |
32 |
public boolean mouseInside = false; |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
public Viewer(JFrame frame) { |
2 |
26 Feb 07 |
jari |
35 |
this.frame = frame; |
2 |
26 Feb 07 |
jari |
36 |
} |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
public Viewer() {} |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
//Should override this method in subclasses |
2 |
26 Feb 07 |
jari |
41 |
public int print(Graphics g, PageFormat format, int pagenum) {return 0;} |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
public void setVisible(boolean state){ |
2 |
26 Feb 07 |
jari |
44 |
super.setVisible(state); |
2 |
26 Feb 07 |
jari |
45 |
if (frame != null) frame.setVisible(state); |
2 |
26 Feb 07 |
jari |
46 |
} |
2 |
26 Feb 07 |
jari |
47 |
|
2 |
26 Feb 07 |
jari |
48 |
public boolean hasFrame() { |
2 |
26 Feb 07 |
jari |
49 |
if (frame != null) return true; |
2 |
26 Feb 07 |
jari |
50 |
else return false; |
2 |
26 Feb 07 |
jari |
51 |
} |
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
public JFrame getFrame() {return this.frame;} |
2 |
26 Feb 07 |
jari |
54 |
public void setCursor(int cursor) {setCursor(Cursor.getPredefinedCursor(cursor));} |
2 |
26 Feb 07 |
jari |
55 |
public void setXOldEvent(int xEvent) {this.xOldEvent = xEvent;} |
2 |
26 Feb 07 |
jari |
56 |
public int getXOldEvent() {return this.xOldEvent;} |
2 |
26 Feb 07 |
jari |
57 |
public void setYOldEvent(int yEvent) {this.yOldEvent = yEvent;} |
2 |
26 Feb 07 |
jari |
58 |
public int getYOldEvent() {return this.yOldEvent;} |
2 |
26 Feb 07 |
jari |
59 |
|
2 |
26 Feb 07 |
jari |
//Creates the pseudo-false color palette |
2 |
26 Feb 07 |
jari |
61 |
public Vector buildPalette() { |
2 |
26 Feb 07 |
jari |
62 |
palette = new Vector(256); |
2 |
26 Feb 07 |
jari |
63 |
Color newColor; |
2 |
26 Feb 07 |
jari |
64 |
double r, g, b; |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
newColor = new Color(0, 0, 0); |
2 |
26 Feb 07 |
jari |
67 |
palette.addElement(newColor); |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
for (int i = 1; i < 256; i++) { |
2 |
26 Feb 07 |
jari |
70 |
i = 255 - i; |
2 |
26 Feb 07 |
jari |
71 |
|
2 |
26 Feb 07 |
jari |
72 |
r = 0; g = 0; b = 0; |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
if (i < 33) r = 255; |
2 |
26 Feb 07 |
jari |
75 |
else if (i > 32 && i < 108) r = Math.abs( 255 * Math.cos((i - 32) * Math.PI / 151)); |
2 |
26 Feb 07 |
jari |
76 |
else if (i > 107) r = 0; |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
if (i < 5) g = 0; |
2 |
26 Feb 07 |
jari |
79 |
else if (i > 4 && i < 101) g = Math.abs((255 * Math.cos((i - 100) * Math.PI / 189))); |
2 |
26 Feb 07 |
jari |
80 |
else if (i > 100 && i < 229) g = Math.abs((255 * Math.cos((i - 100) * Math.PI / 294))); |
2 |
26 Feb 07 |
jari |
81 |
else if (i > 230) g = 0; |
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
if (i < 72) b = 0; |
2 |
26 Feb 07 |
jari |
84 |
else if (i > 71 && i < 200) b = Math.abs((255 * Math.cos((i - 199) * Math.PI / 256))); |
2 |
26 Feb 07 |
jari |
85 |
else if (i > 199) b = Math.abs((255 * Math.cos((i - 199) * Math.PI / 175))); |
2 |
26 Feb 07 |
jari |
86 |
|
2 |
26 Feb 07 |
jari |
87 |
newColor = new Color((float) r / 255, (float) g / 255, (float) b / 255); |
2 |
26 Feb 07 |
jari |
88 |
palette.addElement(newColor); |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
i = 255 - i; |
2 |
26 Feb 07 |
jari |
91 |
} |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
return palette; |
2 |
26 Feb 07 |
jari |
94 |
} |
2 |
26 Feb 07 |
jari |
95 |
} |