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.
80 lines
2.3 KiB
80 lines
2.3 KiB
/* |
|
* Copyright (C), 2018-2021 |
|
* Project: starter |
|
* FileName: DateTypeEditor |
|
* Author: Louis |
|
* Date: 2021/11/15 8:53 |
|
*/ |
|
package com.fr.plugin.hrjf.editors; |
|
|
|
import com.fanruan.api.design.DesignKit; |
|
import com.fanruan.api.util.StringKit; |
|
import com.fr.design.Exception.ValidationException; |
|
import com.fr.design.gui.ibutton.UIButtonGroup; |
|
import com.fr.design.mainframe.widget.editors.AbstractPropertyEditor; |
|
import com.fr.general.ComparatorUtils; |
|
|
|
import java.awt.*; |
|
import java.util.HashMap; |
|
import java.util.Map; |
|
|
|
/** |
|
* <Function Description><br> |
|
* <DateTypeEditor> |
|
* |
|
* @author fr.open |
|
* @since 1.0.0 |
|
*/ |
|
public class DateTypeEditor extends AbstractPropertyEditor { |
|
public static final String DATE = "date"; |
|
public static final String DATETIME = "datetime"; |
|
private static final Map<String, String> ITEMS = new HashMap<String, String>() { |
|
{ |
|
put(DesignKit.i18nText("Plugin-hrjf-Date_Type_Date"), DATE); |
|
put(DesignKit.i18nText("Plugin-hrjf-Date_Type_DateTime"), DATETIME); |
|
} |
|
}; |
|
protected UIButtonGroup<String> buttonGroup; |
|
|
|
|
|
public DateTypeEditor() { |
|
this.buttonGroup = new UIButtonGroup<>(ITEMS.keySet().toArray(new String[0])); |
|
this.initButtonGroupLookAndFeel(); |
|
} |
|
|
|
@Override |
|
public void validateValue() throws ValidationException { |
|
|
|
} |
|
|
|
@Override |
|
public Object getValue() { |
|
if (ComparatorUtils.equals(this.buttonGroup.getSelectedIndex(), 0)) { |
|
return DATE; |
|
} else if (ComparatorUtils.equals(this.buttonGroup.getSelectedIndex(), 1)) { |
|
return DATETIME; |
|
} else { |
|
return DATE; |
|
} |
|
} |
|
|
|
@Override |
|
public void setValue(Object value) { |
|
if (StringKit.equals(String.valueOf(value), DATE)) { |
|
this.buttonGroup.setSelectedIndex(0); |
|
} else if (StringKit.equals(String.valueOf(value), DATETIME)) { |
|
this.buttonGroup.setSelectedIndex(1); |
|
} else { |
|
this.buttonGroup.setSelectedIndex(0); |
|
} |
|
} |
|
|
|
@Override |
|
public Component getCustomEditor() { |
|
return this.buttonGroup; |
|
} |
|
|
|
private void initButtonGroupLookAndFeel() { |
|
this.buttonGroup.addActionListener(e -> DateTypeEditor.this.firePropertyChanged()); |
|
} |
|
} |