Skip to content
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

Bug #550 - Open the NebulaSlider to allow user extension #553

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package org.eclipse.nebula.widgets.opal.nebulaslider.snippets;

import org.eclipse.nebula.widgets.opal.nebulaslider.NebulaSlider;
import org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;

public class NebulaCustomSliderRenderer extends NebularDefaultSliderRenderer {

public NebulaCustomSliderRenderer(final NebulaSlider parentSlider) {
super(parentSlider);
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getBarInsideColor()
*/
@Override
public Color getBarInsideColor() {
return getAndDisposeColor(231, 225, 219);
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getBarBorderColor()
*/
@Override
public Color getBarBorderColor() {
return getAndDisposeColor(219, 211, 203);
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getBarSelectionColor()
*/
@Override
public Color getBarSelectionColor() {
return getAndDisposeColor(129, 108, 91);
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getSelectorColor()
*/
@Override
public Color getSelectorColor() {
return getAndDisposeColor(148, 130, 113);
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getSelectorColorBorder()
*/
@Override
public Color getSelectorColorBorder() {
return getAndDisposeColor(238, 234, 230);
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getSelectorTextColor()
*/
@Override
public Color getSelectorTextColor() {
return getAndDisposeColor(255, 255, 204);
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getArrowColor()
*/
@Override
public Color getArrowColor() {
return getAndDisposeColor(203, 192, 181);
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getTextFont()
*/
@Override
public Font getTextFont() {
final FontData fontData = parentSlider.getFont().getFontData()[0];
final Font newFont = new Font(parentSlider.getDisplay(), "Arial", Math.max(fontData.getHeight(), 14), SWT.ITALIC);
parentSlider.addDisposeListener(e -> {
if (!newFont.isDisposed()) {
newFont.dispose();
}
});
return newFont;
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getHorizontalMargin()
*/
@Override
public int getHorizontalMargin() {
// TODO Auto-generated method stub
return super.getHorizontalMargin();
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getSelectorWidth()
*/
@Override
public int getSelectorWidth() {
return 100;
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getSelectorHeight()
*/
@Override
public int getSelectorHeight() {
return 40;
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getBarHeight()
*/
@Override
public int getBarHeight() {
return 18;
}

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularDefaultSliderRenderer#getArrowLineWidth()
*/
@Override
public int getArrowLineWidth() {
return 5;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: Laurent CARON ([email protected])
Expand All @@ -13,8 +13,6 @@

import org.eclipse.nebula.widgets.opal.nebulaslider.NebulaSlider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
Expand Down Expand Up @@ -53,11 +51,8 @@ public static void main(final String[] args) {
slider.setValue(632);
slider.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

slider.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
System.out.println("New value is " + slider.getValue());
}
slider.addListener(SWT.Selection, e -> {
System.out.println("New value is " + slider.getValue());
});

final GridData layoutData = new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
Expand Down Expand Up @@ -116,14 +111,14 @@ public void widgetSelected(SelectionEvent e) {
display.dispose();
}

private static void createLeftLabel(Shell shell, String text) {
private static void createLeftLabel(final Shell shell, final String text) {
final Label lbl = new Label(shell, SWT.NONE);
lbl.setText(text);
lbl.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
lbl.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
}

private static Text createTextWidget(Shell shell, int value) {
private static Text createTextWidget(final Shell shell, final int value) {
final Text txt = new Text(shell, SWT.BORDER);
txt.setText(String.valueOf(value));
txt.setTextLimit(3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*******************************************************************************
* Copyright (c) 2011 Laurent CARON.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: Laurent CARON ([email protected])
*******************************************************************************/
package org.eclipse.nebula.widgets.opal.nebulaslider.snippets;

import org.eclipse.nebula.widgets.opal.nebulaslider.NebulaSlider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
* A simple snippet for the TextAssist Widget
*/
public class NebulaSliderSnippetOtherRenderer {
public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(2, false));
shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

createLeftLabel(shell, "Minimum");
final Text min = createTextWidget(shell, 0);

createLeftLabel(shell, "Maximum");
final Text max = createTextWidget(shell, 1000);

createLeftLabel(shell, "Value");
final Text value = createTextWidget(shell, 632);

final Button update = new Button(shell, SWT.PUSH);
update.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false, 2, 1));
update.setText("Redraw Slider");

final NebulaSlider slider = new NebulaSlider(shell, SWT.NONE);
slider.setMinimum(0);
slider.setMaximum(1000);
slider.setValue(632);
slider.setRenderer(new NebulaCustomSliderRenderer(slider));
slider.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

slider.addListener(SWT.Selection, e -> {
System.out.println("New value is " + slider.getValue());
});

final GridData layoutData = new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
layoutData.widthHint = 600;
layoutData.heightHint = 50;
slider.setLayoutData(layoutData);

update.addListener(SWT.Selection, e -> {
int minValue = 0;
try {
minValue = Integer.valueOf(min.getText());
} catch (final NumberFormatException nfe) {
showError(shell, "The value [" + min.getText() + "] is not a number");
return;
}

int maxValue = 0;
try {
maxValue = Integer.valueOf(max.getText());
} catch (final NumberFormatException nfe) {
showError(shell, "The value [" + max.getText() + "] is not a number");
return;
}

if (maxValue < minValue) {
showError(shell, "The minimum is greater than the maximum");
return;
}
//
int newValue = 0;
try {
newValue = Integer.valueOf(value.getText());
} catch (final NumberFormatException nfe) {
showError(shell, "The value [" + value.getText() + "] is not a number");
return;
}
if (newValue < minValue || newValue > maxValue) {
showError(shell, "The value [" + newValue + "] should be between " + minValue + " and " + maxValue);
return;
}
//
slider.setMinimum(minValue);
slider.setMaximum(maxValue);
slider.setValue(newValue);

});

shell.pack();
shell.open();

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

private static void createLeftLabel(final Shell shell, final String text) {
final Label lbl = new Label(shell, SWT.NONE);
lbl.setText(text);
lbl.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
lbl.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
}

private static Text createTextWidget(final Shell shell, final int value) {
final Text txt = new Text(shell, SWT.BORDER);
txt.setText(String.valueOf(value));
txt.setTextLimit(3);
final GridData gd = new GridData(GridData.FILL, GridData.CENTER, false, false);
gd.minimumWidth = 40;
txt.setLayoutData(gd);
return txt;
}

private static void showError(final Shell shell, final String message) {
final MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setText("Error");
mb.setMessage(message);
mb.open();
}
}
Loading
Loading