001package org.vishia.gral.swt; 002 003import org.eclipse.swt.graphics.Color; 004import org.eclipse.swt.graphics.Device; 005import org.eclipse.swt.graphics.GC; 006import org.eclipse.swt.widgets.Composite; 007import org.vishia.gral.base.GralMng; 008import org.vishia.gral.base.GralPanelContent; 009import org.vishia.gral.base.GralWidget; 010 011/**This is a org.eclipse.swt.widgets.Composite. 012 * It can contain some GUI-Elements like Button, Text, Label, Table etc from org.eclipse.swt.widgets. 013 * But additional a grid is shown as background. 014 * This class is imaginary for the {@link org.vishia.gral.swt.SwtMng} 015 * to show the grid for positions. 016 * 017 * @author Hartmut Schorrig 018 * 019 */ 020public class SwtGridPanel extends SwtCanvasStorePanel 021{ 022 023 /**Version, history and license. 024 * <ul> 025 * <li>2016-09-02 Hartmut chg: {@link #SwtGridPanel(GralPanelContent, Composite, int, Color, int, int, int, int, GralMng)} is no more invoked with a parent 026 * but the parent is gotten by itself in the constructor from the pos().panel. 027 * Reason: The panel maybe set only after construction of the {@link GralWidget.ImplAccess}. It is not known before. 028 * <li>2011-06-00 Hartmut created 029 * </ul> 030 * 031 * <b>Copyright/Copyleft</b>:<br> 032 * For this source the LGPL Lesser General Public License, 033 * published by the Free Software Foundation is valid. 034 * It means: 035 * <ol> 036 * <li> You can use this source without any restriction for any desired purpose. 037 * <li> You can redistribute copies of this source to everybody. 038 * <li> Every user of this source, also the user of redistribute copies 039 * with or without payment, must accept this license for further using. 040 * <li> But the LPGL is not appropriate for a whole software product, 041 * if this source is only a part of them. It means, the user 042 * must publish this part of source, 043 * but doesn't need to publish the whole source of the own product. 044 * <li> You can study and modify (improve) this source 045 * for own using or for redistribution, but you have to license the 046 * modified sources likewise under this LGPL Lesser General Public License. 047 * You mustn't delete this Copyright/Copyleft inscription in this source file. 048 * </ol> 049 * If you intent to use this source without publishing its usage, you can get 050 * a second license subscribing a special contract with the author. 051 * 052 * @author Hartmut Schorrig = hartmut.schorrig@vishia.de 053 */ 054 public static final String sVersion = "2016-09-02"; 055 056 private static final long serialVersionUID = 6448419343757106982L; 057 058 int xG, yG; 059 060 int xS, yS; 061 062 public SwtGridPanel(GralPanelContent panelg, Composite xxxparent, int style, Color backGround, int xG, int yG, int xS, int yS, GralMng gralMng) 063 { super(panelg); 064 Composite parent = (Composite)panelg.pos().panel._wdgImpl.getWidgetImplementation(); 065 066 swtCanvas = new SwtCanvasGridPanel(this, parent, style); 067 super.panelComposite = swtCanvas; 068 swtCanvas.addControlListener(resizeItemListener); 069 swtCanvas.setData(this); 070 swtCanvas.setLayout(null); 071 currColor = swtCanvas.getForeground(); 072 swtCanvas.addPaintListener(swtCanvas.paintListener); 073 swtCanvas.setBackground(backGround); 074 setGridWidth(xG, yG, xS, yS); 075 } 076 077 public void setGridWidth(int xG, int yG, int xS, int yS) 078 { 079 this.xG = xG; this.yG = yG; 080 this.xS = xS; this.yS = yS; 081 } 082 083 084 085 086 087 protected static class SwtCanvasGridPanel extends SwtCanvas 088 { 089 private final SwtGridPanel mng; 090 091 SwtCanvasGridPanel(SwtGridPanel storeMng, Composite parent, int style) 092 { super(storeMng, parent, style); 093 this.mng = storeMng; 094 095 } 096 097 098 @Override 099 public void drawBackground(GC g, int x, int y, int dx, int dy) { 100 //NOTE: forces stack overflow because calling of this routine recursively: super.paint(g); 101 Color colorBack = getBackground(); 102 Device device = colorBack.getDevice(); 103 Color color1 = new Color(device, colorBack.getRed() ^ 0x08, colorBack.getGreen() ^ 0x08, colorBack.getBlue() ^0x08); 104 Color color2 = new Color(device, colorBack.getRed() ^ 0x10, colorBack.getGreen() ^ 0x10, colorBack.getBlue() ^0x10); 105 int xGrid = mng.xG; 106 int xS1 = mng.xS; 107 while(xGrid < dx){ 108 if(--xS1 <=0){ 109 xS1 = mng.xS; g.setForeground(color2); 110 } else { g.setForeground(color1); 111 } 112 g.drawLine(xGrid, 0, xGrid, dy); 113 xGrid += mng.xG; 114 } 115 int yGrid = mng.yG; 116 int yS1 = mng.yS; 117 while(yGrid < dy){ 118 if(--yS1 <=0){ 119 yS1 = mng.yS; g.setForeground(color2); 120 } else { g.setForeground(color1); 121 } 122 g.drawLine(0, yGrid, dx, yGrid); 123 yGrid += mng.yG; 124 } 125 super.drawBackground(g, x, y, dx, dy); 126 } 127 } 128 129 130 131 void stop(){} //debug 132 133}