comparison scripts/java/org/octave/Octave.java @ 15753:6e39fe7992d9

style fixes and copyright update for java files * ClassHelper.java, DlgListener.java, JDialogBox.java, Matrix.java, OctClassLoader.java, Octave.java, OctaveReference.java, TeXcode.java, TeXtranslator.java: Use Octave copyright text. Style fixes.
author John W. Eaton <jwe@octave.org>
date Sat, 08 Dec 2012 00:24:45 -0500
parents f96faf028d90
children
comparison
equal deleted inserted replaced
15752:f96faf028d90 15753:6e39fe7992d9
1 /* Copyright (C) 2007 Michael Goffioul 1 /*
2 ** 2
3 ** This program is free software; you can redistribute it and/or modify 3 Copyright (C) 2007 Michael Goffioul
4 ** it under the terms of the GNU General Public License as published by 4
5 ** the Free Software Foundation; either version 2 of the License, or 5 This file is part of Octave.
6 ** (at your option) any later version. 6
7 ** 7 Octave is free software; you can redistribute it and/or modify it
8 ** This program is distributed in the hope that it will be useful, 8 under the terms of the GNU General Public License as published by
9 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 9 the Free Software Foundation; either version 3 of the License, or (at
10 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 your option) any later version.
11 ** GNU General Public License for more details. 11
12 ** 12 Octave is distributed in the hope that it will be useful, but
13 ** You should have received a copy of the GNU General Public License 13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** along with this program; If not, see <http://www.gnu.org/licenses/>. 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20
15 */ 21 */
16 22
17 package org.octave; 23 package org.octave;
18 24
19 import java.util.*; 25 import java.util.*;
20 26
21 public class Octave 27 public class Octave
22 { 28 {
23 private static Object notifyObject = null; 29 private static Object notifyObject = null;
24 private static Object[] args = null; 30 private static Object[] args = null;
25 private static LinkedList invokeList = new LinkedList(); 31 private static LinkedList invokeList = new LinkedList ();
26 private static LinkedList waitList = new LinkedList(); 32 private static LinkedList waitList = new LinkedList ();
27 33
28 public native static boolean call (String name, Object[] argin, Object[] argout); 34 public native static boolean call (String name, Object[] argin, Object[] argout);
29 public native static void doInvoke(int ID, Object[] args); 35 public native static void doInvoke (int ID, Object[] args);
30 public native static void doEvalString(String cmd); 36 public native static void doEvalString (String cmd);
31 public native static boolean needThreadedInvokation(); 37 public native static boolean needThreadedInvokation ();
32 38
33 public static void checkPendingAction() 39 public static void checkPendingAction ()
34 { 40 {
35 if (notifyObject != null) 41 if (notifyObject != null)
36 { 42 {
37 synchronized(notifyObject) 43 synchronized (notifyObject)
38 { 44 {
39 if (notifyObject instanceof OctaveReference) 45 if (notifyObject instanceof OctaveReference)
40 doInvoke(((OctaveReference)notifyObject).getID(), args); 46 doInvoke (((OctaveReference)notifyObject).getID (), args);
41 else if (notifyObject instanceof String) 47 else if (notifyObject instanceof String)
42 doEvalString((String)notifyObject); 48 doEvalString ((String)notifyObject);
43 notifyObject.notifyAll(); 49 notifyObject.notifyAll ();
44 } 50 }
45 notifyObject = null; 51 notifyObject = null;
46 args = null; 52 args = null;
47 } 53 }
48 54
49 Object obj; 55 Object obj;
50 Object[] objArgs; 56 Object[] objArgs;
51 57
52 while (true) 58 while (true)
53 { 59 {
54 obj = null; 60 obj = null;
55 objArgs = null; 61 objArgs = null;
56 62
57 synchronized (invokeList) 63 synchronized (invokeList)
58 { 64 {
59 if (invokeList.size() > 0) 65 if (invokeList.size () > 0)
60 { 66 {
61 obj = invokeList.remove(); 67 obj = invokeList.remove ();
62 if (obj instanceof OctaveReference) 68 if (obj instanceof OctaveReference)
63 objArgs = (Object[])invokeList.remove(); 69 objArgs = (Object[])invokeList.remove ();
64 } 70 }
65 } 71 }
66 72
67 if (obj != null) 73 if (obj != null)
68 { 74 {
69 if (obj instanceof Runnable) 75 if (obj instanceof Runnable)
70 ((Runnable)obj).run(); 76 ((Runnable)obj).run ();
71 else if (obj instanceof OctaveReference) 77 else if (obj instanceof OctaveReference)
72 doInvoke(((OctaveReference)obj).getID(), objArgs); 78 doInvoke (((OctaveReference)obj).getID (), objArgs);
73 else if (obj instanceof String) 79 else if (obj instanceof String)
74 doEvalString((String)obj); 80 doEvalString ((String)obj);
75 } 81 }
76 else 82 else
77 break; 83 break;
78 } 84 }
79 /* 85 /*
80 synchronized(invokeList) 86 synchronized (invokeList)
81 { 87 {
82 while (invokeList.size() > 0) 88 while (invokeList.size () > 0)
83 { 89 {
84 Object obj = invokeList.remove(); 90 Object obj = invokeList.remove ();
85 if (obj instanceof Runnable) 91 if (obj instanceof Runnable)
86 ((Runnable)obj).run(); 92 ((Runnable)obj).run ();
87 if (obj instanceof OctaveReference) 93 if (obj instanceof OctaveReference)
88 { 94 {
89 Object[] objArgs = (Object[])invokeList.remove(); 95 Object[] objArgs = (Object[])invokeList.remove ();
90 doInvoke(((OctaveReference)obj).getID(), objArgs); 96 doInvoke (((OctaveReference)obj).getID (), objArgs);
91 } 97 }
92 else if (obj instanceof String) 98 else if (obj instanceof String)
93 doEvalString((String)obj); 99 doEvalString ((String)obj);
94 } 100 }
95 } 101 }
96 */ 102 */
97 } 103 }
98 104
99 private static void checkWaitState() 105 private static void checkWaitState ()
100 { 106 {
101 if (waitList.size() > 0) 107 if (waitList.size () > 0)
102 { 108 {
103 Object wObj = waitList.getFirst(); 109 Object wObj = waitList.getFirst ();
104 synchronized (wObj) 110 synchronized (wObj)
105 { 111 {
106 wObj.notifyAll(); 112 wObj.notifyAll ();
107 } 113 }
108 } 114 }
109 } 115 }
110 116
111 public static void invokeAndWait(OctaveReference ref, Object[] invokeArgs) 117 public static void invokeAndWait (OctaveReference ref, Object[] invokeArgs)
112 { 118 {
113 if (needThreadedInvokation()) 119 if (needThreadedInvokation ())
114 { 120 {
115 synchronized(ref) 121 synchronized (ref)
116 { 122 {
117 notifyObject = ref; 123 notifyObject = ref;
118 args = invokeArgs; 124 args = invokeArgs;
119 try { checkWaitState(); ref.wait(); } 125 try { checkWaitState (); ref.wait (); }
120 catch (InterruptedException e) {} 126 catch (InterruptedException e) {}
121 } 127 }
122 } 128 }
123 else 129 else
124 doInvoke(ref.getID(), invokeArgs); 130 doInvoke (ref.getID (), invokeArgs);
125 } 131 }
126 132
127 public static void evalAndWait(String cmd) 133 public static void evalAndWait (String cmd)
128 { 134 {
129 if (needThreadedInvokation()) 135 if (needThreadedInvokation ())
130 { 136 {
131 synchronized(cmd) 137 synchronized (cmd)
132 { 138 {
133 notifyObject = cmd; 139 notifyObject = cmd;
134 args = null; 140 args = null;
135 try { checkWaitState(); cmd.wait(); } 141 try { checkWaitState (); cmd.wait (); }
136 catch (InterruptedException e) {} 142 catch (InterruptedException e) {}
137 } 143 }
138 } 144 }
139 else 145 else
140 doEvalString(cmd); 146 doEvalString (cmd);
141 } 147 }
142 148
143 public static void invokeLater(Runnable r) 149 public static void invokeLater (Runnable r)
144 { 150 {
145 if (needThreadedInvokation()) 151 if (needThreadedInvokation ())
146 synchronized(invokeList) 152 synchronized (invokeList)
147 { 153 {
148 invokeList.add(r); 154 invokeList.add (r);
149 checkWaitState(); 155 checkWaitState ();
150 } 156 }
151 else 157 else
152 r.run(); 158 r.run ();
153 } 159 }
154 160
155 public static void invokeLater(OctaveReference ref, Object[] invokeArgs) 161 public static void invokeLater (OctaveReference ref, Object[] invokeArgs)
156 { 162 {
157 if (needThreadedInvokation()) 163 if (needThreadedInvokation ())
158 synchronized(invokeList) 164 synchronized (invokeList)
159 { 165 {
160 invokeList.add(ref); 166 invokeList.add (ref);
161 invokeList.add(invokeArgs); 167 invokeList.add (invokeArgs);
162 checkWaitState(); 168 checkWaitState ();
163 } 169 }
164 else 170 else
165 doInvoke(ref.getID(), invokeArgs); 171 doInvoke (ref.getID (), invokeArgs);
166 } 172 }
167 173
168 public static void evalLater(String cmd) 174 public static void evalLater (String cmd)
169 { 175 {
170 if (needThreadedInvokation()) 176 if (needThreadedInvokation ())
171 synchronized(invokeList) 177 synchronized (invokeList)
172 { 178 {
173 invokeList.add(cmd); 179 invokeList.add (cmd);
174 checkWaitState(); 180 checkWaitState ();
175 } 181 }
176 else 182 else
177 doEvalString(cmd); 183 doEvalString (cmd);
178 } 184 }
179 185
180 public static void waitFor(Object wObj) 186 public static void waitFor (Object wObj)
181 { 187 {
182 waitList.add(0, wObj); 188 waitList.add (0, wObj);
183 synchronized (wObj) 189 synchronized (wObj)
184 { 190 {
185 while (waitList.size() > 0 && waitList.getFirst() == wObj) 191 while (waitList.size () > 0 && waitList.getFirst () == wObj)
186 { 192 {
187 try { wObj.wait(); } 193 try { wObj.wait (); }
188 catch (InterruptedException e) {} 194 catch (InterruptedException e) {}
189 checkPendingAction(); 195 checkPendingAction ();
190 } 196 }
191 } 197 }
192 } 198 }
193 199
194 public static void endWaitFor(Object obj) 200 public static void endWaitFor (Object obj)
195 { 201 {
196 boolean isCurrentWaitObject = (waitList.size() > 0 && waitList.getFirst() == obj); 202 boolean isCurrentWaitObject = (waitList.size () > 0 && waitList.getFirst () == obj);
197 203
198 waitList.remove(obj); 204 waitList.remove (obj);
199 if (needThreadedInvokation() && isCurrentWaitObject) 205 if (needThreadedInvokation () && isCurrentWaitObject)
200 synchronized (obj) 206 synchronized (obj)
201 { 207 {
202 obj.notifyAll(); 208 obj.notifyAll ();
203 } 209 }
204 } 210 }
205 211
206 public static Object do_test (String name, Object arg0) throws Exception 212 public static Object do_test (String name, Object arg0) throws Exception
207 { 213 {
208 Object[] argin = new Object[] { arg0 }; 214 Object[] argin = new Object[] { arg0 };
209 Object[] argout = new Object[1]; 215 Object[] argout = new Object[1];
210 if (call (name, argin, argout)) 216 if (call (name, argin, argout))
211 return argout[0]; 217 return argout[0];
212 throw new Exception ("octave call failed"); 218 throw new Exception ("octave call failed");
213 } 219 }
214 } 220 }