forked from fanruan/demo-tabledata-redis
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.8 KiB
114 lines
2.8 KiB
package com.fr.plugin.db.redis.ui.value; |
|
|
|
import com.fr.base.Utils; |
|
import com.fr.design.editor.editor.Editor; |
|
import com.fr.design.gui.itextfield.UIIntNumberField; |
|
import com.fr.design.gui.itextfield.UITextField; |
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
import com.fr.plugin.db.redis.core.order.impl.NumberOrderValue; |
|
import com.fr.stable.StringUtils; |
|
|
|
import java.awt.*; |
|
import java.awt.event.KeyAdapter; |
|
import java.awt.event.KeyEvent; |
|
import java.awt.event.KeyListener; |
|
|
|
|
|
|
|
public class IntegerEditor extends Editor<NumberOrderValue> { |
|
private static final long serialVersionUID = 1L; |
|
protected UIIntNumberField numberField; // text field. |
|
|
|
protected String oldValue = StringUtils.EMPTY; |
|
|
|
/** |
|
* Constructor. |
|
*/ |
|
public IntegerEditor() { |
|
this(null, "序号"); |
|
} |
|
|
|
/** |
|
* Constructor. |
|
*/ |
|
public IntegerEditor(NumberOrderValue value, String name) { |
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
numberField = new UIIntNumberField(); |
|
this.add(numberField, BorderLayout.CENTER); |
|
this.numberField.addKeyListener(textKeyListener); |
|
this.numberField.setHorizontalAlignment(UITextField.RIGHT); |
|
this.setValue(value); |
|
this.setName(name); |
|
} |
|
|
|
|
|
public void setColumns(int columns) { |
|
this.numberField.setColumns(columns); |
|
} |
|
|
|
|
|
public int getHorizontalAlignment() { |
|
return this.numberField.getHorizontalAlignment(); |
|
} |
|
|
|
|
|
public void setHorizontalAlignment(int horizontalAlignment) { |
|
this.numberField.setHorizontalAlignment(horizontalAlignment); |
|
} |
|
|
|
|
|
public void setEnabled(boolean enabled) { |
|
this.numberField.setEnabled(enabled); |
|
} |
|
|
|
public void selected() { |
|
this.requestFocus(); |
|
} |
|
|
|
public String getIconName() { |
|
return "type_double"; |
|
} |
|
|
|
|
|
public void requestFocus() { |
|
this.numberField.requestFocus(); |
|
} |
|
|
|
KeyListener textKeyListener = new KeyAdapter() { |
|
|
|
public void keyReleased(KeyEvent evt) { |
|
int code = evt.getKeyCode(); |
|
|
|
if (code == KeyEvent.VK_ESCAPE) { |
|
numberField.setText(oldValue); |
|
} |
|
if (code == KeyEvent.VK_ENTER) { |
|
fireEditingStopped(); |
|
} else { |
|
fireStateChanged(); |
|
} |
|
} |
|
}; |
|
|
|
@Override |
|
public NumberOrderValue getValue() { |
|
return new NumberOrderValue((int)this.numberField.getValue()); |
|
} |
|
|
|
@Override |
|
public void setValue(NumberOrderValue value) { |
|
if (value == null) { |
|
value = new NumberOrderValue(0); |
|
} |
|
this.numberField.setValue(value.getValue()); |
|
oldValue = Utils.objectToString(value); |
|
} |
|
|
|
|
|
|
|
@Override |
|
public boolean accept(Object object) { |
|
return object != null && object instanceof NumberOrderValue; |
|
} |
|
|
|
} |