GenericIntParameterpublic class GenericIntParameter extends Object
Fields Summary |
---|
private static boolean | DEBUG | private GenericParameterAdapter | adapter | private int | iMinValue | private int | iMaxValue | private int | iDefaultValue | private String | sParamName | private boolean | bGenerateIntermediateEvents | private boolean | bTriggerOnFocusOut | private Spinner | spinner | private TimerEvent | timedSaveEvent | private TimerEventPerformer | timerEventSave |
Constructors Summary |
---|
public GenericIntParameter(GenericParameterAdapter adapter, Composite composite, String name)
iDefaultValue = adapter.getIntValue(name);
initialize(adapter, composite, name);
| public GenericIntParameter(GenericParameterAdapter adapter, Composite composite, String name, int defaultValue)
iDefaultValue = defaultValue;
initialize(adapter, composite, name);
| public GenericIntParameter(GenericParameterAdapter adapter, Composite composite, String name, int minValue, int maxValue)
iDefaultValue = adapter.getIntValue(name);
iMinValue = minValue;
iMaxValue = maxValue;
initialize(adapter, composite, name);
|
Methods Summary |
---|
private void | cancelTimedSaveEvent()
if (timedSaveEvent != null
&& (!timedSaveEvent.hasRun() || !timedSaveEvent.isCancelled())) {
if (DEBUG) {
debug("cancel timeSaveEvent");
}
timedSaveEvent.cancel();
}
| private void | debug(java.lang.String string)
System.out.println("[GenericIntParameter:" + sParamName + "] " + string);
| public Control | getControl()
return spinner;
| public java.lang.String | getName()
return (sParamName);
| public int | getValue()
return (adapter.getIntValue(sParamName, iDefaultValue));
| public void | initialize(GenericParameterAdapter _adapter, Composite composite, java.lang.String name)
adapter = _adapter;
sParamName = name;
timerEventSave = new TimerEventPerformer() {
public void perform(TimerEvent event) {
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (spinner.isDisposed()) {
return;
}
if (DEBUG) {
debug("setIntValue to " + spinner.getSelection()
+ " via timeEventSave");
}
adapter.setIntValue(sParamName, spinner.getSelection());
}
});
}
};
int value = adapter.getIntValue(name, iDefaultValue);
spinner = new Spinner(composite, SWT.BORDER);
setMinimumValue(iMinValue);
setMaximumValue(iMaxValue);
spinner.setSelection(value);
spinner.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (bGenerateIntermediateEvents || !spinner.isFocusControl()) {
adapter.setIntValue(sParamName, spinner.getSelection());
} else {
bTriggerOnFocusOut = true;
cancelTimedSaveEvent();
if (DEBUG) {
debug("create timeSaveEvent (" + spinner.getSelection() + ") ");
}
timedSaveEvent = SimpleTimer.addEvent("IntParam Saver",
SystemTime.getOffsetTime(750), timerEventSave);
}
}
});
/*
* Primarily for OSX, since it doesn't validate or trigger selection
* while typing numbers.
*
* Force into next tab, which will result in a selection
*/
spinner.addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event event) {
if (spinner.isFocusControl()) {
if (DEBUG) {
debug("next");
}
spinner.traverse(SWT.TRAVERSE_TAB_NEXT);
}
}
});
spinner.addListener(SWT.FocusOut, new Listener() {
public void handleEvent(Event event) {
if (bTriggerOnFocusOut) {
if (DEBUG) {
debug("focus out setIntValue(" + spinner.getSelection()
+ "/trigger");
}
cancelTimedSaveEvent();
adapter.setIntValue(sParamName, spinner.getSelection());
}
}
});
| public boolean | isGeneratingIntermediateEvents()
return bGenerateIntermediateEvents;
| public void | resetToDefault()
if (adapter.resetIntDefault(sParamName)) {
setValue(adapter.getIntValue(sParamName));
} else {
setValue(getValue());
}
| public void | setGenerateIntermediateEvents(boolean generateIntermediateEvents)
bGenerateIntermediateEvents = generateIntermediateEvents;
| public void | setLayoutData(java.lang.Object layoutData)
spinner.setLayoutData(layoutData);
| public void | setMaximumValue(int value)
iMaxValue = value;
if (iMaxValue != -1 && getValue() > iMaxValue) {
setValue(iMaxValue);
}
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
spinner.setMaximum(iMaxValue == -1 ? Integer.MAX_VALUE : iMaxValue);
}
});
| public void | setMinimumValue(int value)
iMinValue = value;
if (iMinValue > 0 && getValue() < iMinValue) {
setValue(iMinValue);
}
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
spinner.setMinimum(value);
}
});
| public void | setValue(int value)
int newValue;
if (iMaxValue != -1 && value > iMaxValue) {
newValue = iMaxValue;
} else if (iMinValue > 0 && value < iMinValue) {
newValue = iMinValue;
} else {
newValue = value;
}
final int finalNewValue = newValue;
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (!spinner.isDisposed()) {
if (spinner.getSelection() != finalNewValue) {
if (DEBUG) {
debug("spinner.setSelection(" + finalNewValue + ")");
}
spinner.setSelection(finalNewValue);
}
if (DEBUG) {
debug("setIntValue to " + spinner.getSelection()
+ " via setValue(int)");
}
}
}
});
if (finalNewValue != getValue()) {
adapter.setIntValue(sParamName, finalNewValue);
}
| public void | setValue(int value, boolean force_adapter_set)
if (force_adapter_set) {
setValue(value);
} else {
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (spinner.getSelection() != value) {
spinner.setSelection(value);
}
}
});
}
|
|