Browse Source

基于UISpinner新增字母spinner

fbp/release
renekton 3 months ago
parent
commit
2dc17259e7
  1. 101
      designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java
  2. 150
      designer-base/src/main/java/com/fr/design/gui/ispinner/FineUpperCaseSpinner.java
  3. 63
      designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java
  4. 1
      designer-base/src/main/java/com/fr/design/write/submit/CustomJobPane.java
  5. 2
      designer-realize/src/main/java/com/fr/design/write/submit/SubmitVisitorListPane.java

101
designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java

@ -1,32 +1,22 @@
package com.fr.design.gui.columnrow; package com.fr.design.gui.columnrow;
import com.fine.theme.utils.FineUIUtils;
import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener; import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ispinner.ColumnRowSpinner; import com.fr.design.gui.ispinner.FineUpperCaseSpinner;
import com.fr.design.gui.ispinner.UIBasicSpinner; import com.fr.design.gui.ispinner.UISpinner;
import com.fr.design.gui.ispinner.UpperCaseSpinner;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.stable.ColumnRow; import com.fr.stable.ColumnRow;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import javax.swing.JFormattedTextField;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SpinnerListModel;
import javax.swing.JSpinner.DefaultEditor;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; 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.BorderLayout;
import java.awt.Dimension;
import static com.fine.swing.ui.layout.Layouts.cell; import static com.fine.swing.ui.layout.Layouts.cell;
import static com.fine.swing.ui.layout.Layouts.fix; import static com.fine.swing.ui.layout.Layouts.fix;
@ -40,29 +30,17 @@ import static com.fine.swing.ui.layout.Layouts.row;
public class ColumnRowPane extends JPanel implements UIObserver { public class ColumnRowPane extends JPanel implements UIObserver {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static String[] columnarray = new String[1000];
private static String[] rowarray = new String[5000];
protected FineUpperCaseSpinner columnSpinner;
protected UpperCaseSpinner columnSpinner; protected UISpinner rowSpinner;
protected UIBasicSpinner rowSpinner;
static {
for (int i = 1; i <= 1000; i++) {
columnarray[i - 1] = StableUtils.convertIntToABC(i);
}
for (int i = 1; i <= 5000; i++) {
rowarray[i - 1] = StringUtils.EMPTY + i;
}
}
protected DocumentListener d = new DocumentListener() { protected DocumentListener d = new DocumentListener() {
@Override @Override
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
String rolText = ((DefaultEditor) columnSpinner.getEditor()).getTextField().getText(); String rolText = columnSpinner.getTextFieldNew().getText();
String rowText = ((DefaultEditor) rowSpinner.getEditor()).getTextField().getText(); String rowText = rowSpinner.getTextField().getText();
if (rolText == null || rolText.length() == 0 || rowText == null || rowText.length() == 0) { if (rolText == null || rolText.length() == 0 || rowText == null || rowText.length() == 0) {
return; return;
} }
@ -73,8 +51,8 @@ public class ColumnRowPane extends JPanel implements UIObserver {
@Override @Override
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
int col = StableUtils.convertABCToInt(((DefaultEditor) columnSpinner.getEditor()).getTextField().getText()) - 1; int col = StableUtils.convertABCToInt(columnSpinner.getTextFieldNew().getText()) - 1;
int row = Integer.parseInt(((DefaultEditor) rowSpinner.getEditor()).getTextField().getText()) - 1; int row = Integer.parseInt(rowSpinner.getTextField().getText()) - 1;
setColumnRow(ColumnRow.valueOf(col, row)); setColumnRow(ColumnRow.valueOf(col, row));
} }
@ -128,58 +106,21 @@ public class ColumnRowPane extends JPanel implements UIObserver {
protected void initRowSpinner() { protected void initRowSpinner() {
rowSpinner = new ColumnRowSpinner((new SpinnerListModel(rowarray))) { rowSpinner = new UISpinner(1, 5000, 1);
public boolean shouldResponseChangeListener() {
return false;
}
};
rowSpinner.setBackground(FineUIUtils.getUIColor("background.normal", "background.normal"));
JFormattedTextField rftf = GUICoreUtils.getSpinnerTextField(rowSpinner);
if (rftf != null) {
rftf.setColumns(4); // specify more width than we need
rftf.setHorizontalAlignment(UITextField.LEFT);
}
} }
protected void initColSpinner() { protected void initColSpinner() {
SpinnerListModel columnSpinnerListModel = new SpinnerListModel(columnarray); columnSpinner = new FineUpperCaseSpinner(1, 5000, 1);
columnSpinner = new UpperCaseSpinner(columnSpinnerListModel) {
public boolean shouldResponseChangeListener() {
return false;
}
};
columnSpinner.setBackground(FineUIUtils.getUIColor("background.normal", "background.normal"));
JFormattedTextField cftf = GUICoreUtils.getSpinnerTextField(columnSpinner);
if (cftf != null) {
cftf.setColumns(3); // specify more width than we need
cftf.setHorizontalAlignment(UITextField.LEFT);
}else {
throw new IllegalArgumentException("Spinner'Editor can not be null!");
}
((AbstractDocument) cftf.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);
}
});
} }
protected void addDocumentListener(DocumentListener l) { protected void addDocumentListener(DocumentListener l) {
((DefaultEditor) columnSpinner.getEditor()).getTextField().getDocument().addDocumentListener(l); columnSpinner.getTextFieldNew().getDocument().addDocumentListener(l);
((DefaultEditor) rowSpinner.getEditor()).getTextField().getDocument().addDocumentListener(l); rowSpinner.getTextField().getDocument().addDocumentListener(l);
} }
private void removeDocumentListener(DocumentListener l) { private void removeDocumentListener(DocumentListener l) {
((DefaultEditor) columnSpinner.getEditor()).getTextField().getDocument().removeDocumentListener(l); columnSpinner.getTextFieldNew().getDocument().removeDocumentListener(l);
((DefaultEditor) rowSpinner.getEditor()).getTextField().getDocument().removeDocumentListener(l); rowSpinner.getTextField().getDocument().removeDocumentListener(l);
} }
/** /**
@ -208,17 +149,13 @@ public class ColumnRowPane extends JPanel implements UIObserver {
column = 0; column = 0;
} }
removeDocumentListener(d); removeDocumentListener(d);
String colValue = StableUtils.convertIntToABC(column + 1); columnSpinner.setValue(column+1);
columnSpinner.setValue(colValue);
((DefaultEditor) columnSpinner.getEditor()).getTextField().setText(colValue);
int row = columnRow.getRow(); int row = columnRow.getRow();
// shoc 小于0就蹦了 // shoc 小于0就蹦了
if (row < 0) { if (row < 0) {
row = 0; row = 0;
} }
String rowValue = Integer.toString(row + 1); rowSpinner.setValue(row+1);
rowSpinner.setValue(rowValue);
((DefaultEditor) rowSpinner.getEditor()).getTextField().setText(rowValue);
addDocumentListener(d); addDocumentListener(d);
fireChanged(); fireChanged();
} }

150
designer-base/src/main/java/com/fr/design/gui/ispinner/FineUpperCaseSpinner.java

@ -0,0 +1,150 @@
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
* @Cteated 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);
}
});
}
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;
}
}
}

63
designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java

@ -13,7 +13,6 @@ import com.fr.design.gui.itextfield.UINumberField;
import com.fr.stable.CommonUtils; import com.fr.stable.CommonUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
@ -46,11 +45,11 @@ import static com.fine.theme.utils.FineUIStyle.setStyle;
*/ */
public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, HoverAware { public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, HoverAware {
private final Insets defaultInsets = new Insets(0, 6, 0, 6); protected final Insets defaultInsets = new Insets(0, 6, 0, 6);
private final int defaultButtonSize = 24; private final int defaultButtonSize = 24;
private final int ICON_WIDTH = 12; private final int ICON_WIDTH = 12;
protected double value; protected double value;
private static final int DEFAULT_NUMBERFIELD_COLUMNS = 2; protected static final int DEFAULT_NUMBERFIELD_COLUMNS = 2;
private UINumberField textField; private UINumberField textField;
private UIButton preButton; private UIButton preButton;
private UIButton nextButton; private UIButton nextButton;
@ -64,10 +63,14 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver,
/** /**
* Spinner内的数字文本框长度 * Spinner内的数字文本框长度
*/ */
private int numberFieldColumns; protected int numberFieldColumns;
private boolean textFieldFocus = false; protected boolean textFieldFocus = false;
private boolean hover; protected boolean hover;
protected boolean preAction;
protected boolean nextAction;
private static final String UI_CLASS_ID = "InputUI"; private static final String UI_CLASS_ID = "InputUI";
@ -116,6 +119,11 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver,
}); });
} }
initTextMouseListener();
}
protected void initTextMouseListener() {
textField.addMouseListener(new MouseAdapter() { textField.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
@ -129,7 +137,6 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver,
repaint(); repaint();
} }
}); });
} }
/** /**
@ -281,19 +288,24 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver,
return hover; return hover;
} }
private void initComponents() { protected void initComponents() {
setLayout(new BorderLayout());
textField = initNumberField(); textField = initNumberField();
textField.setMaxValue(maxValue); textField.setMaxValue(maxValue);
textField.setMinValue(minValue); textField.setMinValue(minValue);
Insets insets = FineUIUtils.getUIInsets("InputTextField.borderInsets", defaultInsets); Insets insets = FineUIUtils.getUIInsets("InputTextField.borderInsets", defaultInsets);
textField.setBorder(new ScaledEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)); textField.setBorder(new ScaledEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
textField.setOpaque(false); textField.setOpaque(false);
add(textField, BorderLayout.CENTER);
setValue(value); setValue(value);
initArrowPane();
componentInitListeners();
}
protected void initArrowPane() {
preButton = createArrowButton(new LazyIcon("up_arrow", ICON_WIDTH)); preButton = createArrowButton(new LazyIcon("up_arrow", ICON_WIDTH));
nextButton = createArrowButton(new LazyIcon("down_arrow", ICON_WIDTH)); nextButton = createArrowButton(new LazyIcon("down_arrow", ICON_WIDTH));
setLayout(new BorderLayout());
add(textField, BorderLayout.CENTER);
JPanel arrowPane = new JPanel(); JPanel arrowPane = new JPanel();
arrowPane.setLayout(new GridLayout(2, 1)); arrowPane.setLayout(new GridLayout(2, 1));
arrowPane.add(preButton); arrowPane.add(preButton);
@ -304,7 +316,6 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver,
int buttonHeight = FineUIUtils.getAndScaleInt("InputButton.height", defaultButtonSize); int buttonHeight = FineUIUtils.getAndScaleInt("InputButton.height", defaultButtonSize);
arrowPane.setPreferredSize(new Dimension(buttonWidth, buttonHeight)); arrowPane.setPreferredSize(new Dimension(buttonWidth, buttonHeight));
add(arrowPane, BorderLayout.EAST); add(arrowPane, BorderLayout.EAST);
componentInitListeners();
} }
private UIButton createArrowButton(Icon icon) { private UIButton createArrowButton(Icon icon) {
@ -337,7 +348,8 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver,
textField.setMinValue(minValue); textField.setMinValue(minValue);
} }
private void componentInitListeners() { protected void componentInitListeners() {
initButtonFocusListeners();
preButton.addActionListener(new ActionListener() { preButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -362,6 +374,31 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver,
initTextFiledListeners(); initTextFiledListeners();
} }
protected void initButtonFocusListeners() {
preButton.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
preAction = true;
}
@Override
public void focusLost(FocusEvent e) {
preAction = false;
}
});
nextButton.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
nextAction = true;
}
@Override
public void focusLost(FocusEvent e) {
nextAction = false;
}
});
}
protected void initTextFiledListeners() { protected void initTextFiledListeners() {
textField.getDocument().removeDocumentListener(docListener); textField.getDocument().removeDocumentListener(docListener);
textField.getDocument().addDocumentListener(docListener); textField.getDocument().addDocumentListener(docListener);
@ -391,7 +428,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver,
return numberField; return numberField;
} }
private DocumentListener docListener = new DocumentListener() { protected DocumentListener docListener = new DocumentListener() {
@Override @Override
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
setTextFieldValue(textField.getValue()); setTextFieldValue(textField.getValue());

1
designer-base/src/main/java/com/fr/design/write/submit/CustomJobPane.java

@ -50,6 +50,7 @@ public abstract class CustomJobPane extends BasicBeanPane {
UIButton editButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit")); UIButton editButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit"));
UITextArea area = new UITextArea(2, 1); UITextArea area = new UITextArea(2, 1);
area.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Extend_Class", "com.fr.data.AbstractSubmitTask"));
browserButton.addActionListener(new ActionListener() { browserButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {

2
designer-realize/src/main/java/com/fr/design/write/submit/SubmitVisitorListPane.java

@ -196,7 +196,7 @@ public class SubmitVisitorListPane extends ObjectJControlPane {
JPanel typePane = new JPanel(new BorderLayout()); JPanel typePane = new JPanel(new BorderLayout());
typePane.add(row(10, typePane.add(row(10,
cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Write_Choose_Submit_Type"))), cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Write_Choose_Submit_Type"))),
cell(csjConfigComboBox).weight(0.5)).getComponent()); cell(csjConfigComboBox).weight(0.5), flex()).getComponent());
this.add(column( this.add(column(
cell(FineUIUtils.wrapComponentWithTitle(typePane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Write_Submit_Type"))), cell(FineUIUtils.wrapComponentWithTitle(typePane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Write_Submit_Type"))),

Loading…
Cancel
Save