Skip to main content
summaryrefslogtreecommitdiffstats
blob: e791acc8e654fa3cff260fa46d265567208b6a5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.ui.widgets;

import org.eclipse.net4j.util.ui.UIUtil;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;

/**
 * @author Eike Stepper
 * @since 2.0
 */
// Under development
@Deprecated
public class AuditScale extends Composite
{
  private int direction;

  private int scaleStyle;

  private Scale scale;

  public AuditScale(Composite parent, int scaleStyle)
  {
    super(parent, SWT.NONE);
    setLayout(UIUtil.createGridLayout(1));

    this.scaleStyle = scaleStyle;
    updateDirection();
  }

  /**
   * @since 4.0
   */
  public int getDirection()
  {
    return direction;
  }

  public int getScaleStyle()
  {
    return scaleStyle;
  }

  public Scale getScale()
  {
    return scale;
  }

  protected Scale createScale(int style)
  {
    return new Scale(this, style);
  }

  @Override
  public void setBounds(int x, int y, int width, int height)
  {
    super.setBounds(x, y, width, height);
    updateDirection();
  }

  private void updateDirection()
  {
    int newDirection;
    if ((scaleStyle & SWT.HORIZONTAL) != 0)
    {
      newDirection = SWT.HORIZONTAL;
    }
    else if ((scaleStyle & SWT.VERTICAL) != 0)
    {
      newDirection = SWT.VERTICAL;
    }
    else
    {
      Rectangle clientArea = getClientArea();
      if (clientArea.height > clientArea.width)
      {
        newDirection = SWT.VERTICAL;
      }
      else
      {
        newDirection = SWT.HORIZONTAL;
      }
    }

    if (direction != newDirection)
    {
      direction = newDirection;
      if (scale != null)
      {
        scale.dispose();
        scale = null;
      }
    }

    if (scale == null)
    {
      int style = scaleStyle & ~(SWT.HORIZONTAL | SWT.VERTICAL) | direction;
      scale = createScale(style);
      scale.setLayoutData(UIUtil.createGridData());
    }
  }

  public static void main(String[] args)
  {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(UIUtil.createGridLayout(1));

    AuditScale scale = new AuditScale(shell, SWT.NONE);
    scale.setLayoutData(UIUtil.createGridData());

    // scale.setSize(200, 64);
    // scale.setMaximum(40);
    // scale.setPageIncrement(5);

    shell.open();
    while (!shell.isDisposed())
    {
      if (!display.readAndDispatch())
      {
        display.sleep();
      }
    }

    display.dispose();
  }
}

Back to the top