/Users/lyon/j4p/src/video/NeuquantCaptureBean.java
|
1 package video;
2
3 import j2d.ImageUtils;
4 import xml.Utils;
5
6 import java.awt.Dimension;
7 import java.awt.Rectangle;
8 import java.io.ByteArrayInputStream;
9 import java.io.ByteArrayOutputStream;
10 import java.io.IOException;
11 import java.io.ObjectInputStream;
12 import java.io.ObjectOutputStream;
13 import java.io.Serializable;
14 import java.util.prefs.Preferences;
15
16 /**
17 * DocJava, Inc.
18 * http://www.docjava.com
19 * Programmer: dlyon
20 * Date: Dec 8, 2004
21 * Time: 8:06:45 PM
22 */
23 public class NeuquantCaptureBean implements Serializable {
24 private boolean isSilentOnCapture = false;
25 private double secondsPerFrame = 1;
26 private boolean isLooped = true;
27 private boolean isBuffered = false;
28 private boolean isEntireScreen = true;
29 private String outputFile = null;
30 private Rectangle inputRectangle = ImageUtils.getScreenSize();
31 private Dimension outputSize =
32 new Dimension((int) inputRectangle.getWidth(),
33 (int) inputRectangle.getHeight());
34 private static String key = "NeuquantCaptureBeanProps";
35
36 public String toXml() {
37 return Utils.toXml(this) + "</java>";
38 }
39
40 public String toString() {
41 return toXml();
42 }
43
44 public static void main(String[] args) {
45 NeuquantCaptureBean ncb = NeuquantCaptureBean.restore();
46 System.out.println(ncb);
47 ncb.setLooped(false);
48 ncb.save();
49 }
50
51 /**
52 * saves the properties to the Preferences of the userRoot
53 */
54 public void save() {
55 try {
56 Preferences p = Preferences.userRoot();
57 ByteArrayOutputStream baos = new
58 ByteArrayOutputStream();
59 ObjectOutputStream oos = new
60 ObjectOutputStream(baos);
61 oos.writeObject(this);
62 baos.close();
63 p.putByteArray(key, baos.toByteArray());
64 } catch (IOException e) {
65 e.printStackTrace();
66 }
67 }
68
69 /**
70 * restores the properties from the preference in
71 * the user root.
72 */
73 public static NeuquantCaptureBean restore() {
74 try {
75 Preferences p = Preferences.userRoot();
76 byte b [] = p.getByteArray(key, null);
77 if (b == null)
78 return new NeuquantCaptureBean();
79 ByteArrayInputStream bais = new
80 ByteArrayInputStream(b);
81 ObjectInputStream ois = new
82 ObjectInputStream(bais);
83 Object o = ois.readObject();
84 bais.close();
85 return (NeuquantCaptureBean) o;
86 } catch (IOException e) {
87 e.printStackTrace();
88 } catch (ClassNotFoundException e) {
89 e.printStackTrace();
90 }
91 return new NeuquantCaptureBean();
92 }
93
94 public boolean isSilentOnCapture() {
95 return isSilentOnCapture;
96 }
97
98 public void setSilentOnCapture(boolean silentOnCapture) {
99 isSilentOnCapture = silentOnCapture;
100 }
101
102 public double getSecondsPerFrame() {
103 return secondsPerFrame;
104 }
105
106 public void setSecondsPerFrame(double secondsPerFrame) {
107 this.secondsPerFrame = secondsPerFrame;
108 }
109
110 public boolean isLooped() {
111 return isLooped;
112 }
113
114 public void setLooped(boolean looped) {
115 isLooped = looped;
116 }
117
118 public boolean isBuffered() {
119 return isBuffered;
120 }
121
122 public void setBuffered(boolean buffered) {
123 isBuffered = buffered;
124 }
125
126 public boolean isEntireScreen() {
127 return isEntireScreen;
128 }
129
130 public void setEntireScreen(boolean entireScreen) {
131 isEntireScreen = entireScreen;
132 }
133
134 public Rectangle getInputRectangle() {
135 return inputRectangle;
136 }
137
138 public void setInputRectangle(Rectangle inputRectangle) {
139 this.inputRectangle = inputRectangle;
140 }
141
142 public Dimension getOutputSize() {
143 return outputSize;
144 }
145
146 public void setOutputSize(Dimension outputSize) {
147 this.outputSize = outputSize;
148 }
149
150 public String getOutputFile() {
151 return outputFile;
152 }
153
154 public void setOutputFile(String outputFile) {
155 this.outputFile = outputFile;
156 }
157
158 public boolean isValidData() {
159 return true; // do error checking here....
160 }
161 }
162