1 26 27 package org.nightlabs.editor2d.viewer; 28 29 import java.awt.Point ; 30 31 import org.eclipse.swt.SWT; 32 import org.eclipse.swt.events.SelectionEvent; 33 import org.eclipse.swt.events.SelectionListener; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.layout.GridLayout; 36 import org.eclipse.swt.widgets.Button; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.swt.widgets.Control; 39 import org.eclipse.swt.widgets.Label; 40 import org.eclipse.swt.widgets.Shell; 41 import org.eclipse.swt.widgets.Text; 42 import org.nightlabs.base.dialog.FullScreenDialog; 43 import org.nightlabs.editor2d.DrawComponent; 44 import org.nightlabs.editor2d.render.RenderModeManager; 45 import org.nightlabs.editor2d.viewer.event.IMouseChangedListener; 46 47 public abstract class AbstractTestDialog 48 extends FullScreenDialog 49 { 50 public AbstractTestDialog(Shell shell, DrawComponent dc) 51 { 52 super(shell); 53 setShellStyle(getShellStyle() | SWT.RESIZE); 54 this.dc = dc; 55 dc.setRenderModeManager(new RenderModeManager()); 56 } 57 58 protected DrawComponent dc; 59 protected AbstractCanvasComposite viewer; 60 protected Composite comp; 61 protected Text zoomText; 62 63 protected Control createDialogArea(Composite parent) 64 { 65 GridLayout layout = new GridLayout(1, false); 66 parent.setLayout(layout); 67 68 Composite buttonComp = new Composite(parent, SWT.BORDER); 69 GridLayout buttonCompLayout = new GridLayout(4, true); 70 buttonComp.setLayout(buttonCompLayout); 71 72 GridData buttonCompData = new GridData(GridData.FILL_HORIZONTAL); 73 buttonComp.setLayoutData(buttonCompData); 74 75 Button refreshButton = new Button(buttonComp, SWT.NONE); 77 refreshButton.setText("Refresh"); 78 refreshButton.addSelectionListener(refreshListener); 79 80 Button zoomInButton = new Button(buttonComp, SWT.NONE); 82 zoomInButton.setText("ZoomIn"); 83 zoomInButton.addSelectionListener(zoomInListener); 84 85 Button zoomOutButton = new Button(buttonComp, SWT.NONE); 87 zoomOutButton.setText("ZoomOut"); 88 zoomOutButton.addSelectionListener(zoomOutListener); 89 90 viewer = getViewer(parent); 91 GridData viewerData = new GridData(GridData.FILL_BOTH); 92 viewer.setLayoutData(viewerData); 93 viewer.getMouseManager().addMouseChangedListener(mouseListener); 95 96 Composite bottomComp = new Composite(parent, SWT.BORDER); 97 GridLayout bottomLayout = new GridLayout(3, true); 98 bottomComp.setLayout(bottomLayout); 99 GridData bottmCompData = new GridData(GridData.FILL_HORIZONTAL); 100 bottomComp.setLayoutData(bottmCompData); 101 102 mouseLabelX = new Label(bottomComp, SWT.NONE); 103 mouseLabelX.setText("X = "+10000); 104 mouseLabelY = new Label(bottomComp, SWT.NONE); 105 mouseLabelY.setText("Y = "+10000); 106 107 zoomText = new Text(buttonComp, SWT.BORDER); 109 zoomText.setText(""+(viewer.getZoom()*100)+"%"); 110 viewer.getZoomSupport().addZoomListener(zoomListener); 111 112 return parent; 113 } 114 115 protected abstract AbstractCanvasComposite getViewer(Composite parent); 116 117 protected Label mouseLabelX; 118 protected Label mouseLabelY; 119 120 protected IMouseChangedListener mouseListener = new IMouseChangedListener() 121 { 122 public void mouseChanged(Point relative, Point absolute) 123 { 124 mouseLabelX.setText("X = "+relative.x); 125 mouseLabelY.setText("Y = "+relative.y); 126 } 127 }; 128 129 protected int x; 130 protected int y; 131 132 147 protected SelectionListener refreshListener = new SelectionListener() 148 { 149 public void widgetDefaultSelected(SelectionEvent arg0) { 150 widgetSelected(arg0); 151 } 152 public void widgetSelected(SelectionEvent arg0) { 153 update(); 154 } 155 }; 156 157 protected SelectionListener zoomInListener = new SelectionListener() 158 { 159 public void widgetDefaultSelected(SelectionEvent arg0) { 160 widgetSelected(arg0); 161 } 162 public void widgetSelected(SelectionEvent arg0) { 163 viewer.getZoomSupport().zoomIn(); 164 update(); 165 } 166 }; 167 168 protected SelectionListener zoomOutListener = new SelectionListener() 169 { 170 public void widgetDefaultSelected(SelectionEvent arg0) { 171 widgetSelected(arg0); 172 } 173 public void widgetSelected(SelectionEvent arg0) 174 { 175 viewer.getZoomSupport().zoomOut(); 176 update(); 177 } 178 }; 179 180 protected IZoomListener zoomListener = new IZoomListener() 181 { 182 public void zoomChanged(double zoom) { 183 zoomText.setText(""+(zoom*100)+"%"); 184 } 185 }; 186 187 protected void update() 188 { 189 viewer.updateCanvas(); 190 } 191 192 } 193 | Popular Tags |