View Javadoc

1   /*
2    *  File: LineChartControlPanel.java 
3    *  Copyright (c) 2004-2007  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.linechart.swt;
21  
22  import org.eclipse.swt.SWT;
23  import org.eclipse.swt.events.SelectionAdapter;
24  import org.eclipse.swt.events.SelectionEvent;
25  import org.eclipse.swt.layout.RowData;
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.Scale;
30  
31  import de.jaret.util.ui.timebars.swt.TimeBarViewer;
32  
33  /***
34   * Control panel for the line chart example.
35   * 
36   * @author Peter Kliem
37   * @version $Id: LineChartControlPanel.java 766 2008-05-28 21:36:48Z kliem $
38   */
39  public class LineChartControlPanel extends Composite {
40  
41      private TimeBarViewer _tbv;
42  
43      public LineChartControlPanel(Composite parent, int style, TimeBarViewer tbv) {
44          super(parent, style);
45          _tbv = tbv;
46          createControls(this);
47      }
48  
49      /***
50       * @param panel
51       */
52      private void createControls(LineChartControlPanel panel) {
53          panel.setLayout(new RowLayout());
54  
55          final Scale pixPerSecondsScale = new Scale(this, SWT.HORIZONTAL);
56          pixPerSecondsScale.setMaximum(700);
57          pixPerSecondsScale.setMinimum(1);
58          if (_tbv.getPixelPerSecond() * (24.0 * 60.0 * 60.0) > 700) {
59              pixPerSecondsScale.setMaximum((int) (_tbv.getPixelPerSecond() * (24.0 * 60.0 * 60.0)));
60          }
61          pixPerSecondsScale.addSelectionListener(new SelectionAdapter() {
62              public void widgetSelected(SelectionEvent ev) {
63                  int val = pixPerSecondsScale.getSelection();
64                  double pps = ((double) val) / (24.0 * 60.0 * 60.0);
65                  System.out.println("scale " + val + "pps " + pps);
66                  _tbv.setPixelPerSecond(pps);
67              }
68  
69          });
70          pixPerSecondsScale.setSelection((int) (_tbv.getPixelPerSecond() * (24.0 * 60.0 * 60.0)));
71          RowData rd = new RowData(800, 40);
72          pixPerSecondsScale.setLayoutData(rd);
73          
74          final Button optScrollingCheck = new Button(this, SWT.CHECK);
75          optScrollingCheck.setText("Use optimized scrolling");
76          optScrollingCheck.setSelection(_tbv.getOptimizeScrolling());
77          optScrollingCheck.addSelectionListener(new SelectionAdapter() {
78              public void widgetSelected(SelectionEvent arg0) {
79                  _tbv.setOptimizeScrolling(optScrollingCheck.getSelection());
80              }
81          });
82  
83          
84      }
85  }