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..72929d6c76 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/ispinner/FineUpperCaseSpinner.java @@ -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; + } + } +} 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..e95d1d3ef4 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,16 +348,18 @@ public class UISpinner extends JPanel implements UIObserver, GlobalNameObserver, textField.setMinValue(minValue); } - private void componentInitListeners() { + protected void componentInitListeners() { preButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { + preAction = true; setValue(value + dierta); } }); nextButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { + nextAction = true; setValue(value - dierta); } }); @@ -391,7 +404,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..ba56aa792a 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 @@ -3,7 +3,6 @@ package com.fr.design.write.submit; import com.fine.theme.utils.FineUIScale; import com.fine.theme.utils.FineUIUtils; import com.formdev.flatlaf.util.ScaledEmptyBorder; -import com.fr.base.GraphHelper; import com.fr.data.AbstractClassJob; import com.fr.design.data.tabledata.tabledatapane.ClassNameSelectPane; import com.fr.design.beans.BasicBeanPane; @@ -18,7 +17,7 @@ import com.fr.design.dialog.DialogActionAdapter; import com.fr.stable.ListMap; import com.fr.stable.StringUtils; -import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.design.i18n.Toolkit; import javax.swing.*; import java.awt.*; @@ -28,7 +27,6 @@ import java.awt.event.ActionListener; import static com.fine.swing.ui.layout.Layouts.column; import static com.fine.swing.ui.layout.Layouts.cell; import static com.fine.swing.ui.layout.Layouts.row; -import static com.fine.swing.ui.layout.Layouts.flex; /** * Author : Shockway @@ -45,11 +43,12 @@ public abstract class CustomJobPane extends BasicBeanPane { JPanel reportletNamePane = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(); classNameTextField = new UITextField(); - UIButton browserButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select")); + UIButton browserButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Select")); - UIButton editButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit")); + UIButton editButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Edit")); UITextArea area = new UITextArea(2, 1); + area.setText(Toolkit.i18nText("Fine-Design_Basic_Extend_Class", "com.fr.data.AbstractSubmitTask")); browserButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { @@ -60,7 +59,7 @@ public abstract class CustomJobPane extends BasicBeanPane { new DialogActionAdapter() { public void doOk() { classNameTextField.setText(bPane.getClassPath()); - area.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Extend_Class", "com.fr.data.AbstractSubmitTask")); + area.setText(Toolkit.i18nText("Fine-Design_Basic_Extend_Class", "com.fr.data.AbstractSubmitTask")); checkAddButtonEnable(); } }).setVisible(true); @@ -74,7 +73,7 @@ public abstract class CustomJobPane extends BasicBeanPane { new DialogActionAdapter() { public void doOk() { classNameTextField.setText(javaEditorPane.getClassText()); - area.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Extend_Class", "com.fr.data.AbstractSubmitTask")); + area.setText(Toolkit.i18nText("Fine-Design_Basic_Extend_Class", "com.fr.data.AbstractSubmitTask")); checkAddButtonEnable(); } }); @@ -101,9 +100,9 @@ public abstract class CustomJobPane extends BasicBeanPane { dsPane.setBorder(new ScaledEmptyBorder(10, 0, 0, 0)); dsPane.add(area); this.add(column(20, - cell(FineUIUtils.wrapComponentWithTitle(reportletNamePane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Class_Name"))), - cell(FineUIUtils.wrapComponentWithTitle(objectProperiesPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Property"))).weight(1.0), - cell(FineUIUtils.wrapComponentWithTitle(dsPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom_Job_Description"))) + cell(FineUIUtils.wrapComponentWithTitle(reportletNamePane, Toolkit.i18nText("Fine-Design_Basic_Class_Name"))), + cell(FineUIUtils.wrapComponentWithTitle(objectProperiesPane, Toolkit.i18nText("Fine-Design_Basic_Property"))).weight(1.0), + cell(FineUIUtils.wrapComponentWithTitle(dsPane, Toolkit.i18nText("Fine-Design_Basic_Custom_Job_Description"))) ).getComponent()); checkAddButtonEnable(); } 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..3dcdb44c55 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 @@ -13,8 +13,6 @@ import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.ElementCasePane; -import com.fr.design.scrollruler.ModLineBorder; -import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; @@ -27,6 +25,7 @@ import com.fr.stable.Nameable; import com.fr.write.BuiltInSQLSubmiterProvider; import com.fr.write.DBManipulation; import com.fr.write.WClassSubmiterProvider; +import com.fr.design.i18n.Toolkit; import javax.swing.*; import java.awt.*; @@ -53,12 +52,12 @@ public class SubmitVisitorListPane extends ObjectJControlPane { */ public NameableCreator[] createNameableCreators() { return new NameableCreator[]{ - new NameObjectCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Submit_Type_Build_In_Sql"), + new NameObjectCreator(Toolkit.i18nText("Fine-Design_Report_Submit_Type_Build_In_Sql"), new LazyIcon("dataLink"), BuiltInSQLSubmiter.class, BuildInSQLPane.class), new NameObjectCreator( - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Submit_Type_Custom"), + Toolkit.i18nText("Fine-Design_Report_Submit_Type_Custom"), new LazyIcon("dataLink"), WClassSubmiter.class, CustomPane.class) @@ -194,12 +193,10 @@ public class SubmitVisitorListPane extends ObjectJControlPane { csjConfigComboBox = new UIComboBox(configTypes.toArray()); 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()); + typePane.add(row(10, cell(new UILabel(Toolkit.i18nText("Fine-Design_Report_Write_Choose_Submit_Type"))), 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"))), + cell(FineUIUtils.wrapComponentWithTitle(typePane, Toolkit.i18nText("Fine-Design_Report_Write_Submit_Type"))), cell(customCardPane).weight(1.0)).getComponent()); csjConfigComboBox.addItemListener(new ItemListener() {