forked from fanruan/design
Hoky
3 years ago
82 changed files with 1356 additions and 419 deletions
@ -1,47 +0,0 @@
|
||||
package com.fr.design.data.tabledata.tabledatapane.db; |
||||
|
||||
import com.fr.data.impl.DBTableData; |
||||
import com.fr.esd.event.DSMapping; |
||||
import com.fr.esd.event.DsNameTarget; |
||||
import com.fr.esd.event.StrategyEventsNotifier; |
||||
import com.fr.esd.event.xml.XMLSavedHook; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
public class DBTableDataSavedHook implements XMLSavedHook<DBTableData> { |
||||
|
||||
private static final long serialVersionUID = 4925391747683335372L; |
||||
|
||||
private final String tplPath; |
||||
private String origName; |
||||
|
||||
private String origConnection; |
||||
|
||||
private String origQuery; |
||||
|
||||
public DBTableDataSavedHook(String tplPath, DBTableData origDBTableData) { |
||||
this.tplPath = tplPath; |
||||
this.origName = origDBTableData.getDsName(); |
||||
this.origConnection = origDBTableData.getDatabase().toString(); |
||||
this.origQuery = origDBTableData.getQuery(); |
||||
} |
||||
|
||||
@Override |
||||
public void doAfterSaved(DBTableData saved) { |
||||
String dsName = saved.getDsName(); |
||||
String conn = saved.getDatabase().toString(); |
||||
String query = saved.getQuery(); |
||||
|
||||
|
||||
//检查数据集名称、数据链接和sql是否修改,如果修改需要触发缓存监听事件
|
||||
if (!dsName.equals(origName) || !conn.equals(origConnection) || !query.equals(origQuery)) { |
||||
if (StringUtils.isNotEmpty(tplPath) && StringUtils.isNotEmpty(origName)) { |
||||
//新建数据集的origName为null,不用触发
|
||||
StrategyEventsNotifier.modifyDataSet(new DSMapping(tplPath, new DsNameTarget(origName))); |
||||
} |
||||
} |
||||
|
||||
this.origName = dsName; |
||||
this.origConnection = conn; |
||||
this.origQuery = query; |
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.fr.design.env; |
||||
|
||||
/** |
||||
* |
||||
* @author hades |
||||
* @version 10.0 |
||||
* Created by hades on 2021/8/24 |
||||
*/ |
||||
public class DesignerWorkspaceInfoContext { |
||||
|
||||
private static DesignerWorkspaceInfo workspaceInfo; |
||||
|
||||
public static DesignerWorkspaceInfo getWorkspaceInfo() { |
||||
return workspaceInfo; |
||||
} |
||||
|
||||
public static void setWorkspaceInfo(DesignerWorkspaceInfo workspaceInfo) { |
||||
DesignerWorkspaceInfoContext.workspaceInfo = workspaceInfo; |
||||
} |
||||
} |
@ -0,0 +1,86 @@
|
||||
package com.fr.design.mainframe.theme; |
||||
|
||||
import com.fr.base.theme.TemplateTheme; |
||||
import com.fr.base.theme.TemplateThemeConfig; |
||||
import com.fr.concurrent.NamedThreadFactory; |
||||
import com.fr.module.ModuleContext; |
||||
|
||||
import java.util.concurrent.ExecutorService; |
||||
|
||||
/** |
||||
* @author Starryi |
||||
* @version 1.0 |
||||
* Created by Starryi on 2021/8/24 |
||||
*/ |
||||
public class AsyncThemeFetcher<T extends TemplateTheme> { |
||||
|
||||
private final ExecutorService executorService; |
||||
private final TemplateThemeConfig<T> config; |
||||
|
||||
public AsyncThemeFetcher(int threads, TemplateThemeConfig<T> config) { |
||||
this.executorService = ModuleContext.getExecutor().newFixedThreadPool( |
||||
threads, |
||||
new NamedThreadFactory(this.getClass().getName()) |
||||
); |
||||
this.config = config; |
||||
} |
||||
|
||||
public void shutdown() { |
||||
executorService.shutdown(); |
||||
} |
||||
|
||||
public boolean isShutdown() { |
||||
return executorService.isShutdown(); |
||||
} |
||||
|
||||
public void submit(String themeName, AsyncThemeFetchCallback<T> callback) { |
||||
callback.beforeCachedFetch(); |
||||
executorService.submit(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
if (executorService.isShutdown()) { |
||||
return; |
||||
} |
||||
T theme = config.cachedFetch(themeName, new TemplateThemeConfig.CacheCondition<T>() { |
||||
@Override |
||||
public boolean shouldCacheTheme(T theme) { |
||||
return callback.shouldCache(AsyncThemeFetcher.this, theme); |
||||
} |
||||
}); |
||||
if (executorService.isShutdown()) { |
||||
return; |
||||
} |
||||
callback.afterCachedFetch(theme); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public interface AsyncThemeFetchCallback<T extends TemplateTheme> { |
||||
void beforeCachedFetch(); |
||||
boolean shouldCache(AsyncThemeFetcher<T> fetcher, T theme); |
||||
void afterCachedFetch(T theme); |
||||
} |
||||
|
||||
public static class AsyncThemeFetchCallbackAdapter<T extends TemplateTheme> implements AsyncThemeFetchCallback<T> { |
||||
|
||||
@Override |
||||
public void beforeCachedFetch() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public boolean shouldCache(AsyncThemeFetcher<T> fetcher, T theme) { |
||||
// 如果Fetcher已经关闭就不放进缓存里了
|
||||
// 因为可切换工作目录,所以submit时的工作目录环境与最终获取到主题数据时的工作目录环境可能不是同一个,
|
||||
// 如果仍然放进缓存中,会污染当前工作目录环境的主题缓存.
|
||||
// TODO: 除了根据asyncThemeFetch的关闭情况来判断是否缓存主题,也可以更加精细的判断前后的工作目录环境是否时同一个
|
||||
// TODO: 后续看情况再优化吧.
|
||||
return !fetcher.isShutdown(); |
||||
} |
||||
|
||||
@Override |
||||
public void afterCachedFetch(T theme) { |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,243 @@
|
||||
package com.fr.design.style.background.gradient; |
||||
|
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.style.background.BackgroundJComponent; |
||||
import com.fr.general.Background; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JWindow; |
||||
import javax.swing.SwingUtilities; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.awt.AWTEvent; |
||||
import java.awt.Dimension; |
||||
import java.awt.Point; |
||||
import java.awt.Rectangle; |
||||
import java.awt.Toolkit; |
||||
import java.awt.Window; |
||||
import java.awt.event.AWTEventListener; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
/** |
||||
* @author Bjorn |
||||
* @version 10.0 |
||||
* Created by Bjorn on 2021-08-24 |
||||
*/ |
||||
public abstract class AbstractComponentPopBox extends JComponent { |
||||
|
||||
protected BackgroundJComponent displayComponent; |
||||
|
||||
private JWindow selectPopupWindow; |
||||
private boolean isWindowEventInit = false; |
||||
private static int GAP = 2; |
||||
private static int GAP2 = 20; |
||||
|
||||
private List<ChangeListener> changeListenerList = new ArrayList<ChangeListener>(); |
||||
|
||||
MouseAdapter mouseListener = new MouseAdapter() { |
||||
public void mousePressed(MouseEvent evt) { |
||||
showPopupMenu(); |
||||
} |
||||
|
||||
|
||||
}; |
||||
|
||||
AWTEventListener awt = new AWTEventListener() { |
||||
public void eventDispatched(AWTEvent event) { |
||||
if (event instanceof MouseEvent) { |
||||
MouseEvent evt = (MouseEvent) event; |
||||
if (evt.getClickCount() > 0) { |
||||
mouseClick(evt); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
|
||||
protected void showPopupMenu() { |
||||
if (selectPopupWindow != null && selectPopupWindow.isVisible()) { |
||||
hidePopupMenu(); |
||||
return; |
||||
} |
||||
|
||||
if (!this.isEnabled()) { |
||||
return; |
||||
} |
||||
Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK); |
||||
|
||||
selectPopupWindow = this.getControlWindow(); |
||||
|
||||
Point convertPoint = new Point(0, 0); |
||||
|
||||
// e: 将点(0,0)从ColorSelectionPane的坐标系统转换到屏幕坐标.
|
||||
SwingUtilities.convertPointToScreen(convertPoint, this); |
||||
int y = convertPoint.y + this.getSize().height; |
||||
int x = convertPoint.x; |
||||
int h = y + selectPopupWindow.getHeight(); |
||||
int width = x + selectPopupWindow.getWidth(); |
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
||||
if (h > screenSize.height) { |
||||
y = y - selectPopupWindow.getHeight() - GAP2;// 超过屏幕高度了
|
||||
} |
||||
|
||||
if (width > screenSize.width) { |
||||
x = screenSize.width - selectPopupWindow.getWidth(); |
||||
} |
||||
selectPopupWindow.setLocation(x, y); |
||||
|
||||
selectPopupWindow.setVisible(true); |
||||
|
||||
//wei : 为了点击别的地方下拉颜色窗口消失
|
||||
MouseAdapter parentMouseListener = new MouseAdapter() { |
||||
public void mousePressed(MouseEvent evt) { |
||||
mouseClick(evt); |
||||
} |
||||
}; |
||||
if (!this.isWindowEventInit && SwingUtilities.getAncestorOfClass(GradientBackgroundPane.class, this) != null) { |
||||
SwingUtilities.getAncestorOfClass(GradientBackgroundPane.class, this).addMouseListener(parentMouseListener); |
||||
this.isWindowEventInit = true; |
||||
} |
||||
} |
||||
|
||||
private void mouseClick(MouseEvent evt) { |
||||
Point point = new Point((int) (evt.getLocationOnScreen().getX()), (int) evt.getLocationOnScreen().getY()); |
||||
Dimension popBoxD = AbstractComponentPopBox.this.getSize(); |
||||
try { |
||||
Point popBoxP = AbstractComponentPopBox.this.getLocationOnScreen(); |
||||
Dimension popMenuD = this.getControlWindow().getSize(); |
||||
Point popMenuP = this.getControlWindow().getLocation(); |
||||
Rectangle popBoxRect = new Rectangle(popBoxP, popBoxD); |
||||
Rectangle popMenuRect = new Rectangle(popMenuP, popMenuD); |
||||
if (!popBoxRect.contains(point) && !popMenuRect.contains(point)) { |
||||
this.hidePopupMenu(); |
||||
} |
||||
} catch (Exception ignore) { |
||||
this.hidePopupMenu(); |
||||
} |
||||
} |
||||
|
||||
protected void hidePopupMenu() { |
||||
if (selectPopupWindow != null) { |
||||
selectPopupWindow.setVisible(false); |
||||
} |
||||
|
||||
selectPopupWindow = null; |
||||
Toolkit.getDefaultToolkit().removeAWTEventListener(awt); |
||||
} |
||||
|
||||
protected JWindow getControlWindow() { |
||||
//find parent.
|
||||
if (this.selectPopupWindow == null) { |
||||
Window parentWindow = SwingUtilities.windowForComponent(this); |
||||
if (parentWindow != null) { |
||||
this.selectPopupWindow = new AbstractComponentPopBox.SelectControlWindow(parentWindow); |
||||
} |
||||
|
||||
selectPopupWindow.addMouseListener(new MouseAdapter() { |
||||
public void mouseExited(MouseEvent evt) { |
||||
int x = evt.getLocationOnScreen().x; |
||||
int y = evt.getLocationOnScreen().y; |
||||
|
||||
if (selectPopupWindow != null) { |
||||
double desValue = 2; |
||||
Rectangle rectangle = selectPopupWindow.getBounds(); |
||||
boolean b1 = x < rectangle.x + desValue || x >= rectangle.x + rectangle.width - desValue; |
||||
boolean b2 = y > rectangle.y + rectangle.height - desValue;//避免了鼠标下移刚进入selectPopupWindow的过程中弹出框隐藏,上移移出后由AbstractPopBox的mouseListener处理
|
||||
if (b1 || b2) { |
||||
hidePopupMenu(); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
return selectPopupWindow; |
||||
} |
||||
|
||||
/** |
||||
* 添加事件 |
||||
* |
||||
* @param changeListener 事件 |
||||
*/ |
||||
public void addSelectChangeListener(ChangeListener changeListener) { |
||||
this.changeListenerList.add(changeListener); |
||||
} |
||||
|
||||
/** |
||||
* 删除事件 |
||||
* |
||||
* @param changeListener 事件 |
||||
*/ |
||||
public void removeSelectChangeListener(ChangeListener changeListener) { |
||||
this.changeListenerList.remove(changeListener); |
||||
} |
||||
|
||||
/** |
||||
* 响应事件 |
||||
*/ |
||||
public void fireChangeListener() { |
||||
if (!changeListenerList.isEmpty()) { |
||||
ChangeEvent evt = new ChangeEvent(this); |
||||
for (int i = 0; i < changeListenerList.size(); i++) { |
||||
this.changeListenerList.get(i).stateChanged(evt); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 待说明 |
||||
* |
||||
* @param background 背景 |
||||
*/ |
||||
public void fireDisplayComponent(Background background) { |
||||
if (displayComponent != null) { |
||||
displayComponent.setSelfBackground(background); |
||||
} |
||||
fireChangeListener(); |
||||
this.repaint(); |
||||
} |
||||
|
||||
/** |
||||
* 初始化弹出框的面板 |
||||
* |
||||
* @param preWidth 宽度 |
||||
* @return 弹出面板 |
||||
*/ |
||||
public abstract JPanel initWindowPane(double preWidth); |
||||
|
||||
private class SelectControlWindow extends JWindow { |
||||
private static final long serialVersionUID = -5776589767069105911L; |
||||
|
||||
public SelectControlWindow(Window paranet) { |
||||
super(paranet); |
||||
this.initComponents(); |
||||
} |
||||
|
||||
public void initComponents() { |
||||
JPanel defaultPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
this.setContentPane(defaultPane); |
||||
|
||||
// defaultPane.setBorder(UIManager.getBorder("PopupMenu.border"));
|
||||
|
||||
if (displayComponent != null) { |
||||
defaultPane.add(initWindowPane(displayComponent.getPreferredSize().getWidth())); |
||||
} else { |
||||
defaultPane.add(initWindowPane(20)); |
||||
} |
||||
this.pack(); |
||||
} |
||||
|
||||
@Override |
||||
public void setVisible(boolean b) { |
||||
super.setVisible(b); |
||||
AbstractComponentPopBox.this.repaint(); |
||||
} |
||||
} |
||||
|
||||
protected boolean isPopupVisible() { |
||||
return selectPopupWindow == null ? false : selectPopupWindow.isVisible(); |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.fr.design.designer.beans.actions.behavior; |
||||
|
||||
import com.fr.design.designer.beans.actions.FormWidgetEditAction; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
|
||||
public class CopyableEnable implements UpdateBehavior<FormWidgetEditAction> { |
||||
@Override |
||||
public void doUpdate(FormWidgetEditAction action) { |
||||
FormDesigner designer = action.getEditingComponent(); |
||||
if (designer == null) { |
||||
action.setEnabled(false); |
||||
return; |
||||
} |
||||
action.setEnabled(designer.isCurrentComponentCopyable()); |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.fr.design.designer.beans.actions.behavior; |
||||
|
||||
import com.fr.design.designer.beans.actions.FormWidgetEditAction; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
|
||||
public class CutableEnable implements UpdateBehavior<FormWidgetEditAction> { |
||||
@Override |
||||
public void doUpdate(FormWidgetEditAction action) { |
||||
FormDesigner designer = action.getEditingComponent(); |
||||
if (designer == null) { |
||||
action.setEnabled(false); |
||||
return; |
||||
} |
||||
action.setEnabled(designer.isCurrentComponentCutable()); |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
package com.fr.design.designer.beans.actions.behavior; |
||||
|
||||
import com.fr.design.designer.beans.actions.FormWidgetEditAction; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
|
||||
public class DeletableEnable implements UpdateBehavior<FormWidgetEditAction> { |
||||
@Override |
||||
public void doUpdate(FormWidgetEditAction action) { |
||||
FormDesigner designer = action.getEditingComponent(); |
||||
if (designer == null) { |
||||
action.setEnabled(false); |
||||
return; |
||||
} |
||||
action.setEnabled(designer.isCurrentComponentDeletable()); |
||||
} |
||||
} |
@ -0,0 +1,26 @@
|
||||
package com.fr.design.actions.cell; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.menu.KeySetUtils; |
||||
import com.fr.general.IOUtils; |
||||
|
||||
/** |
||||
* @author Starryi |
||||
* @version 1.0 |
||||
* Created by Starryi on 2021/8/26 |
||||
*/ |
||||
public class CellStyleAttrAction extends CellAttributeTableAction { |
||||
|
||||
public CellStyleAttrAction() { |
||||
this.setMenuKeySet(KeySetUtils.GLOBAL_STYLE); |
||||
this.setName(getMenuKeySet().getMenuKeySetName()); |
||||
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||
this.setSmallIcon(IOUtils.readIcon("/com/fr/design/images/m_format/cell.png")); |
||||
} |
||||
|
||||
@Override |
||||
protected String getID() { |
||||
return Toolkit.i18nText("Fine-Design_Form_Widget_Style"); |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.fr.design.actions.cell; |
||||
|
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.CellElementPropertyPane; |
||||
|
||||
import java.awt.event.ActionEvent; |
||||
|
||||
/** |
||||
* @author Starryi |
||||
* @version 1.0 |
||||
* Created by Starryi on 2021/8/26 |
||||
*/ |
||||
public class CustomCellStyleAction extends CellStyleAttrAction { |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
CellElementPropertyPane.getInstance().GoToPane( |
||||
Toolkit.i18nText("Fine-Design_Report_Engine_Style"), |
||||
Toolkit.i18nText("Fine-Design_Report_Engine_Custom") |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue