📄 shortintegerfieldeditor.java
字号:
/*******************************************************************************
* Copyright (c) 2003 Berthold Daum. All rights reserved. This program and the
* accompanying materials are made available under the terms of the Common
* Public License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors: Berthold Daum
******************************************************************************/
package com.bdaum.SpellChecker.preferences;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
public class ShortIntegerFieldEditor extends StringFieldEditor {
private int minValidValue = 0;
private int maxValidValue = Integer.MAX_VALUE;
/**
* Default constructor.
*/
public ShortIntegerFieldEditor() {
super();
}
/**
* Qualified constructor.
*
* @param name -
* preference key
* @param labelText -
* label text string
* @param parent -
* parent composite
* @param textLimit -
* maximum text width
*/
public ShortIntegerFieldEditor(String name, String labelText,
Composite parent, int width) {
super(name, labelText, width, parent);
setTextLimit(width);
setEmptyStringAllowed(false);
setErrorMessage(JFaceResources
.getString("IntegerFieldEditor.errorMessage"));
}
/**
* Sets the range of valid values for this field.
*
* @param min -
* he minimum allowed value (inclusive)
* @param max -
* the maximum allowed value (inclusive)
*/
public void setValidRange(int min, int max) {
minValidValue = min;
maxValidValue = max;
}
/**
* Checks for valid field content
*
* @return - true if valid
*/
protected boolean checkState() {
Text text = getTextControl();
if (text == null)
return false;
String numberString = text.getText();
try {
int number = Integer.valueOf(numberString).intValue();
if (number >= minValidValue && number <= maxValidValue) {
clearErrorMessage();
return true;
}
} catch (NumberFormatException e1) {
}
showErrorMessage();
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -