    001package org.vishia.gral.awt;
    002
    003import java.awt.Frame;
    004import java.awt.Rectangle;
    005import java.awt.event.ComponentEvent;
    006import java.awt.event.ComponentListener;
    007import java.awt.event.HierarchyBoundsListener;
    008import java.awt.event.HierarchyEvent;
    009import java.awt.event.MouseEvent;
    010import java.awt.event.MouseListener;
    011import java.awt.event.MouseMotionListener;
    012import java.awt.event.WindowAdapter;
    013import java.awt.event.WindowEvent;
    014import java.awt.event.WindowFocusListener;
    015import java.awt.event.WindowListener;
    016import java.awt.event.WindowStateListener;
    017
    018import org.eclipse.swt.graphics.Point;
    019import org.vishia.gral.base.GralMng;
    020import org.vishia.gral.base.GralWidgImpl_ifc;
    021import org.vishia.gral.base.GralWindow;
    022import org.vishia.gral.ifc.GralRectangle;
    023import org.vishia.util.Debugutil;
    024
    025
    026public class AwtSubWindow extends GralWindow.GraphicImplAccess implements GralWidgImpl_ifc
    027{
    028
    029  protected final Frame window;
    030
    031  private final boolean isMainWindow;
    032
    033  public AwtSubWindow(GralWindow wdgGral)
    034  { super(wdgGral);
    035    int windProps = super.getWindowProps();
    036    window = new Frame(getTitle());
    037    int xPos = 100; int yPos = 50; int xSize = 640; int ySize = 480;
    038    window.setBounds(xPos, yPos, xSize, ySize);
    039    window.setVisible(true);
    040    window.setLayout(null);
    041    if((windProps & GralWindow.windIsMain)!=0) {
    042      this.isMainWindow = true;
    043      //window.addKeyListener(AwtWidgetMng.mainKeyListener);
    044    } else {
    045      this.isMainWindow = false;
    046    }
    047    window.addComponentListener(componentListener);
    048    window.addHierarchyBoundsListener(hierarchyBoundsListener);
    049    //window.addContainerListener(containerListener);
    050    //window.addMouseMotionListener(mousMotionListener);
    051    //window.addMouseListener(mouseListener);
    052    window.addWindowListener(new GralAwtWindowAdapter());
    053    //window.addWindowListener(windowClosingAdapter);
    054    //window.addWindowListener(windowListener);
    055    //window.add
    056
    057  }
    058
    059
    060  @Override
    061  public GralRectangle getPixelPositionSize()
    062  {
    063    Rectangle r = window.getBounds();
    064    Debugutil.stop();
    065    return new GralRectangle(r.x, r.y, r.width, r.height);
    066  }
    067
    068  @Override public GralRectangle getPixelSize(){
    069    int dx = window.getWidth();
    070    int dy = window.getHeight();
    071    return new GralRectangle(0,0,dx, dy);
    072  }
    073
    074
    075
    076
    077
    078
    079
    080  @Override
    081  public void setBoundsPixel(int x, int y, int dx, int dy)
    082  { window.setBounds(x,y,dx,dy);
    083  }
    084
    085
    086
    087  @Override
    088  public boolean setFocusGThread()
    089  {
    090    Debugutil.stop();
    091    return false;
    092  }
    093
    094
    095  /**Sets the implementation widget vible or not.
    096   * @see org.vishia.gral.base.GralWidgImpl_ifc#setVisibleGThread(boolean)
    097   */
    098  @Override public void setVisibleGThread(boolean bVisible){ super.setVisibleState(bVisible); window.setVisible(bVisible); }
    099
    100
    101  @Override
    102  public void removeWidgetImplementation()
    103  {
    104    Debugutil.stop();
    105
    106  }
    107
    108
    109  @Override
    110  public void repaintGthread() {
    111    Debugutil.stop();
    112
    113  }
    114
    115
    116  @Override public Object getWidgetImplementation()
    117  {
    118    Debugutil.stop();
    119    return window;
    120  }
    121
    122
    123
    124
    125  WindowListener windowListener = new WindowListener()
    126  {
    127
    128    @Override public void windowOpened(WindowEvent e)
    129    {
    130      Debugutil.stop();
    131
    132    }
    133
    134    @Override public void windowClosing(WindowEvent e)
    135    {
    136      Debugutil.stop();
    137
    138    }
    139
    140    @Override public void windowClosed(WindowEvent e)
    141    {
    142      Debugutil.stop();
    143
    144    }
    145
    146    @Override public void windowIconified(WindowEvent e)
    147    {
    148      Debugutil.stop();
    149
    150    }
    151
    152    @Override public void windowDeiconified(WindowEvent e)
    153    {
    154      Debugutil.stop();
    155
    156    }
    157
    158    @Override public void windowActivated(WindowEvent e)
    159    {
    160      Debugutil.stop();
    161
    162    }
    163
    164    @Override public void windowDeactivated(WindowEvent e)
    165    {
    166      Debugutil.stop();
    167
    168    }
    169  };
    170
    171
    172
    173  @SuppressWarnings("synthetic-access")
    174  WindowListener windowClosingAdapter = new WindowAdapter()
    175  {
    176
    177    public void windowClosing(WindowEvent event)
    178    {
    179      event.getWindow().setVisible(false);
    180      event.getWindow().dispose();
    181      if (isMainWindow)
    182      {
    183        System.exit(0);
    184      }
    185    }
    186  };
    187
    188
    189
    190  public class GralAwtWindowAdapter
    191  implements WindowListener, WindowStateListener, WindowFocusListener
    192  {
    193
    194    @Override public void windowGainedFocus(WindowEvent e)
    195    {
    196      Debugutil.stop();
    197
    198    }
    199
    200    @Override public void windowLostFocus(WindowEvent e)
    201    {
    202      Debugutil.stop();
    203
    204    }
    205
    206    @Override public void windowStateChanged(WindowEvent e)
    207    {
    208      Debugutil.stop();
    209      System.out.println("state changed");
    210
    211    }
    212
    213    @Override public void windowOpened(WindowEvent e)
    214    {
    215      Debugutil.stop();
    216
    217    }
    218
    219    @Override public void windowClosing(WindowEvent event)
    220    {
    221      event.getWindow().setVisible(false);
    222      event.getWindow().dispose();
    223      if (isMainWindow)
    224      {
    225        System.exit(0);
    226      }
    227    }
    228
    229    @Override public void windowClosed(WindowEvent e)
    230    {
    231      Debugutil.stop();
    232
    233    }
    234
    235    @Override public void windowIconified(WindowEvent e)
    236    {
    237      Debugutil.stop();
    238
    239    }
    240
    241    @Override public void windowDeiconified(WindowEvent e)
    242    {
    243      Debugutil.stop();
    244
    245    }
    246
    247    @Override public void windowActivated(WindowEvent e)
    248    {
    249      Debugutil.stop();
    250      System.out.println("AwtWindow: activated");
    251
    252    }
    253
    254    @Override public void windowDeactivated(WindowEvent e)
    255    {
    256      Debugutil.stop();
    257
    258    }
    259
    260  }
    261
    262
    263  MouseMotionListener mousMotionListener = new MouseMotionListener()
    264  {
    265
    266    @Override public void mouseDragged(MouseEvent e)
    267    {
    268      Debugutil.stop();
    269      System.out.println("AwtWindow: mouseDragged");
    270
    271    }
    272
    273    @Override public void mouseMoved(MouseEvent e)
    274    {
    275      Debugutil.stop();
    276      //System.out.println("AwtWindow: mouseMoved");
    277
    278    }
    279
    280  };
    281
    282
    283  MouseListener mouseListener = new MouseListener()
    284  {
    285
    286    @Override public void mouseClicked(MouseEvent e)
    287    {
    288      System.out.println("AwtWindow: mouseclicked");
    289
    290    }
    291
    292    @Override public void mousePressed(MouseEvent e)
    293    {
    294      System.out.println("AwtWindow: mousePressed");
    295
    296    }
    297
    298    @Override public void mouseReleased(MouseEvent e)
    299    {
    300      System.out.println("AwtWindow: mouseReleased");
    301
    302    }
    303
    304    @Override public void mouseEntered(MouseEvent e)
    305    {
    306      System.out.println("AwtWindow: mouseEntered");
    307
    308    }
    309
    310    @Override public void mouseExited(MouseEvent e)
    311    {
    312      System.out.println("AwtWindow: mouseExited");
    313
    314    }
    315
    316
    317  };
    318
    319
    320  //ContainerListener containerListener;
    321
    322
    323  HierarchyBoundsListener hierarchyBoundsListener = new HierarchyBoundsListener()
    324  {
    325
    326    @Override public void ancestorMoved(HierarchyEvent e)
    327    {
    328      System.out.println("AwtWindow: hierarchy-anchestorMoved");
    329
    330    }
    331
    332    @Override public void ancestorResized(HierarchyEvent e)
    333    {
    334      System.out.println("AwtWindow: hierarchy-anchestorResized");
    335
    336    }
    337
    338  };
    339
    340
    341  /**The componentListener is the resize listener especially.
    342   *
    343   */
    344  @SuppressWarnings("synthetic-access")
    345  ComponentListener componentListener = new ComponentListener()
    346  {
    347
    348    @Override public void componentShown(ComponentEvent e)
    349    {
    350      System.out.println("AwtWindow: component shown");
    351
    352    }
    353
    354
    355
    356    @Override public void componentResized(ComponentEvent e)
    357    {
    358      System.out.println("AwtWindow: component resized");
    359      { if(resizeAction() !=null){
    360          resizeAction().exec(0, AwtSubWindow.super.gralWindow);
    361        }
    362      }
    363
    364    }
    365
    366
    367
    368    @Override public void componentMoved(ComponentEvent e)
    369    {
    370      System.out.println("AwtWindow: component moved");
    371
    372    }
    373
    374
    375
    376    @Override public void componentHidden(ComponentEvent e)
    377    {
    378      System.out.println("AwtWindow: component hidden");
    379
    380    }
    381  };
    382
    383
    384}