import java.awt.event.AdjustmentListener;
import javax.swing.JScrollBar;
+import javax.swing.SwingUtilities;
import org.scilab.modules.graphic_objects.graphicController.GraphicController;
import org.scilab.modules.gui.SwingViewWidget;
private static final int MIN_KNOB_SIZE = 40;
private static final int MINIMUM_VALUE = 0;
- private static final int MAXIMUM_VALUE = 1000;
+ private static final int MAXIMUM_VALUE = 10000;
private String uid;
* @param value the minimum value
*/
public void setMinimumValue(double value) {
- updateModel();
+ updateModel(); /* Update the model according to the knob position */
}
/**
* @param value the maximum value
*/
public void setMaximumValue(double value) {
- updateModel();
+ updateModel(); /* Update the model according to the knob position */
}
/**
/* Remove the listener to avoid the callback to be executed */
removeAdjustmentListener(adjustmentListener);
- setBlockIncrement((int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE)));
+ double userMin = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MIN__);
+ double userMax = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MAX__);
+ setBlockIncrement((int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
int oldMax = getMaximum() - getVisibleAmount();
- setVisibleAmount(Math.max((int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE)), MIN_KNOB_SIZE));
+ setVisibleAmount(Math.max((int) ((MAXIMUM_VALUE - MINIMUM_VALUE) / space), MIN_KNOB_SIZE));
setMaximum(oldMax + getVisibleAmount());
/* Put back the listener */
/* Remove the listener to avoid the callback to be executed */
removeAdjustmentListener(adjustmentListener);
- setUnitIncrement((int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE)));
+ double userMin = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MIN__);
+ double userMax = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MAX__);
+ setUnitIncrement((int) (space * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
/* Put back the listener */
addAdjustmentListener(adjustmentListener);
* @param value the new value
*/
public void setUserValue(double value) {
- /* Remove the listener to avoid the callback to be executed */
- removeAdjustmentListener(adjustmentListener);
+ if (!SwingUtilities.isEventDispatchThread()) { /* Avoid double-update when Model is updated from the callback */
+ /* Remove the listener to avoid the callback to be executed */
+ removeAdjustmentListener(adjustmentListener);
- double userMin = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MIN__);
- double userMax = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MAX__);
- super.setValue(MINIMUM_VALUE + (int) ((value - userMin) * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
+ double userMin = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MIN__);
+ double userMax = (Double) GraphicController.getController().getProperty(uid, __GO_UI_MAX__);
+ super.setValue(MINIMUM_VALUE + (int) ((value - userMin) * (MAXIMUM_VALUE - MINIMUM_VALUE) / (userMax - userMin)));
- /* Put back the listener */
- addAdjustmentListener(adjustmentListener);
+ /* Put back the listener */
+ addAdjustmentListener(adjustmentListener);
+ }
}
/**