View Javadoc

1   /*
2    *  File: SwtControlPanel.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.examples.timebars.simple.swt;
21  
22  import org.eclipse.swt.SWT;
23  import org.eclipse.swt.custom.CCombo;
24  import org.eclipse.swt.events.SelectionAdapter;
25  import org.eclipse.swt.events.SelectionEvent;
26  import org.eclipse.swt.layout.RowLayout;
27  import org.eclipse.swt.widgets.Button;
28  import org.eclipse.swt.widgets.Composite;
29  import org.eclipse.swt.widgets.Label;
30  import org.eclipse.swt.widgets.Scale;
31  
32  import de.jaret.examples.timebars.simple.swt.renderer.CheckBoxHeaderRenderer;
33  import de.jaret.util.ui.timebars.swt.TimeBarViewer;
34  import de.jaret.util.ui.timebars.swt.renderer.AbstractGridRenderer;
35  import de.jaret.util.ui.timebars.swt.renderer.DefaultHeaderRenderer;
36  
37  /***
38   * Special setings for the swt overlap example.
39   * 
40   * @author Peter Kliem
41   * @version $Id: OverlapControlPanel.java 810 2009-01-08 22:28:57Z kliem $
42   */
43  public class OverlapControlPanel extends Composite {
44  
45      private TimeBarViewer _tbv;
46  
47      public OverlapControlPanel(Composite arg0, int arg1, TimeBarViewer tbv) {
48          super(arg0, arg1);
49          _tbv = tbv;
50          createControls(this);
51      }
52  
53      /***
54       * @param panel
55       */
56      private void createControls(OverlapControlPanel panel) {
57          panel.setLayout(new RowLayout());
58  
59          // check whether this has been initialized nd return otherwise
60          if (_tbv == null) {
61              return;
62          }
63  
64          final Button toggleSelectionMode = new Button(this, SWT.CHECK);
65          toggleSelectionMode.setText("Toggle row selection mode");
66          toggleSelectionMode.setSelection(_tbv.getSelectionModel().getRowSelectionToggleMode());
67          toggleSelectionMode.addSelectionListener(new SelectionAdapter() {
68              public void widgetSelected(SelectionEvent arg0) {
69                  _tbv.getSelectionModel().setRowSelectionToggleMode(toggleSelectionMode.getSelection());
70              }
71          });
72  
73          Label l = new Label(this, SWT.NULL);
74          l.setText("Header renderer");
75  
76          final CCombo headerRendererCombo = new CCombo(this, SWT.READ_ONLY | SWT.BORDER);
77          headerRendererCombo.setItems(new String[] {"Default", "CheckBoxRenderer"});
78          headerRendererCombo.select(0);
79          headerRendererCombo.addSelectionListener(new SelectionAdapter() {
80              public void widgetSelected(SelectionEvent arg0) {
81                  if (headerRendererCombo.getSelectionIndex() == 0) {
82                      _tbv.setHeaderRenderer(new DefaultHeaderRenderer());
83                  } else if (headerRendererCombo.getSelectionIndex() == 1) {
84                      _tbv.setHeaderRenderer(new CheckBoxHeaderRenderer());
85                  }
86              }
87          });
88          
89          l = new Label(this, SWT.NULL);
90          l.setText("RowSelectAlpha");
91  
92          final Scale selectionAlpha = new Scale(this, SWT.HORIZONTAL);
93          selectionAlpha.setMaximum(255);
94          selectionAlpha.setMinimum(0);
95          final AbstractGridRenderer gridRenderer = (AbstractGridRenderer)_tbv.getGridRenderer();
96          selectionAlpha.setSelection(gridRenderer.getRowSelectAlpha());
97          selectionAlpha.addSelectionListener(new SelectionAdapter() {
98              public void widgetSelected(SelectionEvent ev) {
99                  int val = selectionAlpha.getSelection();
100                 gridRenderer.setRowSelectAlpha(val);
101                 _tbv.redraw();
102             }
103 
104         });
105 //        RowData rd = new RowData(800, 40);
106 //        selectionAlpha.setLayoutData(rd);
107 
108         final Button uniformHeight = new Button(this, SWT.CHECK);
109         uniformHeight.setText("Uniform height");
110         uniformHeight.setSelection(_tbv.getUseUniformHeight());
111         uniformHeight.addSelectionListener(new SelectionAdapter() {
112             public void widgetSelected(SelectionEvent arg0) {
113                 _tbv.setUseUniformHeight(uniformHeight.getSelection());
114             }
115         });
116         
117         
118     }
119 }