Browse Source
Merge in DESIGN/design from ~RENEKTON/design:fbp/release to fbp/release * commit 'ce1eddb869c50da1e6f7469db31a7d3a8184b5a8': 行式放一行 去除包名 去除包名 去掉包名 修改注释 当button点击时不转换成字母 基于UISpinner新增字母spinnerfbp/release
Renekton-张世豪
2 months ago
5 changed files with 211 additions and 113 deletions
@ -0,0 +1,152 @@
|
||||
package com.fr.design.gui.ispinner; |
||||
|
||||
import com.fine.theme.utils.FineUIUtils; |
||||
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.event.DocumentEvent; |
||||
import javax.swing.event.DocumentListener; |
||||
import javax.swing.text.AbstractDocument; |
||||
import javax.swing.text.AttributeSet; |
||||
import javax.swing.text.BadLocationException; |
||||
import javax.swing.text.DocumentFilter; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Insets; |
||||
import java.awt.event.FocusAdapter; |
||||
import java.awt.event.FocusEvent; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
/** |
||||
* 字母spinner |
||||
* |
||||
* @author Renekton |
||||
* @since 11.0 |
||||
* @Created on 2024/09/11 |
||||
*/ |
||||
public class FineUpperCaseSpinner extends UISpinner { |
||||
|
||||
private UITextField textField; |
||||
|
||||
public FineUpperCaseSpinner(double minValue, double maxValue, double dierta) { |
||||
super(minValue, maxValue, dierta); |
||||
} |
||||
|
||||
protected void initComponents() { |
||||
setLayout(new BorderLayout()); |
||||
textField = initTextField(); |
||||
Insets insets = FineUIUtils.getUIInsets("InputTextField.borderInsets", defaultInsets); |
||||
textField.setBorder(new ScaledEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)); |
||||
textField.setOpaque(false); |
||||
add(textField, BorderLayout.CENTER); |
||||
setValue(value); |
||||
|
||||
initArrowPane(); |
||||
componentInitListeners(); |
||||
} |
||||
|
||||
protected void setTextField(double value) { |
||||
textField.getDocument().removeDocumentListener(docListener); |
||||
textField.setText(StableUtils.convertIntToABC((int)value).toUpperCase()); |
||||
textField.getDocument().addDocumentListener(docListener); |
||||
} |
||||
|
||||
|
||||
protected UITextField initTextField() { |
||||
int columns = this.numberFieldColumns == 0 ? DEFAULT_NUMBERFIELD_COLUMNS : this.numberFieldColumns; |
||||
UITextField textField = new UITextField(columns) { |
||||
public boolean shouldResponseChangeListener() { |
||||
return false; |
||||
} |
||||
}; |
||||
((AbstractDocument) textField.getDocument()).setDocumentFilter(new DocumentFilter() { |
||||
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { |
||||
fb.insertString(offset, string.toUpperCase(), attr); |
||||
} |
||||
|
||||
public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr) throws BadLocationException { |
||||
if (string != null) { |
||||
string = string.toUpperCase(); |
||||
} |
||||
fb.replace(offset, length, string, attr); |
||||
} |
||||
}); |
||||
return textField; |
||||
} |
||||
|
||||
protected DocumentListener docListener = new DocumentListener() { |
||||
@Override |
||||
public void removeUpdate(DocumentEvent e) { |
||||
setTextFieldValue(getTextValue()); |
||||
} |
||||
|
||||
@Override |
||||
public void insertUpdate(DocumentEvent e) { |
||||
setTextFieldValue(getTextValue()); |
||||
} |
||||
|
||||
@Override |
||||
public void changedUpdate(DocumentEvent e) { |
||||
setTextFieldValue(getTextValue()); |
||||
} |
||||
}; |
||||
|
||||
|
||||
protected void initTextFiledListeners() { |
||||
textField.getDocument().removeDocumentListener(docListener); |
||||
textField.getDocument().addDocumentListener(docListener); |
||||
textField.addFocusListener(new FocusAdapter() { |
||||
@Override |
||||
public void focusGained(FocusEvent e) { |
||||
textFieldFocus = true; |
||||
} |
||||
|
||||
@Override |
||||
public void focusLost(FocusEvent e) { |
||||
textFieldFocus = false; |
||||
textField.getDocument().removeDocumentListener(docListener); |
||||
if (!preAction && !nextAction) { |
||||
textField.setText(StableUtils.convertIntToABC((int)value).toUpperCase()); |
||||
} |
||||
textField.getDocument().addDocumentListener(docListener); |
||||
preAction = false; |
||||
nextAction = false; |
||||
} |
||||
}); |
||||
} |
||||
|
||||
protected void initTextMouseListener() { |
||||
textField.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseEntered(MouseEvent e) { |
||||
hover = true; |
||||
repaint(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseExited(MouseEvent e) { |
||||
hover = false; |
||||
repaint(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public UITextField getTextFieldNew() { |
||||
return textField; |
||||
} |
||||
|
||||
private double getTextValue() { |
||||
try { |
||||
if (StringUtils.isEmpty(textField.getText())) { |
||||
return 1; |
||||
} else if (StringUtils.isNumber(textField.getText())) { |
||||
return Double.parseDouble(textField.getText()); |
||||
} |
||||
return StableUtils.convertABCToInt(textField.getText()); |
||||
} catch (NumberFormatException numberFormatException) { |
||||
return 1; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue