View Javadoc

1   package com.tapina.robe.swi.wimp;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   import java.util.Iterator;
6   import java.awt.*;
7   
8   /***
9    * This class represents a created window.
10   */
11  public class Window {
12      private static final int SEQUENCE_BASE = 100;
13      private static final int INITIAL_CAPACITY = 20;
14      private static int windowHandleSeq = SEQUENCE_BASE;
15      private static Map windows = new HashMap(INITIAL_CAPACITY);
16  
17      private final int windowHandle;
18      private final WindowBlock windowBlock;
19  
20      public static Window find(int handle) {
21          return (Window) windows.get(new Integer(handle));
22      }
23  
24      public Window(WindowBlock windowBlock) {
25          this.windowBlock = windowBlock;
26          synchronized (Window.class) {
27              windowHandle = windowHandleSeq++;
28          }
29          windows.put(new Integer(windowHandle), this);
30      }
31  
32      public int getWindowHandle() {
33          return windowHandle;
34      }
35  
36  
37      /***
38       * Remove the given icon from the window and its definition from WindowBlock.
39       * If it is not the last icon in the windows list it is only marked as deleted.
40       * @todo Remove the icon from the Java window too when we start creating them
41       * @param iconHandle handle of icon to remove, from 0
42       */
43      public void deleteIcon(int iconHandle) {
44          if (iconHandle < windowBlock.getNumberOfIcons() - 1) {
45              // Mark it as deleted instead of removing it
46              Icon icon = windowBlock.getIcon(iconHandle);
47              icon.setIconFlags(icon.getIconFlags() | Icon.DELETED);
48          } else {
49              windowBlock.removeIcon(iconHandle);
50          }
51      }
52  
53      public Icon getIcon(int iconHandle) {
54          return windowBlock.getIcon(iconHandle);
55      }
56  
57      public Rectangle getVisibleArea() {
58          return windowBlock.getVisibleArea();
59      }
60  
61      public Point getScrollOffset() {
62          return windowBlock.getScrollOffset();
63      }
64  
65      public int getHandleOfWindowAbove() {
66          return windowBlock.getHandleOfWindowAbove();
67      }
68  
69      public int getWindowFlags() {
70          return windowBlock.getWindowFlags();
71      }
72  
73      public Iterator icons() {
74          return windowBlock.icons();
75      }
76  
77      /***
78       * @todo Change the window component too
79       */
80      public void setExtent(Rectangle workArea) {
81          windowBlock.setWorkArea(workArea);
82      }
83  }