1 | //////////////////////////////////////////////////////////////////////// |
---|
2 | // |
---|
3 | // This file RayPanel.java is part of SURFEX. |
---|
4 | // |
---|
5 | //////////////////////////////////////////////////////////////////////// |
---|
6 | |
---|
7 | //////////////////////////////////////////////////////////////////////// |
---|
8 | // |
---|
9 | // SURFEX version 0.90.00 |
---|
10 | // ================= |
---|
11 | // |
---|
12 | // Saarland University at Saarbruecken, Germany |
---|
13 | // Department of Mathematics and Computer Science |
---|
14 | // |
---|
15 | // SURFEX on the web: www.surfex.AlgebraicSurface.net |
---|
16 | // |
---|
17 | // Authors: Oliver Labs (2001-2008), Stephan Holzer (2004-2005) |
---|
18 | // |
---|
19 | // Copyright (C) 2001-2008 |
---|
20 | // |
---|
21 | // |
---|
22 | // *NOTICE* |
---|
23 | // ======== |
---|
24 | // |
---|
25 | // This program is free software; you can redistribute it and/or modify it |
---|
26 | // under the terms of the GNU General Public License as published by the |
---|
27 | // Free Software Foundation ( version 3 or later of the License ). |
---|
28 | // |
---|
29 | // See LICENCE.TXT for details. |
---|
30 | // |
---|
31 | ///////////////////////////////////////////////////////////////////////// |
---|
32 | |
---|
33 | import java.awt.Dimension; |
---|
34 | import java.awt.Graphics; |
---|
35 | import java.awt.Image; |
---|
36 | import java.awt.Toolkit; |
---|
37 | import java.net.URL; |
---|
38 | |
---|
39 | import javax.swing.*; |
---|
40 | import javax.swing.SwingUtilities; |
---|
41 | |
---|
42 | ////////////////////////////////////////////////////////////// |
---|
43 | // |
---|
44 | // class RayPanel |
---|
45 | // |
---|
46 | ////////////////////////////////////////////////////////////// |
---|
47 | |
---|
48 | public class RayPanel extends JPanel { |
---|
49 | private Image theIMG = null; |
---|
50 | |
---|
51 | Graphics offGraphics; |
---|
52 | |
---|
53 | Dimension offDimension; |
---|
54 | |
---|
55 | Image offImage; |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | String picname = ""; |
---|
60 | |
---|
61 | RayPanel() { |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | public void changeBackground(String pn) { |
---|
67 | picname = pn; |
---|
68 | if (theIMG != null) { |
---|
69 | theIMG.flush(); |
---|
70 | theIMG = null; |
---|
71 | } |
---|
72 | // if (theIMG != null) { |
---|
73 | // theIMG.flush(); |
---|
74 | // } |
---|
75 | // theIMG = Toolkit.getDefaultToolkit().getImage(picname); |
---|
76 | |
---|
77 | SwingUtilities.updateComponentTreeUI(this); |
---|
78 | repaint(); |
---|
79 | } |
---|
80 | |
---|
81 | public void paint(Graphics g) { |
---|
82 | update(g); |
---|
83 | } |
---|
84 | |
---|
85 | // |
---|
86 | public void update(Graphics g) { |
---|
87 | // System.out.println("update..."); |
---|
88 | if (1 == 1) { |
---|
89 | Dimension d = getSize(); |
---|
90 | if ((offGraphics == null) || (d.width != offDimension.width) |
---|
91 | || (d.height != offDimension.height)) { |
---|
92 | offDimension = d; |
---|
93 | offImage = createImage(d.width, d.height); |
---|
94 | offGraphics = offImage.getGraphics(); |
---|
95 | } |
---|
96 | |
---|
97 | if (theIMG == null) { |
---|
98 | // System.out.println("null IMG:"+picname+"..."); |
---|
99 | if (picname.length() < 5) { |
---|
100 | if (picname.length() > 0) { |
---|
101 | // System.out.println("get IMG"+picname+"..."); |
---|
102 | theIMG = Toolkit.getDefaultToolkit().getImage(picname); |
---|
103 | // System.out.println("got IMG:"+picname+"."); |
---|
104 | } |
---|
105 | } else { |
---|
106 | if ((picname.substring(0, 5)).equals("http:")) { |
---|
107 | // System.out.println("try to load:"+picname); |
---|
108 | try { |
---|
109 | theIMG = Toolkit.getDefaultToolkit().getImage( |
---|
110 | new URL(picname)); |
---|
111 | // System.out.println("got image"); |
---|
112 | } catch (Exception ex) { |
---|
113 | System.out.println(ex.toString()); |
---|
114 | } |
---|
115 | } else { |
---|
116 | // System.out.println("get IMG"+picname+"..."); |
---|
117 | theIMG = Toolkit.getDefaultToolkit().getImage(picname); |
---|
118 | // System.out.println("got IMG:"+picname+"."); |
---|
119 | // theIMG = Toolkit.getDefaultToolkit().getImage(picname); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | if (theIMG != null) { |
---|
124 | // System.out.println("draw IMG"); |
---|
125 | // offGraphics.setColor(Color.black); |
---|
126 | // offGraphics.clearRect(0,0,d.width,d.height); |
---|
127 | // offGraphics.setClip(0,0,d.width,d.height); |
---|
128 | offGraphics.drawImage(theIMG, 0, 0, d.width, d.height, this); |
---|
129 | // System.out.println("image drawn"); |
---|
130 | } |
---|
131 | |
---|
132 | g.drawImage(offImage, 0, 0, this); |
---|
133 | } |
---|
134 | } |
---|
135 | } // end class RayPanel |
---|
136 | |
---|