/*
* Jampa
* Copyright (C) 2008-2009 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package org.jampa.gui.components.sliders;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Scale;
import org.jampa.controllers.Controller;
import org.jampa.preferences.PreferenceConstants;
/**
* Class to wrap sliders components to either the native SWT component Scale or
* to a DPlayerSlider.
*
* Done because Scale under windows are quite ugly and take to much vertical space.
*
* @author jdevauchelle
*
*/
public class SliderWrapper {
private boolean _boNativeSlider = true;
private DPlayerSlider _nonNativeSlider = null;
private Scale _nativeSlider = null;
public SliderWrapper(Composite parent, int style) {
_boNativeSlider = Controller.getInstance().getPreferenceStore().getBoolean(PreferenceConstants.PLAYERVIEW_USE_NATIVE_SLIDER);
if (_boNativeSlider) {
_nativeSlider = new Scale(parent, style);
} else {
_nonNativeSlider = new DPlayerSlider(parent, style | SWT.BORDER);
_nonNativeSlider.setGauge(10);
}
}
public void setEnabled(boolean value) {
if (_boNativeSlider) {
_nativeSlider.setEnabled(value);
} else {
_nonNativeSlider.setEnabled(value);
}
}
public boolean getEnabled() {
if (_boNativeSlider) {
return _nativeSlider.getEnabled();
} else {
return _nonNativeSlider.getEnabled();
}
}
public int getSelection() {
if (_boNativeSlider) {
return _nativeSlider.getSelection();
} else {
return _nonNativeSlider.getSelection();
}
}
public void setSelection(int value) {
if (_boNativeSlider) {
_nativeSlider.setSelection(value);
} else {
_nonNativeSlider.setSelection(value);
}
}
public void setMinimum(int value) {
if (_boNativeSlider) {
_nativeSlider.setMinimum(value);
} else {
// DPlaylerSlider minimum value is always 0.
}
}
public void setMaximum(int value) {
if (_boNativeSlider) {
_nativeSlider.setMaximum(value);
} else {
_nonNativeSlider.setMaximum(value);
}
}
public void addMouseListener(MouseListener listener) {
if (_boNativeSlider) {
_nativeSlider.addMouseListener(listener);
} else {
_nonNativeSlider.addMouseListener(listener);
}
}
public void addMouseMoveListener(MouseMoveListener listener) {
if (_boNativeSlider) {
_nativeSlider.addMouseMoveListener(listener);
} else {
_nonNativeSlider.addMouseMoveListener(listener);
}
}
public void setLayoutData(GridData gd) {
if (_boNativeSlider) {
_nativeSlider.setLayoutData(gd);
} else {
gd.heightHint = 15;
_nonNativeSlider.setLayoutData(gd);
}
}
public void setToolTipText(String text) {
if (_boNativeSlider) {
_nativeSlider.setToolTipText(text);
} else {
// DPlayerSlider does not handle tooltips.
}
}
}