|
|
|
@ -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; |
|
|
|
@ -19,24 +7,32 @@ import com.fr.design.event.UIObserver;
|
|
|
|
|
import com.fr.design.event.UIObserverListener; |
|
|
|
|
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 com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
|
import javax.swing.event.DocumentEvent; |
|
|
|
|
import javax.swing.event.DocumentListener; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.awt.event.*; |
|
|
|
|
|
|
|
|
|
public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver { |
|
|
|
|
|
|
|
|
|
protected double value; |
|
|
|
|
private static final int SIZE = 20; |
|
|
|
|
private static final int LEN = 13; |
|
|
|
|
private static final int WIDTH = 13; |
|
|
|
|
private static final int HEIGHT = 10; |
|
|
|
|
private UINumberField textField; |
|
|
|
|
private UIButton preButton; |
|
|
|
|
private UIButton nextButton; |
|
|
|
|
private double minValue; |
|
|
|
|
private double maxValue; |
|
|
|
|
private double dierta; |
|
|
|
|
private String spinnerName = ""; |
|
|
|
|
private String spinnerName = StringUtils.EMPTY; |
|
|
|
|
private UIObserverListener uiObserverListener; |
|
|
|
|
private GlobalNameListener globalNameListener = null; |
|
|
|
|
|
|
|
|
@ -70,6 +66,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 给组件分别加上FocusListener |
|
|
|
|
* |
|
|
|
|
* @param focusListener 监听事件 |
|
|
|
|
*/ |
|
|
|
|
public void addUISpinnerFocusListenner(FocusListener focusListener) { |
|
|
|
@ -139,7 +136,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 +145,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) { |
|
|
|
@ -171,8 +170,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
|
|
|
|
|
textField.setMaxValue(maxValue); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
@ -189,15 +187,15 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
|
|
|
|
|
JPanel arrowPane = new JPanel(); |
|
|
|
|
arrowPane.setPreferredSize(new Dimension(LEN, SIZE)); |
|
|
|
|
arrowPane.setLayout(new GridLayout(2, 1)); |
|
|
|
|
preButton.setBounds(0, 1, 13, 10); |
|
|
|
|
nextButton.setBounds(0, 10, 13, 10); |
|
|
|
|
preButton.setBounds(0, 1, WIDTH, HEIGHT); |
|
|
|
|
nextButton.setBounds(0, HEIGHT, WIDTH, HEIGHT); |
|
|
|
|
arrowPane.add(preButton); |
|
|
|
|
arrowPane.add(nextButton); |
|
|
|
|
add(arrowPane, BorderLayout.EAST); |
|
|
|
|
componentInitListeners(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void componentInitListeners(){ |
|
|
|
|
private void componentInitListeners() { |
|
|
|
|
preButton.addActionListener(new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
@ -256,6 +254,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 给组件登记一个观察者监听事件 |
|
|
|
|
* |
|
|
|
|
* @param listener 观察者监听事件 |
|
|
|
|
*/ |
|
|
|
|
public void registerChangeListener(UIObserverListener listener) { |
|
|
|
@ -289,63 +288,24 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private class SpinnerTextFieldUI extends UITextFieldUI { |
|
|
|
|
|
|
|
|
|
public SpinnerTextFieldUI(UITextField textField) { |
|
|
|
|
super(textField); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void paintBorder(Graphics2D g2d, int width, int height, |
|
|
|
|
boolean isRound, int rectDirection) { |
|
|
|
|
// do nothing
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void paintBackground(Graphics g) { |
|
|
|
|
JTextComponent editor = getComponent(); |
|
|
|
|
int width = editor.getWidth(); |
|
|
|
|
int height = editor.getHeight(); |
|
|
|
|
Shape oldClip = g.getClip(); |
|
|
|
|
Shape roundShape = new RoundRectangle2D.Double(0, 0, width, height, UIConstants.ARC, UIConstants.ARC); |
|
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
|
g2d.clearRect(0, 0, width, height); |
|
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
|
|
|
|
g2d.clip(roundShape); |
|
|
|
|
g2d.setColor(Color.WHITE); |
|
|
|
|
g2d.fillRoundRect(1, 1, width - 2, height - 2, UIConstants.ARC, UIConstants.ARC); |
|
|
|
|
if (isRollOver && isEnabled()) { |
|
|
|
|
Shape shape = new RoundRectangle2D.Double(1, 1, width - 3, height - 3, UIConstants.ARC, UIConstants.ARC); |
|
|
|
|
GUIPaintUtils.paintBorderShadow(g2d, 3, shape, UIConstants.HOVER_BLUE, Color.WHITE); |
|
|
|
|
} else { |
|
|
|
|
g2d.setColor(UIConstants.LINE_COLOR); |
|
|
|
|
g2d.drawRoundRect(1, 1, width - 2, height - 2, UIConstants.ARC, UIConstants.ARC); |
|
|
|
|
g2d.clearRect(width - 2, 0, 2, height); |
|
|
|
|
g2d.setClip(oldClip); |
|
|
|
|
g2d.drawLine(width - 2, 1, width, 1); |
|
|
|
|
g2d.drawLine(width - 2, height - 1, width, height - 1); |
|
|
|
|
} |
|
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 程序入口 测试 |
|
|
|
|
* |
|
|
|
|
* @param args 参数 |
|
|
|
|
*/ |
|
|
|
|
public static void main(String... args) { |
|
|
|
|
LayoutManager layoutManager = null; |
|
|
|
|
JFrame jf = new JFrame("test"); |
|
|
|
|
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
|
JPanel content = (JPanel) jf.getContentPane(); |
|
|
|
|
content.setLayout(layoutManager); |
|
|
|
|
|
|
|
|
|
UISpinner bb = new UISpinner(0, 9, 1); |
|
|
|
|
bb.setValue(4); |
|
|
|
|
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height); |
|
|
|
|
content.add(bb); |
|
|
|
|
GUICoreUtils.centerWindow(jf); |
|
|
|
|
jf.setSize(400, 400); |
|
|
|
|
jf.setVisible(true); |
|
|
|
|
// LayoutManager layoutManager = null;
|
|
|
|
|
// JFrame jf = new JFrame("test");
|
|
|
|
|
// jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
// JPanel content = (JPanel) jf.getContentPane();
|
|
|
|
|
// content.setLayout(layoutManager);
|
|
|
|
|
//
|
|
|
|
|
// UISpinner bb = new UISpinner(0, 9, 1);
|
|
|
|
|
// bb.setValue(4);
|
|
|
|
|
// bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height);
|
|
|
|
|
// content.add(bb);
|
|
|
|
|
// GUICoreUtils.centerWindow(jf);
|
|
|
|
|
// jf.setSize(400, 400);
|
|
|
|
|
// jf.setVisible(true);
|
|
|
|
|
} |
|
|
|
|
} |