JSD-8806 VUE日期控件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

227 lines
7.9 KiB

/*
* Copyright (C), 2018-2021
* Project: starter
* FileName: VueAccessibleEditor
* Author: Louis
* Date: 2021/11/25 21:58
*/
package com.fr.plugin.hrjf.accessibles;
import com.fr.base.BaseUtils;
import com.fr.design.Exception.ValidationException;
import com.fr.design.constants.UIConstants;
import com.fr.design.designer.properties.Decoder;
import com.fr.design.designer.properties.Encoder;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIButtonUI;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.widget.accessibles.AccessibleEditor;
import com.fr.design.mainframe.widget.editors.ITextComponent;
import com.fr.design.mainframe.widget.editors.TextField;
import com.fr.design.utils.gui.GUIPaintUtils;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.ButtonUI;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
/**
* <Function Description><br>
* <VueAccessibleEditor>
*
* @author fr.open
* @since 1.0.0
*/
public class BaseAccessibleVueEditor extends BasicPane implements AccessibleEditor {
protected Encoder encoder;
protected ITextComponent txtValue;
private ArrayList<ChangeListener> listeners = new ArrayList();
private boolean showButton;
private Decoder decoder;
private UIButton btPopup;
public BaseAccessibleVueEditor(Encoder var1, Decoder var2, boolean var3) {
this.showButton = var3;
this.encoder = var1;
this.decoder = var2;
this.initComponents();
// this.txtValue.setEditable(var2 != null);
this.txtValue.setEditable(false);
((JComponent) this.txtValue).setOpaque(true);
((JComponent) this.txtValue).setBorder(BorderFactory.createLineBorder(Color.lightGray));
((JComponent) this.txtValue).setBackground(Color.WHITE);
}
public static void showMessage(String var0, Component var1) {
FineJOptionPane.showMessageDialog(var1, var0, "Validation Error", 0);
}
public void requestFocus() {
super.requestFocus();
if (this.decoder != null) {
((JComponent) this.txtValue).requestFocus();
} else if (this.showButton) {
this.btPopup.requestFocus();
}
}
protected ITextComponent createTextField() {
return new TextField() {
public void registerChangeListener(UIObserverListener var1) {
}
public boolean shouldResponseChangeListener() {
return false;
}
};
}
private void initComponents() {
this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 1));
this.txtValue = this.createTextField();
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.txtValue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent var1) {
BaseAccessibleVueEditor.this.txtValueActionPerformed(var1);
}
});
this.add((JComponent) this.txtValue, "Center");
this.setOpaque(false);
if (this.showButton) {
this.btPopup = new UIButton() {
public ButtonUI getUI() {
return new UIButtonUI() {
protected boolean isPressed(AbstractButton var1) {
return model.isArmed() && model.isPressed();
}
protected void doExtraPainting(UIButton var1, Graphics2D var2, int var3, int var4, String var5) {
if (this.isPressed(var1) && var1.isPressedPainted()) {
GUIPaintUtils.fillPressed(var2, 0, 0, var3, var4, var1.isRoundBorder(), var1.getRectDirection(), var1.isDoneAuthorityEdited(var5), UIConstants.COMBOBOX_BTN_PRESS);
} else if (this.isRollOver(var1)) {
GUIPaintUtils.fillRollOver(var2, 0, 0, var3, var4, var1.isRoundBorder(), var1.getRectDirection(), var1.isDoneAuthorityEdited(var5), var1.isPressedPainted(), UIConstants.COMBOBOX_BTN_ROLLOVER);
} else if (var1.isNormalPainted()) {
GUIPaintUtils.fillNormal(var2, 0, 0, var3, var4, var1.isRoundBorder(), var1.getRectDirection(), var1.isDoneAuthorityEdited(var5), var1.isPressedPainted(), UIConstants.COMBOBOX_BTN_NORMAL);
}
}
};
}
};
this.initPopupButton();
this.btPopup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent var1) {
BaseAccessibleVueEditor.this.showEditorPane();
}
});
this.add(this.btPopup, "East");
}
}
protected String title4PopupWindow() {
return "Base";
}
protected void showEditorPane() {
}
protected void initPopupButton() {
if (!this.isComboButton()) {
this.btPopup.setIcon(new ImageIcon(UIConstants.ACCESSIBLE_EDITOR_DOT));
this.btPopup.setPreferredSize(new Dimension(20, 20));
} else {
this.btPopup.setRolloverEnabled(true);
this.btPopup.setFocusPainted(false);
this.btPopup.setPreferredSize(new Dimension(15, 19));
this.btPopup.setBorderPainted(false);
this.btPopup.setContentAreaFilled(false);
this.btPopup.setMargin(new Insets(0, 0, 0, 0));
this.btPopup.setIcon(BaseUtils.readIcon("/com/fr/design/images/form/designer/drop_up.png"));
this.btPopup.setPressedIcon(BaseUtils.readIcon("/com/fr/design/images/form/designer/drop_down.png"));
this.btPopup.setRolloverIcon(BaseUtils.readIcon("/com/fr/design/images/form/designer/drop_over.png"));
}
}
protected boolean isComboButton() {
return false;
}
private void txtValueActionPerformed(ActionEvent var1) {
try {
this.validateValue();
this.fireStateChanged();
} catch (ValidationException var3) {
showMessage(var3.getMessage(), this);
this.txtValue.selectAll();
((JComponent) this.txtValue).requestFocus();
}
}
public Component getEditor() {
return this;
}
public Object getValue() {
return this.decoder.decode(this.txtValue.getText());
}
public void setValue(Object var1) {
if (this.encoder != null) {
this.txtValue.setText(this.encoder.encode(var1));
}
this.txtValue.setValue(var1);
}
public void addChangeListener(ChangeListener var1) {
if (!this.listeners.contains(var1)) {
this.listeners.add(var1);
}
}
public void removeChangeListener(ChangeListener var1) {
if (this.listeners.contains(var1)) {
this.listeners.remove(var1);
}
}
protected void fireStateChanged() {
ChangeEvent var1 = new ChangeEvent(this);
Iterator var2 = this.listeners.iterator();
while (var2.hasNext()) {
ChangeListener var3 = (ChangeListener) var2.next();
var3.stateChanged(var1);
}
}
public Encoder getEncoder() {
return this.encoder;
}
public void setEncoder(Encoder var1) {
this.encoder = var1;
}
public void validateValue() throws ValidationException {
if (this.decoder != null) {
this.decoder.validate(this.txtValue.getText());
}
}
}