Browse Source

format

master
hzzz 7 years ago
parent
commit
e2ad022e9c
  1. 37
      designer_base/src/com/fr/design/gui/ispinner/UISpinner.java
  2. 26
      designer_base/src/com/fr/design/gui/itextfield/UINumberField.java

37
designer_base/src/com/fr/design/gui/ispinner/UISpinner.java

@ -1,17 +1,5 @@
package com.fr.design.gui.ispinner;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.RoundRectangle2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.JTextComponent;
import com.fr.design.constants.UIConstants;
import com.fr.design.event.GlobalNameListener;
import com.fr.design.event.GlobalNameObserver;
@ -21,9 +9,19 @@ import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.itextfield.UINumberField;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.gui.itextfield.UITextFieldUI;
import com.fr.stable.Constants;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.stable.Constants;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.RoundRectangle2D;
public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver {
@ -70,6 +68,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
/**
* 给组件分别加上FocusListener
*
* @param focusListener 监听事件
*/
public void addUISpinnerFocusListenner(FocusListener focusListener) {
@ -139,7 +138,8 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
}
/**
*增加 a <code>ChangeListener</code> to the listener list.
* 增加 a <code>ChangeListener</code> to the listener list.
*
* @param l 监听事件
*/
public void addChangeListener(ChangeListener l) {
@ -147,7 +147,8 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
}
/**
*移除 a <code>ChangeListener</code> from the listener list.
* 移除 a <code>ChangeListener</code> from the listener list.
*
* @param l 监听事件
*/
public void removeChangeListener(ChangeListener l) {
@ -172,7 +173,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
textField.setMinValue(minValue);
setValue(value);
textField.setUI(new SpinnerTextFieldUI(textField));
preButton = new UIButton(UIConstants.ARROW_UP_ICON){
preButton = new UIButton(UIConstants.ARROW_UP_ICON) {
public boolean shouldResponseChangeListener() {
return false;
}
@ -197,7 +198,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
componentInitListeners();
}
private void componentInitListeners(){
private void componentInitListeners() {
preButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -256,6 +257,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
/**
* 给组件登记一个观察者监听事件
*
* @param listener 观察者监听事件
*/
public void registerChangeListener(UIObserverListener listener) {
@ -331,6 +333,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
/**
* 程序入口 测试
*
* @param args 参数
*/
public static void main(String... args) {

26
designer_base/src/com/fr/design/gui/itextfield/UINumberField.java

@ -54,7 +54,7 @@ public class UINumberField extends UITextField {
setFieldDocument();
}
public void setFieldDocument(){
public void setFieldDocument() {
setDocument(new NumberDocument());
initListener();
}
@ -123,8 +123,7 @@ public class UINumberField extends UITextField {
/**
* Set property integer.
*
* @param integer
* New value of property integer.
* @param integer New value of property integer.
*/
public void setInteger(boolean integer) {
if (integer) {
@ -141,7 +140,7 @@ public class UINumberField extends UITextField {
return isContentChanged;
}
public void setisContentChanged(boolean isContentChanged){
public void setisContentChanged(boolean isContentChanged) {
this.isContentChanged = isContentChanged;
}
@ -153,13 +152,14 @@ public class UINumberField extends UITextField {
class NumberDocument extends PlainDocument {
public NumberDocument() {
}
public boolean checkString(int offset, String s, String str) {
return (ComparatorUtils.equals(s,"F")
|| ComparatorUtils.equals(s,"f")
|| ComparatorUtils.equals(s,"D")
|| ComparatorUtils.equals(s,"d")
||(ComparatorUtils.equals(str.trim(),"0") && !ComparatorUtils.equals(s.substring(0, 1),".") && offset != 0)// 第一位是0时,第二位只能为小数点
||(ComparatorUtils.equals(s,".") && maxDecimalLength == 0));
return (ComparatorUtils.equals(s, "F")
|| ComparatorUtils.equals(s, "f")
|| ComparatorUtils.equals(s, "D")
|| ComparatorUtils.equals(s, "d")
|| (ComparatorUtils.equals(str.trim(), "0") && !ComparatorUtils.equals(s.substring(0, 1), ".") && offset != 0)// 第一位是0时,第二位只能为小数点
|| (ComparatorUtils.equals(s, ".") && maxDecimalLength == 0));
}
@ -167,13 +167,13 @@ public class UINumberField extends UITextField {
String str = getText(0, getLength());
// 不能为f,F,d,D
if (checkString(offset,s, str) ) {
if (checkString(offset, s, str)) {
Toolkit.getDefaultToolkit().beep();
return;
}
String strNew = str.substring(0, offset) + s + str.substring(offset, getLength());
if(notChange(strNew)) {
if (notChange(strNew)) {
return;
}
setisContentChanged(true);
@ -218,7 +218,7 @@ public class UINumberField extends UITextField {
private boolean isOverMaxOrMinValue(String strIntPart, String strDecPart, String strNew) {
return strIntPart.length() > maxIntegerLength
|| strDecPart.length() > maxDecimalLength
|| (strNew.length() > 1 && ComparatorUtils.equals(strNew.substring(0, 1), "0") && !ComparatorUtils.equals(strNew.substring(1, 2),"."));
|| (strNew.length() > 1 && ComparatorUtils.equals(strNew.substring(0, 1), "0") && !ComparatorUtils.equals(strNew.substring(1, 2), "."));
}
}

Loading…
Cancel
Save