001package org.vishia.gral.awt;
002
003import java.awt.Component;
004import java.awt.Composite;
005import java.awt.Container;
006import java.awt.Dimension;
007import java.awt.Font;
008import java.awt.Color;
009import java.awt.Frame;
010import java.awt.Label;
011import java.awt.Menu;
012import java.awt.MenuBar;
013import java.awt.Point;
014import java.awt.PopupMenu;
015import java.awt.Rectangle;
016import java.awt.TextArea;
017import java.awt.TextField;
018import java.awt.Window;
019import java.awt.event.FocusEvent;
020import java.awt.event.FocusListener;
021import java.awt.event.KeyEvent;
022import java.awt.event.KeyListener;
023import java.io.InputStream;
024
025import org.vishia.byteData.VariableContainer_ifc;
026import org.vishia.gral.base.GralButton;
027import org.vishia.gral.base.GralCurveView;
028import org.vishia.gral.base.GralGraphicTimeOrder;
029import org.vishia.gral.base.GralGraphicThread;
030import org.vishia.gral.base.GralHtmlBox;
031import org.vishia.gral.base.GralLed;
032import org.vishia.gral.base.GralMenu;
033import org.vishia.gral.base.GralMenu._GraphicImpl;
034import org.vishia.gral.base.GralPanelActivated_ifc;
035import org.vishia.gral.base.GralPanelContent;
036import org.vishia.gral.base.GralPos;
037import org.vishia.gral.base.GralTabbedPanel;
038import org.vishia.gral.base.GralTable;
039import org.vishia.gral.base.GralTextBox;
040import org.vishia.gral.base.GralTextField;
041import org.vishia.gral.base.GralWidget;
042import org.vishia.gral.base.GralMng;
043import org.vishia.gral.base.GralWindow;
044import org.vishia.gral.ifc.GralColor;
045import org.vishia.gral.ifc.GralFileDialog_ifc;
046import org.vishia.gral.ifc.GralRectangle;
047import org.vishia.gral.ifc.GralUserAction;
048import org.vishia.gral.ifc.GralWindow_ifc;
049import org.vishia.gral.widget.GralHorizontalSelector;
050import org.vishia.gral.widget.GralLabel;
051import org.vishia.msgDispatch.LogMessage;
052
053public class AwtWidgetMng extends GralMng.ImplAccess // implements GralMngBuild_ifc, GralMng_ifc
054{
055  
056  final AwtProperties propertiesGuiAwt; 
057  
058  //final Frame mainWindowAwt;
059  
060  
061  /**The standard listener or action for mouse events, able to assign to all widgets which does not need an extra mouse behaviour. */
062  final AwtGralMouseListener.MouseListenerGralAction mouseStdAction = new AwtGralMouseListener.MouseListenerGralAction(null);
063  
064  /**Creates an instance.
065   * @param guiContainer The container where the elements are stored in.
066   * @param width in display-units for the window's width, the number of pixel depends from param displaySize.
067   * @param height in display-units for the window's height, the number of pixel depends from param displaySize.
068   * @param displaySize character 'A' to 'E' to determine the size of the content 
069   *        (font size, pixel per cell). 'A' is the smallest, 'E' the largest size. Default: use 'C'.
070   */
071  public AwtWidgetMng(AwtProperties propertiesGui
072    //, VariableContainer_ifc variableContainer
073    , LogMessage log
074    )
075  { super(GralMng.get(), propertiesGui);
076    //mainWindowAwt = window;
077    this.propertiesGuiAwt = propertiesGui;
078    //mainWindowAwt.addKeyListener(mainKeyListener);
079  }
080
081  
082  
083  @Override public Container getCurrentPanel(){ return (Container)pos().panel.getWidgetImplementation(); }
084
085  
086  public Container getWidgetsPanel(GralWidget widg){ 
087    GralPos pos = widg.pos();
088    if(pos == null) { pos = pos(); } //from GralMng
089    return ((Container)pos.panel.getWidgetImplementation()); 
090  }
091
092
093
094  @Override public void createImplWidget_Gthread(GralWidget widgg){
095    if(widgg instanceof GralLabel){
096      new AwtLabel((GralLabel)widgg, this);
097    } else if(widgg instanceof GralTextField){
098      new AwtTextField((GralTextField)widgg, this);
099    } else if(widgg instanceof GralHorizontalSelector<?>){
100      //SwtHorizontalSelector swtSel = new SwtHorizontalSelector(this, (GralHorizontalSelector<?>)widgg);
101      mng.registerWidget(widgg);
102    } else if(widgg instanceof GralTable<?>){
103      //AwtTable.addTable((GralTable<?>)widgg, this);
104    } else if(widgg instanceof GralButton){
105      new AwtButton((GralButton)widgg, this);
106    }
107  }
108  
109
110  
111  
112  /** Adds a text field for showing or editing a text value.
113   * 
114   * @param sName The registering name
115   * @param width Number of grid units for length
116   * @param editable true than edit-able, false to show content 
117   * @param prompt If not null, than a description label is shown
118   * @param promptStylePosition Position and size of description label:
119   *   upper case letter: normal font, lower case letter: small font
120   *   'l' left, 't' top (above field) 
121   * @return
122  //@Override 
123  public GralTextField addTextField(String name, boolean editable, String prompt, String promptStylePosition)
124  { Container parent = getCurrentPanel();
125    AwtTextField widg = new AwtTextField(name, editable ? 'T' : 'S', this, parent);
126    widg.setPanelMng(mng);
127    widg.widgetAwt.setFont(propertiesGuiAwt.stdInputFont);
128    widg.widgetAwt.setEditable(editable);
129    widg.widgetAwt.setBackground(propertiesGuiAwt.colorAwt(GralColor.getColor("wh")));
130    //widg.widgetAwt.addFocusListener(focusListener);
131
132    //widg.widgetAwt.addMouseListener(mouseClickForInfo);
133    int x =-1, y=-1; 
134    if(x >=0 && y >=0){
135      //edit.setBounds(x, y, dx * properties.xPixelUnit(), 2* properties.yPixelUnit());
136    } else {
137      //widget.setSize(xIncr * propertiesGui.xPixelUnit()-1, 2* propertiesGui.yPixelUnit()-1);
138    }
139    //
140    if(prompt != null && promptStylePosition.startsWith("t")){
141      mng.setNextPosition();
142      final Font promptFont;
143      char sizeFontPrompt;
144      GralRectangle boundsAll, boundsPrompt, boundsField;
145      final GralPos posPrompt = new GralPos(), posField = new GralPos();
146      boundsAll = mng.calcWidgetPosAndSize(this.pos(), 800, 600, 100, 20);
147      float ySize = pos().height();
148      //float xSize = pos.width();
149          posPrompt.setPosition(this.pos(), GralPos.same, ySize * 0.37f + GralPos.size, GralPos.same, GralPos.same, 0, '.');
150          posField.setPosition(this.pos(), GralPos.refer + ySize * 0.37f, GralPos.same, GralPos.same, GralPos.same, 0, '.');
151      promptFont = propertiesGuiAwt.smallPromptFont;
152      boundsPrompt = mng.calcWidgetPosAndSize(posPrompt, boundsAll.dx, boundsAll.dy, 10,100);
153      boundsField = mng.calcWidgetPosAndSize(posField, boundsAll.dx, boundsAll.dy, 10,100);
154      Label wgPrompt = new Label();
155      parent.add(wgPrompt);
156      wgPrompt.setFont(promptFont);
157      wgPrompt.setText(prompt);
158      /*TODO
159      Point promptSize = wgPrompt.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
160      if(promptSize.x > boundsPrompt.dx){
161        boundsPrompt.dx = promptSize.x;  //use the longer value, if the prompt text is longer as the field.
162      }
163      wgPrompt.setBounds(boundsPrompt.x, boundsPrompt.y, boundsPrompt.dx, boundsPrompt.dy+1);
164      widgetSwt.setBounds(boundsField.x, boundsField.y, boundsField.dx, boundsField.dy);
165      posUsed = true;
166      *//*
167    } else {
168      //without prompt
169      setPosAndSize_(widg.widgetAwt);
170    }
171    //
172    if(widg.name !=null && widg.name.charAt(0) == '$'){
173      widg.name = sCurrPanel() + widg.name.substring(1);
174    }
175    //link the widget with is information together.
176    widg.widgetAwt.setData(widg);
177    if(widg.name !=null){
178      if(!editable){
179        mng.registerShowField(widg);
180      }
181    }
182    mng.registerWidget(widg);
183    return widg; 
184  
185  }
186  */
187  
188  
189
190  
191  /** Adds a text box for showing or editing a text in multi lines.
192   * 
193   * @param sName The registering name
194   * @param width Number of grid units for length
195   * @param editable true than edit-able, false to show content 
196   * @param prompt If not null, than a description label is shown
197   * @param promptStylePosition Position and size of description label:
198   *   upper case letter: normal font, lower case letter: small font
199   *   'l' left, 't' top (above field) 
200   * @return
201  //@Override 
202  public GralTextBox addTextBox(String name, boolean editable, String prompt, char promptStylePosition)
203  { Container parent = (Container)pos().panel.getWidgetImplementation();
204    AwtTextBox widgetSwt = new AwtTextBox(name, parent, 0, this);
205    GralWidget widgetInfo = widgetSwt;
206    widgetInfo.setPanelMng(mng);
207    //Text widgetSwt = new Text(((PanelSwt)pos.panel).getPanelImpl(), SWT.MULTI);
208    widgetSwt.textFieldSwt.setFont(propertiesGuiAwt.stdInputFont);
209    widgetSwt.textFieldSwt.setEditable(editable);
210    if(editable)
211      stop();
212    widgetSwt.textFieldSwt.setBackground(propertiesGuiAwt.colorAwt(GralColor.getColor("pbl")));
213    //widgetSwt.textFieldSwt.addMouseListener(mouseClickForInfo);
214    setPosAndSize_(widgetSwt.textFieldSwt);
215    if(prompt != null && promptStylePosition == 't'){
216      final int yPixelField;
217      final Font promptFont;
218      int ySize = (int)(pos().height());
219      switch(ySize){
220      case 3:  promptFont = propertiesGuiAwt.smallPromptFont;
221               yPixelField = propertiesGuiAwt.yPixelUnit() * 2 -3;
222               break;
223      case 2:  promptFont = propertiesGuiAwt.smallPromptFont;
224               yPixelField = (int)(1.5F * mng.propertiesGui.yPixelUnit());
225               break;
226      default: promptFont = propertiesGuiAwt.smallPromptFont;
227               yPixelField = mng.propertiesGui.yPixelUnit() * 2 -3;
228      }//switch
229      Rectangle boundsField = widgetSwt.textFieldSwt.getBounds();
230      Rectangle boundsPrompt = new Rectangle(boundsField.x, boundsField.y-3  //occupy part of field above, only above the normal letters
231        , boundsField.width, boundsField.height );
232      
233      if(promptStylePosition == 't'){ 
234        boundsPrompt.height -= (yPixelField -4);
235        boundsPrompt.y -= 1;
236        
237        boundsField.y += (boundsField.height - yPixelField );
238        boundsField.height = yPixelField;
239      }
240      Label wgPrompt = new Label();
241      parent.add(wgPrompt);
242      wgPrompt.setFont(promptFont);
243      wgPrompt.setText(prompt);
244      widgetSwt.textFieldSwt.setBounds(boundsField);
245      wgPrompt.setBounds(boundsPrompt);
246    } 
247    //
248    if(widgetInfo.name !=null && widgetInfo.name.charAt(0) == '$'){
249      widgetInfo.name = sCurrPanel() + widgetInfo.name.substring(1);
250    }
251    //link the widget with is information together.
252    widgetSwt.textFieldSwt.setData(widgetInfo);
253    if(widgetInfo.name !=null){
254      if(!editable){
255        mng.registerShowField(widgetInfo);
256      }
257    }
258    mng.registerWidget(widgetInfo);
259    return widgetSwt; 
260
261  }
262  */
263    
264
265  @Override public GralHtmlBox addHtmlBox(String name){
266    return null;
267  }
268  
269  
270  @Override public GralCurveView addCurveViewY(String sName, int nrofXvalues, GralCurveView.CommonCurve common)
271  {
272    // TODO Auto-generated method stub
273    return null;
274  }
275
276  @Override
277  public GralWidget addFocusAction(String sName, GralUserAction action, String sCmdEnter,
278    String sCmdRelease)
279  {
280    // TODO Auto-generated method stub
281    return null;
282  }
283
284  @Override
285  public void addFocusAction(GralWidget widgetInfo, GralUserAction action, String sCmdEnter,
286    String sCmdRelease)
287  {
288    // TODO Auto-generated method stub
289    
290  }
291
292  @Override
293  public Object addImage(String sName, InputStream imageStream, int height, int width, String sCmd)
294  {
295    // TODO Auto-generated method stub
296    return null;
297  }
298
299  @Override
300  public GralWidget addSlider(String sName, GralUserAction action, String sShowMethod,
301    String sDataPath)
302  {
303    // TODO Auto-generated method stub
304    return null;
305  }
306
307  @Override
308  public GralTable addTable(String sName, int height, int[] columnWidths)
309  {
310    // TODO Auto-generated method stub
311    return null;
312  }
313  
314  public void add(GralTable<?> table){}
315
316
317  @Override @Deprecated
318  public GralWidget addText(String sText, char size, int color)
319  {
320    // TODO Auto-generated method stub
321    return null;
322  }
323
324  
325  
326
327  
328  @Override protected GralMenu XXXaddPopupMenu(String sName){
329    //Control panelSwt = (Control)pos.panel.getPanelImpl();
330    //SwtMenu menu = new SwtMenu(sName, panelSwt, this);
331    return null; //menu;
332  }
333
334  
335  @Override protected GralMenu createContextMenu(GralWidget widg){
336    Component widgSwt = (Component)widg._wdgImpl.getWidgetImplementation();
337    GralMenu menu = new GralMenu(); new AwtMenu(widg, widgSwt, mng);  //TODO
338    PopupMenu menuAwt = (PopupMenu)menu.getMenuImpl();
339    widgSwt.add(menuAwt);
340    menuAwt.show(widgSwt, 10, 10);
341    return menu;
342  }
343 
344  
345  
346  @Override protected GralMenu createMenuBar(GralWindow windg){
347    Frame windowAwt = (Frame)windg.getWidgetImplementation();
348    GralMenu menu = new GralMenu(); new AwtMenu(windg, windowAwt, mng);  //TODO
349    return menu;
350  }
351 
352  
353  
354
355
356  
357  
358  @Override public GralPanelContent createCompositeBox(String name)
359  {
360      //Composite box = new Composite(graphicFrame, 0);
361      Container box = new Container();
362      Container parent = (Container)pos().panel.getWidgetImplementation();
363      
364      parent.add(box);
365      setPosAndSize_(mng.getPosOldPositioning(), box);
366      Dimension size = box.getSize();
367      GralPanelContent panel = new AwtPanel(name, mng, box);
368      //mng.registerPanel(panel);
369      return panel;
370  }
371
372  @Override
373  public GralFileDialog_ifc createFileDialog()
374  {
375    // TODO Auto-generated method stub
376    return null;
377  }
378
379  @Override
380  public GralPanelContent createGridPanel(String namePanel, GralColor backGround, int xG, int yG,
381    int xS, int yS)
382  {
383    // TODO Auto-generated method stub
384    return null;
385  }
386
387  @Override
388  public GralTabbedPanel addTabbedPanel(String namePanel, GralPanelActivated_ifc user,
389    int properties)
390  {
391    // TODO Auto-generated method stub
392    return null;
393  }
394
395  @Override
396  public GralWindow createWindow(String name, String title, int windPros)
397  {
398    // TODO Auto-generated method stub
399    return null;
400  }
401
402  
403  @Override public void createSubWindow(GralWindow windowGral){
404    AwtSubWindow windowSwt = new AwtSubWindow(windowGral);
405    //new SwtSubWindow(name, swtDevice.displaySwt, title, windProps, this);
406    GralRectangle rect = calcPositionOfWindow(windowGral.pos());
407    windowSwt.window.setBounds(rect.x, rect.y, rect.dx, rect.dy );
408    //window.window.redraw();
409    //window.window.update();
410    windowGral._wdgImpl = windowSwt;
411
412  }
413  
414  /**Calculates the position as absolute value on screen from a given position inside a panel.
415   * @param posWindow contains any {@link GralPos#panel}. Its absolute position will be determined.
416   *   from that position and size the absolute postion will be calculate, with this given grid positions
417   *   inside the panel. 
418   * @return Absolute pixel coordinate.
419   */
420  GralRectangle calcPositionOfWindow(GralPos posWindow)
421  {
422    final GralRectangle windowFrame;
423    if(posWindow.panel !=null) {
424      Object awtWidg = posWindow.panel.getWidgetImplementation();
425      Window parentFrame = (Frame)awtWidg; //((SwtPanel)(swtWidg)).panelComposite; //(Control)posWindow.panel.getPanelImpl();
426      Point loc;
427      windowFrame = getPixelUseableAreaOfWindow(posWindow.panel);
428    } else {
429      windowFrame = new GralRectangle(0,0,800,600);
430    }
431    int dxFrame = 400, dyFrame = 300;  //need if posWindow has coordinates from right or in percent
432    Rectangle rectParent = null;
433    /*
434    if(parentFrame == window){
435      dxFrame = windowFrame.dx; dyFrame = windowFrame.dy;
436    } else {
437      rectParent = parentFrame.getBounds();
438      dxFrame = rectParent.width; dyFrame = rectParent.height;
439    }
440    */
441    final GralRectangle rectangle = mng.calcWidgetPosAndSize(posWindow, dxFrame, dyFrame, 400, 300);
442    rectangle.x += windowFrame.x;
443    rectangle.y += windowFrame.y;
444    /*
445    //
446    while ( parentFrame != window){ //The Shell is the last parentFrame
447      //the bounds are relative to its container. Get all parent container and add all positions
448      //until the shell is reached.
449      rectParent = parentFrame.getBounds();
450      rectangle.x += rectParent.x;
451      rectangle.y += rectParent.y;
452      parentFrame = parentFrame.getParent();
453    }
454    */
455    return rectangle;
456  }
457  
458
459  
460  GralRectangle getPixelUseableAreaOfWindow(GralWidget widgg)
461  { Object oControl = widgg._wdgImpl.getWidgetImplementation();
462    Frame control = (Frame)oControl;
463    Frame window = control;
464    Rectangle rectWindow = window.getBounds();
465    Rectangle rectWindowArea = rectWindow; //window.getClientArea();  //it is inclusive the menu bar.
466    //Problem: the x and y of client are are 0, it may bettet that they are the left top corner
467    //inside the shell window.
468    //assume that the client area is on bottom of the shell. Calculate top position:
469    int dxBorder = rectWindow.width - rectWindowArea.width;
470    int xPos = rectWindow.x + dxBorder/2;
471    int dyTitleMenu = (rectWindow.height - rectWindowArea.height) - dxBorder;  //border and title bar
472    MenuBar menu = window.getMenuBar();
473    if(menu !=null){
474      //assume that the menu has the same hight as title bar, there is not a way to determine it else
475      dyTitleMenu *=2;  
476    }
477    int yPos = rectWindow.y + dxBorder/2 + dyTitleMenu;
478    GralRectangle ret = new GralRectangle(xPos, yPos, rectWindowArea.width, rectWindowArea.height - dyTitleMenu);
479    return ret;
480  }
481  
482
483
484
485  @Override
486  public boolean remove(GralPanelContent compositeBox)
487  {
488    // TODO Auto-generated method stub
489    return false;
490  }
491
492
493
494  @Override public Color getColorImpl(GralColor color) { return propertiesGuiAwt.colorAwt(color); }
495
496  @Override
497  public String getValueFromWidget(GralWidget widgetDescr)
498  {
499    // TODO Auto-generated method stub
500    return null;
501  }
502
503
504  @Override
505  public void redrawWidget(String sName)
506  {
507    // TODO Auto-generated method stub
508    
509  }
510
511  @Override
512  public void resizeWidget(GralWidget widgd, int xSizeParent, int ySizeParent)
513  {
514    Object owidg = widgd._wdgImpl.getWidgetImplementation();
515    int test = 6;
516    if(owidg !=null){
517      Component swtWidget = (Component)owidg;
518      GralPanelContent panel = widgd.pos().panel;
519      GralRectangle size = panel._wdgImpl.getPixelPositionSize(); //PixelSize();
520      GralRectangle posSize = mng.calcWidgetPosAndSize(widgd.pos(), size.dx, size.dy, 0, 0);
521      //Note: the swtWidget may have a resizeListener, see there.
522      swtWidget.setBounds(posSize.x, posSize.y, posSize.dx, posSize.dy );
523      swtWidget.repaint();
524    }
525  }
526
527  @Override
528  public void setSampleCurveViewY(String sName, float[] values)
529  {
530    // TODO Auto-generated method stub
531    
532  }
533
534  
535  
536  /**Places a current component with knowledge of the current positions and the spreads of the component on graphic.
537   * @param component The component to place.
538   */
539  void setBounds_(GralPos pos, Component component)
540  { setPosAndSize_(pos, component);
541    //setBounds_(component, 0,0, 0, 0);
542  }
543  
544  
545  
546  
547  protected void setPosAndSize_(GralPos pos, Component component)
548  { setPosAndSizeAwt(pos, component, 0,0);
549  }  
550  
551  /**
552   * @param component
553   * @param widthwidgetNat
554   * @param heigthWidgetNat
555   *
556   * NOTE: 2015-07-13: This method is set to unused because it uses the mng-position additional to the constructor of GralWidget.
557   * This is the old concept which is in conflict with the usuage there.
558   */
559  protected void XXXsetPosAndSize_(Component component, int widthwidgetNat, int heigthWidgetNat)
560  {
561    mng.setNextPosition();
562    Component parentComp = component.getParent();
563    //Rectangle pos;
564    final GralRectangle rectangle;
565    if(parentComp == null){
566      rectangle = mng.calcWidgetPosAndSize(pos(), 800, 600, widthwidgetNat, heigthWidgetNat);
567    } else {
568      final Rectangle parentSize = parentComp.getBounds();
569      rectangle = mng.calcWidgetPosAndSize(pos(), parentSize.width, parentSize.height, widthwidgetNat, heigthWidgetNat);
570    }
571    component.setBounds(rectangle.x, rectangle.y, rectangle.dx, rectangle.dy );
572       
573  }
574  
575
576  
577    
578  /**Set bounds of a AWT component with a given position.
579   * This method is package-private for SWT-implementation.
580   * @param posP The Position for the component.
581   * @param component The AWT-widget.
582   * @param widthwidgetNat The natural size of the component.
583   * @param heigthWidgetNat The natural size of the component.
584   */
585  void setPosAndSizeAwt(GralPos posP, Component component, int widthwidgetNat, int heigthWidgetNat)
586  {
587    GralRectangle rectangle = calcWidgetPosAndSizeAwt(posP, component, widthwidgetNat, heigthWidgetNat);
588    //on SWT it invokes the resize listener if given.
589    Component parentComp = component.getParent();
590    //if(parentComp instanceof Frame){
591      rectangle.y += 50;  //title and menu bar
592    //}
593    component.setBounds(rectangle.x, rectangle.y, rectangle.dx, rectangle.dy );
594       
595  }
596  
597
598
599  
600  
601  
602  /**Calculates the bounds of a widget with a given pos independent of this {@link #pos}.
603   * This method is a part of the implementing GralMng because the GralPos is not implemented for
604   * any underlying graphic system and the {@link #propertiesGuiSwt} are used.
605   * It is possible to tune the bounds after calculation, for example to enhance the width if a text
606   * is larger then the intended position. 
607   * @param pos The position.
608   * @param widthwidgetNat The natural size of the component.
609   * @param heigthWidgetNat The natural size of the component.
610   * @return A rectangle with position and size.
611   */
612  @Override public GralRectangle calcWidgetPosAndSize(GralPos pos, int widthwidgetNat, int heigthWidgetNat){
613    Component parentComp = (Component)pos.panel.getWidgetImplementation();
614    //Rectangle pos;
615    final GralRectangle rectangle;
616    final Rectangle parentSize;
617    if(parentComp == null){
618      parentSize = new Rectangle(0,0,800, 600);
619    /*
620    } else if(parentComp instanceof Shell) {
621      parentSize = ((Shell)parentComp).getClientArea();
622    */
623    } else {
624      parentSize = parentComp.getBounds();
625    }
626    return pos.calcWidgetPosAndSize(mng.propertiesGui, parentSize.width, parentSize.height, widthwidgetNat, heigthWidgetNat);
627  }
628  
629  
630  
631  
632  
633  
634  /**Calculates the bounds of a SWT component with a given position independent of {@link #pos}.
635   * This method is package-private for SWT-implementation.
636   * It is possible to tune the bounds after calculation, for example to enhance the width if a text
637   * is larger then the intended position. 
638   * @param pos The position.
639   * @param component The SWT-widget.
640   * @param widthwidgetNat The natural size of the component.
641   * @param heigthWidgetNat The natural size of the component.
642   * @return A rectangle with position and size.
643   * @deprecated, use {@link #calcWidgetPosAndSizeSwt(GralPos, int, int)}
644   */
645  GralRectangle calcWidgetPosAndSizeAwt(GralPos pos, Component component, int widthwidgetNat, int heigthWidgetNat){
646    Component parentComp = component.getParent();
647    //Rectangle pos;
648    final GralRectangle rectangle;
649    final Rectangle parentSize;
650    if(parentComp == null){
651      parentSize = new Rectangle(0,0,800, 600);
652    } else if(parentComp instanceof Frame) {
653      parentSize = ((Frame)parentComp).getBounds(); // ??getAccessibleContext().  ??getClientArea();
654      parentSize.height -= 50;
655    } else {
656      parentSize = parentComp.getBounds();
657    }
658    return mng.calcWidgetPosAndSize(pos, parentSize.width, parentSize.height, widthwidgetNat, heigthWidgetNat);
659  }
660  
661
662  
663  
664
665  @Override public boolean showContextMenuGthread(GralWidget widg) {
666    boolean bOk;
667    Component awtWidg = (Component)widg._wdgImpl.getWidgetImplementation();
668    Menu contextMenu = null; //awtWidg.get;
669    if(contextMenu == null){
670      bOk = false;
671    } else {
672      //Rectangle pos = swtWidg.getBounds();
673      GralRectangle pos = AwtWidgetHelper.getPixelPositionSize(awtWidg);
674      //contextMenu.setLocation(pos.x + pos.dx, pos.y + pos.dy);
675      //contextMenu.setVisible(true);
676      bOk = true;
677    }
678    return bOk;
679  }
680  
681  
682
683
684  KeyListener XXXXX_mainKeyListener = new KeyListener(){
685
686    @Override
687    public void keyPressed(KeyEvent e) {
688      // TODO Auto-generated method stub
689      
690    }
691
692    @Override
693    public void keyReleased(KeyEvent e) {
694      // TODO Auto-generated method stub
695      stop();
696    }
697
698    @Override
699    public void keyTyped(KeyEvent e) {
700      // TODO Auto-generated method stub
701      
702    }
703    
704  };
705  
706  /**Universal focus listener to register which widgets were in focus in its order,
707   * to set htmlHelp and to invoke the {@link GralWidget#setActionFocused(GralUserAction)}.
708   */
709  protected class AwtMngFocusListener implements FocusListener
710  {
711    GralMng.GralMngFocusListener gralFocus;
712    
713    AwtMngFocusListener(){
714      gralFocus = GralMng.get().new GralMngFocusListener();
715    }
716    
717    @Override public void focusLost(FocusEvent ev)
718    { GralWidget widgg = GralWidget.ImplAccess.gralWidgetFromImplData(((AwtWidget)ev.getComponent()).getData());
719      gralFocus.focusLostGral(widgg);
720    }
721    
722    @Override public void focusGained(FocusEvent ev)
723    { GralWidget widgg = GralWidget.ImplAccess.gralWidgetFromImplData(((AwtWidget)ev.getComponent()).getData());
724      gralFocus.focusGainedGral(widgg);
725    }
726  }
727  
728  /**The package private universal focus listener. */
729  protected AwtMngFocusListener focusListener = new AwtMngFocusListener();
730
731
732
733  void stop(){}
734
735
736
737  @Override
738  public boolean XXXsetWindowsVisible(GralWindow_ifc window, GralPos atPos)
739  {
740    // TODO Auto-generated method stub
741    return false;
742  }
743
744
745
746
747
748  
749}