30 changed files with 660 additions and 171 deletions
@ -0,0 +1,30 @@ |
|||||||
|
package com.fr.design.debug.edt; |
||||||
|
|
||||||
|
/** |
||||||
|
* Swing组件严格限制EDT运行 |
||||||
|
* |
||||||
|
* @author vito |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2023/8/9 |
||||||
|
*/ |
||||||
|
public class StrictEDTException extends RuntimeException { |
||||||
|
|
||||||
|
public StrictEDTException() { |
||||||
|
} |
||||||
|
|
||||||
|
public StrictEDTException(String message) { |
||||||
|
super(message); |
||||||
|
} |
||||||
|
|
||||||
|
public StrictEDTException(String message, Throwable cause) { |
||||||
|
super(message, cause); |
||||||
|
} |
||||||
|
|
||||||
|
public StrictEDTException(Throwable cause) { |
||||||
|
super(cause); |
||||||
|
} |
||||||
|
|
||||||
|
public StrictEDTException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { |
||||||
|
super(message, cause, enableSuppression, writableStackTrace); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,130 @@ |
|||||||
|
package com.fr.design.debug.edt; |
||||||
|
|
||||||
|
import com.fr.design.ui.util.EdtInvocationManager; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
|
||||||
|
import java.awt.event.ComponentEvent; |
||||||
|
import java.awt.event.ComponentListener; |
||||||
|
import java.awt.event.HierarchyEvent; |
||||||
|
import java.awt.event.HierarchyListener; |
||||||
|
import java.awt.event.KeyEvent; |
||||||
|
import java.awt.event.KeyListener; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.awt.event.MouseListener; |
||||||
|
import java.awt.event.MouseMotionListener; |
||||||
|
import java.awt.event.MouseWheelEvent; |
||||||
|
import java.awt.event.MouseWheelListener; |
||||||
|
import java.beans.PropertyChangeEvent; |
||||||
|
import java.beans.PropertyChangeListener; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Swing组件严格限制EDT运行监听器 |
||||||
|
* |
||||||
|
* @author vito |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2023/8/9 |
||||||
|
*/ |
||||||
|
public class StrictEdtListeners implements HierarchyListener, PropertyChangeListener, ComponentListener, MouseListener, |
||||||
|
MouseWheelListener, MouseMotionListener, KeyListener { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void componentResized(ComponentEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void componentMoved(ComponentEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void componentShown(ComponentEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void componentHidden(ComponentEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void hierarchyChanged(HierarchyEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void keyTyped(KeyEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void keyPressed(KeyEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void keyReleased(KeyEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mouseClicked(MouseEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mousePressed(MouseEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mouseReleased(MouseEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mouseEntered(MouseEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mouseExited(MouseEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
// redispatchMouseEvent(e);
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mouseDragged(MouseEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mouseMoved(MouseEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void mouseWheelMoved(MouseWheelEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange(PropertyChangeEvent e) { |
||||||
|
checkEventDispatchThread(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 检查当前是否处于EDT中,并发出告警 |
||||||
|
*/ |
||||||
|
public static void checkEventDispatchThread() { |
||||||
|
if (!EdtInvocationManager.getInstance().isEventDispatchThread()) { |
||||||
|
String s = String.format( |
||||||
|
"[StrictEDT] The current operation can only be in an EDT (Event Dispatch Thread). Current thread is: %s", |
||||||
|
Thread.currentThread().getName() |
||||||
|
); |
||||||
|
StrictEDTException strictEdtException = new StrictEDTException(s); |
||||||
|
FineLoggerFactory.getLogger().warn(s, strictEdtException); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,135 @@ |
|||||||
|
package com.fr.design.debug.edt; |
||||||
|
|
||||||
|
import com.fanruan.gui.InspectorWindow; |
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
|
||||||
|
import java.awt.AWTEvent; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Container; |
||||||
|
import java.awt.Toolkit; |
||||||
|
import java.awt.Window; |
||||||
|
import java.awt.event.AWTEventListener; |
||||||
|
import java.awt.event.ContainerEvent; |
||||||
|
|
||||||
|
/** |
||||||
|
* 严格UI线程运行管理器 |
||||||
|
* |
||||||
|
* @author vito |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2024/12/20 |
||||||
|
*/ |
||||||
|
public class StrictEdtManager { |
||||||
|
|
||||||
|
private static final StrictEdtListeners LISTENERS = new StrictEdtListeners(); |
||||||
|
|
||||||
|
private static void installContainerEDTCheckers(@NotNull final Container component, int level) { |
||||||
|
if (FineLoggerFactory.getLogger().isDebugEnabled()) { |
||||||
|
for (int i = 0; i < level; i++) { |
||||||
|
FineLoggerFactory.getLogger().debug(" "); |
||||||
|
} |
||||||
|
FineLoggerFactory.getLogger().debug(component.toString()); |
||||||
|
} |
||||||
|
|
||||||
|
int count = component.getComponentCount(); |
||||||
|
level += 1; |
||||||
|
for (int i = 0; i < count; i++) { |
||||||
|
Component comp = component.getComponent(i); |
||||||
|
addEDTCheckersListener(comp); |
||||||
|
if (comp instanceof Container) { |
||||||
|
installContainerEDTCheckers((Container) comp, level); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static void addEDTCheckersListener(Component comp) { |
||||||
|
comp.addHierarchyListener(LISTENERS); |
||||||
|
comp.addPropertyChangeListener(LISTENERS); |
||||||
|
comp.addComponentListener(LISTENERS); |
||||||
|
comp.addMouseListener(LISTENERS); |
||||||
|
comp.addMouseMotionListener(LISTENERS); |
||||||
|
comp.addKeyListener(LISTENERS); |
||||||
|
} |
||||||
|
|
||||||
|
private static void installEDTCheckers(Container container, int level) { |
||||||
|
installContainerEDTCheckers(container, level); |
||||||
|
level += 1; |
||||||
|
if (container instanceof Window) { |
||||||
|
Window[] children = ((Window) container).getOwnedWindows(); |
||||||
|
for (Window child : children) { |
||||||
|
if (child instanceof InspectorWindow) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
installEDTCheckers(child, level); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static final AWTEventListener AWT_EVENT_LISTENER = (AWTEvent event) -> { |
||||||
|
if (event instanceof ContainerEvent) { |
||||||
|
Component child = event.getID() == ContainerEvent.COMPONENT_ADDED ? ((ContainerEvent) event).getChild() : null; |
||||||
|
if (child != null) { |
||||||
|
addEDTCheckersListener(child); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* 监听组件,警告不在EDT中执行的UI操作 |
||||||
|
*/ |
||||||
|
public static void install() { |
||||||
|
// 监听当前的组件
|
||||||
|
installEDTCheckers(DesignerContext.getDesignerFrame(), 0); |
||||||
|
// 监听新增的组件
|
||||||
|
Toolkit.getDefaultToolkit().addAWTEventListener(AWT_EVENT_LISTENER, AWTEvent.CONTAINER_EVENT_MASK); |
||||||
|
FineLoggerFactory.getLogger().info("[StrictEDT] install Strict EDT Checkers"); |
||||||
|
} |
||||||
|
|
||||||
|
private static void uninstallContainerEDTCheckers(@NotNull final Container component, int level) { |
||||||
|
int count = component.getComponentCount(); |
||||||
|
level += 1; |
||||||
|
for (int i = 0; i < count; i++) { |
||||||
|
Component comp = component.getComponent(i); |
||||||
|
removeEDTCheckersListener(comp); |
||||||
|
if (comp instanceof Container) { |
||||||
|
uninstallContainerEDTCheckers((Container) comp, level); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static void removeEDTCheckersListener(Component comp) { |
||||||
|
comp.removeHierarchyListener(LISTENERS); |
||||||
|
comp.removePropertyChangeListener(LISTENERS); |
||||||
|
comp.removeComponentListener(LISTENERS); |
||||||
|
comp.removeMouseListener(LISTENERS); |
||||||
|
comp.removeMouseMotionListener(LISTENERS); |
||||||
|
comp.removeKeyListener(LISTENERS); |
||||||
|
} |
||||||
|
|
||||||
|
private static void removeEDTCheckers(Container container, int level) { |
||||||
|
uninstallContainerEDTCheckers(container, level); |
||||||
|
level += 1; |
||||||
|
if (container instanceof Window) { |
||||||
|
Window[] children = ((Window) container).getOwnedWindows(); |
||||||
|
for (Window child : children) { |
||||||
|
if (child instanceof InspectorWindow) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
removeEDTCheckers(child, level); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 监听组件,警告不在EDT中执行的UI操作 |
||||||
|
*/ |
||||||
|
public static void uninstall() { |
||||||
|
// 取消监听新增的组件
|
||||||
|
Toolkit.getDefaultToolkit().removeAWTEventListener(AWT_EVENT_LISTENER); |
||||||
|
// 解除监听当前的组件
|
||||||
|
removeEDTCheckers(DesignerContext.getDesignerFrame(), 0); |
||||||
|
FineLoggerFactory.getLogger().info("[StrictEDT] uninstall Strict EDT Checkers"); |
||||||
|
} |
||||||
|
} |
@ -1 +1,84 @@ |
|||||||
package com.fr.design.editor.editor;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.stable.ColumnRowGroup;
import java.awt.*;
/**
* Author : Shockway
* Date: 14-1-10
* Time: 下午1:46
*/
public class ColumnRowGroupEditor extends Editor<ColumnRowGroup> {
private UITextField crEditor;
public ColumnRowGroupEditor() {
this("");
}
public ColumnRowGroupEditor(String name) {
this(null, name);
}
public ColumnRowGroupEditor(ColumnRowGroup value) {
this(value, "");
}
public ColumnRowGroupEditor(ColumnRowGroup value, String name) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
crEditor = new UITextField();
this.add(crEditor, BorderLayout.CENTER);
this.setValue(value);
this.setName(name);
}
@Override
public ColumnRowGroup getValue() {
return new ColumnRowGroup(this.crEditor.getText());
}
@Override
public void setValue(ColumnRowGroup value) {
if (value == null) {
this.crEditor.setText("");
} else {
this.crEditor.setText(value.toString());
}
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
this.crEditor.setEnabled(enabled);
}
/**
* 获取焦点
*/
public void requestFocus() {
this.crEditor.requestFocus();
}
public String getIconName() {
return "cell_group";
}
/**
* 是否接收/支持这个对象
* @param object 检测对象
* @return 是否支持
*/
public boolean accept(Object object) {
return object instanceof ColumnRowGroup;
}
} |
package com.fr.design.editor.editor; |
||||||
|
|
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.stable.ColumnRowGroup; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 单元格组编辑 |
||||||
|
* |
||||||
|
* @author Shockway |
||||||
|
* @since 2014-01-10 |
||||||
|
* Created on 2024-01-10 |
||||||
|
*/ |
||||||
|
public class ColumnRowGroupEditor extends Editor<ColumnRowGroup> { |
||||||
|
|
||||||
|
private UITextField crEditor; |
||||||
|
|
||||||
|
public ColumnRowGroupEditor() { |
||||||
|
this(""); |
||||||
|
} |
||||||
|
|
||||||
|
public ColumnRowGroupEditor(String name) { |
||||||
|
this(null, name); |
||||||
|
} |
||||||
|
|
||||||
|
public ColumnRowGroupEditor(ColumnRowGroup value) { |
||||||
|
this(value, ""); |
||||||
|
} |
||||||
|
|
||||||
|
public ColumnRowGroupEditor(ColumnRowGroup value, String name) { |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
crEditor = new UITextField(); |
||||||
|
this.add(crEditor, BorderLayout.CENTER); |
||||||
|
this.setValue(value); |
||||||
|
this.setName(name); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ColumnRowGroup getValue() { |
||||||
|
return new ColumnRowGroup(this.crEditor.getText()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setValue(ColumnRowGroup value) { |
||||||
|
if (value == null) { |
||||||
|
this.crEditor.setText(""); |
||||||
|
} else { |
||||||
|
this.crEditor.setText(value.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setEnabled(boolean enabled) { |
||||||
|
super.setEnabled(enabled); |
||||||
|
|
||||||
|
this.crEditor.setEnabled(enabled); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取焦点 |
||||||
|
*/ |
||||||
|
public void requestFocus() { |
||||||
|
this.crEditor.requestFocus(); |
||||||
|
} |
||||||
|
|
||||||
|
public String getIconName() { |
||||||
|
return "cell_group"; |
||||||
|
} |
||||||
|
|
||||||
|
public String getIconId() { |
||||||
|
return "cell_group_popup"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否接收/支持这个对象 |
||||||
|
* @param object 检测对象 |
||||||
|
* @return 是否支持 |
||||||
|
*/ |
||||||
|
public boolean accept(Object object) { |
||||||
|
return object instanceof ColumnRowGroup; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,56 @@ |
|||||||
|
package com.fr.design.i18n; |
||||||
|
|
||||||
|
import com.fr.config.ConfigContext; |
||||||
|
import com.fr.config.DefaultConfiguration; |
||||||
|
import com.fr.config.Identifier; |
||||||
|
import com.fr.config.holder.factory.Holders; |
||||||
|
import com.fr.config.holder.impl.MapConf; |
||||||
|
|
||||||
|
import java.util.Collections; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 设计器语言扩展配置 |
||||||
|
* |
||||||
|
* @author obo |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2024/09/26 |
||||||
|
*/ |
||||||
|
public class DesignExtendLanguageConfig extends DefaultConfiguration { |
||||||
|
|
||||||
|
private static volatile DesignExtendLanguageConfig designExtendLanguageConfig = null; |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取实例 |
||||||
|
*/ |
||||||
|
public static DesignExtendLanguageConfig getInstance() { |
||||||
|
if (designExtendLanguageConfig == null) { |
||||||
|
designExtendLanguageConfig = ConfigContext.getConfigInstance(DesignExtendLanguageConfig.class); |
||||||
|
} |
||||||
|
return designExtendLanguageConfig; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设计器扩展的语言 |
||||||
|
* key为localeString,例如en_US或en;value为改语言对应的国际化翻译key |
||||||
|
*/ |
||||||
|
@Identifier("extendDesignLocales") |
||||||
|
private MapConf<Map<String, String>> extendDesignLocales = Holders.map(new HashMap<>(), String.class, String.class); |
||||||
|
|
||||||
|
public Map<String, String> getExtendedDesignLocales() { |
||||||
|
return Collections.unmodifiableMap(extendDesignLocales.get()); |
||||||
|
} |
||||||
|
|
||||||
|
public void setExtendedDesignLocales(Map<String, String> map) { |
||||||
|
extendDesignLocales.set(map); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
|
DesignExtendLanguageConfig cloned = (DesignExtendLanguageConfig) super.clone(); |
||||||
|
cloned.extendDesignLocales = ( MapConf<Map<String, String>>) extendDesignLocales.clone(); |
||||||
|
return cloned; |
||||||
|
} |
||||||
|
|
||||||
|
} |
After Width: | Height: | Size: 985 B |
After Width: | Height: | Size: 1.0 KiB |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue