diff --git a/designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java b/designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java index d23a1fd22f..6f0fd085aa 100644 --- a/designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java @@ -1,32 +1,22 @@ package com.fr.design.gui.columnrow; -import com.fine.theme.utils.FineUIUtils; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; -import com.fr.design.gui.ispinner.ColumnRowSpinner; -import com.fr.design.gui.ispinner.UIBasicSpinner; -import com.fr.design.gui.ispinner.UpperCaseSpinner; -import com.fr.design.gui.itextfield.UITextField; -import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.design.gui.ispinner.FineUpperCaseSpinner; +import com.fr.design.gui.ispinner.UISpinner; + import com.fr.general.ComparatorUtils; import com.fr.stable.ColumnRow; import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; -import javax.swing.JFormattedTextField; import javax.swing.JPanel; -import javax.swing.SpinnerListModel; -import javax.swing.JSpinner.DefaultEditor; + import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; 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.Dimension; import static com.fine.swing.ui.layout.Layouts.cell; 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 { private static final long serialVersionUID = 1L; - private static String[] columnarray = new String[1000]; - private static String[] rowarray = new String[5000]; - - protected UpperCaseSpinner columnSpinner; - 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 FineUpperCaseSpinner columnSpinner; + protected UISpinner rowSpinner; protected DocumentListener d = new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { - String rolText = ((DefaultEditor) columnSpinner.getEditor()).getTextField().getText(); - String rowText = ((DefaultEditor) rowSpinner.getEditor()).getTextField().getText(); + String rolText = columnSpinner.getTextFieldNew().getText(); + String rowText = rowSpinner.getTextField().getText(); if (rolText == null || rolText.length() == 0 || rowText == null || rowText.length() == 0) { return; } @@ -73,8 +51,8 @@ public class ColumnRowPane extends JPanel implements UIObserver { @Override public void insertUpdate(DocumentEvent e) { - int col = StableUtils.convertABCToInt(((DefaultEditor) columnSpinner.getEditor()).getTextField().getText()) - 1; - int row = Integer.parseInt(((DefaultEditor) rowSpinner.getEditor()).getTextField().getText()) - 1; + int col = StableUtils.convertABCToInt(columnSpinner.getTextFieldNew().getText()) - 1; + int row = Integer.parseInt(rowSpinner.getTextField().getText()) - 1; setColumnRow(ColumnRow.valueOf(col, row)); } @@ -128,58 +106,21 @@ public class ColumnRowPane extends JPanel implements UIObserver { protected void initRowSpinner() { - rowSpinner = new ColumnRowSpinner((new SpinnerListModel(rowarray))) { - 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); - } + rowSpinner = new UISpinner(1, 5000, 1); } protected void initColSpinner() { - SpinnerListModel columnSpinnerListModel = new SpinnerListModel(columnarray); - 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); - } - }); + columnSpinner = new FineUpperCaseSpinner(1, 5000, 1); } protected void addDocumentListener(DocumentListener l) { - ((DefaultEditor) columnSpinner.getEditor()).getTextField().getDocument().addDocumentListener(l); - ((DefaultEditor) rowSpinner.getEditor()).getTextField().getDocument().addDocumentListener(l); + columnSpinner.getTextFieldNew().getDocument().addDocumentListener(l); + rowSpinner.getTextField().getDocument().addDocumentListener(l); } private void removeDocumentListener(DocumentListener l) { - ((DefaultEditor) columnSpinner.getEditor()).getTextField().getDocument().removeDocumentListener(l); - ((DefaultEditor) rowSpinner.getEditor()).getTextField().getDocument().removeDocumentListener(l); + columnSpinner.getTextFieldNew().getDocument().removeDocumentListener(l); + rowSpinner.getTextField().getDocument().removeDocumentListener(l); } /** @@ -208,17 +149,13 @@ public class ColumnRowPane extends JPanel implements UIObserver { column = 0; } removeDocumentListener(d); - String colValue = StableUtils.convertIntToABC(column + 1); - columnSpinner.setValue(colValue); - ((DefaultEditor) columnSpinner.getEditor()).getTextField().setText(colValue); + columnSpinner.setValue(column+1); int row = columnRow.getRow(); // shoc 小于0就蹦了 if (row < 0) { row = 0; } - String rowValue = Integer.toString(row + 1); - rowSpinner.setValue(rowValue); - ((DefaultEditor) rowSpinner.getEditor()).getTextField().setText(rowValue); + rowSpinner.setValue(row+1); addDocumentListener(d); fireChanged(); } diff --git a/designer-base/src/main/java/com/fr/design/gui/ispinner/FineUpperCaseSpinner.java b/designer-base/src/main/java/com/fr/design/gui/ispinner/FineUpperCaseSpinner.java new file mode 100644 index 0000000000..5d4538e4f4 --- /dev/null +++ b/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; + } + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java b/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java index f6b75b7c4f..6e4965a8f0 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ispinner/UISpinner.java +++ b/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.StringUtils; -import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JPanel; 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 { - 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 ICON_WIDTH = 12; protected double value; - private static final int DEFAULT_NUMBERFIELD_COLUMNS = 2; + protected static final int DEFAULT_NUMBERFIELD_COLUMNS = 2; private UINumberField textField; private UIButton preButton; private UIButton nextButton; @@ -64,10 +63,14 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, /** * Spinner内的数字文本框长度 */ - private int numberFieldColumns; - private boolean textFieldFocus = false; + protected int numberFieldColumns; + protected boolean textFieldFocus = false; - private boolean hover; + protected boolean hover; + + protected boolean preAction; + + protected boolean nextAction; 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() { @Override public void mouseEntered(MouseEvent e) { @@ -129,7 +137,6 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, repaint(); } }); - } /** @@ -281,19 +288,24 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, return hover; } - private void initComponents() { + protected void initComponents() { + setLayout(new BorderLayout()); textField = initNumberField(); textField.setMaxValue(maxValue); textField.setMinValue(minValue); 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 initArrowPane() { preButton = createArrowButton(new LazyIcon("up_arrow", ICON_WIDTH)); nextButton = createArrowButton(new LazyIcon("down_arrow", ICON_WIDTH)); - setLayout(new BorderLayout()); - add(textField, BorderLayout.CENTER); JPanel arrowPane = new JPanel(); arrowPane.setLayout(new GridLayout(2, 1)); arrowPane.add(preButton); @@ -304,7 +316,6 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, int buttonHeight = FineUIUtils.getAndScaleInt("InputButton.height", defaultButtonSize); arrowPane.setPreferredSize(new Dimension(buttonWidth, buttonHeight)); add(arrowPane, BorderLayout.EAST); - componentInitListeners(); } private UIButton createArrowButton(Icon icon) { @@ -337,7 +348,8 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, textField.setMinValue(minValue); } - private void componentInitListeners() { + protected void componentInitListeners() { + initButtonFocusListeners(); preButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -362,6 +374,31 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, 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() { textField.getDocument().removeDocumentListener(docListener); textField.getDocument().addDocumentListener(docListener); @@ -391,7 +428,7 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, return numberField; } - private DocumentListener docListener = new DocumentListener() { + protected DocumentListener docListener = new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { setTextFieldValue(textField.getValue()); diff --git a/designer-base/src/main/java/com/fr/design/write/submit/CustomJobPane.java b/designer-base/src/main/java/com/fr/design/write/submit/CustomJobPane.java index 7b67d5137d..7229ad0b8b 100644 --- a/designer-base/src/main/java/com/fr/design/write/submit/CustomJobPane.java +++ b/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")); 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() { public void actionPerformed(ActionEvent evt) { diff --git a/designer-realize/src/main/java/com/fr/design/write/submit/SubmitVisitorListPane.java b/designer-realize/src/main/java/com/fr/design/write/submit/SubmitVisitorListPane.java index 4cb4dea409..d930a3bfbf 100644 --- a/designer-realize/src/main/java/com/fr/design/write/submit/SubmitVisitorListPane.java +++ b/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()); typePane.add(row(10, 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( cell(FineUIUtils.wrapComponentWithTitle(typePane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Write_Submit_Type"))),