-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of slider widget. #166
base: master
Are you sure you want to change the base?
Conversation
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may add yourself.
case SWT.MouseUp -> onMouseUp(event); | ||
case SWT.MouseHorizontalWheel -> onMouseHorizontalWheel(event); | ||
case SWT.MouseVerticalWheel -> onMouseVerticalWheel(event); | ||
case SWT.Paint -> onPaint(event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd order the events by importance (most important Paint should come first), but otherwise good to use the light-weight events.
orientation = style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); | ||
|
||
super.style |= horizontal ? SWT.HORIZONTAL : SWT.VERTICAL; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove empty lines after { or before }.
private void onMouseVerticalWheel(Event event) { | ||
if (!isVisible()) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, if not visible, there should not be any event at all. Did you got some while invisible?
|
||
private void onMouseHorizontalWheel(Event event) { | ||
if (!isVisible()) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
} | ||
|
||
if (event.count > 0) { | ||
increment(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What means this hard-coded 2
? Why not 1
?
private void onPaint(Event event) { | ||
if (!isVisible()) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SWT.Paint should not be sent if not visible.
} | ||
|
||
private void onMouseDown(Event event) { | ||
// Drag of the thumb. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it work for any mouse button? If not, please check with if (event.button != 1) return;
|
||
|
||
private void onMouseUp(Event event) { | ||
if (isDragging) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try with moving the mouse outside the shell and moving it back. There exists a method to get all mouse events (forgot its name).
} | ||
|
||
private void onMouseMove(Event event) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line after {
} else { | ||
thumbHovered = false; | ||
redraw(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if-statement is not necessary - thumbHovered = isThumbHovered; redraw();
should do the same.
int height = drawingArea.height; | ||
|
||
// Fill background | ||
if (getBackground() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getBackground() will always return != null.
|
||
// Fill background | ||
if (getBackground() != null) { | ||
gc.setBackground(getBackground()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't invoke the getter twice but store in local variable.
public void removeSelectionListener(SelectionListener listener) { | ||
checkWidget(); | ||
if (listener == null) | ||
error(SWT.ERROR_NULL_ARGUMENT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be on same line or as block statement ({ ... }
).
* </ul> | ||
*/ | ||
public int getIncrement() { | ||
checkWidget(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably these checks can be removed for such plain getters. Later, the separate Renderer needs to use these methods and checking for each method is useless wasted CPU time.
private int minMax(int min, int value, int max) { | ||
return Math.min(Math.max(min, value), max); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line
this.pageIncrement = pageIncrement; | ||
} | ||
|
||
private int minMax(int min, int value, int max) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be static
. Maybe it could be moved to a different utilities class?
No description provided.