History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/awt/iFramePeer.java (1 of 18352 files). Show all

Unified · Split

java/pkg/awt/iFramePeer.java+527−0
@@ -0,0 +1,527 @@
1package inferno.awt;
2
3import java.awt.*;
4import java.awt.event.*;
5import java.awt.peer.*;
6import java.awt.image.ImageProducer;
7import java.awt.image.ImageObserver;
8import java.awt.image.ColorModel;
9import java.awt.image.DirectColorModel;
10import java.util.*;
11import inferno.awt.iGraphics;
12
13public class iFramePeer implements FramePeer, DoubleBufferingPeer {
14 private Object pCanvas; // Set inside create() used by natives
15
16 // set inside create(), used by natives, to avoid some clutter in
17 // escaping the Limbo type system.
18 private Object thisAsJObject;
19
20 private Frame target;
21
22 private int leftInset=0; // How much canvas is inset from frame
23 private int rightInset=0;
24 private int topInset=0;
25 private int bottomInset=0;
26 private int left; // x position of left of frame
27 private int top; // y position of top of frame
28
29 private Point oldMousePoint;
30 private boolean buttonState[];
31
32 private int resizable = 1;
33
34 public iFramePeer(Frame target) {
35 this.target = target;
36 oldMousePoint=new Point(-1,-1);
37 buttonState=new boolean[3];
38 for (int i=0;i<3;i++) buttonState[i]=false; //up
39 // create(this);
40 if (target.getTitle() != null) {
41 setTitle(target.getTitle());
42 }
43 Font f = target.getFont();
44 if (f == null) {
45 f = new Font("Dialog", Font.PLAIN, 12);
46 target.setFont(f);
47 setFont(f);
48 }
49 Color c = target.getBackground();
50 if (c == null) {
51 c = SystemColor.window;
52 target.setBackground(c);
53 setBackground(c);
54 }
55 c = target.getForeground();
56 if (c == null) {
57 target.setForeground(Color.black);
58 setForeground(Color.black);
59 }
60 if (!target.isResizable())
61 this.resizable = 0;
62
63 create(this);
64
65 }
66
67 /* implementation of java.awt.peer.DoubleBufferingPeer */
68 public boolean isDoubleBuffered() {
69 return true;
70 }
71
72 private native Object getRefImage(); // Returns dev/draw image of canvas
73
74 private native Object getRefOffScreenImage(); // Returns off-screen buffer image
75
76 private native void pReshape(int x, int y, int width, int height);
77
78 private native void pHide(); // Hide frame
79
80 private native void pShow(iFramePeer fp); // Show frame
81
82 private native int getXYLoc(int coord); // get x or y value of the global position
83
84 // Create frame putting canvas in pcanvas
85 private native void create(iFramePeer me);
86
87 public native void pDispose(); // Destroy frame
88 public native void setCursor(int cursorType); // Set cursor
89 public native void setTitle(String title); // Set title of frame
90 public native void toFront(); // Move frame to front
91 public native void toBack(); // Move frame to back
92
93
94 /* New 1.1 API */
95 public Point getLocationOnScreen() // Return position on screen
96 {
97 Point p = new Point();
98 p.x = getXYLoc(0);
99 p.y = getXYLoc(1);
100 return p;
101 }
102
103 public void recalculate()
104 {
105 MenuBar mb=target.getMenuBar();
106 if (mb!=null)
107 {
108 iMenuBarPeer ip=(iMenuBarPeer)mb.getPeer();
109
110 if (ip!=null)
111 {
112 ip.recalculate();
113 }
114 }
115 }
116
117 public void setCursor(Cursor c)
118 {
119 if (c!=null)
120 setCursor(c.getType());
121 }
122
123 public void setResizable(boolean resizable)
124 {
125 System.out.println("java: setResizable() get called" + resizable);
126 if(!resizable)
127 this.resizable = 0;
128 }
129
130 public void setMenuBar(MenuBar mb)
131 {
132 recalculate();
133 }
134
135 public void setIconImage(Image im)
136 {
137 }
138
139 public Insets getInsets()
140 {
141 Insets i=new Insets(topInset,leftInset,bottomInset,rightInset);
142
143 MenuBar mb=target.getMenuBar();
144
145 if (mb!=null)
146 {
147 iMenuBarPeer peer=(iMenuBarPeer)mb.getPeer();
148
149 if (peer!=null)
150 {
151 i=(Insets)i.clone(); //Get new copy
152
153 i.top+=peer.getHeight();
154 }
155
156 }
157
158 return i;
159 }
160
161 public Insets insets()
162 {
163 return getInsets();
164 }
165
166 public void endValidate()
167 {
168
169 }
170
171 public void beginValidate()
172 {
173
174 }
175
176 public void setBounds(int x, int y, int width, int height) {
177 pReshape(x, y, width, height);
178 }
179
180 public void reshape(int x, int y, int width, int height) {
181 pReshape(x, y, width, height);
182 }
183
184
185 public void dispose()
186 {
187 pDispose();
188 pCanvas=null;
189 }
190
191 public void disable()
192 {
193 setEnabled(false);
194 }
195
196 public void enable()
197 {
198 setEnabled(false);
199 }
200
201 public void setEnabled(boolean b)
202 {
203
204 }
205
206 public void hide()
207 {
208 setVisible(false);
209 }
210
211 public void show()
212 {
213 setVisible(true);
214 }
215
216 public void setVisible(boolean b)
217 {
218 if (b)
219 pShow(this);
220 else
221 pHide();
222 }
223
224 public Dimension getMinimumSize() {
225 return target.getSize();
226 }
227
228 public Dimension getPreferredSize() {
229 return getMinimumSize();
230 }
231
232 public Dimension minimumSize() {
233 return getMinimumSize();
234 }
235
236 public Dimension preferredSize() {
237 return getPreferredSize();
238 }
239
240
241 public int checkImage(Image img, int w, int h, ImageObserver o) {
242 return 0;
243 }
244
245 public FontMetrics getFontMetrics(Font font) {
246 return iFontMetrics.getFontMetrics(font);
247 }
248
249 public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
250 return false;
251 }
252
253
254 public Image createImage(ImageProducer producer) {
255 return null/*new Win32Image(producer)*/;
256 }
257 public Image createImage(int width, int height) {
258 return null/*new Win32Image(target, width, height)*/;
259 }
260
261 public boolean isFocusTraversable() {
262 return false;
263 }
264
265 public void requestFocus()
266 {
267 }
268
269 public void nextFocus()
270 {
271 }
272
273 public void setFont(Font f)
274 {
275
276 }
277
278 public Font getFont()
279 {
280 return null;
281 }
282
283 public void setBackground(Color c)
284 {
285
286 }
287
288 public void setForeground(Color c)
289 {
290
291 }
292
293 public Graphics getGraphics()
294 {
295 if (pCanvas==null) {
296 System.out.println("iFramePeer.getGraphics(): pCanvas == null!"); // jfs - remove
297 return null;
298 }
299 Rectangle bounds = target.getBounds();
300 Rectangle clip = new Rectangle(bounds.x+leftInset,
301 bounds.y+topInset,
302 bounds.width-leftInset-rightInset,
303 bounds.height-topInset-bottomInset);
304 Graphics g=new iGraphics(getRefImage(),getRefOffScreenImage(), clip, target);
305 g.translate(bounds.x,bounds.y); // bounds have already been set - lg
306 return g;
307 }
308
309 public java.awt.Toolkit getToolkit() {
310 return Toolkit.getDefaultToolkit();
311 }
312
313 public ColorModel getColorModel() {
314 return iToolkit.getStaticColorModel();
315 }
316
317 public void handleEvent(AWTEvent e)
318 {
319
320 }
321
322 public void print(Graphics g)
323 {
324 }
325
326 public void paint(Graphics g)
327 {
328 g.setColor(target.getForeground());
329 g.setFont(target.getFont());
330 MenuBar mb=target.getMenuBar();
331 if (mb!=null)
332 {
333 iMenuBarPeer ip=(iMenuBarPeer)mb.getPeer();
334
335 if (ip!=null)
336 {
337 ip.paint(g);
338 }
339 }
340 target.paint(g);
341 }
342
343
344 public void repaint(long tm, int x, int y, int width, int height) {
345
346 iToolkit.postEvent(new PaintEvent((Component)target, PaintEvent.UPDATE,
347 new Rectangle(x, y, width, height)));
348
349 }
350
351 private void handleKeyEvents(int ch)
352 {
353 char keyChar = (char)ch;
354 boolean control = ch >= 0 && ch <= 31;
355 boolean lowercase = ch >= (int)'a' && ch <= (int)'z';
356 boolean uppercase = ch >= (int)'A' && ch <= (int)'Z';
357 int modifiers = control?InputEvent.CTRL_MASK:
358 uppercase?InputEvent.SHIFT_MASK:0;
359 int keyCode = control?ch+64:lowercase?ch-32:ch;
360
361 // constructing a Date is slow, System.currentTimeMillis(),
362 // is faster, but it's implementation opens #c/time and
363 // converts a string to a big. Fastest still and probably
364 // with sufficient resolution would be natively time stamping
365 // events with sys->millisec(). -jfs
366 //// Date d = new Date();
367 //// long when = d.getTime();
368 long when = System.currentTimeMillis();
369
370
371 iToolkit.postEvent(new KeyEvent(target,KeyEvent.KEY_PRESSED,
372 when,modifiers,keyCode,keyChar));
373
374 // synthesize events that we don't get from /dev/keyboard via
375 // Inferno's Tk (this is some fast typist!)
376 /*
377 iToolkit.postEvent(new KeyEvent(target,KeyEvent.KEY_TYPED,
378 when+1,modifiers,keyCode,keyChar));
379 iToolkit.postEvent(new KeyEvent(target,KeyEvent.KEY_RELEASED,
380 when+2,modifiers,keyCode,keyChar));
381 */
382 }
383
384 private void handleMouseEvents(int m,int button,int x,int y)
385 {
386 char mode=(char)m;
387 // System.out.println("Mouse event "+mode+" "+button+" "+x+" "+y);
388 switch(mode)
389 {
390case 'd':
391case 'r':
392case 'm':
393case 'p':
394 Rectangle bounds = target.getBounds();
395 int xx=x-bounds.x-leftInset;
396 int yy=y-bounds.y; // -topInset;
397
398 Point mousePoint=new Point(xx,yy);
399 long when = System.currentTimeMillis();
400 int modifier;
401
402 switch(button)
403 {
404case 1:
405 modifier=InputEvent.BUTTON1_MASK;
406 break;
407
408case 2:
409 modifier=InputEvent.BUTTON2_MASK;
410 break;
411
412case 3:
413 modifier=InputEvent.BUTTON3_MASK;
414 break;
415
416default:
417 modifier=0;
418 }
419
420 switch(mode)
421 {
422case 'p': // Pressed
423case 'd': // Double click
424 {
425 if (button>0 && button<=3 && buttonState[button-1]==false)
426 {
427 oldMousePoint=mousePoint;
428 buttonState[button-1]=true;
429 iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_PRESSED,
430 when,modifier,xx,yy,1,false));
431
432 }
433 break;
434 }
435case 'r': // Released
436 {
437 if (button>0 && button<=3 && buttonState[button-1]==true)
438 {
439 buttonState[button-1]=false;
440 iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_RELEASED,
441 when,modifier,xx,yy,1,false));
442 if (mousePoint.equals(oldMousePoint))
443 {
444 iToolkit.postEvent(new MouseEvent(target,MouseEvent.MOUSE_CLICKED,
445 when,modifier,xx,yy,1,button==2));
446 }
447 }
448 break;
449 }
450case 'm': // Moved
451 {
452 modifier=0;
453 if (buttonState[0]) modifier|=InputEvent.BUTTON1_MASK;
454 if (buttonState[1]) modifier|=InputEvent.BUTTON2_MASK;
455 if (buttonState[2]) modifier|=InputEvent.BUTTON3_MASK;
456 iToolkit.postEvent(new MouseEvent(target,
457 modifier==0?MouseEvent.MOUSE_MOVED:MouseEvent.MOUSE_DRAGGED,
458 when,modifier,xx,yy,1,false));
459
460 break;
461 }
462default:
463 // System.out.println("focusEvent:" + mouseString);
464 }
465 break;
466 }
467
468 // System.out.println("mouseString "+mouseString);
469 }
470
471 private void moveSize(int x, int y, int width, int height)
472 {
473 Rectangle old = target.getBounds();
474 Rectangle n = new Rectangle(x, y, width, height);
475 if (!n.equals(old)){
476 target.setBounds(x, y, width, height);
477 target.validate();
478 target.repaint();
479 }
480 }
481
482 private void paintTarget(int x, int y, int width, int height)
483 {
484 target.setBounds(x, y, width, height);
485 target.validate();
486 target.repaint();
487 }
488
489 //
490 // Callbacks from native for Window Events
491 //
492 private void handleActivated() {
493 iToolkit.postEvent(new WindowEvent(target,
494 WindowEvent.WINDOW_ACTIVATED));
495 iToolkit.postEvent(new FocusEvent(target,
496 FocusEvent.FOCUS_GAINED, false));
497 }
498 private void handleDeactivated() {
499 iToolkit.postEvent(new WindowEvent(target,
500 WindowEvent.WINDOW_DEACTIVATED));
501 iToolkit.postEvent(new FocusEvent(target,
502 FocusEvent.FOCUS_LOST, true));
503 }
504 private void handleClosing() {
505 //System.out.println("iFramePeer.handleClosing():");
506 // Java Frame can then call System.exit() to shutdown the VM
507 // if it so desires
508 iToolkit.postEvent(new WindowEvent(target,
509 WindowEvent.WINDOW_CLOSING));
510 }
511 private void handleIconified() {
512 //System.out.println("iFramePeer.handleIconified():");
513 iToolkit.postEvent(new WindowEvent(target,
514 WindowEvent.WINDOW_ICONIFIED));
515
516 }
517 private void handleDeIconified() {
518 // System.out.println("iFramePeer.handleDeiconified():");
519 iToolkit.postEvent(new WindowEvent(target,
520 WindowEvent.WINDOW_DEICONIFIED));
521
522 // may need to make Cursors visible as well??? - jfs
523 // target.repaint();
524 }
525}
526
527