Skip to content

Commit

Permalink
Bug #550 - Open the NebulaSlider to allow user extension
Browse files Browse the repository at this point in the history
All graphical information (sizes, colors, font) are now handled by a
configuration that can be customized.
  • Loading branch information
LaurentCaronAkuiteo committed Jan 22, 2024
1 parent 879f570 commit 2d70dd6
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ http://www.eclipse.org/legal/epl-v10.html
<parent>
<groupId>org.eclipse.nebula</groupId>
<artifactId>nebulaslider</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.nebula.widgets.nebulaslider.snippets</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*******************************************************************************
* Copyright (c) 2024 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 (laurent.caron at gmail dot com) - Initial
* implementation and API
*******************************************************************************/
package org.eclipse.nebula.widgets.opal.nebulaslider.snippets;

import org.eclipse.nebula.widgets.opal.nebulaslider.NebulaSlider;
import org.eclipse.nebula.widgets.opal.nebulaslider.NebularSliderDefaultConfiguration;
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 NebulaCustomSliderConfiguration extends NebularSliderDefaultConfiguration {

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

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

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

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

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

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

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

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

/**
* @see org.eclipse.nebula.widgets.opal.nebulaslider.NebularSliderDefaultConfiguration#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.NebularSliderDefaultConfiguration#getHorizontalMargin()
*/
@Override
public int getHorizontalMargin() {
// TODO Auto-generated method stub
return super.getHorizontalMargin();
}

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

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

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

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

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Laurent CARON.
* Copyright (c) 2018-2024 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Laurent CARON.
* Copyright (c) 2024 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
Expand Down Expand Up @@ -49,7 +49,7 @@ public static void main(final String[] args) {
slider.setMinimum(0);
slider.setMaximum(1000);
slider.setValue(632);
slider.setRenderer(new NebulaCustomSliderRenderer(slider));
slider.setRenderer(new NebulaCustomSliderConfiguration(slider));
slider.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

slider.addListener(SWT.Selection, e -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ http://www.eclipse.org/legal/epl-v10.html
<parent>
<groupId>org.eclipse.nebula</groupId>
<artifactId>nebulaslider</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.nebula.widgets.nebulaslider</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Laurent CARON
* Copyright (c) 2018-2024 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
Expand Down Expand Up @@ -37,7 +37,7 @@
*/
public class NebulaSlider extends Canvas {

private NebulaSliderRenderer renderer;
private NebulaSliderGraphicConfiguration renderer;

private int minimum;
private int maximum;
Expand Down Expand Up @@ -80,7 +80,7 @@ public class NebulaSlider extends Canvas {
public NebulaSlider(final Composite parent, final int style) {
super(parent, checkStyle(style) | SWT.DOUBLE_BUFFERED);

renderer = new NebularDefaultSliderRenderer(this);
renderer = new NebularSliderDefaultConfiguration(this);

minimum = Integer.MIN_VALUE;
maximum = Integer.MAX_VALUE;
Expand Down Expand Up @@ -428,7 +428,7 @@ public void setValue(final int value) {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public NebulaSliderRenderer getRenderer() {
public NebulaSliderGraphicConfiguration getRenderer() {
checkWidget();
return renderer;
}
Expand All @@ -444,7 +444,7 @@ public NebulaSliderRenderer getRenderer() {
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
* </ul>
*/
public void setRenderer(final NebulaSliderRenderer renderer) {
public void setRenderer(final NebulaSliderGraphicConfiguration renderer) {
checkWidget();
this.renderer = renderer;
redraw();
Expand Down
Loading

0 comments on commit 2d70dd6

Please sign in to comment.