    001package org.vishia.gral.swt;
    002
    003
    004import java.awt.Component;
    005import java.awt.Dimension;
    006
    007import org.eclipse.swt.events.ControlEvent;
    008import org.eclipse.swt.events.ControlListener;
    009import org.eclipse.swt.graphics.Rectangle;
    010import org.eclipse.swt.widgets.Composite;
    011import org.eclipse.swt.widgets.Control;
    012import org.eclipse.swt.widgets.Shell;
    013import org.eclipse.swt.widgets.TabItem;
    014import org.eclipse.swt.widgets.Widget;
    015import org.vishia.gral.base.GralWidget;
    016import org.vishia.gral.base.GralMng;
    017import org.vishia.gral.base.GralPanelContent;
    018import org.vishia.gral.ifc.GralColor;
    019import org.vishia.gral.ifc.GralPrimaryWindow_ifc;
    020import org.vishia.gral.ifc.GralRectangle;
    021
    022public class SwtPanel extends GralPanelContent.ImplAccess
    023{
    024
    025  /**Version history:
    026   * <ul>
    027   * <li>2011-11-19 Hartmut chg: {@link #itsTabSwt} with correct type moved from {@link GralPanelContent}.
    028   * <li>2011-09-25 Hartmut creation: Common class for all Swt implementations of Panels.
    029   *   This class can implement the abstract methods from {@link GralPanelContent} for the implementation
    030   *   in a common form.
    031   * </ul>
    032   *
    033   */
    034  @SuppressWarnings("hiding")
    035  public final static int version = 0x20111119;
    036
    037
    038  /**It is either a Composite or a SwtCanvas
    039   *
    040   */
    041  public Composite panelComposite;
    042
    043  /**The associated tab in a TabFolder if this panel is the main panel of the TabItem, or null
    044   * if it isn't a main panel of a tab in a tabbed panel.
    045   * <br><br>
    046   * Note: can't be final because it may be unknown on calling constructor. The property whether
    047   * a panel is a tab-panel can't be presented with an extra subclass, because this class is the subclass
    048   * of several Swt panel types. Use the aggregation principle instead multi-inheritance.
    049   */
    050  public TabItem itsTabSwt;
    051
    052
    053  //protected Composite panelSwt;
    054
    055  private SwtPanel(GralPanelContent panelg)
    056  { super(panelg);
    057    panelComposite = null;
    058  }
    059
    060  /**Constructs a panel
    061   * @param name of panel.
    062   * @param mng The widget manager
    063   * @param panelSwt may be null, then the {@link GralPanelContent#panelComposite} should be set
    064   *   after construction of a derived class.
    065   */
    066  public SwtPanel(GralPanelContent panelg, Composite panelSwt)
    067  { super(panelg);
    068    panelComposite = panelSwt;
    069    if(panelSwt !=null){
    070      panelSwt.addControlListener(resizeItemListener);
    071    }
    072  }
    073
    074  /*
    075  @Override public Composite getPanelImpl()
    076  {
    077    return (Composite)panelComposite;
    078  }*/
    079
    080
    081
    082
    083  @Override public GralRectangle getPixelPositionSize(){ return SwtWidgetHelper.getPixelPositionSize((Composite)panelComposite); }
    084
    085
    086  @Override public GralRectangle getPixelSize(){
    087    Rectangle r = ((Composite)panelComposite).getClientArea();
    088    GralRectangle posSize = new GralRectangle(0, 0, r.width, r.height);
    089    return posSize;
    090  }
    091
    092
    093  @Override public void setBoundsPixel(int x, int y, int dx, int dy)
    094  { ((Composite)panelComposite).setBounds(x,y,dx,dy);
    095  }
    096
    097
    098
    099  @Override public void repaintGthread(){
    100    if(panelComposite !=null){
    101      ((Composite)panelComposite).redraw();
    102    }
    103  }
    104
    105
    106
    107
    108  @Override public void removeWidgetImplementation()
    109  { if(panelComposite !=null){
    110      ((Composite)panelComposite).dispose();
    111      panelComposite = null;
    112    }
    113  }
    114
    115
    116  //@Override
    117  public boolean remove(){
    118
    119    //super.remove();
    120    if(itsTabSwt !=null){
    121      itsTabSwt.dispose();
    122      itsTabSwt = null;
    123    }
    124    if(panelComposite !=null){
    125      panelComposite.dispose();
    126    }
    127    return true;
    128  }
    129
    130
    131
    132  protected ControlListener resizeItemListener = new ControlListener()
    133  { @Override public void controlMoved(ControlEvent e)
    134    { //do nothing if moved.
    135    }
    136
    137    @Override public void controlResized(ControlEvent e)
    138    {
    139      Widget wparent = e.widget; //it is the SwtCanvas because this method is assigned only there.
    140      //Control parent = wparent;
    141      for(GralWidget widg1: ((GralPanelContent)widgg).widgetsToResize){
    142        widg1.gralMng().resizeWidget(widg1, 0, 0);
    143      }
    144      //validateFrameAreas();  //calculates the size of the areas newly and redraw.
    145    }
    146
    147  };
    148
    149
    150  @Override public boolean setFocusGThread()
    151  {
    152    setVisibleGThread(true);
    153    boolean bRet = panelComposite.setFocus();
    154    return bRet;
    155  }
    156
    157  @Override public void setVisibleGThread(boolean bVisible) { super.setVisibleState(bVisible); panelComposite.setVisible(bVisible); }
    158
    159
    160  @Override public Object getWidgetImplementation()
    161  {
    162    // TODO Auto-generated method stub
    163    return panelComposite;
    164  }
    165
    166
    167
    168
    169
    170}