Skip to content

Commit

Permalink
Merge pull request #2395 from dls-controls/2334-cursors
Browse files Browse the repository at this point in the history
Improve cursor behaviour in BOY
  • Loading branch information
berryma4 committed Feb 14, 2018
2 parents 1895ee1 + e548055 commit 5061114
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
Expand Up @@ -35,7 +35,7 @@ public String getTypeID() {

/** The message which will be shown on confirm dialog. */
public static final String PROP_CONFIRM_TIP = "confirm_message"; //$NON-NLS-1$
public static final String DEFAULT_CONFIRM_TIP = "Are your sure you want to do this?";
public static final String DEFAULT_CONFIRM_TIP = "Are you sure you want to do this?";

/**
* The action which will be executed when widget is pushed. It is the index the actions in
Expand Down
Expand Up @@ -43,8 +43,10 @@ protected IFigure doCreateFigure() {
slider.setHorizontal(model.isHorizontal());
slider.setStepIncrement(model.getStepIncrement());
slider.setPageIncrement(model.getPageIncrement());
slider.setRunMode(getExecutionMode().equals(ExecutionMode.RUN_MODE));
slider.addManualValueChangeListener(new IManualValueChangeListener() {

@Override
public void manualValueChanged(double newValue) {
if (getExecutionMode() == ExecutionMode.RUN_MODE)
setPVValue(ScaledSliderModel.PROP_PVNAME, newValue);
Expand All @@ -70,6 +72,7 @@ protected void registerPropertyChangeHandlers() {

//fillColor
IWidgetPropertyChangeHandler fillColorHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue,
final Object newValue,
final IFigure refreshableFigure) {
Expand Down
Expand Up @@ -68,6 +68,7 @@ public void mouseExited(MouseEvent me) {
* @param y the y coordinate
* @return <code>true</code>if the given point is contained
*/
@Override
public boolean containsPoint(int x, int y) {
if (!super.containsPoint(x, y))
return false;
Expand Down Expand Up @@ -183,6 +184,7 @@ public void mouseExited(MouseEvent me) {
/**
* This must be implemented to make tool tip work. I don't know why.
*/
@Override
public boolean containsPoint(int x, int y) {
return getBounds().getCopy().shrink(2, 2).contains(x, y);
}
Expand Down Expand Up @@ -439,20 +441,18 @@ public void setEnabled(boolean value) {
super.setEnabled(value);
if(runMode){
if(value){
if(cursor == null || cursor.isDisposed())
cursor = Cursors.HAND;
}else {
cursor = null;
cursor = Cursors.HAND;
} else {
cursor = Cursors.NO;
}
}
if(squareButton)
if(squareButton) {
squareButtonFigure.setEnabled(value);
else
squareButtonFigure.setCursor(runMode ? cursor : null);
} else {
ellipseButton.setEnabled(value);
if(ellipseButton.isVisible())
ellipseButton.setCursor(runMode ? cursor : null);
else if (squareButtonFigure.isVisible())
squareButtonFigure.setCursor(runMode ? cursor : null);
}
}

@Override
Expand Down
Expand Up @@ -90,6 +90,8 @@ public class ScaledSliderFigure extends AbstractLinearMarkedFigure {

private double pageIncrement = 10;

private boolean runMode = false;

/**
* Listeners that react on slider events.
*/
Expand Down Expand Up @@ -128,13 +130,15 @@ public ScaledSliderFigure() {
add(label, "label");

addFigureListener(new FigureListener() {
@Override
public void figureMoved(IFigure source) {
revalidate();
}
});

addKeyListener(new KeyListener() {

@Override
public void keyPressed(KeyEvent ke) {
if((ke.keycode == SWT.ARROW_DOWN && !horizontal) ||
(ke.keycode == SWT.ARROW_LEFT && horizontal) )
Expand All @@ -148,16 +152,19 @@ else if(ke.keycode == SWT.PAGE_DOWN)
pageDown();
}

@Override
public void keyReleased(KeyEvent ke) {
}
});

addFocusListener(new FocusListener() {

@Override
public void focusGained(FocusEvent fe) {
repaint();
}

@Override
public void focusLost(FocusEvent fe) {
repaint();
}
Expand Down Expand Up @@ -335,12 +342,19 @@ public void setEffect3D(boolean effect3D) {
repaint();
}


@Override
public void setEnabled(boolean value) {
super.setEnabled(value);
if (runMode) {
if(value){
track.setCursor(Cursors.HAND);
thumb.setCursor(Cursors.HAND);
} else {
track.setCursor(Cursors.NO);
thumb.setCursor(Cursors.NO);
}
}
repaint();

}

/**
Expand Down Expand Up @@ -422,6 +436,11 @@ public void stepUp(){
fireManualValueChange(getValue());
}

public void setRunMode(boolean runMode) {
this.runMode = runMode;
thumb.setCursor(runMode ? Cursors.HAND: null);
track.setCursor(runMode ? Cursors.HAND: null);
}

class Thumb extends Polygon {
class ThumbDragger
Expand All @@ -433,10 +452,12 @@ class ThumbDragger

private OPITimer timer;

@Override
public void mouseDoubleClicked(MouseEvent me) {

}

@Override
public void mouseDragged(MouseEvent me) {
if (!armed)
return;
Expand Down Expand Up @@ -479,18 +500,21 @@ public void run() {



@Override
public void mouseEntered(MouseEvent me) {
temp = thumbColor;
thumbColor = GREEN_COLOR;
repaint();
}

@Override
public void mouseExited(MouseEvent me) {
thumbColor = temp;
label.setVisible(false);
repaint();
}

@Override
public void mousePressed(MouseEvent me) {
if(me.button != 1)
return;
Expand All @@ -508,6 +532,7 @@ public void mousePressed(MouseEvent me) {

}

@Override
public void mouseReleased(MouseEvent me) {
if(me.button != 1)
return;
Expand Down Expand Up @@ -583,6 +608,7 @@ public Track() {

behavior.setRunTask(new Runnable() {

@Override
public void run() {
if(pageUp){
if(getValue() >=pressedValue)
Expand Down Expand Up @@ -802,6 +828,7 @@ private void horizontalLayout(IFigure container) {
setLabel();
}

@Override
public void layout(IFigure container) {
if(horizontal)
horizontalLayout(container);
Expand Down

0 comments on commit 5061114

Please sign in to comment.