View Javadoc

1   /*
2    *  File: DefaultMiscRenderer.java 
3    *  Copyright (c) 2004-2008  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation; either version 2 of the License, or
9    *  (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *  GNU General Public License for more details.
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package de.jaret.util.ui.timebars.swt.renderer;
21  
22  import java.awt.Rectangle;
23  
24  import org.eclipse.swt.SWT;
25  import org.eclipse.swt.graphics.Color;
26  import org.eclipse.swt.graphics.GC;
27  import org.eclipse.swt.printing.Printer;
28  
29  import de.jaret.util.ui.timebars.TimeBarViewerDelegate;
30  import de.jaret.util.ui.timebars.swt.TimeBarViewer;
31  
32  /**
33   * Default implementation of the IMiscRenderer for SWT.
34   * 
35   * @author kliem
36   * @version $Id: DefaultMiscRenderer.java 800 2008-12-27 22:27:33Z kliem $
37   */
38  public class DefaultMiscRenderer extends RendererBase implements IMiscRenderer {
39  
40      /**
41       * Default constructor.
42       */
43      public DefaultMiscRenderer() {
44          super(null);
45      }
46  
47      /**
48       * Construct the renderer for printing.
49       * 
50       * @param printer the printer device.
51       */
52      public DefaultMiscRenderer(Printer printer) {
53          super(printer);
54      }
55  
56      /**
57       * {@inheritDoc}
58       */
59      public void dispose() {
60      }
61  
62      /**
63       * {@inheritDoc}
64       */
65      public void renderRegionSelection(GC gc, TimeBarViewer tbv, TimeBarViewerDelegate delegate) {
66          if (delegate.getRegionRect() != null) {
67              Rectangle rect = delegate.calcRect(delegate.getRegionRect());
68  
69              // save
70              Color bg = gc.getBackground();
71              int alpha = gc.getAlpha();
72  
73              gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_GRAY));
74              gc.setAlpha(100);
75              gc.fillRectangle(rect.x, rect.y, rect.width, rect.height);
76              gc.setAlpha(255);
77              gc.drawRectangle(rect.x, rect.y, rect.width, rect.height);
78  
79              // restore
80              gc.setAlpha(alpha);
81              gc.setBackground(bg);
82          }
83  
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      public void renderSelectionRect(GC gc, Rectangle selRect) {
90          Color fg = gc.getForeground();
91          gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_DARK_MAGENTA));
92          gc.drawRectangle(selRect.x, selRect.y, selRect.width, selRect.height);
93          gc.setForeground(fg);
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      public IMiscRenderer createPrintRenderer(Printer printer) {
100         return new DefaultMiscRenderer(printer);
101     }
102 
103 }