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