< prev index next >

src/java.desktop/unix/classes/sun/awt/X11/InfoWindow.java

Print this page




  54             }
  55         };
  56         setLayout(new BorderLayout());
  57         setBackground(borderColor);
  58         add(container, BorderLayout.CENTER);
  59         container.setLayout(new BorderLayout());
  60 
  61         closer = new Closer();
  62     }
  63 
  64     public Component add(Component c) {
  65         container.add(c, BorderLayout.CENTER);
  66         return c;
  67     }
  68 
  69     protected void setCloser(Runnable action, int time) {
  70         closer.set(action, time);
  71     }
  72 
  73     // Must be executed on EDT.

  74     protected void show(Point corner, int indent) {
  75         assert SunToolkit.isDispatchThreadForAppContext(this);
  76 
  77         pack();
  78 
  79         Dimension size = getSize();
  80         // TODO: When 6356322 is fixed we should get screen bounds in
  81         // this way: eframe.getGraphicsConfiguration().getBounds().
  82         Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
  83 
  84         if (corner.x < scrSize.width/2 && corner.y < scrSize.height/2) { // 1st square
  85             setLocation(corner.x + indent, corner.y + indent);
  86 
  87         } else if (corner.x >= scrSize.width/2 && corner.y < scrSize.height/2) { // 2nd square
  88             setLocation(corner.x - indent - size.width, corner.y + indent);
  89 
  90         } else if (corner.x < scrSize.width/2 && corner.y >= scrSize.height/2) { // 3rd square
  91             setLocation(corner.x + indent, corner.y - indent - size.height);
  92 
  93         } else if (corner.x >= scrSize.width/2 && corner.y >= scrSize.height/2) { // 4th square
  94             setLocation(corner.x - indent - size.width, corner.y - indent - size.height);
  95         }
  96 
  97         super.show();
  98         closer.schedule();
  99     }
 100 

 101     public void hide() {
 102         closer.close();
 103     }
 104 
 105     private class Closer implements Runnable {
 106         Runnable action;
 107         int time;
 108 
 109         public void run() {
 110             doClose();
 111         }
 112 
 113         void set(Runnable action, int time) {
 114             this.action = action;
 115             this.time = time;
 116         }
 117 
 118         void schedule() {
 119             XToolkit.schedule(this, time);
 120         }
 121 
 122         void close() {
 123             XToolkit.remove(this);
 124             doClose();
 125         }
 126 
 127         // WARNING: this method may be executed on Toolkit thread.

 128         private void doClose() {
 129             SunToolkit.executeOnEventHandlerThread(InfoWindow.this, new Runnable() {
 130                 public void run() {
 131                     InfoWindow.super.hide();
 132                     invalidate();
 133                     if (action != null) {
 134                         action.run();
 135                     }
 136                 }
 137             });
 138         }
 139     }
 140 
 141 
 142     private interface LiveArguments {
 143         /** Whether the target of the InfoWindow is disposed. */
 144         boolean isDisposed();
 145 
 146         /** The bounds of the target of the InfoWindow. */
 147         Rectangle getBounds();




  54             }
  55         };
  56         setLayout(new BorderLayout());
  57         setBackground(borderColor);
  58         add(container, BorderLayout.CENTER);
  59         container.setLayout(new BorderLayout());
  60 
  61         closer = new Closer();
  62     }
  63 
  64     public Component add(Component c) {
  65         container.add(c, BorderLayout.CENTER);
  66         return c;
  67     }
  68 
  69     protected void setCloser(Runnable action, int time) {
  70         closer.set(action, time);
  71     }
  72 
  73     // Must be executed on EDT.
  74     @SuppressWarnings("deprecation")
  75     protected void show(Point corner, int indent) {
  76         assert SunToolkit.isDispatchThreadForAppContext(this);
  77 
  78         pack();
  79 
  80         Dimension size = getSize();
  81         // TODO: When 6356322 is fixed we should get screen bounds in
  82         // this way: eframe.getGraphicsConfiguration().getBounds().
  83         Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
  84 
  85         if (corner.x < scrSize.width/2 && corner.y < scrSize.height/2) { // 1st square
  86             setLocation(corner.x + indent, corner.y + indent);
  87 
  88         } else if (corner.x >= scrSize.width/2 && corner.y < scrSize.height/2) { // 2nd square
  89             setLocation(corner.x - indent - size.width, corner.y + indent);
  90 
  91         } else if (corner.x < scrSize.width/2 && corner.y >= scrSize.height/2) { // 3rd square
  92             setLocation(corner.x + indent, corner.y - indent - size.height);
  93 
  94         } else if (corner.x >= scrSize.width/2 && corner.y >= scrSize.height/2) { // 4th square
  95             setLocation(corner.x - indent - size.width, corner.y - indent - size.height);
  96         }
  97 
  98         super.show();
  99         closer.schedule();
 100     }
 101 
 102     @SuppressWarnings("deprecation")
 103     public void hide() {
 104         closer.close();
 105     }
 106 
 107     private class Closer implements Runnable {
 108         Runnable action;
 109         int time;
 110 
 111         public void run() {
 112             doClose();
 113         }
 114 
 115         void set(Runnable action, int time) {
 116             this.action = action;
 117             this.time = time;
 118         }
 119 
 120         void schedule() {
 121             XToolkit.schedule(this, time);
 122         }
 123 
 124         void close() {
 125             XToolkit.remove(this);
 126             doClose();
 127         }
 128 
 129         // WARNING: this method may be executed on Toolkit thread.
 130         @SuppressWarnings("deprecation")
 131         private void doClose() {
 132             SunToolkit.executeOnEventHandlerThread(InfoWindow.this, new Runnable() {
 133                 public void run() {
 134                     InfoWindow.super.hide();
 135                     invalidate();
 136                     if (action != null) {
 137                         action.run();
 138                     }
 139                 }
 140             });
 141         }
 142     }
 143 
 144 
 145     private interface LiveArguments {
 146         /** Whether the target of the InfoWindow is disposed. */
 147         boolean isDisposed();
 148 
 149         /** The bounds of the target of the InfoWindow. */
 150         Rectangle getBounds();


< prev index next >