Browse Source

Pull request #4289: 无jira任务 feature/10.0合feature/x

Merge in DESIGN/design from ~TOMMY/design:feature/x to feature/x

* commit 'acbec8eb98ce28cf910b5d13ac31894cdaa3a87d':
  REPORT-52411 && REPORT-52222 设计器吃资源cpu和gpu
  REPORT-52418   国际化适配
  REPORT-51678 复用组件插件合并主jar
  REPORT-51678 复用组件合并主jar国际化
  REPORT-52151 控件事件支持重命名开发
  REPORT-51678 组件复用插件代码合并主jar
research/11.0
ju|剧浩宇 4 years ago
parent
commit
0fe1f8e99c
  1. 5
      designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java
  2. 5
      designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java
  3. 38
      designer-base/src/main/java/com/fr/design/gui/controlpane/CommonShortCutHandlers.java
  4. 144
      designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneHelper.java
  5. 10
      designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java
  6. 130
      designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java
  7. 22
      designer-base/src/main/java/com/fr/design/gui/controlpane/UINameableListCellRenderer.java
  8. 3
      designer-base/src/main/java/com/fr/design/mainframe/OpenLoadingPane.java
  9. 6
      designer-base/src/main/java/com/fr/design/os/impl/PopupDialogSaveAction.java
  10. 12
      designer-base/src/main/java/com/fr/design/widget/EventCreator.java
  11. 41
      designer-base/src/test/java/com/fr/design/gui/controlpane/ListControlPaneHelperTest.java
  12. 6
      designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java
  13. 25
      designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java
  14. 54
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  15. 1
      designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java
  16. 36
      designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java
  17. 77
      designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java
  18. 6
      designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java
  19. 80
      designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java
  20. 533
      designer-form/src/main/java/com/fr/design/gui/controlpane/EventPropertyPane.java
  21. 129
      designer-form/src/main/java/com/fr/design/mainframe/CoverPane.java
  22. 174
      designer-form/src/main/java/com/fr/design/mainframe/CoverReportPane.java
  23. 133
      designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java
  24. 4
      designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java
  25. 420
      designer-form/src/main/java/com/fr/design/mainframe/FormWidgetDetailPane.java
  26. 314
      designer-form/src/main/java/com/fr/design/mainframe/ShareWidgetButton.java
  27. 29
      designer-form/src/main/java/com/fr/design/mainframe/ShareWidgetPane.java
  28. 11
      designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java
  29. 62
      designer-form/src/main/java/com/fr/design/mainframe/share/AbstractWidgetSelectPane.java
  30. 59
      designer-form/src/main/java/com/fr/design/mainframe/share/Bean/ComponentGenerateInfo.java
  31. 114
      designer-form/src/main/java/com/fr/design/mainframe/share/Bean/LinkageChangeBean.java
  32. 398
      designer-form/src/main/java/com/fr/design/mainframe/share/action/CreateComponentAction.java
  33. 163
      designer-form/src/main/java/com/fr/design/mainframe/share/action/InstallComponentAction.java
  34. 9
      designer-form/src/main/java/com/fr/design/mainframe/share/action/ShareUIAspect.java
  35. 89
      designer-form/src/main/java/com/fr/design/mainframe/share/collect/CollectorManager.java
  36. 541
      designer-form/src/main/java/com/fr/design/mainframe/share/collect/ComponentCollector.java
  37. 45
      designer-form/src/main/java/com/fr/design/mainframe/share/collect/ComponentSender.java
  38. 18
      designer-form/src/main/java/com/fr/design/mainframe/share/constants/ComponentType.java
  39. 193
      designer-form/src/main/java/com/fr/design/mainframe/share/constants/ComponentTypes.java
  40. 66
      designer-form/src/main/java/com/fr/design/mainframe/share/constants/DisplayDevice.java
  41. 6
      designer-form/src/main/java/com/fr/design/mainframe/share/constants/ShareEntryKey.java
  42. 81
      designer-form/src/main/java/com/fr/design/mainframe/share/constants/StyleTheme.java
  43. 14
      designer-form/src/main/java/com/fr/design/mainframe/share/exception/LackOfValueException.java
  44. 9
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/AbstractComponentTask.java
  45. 14
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentBanner.java
  46. 20
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentCreatorProcessor.java
  47. 22
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentGenerator.java
  48. 68
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentGeneratorCenter.java
  49. 13
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentTask.java
  50. 26
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentTaskAdaptor.java
  51. 24
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/impl/AbstractComponentCreatorProcessor.java
  52. 161
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/impl/AbstractComponentGenerator.java
  53. 57
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/impl/ComponentPureGenerator.java
  54. 99
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/impl/ComponentUploadGenerator.java
  55. 114
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java
  56. 44
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentDesensitize.java
  57. 28
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentEncrypt.java
  58. 19
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentGenerateComplete.java
  59. 19
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentUploadComplete.java
  60. 153
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentUploader.java
  61. 59
      designer-form/src/main/java/com/fr/design/mainframe/share/group/ui/BaseGroupDialog.java
  62. 173
      designer-form/src/main/java/com/fr/design/mainframe/share/group/ui/GroupFileDialog.java
  63. 79
      designer-form/src/main/java/com/fr/design/mainframe/share/group/ui/GroupMoveDialog.java
  64. 25
      designer-form/src/main/java/com/fr/design/mainframe/share/select/ComponentTransformer.java
  65. 53
      designer-form/src/main/java/com/fr/design/mainframe/share/select/ComponentTransformerFactory.java
  66. 156
      designer-form/src/main/java/com/fr/design/mainframe/share/select/ComponentTransformerImpl.java
  67. 112
      designer-form/src/main/java/com/fr/design/mainframe/share/select/TransformerKey.java
  68. 153
      designer-form/src/main/java/com/fr/design/mainframe/share/sort/OnlineWidgetSortType.java
  69. 12
      designer-form/src/main/java/com/fr/design/mainframe/share/sort/SortType.java
  70. 55
      designer-form/src/main/java/com/fr/design/mainframe/share/sort/WidgetSortType.java
  71. 91
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ChartIcon.java
  72. 92
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/DictionaryComboCheckBox.java
  73. 129
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/DownloadProgressPane.java
  74. 58
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/FailureMessagePane.java
  75. 172
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/FlexSearchFieldPane.java
  76. 226
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ImageBackgroundPane.java
  77. 28
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ImagePanel.java
  78. 129
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ImitationProgress.java
  79. 44
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/LeftWordsTextArea.java
  80. 49
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/LoadingPane.java
  81. 34
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/MouseClickListener.java
  82. 41
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/NoMatchPane.java
  83. 128
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PageableButton.java
  84. 213
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PagingFiledPane.java
  85. 42
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PlaceholderTextArea.java
  86. 31
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PopupMenuItem.java
  87. 83
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PopupPreviewPane.java
  88. 231
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ShareProgressBar.java
  89. 104
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/SortPopupMenuItem.java
  90. 48
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ui/PlaceHolderUI.java
  91. 82
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ui/SharePopupMenuItemUI.java
  92. 94
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java
  93. 72
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/DragAndDropDragGestureListener.java
  94. 313
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java
  95. 303
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java
  96. 57
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetPackageBlock.java
  97. 138
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/PreviewWidgetBlock.java
  98. 17
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/SimpleWidgetBlock.java
  99. 380
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/GroupPane.java
  100. 87
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/LocalPaneStatus.java
  101. Some files were not shown because too many files have changed in this diff Show More

5
designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java

@ -74,6 +74,7 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
private String originalCharSet = null; private String originalCharSet = null;
private JPanel mainPanel; private JPanel mainPanel;
// Database pane // Database pane
public DatabaseConnectionPane() { public DatabaseConnectionPane() {
this.initComponents(); this.initComponents();
@ -122,7 +123,7 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
driverTips.setText(Toolkit.i18nText("Fine_Designer_Not_Found_Driver")); driverTips.setText(Toolkit.i18nText("Fine_Designer_Not_Found_Driver"));
gridJpanel.add(driverTips); gridJpanel.add(driverTips);
UILabel deatail = new UILabel(); UILabel deatail = new UILabel();
String content = Toolkit.i18nText("Fine_Designer_Not_Found") + select.getResultException().getDetailMessage() + Toolkit.i18nText("Fine_Designer_Driver"); String content = Toolkit.i18nText("Fine_Designer_Not_Found") + " " + select.getResultException().getDetailMessage() + " " + Toolkit.i18nText("Fine_Designer_Driver");
deatail.setText(content); deatail.setText(content);
deatail.setToolTipText(content); deatail.setToolTipText(content);
gridJpanel.add(deatail); gridJpanel.add(deatail);
@ -422,7 +423,7 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
private static JNDIDefPane jndiDefPane = new JNDIDefPane(); private static JNDIDefPane jndiDefPane = new JNDIDefPane();
@Override @Override
protected JPanel mainPanel() { protected JPanel mainPanel() {
return jndiDefPane; return jndiDefPane;
} }

5
designer-base/src/main/java/com/fr/design/file/MutilTempalteTabPane.java

@ -19,6 +19,7 @@ import com.fr.design.worker.WorkerManager;
import com.fr.design.worker.save.CallbackSaveWorker; import com.fr.design.worker.save.CallbackSaveWorker;
import com.fr.file.FILE; import com.fr.file.FILE;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import com.fr.third.javax.annotation.Nonnull; import com.fr.third.javax.annotation.Nonnull;
@ -70,8 +71,8 @@ public class MutilTempalteTabPane extends JComponent {
private static Icon CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/close_icon.png"); private static Icon CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/close_icon.png");
private static Icon MOUSE_OVER_CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/mouseoverclose icon.png"); private static Icon MOUSE_OVER_CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/mouseoverclose icon.png");
private static Icon MOUSE_PRESS_CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/pressclose icon.png"); private static Icon MOUSE_PRESS_CLOSE = BaseUtils.readIcon("/com/fr/design/images/buttonicon/pressclose icon.png");
private static final Icon WHITE_SAVING_CLOSE_ICON = new ImageIcon(MutilTempalteTabPane.class.getResource("/com/fr/design/images/file/white_saving_close.gif")); private static final Icon WHITE_SAVING_CLOSE_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/file/white_saving_close.gif"));
private static final Icon GREY_SAVING_CLOSE_ICON = new ImageIcon(MutilTempalteTabPane.class.getResource("/com/fr/design/images/file/grey_saving_close.gif")); private static final Icon GREY_SAVING_CLOSE_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/file/grey_saving_close.gif"));
private static final String ELLIPSIS = "..."; private static final String ELLIPSIS = "...";
private static final int GAP = 5; private static final int GAP = 5;
private static final int SMALLGAP = 3; private static final int SMALLGAP = 3;

38
designer-base/src/main/java/com/fr/design/gui/controlpane/CommonShortCutHandlers.java

@ -21,11 +21,9 @@ import java.util.Comparator;
*/ */
public class CommonShortCutHandlers { public class CommonShortCutHandlers {
ListControlPaneProvider listControlPane; ListControlPaneProvider listControlPane;
JNameEdList nameableList;
private CommonShortCutHandlers(ListControlPaneProvider listControlPane) { private CommonShortCutHandlers(ListControlPaneProvider listControlPane) {
this.listControlPane = listControlPane; this.listControlPane = listControlPane;
this.nameableList = listControlPane.getNameableList();
} }
public static CommonShortCutHandlers newInstance(ListControlPaneProvider listControlPane) { public static CommonShortCutHandlers newInstance(ListControlPaneProvider listControlPane) {
@ -43,19 +41,19 @@ public class CommonShortCutHandlers {
public void onRemoveItem() { public void onRemoveItem() {
try { try {
nameableList.getCellEditor() listControlPane.getNameableList().getCellEditor()
.stopCellEditing(); .stopCellEditing();
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities
.getWindowAncestor((Component) listControlPane), nameableList)) { .getWindowAncestor((Component) listControlPane), listControlPane.getNameableList())) {
listControlPane.checkButtonEnabled(); listControlPane.checkButtonEnabled();
} }
} }
public void onCopyItem() { public void onCopyItem() {
// p:选中的值. // p:选中的值.
ListModelElement selectedValue = (ListModelElement) nameableList.getSelectedValue(); ListModelElement selectedValue = (ListModelElement) listControlPane.getNameableList().getSelectedValue();
if (selectedValue == null) { if (selectedValue == null) {
return; return;
} }
@ -76,47 +74,51 @@ public class CommonShortCutHandlers {
} }
public void onMoveUpItem() { public void onMoveUpItem() {
int selectedIndex = nameableList.getSelectedIndex(); int selectedIndex = listControlPane.getNameableList().getSelectedIndex();
if (selectedIndex == -1) { if (selectedIndex == -1) {
return; return;
} }
// 上移 // 上移
if (selectedIndex > 0) { if (selectedIndex > 0) {
DefaultListModel listModel = (DefaultListModel) nameableList.getModel(); DefaultListModel listModel = (DefaultListModel) listControlPane.getNameableList().getModel();
Object selecteObj1 = listModel.get(selectedIndex - 1); Object selecteObj1 = listModel.get(selectedIndex - 1);
listModel.set(selectedIndex - 1, listModel.get(selectedIndex)); listModel.set(selectedIndex - 1, listModel.get(selectedIndex));
listModel.set(selectedIndex, selecteObj1); listModel.set(selectedIndex, selecteObj1);
nameableList.setSelectedIndex(selectedIndex - 1); listControlPane.getNameableList().setSelectedIndex(selectedIndex - 1);
nameableList.ensureIndexIsVisible(selectedIndex - 1); listControlPane.getNameableList().ensureIndexIsVisible(selectedIndex - 1);
} }
} }
public void onMoveDownItem() { public void onMoveDownItem() {
int selectedIndex = nameableList.getSelectedIndex(); int selectedIndex = listControlPane.getNameableList().getSelectedIndex();
if (selectedIndex == -1) { if (selectedIndex == -1) {
return; return;
} }
if (selectedIndex < nameableList.getModel().getSize() - 1) { if (selectedIndex < listControlPane.getNameableList().getModel().getSize() - 1) {
DefaultListModel listModel = (DefaultListModel) nameableList DefaultListModel listModel = (DefaultListModel) listControlPane.getNameableList()
.getModel(); .getModel();
Object selecteObj1 = listModel.get(selectedIndex + 1); Object selecteObj1 = listModel.get(selectedIndex + 1);
listModel.set(selectedIndex + 1, listModel.get(selectedIndex)); listModel.set(selectedIndex + 1, listModel.get(selectedIndex));
listModel.set(selectedIndex, selecteObj1); listModel.set(selectedIndex, selecteObj1);
nameableList.setSelectedIndex(selectedIndex + 1); listControlPane.getNameableList().setSelectedIndex(selectedIndex + 1);
nameableList.ensureIndexIsVisible(selectedIndex + 1); listControlPane.getNameableList().ensureIndexIsVisible(selectedIndex + 1);
} }
} }
public void onSortItem(boolean isAtoZ) { public void onSortItem(boolean isAtoZ) {
onSortItem(isAtoZ, listControlPane.getNameableList());
}
public void onSortItem(boolean isAtoZ, JNameEdList nameEdList) {
// p:选中的值. // p:选中的值.
Object selectedValue = nameableList.getSelectedValue(); Object selectedValue = nameEdList.getSelectedValue();
DefaultListModel listModel = (DefaultListModel) nameableList DefaultListModel listModel = (DefaultListModel) nameEdList
.getModel(); .getModel();
Nameable[] nameableArray = new Nameable[listModel.getSize()]; Nameable[] nameableArray = new Nameable[listModel.getSize()];
if (nameableArray.length <= 0) { if (nameableArray.length <= 0) {
@ -156,12 +158,12 @@ public class CommonShortCutHandlers {
// p:需要选中以前的那个值. // p:需要选中以前的那个值.
if (selectedValue != null) { if (selectedValue != null) {
nameableList.setSelectedValue(selectedValue, true); nameEdList.setSelectedValue(selectedValue, true);
} }
listControlPane.checkButtonEnabled(); listControlPane.checkButtonEnabled();
// p:需要repaint. // p:需要repaint.
nameableList.repaint(); nameEdList.repaint();
} }
private String createUnrepeatedCopyName(String suffix) { private String createUnrepeatedCopyName(String suffix) {

144
designer-base/src/main/java/com/fr/design/gui/controlpane/ListControlPaneHelper.java

@ -4,18 +4,41 @@ import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.ilist.JNameEdList; import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.gui.ilist.UINameEdList;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.os.impl.PopupDialogSaveAction;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.form.event.Listener;
import com.fr.general.NameObject;
import com.fr.stable.Nameable; import com.fr.stable.Nameable;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.os.support.OSSupportCenter;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.JOptionPane; import javax.swing.JList;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import java.awt.Component; import java.awt.Component;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* 存放一些公用的方法 * 存放一些公用的方法
* Created by plough on 2018/8/13. * Created by plough on 2018/8/13.
*/ */
class ListControlPaneHelper { class ListControlPaneHelper {
private static final int EDIT_RANGE = 25; // 编辑按钮的x坐标范围
private ListControlPaneProvider listControlPane; private ListControlPaneProvider listControlPane;
private ListControlPaneHelper(ListControlPaneProvider listControlPane) { private ListControlPaneHelper(ListControlPaneProvider listControlPane) {
@ -110,4 +133,123 @@ class ListControlPaneHelper {
} }
protected void popupEditDialog(Point mousePos, UINameEdList nameableList, UIControlPane controlPane) {
int editingIndex = nameableList.getSelectedIndex();
Rectangle currentCellBounds = nameableList.getCellBounds(editingIndex, editingIndex);
if (editingIndex < 0 || (mousePos != null && !currentCellBounds.contains(mousePos))) {
return;
}
Window popupEditDialog = controlPane.getPopupEditDialog();
popupEditDialog.setLocation(getPopupDialogLocation(nameableList, popupEditDialog));
if (popupEditDialog instanceof UIControlPane.PopupEditDialog) {
((UIControlPane.PopupEditDialog) popupEditDialog).setTitle(getSelectedName());
}
popupEditDialog.setVisible(true);
PopupDialogSaveAction osBasedAction = OSSupportCenter.getAction(PopupDialogSaveAction.class);
osBasedAction.register(controlPane, popupEditDialog);
}
private Point getPopupDialogLocation(UINameEdList nameableList, Window popupEditDialog) {
Point resultPos = new Point(0, 0);
Point listPos = nameableList.getLocationOnScreen();
resultPos.x = listPos.x - popupEditDialog.getWidth();
resultPos.y = listPos.y + (nameableList.getSelectedIndex() - 1) * EDIT_RANGE;
// 当对象在屏幕上的位置比较靠下时,往下移动弹窗至与属性面板平齐
Window frame = DesignerContext.getDesignerFrame();
// 不能太低
int maxY = frame.getLocationOnScreen().y + frame.getHeight() - popupEditDialog.getHeight();
if (resultPos.y > maxY) {
resultPos.y = maxY;
}
// 也不能太高
int minY = frame.getLocationOnScreen().y + EDIT_RANGE;
if (resultPos.y < minY) {
resultPos.y = minY;
}
// 当在左侧显示不下时,在右侧弹出弹窗
if (resultPos.x < 0) {
resultPos.x = listPos.x + nameableList.getParent().getWidth();
}
// 如果右侧显示不下,可以向左移动
int maxX = frame.getLocationOnScreen().x + frame.getWidth() - popupEditDialog.getWidth() - EDIT_RANGE;
if (resultPos.x > maxX) {
resultPos.x = maxX;
}
return resultPos;
}
/*
* UINameEdList的鼠标事件
*/
protected MouseListener getListMouseListener(UINameEdList nameableList, UIControlPane controlPane) {
return new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent evt) {
nameableList.stopEditing();
if (evt.getClickCount() >= 2
&& SwingUtilities.isLeftMouseButton(evt) && evt.getX() > EDIT_RANGE) {
nameableList.editItemAt(nameableList.getSelectedIndex());
} else if (SwingUtilities.isLeftMouseButton(evt) && evt.getX() <= EDIT_RANGE) {
popupEditDialog(evt.getPoint(), nameableList, controlPane);
}
// peter:处理右键的弹出菜单
if (!SwingUtilities.isRightMouseButton(evt)) {
return;
}
// peter: 注意,在checkButtonEnabled()方法里面,设置了所有的Action的Enabled.
checkButtonEnabled();
// p:右键菜单.
JPopupMenu popupMenu = new JPopupMenu();
for (ShortCut4JControlPane sj : listControlPane.getShorts()) {
sj.getShortCut().intoJPopupMenu(popupMenu);
}
// peter: 只有弹出菜单有子菜单的时候,才需要弹出来.
GUICoreUtils.showPopupMenu(popupMenu, nameableList, evt.getX() - 1,
evt.getY() - 1);
}
@Override
public void mouseClicked(MouseEvent e) {
JList list = (JList) e.getSource();
if (list.locationToIndex(e.getPoint()) == -1 && !e.isShiftDown()
&& !isMenuShortcutKeyDown(e)) {
list.clearSelection();
}
}
private boolean isMenuShortcutKeyDown(InputEvent event) {
return (event.getModifiers() & Toolkit.getDefaultToolkit()
.getMenuShortcutKeyMask()) != 0;
}
@Override
public void mouseMoved(MouseEvent e) {
}
};
}
public Map<String, List<NameObject>> processCatalog(List<NameObject> nameObjectList) {
Map<String, List<NameObject>> map = new HashMap<>();
for (NameObject nameObject : nameObjectList) {
Listener listener = (Listener) nameObject.getObject();
if (StringUtils.isNotEmpty(listener.getName())) {
nameObject.setName(listener.getName());
}
List<NameObject> list = map.computeIfAbsent(listener.getEventName(), k -> new ArrayList<>());
list.add(nameObject);
}
return map;
}
} }

10
designer-base/src/main/java/com/fr/design/gui/controlpane/UIControlPane.java

@ -49,7 +49,7 @@ import java.awt.event.WindowEvent;
/** /**
* Created by plough on 2017/7/21. * Created by plough on 2017/7/21.
*/ */
abstract class UIControlPane extends JControlPane { public abstract class UIControlPane extends JControlPane {
private UIToolbar topToolBar; private UIToolbar topToolBar;
protected Window popupEditDialog; protected Window popupEditDialog;
private static final int TOP_TOOLBAR_HEIGHT = 20; private static final int TOP_TOOLBAR_HEIGHT = 20;
@ -78,7 +78,7 @@ abstract class UIControlPane extends JControlPane {
initCardPane(); initCardPane();
if (isNewStyle()) { if (isNewStyle()) {
getPopupEditDialog(cardPane); createPopupEditDialog(cardPane);
this.add(getLeftPane(), BorderLayout.CENTER); this.add(getLeftPane(), BorderLayout.CENTER);
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 15, 10)); this.setBorder(BorderFactory.createEmptyBorder(10, 10, 15, 10));
} else { } else {
@ -100,7 +100,11 @@ abstract class UIControlPane extends JControlPane {
this.checkButtonEnabled(); this.checkButtonEnabled();
} }
private void getPopupEditDialog(JPanel cardPane) { protected Window getPopupEditDialog(){
return this.popupEditDialog;
}
private void createPopupEditDialog(JPanel cardPane) {
popupEditDialog = new PopupEditDialog(cardPane); popupEditDialog = new PopupEditDialog(cardPane);
} }

130
designer-base/src/main/java/com/fr/design/gui/controlpane/UIListControlPane.java

@ -6,32 +6,18 @@ import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilist.JNameEdList; import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.gui.ilist.UINameEdList; import com.fr.design.gui.ilist.UINameEdList;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.os.impl.PopupDialogSaveAction;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.Nameable; import com.fr.stable.Nameable;
import com.fr.stable.os.support.OSSupportCenter;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener; import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -41,11 +27,8 @@ import java.lang.reflect.InvocationTargetException;
public abstract class UIListControlPane extends UIControlPane implements ListControlPaneProvider { public abstract class UIListControlPane extends UIControlPane implements ListControlPaneProvider {
private static final String LIST_NAME = "UIControl_List"; private static final String LIST_NAME = "UIControl_List";
private static final int EDIT_RANGE = 25; // 编辑按钮的x坐标范围
protected UINameEdList nameableList; protected UINameEdList nameableList;
private int editingIndex;
protected String selectedName;
protected boolean isPopulating = false; protected boolean isPopulating = false;
private CommonShortCutHandlers commonHandlers; private CommonShortCutHandlers commonHandlers;
private ListControlPaneHelper helper; private ListControlPaneHelper helper;
@ -93,7 +76,7 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon
nameableList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); nameableList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
nameableList.addMouseListener(getListMouseListener()); nameableList.addMouseListener(getHelper().getListMouseListener(nameableList, this));
nameableList.addListSelectionListener(new ListSelectionListener() { nameableList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) { public void valueChanged(ListSelectionEvent evt) {
// richie:避免多次update和populate大大降低效率 // richie:避免多次update和populate大大降低效率
@ -139,7 +122,7 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon
saveSettings(); saveSettings();
} }
}; };
nameEdList.setCellRenderer(new UINameableListCellRenderer(this)); nameEdList.setCellRenderer(new UINameableListCellRenderer(this.isNewStyle(), this.creators));
return nameEdList; return nameEdList;
} }
@ -181,13 +164,6 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon
} }
/**
* 获取选中的名字
*/
public String getSelectedName() {
return getHelper().getSelectedName();
}
/** /**
* 添加 Nameable * 添加 Nameable
* *
@ -209,51 +185,10 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon
protected void popupEditDialog(Point mousePos) { protected void popupEditDialog(Point mousePos) {
if (isNewStyle()) { if (isNewStyle()) {
Rectangle currentCellBounds = nameableList.getCellBounds(editingIndex, editingIndex); getHelper().popupEditDialog(mousePos, nameableList, this);
if (editingIndex < 0 || (mousePos != null && !currentCellBounds.contains(mousePos))) {
return;
}
popupEditDialog.setLocation(getPopupDialogLocation());
if (popupEditDialog instanceof PopupEditDialog) {
((PopupEditDialog)popupEditDialog).setTitle(getSelectedName());
}
popupEditDialog.setVisible(true);
PopupDialogSaveAction osBasedAction = OSSupportCenter.getAction(PopupDialogSaveAction.class);
osBasedAction.register(this, popupEditDialog);
} }
} }
private Point getPopupDialogLocation() {
Point resultPos = new Point(0, 0);
Point listPos = nameableList.getLocationOnScreen();
resultPos.x = listPos.x - popupEditDialog.getWidth();
resultPos.y = listPos.y + (nameableList.getSelectedIndex() - 1) * EDIT_RANGE;
// 当对象在屏幕上的位置比较靠下时,往下移动弹窗至与属性面板平齐
Window frame = DesignerContext.getDesignerFrame();
// 不能太低
int maxY = frame.getLocationOnScreen().y + frame.getHeight() - popupEditDialog.getHeight();
if (resultPos.y > maxY) {
resultPos.y = maxY;
}
// 也不能太高
int minY = frame.getLocationOnScreen().y + EDIT_RANGE;
if (resultPos.y < minY) {
resultPos.y = minY;
}
// 当在左侧显示不下时,在右侧弹出弹窗
if (resultPos.x < 0) {
resultPos.x = listPos.x + nameableList.getParent().getWidth();
}
// 如果右侧显示不下,可以向左移动
int maxX = frame.getLocationOnScreen().x + frame.getWidth() - popupEditDialog.getWidth() - EDIT_RANGE;
if (resultPos.x > maxX) {
resultPos.x = maxX;
}
return resultPos;
}
/** /**
* 生成不重复的名字 * 生成不重复的名字
@ -301,65 +236,6 @@ public abstract class UIListControlPane extends UIControlPane implements ListCon
return getModel().getSize() > 0 && nameableList.getSelectedIndex() != -1; return getModel().getSize() > 0 && nameableList.getSelectedIndex() != -1;
} }
/*
* UINameEdList的鼠标事件
*/
private MouseListener getListMouseListener() {
return new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent evt) {
nameableList.stopEditing();
if (evt.getClickCount() >= 2
&& SwingUtilities.isLeftMouseButton(evt) && evt.getX() > EDIT_RANGE) {
editingIndex = nameableList.getSelectedIndex();
selectedName = nameableList.getNameAt(editingIndex);
nameableList.editItemAt(nameableList.getSelectedIndex());
} else if (SwingUtilities.isLeftMouseButton(evt) && evt.getX() <= EDIT_RANGE) {
editingIndex = nameableList.getSelectedIndex();
selectedName = nameableList.getNameAt(editingIndex);
popupEditDialog(evt.getPoint());
}
// peter:处理右键的弹出菜单
if (!SwingUtilities.isRightMouseButton(evt)) {
return;
}
// peter: 注意,在checkButtonEnabled()方法里面,设置了所有的Action的Enabled.
checkButtonEnabled();
// p:右键菜单.
JPopupMenu popupMenu = new JPopupMenu();
for (ShortCut4JControlPane sj : getShorts()) {
sj.getShortCut().intoJPopupMenu(popupMenu);
}
// peter: 只有弹出菜单有子菜单的时候,才需要弹出来.
GUICoreUtils.showPopupMenu(popupMenu, nameableList, evt.getX() - 1,
evt.getY() - 1);
}
@Override
public void mouseClicked(MouseEvent e) {
JList list = (JList) e.getSource();
if (list.locationToIndex(e.getPoint()) == -1 && !e.isShiftDown()
&& !isMenuShortcutKeyDown(e)) {
list.clearSelection();
}
}
private boolean isMenuShortcutKeyDown(InputEvent event) {
return (event.getModifiers() & Toolkit.getDefaultToolkit()
.getMenuShortcutKeyMask()) != 0;
}
@Override
public void mouseMoved(MouseEvent e) {
}
};
}
/** /**
* 检查按钮可用状态 Check button enabled. * 检查按钮可用状态 Check button enabled.

22
designer-base/src/main/java/com/fr/design/gui/controlpane/UINameableListCellRenderer.java

@ -1,12 +1,8 @@
package com.fr.design.gui.controlpane; package com.fr.design.gui.controlpane;
import com.fr.base.BaseUtils;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ilist.ListModelElement; import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.Nameable; import com.fr.stable.Nameable;
import sun.swing.DefaultLookup; import sun.swing.DefaultLookup;
@ -14,8 +10,6 @@ import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/** /**
* Nameable的ListCellRenerer * Nameable的ListCellRenerer
@ -32,12 +26,14 @@ public class UINameableListCellRenderer extends
private static final int BUTTON_WIDTH = 25; private static final int BUTTON_WIDTH = 25;
private UILabel editButton; // "编辑按钮",实际上是一个 UILabel,由列表项(UIListControlPane)统一处理点击事件 private UILabel editButton; // "编辑按钮",实际上是一个 UILabel,由列表项(UIListControlPane)统一处理点击事件
private UILabel label; private UILabel label;
private UIListControlPane listControlPane; private boolean isNewStyle;
private NameableCreator[] creators;
private Color initialLabelForeground; private Color initialLabelForeground;
public UINameableListCellRenderer(UIListControlPane listControlPane) { public UINameableListCellRenderer( boolean isNewStyle, NameableCreator[] creators) {
super(); super();
this.listControlPane = listControlPane; this.isNewStyle = isNewStyle;
this.creators = creators;
initComponents(); initComponents();
setOpaque(true); setOpaque(true);
setBorder(getNoFocusBorder()); setBorder(getNoFocusBorder());
@ -50,7 +46,7 @@ public class UINameableListCellRenderer extends
return new Dimension(BUTTON_WIDTH, BUTTON_WIDTH); return new Dimension(BUTTON_WIDTH, BUTTON_WIDTH);
} }
}; };
editButton.setIcon(listControlPane.isNewStyle() ? UIConstants.LIST_EDIT_ICON : UIConstants.CPT_ICON); editButton.setIcon(isNewStyle ? UIConstants.LIST_EDIT_ICON : UIConstants.CPT_ICON);
editButton.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, UIConstants.LIST_ITEM_SPLIT_LINE)); editButton.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, UIConstants.LIST_ITEM_SPLIT_LINE));
editButton.setHorizontalAlignment(SwingConstants.CENTER); editButton.setHorizontalAlignment(SwingConstants.CENTER);
label = new UILabel(); label = new UILabel();
@ -92,7 +88,7 @@ public class UINameableListCellRenderer extends
setBackground(bg == null ? list.getSelectionBackground() : bg); setBackground(bg == null ? list.getSelectionBackground() : bg);
setForeground(fg == null ? list.getSelectionForeground() : fg); setForeground(fg == null ? list.getSelectionForeground() : fg);
label.setForeground(Color.WHITE); label.setForeground(Color.WHITE);
if (listControlPane.isNewStyle()) { if (isNewStyle) {
editButton.setIcon(UIConstants.LIST_EDIT_WHITE_ICON); editButton.setIcon(UIConstants.LIST_EDIT_WHITE_ICON);
} }
} }
@ -100,7 +96,7 @@ public class UINameableListCellRenderer extends
setBackground(list.getBackground()); setBackground(list.getBackground());
setForeground(list.getForeground()); setForeground(list.getForeground());
label.setForeground(initialLabelForeground); label.setForeground(initialLabelForeground);
if (listControlPane.isNewStyle()) { if (isNewStyle) {
editButton.setIcon(UIConstants.LIST_EDIT_ICON); editButton.setIcon(UIConstants.LIST_EDIT_ICON);
} }
} }
@ -114,7 +110,7 @@ public class UINameableListCellRenderer extends
Nameable wrappee = ((ListModelElement) value).wrapper; Nameable wrappee = ((ListModelElement) value).wrapper;
this.setText(((ListModelElement) value).wrapper.getName()); this.setText(((ListModelElement) value).wrapper.getName());
for (NameableCreator creator : listControlPane.creators()) { for (NameableCreator creator : creators) {
if (creator.menuIcon() != null && creator.acceptObject2Populate(wrappee) != null) { if (creator.menuIcon() != null && creator.acceptObject2Populate(wrappee) != null) {
this.setToolTipText(creator.createTooltip()); this.setToolTipText(creator.createTooltip());
break; break;

3
designer-base/src/main/java/com/fr/design/mainframe/OpenLoadingPane.java

@ -1,6 +1,7 @@
package com.fr.design.mainframe; package com.fr.design.mainframe;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.general.IOUtils;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Container; import java.awt.Container;
@ -16,7 +17,7 @@ import javax.swing.JPanel;
*/ */
public class OpenLoadingPane extends JPanel { public class OpenLoadingPane extends JPanel {
private static final ImageIcon LOADING_ICON = new ImageIcon(OpenLoadingPane.class.getResource("/com/fr/design/images/mainframe/loading.gif")); private static final ImageIcon LOADING_ICON = new ImageIcon(IOUtils.readImage("/com/fr/design/images/mainframe/loading.gif"));
private UILabel loadingLabel; private UILabel loadingLabel;

6
designer-base/src/main/java/com/fr/design/os/impl/PopupDialogSaveAction.java

@ -1,6 +1,6 @@
package com.fr.design.os.impl; package com.fr.design.os.impl;
import com.fr.design.gui.controlpane.UIListControlPane; import com.fr.design.gui.controlpane.UIControlPane;
import com.fr.stable.os.OperatingSystem; import com.fr.stable.os.OperatingSystem;
import com.fr.stable.os.support.OSBasedAction; import com.fr.stable.os.support.OSBasedAction;
@ -15,7 +15,7 @@ import java.awt.*;
*/ */
public class PopupDialogSaveAction implements OSBasedAction { public class PopupDialogSaveAction implements OSBasedAction {
private UIListControlPane currentControlPane; private UIControlPane currentControlPane;
private Window popupDialog; private Window popupDialog;
@Override @Override
@ -26,7 +26,7 @@ public class PopupDialogSaveAction implements OSBasedAction {
} }
} }
public void register(UIListControlPane currentControlPane, Window popupDialog) { public void register(UIControlPane currentControlPane, Window popupDialog) {
this.currentControlPane = currentControlPane; this.currentControlPane = currentControlPane;
this.popupDialog = popupDialog; this.popupDialog = popupDialog;
} }

12
designer-base/src/main/java/com/fr/design/widget/EventCreator.java

@ -18,6 +18,10 @@ public class EventCreator extends NameableSelfCreator {
this.eventName = eventName; this.eventName = eventName;
} }
public String getEventName() {
return eventName;
}
@Override @Override
public Nameable createNameable(UnrepeatedNameHelper helper) { public Nameable createNameable(UnrepeatedNameHelper helper) {
return new NameObject(helper.createUnrepeatedName(this.menuName()),new Listener(this.eventName)) ; return new NameObject(helper.createUnrepeatedName(this.menuName()),new Listener(this.eventName)) ;
@ -47,9 +51,13 @@ public class EventCreator extends NameableSelfCreator {
return eventName; return eventName;
} }
} }
@Override @Override
public void saveUpdatedBean(ListModelElement wrapper, Object bean) { public void saveUpdatedBean(ListModelElement element, Object bean) {
((NameObject)wrapper.wrapper).setObject(bean); if (bean instanceof Listener){
((Listener)bean).setName(element.wrapper.getName());
}
((NameObject)element.wrapper).setObject(bean);
} }
@Override @Override

41
designer-base/src/test/java/com/fr/design/gui/controlpane/ListControlPaneHelperTest.java

@ -0,0 +1,41 @@
package com.fr.design.gui.controlpane;
import com.fr.form.event.Listener;
import com.fr.general.NameObject;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by kerry on 5/17/21
*/
public class ListControlPaneHelperTest {
@Test
public void testProcessCatalog() {
ListControlPaneHelper helper = ListControlPaneHelper.newInstance(EasyMock.mock(ListControlPaneProvider.class));
List<NameObject> nameObjectList = new ArrayList<>();
Listener listener1 = new Listener();
listener1.setEventName("click");
Listener listener2 = new Listener();
listener2.setEventName("afterInit");
Listener listener3 = new Listener();
listener3.setEventName("click");
Listener listener4 = new Listener();
listener4.setEventName("afterInit");
listener4.setName("test");
nameObjectList.add(new NameObject("click", listener1));
nameObjectList.add(new NameObject("afterInit", listener2));
nameObjectList.add(new NameObject("click", listener3));
nameObjectList.add(new NameObject("afterInit", listener4));
Map<String, List<NameObject>> map = helper.processCatalog(nameObjectList);
Assert.assertEquals(2, map.size());
Assert.assertEquals(2, map.get("afterInit").size());
Assert.assertEquals(2, map.get("click").size());
}
}

6
designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java

@ -1,6 +1,7 @@
package com.fr.design.designer.creator; package com.fr.design.designer.creator;
import com.fr.base.BaseFormula; import com.fr.base.BaseFormula;
import com.fr.base.iofile.attr.ExtendSharableAttrMark;
import com.fr.design.border.UIRoundedBorder; import com.fr.design.border.UIRoundedBorder;
import com.fr.form.ui.AbstractBorderStyleWidget; import com.fr.form.ui.AbstractBorderStyleWidget;
import com.fr.form.ui.Label; import com.fr.form.ui.Label;
@ -31,6 +32,11 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) {
super(widget, initSize); super(widget, initSize);
ExtendSharableAttrMark sharableAttrMark = this.toData().getWidgetAttrMark(ExtendSharableAttrMark.XML_TAG);
if (sharableAttrMark != null) {
this.setShareId(sharableAttrMark.getShareId());
}
} }
/** /**

25
designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java

@ -17,7 +17,6 @@ import com.fr.design.mainframe.CoverReportPane;
import com.fr.design.mainframe.EastRegionContainerPane; import com.fr.design.mainframe.EastRegionContainerPane;
import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.HelpDialogManager;
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor;
import com.fr.design.module.DesignModuleFactory; import com.fr.design.module.DesignModuleFactory;
import com.fr.form.ui.BaseChartEditor; import com.fr.form.ui.BaseChartEditor;
@ -276,10 +275,11 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
} }
} }
} }
HelpDialogManager.getInstance().setPane(coverPanel); if (this.isShareConfigButtonFocus()) {
if (this.isHelpBtnOnFocus()) { CoverReportPane.showShareConfig(((XCreator) this.getParent()).toData());
coverPanel.setMsgDisplay(e);
} }
} }
@Override @Override
@ -318,23 +318,6 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
return editor; return editor;
} }
/**
* 是否展现覆盖的pane
*
* @param display 是否
*/
public void displayCoverPane(boolean display) {
isHovering = display;
coverPanel.setVisible(display);
coverPanel.setPreferredSize(editor.getPreferredSize());
coverPanel.setBounds(editor.getBounds());
editor.repaint();
}
public JComponent getCoverPane() {
return coverPanel;
}
/** /**
* 是否支持设置可用 * 是否支持设置可用
* return boolean * return boolean

54
designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java

@ -24,16 +24,11 @@ import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.container.WTitleLayout;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import com.fr.stable.CoreGraphHelper;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.third.javax.annotation.Nullable;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.border.Border; import javax.swing.border.Border;
import java.awt.BorderLayout; import java.awt.BorderLayout;
@ -43,7 +38,6 @@ import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -71,7 +65,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
private int[] directions; private int[] directions;
private Rectangle backupBound; private Rectangle backupBound;
private String shareId = StringUtils.EMPTY;//如果组件是共享的会有这个属性 private String shareId = StringUtils.EMPTY;//如果组件是共享的会有这个属性
private boolean isHelpBtnOnFocus = false;//焦点是否在帮助按钮上 private boolean isShareConfigButtonFocus = false;//焦点是否在帮助按钮上
private static final int SHORTS_SEPARATOR_POS = 4; // 弹出菜单分割的位置 private static final int SHORTS_SEPARATOR_POS = 4; // 弹出菜单分割的位置
public XCreator(Widget ob, Dimension initSize) { public XCreator(Widget ob, Dimension initSize) {
@ -658,6 +652,9 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
public void setShareId(String shareId) { public void setShareId(String shareId) {
this.shareId = shareId; this.shareId = shareId;
if (coverPanel != null) {
coverPanel.setShared(isShared());
}
} }
public String getShareId() { public String getShareId() {
@ -668,54 +665,31 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
* 焦点是否在帮助按钮上 * 焦点是否在帮助按钮上
* @return 焦点是否在帮助按钮上 * @return 焦点是否在帮助按钮上
*/ */
public boolean isHelpBtnOnFocus() { public boolean isShareConfigButtonFocus() {
return isHelpBtnOnFocus; return isShareConfigButtonFocus;
} }
public void setHelpBtnOnFocus(boolean helpBtnOnFocus) { public void setShareConfigButtonFocus(boolean shareConfigButtonFocus) {
isHelpBtnOnFocus = helpBtnOnFocus; isShareConfigButtonFocus = shareConfigButtonFocus;
} }
/**
* 设置描述信息
* @param msg 帮助信息
*/
public void setXDescrption(String msg){
if (coverPanel != null) {
coverPanel.setHelpMsg(msg);
}
}
public JComponent getCoverPane(){ public CoverReportPane getCoverPane(){
return coverPanel; return coverPanel;
} }
/**
* 销毁帮助提示框
*/
public void destroyHelpDialog(){
if (coverPanel != null) {
coverPanel.destroyHelpDialog();
}
}
/** /**
* 是否展现覆盖的pane * 是否展现覆盖的pane
* @param display 是否 * @param display 是否
*/ */
public void displayCoverPane(boolean display){ public void displayCoverPane(boolean display){
} if (coverPanel != null) {
coverPanel.setVisible(display);
/** coverPanel.setPreferredSize(editor.getPreferredSize());
* 根据widget设置Xcreator描述信息 coverPanel.setBounds(editor.getBounds());
* @param widget editor.repaint();
*/
public void setXDescrption(Widget widget){
if (widget != null) {
setXDescrption(widget.getDescription());
} }
} }
/** /**
* 按照比例调整组件的宽度 * 按照比例调整组件的宽度
* @param percent 比例 * @param percent 比例

1
designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java

@ -257,7 +257,6 @@ public class XCreatorUtils {
FineLoggerFactory.getLogger().error("Error to create xcreator!"); FineLoggerFactory.getLogger().error("Error to create xcreator!");
creator = new NullCreator(widget, d); creator = new NullCreator(widget, d);
} }
creator.setXDescrption(widget);//设置描述信息
return creator; return creator;
} }

36
designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java

@ -34,7 +34,6 @@ import java.util.Set;
public class XElementCase extends XBorderStyleWidgetCreator implements FormElementCaseContainerProvider{ public class XElementCase extends XBorderStyleWidgetCreator implements FormElementCaseContainerProvider{
private UILabel imageLable; private UILabel imageLable;
private CoverReportPane coverPanel;
private FormDesigner designer; private FormDesigner designer;
private static BufferedImage DEFAULT_BACKGROUND; private static BufferedImage DEFAULT_BACKGROUND;
private boolean isHovering = false; private boolean isHovering = false;
@ -223,28 +222,6 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
imageLable.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight()); imageLable.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
} }
/**
* 是否展现覆盖的pane
* @param display 是否
*/
public void displayCoverPane(boolean display){
isHovering = display;
coverPanel.setVisible(display);
coverPanel.setBounds(1, 1, (int) editor.getBounds().getWidth(), (int) editor.getBounds().getHeight());
editor.repaint();
}
/**
* 销毁帮助提示框
*/
public void destroyHelpDialog(){
coverPanel.destroyHelpDialog();
}
public JComponent getCoverPane(){
return coverPanel;
}
@Override @Override
public void paintBorder(Graphics g, Rectangle bounds){ public void paintBorder(Graphics g, Rectangle bounds){
if (!isHovering) { if (!isHovering) {
@ -316,11 +293,10 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
* @param e 点击事件 * @param e 点击事件
*/ */
public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){ public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){
HelpDialogManager.getInstance().setPane(coverPanel);
super.respondClick(editingMouseListener, e); super.respondClick(editingMouseListener, e);
editingMouseListener.refreshTopXCreator(); editingMouseListener.refreshTopXCreator();
if (this.isHelpBtnOnFocus()) { if (this.isShareConfigButtonFocus()) {
coverPanel.setMsgDisplay(e); CoverReportPane.showShareConfig(((XCreator)this.getParent()).toData());
} else { } else {
switchTab(e, editingMouseListener); switchTab(e, editingMouseListener);
} }
@ -342,11 +318,6 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
return new WidgetPropertyUIProvider[]{ new ElementCasePropertyUI(this)}; return new WidgetPropertyUIProvider[]{ new ElementCasePropertyUI(this)};
} }
@Override
public void setXDescrption(String msg) {
coverPanel.setHelpMsg(msg);
}
/** /**
* data属性改变触发其他操作 * data属性改变触发其他操作
* *
@ -370,7 +341,4 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
public boolean isSupportShared() { public boolean isSupportShared() {
return true; return true;
} }
} }

77
designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java

@ -4,8 +4,6 @@
package com.fr.design.designer.creator; package com.fr.design.designer.creator;
import com.fr.base.GraphHelper; import com.fr.base.GraphHelper;
import com.fr.base.iofile.attr.SharableAttrMark;
import com.fr.design.constants.UIConstants;
import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
@ -17,40 +15,28 @@ import com.fr.design.designer.properties.mobile.MobileBooKMarkUsePropertyUI;
import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.fit.DesignerUIModeConfig;
import com.fr.design.form.layout.FRAbsoluteLayout; import com.fr.design.form.layout.FRAbsoluteLayout;
import com.fr.design.form.util.FormDesignerUtils; import com.fr.design.form.util.FormDesignerUtils;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.fun.WidgetPropertyUIProvider;
import com.fr.design.icon.IconPathConstants; import com.fr.design.mainframe.CoverReportPane;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormArea; import com.fr.design.mainframe.FormArea;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.WidgetHelpDialog;
import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.form.ui.Connector; import com.fr.form.ui.Connector;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.WLayout;
import com.fr.general.IOUtils;
import com.fr.share.ShareConstants;
import com.fr.stable.AssistUtils; import com.fr.stable.AssistUtils;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import javax.swing.Icon;
import java.awt.AlphaComposite;
import java.awt.Color; import java.awt.Color;
import java.awt.Composite;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.event.ContainerEvent; import java.awt.event.ContainerEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -61,20 +47,14 @@ import java.util.HashMap;
*/ */
public class XWAbsoluteLayout extends XLayoutContainer { public class XWAbsoluteLayout extends XLayoutContainer {
private static final int EDIT_BTN_WIDTH = 75;
private static final int EDIT_BTN_HEIGHT = 20;
private int minWidth = WLayout.MIN_WIDTH; private int minWidth = WLayout.MIN_WIDTH;
private int minHeight = WLayout.MIN_HEIGHT; private int minHeight = WLayout.MIN_HEIGHT;
private static final Color OUTER_BORDER_COLOR = new Color(65, 155, 249, 30); private static final Color OUTER_BORDER_COLOR = new Color(65, 155, 249, 30);
private static final Color INNER_BORDER_COLOR = new Color(65, 155, 249); private static final Color INNER_BORDER_COLOR = new Color(65, 155, 249);
private static final int BORDER_WIDTH = 1;
private Icon controlMode = IOUtils.readIcon(IconPathConstants.TD_EL_SHARE_HELP_ICON_PATH);
//由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算 //由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算
protected double containerPercent = 1.0; protected double containerPercent = 1.0;
private boolean isHovering = false;
private HashMap<Connector, XConnector> xConnectorMap; private HashMap<Connector, XConnector> xConnectorMap;
public XWAbsoluteLayout() { public XWAbsoluteLayout() {
@ -462,52 +442,10 @@ public class XWAbsoluteLayout extends XLayoutContainer {
super.paint(g); super.paint(g);
//如果鼠标移动到布局内且布局不可编辑,画出编辑蒙层 //如果鼠标移动到布局内且布局不可编辑,画出编辑蒙层
if (isMouseEnter && !this.editable) { if (isMouseEnter && !this.editable) {
int x = 0; CoverReportPane.paintEditButton(g, this);
int y = 0; if (isShared()) {
int w = getWidth(); CoverReportPane.paintShareButton(g, this);
int h = getHeight(); }
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
//画白色的编辑层
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 50 / 100.0F));
g2d.setColor(XCreatorConstants.COVER_COLOR);
g2d.fillRect(x, y, w, h);
//画编辑按钮所在框
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner();
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, formDesigner.getCursor().getType() != Cursor.DEFAULT_CURSOR ? 0.9f : 0.7f);
g2d.setColor(XCreatorConstants.EDIT_COLOR);
g2d.setComposite(alphaComposite);
g2d.fillRoundRect((x + w / 2 - EDIT_BTN_WIDTH / 2), (y + h / 2 - EDIT_BTN_HEIGHT / 2), EDIT_BTN_WIDTH, EDIT_BTN_HEIGHT, 4, 4);
g2d.setComposite(oldComposite);
//画编辑按钮图标
BufferedImage image = IOUtils.readImage(IconPathConstants.EDIT_ICON_PATH);
g2d.drawImage(
image,
(x + w / 2 - 23),
(y + h / 2 - image.getHeight() / 2),
image.getWidth(),
image.getHeight(),
null,
this
);
g2d.setColor(Color.WHITE);
//画编辑文字
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawString(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit"), x + w / 2 - 2, y + h / 2 + 5);
g.setColor(XCreatorConstants.FORM_BORDER_COLOR);
GraphHelper.draw(g, new Rectangle(BORDER_WIDTH, BORDER_WIDTH, getWidth() - BORDER_WIDTH * 2, getHeight() - BORDER_WIDTH * 2), Constants.LINE_MEDIUM);
paintExtro(g);
}
}
public void paintExtro(Graphics g) {
if (this.toData().getWidgetAttrMark(SharableAttrMark.XML_TAG) != null) {
int width = getWidth() - ShareConstants.SHARE_EL_CONTROL_BUTTON_HW;
g.setColor(UIConstants.NORMAL_BACKGROUND);
g.fillArc(width, 0, ShareConstants.SHARE_EL_CONTROL_BUTTON_HW, ShareConstants.SHARE_EL_CONTROL_BUTTON_HW,
0, 360);
controlMode.paintIcon(this, g, width, 0);
} }
} }
@ -529,9 +467,8 @@ public class XWAbsoluteLayout extends XLayoutContainer {
* @param e 鼠标点击事件 * @param e 鼠标点击事件
*/ */
public void respondClick(EditingMouseListener editingMouseListener, MouseEvent e) { public void respondClick(EditingMouseListener editingMouseListener, MouseEvent e) {
//帮助弹窗 if (this.isShareConfigButtonFocus()) {
if (this.isHelpBtnOnFocus()) { CoverReportPane.showShareConfig(this.toData());
new WidgetHelpDialog(DesignerContext.getDesignerFrame(), this.toData().getDescription()).showWindow(e);
return; return;
} }
FormDesigner designer = editingMouseListener.getDesigner(); FormDesigner designer = editingMouseListener.getDesigner();

6
designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java

@ -13,6 +13,7 @@ import com.fr.form.ui.WidgetTitle;
import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.stable.StringUtils;
import java.awt.*; import java.awt.*;
import java.awt.event.ContainerEvent; import java.awt.event.ContainerEvent;
@ -190,4 +191,9 @@ public class XWTitleLayout extends DedicateLayoutContainer {
return creator.getWidgetPropertyUIProviders(); return creator.getWidgetPropertyUIProviders();
} }
@Override
public void setShareId(String shareId) {
super.setShareId(shareId);
this.getEditingChildCreator().setShareId(shareId);
}
} }

80
designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java

@ -3,9 +3,6 @@
*/ */
package com.fr.design.designer.creator.cardlayout; package com.fr.design.designer.creator.cardlayout;
import com.fr.base.GraphHelper;
import com.fr.base.iofile.attr.SharableAttrMark;
import com.fr.design.constants.UIConstants;
import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
@ -16,13 +13,9 @@ import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWBorderLayout; import com.fr.design.designer.creator.XWBorderLayout;
import com.fr.design.designer.creator.XWidgetCreator; import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.form.util.XCreatorConstants; import com.fr.design.mainframe.CoverReportPane;
import com.fr.design.icon.IconPathConstants;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.WidgetHelpDialog;
import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.form.event.Listener; import com.fr.form.event.Listener;
import com.fr.form.ui.CardSwitchButton; import com.fr.form.ui.CardSwitchButton;
import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.LayoutBorderStyle;
@ -36,25 +29,15 @@ import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WCardTagLayout;
import com.fr.form.ui.container.cardlayout.WCardTitleLayout; import com.fr.form.ui.container.cardlayout.WCardTitleLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.general.act.BorderPacker; import com.fr.general.act.BorderPacker;
import com.fr.share.ShareConstants;
import com.fr.stable.Constants;
import javax.swing.Icon;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Composite;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -67,15 +50,10 @@ import java.util.List;
*/ */
public class XWCardMainBorderLayout extends XWBorderLayout { public class XWCardMainBorderLayout extends XWBorderLayout {
private Icon controlMode = IOUtils.readIcon(IconPathConstants.TD_EL_SHARE_HELP_ICON_PATH);
private static final int CENTER = 1; private static final int CENTER = 1;
private static final int NORTH = 0; private static final int NORTH = 0;
private static final int TITLE_STYLE = 2; private static final int TITLE_STYLE = 2;
private static final int EDIT_BTN_WIDTH = 75;
private static final int EDIT_BTN_HEIGHT = 20;
private static final int BORDER_WIDTH = 1;
private final int CARDMAINLAYOUT_CHILD_COUNT = 1; private final int CARDMAINLAYOUT_CHILD_COUNT = 1;
/** /**
@ -358,53 +336,10 @@ public class XWCardMainBorderLayout extends XWBorderLayout {
super.paint(g); super.paint(g);
//如果鼠标移动到布局内且布局不可编辑,画出编辑蒙层 //如果鼠标移动到布局内且布局不可编辑,画出编辑蒙层
if (isMouseEnter && !editable) { if (isMouseEnter && !editable) {
int x = 0; CoverReportPane.paintEditButton(g, this);
int y = 0; if (isShared()) {
int w = getWidth(); CoverReportPane.paintShareButton(g, this);
int h = getHeight(); }
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
//画白色的编辑层
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 50 / 100.0F));
g2d.setColor(XCreatorConstants.COVER_COLOR);
g2d.fillRect(x, y, w, h);
//画编辑按钮所在框
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner();
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, formDesigner.getCursor().getType() != Cursor.DEFAULT_CURSOR ? 0.9f : 0.7f);
g2d.setColor(XCreatorConstants.EDIT_COLOR);
g2d.setComposite(alphaComposite);
g2d.fillRoundRect((x + w / 2 - EDIT_BTN_WIDTH / 2), (y + h / 2 - EDIT_BTN_HEIGHT / 2), EDIT_BTN_WIDTH, EDIT_BTN_HEIGHT, 4, 4);
g2d.setComposite(oldComposite);
//画编辑按钮图标
BufferedImage image = IOUtils.readImage(IconPathConstants.EDIT_ICON_PATH);
g2d.drawImage(
image,
(x + w / 2 - 23),
(y + h / 2 - image.getHeight() / 2),
image.getWidth(),
image.getHeight(),
null,
this
);
g2d.setColor(Color.WHITE);
//画编辑文字
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawString(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit"), x + w / 2 - 2, y + h / 2 + 5);
g.setColor(XCreatorConstants.FORM_BORDER_COLOR);
GraphHelper.draw(g, new Rectangle(BORDER_WIDTH, BORDER_WIDTH, getWidth() - BORDER_WIDTH * 2, getHeight() - BORDER_WIDTH * 2), Constants.LINE_MEDIUM);
paintExtro(g);
}
}
public void paintExtro(Graphics g) {
if (this.toData().getWidgetAttrMark(SharableAttrMark.XML_TAG) != null) {
int width = getWidth() - ShareConstants.SHARE_EL_CONTROL_BUTTON_HW;
g.setColor(UIConstants.NORMAL_BACKGROUND);
g.fillArc(width, 0, ShareConstants.SHARE_EL_CONTROL_BUTTON_HW, ShareConstants.SHARE_EL_CONTROL_BUTTON_HW,
0, 360);
controlMode.paintIcon(this, g, width, 0);
} }
} }
@ -423,9 +358,8 @@ public class XWCardMainBorderLayout extends XWBorderLayout {
*/ */
@Override @Override
public void respondClick(EditingMouseListener editingMouseListener, MouseEvent e){ public void respondClick(EditingMouseListener editingMouseListener, MouseEvent e){
//帮助弹窗 if (this.isShareConfigButtonFocus()) {
if (this.isHelpBtnOnFocus()) { CoverReportPane.showShareConfig(this.toData());
new WidgetHelpDialog(DesignerContext.getDesignerFrame(), this.toData().getDescription()).showWindow(e);
return; return;
} }
FormDesigner designer = editingMouseListener.getDesigner(); FormDesigner designer = editingMouseListener.getDesigner();

533
designer-form/src/main/java/com/fr/design/gui/controlpane/EventPropertyPane.java

@ -0,0 +1,533 @@
package com.fr.design.gui.controlpane;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.constants.UIConstants;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.properties.EventPropertyTable;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ilist.JNameEdList;
import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.gui.ilist.ModNameActionListener;
import com.fr.design.gui.ilist.UINameEdList;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.widget.EventCreator;
import com.fr.form.event.Listener;
import com.fr.form.ui.Widget;
import com.fr.general.NameObject;
import com.fr.report.web.util.ReportEngineEventMapping;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Nameable;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Created by kerry on 5/17/21
*/
public class EventPropertyPane extends UIControlPane implements ListControlPaneProvider {
private XCreator creator;
private boolean isPopulating = false;
private UINameEdList selectNameEdList;
private Map<String, EventListWrapperPane> nameEdListMap = new HashMap<>();
private CommonShortCutHandlers commonHandlers;
private ListControlPaneHelper helper;
private JPanel contentPane;
private FormDesigner designer;
private ListControlPaneHelper getHelper() {
if (helper == null) {
helper = ListControlPaneHelper.newInstance(this);
}
return helper;
}
private CommonShortCutHandlers getCommonHandlers() {
if (commonHandlers == null) {
commonHandlers = CommonShortCutHandlers.newInstance(this);
}
return commonHandlers;
}
public EventPropertyPane(FormDesigner designer) {
super();
this.designer = designer;
}
@Override
protected void initLeftPane(JPanel leftPane) {
leftPane.add(new UIScrollPane(contentPane = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 0)), BorderLayout.CENTER);
}
/**
* 刷新
*/
public void refresh() {
int selectionSize = designer.getSelectionModel().getSelection().size();
if (selectionSize == 0 || selectionSize == 1) {
this.creator = selectionSize == 0 ? designer.getRootComponent() : designer.getSelectionModel()
.getSelection().getSelectedCreator();
} else {
this.creator = null;
contentPane.removeAll();
checkButtonEnabled();
return;
}
Widget widget = creator.toData();
refreshContentPane(widget.supportedEvents());
refreshNameableCreator(EventCreator.createEventCreator(widget.supportedEvents(), EventPropertyTable.WidgetEventListenerUpdatePane.class));
populateNameObjects();
}
private void refreshContentPane(String[] supportedEvents) {
for (String event : supportedEvents) {
if (nameEdListMap.containsKey(event)) {
continue;
}
UINameEdList list = createJNameList(event);
EventListWrapperPane wrapperPane = new EventListWrapperPane(switchLang(event), list);
if (this.selectNameEdList == null) {
this.selectNameEdList = wrapperPane.getNameEdList();
}
contentPane.add(wrapperPane);
nameEdListMap.put(event, wrapperPane);
}
}
public void populateNameObjects() {
Widget widget = creator.toData();
ArrayList<NameObject> nameObjectList = new ArrayList<>();
for (int i = 0, size = widget.getListenerSize(); i < size; i++) {
Listener listener = widget.getListener(i);
if (!listener.isDefault()) {
nameObjectList.add(i, new NameObject(switchLang(listener.getEventName()) + (i + 1), listener));
}
}
populate(getHelper().processCatalog(nameObjectList));
checkButtonEnabled();
this.repaint();
}
public void populate(Map<String, List<NameObject>> map) {
isPopulating = true; // 加一个标识位,避免切换单元格时,触发 saveSettings
Iterator<Map.Entry<String, List<NameObject>>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, List<NameObject>> entry = iterator.next();
List<NameObject> valueList = entry.getValue();
EventListWrapperPane eventListWrapperPane = nameEdListMap.get(entry.getKey());
populateChildNameList(eventListWrapperPane.getNameEdList(), valueList.toArray(new NameObject[valueList.size()]));
}
this.checkButtonEnabled();
refreshEventListWrapperPane();
isPopulating = false;
}
private void refreshEventListWrapperPane() {
Iterator<Map.Entry<String, EventListWrapperPane>> iterator = nameEdListMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, EventListWrapperPane> entry = iterator.next();
EventListWrapperPane eventListWrapperPane = entry.getValue();
UINameEdList nameEdList = eventListWrapperPane.getNameEdList();
int listSize = nameEdList.getModel().getSize();
if (this.selectNameEdList.getModel().getSize() == 0 && listSize > 0) {
this.selectNameEdList = nameEdList;
}
eventListWrapperPane.setVisible(listSize > 0);
}
this.selectNameEdList.setSelectedIndex(0);
this.repaint();
}
private void populateChildNameList(UINameEdList nameableList, Nameable[] nameableArray) {
nameableList.getCellEditor().stopCellEditing();
DefaultListModel listModel = (DefaultListModel) nameableList.getModel();
listModel.removeAllElements();
if (ArrayUtils.isEmpty(nameableArray)) {
isPopulating = false;
return;
}
listModel.setSize(nameableArray.length);
for (int i = 0; i < nameableArray.length; i++) {
listModel.set(i, new ListModelElement(nameableArray[i]));
}
}
protected UINameEdList createJNameList(String text) {
UINameEdList nameEdList = new UINameEdList(new DefaultListModel()) {
@Override
protected void doAfterLostFocus() {
((JControlUpdatePane) controlUpdatePane).update();
}
@Override
protected void doAfterStopEditing() {
saveSettings();
}
};
nameEdList.setCellRenderer(new UINameableListCellRenderer(true, this.creators));
nameEdList.setName(text);
nameEdList.setSelectionBackground(UIConstants.ATTRIBUTE_PRESS);
nameEdList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
nameEdList.addMouseListener(getHelper().getListMouseListener(nameEdList, this));
nameEdList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
selectNameEdList = nameEdList;
updateUINameListSelect();
}
});
nameEdList.addModNameActionListener(new ModNameActionListener() {
@Override
public void nameModed(int index, String oldName, String newName) {
saveSettings();
}
});
nameEdList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
// richie:避免多次update和populate大大降低效率
if (!evt.getValueIsAdjusting() && !isPopulating) {
// shoc 切换的时候加检验
if (hasInvalid(false)) {
return;
}
((JControlUpdatePane) EventPropertyPane.this.controlUpdatePane).update();
((JControlUpdatePane) EventPropertyPane.this.controlUpdatePane).populate();
EventPropertyPane.this.checkButtonEnabled();
}
}
});
nameEdList.getModel().addListDataListener(new ListDataListener() {
@Override
public void intervalAdded(ListDataEvent e) {
saveSettings();
}
@Override
public void intervalRemoved(ListDataEvent e) {
saveSettings();
}
@Override
public void contentsChanged(ListDataEvent e) {
saveSettings();
}
});
return nameEdList;
}
private void updateUINameListSelect() {
Iterator<Map.Entry<String, EventListWrapperPane>> iterator = nameEdListMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, EventListWrapperPane> entry = iterator.next();
UINameEdList nameEdList = entry.getValue().getNameEdList();
if (nameEdList != selectNameEdList) {
nameEdList.clearSelection();
}
}
}
@Override
public void checkButtonEnabled() {
getHelper().checkButtonEnabled();
}
private String switchLang(String eventName) {
// 在 properties 文件中找到相应的 key 值
String localeKey = ReportEngineEventMapping.getLocaleName(eventName);
return com.fr.design.i18n.Toolkit.i18nText(localeKey);
}
/**
* 更新控件事件
*
* @param creator 控件
*/
public void updateWidgetListener(XCreator creator) {
(creator.toData()).clearListeners();
Nameable[] res = this.update();
for (int i = 0; i < res.length; i++) {
NameObject nameObject = (NameObject) res[i];
(creator.toData()).addListener((Listener) nameObject.getObject());
}
designer.fireTargetModified();
checkButtonEnabled();
}
/**
* 生成不重复的名字
*
* @param prefix 名字前缀
* @return 名字
*/
@Override
public String createUnrepeatedName(String prefix) {
return getCommonHandlers().createUnrepeatedName(prefix);
}
private void updateSelectedNameList(NameableCreator creator) {
String eventName = ((EventCreator) creator).getEventName();
EventListWrapperPane wrapperPane = nameEdListMap.get(eventName);
wrapperPane.setVisible(true);
setSelectNameEdList(wrapperPane.getNameEdList());
}
private void setSelectNameEdList(UINameEdList nameEdList) {
if (this.selectNameEdList != null) {
this.selectNameEdList.clearSelection();
}
this.selectNameEdList = nameEdList;
}
@Override
public void onAddItem(NameableCreator creator) {
updateSelectedNameList(creator);
getCommonHandlers().onAddItem(creator);
}
@Override
public void onRemoveItem() {
getCommonHandlers().onRemoveItem();
refreshEventListWrapperPane();
}
@Override
public void onCopyItem() {
getCommonHandlers().onCopyItem();
}
@Override
public void onMoveUpItem() {
getCommonHandlers().onMoveUpItem();
}
@Override
public void onMoveDownItem() {
getCommonHandlers().onMoveDownItem();
}
@Override
public void onSortItem(boolean isAtoZ) {
Iterator<Map.Entry<String, EventListWrapperPane>> iterator = nameEdListMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, EventListWrapperPane> entry = iterator.next();
UINameEdList nameEdList = entry.getValue().getNameEdList();
getCommonHandlers().onSortItem(isAtoZ, nameEdList);
}
}
@Override
public boolean isItemSelected() {
return getModel().getSize() > 0 && getSelectedIndex() != -1;
}
@Override
protected JPanel createControlUpdatePane() {
return JControlUpdatePane.newInstance(this);
}
@Override
public Nameable[] update() {
java.util.List<Nameable> res = new java.util.ArrayList<Nameable>();
getControlUpdatePane().update();
Iterator<Map.Entry<String, EventListWrapperPane>> iterator = nameEdListMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, EventListWrapperPane> entry = iterator.next();
UINameEdList nameEdList = entry.getValue().getNameEdList();
DefaultListModel listModel = (DefaultListModel) nameEdList.getModel();
for (int i = 0, len = listModel.getSize(); i < len; i++) {
res.add(((ListModelElement) listModel.getElementAt(i)).wrapper);
}
}
return res.toArray(new Nameable[0]);
}
@Override
public NameableCreator[] createNameableCreators() {
return new NameableCreator[]{
new EventCreator(Widget.EVENT_STATECHANGE, EventPropertyTable.WidgetEventListenerUpdatePane.class)
};
}
@Override
public void saveSettings() {
if (isPopulating) {
return;
}
updateWidgetListener(creator);
}
@Override
protected String title4PopupWindow() {
return "Event";
}
@Override
public String getAddItemText() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Add_Event");
}
public BasicBeanPane createPaneByCreators(NameableCreator creator) {
try {
return creator.getUpdatePane().newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public BasicBeanPane createPaneByCreators(NameableCreator creator, String string) {
Constructor constructor = null;
try {
constructor = creator.getUpdatePane().getDeclaredConstructor(new Class[]{String.class});
constructor.setAccessible(true);
return (BasicBeanPane) constructor.newInstance(string);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
@Override
public DefaultListModel getModel() {
if (this.selectNameEdList == null) {
return new DefaultListModel();
}
return (DefaultListModel) this.selectNameEdList.getModel();
}
/**
* 检查是否符合规范
*
* @throws Exception
*/
@Override
public void checkValid() throws Exception {
((JControlUpdatePane) this.controlUpdatePane).checkValid();
}
@Override
public boolean hasInvalid(boolean isAdd) {
return getHelper().hasInvalid(isAdd);
}
public void addNameable(Nameable nameable, int index) {
getHelper().addNameable(nameable, index);
popupEditDialog();
}
/**
* 设置选中项
*
* @param index 选中项的序列号
*/
public void setSelectedIndex(int index) {
if (this.selectNameEdList != null) {
this.selectNameEdList.setSelectedIndex(index);
}
}
@Override
public int getSelectedIndex() {
if (this.selectNameEdList == null) {
return -1;
}
return this.selectNameEdList.getSelectedIndex();
}
@Override
public ListModelElement getSelectedValue() {
if (this.selectNameEdList == null) {
return null;
}
return (ListModelElement) this.selectNameEdList.getSelectedValue();
}
@Override
public JControlUpdatePane getControlUpdatePane() {
return (JControlUpdatePane) controlUpdatePane;
}
@Override
public JNameEdList getNameableList() {
return this.selectNameEdList;
}
private void popupEditDialog() {
getHelper().popupEditDialog(null, this.selectNameEdList, this);
}
private class EventListWrapperPane extends JPanel {
private UINameEdList nameEdList;
public EventListWrapperPane(String labelText, UINameEdList nameEdList) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
UILabel label = new UILabel(labelText + Toolkit.i18nText("Fine-Design_Report_Event"));
label.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
label.setBackground(Color.decode("#FFFFFF"));
label.setPreferredSize(new Dimension(226, 26));
this.nameEdList = nameEdList;
this.add(label, BorderLayout.NORTH);
this.add(this.nameEdList, BorderLayout.CENTER);
}
public UINameEdList getNameEdList() {
return this.nameEdList;
}
}
}

129
designer-form/src/main/java/com/fr/design/mainframe/CoverPane.java

@ -13,13 +13,12 @@ import java.awt.AlphaComposite;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Composite; import java.awt.Composite;
import java.awt.Container;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.LayoutManager;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
/** /**
@ -29,29 +28,52 @@ import java.awt.Rectangle;
* Time: 上午9:09 * Time: 上午9:09
*/ */
public class CoverPane extends JComponent { public class CoverPane extends JComponent {
private UIButton editButton;
private AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f); private AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
private static final int BORDER_WIDTH = 2; protected static final int BORDER_WIDTH = 2;
private static final Color COVER_COLOR = new Color(216, 242, 253); public static final int EDIT_BTN_W = 75;
private static final int EDIT_BTN_WIDTH = 75; public static final int EDIT_BTN_H = 20;
private static final int EDIT_BTN_HEIGHT = 20;
public static void paintEditButton(Graphics g, Component component) {
int x = 0;
int y = 0;
int w = component.getWidth();
int h = component.getHeight();
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
//画白色的编辑层
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 50 / 100.0F));
g2d.setColor(XCreatorConstants.COVER_COLOR);
g2d.fillRect(x, y, w, h);
//画编辑按钮所在框
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner();
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, formDesigner.getCursor().getType() != Cursor.DEFAULT_CURSOR ? 0.9f : 0.7f);
g2d.setColor(XCreatorConstants.EDIT_COLOR);
g2d.setComposite(alphaComposite);
g2d.fillRoundRect((x + w / 2 - EDIT_BTN_W / 2), (y + h / 2 - EDIT_BTN_H / 2), EDIT_BTN_W, EDIT_BTN_H, 4, 4);
g2d.setComposite(oldComposite);
//画编辑按钮图标
BufferedImage image = IOUtils.readImage(IconPathConstants.EDIT_ICON_PATH);
g2d.drawImage(
image,
(x + w / 2 - 23),
(y + h / 2 - image.getHeight() / 2),
image.getWidth(),
image.getHeight(),
null
);
g2d.setColor(Color.WHITE);
//画编辑文字
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawString(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit"), x + w / 2 - 2, y + h / 2 + 5);
g.setColor(XCreatorConstants.FORM_BORDER_COLOR);
GraphHelper.draw(g, new Rectangle(BORDER_WIDTH, BORDER_WIDTH, w - BORDER_WIDTH * 2, h - BORDER_WIDTH * 2), Constants.LINE_MEDIUM);
}
public CoverPane() { public CoverPane() {
setLayout(getCoverLayout());
setBackground(null); setBackground(null);
setOpaque(false); setOpaque(false);
editButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Edit"), IOUtils.readIcon(IconPathConstants.EDIT_ICON_PATH)) {
@Override
public Dimension getPreferredSize() {
return new Dimension(60, 24);
}
};
editButton.setBorderPainted(false);
editButton.setExtraPainted(false);
editButton.setForeground(Color.WHITE);
add(editButton);
} }
public AlphaComposite getComposite() { public AlphaComposite getComposite() {
@ -62,72 +84,9 @@ public class CoverPane extends JComponent {
this.composite = composite; this.composite = composite;
} }
public UIButton getEditButton() {
return editButton;
}
public void setEditButton(UIButton editButton) {
this.editButton = editButton;
}
protected LayoutManager getCoverLayout() {
return new LayoutManager() {
@Override
public void removeLayoutComponent(Component comp) {
}
@Override
public Dimension preferredLayoutSize(Container parent) {
return parent.getPreferredSize();
}
@Override
public Dimension minimumLayoutSize(Container parent) {
return null;
}
@Override
public void layoutContainer(Container parent) {
int width = parent.getParent().getWidth();
int height = parent.getParent().getHeight();
int preferWidth = editButton.getPreferredSize().width;
int preferHeight = editButton.getPreferredSize().height;
editButton.setBounds((width - preferWidth) / 2, (height - preferHeight) / 2, preferWidth, preferHeight);
}
@Override
public void addLayoutComponent(String name, Component comp) {
}
};
}
public void paint(Graphics g) { public void paint(Graphics g) {
int x = 0;
int y = 0;
int w = getWidth();
int h = getHeight();
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
g2d.setComposite(composite);
g2d.setColor(COVER_COLOR);
g2d.fillRect(0, 0, getWidth(), getHeight());
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner();
g2d.setColor(XCreatorConstants.EDIT_COLOR);
boolean editHover = formDesigner.getCursor().getType() != Cursor.DEFAULT_CURSOR;
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, editHover ? 0.9f : 0.7f);
g2d.setComposite(alphaComposite);
g2d.fillRoundRect((x + w / 2 - EDIT_BTN_WIDTH / 2), (y + h / 2 - EDIT_BTN_HEIGHT / 2), EDIT_BTN_WIDTH, EDIT_BTN_HEIGHT, 4, 4);
g2d.setComposite(oldComposite);
g.setColor(XCreatorConstants.FORM_BORDER_COLOR);
GraphHelper.draw(g, getPaintBorderBounds(), Constants.LINE_MEDIUM);
super.paint(g); super.paint(g);
} paintEditButton(g, this);
protected Rectangle getPaintBorderBounds(){
return new Rectangle(BORDER_WIDTH, BORDER_WIDTH, getWidth() - BORDER_WIDTH * 2 , getHeight() - BORDER_WIDTH * 2);
} }
} }

174
designer-form/src/main/java/com/fr/design/mainframe/CoverReportPane.java

@ -1,18 +1,20 @@
package com.fr.design.mainframe; package com.fr.design.mainframe;
import com.fr.design.constants.UIConstants; import com.fr.base.BaseUtils;
import com.fr.design.fit.DesignerUIModeConfig; import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.i18n.Toolkit;
import com.fr.design.icon.IconPathConstants; import com.fr.design.mainframe.share.constants.ShareEntryKey;
import com.fr.share.ShareConstants; import com.fr.form.ui.Widget;
import com.fr.general.IOUtils; import com.fr.stable.Constants;
import com.fr.stable.StringUtils; import com.fr.stable.bridge.StableFactory;
import javax.swing.*; import java.awt.Color;
import java.awt.*; import java.awt.Component;
import java.awt.event.MouseEvent; import java.awt.Graphics;
import java.awt.event.WindowAdapter; import java.awt.Graphics2D;
import java.awt.event.WindowEvent; import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.util.HashMap;
/** /**
* 报表块的封面如果后面所有的组件都有帮助信息的话就抽接口吧 * 报表块的封面如果后面所有的组件都有帮助信息的话就抽接口吧
@ -20,123 +22,61 @@ import java.awt.event.WindowEvent;
* Date: 2016/11/2 * Date: 2016/11/2
* Time: 11:32 * Time: 11:32
*/ */
public class CoverReportPane extends CoverPane implements HelpDialogHandler{ public class CoverReportPane extends CoverPane{
private static final int BORDER_WIDTH = 1; public static final int SHARE_CONF_BTN_W = 90;
private Icon controlMode = IOUtils.readIcon(IconPathConstants.TD_EL_SHARE_HELP_ICON_PATH); public static final int SHARE_CONF_BTN_H = 24;
private JComponent controlButton = new JComponent() {
protected void paintComponent(Graphics g) { public static final Color SHARE_BTN_BG = new Color(152, 193, 250);
g.setColor(UIConstants.NORMAL_BACKGROUND);
g.fillArc(0, 0, ShareConstants.SHARE_EL_CONTROL_BUTTON_HW, ShareConstants.SHARE_EL_CONTROL_BUTTON_HW, public static void showShareConfig(Widget widget) {
0, 360); Object[] compositeArg = new Object[]{widget};
controlMode.paintIcon(this, g, 0, 0); HashMap<String, Class> compoClass = new HashMap<String, Class>();
} compoClass.put(Constants.ARG_0, Widget.class);
}; BasicPane shareGuidePane = StableFactory.getMarkedInstanceObjectFromClass(ShareEntryKey.SHARE_CONFIG, compositeArg, compoClass, BasicPane.class);
shareGuidePane.show();
private String helpMsg;//帮助信息(后续帮助信息可能会变成标配,就直接放这边了)
private WidgetHelpDialog helpDialog = null;
public CoverReportPane() {
this(StringUtils.EMPTY);
}
public CoverReportPane(String helpMsg) {
super();
this.helpMsg = helpMsg;
} }
public String getHelpMsg() { public static void paintShareButton(Graphics g, Component component) {
return helpMsg; int x = component.getWidth() - SHARE_CONF_BTN_W;
int y = 0;
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(SHARE_BTN_BG);
g2d.fillRoundRect(x ,y, SHARE_CONF_BTN_W, SHARE_CONF_BTN_H,5,5);
g2d.setColor(Color.WHITE);
// 画配置文字
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawString(Toolkit.i18nText("Fine-Design_Share_Help_Settings"),x + 30, 17);
// 画图标
BufferedImage image = BaseUtils.readImage("com/fr/base/images/share/config.png");
g2d.drawImage(image, x + 10, 5, image.getWidth(), image.getHeight(), null);
} }
public void setHelpMsg(String helpMsg) { private boolean isShared = false;
this.helpMsg = helpMsg;
//帮助信息为空就不显示帮助按钮
if (StringUtils.isNotEmpty(helpMsg)) {
add(controlButton);
}
}
public void setMsgDisplay(MouseEvent e) { public CoverReportPane() {
if (helpDialog == null) { this(false);
// controlMode = IOUtils.readIcon(IconPathConstants.TD_EL_SHARE_CLOSE_ICON_PATH);
controlButton.setVisible(false);
helpDialog = new WidgetHelpDialog(DesignerContext.getDesignerFrame(), helpMsg);
double screenValue = DesignerUIModeConfig.getInstance().getDesignScreenByDimension(Toolkit.getDefaultToolkit().getScreenSize()).getValue();
int offsetX = 0;
if (screenValue < FormArea.DEFAULT_SLIDER) {
offsetX = (int) ((1 - screenValue / FormArea.DEFAULT_SLIDER)
* WidgetPropertyPane.getInstance().getEditingFormDesigner().getRootComponent().getWidth() / 2);
}
int rX = WestRegionContainerPane.getInstance().getWidth() + e.getX() + offsetX - 227;//弹出框宽度190加上图标的宽度27加上10的偏移
int rY = 165 + e.getY();//165是设计器最上面几个面板的高度
helpDialog.setLocationRelativeTo(DesignerContext.getDesignerFrame(), rX, rY);
helpDialog.showWindow();
helpDialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
helpDialog = null;
controlButton.setVisible(true);
}
});
HelpDialogManager.getInstance().setPane(this);
}
} }
protected LayoutManager getCoverLayout() { public CoverReportPane(boolean shared) {
return new LayoutManager() { super();
isShared = shared;
@Override
public void removeLayoutComponent(Component comp) {
}
@Override
public Dimension preferredLayoutSize(Container parent) {
return parent.getPreferredSize();
}
@Override
public Dimension minimumLayoutSize(Container parent) {
return null;
}
@Override
public void layoutContainer(Container parent) {
UIButton editButton = getEditButton();
int width = parent.getParent().getWidth();
int height = parent.getParent().getHeight();
int preferWidth = editButton.getPreferredSize().width;
int preferHeight = editButton.getPreferredSize().height;
editButton.setBounds((width - preferWidth) / 2, (height - preferHeight) / 2, preferWidth, preferHeight);
controlButton.setBounds((width - 28), 0, 27, 27);
}
@Override
public void addLayoutComponent(String name, Component comp) {
}
};
} }
public void destroyHelpDialog() { public boolean isShared() {
if (helpDialog != null) { return isShared;
controlMode = IOUtils.readIcon(IconPathConstants.TD_EL_SHARE_HELP_ICON_PATH);
controlButton.repaint();
helpDialog.dispose();
helpDialog = null;
}
} }
@Override public void setShared(boolean shared) {
protected Rectangle getPaintBorderBounds(){ isShared = shared;
return new Rectangle(BORDER_WIDTH, BORDER_WIDTH, getWidth() - 3 * BORDER_WIDTH , getHeight() - 3 * BORDER_WIDTH);
} }
@Override @Override
public void setVisible(boolean aFlag) { public void paint(Graphics g) {
super.setVisible(aFlag); super.paint(g);
// if (aFlag) { if (isShared()) {
// HelpDialogManager.getInstance().setPane(this); paintShareButton(g, this);
// } }
} }
} }

133
designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java

@ -11,6 +11,7 @@ import com.fr.design.designer.beans.location.Direction;
import com.fr.design.designer.beans.location.Location; import com.fr.design.designer.beans.location.Location;
import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.beans.models.StateModel; import com.fr.design.designer.beans.models.StateModel;
import com.fr.design.designer.creator.XBorderStyleWidgetCreator;
import com.fr.design.designer.creator.XChartEditor; import com.fr.design.designer.creator.XChartEditor;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XCreatorUtils;
@ -28,9 +29,7 @@ import com.fr.design.icon.IconPathConstants;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.design.utils.gui.LayoutUtils; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.share.ShareConstants;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JComponent; import javax.swing.JComponent;
@ -41,6 +40,7 @@ import javax.swing.event.MouseInputAdapter;
import java.awt.Color; import java.awt.Color;
import java.awt.Container; import java.awt.Container;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Insets;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
@ -106,10 +106,10 @@ public class EditingMouseListener extends MouseInputAdapter {
private int minDragSize = 5; private int minDragSize = 5;
private int minMoveSize = 8; private int minMoveSize = 8;
private static final int EDIT_BTN_WIDTH = 60; private static final Insets DEEFAULT_INSETS = new Insets(0,0,0,0);
private static final int EDIT_BTN_HEIGHT = 24;
//报表块的编辑按钮不灵敏,范围扩大一点 //报表块的编辑按钮不灵敏,范围扩大一点
private static final int GAP = 10; private static final int GAP = 5;
private XElementCase xElementCase; private XElementCase xElementCase;
private XChartEditor xChartEditor; private XChartEditor xChartEditor;
@ -353,62 +353,48 @@ public class EditingMouseListener extends MouseInputAdapter {
} }
private void elementCaseMouseMoved(MouseEvent e, XCreator component) { private boolean isShareConfigButton(MouseEvent e, XCreator component, Insets insets) {
xElementCase = (XElementCase) component; if (component.isShared()) {
UIButton button = (UIButton) xElementCase.getCoverPane().getComponent(0); int minX = getParentPositionX(component, component.getX()) + component.getWidth() - insets.right - CoverReportPane.SHARE_CONF_BTN_W - designer.getHorizontalScaleValue();
if (designer.getCursor().getType() == Cursor.HAND_CURSOR) { int maxX = minX + CoverReportPane.SHARE_CONF_BTN_W;
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); int minY = getParentPositionY(component, component.getY()) + insets.top - designer.getVerticalScaleValue();
} // component.getParent() 是报表块所在的XWTitleLayout int maxY = minY + CoverReportPane.SHARE_CONF_BTN_H;
int minX = button.getX() + getParentPositionX(component, 0) - designer.getHorizontalScaleValue();
int minY = button.getY() + getParentPositionY(component, 0) - designer.getVerticalScaleValue() + xElementCase.getY(); if ((e.getX() > minX - GAP) && e.getX() < maxX + GAP) {
if (e.getX() + GAP - xElementCase.getInsets().left > minX && e.getX() - GAP - xElementCase.getInsets().left < minX + button.getWidth()) { if (e.getY() > minY - GAP && e.getY() < maxY + GAP) {
if (e.getY() + GAP - xElementCase.getInsets().top > minY && e.getY() - GAP - xElementCase.getInsets().top < minY + button.getHeight()) { return true;
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); }
} }
} }
setHelpBtnFocus(e, xElementCase); return false;
} }
private void setHelpBtnFocus(MouseEvent e, XCreator component) { private boolean isEditButton(MouseEvent e, XCreator component, Insets insets) {
component.setHelpBtnOnFocus(false); int innerWidth = component.getWidth() - insets.left - insets.right;
if (component.getCoverPane() != null) { int innerHeight = component.getHeight() - insets.top - insets.bottom;
if (component.getCoverPane().getComponentCount() > 1) {
JComponent button1 = (JComponent) component.getCoverPane().getComponent(1); int minX = getParentPositionX(component, component.getX()) + insets.left + (innerWidth - CoverReportPane.EDIT_BTN_W) / 2 - designer.getHorizontalScaleValue();
int minX1 = button1.getX() + getParentPositionX(component, 0) - designer.getHorizontalScaleValue(); int maxX = minX + CoverReportPane.EDIT_BTN_W;
int minY1 = button1.getY() + getParentPositionY(component, 0) - designer.getVerticalScaleValue() + component.getY(); int minY = getParentPositionY(component, component.getY()) + insets.top + (innerHeight - CoverReportPane.EDIT_BTN_H) / 2 - designer.getVerticalScaleValue();
if (e.getX() + GAP - component.getInsets().left > minX1 && e.getX() - GAP - component.getInsets().left < minX1 + button1.getWidth()) { int maxY = minY + CoverReportPane.EDIT_BTN_H;
if (e.getY() + GAP - component.getInsets().top > minY1 && e.getY() - GAP - component.getInsets().top < minY1 + button1.getHeight()) { if (e.getX() > minX - GAP && e.getX() < maxX + GAP) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); if (e.getY() > minY - GAP && e.getY() < maxY + GAP) {
component.setHelpBtnOnFocus(true); return true;
}
}
}
component.displayCoverPane(true);
component.setDirections(Direction.TOP_BOTTOM_LEFT_RIGHT);
} else {
//没有帮助信息时,不显示帮助图标
if (StringUtils.isEmpty(component.toData().getDescription())) {
return;
}
int minX1 = getParentPositionX(component, component.getX()) + component.getWidth() - ShareConstants.SHARE_EL_CONTROL_BUTTON_HW - designer.getHorizontalScaleValue();
int minY1 = getParentPositionY(component, component.getY()) - designer.getVerticalScaleValue();
if (e.getX() + GAP - component.getInsets().left > minX1 && e.getX() - GAP - component.getInsets().left < minX1 + ShareConstants.SHARE_EL_CONTROL_BUTTON_HW) {
if (e.getY() + GAP - component.getInsets().top > minY1 && e.getY() - GAP - component.getInsets().top < minY1 + ShareConstants.SHARE_EL_CONTROL_BUTTON_HW) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
component.setHelpBtnOnFocus(true);
}
} }
} }
return false;
} }
private void setCoverPaneNotDisplay(XCreator component, MouseEvent e, boolean isLinkedHelpDialog) { private void elementCaseMouseMoved(MouseEvent e, XCreator component) {
xElementCase = (XElementCase) component;
component.displayCoverPane(true);
processCoverMouseMove(component, e);
}
private void setCoverPaneNotDisplay(XCreator component, MouseEvent e, boolean isLinkedHelpDialog) {
if (xChartEditor != null) { if (xChartEditor != null) {
xChartEditor.displayCoverPane(false); xChartEditor.displayCoverPane(false);
} }
if (isLinkedHelpDialog) {
component.destroyHelpDialog();
}
component.displayCoverPane(false); component.displayCoverPane(false);
if (xTopLayoutContainer != null) { if (xTopLayoutContainer != null) {
xTopLayoutContainer.setMouseEnter(false); xTopLayoutContainer.setMouseEnter(false);
@ -432,19 +418,7 @@ public class EditingMouseListener extends MouseInputAdapter {
xTopLayoutContainer.setMouseEnter(true); xTopLayoutContainer.setMouseEnter(true);
designer.repaint(); designer.repaint();
if (!xTopLayoutContainer.isEditable()) { if (!xTopLayoutContainer.isEditable()) {
if (designer.getCursor().getType() == Cursor.HAND_CURSOR) { processCoverMouseMove(parent, e);
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
int minX = getParentPositionX(parent, parent.getX()) + parent.getWidth() / 2;
int minY = getParentPositionY(parent, parent.getY()) + parent.getHeight() / 2;
int offsetX = EDIT_BTN_WIDTH / 2 + GAP;
int offsetY = EDIT_BTN_HEIGHT / 2 + GAP;
if (e.getX() > (minX - offsetX) && e.getX() < (minX + offsetX)) {
if (e.getY() > (minY - offsetY) && e.getY() < (minY + offsetY + designer.getParaHeight())) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
}
setHelpBtnFocus(e, xTopLayoutContainer);
return true; return true;
} }
} }
@ -454,19 +428,28 @@ public class EditingMouseListener extends MouseInputAdapter {
private void processChartEditorMouseMove(XCreator component, MouseEvent e) { private void processChartEditorMouseMove(XCreator component, MouseEvent e) {
if (component instanceof XChartEditor) { if (component instanceof XChartEditor) {
xChartEditor = (XChartEditor) component; xChartEditor = (XChartEditor) component;
UIButton button = (UIButton) xChartEditor.getCoverPane().getComponent(0); component.displayCoverPane(true);
if (designer.getCursor().getType() == Cursor.HAND_CURSOR) { processCoverMouseMove(component, e);
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
} }
int minX = button.getX() + getParentPositionX(component, 0) - designer.getHorizontalScaleValue(); }
int minY = button.getY() + getParentPositionY(component, 0) - designer.getVerticalScaleValue() + xChartEditor.getY();
if (e.getX() + GAP > minX && e.getX() - GAP < minX + button.getWidth()) { private void processCoverMouseMove(XCreator component, MouseEvent e) {
if (e.getY() + GAP > minY && e.getY() - GAP < minY + button.getHeight()) { component.setShareConfigButtonFocus(false);
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); Insets insets;
} if (component instanceof XBorderStyleWidgetCreator) {
} insets = ((XBorderStyleWidgetCreator) component).getInsets();
setHelpBtnFocus(e, xChartEditor); } else {
designer.repaint(); insets = DEEFAULT_INSETS;
}
if (designer.getCursor().getType() == Cursor.HAND_CURSOR) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
if (isShareConfigButton(e, component, insets)) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
component.setShareConfigButtonFocus(true);
} else if (isEditButton(e, component, insets)) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
} }
} }

4
designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java

@ -22,10 +22,9 @@ import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.icon.IconPathConstants; import com.fr.design.icon.IconPathConstants;
import com.fr.design.mainframe.chart.info.ChartInfoCollector; import com.fr.design.mainframe.chart.info.ChartInfoCollector;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.form.share.SharableEditorProvider; import com.fr.form.share.editor.SharableEditorProvider;
import com.fr.form.share.SharableWidgetProvider; import com.fr.form.share.SharableWidgetProvider;
import com.fr.form.share.ShareLoader; import com.fr.form.share.ShareLoader;
import com.fr.form.ui.ChartEditor;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -43,7 +42,6 @@ import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent; import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent; import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent; import java.awt.dnd.DropTargetEvent;
import java.util.Map;
/** /**
* 添加模式下鼠标事件处理器 * 添加模式下鼠标事件处理器

420
designer-form/src/main/java/com/fr/design/mainframe/FormWidgetDetailPane.java

@ -1,45 +1,20 @@
package com.fr.design.mainframe; package com.fr.design.mainframe;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.FRContext; import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIHeadGroup;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ifilechooser.UINativeFileChooser;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.mainframe.share.collect.ComponentCollector;
import com.fr.design.widget.FRWidgetFactory; import com.fr.design.mainframe.share.ui.local.LocalWidgetRepoPane;
import com.fr.form.share.SharableWidgetProvider; import com.fr.design.mainframe.share.ui.online.OnlineWidgetRepoPane;
import com.fr.form.share.ShareLoader;
import com.fr.general.CloudCenter;
import com.fr.log.FineLoggerFactory;
import com.fr.share.ShareConstants;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.CardLayout;
import java.awt.Desktop; import java.util.ArrayList;
import java.awt.Dimension; import java.util.List;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
/** /**
* Created with IntelliJ IDEA. * Created with IntelliJ IDEA.
@ -48,19 +23,8 @@ import java.net.URISyntaxException;
* Time: 下午8:18 * Time: 下午8:18
*/ */
public class FormWidgetDetailPane extends FormDockView{ public class FormWidgetDetailPane extends FormDockView{
private static final int LOCAL_WIDGET_LABEL_WIDTH = 90; private JPanel centerPane;
private List<BasicPane> paneList;
private UIScrollPane downPane;
private JPanel reuWidgetPanel;
private UIComboBox comboBox;
private SharableWidgetProvider[] elCaseBindInfoList;
private UIButton deleteButton;
private JPanel editPanel;
private JPanel resetPanel;
private JPanel menutPanelNorthPane;
private SwingWorker sw;
//组件面板是否可以编辑
private boolean isEdit;
public static FormWidgetDetailPane getInstance() { public static FormWidgetDetailPane getInstance() {
if (HOLDER.singleton == null) { if (HOLDER.singleton == null) {
@ -99,348 +63,32 @@ public class FormWidgetDetailPane extends FormDockView{
public void refreshDockingView(){ public void refreshDockingView(){
FormDesigner designer = this.getEditingFormDesigner(); FormDesigner designer = this.getEditingFormDesigner();
removeAll(); removeAll();
if(designer == null){ if (designer == null) {
clearDockingView(); clearDockingView();
return; return;
} }
reuWidgetPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
reuWidgetPanel.setBorder(null);
if (elCaseBindInfoList == null) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
refreshDownPanel(false);
return null;
}
};
sw.execute();
}
initReuWidgetPanel();
initMenuPanel();
add(reuWidgetPanel, BorderLayout.CENTER);
}
/**
* 初始化组件共享和复用面板
*/
private void initReuWidgetPanel() {
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
downPane = new UIScrollPane(new ShareWidgetPane(elCaseBindInfoList, false));
downPane.setBorder(null);
reuWidgetPanel.add(downPane);
}
/**
* 初始化菜单栏面板
*/
private void initMenuPanel() {
JPanel menutPanel = new JPanel();
menutPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
menutPanel.setBorder(BorderFactory.createEmptyBorder(3, 10, 10, 15));
menutPanelNorthPane = new JPanel(new BorderLayout());
UILabel localWidgetLabel = FRWidgetFactory.createLineWrapLabel(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Local_Widget"),
LOCAL_WIDGET_LABEL_WIDTH);
menutPanelNorthPane.add(localWidgetLabel, BorderLayout.WEST);
menutPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
menutPanelNorthPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
menutPanel.add(menutPanelNorthPane, BorderLayout.NORTH);
comboBox = new UIComboBox(getFormCategories());
comboBox.setPreferredSize(new Dimension(240, comboBox.getPreferredSize().height));
initComboBoxSelectedListener();
menutPanel.add(comboBox, BorderLayout.CENTER);
reuWidgetPanel.add(menutPanel, BorderLayout.NORTH);
}
/**
* 创建菜单栏按钮面板
*/
private JPanel initEditButtonPane() {
editPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
editPanel.add(createRefreshButton());
editPanel.add(createDownloadButton());
editPanel.add(createInstallButton());
editPanel.add(createDeleteButton());
return editPanel;
}
/**
* 创建取消删除面板
*/
private JPanel initResetButtonPane() {
resetPanel = new JPanel();
UIButton resetButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Reset"));
resetPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
resetButton.setBackground(Color.white);
resetButton.setForeground(new Color(0x333334));
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshDownPanel(false);
replaceButtonPanel(false);
reuWidgetPanel.remove(deleteButton);
}
});
deleteButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Remove_Item"));
deleteButton.setBackground(Color.white);
deleteButton.setForeground(new Color(0xeb1d1f));
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (ShareLoader.getLoader().removeModulesFromList()) {
refreshShareMoudule();
reuWidgetPanel.remove(deleteButton);
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Successful"));
refreshDownPanel(false);
replaceButtonPanel(false);
refreshComboxData();
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_Removed_Failed"));
}
}
});
JPanel deletePane = new JPanel(new BorderLayout());
deletePane.add(deleteButton, BorderLayout.CENTER);
deletePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
resetPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
resetPanel.add(resetButton, BorderLayout.CENTER);
resetPanel.add(deletePane, BorderLayout.WEST);
refreshDownPanel(true);
return resetPanel;
}
private void initComboBoxSelectedListener() {
comboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ShareLoader.getLoader().resetRemovedModuleList();
int filterIndex = comboBox.getSelectedIndex();
if (filterIndex == 0) {
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
} else {
String filterName = comboBox.getSelectedItem().toString();
elCaseBindInfoList = ShareLoader.getLoader().getFilterBindInfoList(filterName);
}
refreshDownPanel(isEdit);
}
});
}
/**
* 创建工具条按钮
*/
private UIButton createToolButton(Icon icon, String toolTip, ActionListener actionListener) {
UIButton toolButton = new UIButton();
toolButton.setIcon(icon);
toolButton.setToolTipText(toolTip);
toolButton.set4ToolbarButton();
toolButton.addActionListener(actionListener);
return toolButton;
}
/**
* 创建刷新按钮
*/
private UIButton createRefreshButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/refresh.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Refresh"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (sw != null) {
sw.cancel(true);
}
sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
ShareLoader.getLoader().refreshModule();
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
refreshComboxData();
refreshDownPanel(false);
return null;
}
};
sw.execute();
}
}
);
}
private void refreshComboxData() {
comboBox.setSelectedIndex(0);
comboBox.setModel(new DefaultComboBoxModel(getFormCategories()));
}
/** initPaneList();
* 创建下载模板的按钮 this.setBorder(null);
*/ final CardLayout cardLayout = new CardLayout();
private UIButton createDownloadButton() { centerPane = new JPanel(cardLayout);
UIButton downloadButton = new UIButton(); String[] paneNames = new String[paneList.size()];
downloadButton.setIcon(BaseUtils.readIcon("/com/fr/design/form/images/download icon.png")); for (int i = 0; i < paneList.size(); i++) {
downloadButton.set4ToolbarButton(); String title = paneList.get(i).getTitle();
downloadButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Download_Template")); paneNames[i] = title;
downloadButton.addActionListener(new ActionListener() { centerPane.add(paneList.get(i), title);
@Override
public void actionPerformed(ActionEvent e) {
String url = CloudCenter.getInstance().acquireUrlByKind("reuse.url");
if (StringUtils.isEmpty(url)) {
FRContext.getLogger().info("The URL is empty!");
return;
}
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException exp) {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Set_Default_Browser_Duplicate"));
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (URISyntaxException exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
} catch (Exception exp) {
FineLoggerFactory.getLogger().error(exp.getMessage(), exp);
FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + url);
}
}
});
return downloadButton;
}
/**
* 创建安装模板的按钮
*/
private UIButton createInstallButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/install icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Install_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (SupportOSImpl.NATIVE_CHOOSER.support()) {
UINativeFileChooser nativeFileChooser = new UINativeFileChooser();
nativeFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
nativeFileChooser.setMultiSelectionEnabled(true);
nativeFileChooser.setExtensionFilter("*.reu");
nativeFileChooser.setDialogTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select"));
int returnValue = nativeFileChooser.showOpenDialog(new UILabel());
if (returnValue == JFileChooser.APPROVE_OPTION) {
final File[] chosenFiles = nativeFileChooser.getSelectedFiles();
for (File file : chosenFiles) {
installFromDiskZipFile(file);
}
}
} else {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setMultiSelectionEnabled(true);
fileChooser.setFileFilter(new FileNameExtensionFilter(".reu", "reu"));
int returnValue = fileChooser.showDialog(new UILabel(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Select"));
if (returnValue == JFileChooser.APPROVE_OPTION) {
final File[] chosenFiles = fileChooser.getSelectedFiles();
for (File file : chosenFiles) {
installFromDiskZipFile(file);
}
}
}
}
}
);
}
/**
* 创建删除模板的按钮
*/
private UIButton createDeleteButton() {
return createToolButton(
BaseUtils.readIcon("/com/fr/design/form/images/delete icon.png"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Delete_Template"),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
replaceButtonPanel(true);
}
}
);
}
private void replaceButtonPanel(boolean isEdit) {
this.isEdit = isEdit;
if (isEdit) {
menutPanelNorthPane.remove(editPanel);
menutPanelNorthPane.add(initResetButtonPane(), BorderLayout.EAST);
} else {
menutPanelNorthPane.remove(resetPanel);
menutPanelNorthPane.add(initEditButtonPane(), BorderLayout.EAST);
ShareLoader.getLoader().resetRemovedModuleList();
} }
} UIHeadGroup headGroup = new UIHeadGroup(paneNames) {
protected void tabChanged(int newSelectedIndex) {
private void installFromDiskZipFile(File chosenFile) { if (newSelectedIndex == 1) {
if (chosenFile != null && chosenFile.getName().endsWith(ShareConstants.SUFFIX_MODULE)) { ComponentCollector.getInstance().collectMarkerClick();
try {
if (ShareLoader.getLoader().installModuleFromDiskZipFile(chosenFile)) {
refreshShareMoudule();
elCaseBindInfoList = ShareLoader.getLoader().getAllBindInfoList();
refreshDownPanel(false);
refreshComboxData();
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Share_Module_OK"));
} else {
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
} }
} catch (IOException e) { cardLayout.show(centerPane, paneList.get(newSelectedIndex).getTitle());
JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Share_Module_Error"));
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} };
} headGroup.setSelectedIndex(0);
this.add(headGroup, BorderLayout.NORTH);
private void refreshShareMoudule() { this.add(centerPane, BorderLayout.CENTER);
try {
ShareLoader.getLoader().refreshModule();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
* 获取报表块组件分类
*/
public String[] getFormCategories() {
return ArrayUtils.addAll(new String[] {com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_AllCategories")}, ShareLoader.getLoader().getModuleCategory());
}
public void refreshDownPanel(boolean isEdit) {
reuWidgetPanel.remove(downPane);
downPane = new UIScrollPane(new ShareWidgetPane(elCaseBindInfoList, isEdit));
downPane.setBorder(null);
reuWidgetPanel.add(downPane);
repaintContainer();
}
public void repaintContainer() {
validate();
repaint();
revalidate();
} }
/** /**
@ -453,14 +101,20 @@ public class FormWidgetDetailPane extends FormDockView{
} }
/** /**
* 定位 * 定位
* @return 位置 *
* @return 位置
*/ */
@Override
public Location preferredLocation() { public Location preferredLocation() {
return Location.WEST_BELOW; return Location.WEST_BELOW;
} }
private void initPaneList() {
paneList = new ArrayList<>();
paneList.add(LocalWidgetRepoPane.getInstance());
paneList.add(OnlineWidgetRepoPane.getInstance());
}
} }

314
designer-form/src/main/java/com/fr/design/mainframe/ShareWidgetButton.java

@ -1,314 +0,0 @@
package com.fr.design.mainframe;
import com.fr.base.iofile.attr.SharableAttrMark;
import com.fr.base.vcs.DesignerMode;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.gui.ilable.UILabel;
import com.fr.form.share.SharableWidgetProvider;
import com.fr.form.share.ShareLoader;
import com.fr.form.ui.AbstractBorderStyleWidget;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.share.ShareConstants;
import com.fr.stable.StringUtils;
import org.jetbrains.annotations.NotNull;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Composite;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceAdapter;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.IOException;
import java.io.Serializable;
/**
* Coder: zack
* Date: 2016/10/9
* Time: 16:14
*/
public class ShareWidgetButton extends JPanel implements MouseListener, MouseMotionListener, Serializable {
protected SharableWidgetProvider bindInfo;
protected MouseEvent lastPressEvent;
protected JPanel reportPane;
protected boolean isEdit;
protected boolean isMarked;
private ShareWidgetUI ui;
private Icon markedMode = IOUtils.readIcon("/com/fr/design/form/images/marked.png");
private Icon unMarkedMode = IOUtils.readIcon("/com/fr/design/form/images/unmarked.png");
private AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 60 / 100.0F);
private JComponent markedButton = new JComponent() {
protected void paintComponent(Graphics g) {
markedMode.paintIcon(this, g, 0, 0);
}
};
private JComponent unMarkedButton = new JComponent() {
protected void paintComponent(Graphics g) {
unMarkedMode.paintIcon(this, g, 0, 0);
}
};
public ShareWidgetButton(SharableWidgetProvider bindInfo, ShareWidgetUI ui) {
this.bindInfo = bindInfo;
this.ui = ui;
this.setPreferredSize(new Dimension(108, 68));
initUI();
this.setLayout(getCoverLayout());
this.addMouseListener(this);
this.addMouseMotionListener(this);
new DragAndDropDragGestureListener(this, DnDConstants.ACTION_COPY_OR_MOVE);
}
public ShareWidgetButton(SharableWidgetProvider bindInfo) {
this(bindInfo, new ShareWidgetUI());
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
g2d.setComposite(composite);
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setComposite(oldComposite);
super.paint(g);
}
public void setElementCaseEdit(boolean isEdit) {
this.isEdit = isEdit;
if (isEdit) {
this.add(unMarkedButton, 0);
repaint();
}
}
private void initUI() {
reportPane = new JPanel(new BorderLayout());
reportPane.add(new UILabel(new ImageIcon(bindInfo.getCover())), BorderLayout.CENTER);
JPanel labelPane = new JPanel(new BorderLayout());
UILabel label = new UILabel(bindInfo.getName(), UILabel.CENTER);
labelPane.setBackground(new Color(184, 220, 242));
labelPane.add(label, BorderLayout.CENTER);
reportPane.add(labelPane, BorderLayout.SOUTH);
add(reportPane);
}
protected LayoutManager getCoverLayout() {
return new LayoutManager() {
@Override
public void removeLayoutComponent(Component comp) {
}
@Override
public Dimension preferredLayoutSize(Container parent) {
return parent.getPreferredSize();
}
@Override
public Dimension minimumLayoutSize(Container parent) {
return null;
}
@Override
public void layoutContainer(Container parent) {
int width = parent.getWidth();
int height = parent.getHeight();
markedButton.setBounds((width - 25), 0, 25, 25);
unMarkedButton.setBounds((width - 25), 0, 25, 25);
reportPane.setBounds(0, 0, width, height);
}
@Override
public void addLayoutComponent(String name, Component comp) {
}
};
}
public SharableWidgetProvider getBindInfo() {
return bindInfo;
}
public void setBindInfo(SharableWidgetProvider bindInfo) {
this.bindInfo = bindInfo;
}
public String getFileName() {
return bindInfo.getName() +"." + bindInfo.getId() + ShareConstants.SUFFIX_MODULE;
}
@Override
public void mouseClicked(MouseEvent e) {
if (isEdit) {
if (isMarked) {
remove(markedButton);
ShareLoader.getLoader().removeModuleForList(getFileName());
isMarked = false;
} else {
add(markedButton,0);
ShareLoader.getLoader().addModuleToList(getFileName());
isMarked = true;
}
}
repaint();
}
@Override
public void mousePressed(MouseEvent e) {
lastPressEvent = e;
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseDragged(MouseEvent e) {
if (DesignerMode.isAuthorityEditing()) {
return;
}
if (lastPressEvent == null) {
return;
}
Object source = e.getSource();
Widget creatorSource = null;
String shareId = StringUtils.EMPTY;
if (source instanceof ShareWidgetButton) {
ShareWidgetButton no = (ShareWidgetButton) e.getSource();
if (no == null) {
return;
}
shareId = no.getBindInfo().getId();
creatorSource = ShareLoader.getLoader().getElCaseEditorById(shareId);
if (creatorSource != null) {
((AbstractBorderStyleWidget)creatorSource).addWidgetAttrMark(new SharableAttrMark(true));
//tab布局WCardMainBorderLayout通过反射出来的大小是960*480
XCreator xCreator = ui.createXCreator(creatorSource, shareId, no.getBindInfo());
WidgetToolBarPane.getTarget().startDraggingBean(xCreator);
lastPressEvent = null;
this.setBorder(null);
}
}
}
@Override
public void mouseMoved(MouseEvent e) {
}
public class DragAndDropDragGestureListener extends DragSourceAdapter implements DragGestureListener {
private DragSource source;
public DragAndDropDragGestureListener(ShareWidgetButton tt, int actions) {
source = new DragSource();
source.createDefaultDragGestureRecognizer(tt, actions, this);
}
public void dragGestureRecognized(DragGestureEvent dge) {
ShareWidgetButton shareWidgetButton = (ShareWidgetButton) dge.getComponent();
if (shareWidgetButton != null) {
Widget widget = ShareLoader.getLoader().getElCaseEditorById(shareWidgetButton.getBindInfo().getId());
DragAndDropTransferable dragAndDropTransferable = new DragAndDropTransferable(widget);
dge.startDrag(DragSource.DefaultCopyDrop, dragAndDropTransferable, this);
}
}
@Override
public void dragEnter(DragSourceDragEvent dragSourceDragEvent) {
}
}
public class DragAndDropTransferable implements Transferable {
private Widget widget;
public DragAndDropTransferable(Widget widget) {
this.widget = widget;
}
DataFlavor[] flavors = {new DataFlavor(Widget.class, "Widget")};
public DataFlavor[] getTransferDataFlavors() {
return flavors;
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
for (DataFlavor df : flavors) {
if (ComparatorUtils.equals(df, flavor)) {
return true;
}
}
return false;
}
public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException {
return widget;
}
}
/**
* 抽出来专门为了创建 ui 来搞
*/
public static class ShareWidgetUI {
private static final Dimension TAB_DEFAULT_SIZE = new Dimension(500, 300);
@NotNull
public XCreator createXCreator(Widget creatorSource, String shareId, SharableWidgetProvider provider) {
XCreator xCreator = null;
if (creatorSource instanceof WCardMainBorderLayout) {
xCreator = XCreatorUtils.createXCreator(creatorSource, TAB_DEFAULT_SIZE);
} else {
xCreator = XCreatorUtils.createXCreator(creatorSource, new Dimension(provider.getWidth(), provider.getHeight()));
}
xCreator.setBackupBound(new Rectangle(provider.getWidth(), provider.getHeight()));
xCreator.setShareId(shareId);
return xCreator;
}
}
}

29
designer-form/src/main/java/com/fr/design/mainframe/ShareWidgetPane.java

@ -1,29 +0,0 @@
package com.fr.design.mainframe;
import com.fr.form.share.SharableWidgetProvider;
import javax.swing.*;
import java.awt.*;
/**
* Created by xiaxiang on 2016/10/10.
*/
public class ShareWidgetPane extends JPanel {
public ShareWidgetPane(SharableWidgetProvider[] elCaseBindInfoList, boolean isEdit) {
this.setBorder(BorderFactory.createEmptyBorder(10, 3, 0, 0));// 设置面板的边框 ,距离上、左、下、右 的距离
if (elCaseBindInfoList != null) {
int rowCount = (elCaseBindInfoList.length + 1) / 2;
this.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 10));
for (SharableWidgetProvider rbModuleInfo : elCaseBindInfoList) {
ShareWidgetButton widgetButton = new ShareWidgetButton(rbModuleInfo);
widgetButton.setElementCaseEdit(isEdit);
this.add(widgetButton);
}
this.setPreferredSize(new Dimension(240, rowCount * 80));
}
}
}

11
designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java

@ -6,13 +6,12 @@ import com.fr.design.constants.UIConstants;
import com.fr.design.designer.beans.events.DesignerEditListener; import com.fr.design.designer.beans.events.DesignerEditListener;
import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.*; import com.fr.design.designer.creator.*;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import com.fr.design.designer.creator.cardlayout.XWCardTagLayout; import com.fr.design.designer.creator.cardlayout.XWCardTagLayout;
import com.fr.design.designer.properties.EventPropertyTable;
import com.fr.design.designer.properties.mobile.MobileBookMarkPropertyUI; import com.fr.design.designer.properties.mobile.MobileBookMarkPropertyUI;
import com.fr.design.designer.properties.mobile.MobileStylePropertyUI; import com.fr.design.designer.properties.mobile.MobileStylePropertyUI;
import com.fr.design.form.util.FormDesignerUtils; import com.fr.design.form.util.FormDesignerUtils;
import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.fun.WidgetPropertyUIProvider;
import com.fr.design.gui.controlpane.EventPropertyPane;
import com.fr.design.gui.ibutton.UIHeadGroup; import com.fr.design.gui.ibutton.UIHeadGroup;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
@ -38,7 +37,7 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
private static final int PADDING = 10; private static final int PADDING = 10;
private static final int PADDING_M = 12; private static final int PADDING_M = 12;
private FormWidgetCardPane formWidgetCardPane; // 控件的属性表 private FormWidgetCardPane formWidgetCardPane; // 控件的属性表
private EventPropertyTable eventTable; // 控件的事件表 private EventPropertyPane eventTable; // 控件的事件表
private List<AbstractPropertyTable> widgetPropertyTables; // 这个变量应该是保存控件拓展的属性tab private List<AbstractPropertyTable> widgetPropertyTables; // 这个变量应该是保存控件拓展的属性tab
private List<MobileWidgetDefinePane> mobileExtraPropertyPanes; // 保存9.0设计器下移动端拓展的属性tab,舍弃JTable private List<MobileWidgetDefinePane> mobileExtraPropertyPanes; // 保存9.0设计器下移动端拓展的属性tab,舍弃JTable
private FormDesigner designer; // 当前designer private FormDesigner designer; // 当前designer
@ -141,7 +140,7 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
* 创建事件表事件选项卡不是JTable * 创建事件表事件选项卡不是JTable
*/ */
private void createEventTable() { private void createEventTable() {
eventTable = new EventPropertyTable(designer); eventTable = new EventPropertyPane(designer);
designer.addDesignerEditListener(new EventPropertyDesignerAdapter(eventTable)); designer.addDesignerEditListener(new EventPropertyDesignerAdapter(eventTable));
} }
@ -337,9 +336,9 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
* 事件表监听界面事件编辑选中 * 事件表监听界面事件编辑选中
*/ */
private class EventPropertyDesignerAdapter implements DesignerEditListener { private class EventPropertyDesignerAdapter implements DesignerEditListener {
EventPropertyTable propertyTable; EventPropertyPane propertyTable;
EventPropertyDesignerAdapter(EventPropertyTable eventTable) { EventPropertyDesignerAdapter(EventPropertyPane eventTable) {
this.propertyTable = eventTable; this.propertyTable = eventTable;
} }

62
designer-form/src/main/java/com/fr/design/mainframe/share/AbstractWidgetSelectPane.java

@ -0,0 +1,62 @@
package com.fr.design.mainframe.share;
import com.fr.design.mainframe.share.ui.base.PopupPreviewPane;
import com.fr.design.mainframe.share.ui.block.PreviewWidgetBlock;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.stable.StringUtils;
import javax.swing.JPanel;
import java.awt.Container;
/**
* @Author: Yuan.Wang
* @Date: 2021/1/15
*/
public abstract class AbstractWidgetSelectPane extends JPanel {
private static final int SCROLL_BAR_HEIGHT = 10;
private final PopupPreviewPane previewPane;
private String currentShowWidgetID;
public AbstractWidgetSelectPane() {
this.previewPane = new PopupPreviewPane();
}
public void showPreviewPane(PreviewWidgetBlock<?> comp, String showWidgetID) {
if (ComparatorUtils.equals(currentShowWidgetID, showWidgetID)) {
return;
}
popupPreviewPane(comp, showWidgetID);
}
public void hidePreviewPane() {
if (previewPane != null && previewPane.isVisible()) {
previewPane.setVisible(false);
}
this.currentShowWidgetID = StringUtils.EMPTY;
}
private void popupPreviewPane(PreviewWidgetBlock<?> comp, String showWidgetID) {
if (previewPane.isVisible()) {
previewPane.setVisible(false);
}
if (!previewPane.isVisible() && comp.getWidth() != 0 && comp.getHeight() != 0) {
//父容器是GroupPane,要获得的是GroupPane的父容器
Container parentContainer =getParentContainer();
previewPane.setComp(comp.getPreviewImage());
int popupPosY = comp.getLocationOnScreen().y - parentContainer.getLocationOnScreen().y;
if (previewPane.getHeight() + popupPosY > parentContainer.getHeight() + SCROLL_BAR_HEIGHT) {
popupPosY -= (previewPane.getHeight() + popupPosY - parentContainer.getHeight() - SCROLL_BAR_HEIGHT);
}
int popupPosX = -previewPane.getPreferredSize().width;
if (parentContainer.getLocationOnScreen().x < previewPane.getPreferredSize().width) {
popupPosX = parentContainer.getWidth();
}
GUICoreUtils.showPopupMenu(previewPane, parentContainer, popupPosX, popupPosY);
this.currentShowWidgetID = showWidgetID;
}
}
abstract protected Container getParentContainer();
}

59
designer-form/src/main/java/com/fr/design/mainframe/share/Bean/ComponentGenerateInfo.java

@ -0,0 +1,59 @@
package com.fr.design.mainframe.share.Bean;
import com.fr.design.mainframe.JTemplate;
import com.fr.form.share.DefaultSharableWidget;
import com.fr.form.ui.Widget;
import java.util.Map;
/**
* created by Harrison on 2020/04/13
*
* 组件生成信息
**/
public class ComponentGenerateInfo {
private boolean autoUpload;
private JTemplate<?, ?> jt;
private Map<String, Object> paraMap;
private Widget widget;
private DefaultSharableWidget info;
public ComponentGenerateInfo(boolean autoUpload, JTemplate<?, ?> jt, Map<String, Object> paraMap, Widget widget, DefaultSharableWidget info) {
this.autoUpload = autoUpload;
this.jt = jt;
this.paraMap = paraMap;
this.widget = widget;
this.info = info;
}
public boolean isAutoUpload() {
return autoUpload;
}
public JTemplate<?, ?> getJt() {
return jt;
}
public Map<String, Object> getParaMap() {
return paraMap;
}
public Widget getWidget() {
return widget;
}
public DefaultSharableWidget getInfo() {
return info;
}
}

114
designer-form/src/main/java/com/fr/design/mainframe/share/Bean/LinkageChangeBean.java

@ -0,0 +1,114 @@
package com.fr.design.mainframe.share.Bean;
import com.fr.design.mainframe.share.constants.ComponentTypes;
import com.fr.form.share.bean.WidgetDeviceBean;
import com.fr.form.share.bean.WidgetTypeBean;
import com.fr.design.mainframe.share.constants.DisplayDevice;
import com.fr.stable.AssistUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 下拉框与下拉复现框联动状态
* @author hades
* @version 10.0
* Created by hades on 2020/6/9
*/
public class LinkageChangeBean {
private static final Map<LinkageChangeBean, List<String>> STATE_MAP = new HashMap<>();
static {
// all or default
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(false, false), new WidgetTypeBean(false, false)), ComponentTypes.allTypes());
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(true, true), new WidgetTypeBean(true, true)), ComponentTypes.allTypes());
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(false, false), new WidgetTypeBean(true, true)), ComponentTypes.allTypes());
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(true, true), new WidgetTypeBean(false, false)), ComponentTypes.allTypes());
// pc
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(false, true), new WidgetTypeBean(false, false)), ComponentTypes.allTypesByDevice(DisplayDevice.PC.getType()));
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(false, true), new WidgetTypeBean(true, true)), ComponentTypes.allTypesByDevice(DisplayDevice.PC.getType()));
// mobile
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(true, false), new WidgetTypeBean(false, false)), ComponentTypes.allTypesByDevice(DisplayDevice.MOBILE.getType()));
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(true, false), new WidgetTypeBean(true, true)), ComponentTypes.allTypesByDevice(DisplayDevice.MOBILE.getType()));
// report
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(false, false), new WidgetTypeBean(true, false)), ComponentTypes.REPORT.types());
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(true, true), new WidgetTypeBean(true, false)), ComponentTypes.REPORT.types());
// chart
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(false, false), new WidgetTypeBean(false, true)), ComponentTypes.CHART.types());
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(true, true), new WidgetTypeBean(false, true)), ComponentTypes.CHART.types());
// pc-report
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(false, true), new WidgetTypeBean(true, false)), ComponentTypes.REPORT.children(DisplayDevice.PC.getType()));
// pc-chart
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(false, true), new WidgetTypeBean(false, true)), ComponentTypes.CHART.children(DisplayDevice.PC.getType()));
// mobile-report
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(true, false), new WidgetTypeBean(true, false)), ComponentTypes.REPORT.children(DisplayDevice.MOBILE.getType()));
// mobile-chart
STATE_MAP.put(new LinkageChangeBean(new WidgetDeviceBean(true, false), new WidgetTypeBean(false, true)), ComponentTypes.CHART.children(DisplayDevice.MOBILE.getType()));
}
public static List<String> getComboBoxItems(LinkageChangeBean bean) {
return STATE_MAP.get(bean);
}
private LinkageChangeBean(WidgetDeviceBean widgetDeviceBean, WidgetTypeBean widgetTypeBean) {
this.widgetDeviceBean = widgetDeviceBean;
this.widgetTypeBean = widgetTypeBean;
}
private WidgetTypeBean widgetTypeBean;
private WidgetDeviceBean widgetDeviceBean;
public static class Builder {
private boolean report;
private boolean chart;
private boolean mobile;
private boolean pc;
public Builder setReport(boolean report) {
this.report = report;
return this;
}
public Builder setChart(boolean chart) {
this.chart = chart;
return this;
}
public Builder setMobile(boolean mobile) {
this.mobile = mobile;
return this;
}
public Builder setPc(boolean pc) {
this.pc = pc;
return this;
}
public LinkageChangeBean build() {
return new LinkageChangeBean(new WidgetDeviceBean(this.mobile, this.pc), new WidgetTypeBean(this.report, this.chart));
}
}
@Override
public boolean equals(Object o) {
return o instanceof LinkageChangeBean
&& AssistUtils.equals(this.widgetDeviceBean, ((LinkageChangeBean) o).widgetDeviceBean)
&& AssistUtils.equals(this.widgetTypeBean, ((LinkageChangeBean) o).widgetTypeBean);
}
@Override
public int hashCode() {
return AssistUtils.hashCode(this.widgetDeviceBean, this.widgetTypeBean);
}
}

398
designer-form/src/main/java/com/fr/design/mainframe/share/action/CreateComponentAction.java

@ -0,0 +1,398 @@
package com.fr.design.mainframe.share.action;
import com.fr.base.Parameter;
import com.fr.base.ParameterMapNameSpace;
import com.fr.base.TableData;
import com.fr.chart.chartattr.Chart;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.chartdata.TableDataDefinition;
import com.fr.data.impl.NameTableData;
import com.fr.data.impl.TableDataDictionary;
import com.fr.design.actions.UpdateAction;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrame;
import com.fr.design.mainframe.FormSelection;
import com.fr.design.mainframe.JForm;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.share.constants.ShareEntryKey;
import com.fr.design.mainframe.share.select.ComponentTransformerFactory;
import com.fr.design.parameter.ParameterInputPane;
import com.fr.form.FormElementCaseProvider;
import com.fr.form.main.Form;
import com.fr.form.main.FormIO;
import com.fr.form.main.WidgetGather;
import com.fr.form.ui.BaseChartEditor;
import com.fr.form.ui.ChartEditor;
import com.fr.form.ui.DataControl;
import com.fr.form.ui.DictionaryContainer;
import com.fr.form.ui.ElementCaseEditor;
import com.fr.form.ui.Widget;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.report.cell.DefaultTemplateCellElement;
import com.fr.report.cell.cellattr.core.group.DSColumn;
import com.fr.script.Calculator;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Constants;
import com.fr.stable.CoreGraphHelper;
import com.fr.stable.DependenceProvider;
import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils;
import com.fr.stable.bridge.StableFactory;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.script.NameSpace;
import com.fr.third.guava.base.Preconditions;
import com.fr.third.org.apache.commons.lang3.tuple.ImmutableTriple;
import com.fr.third.org.apache.commons.lang3.tuple.Triple;
import javax.swing.Action;
import javax.swing.UIManager;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import static javax.swing.JOptionPane.ERROR_MESSAGE;
/**
* @Author: Yuan.Wang
* @Date: 2020/11/3
* 创建组件事件
*/
public class CreateComponentAction extends UpdateAction {
ShareUIAspect aspect;
/**
* 等待时间 500 ms.
*/
private static final int WAIT_TIME = 500;
private final HashMap<String, Object> parameterMap = new HashMap<>();
private String[] widgetPara = new String[]{};
public CreateComponentAction(ShareUIAspect aspect) {
this.putValue(Action.SMALL_ICON, null);
this.setName(Toolkit.i18nText("Fine-Design_Share_Create"));
this.aspect = aspect;
}
@Override
public void actionPerformed(ActionEvent event) {
DesignerFrame designerFrame = DesignerContext.getDesignerFrame();
// 停止编辑
JTemplate<?, ?> jt = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate();
jt.stopEditing();
Form form = null;
try {
form = (Form) jt.getTarget().clone();
} catch (CloneNotSupportedException e1) {
FineLoggerFactory.getLogger().error(e1.getMessage(), e1);
}
FormSelection selection = ((JForm) jt).getFormDesign().getSelectionModel().getSelection();
// 获取选中的组件
Triple<Widget, XCreator, Rectangle> sharedTriple = ComponentTransformerFactory.getInstance().transform(selection);
if (sharedTriple == null) {
FineJOptionPane.showMessageDialog(designerFrame, Toolkit.i18nText("Fine-Design_Share_Select_Error_Tip"),
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), ERROR_MESSAGE, IOUtils.readIcon("/com/fr/base/images/share/Information_Icon_warning_normal_32x32.png"));
return;
}
Widget widget = sharedTriple.getLeft();
try {
if (form == null) {
throw new NullPointerException("tpl get failed");
}
//准备参数
prepareParameter(widget, designerFrame);
//准备的封面大小
//组件大小
Rectangle reportRec = FormIO.getContentRect(form);
Image coverImage = toCoverImage(form, sharedTriple, parameterMap, reportRec);
Object[] compositeArg = new Object[]{jt, widget, sharedTriple.getRight(), coverImage, parameterMap, (ShareUIAspect)aspect};
HashMap<String, Class> compoClass = new HashMap<String, Class>();
compoClass.put(Constants.ARG_0, JTemplate.class);
compoClass.put(Constants.ARG_1, Widget.class);
compoClass.put(Constants.ARG_2, Rectangle.class);
compoClass.put(Constants.ARG_3, Image.class);
compoClass.put(Constants.ARG_4, HashMap.class);
compoClass.put(Constants.ARG_5, ShareUIAspect.class);
BasicPane ShareGuidePane = StableFactory.getMarkedInstanceObjectFromClass(ShareEntryKey.SHARE_GENERATE, compositeArg, compoClass, BasicPane.class);
// ShareGuidePane moduleGuidePane = new ShareGuidePane(jt, widget, sharedTriple.getRight(), coverImage, parameterMap, aspect);
ShareGuidePane.show();
} catch (Exception e) {
FineJOptionPane.showMessageDialog(designerFrame, Toolkit.i18nText("Fine-Design_Share_Create_Share_Pane_Failed"),
Toolkit.i18nText("Fine-Design_Basic_Error"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon"));
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
* 准备参数
*/
private void prepareParameter(Widget widget, DesignerFrame designerFrame) {
final Calculator ca = Calculator.createCalculator();
Parameter[] tplParameters = ((Form)HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().getTarget()).getParameters();
widgetPara = new String[]{};
calWidgetParameter(widget, ca);
List<Parameter> tplPList = new ArrayList<Parameter>();
//只弹出使用到参数,其他的不要
for (String wp : widgetPara) {
for (Parameter tplParameter : tplParameters) {
if (wp.length() > 0 && StringUtils.equals(wp, tplParameter.getName())) {
tplPList.add(tplParameter);
} else if (wp.contains("$") && StringUtils.equals(wp.substring(1, wp.length()), tplParameter.getName())){
tplPList.add(tplParameter);
}
}
}
Parameter[] parameters = new Parameter[tplPList.size()];
tplPList.toArray(parameters);
if (ArrayUtils.isNotEmpty(parameters)) {// 检查Parameter.
final ParameterInputPane pPane = new ParameterInputPane(parameters);
pPane.showSmallWindow(designerFrame, new DialogActionAdapter() {
@Override
public void doOk() {
parameterMap.putAll(pPane.update());
}
}).setVisible(true);
}
}
private Triple<Widget, XCreator, Rectangle> prepareImageArgs(Triple<Widget, XCreator, Rectangle> pair, Rectangle reportRec) {
Widget widget = pair.getLeft();
XCreator xCreator = pair.getMiddle();
Rectangle rectangle = pair.getRight();
if (widget instanceof ElementCaseEditor) {
rectangle = reportRec;
}
return new ImmutableTriple<>(widget, xCreator, rectangle);
}
/**
* 准备封面
* <p>
* 操作可能会很耗时所以加个时间限制
*/
private Image toCoverImage(final Form form,
final Triple<Widget, XCreator, Rectangle> triple,
final Map<String, Object> parameterMap,
Rectangle reportRec) {
final Triple<Widget, XCreator, Rectangle> imageArgs = prepareImageArgs(triple, reportRec);
FutureTask<Image> task = new FutureTask<>(new Callable<Image>() {
@Override
public Image call() throws Exception {
Preconditions.checkNotNull(imageArgs);
Widget widget = imageArgs.getLeft();
XCreator xCreator = imageArgs.getMiddle();
Rectangle rectangle = imageArgs.getRight();
if (widget instanceof ElementCaseEditor) {
return moduleToImage(form, (ElementCaseEditor) widget, parameterMap, rectangle);
} else {
return componentToImage(xCreator, rectangle);
}
}
});
Thread imgThread = new Thread(task, "img-thread");
try {
imgThread.start();
//等待一段时间
return task.get(WAIT_TIME, TimeUnit.MILLISECONDS);
} catch (Throwable throwable) {
FineLoggerFactory.getLogger().debug("--- img generate failed ---");
FineLoggerFactory.getLogger().debug(throwable.getMessage(), throwable);
FineLoggerFactory.getLogger().debug("--- prepare use default img ---");
try (InputStream in = this.getClass().getResourceAsStream("/com/fr/base/images/share/default_cover.png")) {
//读取默认图表
return IOUtils.readImage(in);
} catch (Throwable e) {
//随便画一个
Rectangle realRec = triple.getRight();
BufferedImage allInOne = CoreGraphHelper.createBufferedImage(realRec.width, realRec.height);
Graphics2D g2d = allInOne.createGraphics();
g2d.setBackground(Color.white);
return allInOne;
}
}
}
private Image componentToImage(Component comp, Rectangle rect) {
BufferedImage im = new BufferedImage((int) rect.getWidth(), (int) rect.getHeight(), BufferedImage.TYPE_INT_ARGB);
comp.paint(im.getGraphics());
return im;
}
//画报表块的缩略图
private Image moduleToImage(Form form, ElementCaseEditor editor, Map<String, Object> parameterMap, Rectangle rect) {
if (editor == null) {
return new BufferedImage((int) rect.getWidth(), (int) rect.getHeight(), BufferedImage.TYPE_INT_ARGB);
}
FormElementCaseProvider provider = editor.getElementCase();
provider.setName(editor.getWidgetName());
provider.setTabledataSource(form);
final Calculator ca = Calculator.createCalculator();
NameSpace ns = ParameterMapNameSpace.create(parameterMap);
ca.pushNameSpace(ns);
BufferedImage image = provider.toImage(ca, (int) rect.getWidth(), (int) rect.getHeight(), parameterMap, true);
return image;
}
//计算容器内使用到的参数
private void calWidgetParameter(Widget widget, final Calculator ca) {
Form.traversalWidget(widget, new WidgetGather() {
@Override
public void dealWith(Widget widget) {
DataControl dc = (DataControl) widget;
TableData tableData = null;
try {
tableData = ((TableDataDictionary)(((DictionaryContainer) dc).getDictionary())).getTableData();
} catch (Exception ignore) {
//ignore
}
widgetPara = ArrayUtils.addAll(widgetPara, getTableDataPara(tableData));
}
@Override
public boolean dealWithAllCards() {
return true;
}
}, DataControl.class);
Form.traversalWidget(widget, new WidgetGather() {
@Override
public void dealWith(Widget widget) {
ElementCaseEditor el = (ElementCaseEditor) widget;
widgetPara = ArrayUtils.addAll(widgetPara, getCellParameters(el.getElementCase(), ca));
widgetPara = ArrayUtils.addAll(widgetPara, el.getElementCase().dependence(ca));
}
public boolean dealWithAllCards() {
return true;
}
}, ElementCaseEditor.class);
Form.traversalWidget(widget, new WidgetGather() {
@Override
public void dealWith(Widget widget) {
//算的好麻烦,本来直接用dependence就好了,但是表单的selectedChart中的tabledata只有一个name,里面的_tableData是null、、所以从环境中重新取一下
Chart selectedChart = ((ChartCollection) ((ChartEditor) widget).getChartCollection()).getSelectedChart();
TableData tableData = null;
try {
tableData = ((TableDataDefinition)selectedChart.getFilterDefinition()).getTableData();
} catch (Exception ignore) {
//ignore
}
widgetPara = ArrayUtils.addAll(widgetPara, getTableDataPara(tableData));
}
public boolean dealWithAllCards() {
return true;
}
}, BaseChartEditor.class);
}
private ArrayList<String> getTableDataName(FormElementCaseProvider el, CalculatorProvider ca) {
Iterator<DefaultTemplateCellElement> it = el.cellIterator();
ArrayList<String> allECDepends = new ArrayList<String>();
while(it.hasNext()){
DefaultTemplateCellElement ce = it.next();
Object value = ce.getValue();
//先处理单元格值(图表, 公式)
if(value instanceof DSColumn){
String[] valueDep = ((DependenceProvider) value).dependence(ca);
allECDepends.addAll(Arrays.asList(valueDep));
}
}
return allECDepends;
}
private String[] getTableDataPara(TableData tableData) {
try {
return getTableParameters(((NameTableData) tableData).getName());
} catch (Exception ignore) {
return new String[]{};
}
}
private String[] getCellParameters(FormElementCaseProvider formElementCase,Calculator ca) {
Iterator<DefaultTemplateCellElement> it = formElementCase.cellIterator();
ArrayList<String> allECDepends = new ArrayList<String>();
while(it.hasNext()){
DefaultTemplateCellElement ce = it.next();
Object value = ce.getValue();
//处理单元格值(图表, 公式)
if(value instanceof DependenceProvider){
String[] valueDep = ((DependenceProvider) value).dependence(ca);
allECDepends.addAll(Arrays.asList(valueDep));
if (value instanceof DSColumn) {
String[] dsPara = getTableParameters(((DSColumn) value).getDSName());
allECDepends.addAll(Arrays.asList(dsPara));
}
}
}
//去掉重复的dependence
HashSet<String> removeRepeat = new HashSet<String>(allECDepends);
return removeRepeat.toArray(new String[removeRepeat.size()]);
}
//通过tableName获取所用参数
private String[] getTableParameters(String name) {
final Calculator ca = Calculator.createCalculator();
ParameterProvider[] parameterProviders = new ParameterProvider[]{};
TableData tableData = DesignTableDataManager.getEditingTableDataSource().getTableData(name);
//只使用自定义数据集的数据
if (tableData == null) {
return new String[]{};
}
parameterProviders = tableData.getParameters(ca);
String[] paras = new String[parameterProviders.length];
for (int i = 0; i < parameterProviders.length; i++) {
paras[i] = parameterProviders[0].getName();
}
return paras;
}
}

163
designer-form/src/main/java/com/fr/design/mainframe/share/action/InstallComponentAction.java

@ -0,0 +1,163 @@
package com.fr.design.mainframe.share.action;
import com.fr.design.actions.UpdateAction;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.ifilechooser.UINativeFileChooser;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.share.ui.base.FailureMessagePane;
import com.fr.design.mainframe.share.ui.local.LocalWidgetRepoPane;
import com.fr.design.mainframe.share.util.InstallUtils;
import com.fr.design.mainframe.share.util.ShareComponentUtils;
import com.fr.design.mainframe.share.util.ShareUIUtils;
import com.fr.design.os.impl.SupportOSImpl;
import com.fr.form.share.record.ShareWidgetInfoManager;
import com.fr.form.share.utils.ReuxUtils;
import com.fr.log.FineLoggerFactory;
import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
* @Author: Yuan.Wang
* @Date: 2020/12/8
*/
public class InstallComponentAction extends UpdateAction {
public InstallComponentAction() {
this.putValue(Action.SMALL_ICON, null);
this.setName(Toolkit.i18nText("Fine-Design_Share_Install"));
}
@Override
public void actionPerformed(ActionEvent e) {
if (SupportOSImpl.NATIVE_CHOOSER.support()) {
UINativeFileChooser nativeFileChooser = new UINativeFileChooser();
nativeFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
nativeFileChooser.setMultiSelectionEnabled(true);
nativeFileChooser.setFileFilter(new FileNameExtensionFilter("reu reus", "reu", "reus"));
nativeFileChooser.setDialogTitle(Toolkit.i18nText("Fine-Design_Basic_Select"));
int returnValue = nativeFileChooser.showOpenDialog(new UILabel());
installComponent(returnValue, nativeFileChooser.getSelectedFiles());
} else {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setMultiSelectionEnabled(true);
fileChooser.setFileFilter(new FileNameExtensionFilter("reu reus", "reu", "reus"));
int returnValue = fileChooser.showDialog(new UILabel(), Toolkit.i18nText("Fine-Design_Basic_Select"));
installComponent(returnValue, fileChooser.getSelectedFiles());
}
}
private void installComponent(int returnValue, File[] selectedFiles) {
if (returnValue != JFileChooser.APPROVE_OPTION) {
return;
}
LocalWidgetRepoPane.getInstance().switch2InstallingPane();
final File[] chosenFiles = selectedFiles;
new SwingWorker<InstallBackInfo, Void>() {
@Override
protected InstallBackInfo doInBackground() {
return batchInstallZipFiles(chosenFiles);
}
@Override
protected void done() {
try {
InstallBackInfo info = get();
LocalWidgetRepoPane.getInstance().refreshAllGroupPane();
showMessageDialog(info);
} catch (InterruptedException | ExecutionException e) {
FineLoggerFactory.getLogger().error(e, e.getMessage());
}
}
}.execute();
}
private InstallBackInfo batchInstallZipFiles(File[] chosenFiles) {
try {
long installTime = System.currentTimeMillis();
boolean installStatus = true;
//记录安装失败的组件
List<String> failureList = new ArrayList<>();
for (File file : chosenFiles) {
installStatus &= installFromDiskZipFile(file, installTime, failureList);
}
ShareWidgetInfoManager.getInstance().saveXmlInfo();
boolean needShowMessage = (chosenFiles.length > 1 && chosenFiles.length != failureList.size()) || containRues(chosenFiles);
return new InstallBackInfo(installStatus, needShowMessage, failureList);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return new InstallBackInfo(false, false, new ArrayList<>());
}
}
private void showMessageDialog(InstallBackInfo info) {
if (info.success) {
FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Form_Share_Module_OK"));
return;
}
if (info.needShowMessage) {
final FailureMessagePane failureMessagePane = new FailureMessagePane(appendString(info.failureInfo));
BasicDialog dialog = failureMessagePane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() {
});
dialog.setVisible(true);
} else {
ShareUIUtils.showErrorMessageDialog(Toolkit.i18nText("Fine-Design_Share_Share_Module_Install_Error"));
}
}
private boolean containRues(File[] chosenFiles) {
for (File file : chosenFiles) {
if (file.getName().endsWith(ReuxUtils.REUS_SUFFIX))
return true;
}
return false;
}
private String appendString(List<String> list) {
StringBuilder builder = new StringBuilder();
for (String str : list) {
builder.append(str).append("\n");
}
return builder.toString();
}
/**
* 安装选中文件
*/
private boolean installFromDiskZipFile(File chosenFile, long installTime, List<String> failList) {
if (chosenFile == null) {
return false;
}
ShareComponentUtils.checkReadMe();
boolean isReus = chosenFile.getName().endsWith(ReuxUtils.REUS_SUFFIX);
return isReus ? InstallUtils.installReusFile(chosenFile, installTime, failList) : InstallUtils.installReuFile(chosenFile, installTime, failList);
}
private static class InstallBackInfo {
final boolean success;
final boolean needShowMessage;
final List<String> failureInfo;
public InstallBackInfo(boolean success, boolean needShowMessage, List<String> failureInfo) {
this.success = success;
this.needShowMessage = needShowMessage;
this.failureInfo = failureInfo;
}
}
}

9
designer-form/src/main/java/com/fr/design/mainframe/share/action/ShareUIAspect.java

@ -0,0 +1,9 @@
package com.fr.design.mainframe.share.action;
/**
* created by Harrison on 2020/04/22
**/
public interface ShareUIAspect {
void afterOk();
}

89
designer-form/src/main/java/com/fr/design/mainframe/share/collect/CollectorManager.java

@ -0,0 +1,89 @@
package com.fr.design.mainframe.share.collect;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.stable.StringUtils;
import com.fr.third.joda.time.DateTime;
import com.fr.third.joda.time.Days;
import com.fr.third.joda.time.format.DateTimeFormat;
import com.fr.third.joda.time.format.DateTimeFormatter;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* created by Harrison on 2020/03/25
**/
public class CollectorManager {
/**
* 1
*/
private static final int DELTA = 1;
/**
* 发送间隔 5 分钟
*/
private static final long SEND_DELAY = 300 * 1000L;
/**
* 线程
*/
private ScheduledExecutorService service;
private static class ConfigManagerHolder {
private static CollectorManager instance = new CollectorManager();
}
public static CollectorManager getInstance() {
return ConfigManagerHolder.instance;
}
public void execute() {
service = Executors
.newSingleThreadScheduledExecutor(new NamedThreadFactory("plugin-CollectorManager", true));
service.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
sendCloudCenter();
}
}, SEND_DELAY, SEND_DELAY, TimeUnit.MILLISECONDS);
}
public void shutdown() {
ComponentCollector.getInstance().saveInfo();
if (service != null) {
service.shutdown();
}
}
private void sendCloudCenter() {
String lastTime = ComponentCollector.getInstance().getLastTime();
if (validate(lastTime)) {
boolean sendSuccess = ComponentSender.send();
String currentTime = DateTime.now().toString("yyyy-MM-dd");
ComponentCollector.getInstance().setLastTime(currentTime);
if (sendSuccess) {
ComponentCollector.getInstance().clear();
}
}
ComponentCollector.getInstance().saveInfo();
}
private boolean validate(String lastTime) {
if (StringUtils.isEmpty(lastTime)) {
return true;
}
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime last = formatter.parseDateTime(lastTime);
DateTime current = DateTime.now();
return Days.daysBetween(last, current).getDays() >= DELTA;
}
}

541
designer-form/src/main/java/com/fr/design/mainframe/share/collect/ComponentCollector.java

@ -0,0 +1,541 @@
package com.fr.design.mainframe.share.collect;
import com.fr.base.io.XMLReadHelper;
import com.fr.config.MarketConfig;
import com.fr.design.DesignerEnvManager;
import com.fr.form.share.DefaultSharableWidget;
import com.fr.form.share.SharableWidgetProvider;
import com.fr.form.share.constants.ComponentPath;
import com.fr.form.share.group.DefaultShareGroupManager;
import com.fr.form.share.Group;
import com.fr.form.share.group.filter.DirFilter;
import com.fr.form.share.group.filter.ReuFilter;
import com.fr.general.ComparatorUtils;
import com.fr.json.JSON;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONFactory;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.context.PluginContexts;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException;
import com.fr.third.joda.time.DateTime;
import com.fr.third.joda.time.Days;
import com.fr.third.org.apache.commons.io.FileUtils;
import com.fr.workspace.WorkContext;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
/**
* created by Harrison on 2020/03/25
**/
public class ComponentCollector implements XMLable {
private static final String SIMPLE_DATE_PATTERN = "yyyy-MM-dd";
private static final String XML = "ComponentCollector";
private static final String ACTIVATE_VALUE = "activateValue";
private static final String COMP_PKT_CLICK = "cmpPktClick";
private static final String DOWNLOAD_PKT_NUM = "downloadPktNum";
private static final String DOWNLOAD_CMP = "downloadCmp";
private static final int ACTIVATE_INITIAL_VALUE = 1;
private static final String ACTIVATE_DATE = "date";
private static final String GENERATE_CMP_RECORD_NAME = "name";
private static final String GENERATE_CMP_RECORD_TYPE = "type";
private static final String GENERATE_CMP_RECORD_UUID = "uuid";
private static final String HELP_CONFIG_INFO = "helpConfigInfo";
private static final String HELP_CONFIG_USE_INFO = "helpConfigUseInfo";
private static final String TEMPLATE_ID = "templateId";
private static final String SHOW_COUNT = "showCount";
private static final String USE_COUNT = "useCount";
private static final String GROUPING_DETAIL = "groupingDetail";
private static final String GROUP_NAME = "groupName";
private static final String CONTAIN_AMOUNT = "containAmount";
private static final String SEARCH_CONTENT = "searchContent";
private static final String FILTER_CONTENT = "filterContent";
private static final String SORT_TYPE = "sortType";
private static final String MARKET_CLICK = "marketClick";
private static final String uuid = DesignerEnvManager.getEnvManager().getUUID();
private static ComponentCollector instance;
private int localCmpNumber = 0;
private int remoteCmpNumber = 0;
private int generateCmpNumber = 0;
private int uploadCmpNumber = 0;
private int cmpBoardClick = 0;
private JSONArray activateRecord = JSONFactory.createJSON(JSON.ARRAY);
private JSONArray generateCmpRecord = JSONFactory.createJSON(JSON.ARRAY);
private JSONArray helpConfigInfo = JSONFactory.createJSON(JSON.ARRAY);
private JSONArray searchContent = JSONFactory.createJSON(JSON.ARRAY);
private JSONArray filterContent = JSONFactory.createJSON(JSON.ARRAY);
private JSONArray sortType = JSONFactory.createJSON(JSON.ARRAY);
private String startTime = StringUtils.EMPTY;
private String lastTime = StringUtils.EMPTY;
private JSONArray helpConfigUseInfo = JSONFactory.createJSON(JSON.ARRAY);
private static class ComponentCollectorHolder {
private static ComponentCollector collector = new ComponentCollector();
}
public static ComponentCollector getInstance() {
return ComponentCollectorHolder.collector;
}
private ComponentCollector() {
loadFromFile();
if (StringUtils.isEmpty(startTime)) {
startTime = DateTime.now().toString(SIMPLE_DATE_PATTERN);
}
}
public void collectGenerateCmpNumber() {
generateCmpNumber++;
saveInfo();
}
public void collectUploadCmpNumber() {
uploadCmpNumber++;
saveInfo();
}
public void collectTepMenuEnterClick() {
saveInfo();
}
public void collectCmpBoardClick() {
collectActivateRecord();
cmpBoardClick++;
saveInfo();
}
public void collectCmpNumber() {
int count = 0;
//默认分组组件数量
String[] reus = WorkContext.getWorkResource().list(ComponentPath.SHARE_PATH.path(), new ReuFilter());
count += reus.length;
//其他分组组件数量
String[] groups = WorkContext.getWorkResource().list(ComponentPath.SHARE_PATH.path(), new DirFilter());
for (String groupName : groups) {
String relativePath = StableUtils.pathJoin(ComponentPath.SHARE_PATH.path(), groupName);
String[] groupReus = WorkContext.getWorkResource().list(relativePath, new ReuFilter());
count += groupReus.length;
}
if (WorkContext.getCurrent().isLocal()) {
localCmpNumber = count;
} else {
remoteCmpNumber = count;
}
saveInfo();
}
public void collectCmpPktClick() {
collectAttrActiveCount(COMP_PKT_CLICK);
saveInfo();
}
public void collectDownloadPktNum() {
collectAttrActiveCount(DOWNLOAD_PKT_NUM);
saveInfo();
}
public void collectMarkerClick() {
collectAttrActiveCount(MARKET_CLICK);
}
public void clearActiveRecord() {
String currentDate = DateTime.now().toString(SIMPLE_DATE_PATTERN);
Iterator<Object> iterator = activateRecord.iterator();
while (iterator.hasNext()) {
JSONObject jo = (JSONObject) iterator.next();
if (!ComparatorUtils.equals(currentDate, jo.getString(ACTIVATE_DATE))) {
iterator.remove();
}
}
}
public void collectGenerateCmpRecord(SharableWidgetProvider bindInfo) {
JSONObject jo = JSONFactory.createJSON(JSON.OBJECT);
jo.put(GENERATE_CMP_RECORD_NAME, bindInfo.getName())
.put(GENERATE_CMP_RECORD_TYPE, ((DefaultSharableWidget) bindInfo).getChildClassify())
.put(GENERATE_CMP_RECORD_UUID, bindInfo.getId());
generateCmpRecord.add(jo);
}
public void clearGenerateCmpRecord() {
generateCmpRecord = JSONFactory.createJSON(JSON.ARRAY);
}
public void collectCmpDownLoad(String uuid) {
String currentDate = DateTime.now().toString(SIMPLE_DATE_PATTERN);
for (int i = 0; i < activateRecord.size(); i++) {
JSONObject jo = activateRecord.getJSONObject(i);
if (ComparatorUtils.equals(currentDate, jo.getString(ACTIVATE_DATE))) {
JSONArray downloadComp = jo.containsKey(DOWNLOAD_CMP) ? jo.getJSONArray(DOWNLOAD_CMP) : JSONFactory.createJSON(JSON.ARRAY);
downloadComp.add(uuid);
jo.put(DOWNLOAD_CMP, downloadComp);
saveInfo();
return;
}
}
JSONObject jo = JSONFactory.createJSON(JSON.OBJECT);
jo.put(ACTIVATE_DATE, currentDate).put(DOWNLOAD_CMP, JSONFactory.createJSON(JSON.ARRAY).add(uuid));
activateRecord.add(jo);
saveInfo();
}
public JSONArray getActivateRecord() {
return activateRecord;
}
public JSONArray getGenerateCmpRecord() {
return generateCmpRecord;
}
private void collectActivateRecord() {
collectAttrActiveCount(ACTIVATE_VALUE);
}
private void collectAttrActiveCount(String attrName) {
String currentDate = DateTime.now().toString(SIMPLE_DATE_PATTERN);
for (int i = 0; i < activateRecord.size(); i++) {
JSONObject jo = activateRecord.getJSONObject(i);
if (ComparatorUtils.equals(currentDate, jo.getString(ACTIVATE_DATE))) {
int attrNum = jo.getInt(attrName);
attrNum++;
jo.put(attrName, attrNum);
return;
}
}
JSONObject jo = JSONFactory.createJSON(JSON.OBJECT);
jo.put(ACTIVATE_DATE, currentDate).put(attrName, ACTIVATE_INITIAL_VALUE);
activateRecord.add(jo);
}
private JSONArray getGroupingDetail() {
JSONArray ja = JSONFactory.createJSON(JSON.ARRAY);
Group[] groups = DefaultShareGroupManager.getInstance().getAllGroup();
for(Group group : groups) {
JSONObject jo = JSONFactory.createJSON(JSON.OBJECT);
jo.put(GROUP_NAME, group.getGroupName());
jo.put(CONTAIN_AMOUNT, group.getAllBindInfoList().length);
ja.add(jo);
}
return ja;
}
public void collectHelpConfigInfo(String templateId, int showCount, int useCount) {
JSONObject jo = JSONFactory.createJSON(JSON.OBJECT);
jo.put(TEMPLATE_ID, templateId);
jo.put(SHOW_COUNT, showCount);
jo.put(USE_COUNT, useCount);
helpConfigInfo.add(jo);
saveInfo();
}
public void clearHelpConfigInfo() {
helpConfigInfo = JSONFactory.createJSON(JSON.ARRAY);
}
public void collectSearchContent(String search) {
searchContent.add(search);
}
public void clearSearchContent() {
searchContent = JSONFactory.createJSON(JSON.ARRAY);
}
public void collectFilterContent(String filter) {
filterContent.add(filter);
saveInfo();
}
public void clearFilterContent() {
filterContent = JSONFactory.createJSON(JSON.ARRAY);
}
public void collectSortType(String type) {
sortType.add(type);
saveInfo();
}
public void clearSortType() {
sortType = JSONFactory.createJSON(JSON.ARRAY);
}
private int cmpBoardClickDaily() {
DateTime dateTime = DateTime.parse(startTime);
DateTime currTime = DateTime.now();
int days = (Days.daysBetween(dateTime, currTime).getDays() + 1);
return cmpBoardClick / days;
}
public String getLastTime() {
return lastTime;
}
public void setLastTime(String lastTime) {
this.lastTime = lastTime;
}
/**
* 保存埋点信息到文件中
*/
public void saveInfo() {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLTools.writeOutputStreamXML(this, out);
out.flush();
out.close();
String fileContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
FileUtils.writeStringToFile(getInfoFile(), fileContent, StandardCharsets.UTF_8);
} catch (Exception ex) {
FineLoggerFactory.getLogger().error(ex.getMessage());
}
}
/**
* 从文件中读取埋点信息
*/
private void loadFromFile() {
if (!getInfoFile().exists()) {
return;
}
XMLableReader reader = null;
try (InputStream in = new FileInputStream(getInfoFile())) {
// XMLableReader 还是应该考虑实现 Closable 接口的,这样就能使用 try-with 语句了
reader = XMLReadHelper.createXMLableReader(in, XMLPrintWriter.XML_ENCODER);
if (reader == null) {
return;
}
reader.readXMLObject(this);
} catch (FileNotFoundException e) {
// do nothing
} catch (XMLStreamException | IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (XMLStreamException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
private File getInfoFile() {
File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), "component.info"));
try {
if (!file.exists()) {
file.createNewFile();
}
} catch (Exception ex) {
FineLoggerFactory.getLogger().error(ex.getMessage(), ex);
}
return file;
}
@Override
public void readXML(XMLableReader reader) {
String tagName = reader.getTagName();
if (tagName.equals(XML)) {
this.cmpBoardClick = reader.getAttrAsInt("cmpBoardClick", 0);
this.startTime = reader.getAttrAsString("startTime", StringUtils.EMPTY);
this.lastTime = reader.getAttrAsString("lastTime", StringUtils.EMPTY);
this.localCmpNumber = reader.getAttrAsInt("localCmpNumber", 0);
this.remoteCmpNumber = reader.getAttrAsInt("remoteCmpNumber", 0);
this.generateCmpNumber = reader.getAttrAsInt("generateCmpNumber", 0);
this.uploadCmpNumber = reader.getAttrAsInt("uploadCmpNumber", 0);
String activateRecordStr = reader.getAttrAsString("activateRecord", StringUtils.EMPTY);
activateRecord = parseJSONArray(activateRecordStr);
String generateCmpRecordStr = reader.getAttrAsString("generateCmpRecord", StringUtils.EMPTY);
generateCmpRecord = parseJSONArray(generateCmpRecordStr);
this.helpConfigInfo = parseJSONArray(reader.getAttrAsString(HELP_CONFIG_INFO, StringUtils.EMPTY));
this.helpConfigUseInfo = parseJSONArray(reader.getAttrAsString(HELP_CONFIG_USE_INFO, StringUtils.EMPTY));
this.searchContent = parseJSONArray(reader.getAttrAsString(SEARCH_CONTENT,StringUtils.EMPTY));
this.filterContent = parseJSONArray(reader.getAttrAsString(FILTER_CONTENT, StringUtils.EMPTY));
this.sortType = parseJSONArray(reader.getAttrAsString(SORT_TYPE, StringUtils.EMPTY));
}
}
private JSONArray parseJSONArray(String value) {
JSONArray ja;
try {
ja = new JSONArray(value);
} catch (JSONException e) {
ja = JSONFactory.createJSON(JSON.ARRAY);
}
return ja;
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML)
.attr("cmpBoardClick", cmpBoardClick)
.attr("startTime", startTime)
.attr("lastTime", lastTime)
.attr("localCmpNumber", localCmpNumber)
.attr("remoteCmpNumber", remoteCmpNumber)
.attr("uploadCmpNumber", uploadCmpNumber)
.attr("generateCmpNumber", generateCmpNumber)
.attr("activateRecord", activateRecord.toString())
.attr("generateCmpRecord", generateCmpRecord.toString())
.attr(HELP_CONFIG_INFO, helpConfigInfo.toString())
.attr(HELP_CONFIG_USE_INFO, helpConfigUseInfo.toString())
.attr(SEARCH_CONTENT, searchContent.toString())
.attr(FILTER_CONTENT, filterContent.toString())
.attr(SORT_TYPE, sortType.toString())
.end();
}
/**
* 累计信息
*/
public String generateTotalInfo() {
collectCmpNumber();
JSONObject jo = JSONObject.create();
jo.put("userId", MarketConfig.getInstance().getBBSAttr().getBbsUid());
jo.put("uuid", uuid);
jo.put("cmpBoardClickDaily", cmpBoardClickDaily());
jo.put("pluginVersion", PluginContexts.currentContext().getVersion());
jo.put("localCmpNumber", localCmpNumber);
jo.put("remoteCmpNumber", remoteCmpNumber);
jo.put("uploadCmpNumber", uploadCmpNumber);
jo.put("generateCmpNumber", generateCmpNumber);
jo.put("activateRecord", getValidActivateRecord());
jo.put("generateCmpRecord", generateCmpRecord.toString());
jo.put(HELP_CONFIG_INFO, helpConfigInfo.toString());
jo.put(GROUPING_DETAIL, getGroupingDetail().toString());
jo.put(SEARCH_CONTENT, searchContent.toString());
jo.put(FILTER_CONTENT, filterContent.toString());
jo.put(SORT_TYPE, sortType.toString());
return jo.toString();
}
public String getValidActivateRecord() {
JSONArray result = JSONFactory.createJSON(JSON.ARRAY);
String currentDate = DateTime.now().toString(SIMPLE_DATE_PATTERN);
for (Object o : activateRecord) {
JSONObject jo = (JSONObject) o;
if (!ComparatorUtils.equals(currentDate, jo.getString(ACTIVATE_DATE))) {
result.add(jo);
}
}
return result.toString();
}
@Override
public Object clone() throws CloneNotSupportedException {
return null;
}
public void setHelpConfigUseInfo(String templateId, String widgetId) {
for (int i = 0; i < helpConfigUseInfo.size(); i++) {
JSONObject jo = helpConfigUseInfo.getJSONObject(i);
if (ComparatorUtils.equals(templateId, jo.getString(TEMPLATE_ID))) {
JSONArray useInfo = jo.getJSONArray(HELP_CONFIG_USE_INFO);
if (!useInfo.contains(widgetId)) {
useInfo.add(widgetId);
}
jo.put(HELP_CONFIG_USE_INFO, useInfo);
return;
}
}
JSONObject jo = JSONFactory.createJSON(JSON.OBJECT);
JSONArray ja = JSONFactory.createJSON(JSON.ARRAY);
ja.add(widgetId);
jo.put(TEMPLATE_ID, templateId);
jo.put(HELP_CONFIG_USE_INFO, ja);
helpConfigUseInfo.add(jo);
saveInfo();
}
public JSONArray getHelpConfigUseInfoWithTemplate(String templateId) {
for (int i = 0; i < helpConfigUseInfo.size(); i++) {
JSONObject jo = helpConfigUseInfo.getJSONObject(i);
if (ComparatorUtils.equals(templateId, jo.getString(TEMPLATE_ID))) {
return jo.getJSONArray(HELP_CONFIG_USE_INFO);
}
}
return JSONFactory.createJSON(JSON.ARRAY);
}
public void clear(){
clearActiveRecord();
clearGenerateCmpRecord();
clearFilterContent();
clearHelpConfigInfo();
clearSearchContent();
clearSortType();
saveInfo();
}
}

45
designer-form/src/main/java/com/fr/design/mainframe/share/collect/ComponentSender.java

@ -0,0 +1,45 @@
package com.fr.design.mainframe.share.collect;
import com.fr.design.mainframe.SiteCenterToken;
import com.fr.general.ComparatorUtils;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import java.util.HashMap;
import java.util.Map;
/**
* created by Harrison on 2020/03/25
**/
public class ComponentSender {
private static final String CLOUD_REUSE_URL = "https://cloud.fanruan.com/api/monitor/record_of_reusePlugin/single";
public static boolean send() {
long start = System.currentTimeMillis();
String content = ComponentCollector.getInstance().generateTotalInfo();
long end = System.currentTimeMillis();
FineLoggerFactory.getLogger().error("cal time cost {} ms", end - start);
return sendInfo(CLOUD_REUSE_URL, content);
}
private static boolean sendInfo(String url, String content) {
Map<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
para.put("content", content);
try {
String res = HttpToolbox.post(url, para);
return ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
} catch (Throwable e) {
// 客户不需要关心,错误等级为 debug 就行了
FineLoggerFactory.getLogger().debug(e.getMessage(), e);
}
return false;
}
}

18
designer-form/src/main/java/com/fr/design/mainframe/share/constants/ComponentType.java

@ -0,0 +1,18 @@
package com.fr.design.mainframe.share.constants;
import java.util.List;
/**
* created by Harrison on 2020/04/20
**/
public interface ComponentType {
List<String> children(int device);
/**
* 返回子类型所有
*
* @return
*/
List<String> types();
}

193
designer-form/src/main/java/com/fr/design/mainframe/share/constants/ComponentTypes.java

@ -0,0 +1,193 @@
package com.fr.design.mainframe.share.constants;
import com.fr.design.i18n.Toolkit;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* created by Harrison on 2020/04/20
**/
public enum ComponentTypes implements ComponentType {
CHART("Fine-Design_Share_Type_Basic_Element") {
@Override
public List<String> children(int device) {
return ChartChildTypes.support(device);
}
@Override
public List<String> types() {
List<String> list = new ArrayList<>();
for (ChartChildTypes types : ChartChildTypes.values()) {
list.add(types.getLocText());
}
return list;
}
},
REPORT("Fine-Design_Share_Type_Report") {
@Override
public List<String> children(int device) {
if (DisplayDevice.supportMobile(device)) {
return ReportChildTypes.support(DisplayDevice.MOBILE.getType());
}
return ReportChildTypes.support(DisplayDevice.PC.getType());
}
@Override
public List<String> types() {
List<String> list = new ArrayList<>();
for (ReportChildTypes types : ReportChildTypes.values()) {
list.add(types.getLocText());
}
return list;
}
};
/**
* 所有类型
*
* @return
*/
public static List<String> allTypes() {
List<String> allTypes = new ArrayList<>();
Set<String> set = new LinkedHashSet<>();
for (ComponentTypes types : values()) {
set.addAll(types.children(DisplayDevice.MOBILE.getType()));
set.addAll(types.children(DisplayDevice.PC.getType()));
}
allTypes.addAll(set);
return allTypes;
}
/**
* 根据终端返回所有类型
*
* @param device
* @return
*/
public static List<String> allTypesByDevice(int device) {
List<String> allTypes = new ArrayList<>();
for (ComponentTypes types : values()) {
allTypes.addAll(types.children(device));
}
return allTypes;
}
private enum ReportChildTypes {
INDICATOR_CARD("Fine-Design_Share_Type_Indicator_Card"),
TITLE("Fine-Design_Share_Type_Title"),
DIMENSION_CHANGE("Fine-Design_Share_Type_Dimension_Change"),
FILL("Fine-Design_Share_Type_Fill", DisplayDevice.MOBILE),
Directory_Navigation("Fine-Design_Share_Type_Mobile_Directory_Navigation", DisplayDevice.MOBILE),
SPECIAL_CARD("Fine-Design_Share_Type_Special_Card");
private String locale;
/**
* @see DisplayDevice
*/
private int support;
ReportChildTypes(String locale) {
this(locale, DisplayDevice.buildAll());
}
ReportChildTypes(String locale, DisplayDevice device) {
this(locale, device.getType());
}
ReportChildTypes(String locale, int support) {
this.locale = locale;
this.support = support;
}
public static List<String> support(int device) {
List<String> list = new ArrayList<>();
ReportChildTypes[] values = ReportChildTypes.values();
for (ReportChildTypes value : values) {
//支持当前设备
if (DisplayDevice.supportDevice(device, value.support)) {
list.add(value.getLocText());
}
}
return list;
}
public String getLocText() {
return Toolkit.i18nText(this.locale);
}
}
private enum ChartChildTypes {
COLUMN_CHART("Fine-Design_Share_Type_Chart_Column"),
PIE_CHART("Fine-Design_Share_Type_Chart_Pie"),
FOLD_LINE_CHART("Fine-Design_Share_Type_Chart_Fold_Line"),
COMBINE_CHART("Fine-Design_Share_Type_Chart_Combine"),
METER_CHART("Fine-Design_Share_Type_Chart_Meter"),
MAP_CHART("Fine-Design_Share_Type_Chart_Map"),
OTHERS("Fine-Design_Share_Type_Chart_Other"),
DETAIL_LIST("Fine-Design_Share_Type_Detail_List"),
BASIC_WIDGET("Fine-Design_Share_Type_Basic_Widget");
private String locale;
ChartChildTypes(String locale) {
this.locale = locale;
}
public static List<String> support(int device) {
List<String> list = new ArrayList<>();
ChartChildTypes[] values = ChartChildTypes.values();
for (ChartChildTypes value : values) {
list.add(value.getLocText());
}
return list;
}
public String getLocText() {
return Toolkit.i18nText(this.locale);
}
}
private String locale;
ComponentTypes(String locale) {
this.locale = locale;
}
public String getLocText() {
return Toolkit.i18nText(this.locale);
}
@Override
public String toString() {
return getLocText();
}
}

66
designer-form/src/main/java/com/fr/design/mainframe/share/constants/DisplayDevice.java

@ -0,0 +1,66 @@
package com.fr.design.mainframe.share.constants;
/**
* created by Harrison on 2020/04/21
**/
public enum DisplayDevice {
NONE(0),
MOBILE(1),
PC(2);
private int type;
DisplayDevice(int type) {
this.type = type;
}
public int getType() {
return type;
}
public static int buildAll() {
int support = 0;
DisplayDevice[] values = DisplayDevice.values();
for (DisplayDevice value : values) {
support |= value.getType();
}
return support;
}
public static int buildDevice(Iterable<DisplayDevice> devices) {
int support = 0;
if (devices == null) {
return support;
}
for (DisplayDevice device : devices) {
support |= device.type;
}
return support;
}
public static boolean supportDevice(int device, int support) {
return device == buildAll() || (support & device) == device;
}
public static boolean supportMobile(int device) {
return (device & MOBILE.getType()) == MOBILE.getType();
}
public static boolean supportPC(int device) {
return (device & PC.getType()) == PC.getType();
}
private static int calVal(DisplayDevice device) {
return 1 << device.type;
}
}

6
designer-form/src/main/java/com/fr/design/mainframe/share/constants/ShareEntryKey.java

@ -0,0 +1,6 @@
package com.fr.design.mainframe.share.constants;
public class ShareEntryKey {
static public final String SHARE_GENERATE = "ShareGeneratePane";
static public final String SHARE_CONFIG = "ShareConfigPane";
}

81
designer-form/src/main/java/com/fr/design/mainframe/share/constants/StyleTheme.java

@ -0,0 +1,81 @@
package com.fr.design.mainframe.share.constants;
import com.fr.design.i18n.Toolkit;
import com.fr.form.share.bean.StyleThemeBean;
import com.fr.form.share.bean.WidgetFilterInfo;
import com.fr.form.share.bean.WidgetFilterTypeInfo;
import com.fr.form.share.constants.ShareComponentConstants;
import com.fr.form.share.utils.ShareUtils;
import com.fr.general.ComparatorUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Created by kerry on 2020-12-09
*/
public enum StyleTheme {
SIMPLE_FRESH("Fine-Design_Share_Style_Theme_Simple", "1"),
BUSINESS_STABLE("Fine-Design_Share_Style_Theme_Business", "2"),
LIVE_GORGEOUS("Fine-Design_Share_Style_Theme_Live", "3"),
COOL_TECHNOLOGY("Fine-Design_Share_Style_Theme_Cool", "4"),
OTHER_THEME("Fine-Design_Share_Style_Theme_Other", "5");
private final String local;
private final String id;
StyleTheme(String name, String id) {
this.local = name;
this.id = id;
}
public String getLocText() {
return Toolkit.i18nText(this.local);
}
public String getId() {
return this.id;
}
private static List<StyleThemeBean> types() {
List<StyleThemeBean> list = new ArrayList<>();
for (StyleTheme type : StyleTheme.values()) {
list.add(new StyleThemeBean(type.getId(), type.getLocText()));
}
return list;
}
/**
* 获取样式风格属性list
*
* @return List
*/
public static List<StyleThemeBean> getStyleThemeTypeInfo() {
List<WidgetFilterTypeInfo> widgetFilterTypeInfos = ShareUtils.getWidgetFilterTypeInfos();
if (widgetFilterTypeInfos.isEmpty()) {
return types();
}
WidgetFilterTypeInfo styleThemeFilterInfo = new WidgetFilterTypeInfo();
for (WidgetFilterTypeInfo typeInfo : widgetFilterTypeInfos) {
if (ComparatorUtils.equals(ShareComponentConstants.STYLE_THEME_KEY, typeInfo.getKey())) {
styleThemeFilterInfo = typeInfo;
break;
}
}
List<StyleThemeBean> resultList = new ArrayList<>();
List<WidgetFilterInfo> filterInfoList = styleThemeFilterInfo.getFilterItems();
Iterator<WidgetFilterInfo> infoIterator = filterInfoList.iterator();
while (infoIterator.hasNext()) {
WidgetFilterInfo filterInfo = infoIterator.next();
if (!ComparatorUtils.equals(ShareComponentConstants.ALL_STYLE_THEME, filterInfo.getId())) {
resultList.add(new StyleThemeBean(filterInfo.getId(), filterInfo.getName()));
}
}
return resultList;
}
}

14
designer-form/src/main/java/com/fr/design/mainframe/share/exception/LackOfValueException.java

@ -0,0 +1,14 @@
package com.fr.design.mainframe.share.exception;
import com.fr.design.i18n.Toolkit;
/**
* created by Harrison on 2020/04/21
**/
public class LackOfValueException extends RuntimeException{
public LackOfValueException() {
super(Toolkit.i18nText("Fine-Design_Share_Lack_Val"));
}
}

9
designer-form/src/main/java/com/fr/design/mainframe/share/generate/AbstractComponentTask.java

@ -0,0 +1,9 @@
package com.fr.design.mainframe.share.generate;
/**
* created by Harrison on 2020/04/23
**/
public abstract class AbstractComponentTask<T> implements ComponentTask<T> {
}

14
designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentBanner.java

@ -0,0 +1,14 @@
package com.fr.design.mainframe.share.generate;
/**
* created by Harrison on 2020/04/13
**/
public interface ComponentBanner {
/**
* 加载文字
*
* @return 加载
*/
String getLoadingText();
}

20
designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentCreatorProcessor.java

@ -0,0 +1,20 @@
package com.fr.design.mainframe.share.generate;
import com.fr.design.mainframe.JTemplate;
import com.fr.form.share.DefaultSharableWidget;
import com.fr.form.share.bean.ComponentReuBean;
import com.fr.form.ui.Widget;
import com.fr.stable.fun.mark.Immutable;
import java.util.Map;
/**
* Created by kerry on 2020-07-30
*/
public interface ComponentCreatorProcessor extends ComponentBanner, Immutable {
String MARK_STRING = "ComponentCreatorProcessor";
int CURRENT_LEVEL = 1;
ComponentReuBean create(JTemplate<?, ?> jt, Map<String, Object> paraMap, Widget widget, DefaultSharableWidget info) throws Exception;
}

22
designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentGenerator.java

@ -0,0 +1,22 @@
package com.fr.design.mainframe.share.generate;
/**
* created by Harrison on 2020/04/16
**/
public interface ComponentGenerator {
/**
* 生成组件
*
* @return 组件
*/
boolean generate() throws Throwable;
/**
* 耗时/速率
*
* @return 时间
*/
int speed();
}

68
designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentGeneratorCenter.java

@ -0,0 +1,68 @@
package com.fr.design.mainframe.share.generate;
import com.fr.design.mainframe.share.Bean.ComponentGenerateInfo;
import com.fr.design.mainframe.share.generate.impl.ComponentPureGenerator;
import com.fr.design.mainframe.share.generate.impl.ComponentUploadGenerator;
import com.fr.design.mainframe.share.ui.base.ShareProgressBar;
import com.fr.log.FineLoggerFactory;
import java.util.concurrent.Future;
/**
* created by Harrison on 2020/04/13
**/
public class ComponentGeneratorCenter {
private ComponentGenerateInfo info;
public ComponentGeneratorCenter(ComponentGenerateInfo info) {
this.info = info;
}
public boolean generate() throws Exception {
try {
return generate0();
} catch (RuntimeException e) {
throw e;
} catch (Throwable throwable) {
FineLoggerFactory.getLogger().error(throwable.getMessage(), throwable);
return false;
} finally {
ShareProgressBar.getInstance().completeNow();
}
}
private boolean generate0() throws Throwable{
ComponentGenerator generator = innerGenerator();
//ui
ShareProgressBar progressBar = ShareProgressBar.getInstance();
progressBar.prepare(generator.speed());
progressBar.monitor();
return generator.generate();
}
private void waitComplete(Future<Boolean> complete) {
try {
complete.get();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
private ComponentGenerator innerGenerator() {
if (info.isAutoUpload()) {
return ComponentUploadGenerator.create(info);
} else {
return ComponentPureGenerator.create(info);
}
}
}

13
designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentTask.java

@ -0,0 +1,13 @@
package com.fr.design.mainframe.share.generate;
/**
* created by Harrison on 2020/04/23
**/
public interface ComponentTask<T> {
T execute() throws Exception;
double indicator();
String getLoadingText();
}

26
designer-form/src/main/java/com/fr/design/mainframe/share/generate/ComponentTaskAdaptor.java

@ -0,0 +1,26 @@
package com.fr.design.mainframe.share.generate;
/**
* created by Harrison on 2020/04/23
**/
public abstract class ComponentTaskAdaptor<T> extends AbstractComponentTask<T> {
private double indicator;
private String loadingText;
public ComponentTaskAdaptor(double indicator, String loadingText) {
this.indicator = indicator;
this.loadingText = loadingText;
}
@Override
public double indicator() {
return this.indicator;
}
@Override
public String getLoadingText() {
return this.loadingText;
}
}

24
designer-form/src/main/java/com/fr/design/mainframe/share/generate/impl/AbstractComponentCreatorProcessor.java

@ -0,0 +1,24 @@
package com.fr.design.mainframe.share.generate.impl;
import com.fr.design.mainframe.share.generate.ComponentCreatorProcessor;
import com.fr.stable.fun.mark.API;
/**
* Created by kerry on 2020-07-30
*/
@API(level = ComponentCreatorProcessor.CURRENT_LEVEL)
public abstract class AbstractComponentCreatorProcessor implements ComponentCreatorProcessor {
@Override
public int currentAPILevel() {
return CURRENT_LEVEL;
}
@Override
public int layerIndex() {
return DEFAULT_LAYER_INDEX;
}
}

161
designer-form/src/main/java/com/fr/design/mainframe/share/generate/impl/AbstractComponentGenerator.java

@ -0,0 +1,161 @@
package com.fr.design.mainframe.share.generate.impl;
import com.fr.design.mainframe.share.Bean.ComponentGenerateInfo;
import com.fr.design.mainframe.share.generate.ComponentBanner;
import com.fr.design.mainframe.share.generate.ComponentCreatorProcessor;
import com.fr.design.mainframe.share.generate.ComponentGenerator;
import com.fr.design.mainframe.share.generate.ComponentTask;
import com.fr.design.mainframe.share.generate.task.ComponentCreator;
import com.fr.design.mainframe.share.ui.base.ShareProgressBar;
import com.fr.design.mainframe.share.util.ShareUIUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.report.ExtraReportClassManager;
import com.fr.third.org.apache.commons.lang3.time.StopWatch;
import javax.swing.SwingWorker;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.Callable;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
/**
* created by Harrison on 2020/04/16
**/
public abstract class AbstractComponentGenerator implements ComponentGenerator {
/**
* 默认 40 ms
*/
private static final int DEFAULT_SPEED = 40;
/**
* 进度 100
*/
private static final int PROGRESS = 100;
/**
* 每一个任务平均耗时 2000 ms
*/
private static final int PER_TIME = 2000;
private final int speed;
private ComponentGenerateInfo info;
public AbstractComponentGenerator(ComponentGenerateInfo info, ComponentBanner... banners) {
this.info = info;
this.speed = calSpeed(banners);
}
public ComponentGenerateInfo getInfo() {
return info;
}
private int calSpeed(ComponentBanner... banners) {
if (banners == null || banners.length == 0) {
return DEFAULT_SPEED;
}
return PER_TIME / (PROGRESS / banners.length);
}
/**
* 进度条 100
* 目前有 n 个任务
* 每个任务至少 2000 ms
* <p>
* 则平均速度为 2000 / 100/n
*/
@Override
public int speed() {
return this.speed;
}
@Override
public boolean generate() throws Throwable {
try {
return generate0();
} catch (ExecutionException e) {
//抛出根本原因
throw e.getCause();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
}
}
protected abstract boolean generate0() throws InterruptedException, ExecutionException;
protected <T> T execute(final ComponentTask<T> componentTask) throws InterruptedException, ExecutionException {
final CyclicBarrier barrier = new CyclicBarrier(2);
Thread UIThread = new Thread(new FutureTask<Void>(new Callable<Void>() {
@Override
public Void call() throws Exception {
SwingWorker<Void, Boolean> worker = new SwingWorker<Void, Boolean>() {
@Override
protected Void doInBackground() throws Exception {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//ui更新
doUIUpdate();
stopWatch.stop();
long time = stopWatch.getTime(TimeUnit.MILLISECONDS);
if (time < 2000L) {
//不到 2 s
ShareUIUtils.wait((int) (2000L - time));
}
//完成更新
finishUpdate();
return null;
}
private int finishUpdate() throws InterruptedException, BrokenBarrierException {
return barrier.await();
}
private void doUIUpdate() throws Exception {
ShareProgressBar.getInstance().updateProgress(componentTask.indicator(), componentTask.getLoadingText());
}
};
worker.execute();
return null;
}
}));
UIThread.setName("Component-UIThread");
FutureTask<T> task = new FutureTask<>(new Callable<T>() {
@Override
public T call() throws Exception {
T result = componentTask.execute();
barrier.await();
return result;
}
});
Thread workThread = new Thread(task);
workThread.setName("Component-WorkThread");
parallel(UIThread, workThread);
return task.get();
}
private void parallel(Thread UIThread, Thread workThread) {
UIThread.start();
workThread.start();
}
public static ComponentCreatorProcessor getComponentCreator(){
ComponentCreatorProcessor processor = ExtraReportClassManager.getInstance().getSingle(ComponentCreatorProcessor.MARK_STRING, ComponentCreator.class);
return processor;
}
}

57
designer-form/src/main/java/com/fr/design/mainframe/share/generate/impl/ComponentPureGenerator.java

@ -0,0 +1,57 @@
package com.fr.design.mainframe.share.generate.impl;
import com.fr.design.mainframe.share.Bean.ComponentGenerateInfo;
import com.fr.design.mainframe.share.generate.ComponentCreatorProcessor;
import com.fr.design.mainframe.share.generate.ComponentTaskAdaptor;
import com.fr.design.mainframe.share.generate.task.ComponentGenerateComplete;
import com.fr.form.share.bean.ComponentReuBean;
import java.util.concurrent.ExecutionException;
/**
* created by Harrison on 2020/04/16
**/
public class ComponentPureGenerator extends AbstractComponentGenerator {
private ComponentCreatorProcessor creator;
private ComponentGenerateComplete complete;
private ComponentPureGenerator(ComponentGenerateInfo info, ComponentCreatorProcessor creator, ComponentGenerateComplete complete) {
super(info, creator, complete);
this.creator = creator;
this.complete = complete;
}
public static ComponentPureGenerator create(ComponentGenerateInfo info) {
ComponentCreatorProcessor creator = getComponentCreator();
ComponentGenerateComplete complete = new ComponentGenerateComplete();
return new ComponentPureGenerator(info, creator, complete);
}
@Override
protected boolean generate0() throws InterruptedException, ExecutionException {
final ComponentGenerateInfo info = getInfo();
ComponentTaskAdaptor<ComponentReuBean> createTest = new ComponentTaskAdaptor<ComponentReuBean>(1.0, creator.getLoadingText()) {
@Override
public ComponentReuBean execute() throws Exception {
return creator.create(info.getJt(), info.getParaMap(), info.getWidget(), info.getInfo());
}
};
ComponentReuBean bean = execute(createTest);
ComponentTaskAdaptor<Void> completeTask = new ComponentTaskAdaptor<Void>(1.0, complete.getLoadingText()) {
@Override
public Void execute() throws Exception {
complete.execute();
return null;
}
};
Void result = execute(completeTask);
return true;
}
}

99
designer-form/src/main/java/com/fr/design/mainframe/share/generate/impl/ComponentUploadGenerator.java

@ -0,0 +1,99 @@
package com.fr.design.mainframe.share.generate.impl;
import com.fr.design.mainframe.share.Bean.ComponentGenerateInfo;
import com.fr.design.mainframe.share.generate.ComponentCreatorProcessor;
import com.fr.design.mainframe.share.generate.ComponentTaskAdaptor;
import com.fr.design.mainframe.share.generate.task.ComponentDesensitize;
import com.fr.design.mainframe.share.generate.task.ComponentEncrypt;
import com.fr.design.mainframe.share.generate.task.ComponentUploadComplete;
import com.fr.design.mainframe.share.generate.task.ComponentUploader;
import com.fr.form.share.bean.ComponentReuBean;
import java.util.concurrent.ExecutionException;
/**
* created by Harrison on 2020/04/16
**/
public class ComponentUploadGenerator extends AbstractComponentGenerator {
private ComponentCreatorProcessor creator;
private ComponentEncrypt encrypt;
private ComponentDesensitize desensitize;
private ComponentUploader uploader;
private ComponentUploadComplete complete;
private ComponentUploadGenerator(ComponentGenerateInfo info, ComponentCreatorProcessor creator, ComponentEncrypt encrypt, ComponentDesensitize desensitize, ComponentUploader uploader, ComponentUploadComplete complete) {
super(info, creator, desensitize, encrypt, uploader);
this.creator = creator;
this.encrypt = encrypt;
this.desensitize = desensitize;
this.uploader = uploader;
this.complete = complete;
}
public static ComponentUploadGenerator create(ComponentGenerateInfo info) {
ComponentCreatorProcessor creator = getComponentCreator();
ComponentUploader uploader = new ComponentUploader();
ComponentEncrypt encrypt = new ComponentEncrypt();
ComponentDesensitize desensitize = new ComponentDesensitize();
ComponentUploadComplete complete = new ComponentUploadComplete();
return new ComponentUploadGenerator(info, creator, encrypt, desensitize, uploader, complete);
}
@Override
protected boolean generate0() throws InterruptedException, ExecutionException {
final ComponentGenerateInfo info = getInfo();
//创建
ComponentTaskAdaptor<ComponentReuBean> createTask = new ComponentTaskAdaptor<ComponentReuBean>(0.20, creator.getLoadingText()) {
@Override
public ComponentReuBean execute() throws Exception {
return creator.create(info.getJt(), info.getParaMap(), info.getWidget(), info.getInfo());
}
};
final ComponentReuBean plainBean = execute(createTask);
//脱敏
ComponentTaskAdaptor<Object> desensitizeTask = new ComponentTaskAdaptor<Object>(0.60, desensitize.getLoadingText()) {
@Override
public Object execute() throws Exception {
desensitize.execute();
return null;
}
};
execute(desensitizeTask);
//加密
ComponentTaskAdaptor<ComponentReuBean> encryptTask = new ComponentTaskAdaptor<ComponentReuBean>(0.85, encrypt.getLoadingText()) {
@Override
public ComponentReuBean execute() throws Exception {
return encrypt.execute(plainBean);
}
};
final ComponentReuBean encryptBean = execute(encryptTask);
//上传
ComponentTaskAdaptor<Boolean> uploadTask = new ComponentTaskAdaptor<Boolean>(1.0, uploader.getLoadingText()) {
@Override
public Boolean execute() throws Exception {
return uploader.upload(encryptBean.getPath());
}
};
Boolean success = execute(uploadTask);
//完成
final ComponentTaskAdaptor<Boolean> completeTask = new ComponentTaskAdaptor<Boolean>(1.0, complete.getLoadingText()) {
@Override
public Boolean execute() throws Exception {
return complete.execute();
}
};
return success && execute(completeTask);
}
}

114
designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java

@ -0,0 +1,114 @@
package com.fr.design.mainframe.share.generate.task;
import com.fr.base.iofile.attr.ExtendSharableAttrMark;
import com.fr.base.iofile.attr.SharableAttrMark;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.share.generate.impl.AbstractComponentCreatorProcessor;
import com.fr.form.main.Form;
import com.fr.form.main.WidgetGatherAdapter;
import com.fr.form.share.DefaultSharableWidget;
import com.fr.form.share.ShareEmbeddedConverter;
import com.fr.form.share.bean.ComponentReuBean;
import com.fr.form.share.editor.DefaultSharableEditor;
import com.fr.form.share.editor.PlainSharableEditor;
import com.fr.form.share.utils.ShareUtils;
import com.fr.form.ui.AbstractBorderStyleWidget;
import com.fr.form.ui.Widget;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.fun.IOFileAttrMark;
import com.fr.workspace.WorkContext;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
/**
* created by Harrison on 2020/04/13
**/
public class ComponentCreator extends AbstractComponentCreatorProcessor {
/**
* 生成组件
* 返回组件的路径
*
* @return 路径
*/
@Override
public ComponentReuBean create(JTemplate<?, ?> jt, Map<String, Object> paraMap, Widget widget, DefaultSharableWidget info) throws Exception {
// 遍历判断是否存在共享组件
checkOriginStatus(widget, info);
// 导出内置数据集
Form form = embeddedForm(jt, paraMap);
// 创建组件
DefaultSharableEditor editor = createSharableEditor(form, paraMap, widget, info);
// 生成组件
String generatePath = generate(editor, info);
return new ComponentReuBean(generatePath, editor, info);
}
protected void checkOriginStatus(Widget widget, final DefaultSharableWidget info) {
Form.traversalWidget(widget, new WidgetGatherAdapter() {
@Override
public void dealWith(Widget widget) {
AbstractBorderStyleWidget borderStyleWidget = (AbstractBorderStyleWidget) widget;
IOFileAttrMark attrMark = borderStyleWidget.getWidgetAttrMark(SharableAttrMark.XML_TAG);
if (attrMark != null) {
info.setTransform();
}
}
}, AbstractBorderStyleWidget.class);
}
@Override
public String getLoadingText() {
return Toolkit.i18nText("Fine-Design_Share_Generate_Ing");
}
/**
* 内置数据集处理
*
* @return 返回
*/
protected Form embeddedForm(JTemplate<?, ?> jt, Map<String, Object> paraMap) throws Exception {
jt.stopEditing();
Form tpl = null;
try {
tpl = (Form) jt.getTarget().clone();
} catch (CloneNotSupportedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
// //内置数据集
ShareEmbeddedConverter embeddedConverter = WorkContext.getCurrent().get(ShareEmbeddedConverter.class);
embeddedConverter.convertToEmbeddedTableData(tpl, paraMap);
return tpl;
}
@NotNull
protected DefaultSharableEditor createSharableEditor(Form form, Map<String, Object> paraMap, Widget widget, DefaultSharableWidget info) {
String uuid = info.getId();
((AbstractBorderStyleWidget) widget).addWidgetAttrMark(new SharableAttrMark());
((AbstractBorderStyleWidget) widget).addWidgetAttrMark(new ExtendSharableAttrMark(uuid));
return new PlainSharableEditor(uuid, widget, form, (HashMap<String, Object>) paraMap);
}
protected String generate(Widget editor, DefaultSharableWidget info) throws Exception {
return ShareUtils.generateModule(editor, info);
}
}

44
designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentDesensitize.java

@ -0,0 +1,44 @@
package com.fr.design.mainframe.share.generate.task;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.share.generate.ComponentBanner;
import com.fr.form.share.exception.NetWorkFailedException;
import com.fr.general.http.HttpRequest;
import com.fr.general.http.HttpToolbox;
import com.fr.log.FineLoggerFactory;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
/**
* created by Harrison on 2020/04/22
**/
public class ComponentDesensitize implements ComponentBanner {
private static final String TEST_URL = "http://www.baidu.com";
public void execute() {
if (!testNet()) {
throw new NetWorkFailedException();
}
}
private boolean testNet() {
try {
HttpRequest httpRequest = HttpRequest.custom().url(TEST_URL).build();
CloseableHttpResponse response = HttpToolbox.execute(httpRequest);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
return true;
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return false;
}
@Override
public String getLoadingText() {
return Toolkit.i18nText("Fine-Design_Share_Desensitize");
}
}

28
designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentEncrypt.java

@ -0,0 +1,28 @@
package com.fr.design.mainframe.share.generate.task;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.share.generate.ComponentBanner;
import com.fr.form.share.bean.ComponentReuBean;
import com.fr.workspace.WorkContext;
/**
* created by Harrison on 2020/04/22
**/
public class ComponentEncrypt implements ComponentBanner {
public ComponentReuBean execute(ComponentReuBean bean) throws Exception {
try {
return bean;
} catch (Exception e) {
String path = bean.getPath();
WorkContext.getWorkResource().delete(path);
throw e;
}
}
@Override
public String getLoadingText() {
return Toolkit.i18nText("Fine-Design_Share_Encrypt");
}
}

19
designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentGenerateComplete.java

@ -0,0 +1,19 @@
package com.fr.design.mainframe.share.generate.task;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.share.generate.ComponentBanner;
/**
* created by Harrison on 2020/04/13
**/
public class ComponentGenerateComplete implements ComponentBanner {
public void execute() throws InterruptedException {
}
@Override
public String getLoadingText() {
return Toolkit.i18nText("Fine-Design_Share_Generate_Success");
}
}

19
designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentUploadComplete.java

@ -0,0 +1,19 @@
package com.fr.design.mainframe.share.generate.task;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.share.generate.ComponentBanner;
/**
* created by Harrison on 2020/06/16
**/
public class ComponentUploadComplete implements ComponentBanner {
public boolean execute() throws InterruptedException {
return true;
}
@Override
public String getLoadingText() {
return Toolkit.i18nText("Fine-Design_Share_Upload_Success");
}
}

153
designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentUploader.java

@ -0,0 +1,153 @@
package com.fr.design.mainframe.share.generate.task;
import com.fr.config.MarketConfig;
import com.fr.design.i18n.Toolkit;
import com.fr.form.share.config.ComponentReuseConfigManager;
import com.fr.design.mainframe.share.generate.ComponentBanner;
import com.fr.io.utils.ResourceIOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.client.config.CookieSpecs;
import com.fr.third.org.apache.http.client.config.RequestConfig;
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpPost;
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier;
import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import com.fr.third.org.apache.http.entity.mime.HttpMultipartMode;
import com.fr.third.org.apache.http.entity.mime.MultipartEntityBuilder;
import com.fr.third.org.apache.http.entity.mime.content.ByteArrayBody;
import com.fr.third.org.apache.http.impl.client.BasicCookieStore;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.message.BasicNameValuePair;
import com.fr.third.org.apache.http.ssl.SSLContextBuilder;
import com.fr.third.org.apache.http.ssl.TrustStrategy;
import com.fr.workspace.WorkContext;
import org.jetbrains.annotations.NotNull;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
/**
* 组件上传
* <p>
* created by Harrison on 2020/04/13
**/
public class ComponentUploader implements ComponentBanner {
//private static final String MARKET_LOGIN = CloudCenter.getInstance().acquireUrlByKind("market.login", "https://market.fanruan.com/ShopServer?pg=login&_=1590635085629");
//private static final String MARKET_REU_FILE_UPLOAD = CloudCenter.getInstance().acquireUrlByKind("market.reuses.upload", "https://market.fanruan.com/reuses/upload");
/**
* 先用临时的 暂时不上线
*/
private static final String URL_MARKET_LOGIN = ComponentReuseConfigManager.getInstance().getMarketLoginUrl();
private static final String URL_MARKET_REU_FILE_UPLOAD = ComponentReuseConfigManager.getInstance().getComponentUploadUrl();
private static final String KEY_USERNAME = "username";
private static final String KEY_PASSWORD = "password";
private static final String KEY_FILE = "file";
public boolean upload(String path) {
boolean success = false;
try {
success = upload0(path);
} catch (Exception e) {
WorkContext.getWorkResource().delete(path);
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return success;
}
@Override
public String getLoadingText() {
return Toolkit.i18nText("Fine-Design_Share_Encrypt");
}
private boolean upload0(String path) throws Exception {
CloseableHttpClient client = createClient();
if (login(client)) {
HttpPost uploadRequest = new HttpPost(URL_MARKET_REU_FILE_UPLOAD);
byte[] bytes = WorkContext.getWorkResource().readFully(path);
String fileName = ResourceIOUtils.getName(path);
HttpEntity reqEntity = MultipartEntityBuilder.create()
.setCharset(StandardCharsets.UTF_8)
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
// 相当于<input type="file" name="file"/>
.addPart(KEY_FILE, new ByteArrayBody(bytes, fileName))
.build();
uploadRequest.setEntity(reqEntity);
// 发起请求 并返回请求的响应
CloseableHttpResponse uploadResponse = client.execute(uploadRequest);
FineLoggerFactory.getLogger().info(uploadResponse.toString());
return uploadResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
}
return false;
}
private boolean login(CloseableHttpClient client) throws IOException {
String bbsUsername = MarketConfig.getInstance().getBbsUsername();
String bbsPassword = MarketConfig.getInstance().getBbsPassword();
List<BasicNameValuePair> pairs = new ArrayList<>();
pairs.add(new BasicNameValuePair(KEY_USERNAME, bbsUsername));
pairs.add(new BasicNameValuePair(KEY_PASSWORD, bbsPassword));
HttpPost login = new HttpPost(URL_MARKET_LOGIN);
login.setEntity(new UrlEncodedFormEntity(pairs, StandardCharsets.UTF_8));
login.addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36");
login.addHeader("Connection", "keep-alive");
CloseableHttpResponse loginResponse = client.execute(login);
FineLoggerFactory.getLogger().info(loginResponse.toString());
return loginResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
}
private static CloseableHttpClient createClient() throws Exception {
SSLConnectionSocketFactory connectionFactory = createSSL();
BasicCookieStore cookieStore = new BasicCookieStore();
return HttpClients.custom()
.setDefaultRequestConfig(RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD)
.setSocketTimeout(2000)
.setConnectTimeout(5000)
.setConnectionRequestTimeout(5000)
.setAuthenticationEnabled(false)
.build())
.setDefaultCookieStore(cookieStore)
.setSSLSocketFactory(connectionFactory)
.build();
}
@NotNull
private static SSLConnectionSocketFactory createSSL() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
SSLContext sslContext = SSLContextBuilder
.create()
.loadTrustMaterial(new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
return true;
}
})
.build();
HostnameVerifier allowAllHosts = new NoopHostnameVerifier();
return new SSLConnectionSocketFactory(sslContext, allowAllHosts);
}
}

59
designer-form/src/main/java/com/fr/design/mainframe/share/group/ui/BaseGroupDialog.java

@ -0,0 +1,59 @@
package com.fr.design.mainframe.share.group.ui;
import com.fr.base.BaseUtils;
import com.fr.design.dialog.UIDialog;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.i18n.Toolkit;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.JDialog;
import java.awt.Dimension;
import java.awt.Frame;
/**
* @Author: Yuan.Wang
* @Date: 2020/12/9
*/
abstract public class BaseGroupDialog extends UIDialog {
public BaseGroupDialog(Frame parent) {
super(parent);
}
protected UIButton createConfirmButton() {
UIButton confirmButton;
confirmButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Confirm"));
confirmButton.setPreferredSize(new Dimension(60, 25));
confirmButton.setEnabled(false);
confirmButton.addActionListener(e -> confirmClose());
return confirmButton;
}
protected UIButton createCancelButton() {
UIButton cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel"));
cancelButton.setPreferredSize(new Dimension(60, 25));
cancelButton.addActionListener(e -> dispose());
return cancelButton;
}
/**
* 点击确定后的处理方法
*/
abstract protected void confirmClose();
protected void initStyle() {
this.setSize(340, 180);
this.setResizable(false);
this.setAlwaysOnTop(true);
this.setIconImage(BaseUtils.readImage("/com/fr/base/images/oem/logo.png"));
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
GUICoreUtils.centerWindow(this);
this.setVisible(true);
}
@Override
public void checkValid() throws Exception {
// do nothing
}
}

173
designer-form/src/main/java/com/fr/design/mainframe/share/group/ui/GroupFileDialog.java

@ -0,0 +1,173 @@
package com.fr.design.mainframe.share.group.ui;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
/**
* @Author: Yuan.Wang
* @Date: 2020/10/29
*/
abstract public class GroupFileDialog extends BaseGroupDialog {
private UITextField nameField;
private UILabel warnLabel;
private final UIButton confirmButton;
public GroupFileDialog(Frame frame, String title) {
this(frame, title, StringUtils.EMPTY);
}
public GroupFileDialog(Frame frame, String title, String defaultName) {
super(frame);
this.setLayout(new BorderLayout());
this.setModal(true);
setTitle(title);
// 标签
UILabel newNameLabel = creteNewNameLabel();
// 输入框
createNameField(defaultName);
// 重名提示
createWarnLabel();
// 确认按钮
confirmButton = createConfirmButton();
// 取消按钮
UIButton cancelButton = createCancelButton();
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 5));
topPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 0, 15));
topPanel.add(newNameLabel);
topPanel.add(nameField);
JPanel midPanel = new JPanel(new BorderLayout());
midPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15));
midPanel.add(warnLabel, BorderLayout.WEST);
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
bottomPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15));
bottomPanel.add(confirmButton);
bottomPanel.add(cancelButton);
this.add(
TableLayoutHelper.createTableLayoutPane(
new Component[][]{
new Component[]{topPanel},
new Component[]{midPanel},
new Component[]{bottomPanel}
},
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL},
new double[]{TableLayout.FILL}
), BorderLayout.CENTER);
initStyle();
}
protected String getFileName() {
return nameField.getText().trim();
}
protected void validInput() {
//抽成模板方法
String userInput = getFileName();
if (StringUtils.isEmpty(userInput)) {
confirmButton.setEnabled(false);
return;
}
String name = nameField.getText().trim();
if (isDuplicate(name)) {
nameField.selectAll();
// 如果文件名已存在,则灰掉确认按钮
warnLabel.setText(Toolkit.i18nText("Fine-Design_Share_Group_Repeat_Name_Info"));
warnLabel.setVisible(true);
confirmButton.setEnabled(false);
} else {
warnLabel.setVisible(false);
confirmButton.setEnabled(true);
}
}
/**
* 点击确定后的处理方法
*/
abstract protected void confirmClose();
/**
* 是否重名
*/
abstract protected boolean isDuplicate(String fileName);
private UILabel creteNewNameLabel() {
// 输入框前提示
UILabel newNameLabel = new UILabel(Toolkit.i18nText("Fine-Design_Share_Group_Enter_New_Folder_Name"));
newNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
newNameLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
newNameLabel.setPreferredSize(new Dimension(84, 16));
return newNameLabel;
}
private void createNameField(String name) {
// 文件名输入框
nameField = new UITextField(name);
nameField.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
validInput();
}
public void insertUpdate(DocumentEvent e) {
validInput();
}
public void removeUpdate(DocumentEvent e) {
validInput();
}
});
nameField.selectAll();
nameField.setPreferredSize(new Dimension(200, 20));
// 增加enter以及esc快捷键的支持
nameField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
dispose();
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (confirmButton.isEnabled()) {
confirmClose();
}
}
}
});
}
private void createWarnLabel() {
warnLabel = new UILabel();
warnLabel.setPreferredSize(new Dimension(300, 30));
warnLabel.setHorizontalAlignment(SwingConstants.LEFT);
warnLabel.setForeground(Color.RED);
warnLabel.setVisible(false);
}
}

79
designer-form/src/main/java/com/fr/design/mainframe/share/group/ui/GroupMoveDialog.java

@ -0,0 +1,79 @@
package com.fr.design.mainframe.share.group.ui;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.form.share.group.DefaultShareGroupManager;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
/**
* @Author: Yuan.Wang
* @Date: 2020/12/9
*/
abstract public class GroupMoveDialog extends BaseGroupDialog {
private UIComboBox selectGroupBox;
public GroupMoveDialog(Frame frame) {
super(frame);
this.setLayout(new BorderLayout());
this.setModal(true);
setTitle(Toolkit.i18nText("Fine-Design_Share_Group_Move"));
// 标签
UILabel newNameLabel = creteNewNameLabel();
// 输入框
createSwitchGroupBox();
// 确认按钮
UIButton confirmButton = createConfirmButton();
confirmButton.setEnabled(true);
// 取消按钮
UIButton cancelButton = createCancelButton();
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 5));
topPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 0, 15));
topPanel.add(newNameLabel);
topPanel.add(selectGroupBox);
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
bottomPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15));
bottomPanel.setPreferredSize(new Dimension(340, 45));
bottomPanel.add(confirmButton);
bottomPanel.add(cancelButton);
this.add(topPanel, BorderLayout.CENTER);
this.add(bottomPanel, BorderLayout.SOUTH);
initStyle();
}
private void createSwitchGroupBox() {
// 文件名输入框
selectGroupBox = new UIComboBox(DefaultShareGroupManager.getInstance().getAllGroup());
selectGroupBox.setPreferredSize(new Dimension(225, 20));
}
private UILabel creteNewNameLabel() {
// 输入框前提示
UILabel newNameLabel = new UILabel(Toolkit.i18nText("Fine-Design_Share_Group_Select"));
newNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
newNameLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
newNameLabel.setPreferredSize(new Dimension(60, 16));
return newNameLabel;
}
protected UIComboBox getSelectGroupBox() {
return selectGroupBox;
}
}

25
designer-form/src/main/java/com/fr/design/mainframe/share/select/ComponentTransformer.java

@ -0,0 +1,25 @@
package com.fr.design.mainframe.share.select;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.mainframe.FormSelection;
import com.fr.form.ui.Widget;
import com.fr.third.org.apache.commons.lang3.tuple.Triple;
import java.awt.Rectangle;
/**
* 组件选择器
* <p>
* created by Harrison on 2020/06/11
**/
public interface ComponentTransformer {
/**
* 获取选择到组件
*
* @return 组件相关信息
*/
Triple<Widget, XCreator, Rectangle> transform(FormSelection selection);
}

53
designer-form/src/main/java/com/fr/design/mainframe/share/select/ComponentTransformerFactory.java

@ -0,0 +1,53 @@
package com.fr.design.mainframe.share.select;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.mainframe.FormSelection;
import com.fr.form.ui.Widget;
import com.fr.stable.AssistUtils;
import com.fr.third.org.apache.commons.lang3.tuple.Triple;
import org.jetbrains.annotations.Nullable;
import java.awt.Rectangle;
/**
* created by Harrison on 2020/06/11
**/
public class ComponentTransformerFactory {
private TransformerKey lastKey;
private Triple<Widget, XCreator, Rectangle> lastCache;
private ComponentTransformer transformer = new ComponentTransformerImpl();
private static class InstanceHolder {
private static ComponentTransformerFactory INSTANCE = new ComponentTransformerFactory();
}
public static ComponentTransformerFactory getInstance() {
return InstanceHolder.INSTANCE;
}
@Nullable
public Triple<Widget, XCreator, Rectangle> transform(FormSelection selection) {
if (selection == null) {
return null;
}
TransformerKey transformerKey = new TransformerKey(selection);
if (AssistUtils.equals(lastKey, transformerKey)) {
return lastCache;
}
Triple<Widget, XCreator, Rectangle> triple = transformer.transform(selection);
//缓存一下。
cache(transformerKey, triple);
return triple;
}
private void cache(TransformerKey transformerKey, Triple<Widget, XCreator, Rectangle> triple) {
this.lastKey = transformerKey;
this.lastCache = triple;
}
}

156
designer-form/src/main/java/com/fr/design/mainframe/share/select/ComponentTransformerImpl.java

@ -0,0 +1,156 @@
package com.fr.design.mainframe.share.select;
import com.fr.base.FRContext;
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.mainframe.FormSelection;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.form.main.Form;
import com.fr.form.share.bean.ShareLayoutWidget;
import com.fr.form.ui.AbstractBorderStyleWidget;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteBodyLayout;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WBorderLayout;
import com.fr.form.ui.container.WFitLayout;
import com.fr.form.ui.container.WLayout;
import com.fr.form.ui.container.WParameterLayout;
import com.fr.form.ui.widget.CRBoundsWidget;
import com.fr.general.Inter;
import com.fr.log.FineLoggerFactory;
import com.fr.third.org.apache.commons.lang3.tuple.ImmutableTriple;
import com.fr.third.org.apache.commons.lang3.tuple.Triple;
import com.fr.web.FormCompVisibleUtils;
import org.jetbrains.annotations.Nullable;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
/**
* created by Harrison on 2020/06/11
**/
public class ComponentTransformerImpl implements ComponentTransformer {
@Override
@Nullable
public Triple<Widget, XCreator, Rectangle> transform(FormSelection selection) {
XCreator selectedCreator;
Widget selectedWidget;
if (selection == null) {
return null;
}
Rectangle selectionBounds = selection.getSelctionBounds();
Rectangle selectedTriple = new Rectangle(0, 0, selectionBounds.width, selectionBounds.height);
XCreator[] xCreators = selection.getSelectedCreators();
if (xCreators.length == 1) {
selectedCreator = xCreators[0];
selectedWidget = selectedCreator.toData();
} else {
WAbsoluteLayout wAbsoluteLayout = new WAbsoluteLayout("absolute");
wAbsoluteLayout.setCompState(WAbsoluteLayout.STATE_FIT);
Map<Integer, Widget> widgetMap = new TreeMap<>(
new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o2.compareTo(o1);
}
}
);
//控件上下层关系需要继承下来
for (XCreator xCreator : xCreators) {
XLayoutContainer container = (XLayoutContainer) xCreator.getParent();
int i = container.getComponentZOrder(xCreator);
widgetMap.put(i, xCreator.toData());
}
JTemplate<?, ?> jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
Form form = (Form) jt.getTarget();
for (Widget innerWidget : widgetMap.values()) {
WLayout parentWLayout = getParentLayout(form, innerWidget);
if (parentWLayout == null){
continue;
}
try {
CRBoundsWidget boundsWidget = (CRBoundsWidget) parentWLayout.getBoundsWidget(innerWidget).clone();
adaptBounds(boundsWidget, selectionBounds);
wAbsoluteLayout.addWidget(boundsWidget);
} catch (CloneNotSupportedException e1) {
FRContext.getLogger().error(e1.getMessage(), e1);
}
}
wAbsoluteLayout.setDesigningResolution(Toolkit.getDefaultToolkit().getScreenSize());
selectedCreator = new XWAbsoluteLayout(wAbsoluteLayout, new Dimension(selectedTriple.width, selectedTriple.height));
selectedWidget = selectedCreator.toData();
//将选中的类型初始化一下。
CompositeComponentAdapter adapter = new CompositeComponentAdapter(WidgetPropertyPane.getInstance().getEditingFormDesigner(), selectedCreator);
adapter.initialize();
//并且初始化一次。缓存一下值。
selectedCreator.repaint();
}
try {
if (!supportShared(selectedWidget)) {
return null;
}
if (!(selectedWidget instanceof AbstractBorderStyleWidget)) {
selectedWidget = new ShareLayoutWidget(selectedWidget);
}
selectedWidget = (Widget) selectedWidget.clone();
} catch (CloneNotSupportedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
FineJOptionPane.showMessageDialog(null, Inter.getLocText("Fine-Design_Share_Module_Failed"));
}
return new ImmutableTriple<>(selectedWidget, selectedCreator, selectedTriple);
}
//先从body中找,如果找不到再从参数面板中找
@Nullable
private WLayout getParentLayout(Form form, Widget innerWidget) {
WLayout bodyLayout = (WLayout) ((WBorderLayout) form.getContainer()).getLayoutWidget(WBorderLayout.CENTER);
WLayout paraLayout = (WLayout) ((WBorderLayout) form.getContainer()).getLayoutWidget(WBorderLayout.NORTH);
WLayout parentLayout = FormCompVisibleUtils.findFitLayout(bodyLayout, innerWidget);
if (parentLayout == null && paraLayout != null) {
parentLayout = FormCompVisibleUtils.findFitLayout(paraLayout, innerWidget);
}
return parentLayout;
}
//组件集合产生绝对布局的时候,子组件的bounds需要去掉主框架的xy值,保证边界和绝对布局对齐
private static void adaptBounds(CRBoundsWidget cRBoundsWidget, Rectangle delRec) {
Rectangle rec = cRBoundsWidget.getBounds();
int originX = rec.x;
int originY = rec.y;
int delX = delRec.x;
int delY = delRec.y;
cRBoundsWidget.setBounds(new Rectangle(originX - delX, originY - delY, rec.width, rec.height));
}
private static boolean supportShared(Widget widget) {
return notBody(widget) && notForm(widget);
}
private static boolean notBody(Widget widget) {
return !(widget instanceof WAbsoluteBodyLayout || widget instanceof WFitLayout || widget instanceof WParameterLayout);
}
private static boolean notForm(Widget widget) {
if (!(widget instanceof WBorderLayout)) {
return true;
}
Widget centerWidget = ((WBorderLayout) widget).getLayoutWidget(WBorderLayout.CENTER);
return notBody(centerWidget);
}
}

112
designer-form/src/main/java/com/fr/design/mainframe/share/select/TransformerKey.java

@ -0,0 +1,112 @@
package com.fr.design.mainframe.share.select;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.mainframe.FormSelection;
import com.fr.form.ui.Widget;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.AssistUtils;
import org.jetbrains.annotations.Nullable;
import java.awt.Rectangle;
import java.util.Arrays;
import java.util.Objects;
import java.util.UUID;
/**
* created by Harrison on 2020/06/11
**/
public class TransformerKey {
private Rectangle selectionBounds;
private Widget[] widgets;
public TransformerKey(FormSelection selection) {
this.selectionBounds = selection.getSelctionBounds();
this.widgets = deepData(selection.getSelectedCreators());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TransformerKey that = (TransformerKey) o;
return Objects.equals(selectionBounds, that.selectionBounds) &&
Arrays.equals(widgets, that.widgets);
}
@Override
public int hashCode() {
int result = Objects.hash(selectionBounds);
result = 31 * result
+ Arrays.hashCode(widgets);
return result;
}
private Widget[] deepData(XCreator[] xCreators) {
if (xCreators == null) {
return new UniqueWidgetWrapper[0];
}
Widget[] widgets = new Widget[xCreators.length];
int i = 0;
for (XCreator xCreator : xCreators) {
widgets[i++] = new UniqueWidgetWrapper(cloneWidget(xCreator));
}
return widgets;
}
@Nullable
private Widget cloneWidget(XCreator xCreator) {
try {
return xCreator.toData() != null ? (Widget) xCreator.toData().clone() : null;
} catch (CloneNotSupportedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return null;
}
}
private static class UniqueWidgetWrapper extends Widget {
private String uuid;
private Widget widget;
public UniqueWidgetWrapper(Widget widget) {
this.widget = widget;
this.uuid = UUID.randomUUID().toString();
}
@Override
public String getXType() {
return "UniqueWidgetWrapper";
}
@Override
public boolean isEditor() {
return false;
}
@Override
public String[] supportedEvents() {
return new String[0];
}
/**
* hash码
*
* @return 返回int
*/
@Override
public int hashCode() {
return 31 * super.hashCode() + AssistUtils.hashCode(this.uuid, this.widget);
}
@Override
public boolean equals(Object obj) {
return obj instanceof UniqueWidgetWrapper
&& super.equals(obj)
&& ComparatorUtils.equals(((UniqueWidgetWrapper) obj).uuid, this.uuid)
&& ComparatorUtils.equals(((UniqueWidgetWrapper) obj).widget, this.widget);
}
}
}

153
designer-form/src/main/java/com/fr/design/mainframe/share/sort/OnlineWidgetSortType.java

@ -0,0 +1,153 @@
package com.fr.design.mainframe.share.sort;
import com.fr.design.i18n.Toolkit;
import com.fr.form.share.bean.OnlineShareWidget;
import com.fr.form.share.bean.SortParameter;
import com.fr.form.share.utils.ShareUtils;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralContext;
import java.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.Map;
/**
* Created by kerry on 2020-10-22
*/
public enum OnlineWidgetSortType implements SortType<OnlineShareWidget> {
COMPOSITE {
@Override
public void sort(OnlineShareWidget[] widgetProviders) {
Map<String, SortParameter> parameterMap = ShareUtils.getCompositeSortPara();
Arrays.sort(widgetProviders, new Comparator<OnlineShareWidget>() {
@Override
public int compare(OnlineShareWidget o1, OnlineShareWidget o2) {
double t1 = getSortValue(o1, parameterMap);
double t2 = getSortValue(o2, parameterMap);
return ComparatorUtils.compareCommonType(t2, t1);
}
});
}
private double getSortValue(OnlineShareWidget o, Map<String, SortParameter> parameterMap) {
double a1 = getParaValue("a1", parameterMap),
a2 = getParaValue("a2", parameterMap),
a3 = getParaValue("a3", parameterMap),
b1 = getParaValue("b1", parameterMap),
b2 = getParaValue("b2", parameterMap),
k = getParaValue("k", parameterMap),
q1 = getParaValue("q1", parameterMap),
q2 = getParaValue("q2", parameterMap);
String[] hot2 = new String[]{"report-1", "report-2"};
String[] hot1 = new String[]{"chart-1", "chart-2", "chart-3", "chart-4", "chart-5", "chart-6"};
int commentNumber = o.getCommentNumber(), weight = o.getWeight(), downloadTimes = o.getDownloadTimes();
double hotValue = a3;
String cid = o.getCid();
for (String str2 : hot2) {
if (ComparatorUtils.equals(str2, cid)) {
hotValue = a2;
break;
}
}
for (String str1 : hot1) {
if (ComparatorUtils.equals(str1, cid)) {
hotValue = a1;
break;
}
}
double t = (new Date().getTime() - o.getUploadTime().getTime()) / (3600 * 1000 * 24D);
return q1 * hotValue * Math.pow(2.718, (0 - k) * t) + q2 * (b1 * commentNumber + b2 * downloadTimes) * Math.pow(2.718, (0 - k) * t) + weight;
}
private double getParaValue(String parameter, Map<String, SortParameter> parameterMap) {
SortParameter sortParameter = parameterMap.get(parameter);
if (sortParameter == null) {
return 0.0D;
}
return sortParameter.getValue();
}
@Override
public String getDisplayName() {
return Toolkit.i18nText("Fine-Design_Share_Composite");
}
},
SALES {
@Override
public void sort(OnlineShareWidget[] widgetProviders) {
Arrays.sort(widgetProviders, new Comparator<OnlineShareWidget>() {
@Override
public int compare(OnlineShareWidget o1, OnlineShareWidget o2) {
int t1 = o1.getDownloadTimes();
int t2 = o2.getDownloadTimes();
int result = ComparatorUtils.compareCommonType(t2, t1);
if (result == 0) {
result = Collator.getInstance(GeneralContext.getLocale()).compare(o1.getName(), o2.getName());
}
return result;
}
});
}
@Override
public String getDisplayName() {
return Toolkit.i18nText("Fine-Design_Share_Sale");
}
},
NEW_PRODUCT {
@Override
public void sort(OnlineShareWidget[] widgetProviders) {
Arrays.sort(widgetProviders, new Comparator<OnlineShareWidget>() {
@Override
public int compare(OnlineShareWidget o1, OnlineShareWidget o2) {
long t1 = o1.getUploadTime().getTime();
long t2 = o2.getUploadTime().getTime();
int result = ComparatorUtils.compareCommonType(t2, t1);
if (result == 0) {
result = Collator.getInstance(GeneralContext.getLocale()).compare(o1.getName(), o2.getName());
}
return result;
}
});
}
@Override
public String getDisplayName() {
return Toolkit.i18nText("Fine-Design_Share_New_Product");
}
}
//现在不用,以后可能会用,先注释掉
/*,
PRICE {
@Override
public void sort(OnlineShareWidget[] widgetProviders) {
Arrays.sort(widgetProviders, new Comparator<OnlineShareWidget>() {
@Override
public int compare(OnlineShareWidget o1, OnlineShareWidget o2) {
double t1 = o1.getPrice();
double t2 = o2.getPrice();
int result = ComparatorUtils.compareCommonType(t2, t1);
if (result == 0) {
result = Collator.getInstance(GeneralContext.getLocale()).compare(o1.getName(), o2.getName());
}
return result;
}
});
}
@Override
public String getDisplayName() {
return Toolkit.i18nText("Fine-Design_Share_Price");
}
};*/
}

12
designer-form/src/main/java/com/fr/design/mainframe/share/sort/SortType.java

@ -0,0 +1,12 @@
package com.fr.design.mainframe.share.sort;
/**
* @Author: Yuan.Wang
* @Date: 2020/11/19
*/
public interface SortType<T> {
void sort(T[] widgetProviders);
String getDisplayName();
}

55
designer-form/src/main/java/com/fr/design/mainframe/share/sort/WidgetSortType.java

@ -0,0 +1,55 @@
package com.fr.design.mainframe.share.sort;
import com.fr.design.i18n.Toolkit;
import com.fr.form.share.SharableWidgetProvider;
import com.fr.form.share.record.ShareWidgetInfoManager;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralContext;
import java.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
/**
* Created by kerry on 2020-07-01
*/
public enum WidgetSortType implements SortType<SharableWidgetProvider> {
INSTALL_TIME {
@Override
public void sort(SharableWidgetProvider[] widgetProviders) {
Arrays.sort(widgetProviders, new Comparator<SharableWidgetProvider>() {
@Override
public int compare(SharableWidgetProvider o1, SharableWidgetProvider o2) {
long t1 = ShareWidgetInfoManager.getInstance().getCompInstallTime(o1.getName() + "." + o1.getId());
long t2 = ShareWidgetInfoManager.getInstance().getCompInstallTime(o2.getName() + "." + o2.getId());
int result = ComparatorUtils.compareCommonType(t2, t1);
if (result == 0) {
result = Collator.getInstance(GeneralContext.getLocale()).compare(o1.getName(), o2.getName());
}
return result;
}
});
}
@Override
public String getDisplayName() {
return Toolkit.i18nText("Fine-Design_Share_Install_Time");
}
},
COMPONENT_NAME {
@Override
public void sort(SharableWidgetProvider[] widgetProviders) {
Arrays.sort(widgetProviders, new Comparator<SharableWidgetProvider>() {
@Override
public int compare(SharableWidgetProvider o1, SharableWidgetProvider o2) {
return Collator.getInstance(GeneralContext.getLocale()).compare(o1.getName(), o2.getName());
}
});
}
@Override
public String getDisplayName() {
return Toolkit.i18nText("Fine-Design_Share_Sort_Name");
}
}
}

91
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ChartIcon.java

@ -0,0 +1,91 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.base.chart.BaseChartCollection;
import com.fr.base.chart.BaseChartPainter;
import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.base.chart.result.WebChartIDInfo;
import com.fr.script.Calculator;
import javax.swing.Icon;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
public class ChartIcon implements Icon {
private BaseChartCollection chartCollection;
private CallbackEvent callbackEvent;
private int width;
private int height;
/**
* 构造Chart的缩略图Icon
*/
public ChartIcon(BaseChartCollection chartCollection, int width, int height) {
try {
this.chartCollection = (BaseChartCollection) chartCollection.clone();
} catch (CloneNotSupportedException e) {
this.chartCollection = chartCollection;
}
this.width = width;
this.height = height;
}
public void registerCallBackEvent(CallbackEvent callbackEvent) {
this.callbackEvent = callbackEvent;
}
/**
* 画出缩略图Icon
*
* @param g 图形的上下文
* @param c 所在的Component
* @param x 缩略图的起始坐标x
* @param y 缩略图的起始坐标y
*/
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
BaseChartPainter chartPainter = getChartPainter();
Graphics2D g2d = (Graphics2D) g;
Paint oldPaint = g2d.getPaint();
g.translate(x, y);
g2d.setPaint(Color.white);
g2d.fillRect(0, 0, getIconWidth(), getIconHeight());
chartPainter.paint(g2d, getIconWidth(), getIconHeight(), 0, null, callbackEvent);
g.translate(-x, -y);
g2d.setPaint(oldPaint);
}
protected BaseChartPainter getChartPainter() {
BaseChartPainter painter = chartCollection.createResultChartPainterWithOutDealFormula(Calculator.createCalculator(),
WebChartIDInfo.createEmptyDesignerInfo(), getIconWidth(), getIconHeight());
return painter;
}
/**
* 返回缩略图的宽度
*
* @return int 缩略图宽度
*/
@Override
public int getIconWidth() {
return width;
}
/**
* 返回缩略图的高度
*
* @return int 缩略图高度
*/
@Override
public int getIconHeight() {
return height;
}
}

92
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/DictionaryComboCheckBox.java

@ -0,0 +1,92 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.gui.icombocheckbox.UIComboCheckBox;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.stable.StringUtils;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
/**
* created by Harrison on 2020/04/21
**/
public class DictionaryComboCheckBox extends UIComboCheckBox {
private static final String DEFAULT_VALUE_SEPARATOR = ",";
private static final String EDITOR_FIELD = "editor";
private Object[] values;
private Object[] displays;
private String locale;
private UITextField newEditor = null;
public DictionaryComboCheckBox(Object[] values, String[] displays, String locale) {
super(displays);
init(values, displays);
this.locale = locale;
installUI();
}
private void init(Object[] keys, String[] displays) {
this.displays = displays;
this.values = keys;
}
/**
* 这里是有问题的 这里本身直接获取比较好
*/
@Deprecated
private void installUI() {
Component[] components = getComponents();
UITextField editor = (UITextField) components[0];
editor.setPlaceholder(Toolkit.i18nText(locale));
}
@Override
public String getText() {
Object[] selectedValues = getSelectedValues();
StringBuilder builder = new StringBuilder();
if (selectedValues != null) {
for (Object value : selectedValues) {
builder.append(value);
builder.append(DEFAULT_VALUE_SEPARATOR);
}
}
//去掉末尾多余的逗号
return builder.length() > 0 ? builder.substring(0, builder.length() - 1) : StringUtils.EMPTY;
}
@Override
public Object[] getSelectedValues() {
Object[] selectedValues = super.getSelectedValues();
List<Object> realValues = new ArrayList<>();
for (Object selectedValue : selectedValues) {
Object realValue = matchValue(selectedValue);
if (realValue != null) {
realValues.add(realValue);
}
}
return realValues.toArray();
}
protected Object matchValue(Object key) {
for (int i = 0; i < displays.length; i++) {
if (displays[i].equals(key)) {
return values[i];
}
}
return null;
}
}

129
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/DownloadProgressPane.java

@ -0,0 +1,129 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.iprogressbar.ModernUIProgressBarUI;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.IOUtils;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
/**
* @Author: Yuan.Wang
* @Date: 2020/12/24
* 下载组件包的时候用到的进度条
*/
public class DownloadProgressPane extends JPanel {
private static final int MAX_NUM = 1000;
private final UILabel tipLabel;
private final UILabel closeLabel;
private final JProgressBar processBar;
public DownloadProgressPane(MouseClickListener listener) {
this.setLayout(new BorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(200, 25, 0, 25));
processBar = createProgressBar();
tipLabel = createTipLabel();
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(false);
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
panel.setPreferredSize(new Dimension(240, 60));
panel.add(processBar, BorderLayout.CENTER);
closeLabel = new UILabel(IOUtils.readIcon("/com/fr/base/images/share/close_small.png"));
closeLabel.addMouseListener(listener);
JPanel labelPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
labelPane.setOpaque(false);
labelPane.add(tipLabel, BorderLayout.CENTER);
labelPane.add(closeLabel, BorderLayout.EAST);
labelPane.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 7));
UILabel downloadTipLabel = new UILabel(Toolkit.i18nText("Fine-Design_Share_Package_Downloading_Tip"));
downloadTipLabel.setPreferredSize(new Dimension(240, 90));
downloadTipLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
downloadTipLabel.setForeground(Color.WHITE);
downloadTipLabel.setHorizontalTextPosition(UILabel.CENTER);
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
centerPane.setPreferredSize(new Dimension(240, 138));
centerPane.add(labelPane, BorderLayout.NORTH);
centerPane.add(panel, BorderLayout.CENTER);
centerPane.add(downloadTipLabel, BorderLayout.SOUTH);
centerPane.setOpaque(false);
this.add(centerPane, BorderLayout.NORTH);
this.setSize(new Dimension(240, 800));
this.setBackground(new Color(0, 0, 0, 0));
this.setOpaque(false);
}
private UILabel createTipLabel() {
UILabel label = new UILabel(ProcessState.DOWNLOADING.tip);
label.setPreferredSize(new Dimension(200, 20));
label.setHorizontalAlignment(UILabel.CENTER);
label.setOpaque(false);
label.setForeground(Color.WHITE);
return label;
}
private JProgressBar createProgressBar() {
JProgressBar jProgressBar = new JProgressBar();
jProgressBar.setUI(new ModernUIProgressBarUI());
jProgressBar.setBorderPainted(false);
jProgressBar.setOpaque(false);
jProgressBar.setBorder(null);
jProgressBar.setMaximum(MAX_NUM);
return jProgressBar;
}
public void changeState() {
tipLabel.setText(ProcessState.INSTALLING.tip);
closeLabel.setVisible(false);
this.validate();
this.repaint();
}
public void updateProgress(double process) {
if (process < 0 || process > 1) {
throw new IllegalArgumentException();
}
processBar.setValue((int) (process * MAX_NUM));
}
private enum ProcessState {
DOWNLOADING(Toolkit.i18nText("Fine-Design_Share_Package_Downloading")),
INSTALLING(Toolkit.i18nText("Fine-Design_Share_Package_Installing"));
private final String tip;
ProcessState(String tip) {
this.tip = tip;
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(600, 200, 240, 500);
DownloadProgressPane pane = new DownloadProgressPane(null);
pane.updateProgress(0.5);
frame.add(pane);
frame.setVisible(true);
}
}

58
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/FailureMessagePane.java

@ -0,0 +1,58 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.frpane.UITextPane;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.general.IOUtils;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
/**
* @Author: Yuan.Wang
* @Date: 2020/9/14
*/
public class FailureMessagePane extends BasicPane {
public FailureMessagePane(String str) {
UILabel imageLabel = new UILabel(IOUtils.readIcon("/com/fr/base/images/share/error_icon.png"));
UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Share_Share_Modules_Error"));
UITextPane textPane = new UITextPane();
UIScrollPane jScrollPane = new UIScrollPane(textPane);
JPanel panel = new JPanel();
Style style = new StyleContext().new NamedStyle();
StyleConstants.setLineSpacing(style, 0.1f);
StyleConstants.setFontSize(style, 12);
textPane.setLogicalStyle(style);
textPane.setText(str);
textPane.setCaretPosition(0);
textPane.setEditable(false);
textPane.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
jScrollPane.setBorder(BorderFactory.createEmptyBorder());
label.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8));
panel.add(imageLabel);
panel.add(label);
panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
panel.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0));
add(panel, BorderLayout.NORTH);
add(jScrollPane, BorderLayout.CENTER);
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Share_Dialog_Message");
}
}

172
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/FlexSearchFieldPane.java

@ -0,0 +1,172 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.base.BaseUtils;
import com.fr.design.event.ChangeEvent;
import com.fr.design.event.ChangeListener;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.IOUtils;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
/**
* Created by kerry on 2020-10-19
*/
public class FlexSearchFieldPane extends JPanel {
private static final String SEARCH = "SEARCH";
private static final String OTHER = "OTHER";
private static final Color SEARCH_BORDER_COLOR = Color.decode("#F5F5F7");
private static final Color SEARCH_BORDER_INPUT_COLOR = Color.decode("#419BF9");
private UITextField searchTextField;
private CardLayout cardLayout;
private JPanel centerPane;
private List<ChangeListener> changeListenerList = new ArrayList<>();
private List<FocusListener> focusListeners = new ArrayList<>();
private List<MouseListener> deleteIconMouseListener = new ArrayList<>();
private List<DocumentListener> fieldDocumentListener = new ArrayList<>();
public FlexSearchFieldPane(JPanel otherPane) {
JPanel searchFieldPane = createSearchField();
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
jPanel.add(otherPane, BorderLayout.CENTER);
jPanel.add(createSearchLabel(), BorderLayout.EAST);
cardLayout = new CardLayout();
centerPane = new JPanel(cardLayout);
centerPane.add(searchFieldPane, SEARCH);
centerPane.add(jPanel, OTHER);
cardLayout.show(centerPane, OTHER);
this.add(centerPane, BorderLayout.CENTER);
}
private JPanel createSearchLabel() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
UILabel label = new UILabel(IOUtils.readIcon("/com/fr/base/images/share/search_icon.png"));
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
jPanel.add(label, BorderLayout.EAST);
label.addMouseListener(new MouseClickListener() {
@Override
public void mouseClicked(MouseEvent e) {
cardLayout.show(centerPane, SEARCH);
searchTextField.requestFocus();
}
});
return jPanel;
}
private JPanel createSearchField() {
final JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
jPanel.setPreferredSize(new Dimension(228, 20));
jPanel.setBorder(BorderFactory.createLineBorder(SEARCH_BORDER_COLOR));
jPanel.setBackground(Color.WHITE);
UILabel label = new UILabel(IOUtils.readIcon("/com/fr/base/images/share/search_icon.png"));
label.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));
jPanel.add(label, BorderLayout.WEST);
this.searchTextField = new UITextField();
this.searchTextField.setBorderPainted(false);
this.searchTextField.setPlaceholder(Toolkit.i18nText("Fine-Design_Basic_Plugin_Search"));
this.searchTextField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
jPanel.setBorder(BorderFactory.createLineBorder(SEARCH_BORDER_INPUT_COLOR));
jPanel.repaint();
for (FocusListener focusListener : focusListeners) {
focusListener.focusGained(e);
}
}
@Override
public void focusLost(FocusEvent e) {
jPanel.setBorder(BorderFactory.createLineBorder(SEARCH_BORDER_COLOR));
jPanel.repaint();
for (FocusListener focusListener : focusListeners) {
focusListener.focusLost(e);
}
}
});
this.searchTextField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
filterByName();
for (DocumentListener listener : fieldDocumentListener) {
listener.insertUpdate(e);
}
}
@Override
public void removeUpdate(DocumentEvent e) {
filterByName();
for (DocumentListener listener : fieldDocumentListener) {
listener.removeUpdate(e);
}
}
@Override
public void changedUpdate(DocumentEvent e) {
filterByName();
for (DocumentListener listener : fieldDocumentListener) {
listener.changedUpdate(e);
}
}
});
jPanel.add(this.searchTextField, BorderLayout.CENTER);
UILabel xLabel = new UILabel(BaseUtils.readIcon("/com/fr/design/images/buttonicon/close_icon.png"));
xLabel.addMouseListener(new MouseClickListener() {
@Override
public void mouseClicked(MouseEvent e) {
searchTextField.setText(StringUtils.EMPTY);
cardLayout.show(centerPane, OTHER);
for (MouseListener listener : deleteIconMouseListener) {
listener.mouseClicked(e);
}
}
});
xLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
jPanel.add(xLabel, BorderLayout.EAST);
return jPanel;
}
private void filterByName() {
String text = searchTextField.getText();
for (ChangeListener listener : changeListenerList) {
listener.fireChanged(new ChangeEvent(text));
}
}
public void registerChangeListener(ChangeListener changeListener) {
changeListenerList.add(changeListener);
}
public void registerSearchTextFieldFocusListener(FocusListener focusListener) {
focusListeners.add(focusListener);
}
public void registerDeleteIconMouseListener(MouseListener mouseListener) {
deleteIconMouseListener.add(mouseListener);
}
public void registerFieldDocumentListener(DocumentListener documentListener) {
fieldDocumentListener.add(documentListener);
}
}

226
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ImageBackgroundPane.java

@ -0,0 +1,226 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.base.Style;
import com.fr.base.background.ImageBackground;
import com.fr.base.background.ImageFileBackground;
import com.fr.design.gui.frpane.ImgChooseWrapper;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.style.background.BackgroundDetailPane;
import com.fr.design.style.background.image.ImageFileChooser;
import com.fr.design.style.background.image.ImagePreviewPane;
import com.fr.general.Background;
import com.fr.stable.Constants;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Image background pane.
*/
public class ImageBackgroundPane extends BackgroundDetailPane {
protected ImagePreviewPane previewPane = null;
private Style imageStyle = null;
private ChangeListener changeListener = null;
private ImageFileChooser imageFileChooser = null;
protected UILabel imageSizeLabel = new UILabel();
protected UIRadioButton defaultRadioButton = null;
protected UIRadioButton tiledRadioButton = null;
private UIRadioButton extendRadioButton = null;
private UIRadioButton adjustRadioButton = null;
public ImageBackgroundPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
// preview pane
JPanel previewContainerPane = FRGUIPaneFactory.createBorderLayout_L_Pane();
this.add(previewContainerPane, BorderLayout.CENTER);
JPanel previewOwnerPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview"));
previewOwnerPane.setLayout(new BorderLayout());
previewContainerPane.add(previewOwnerPane, BorderLayout.CENTER);
previewContainerPane.add(initSelectFilePane(), BorderLayout.EAST);
previewPane = new ImagePreviewPane();
previewOwnerPane.add(new JScrollPane(previewPane));
previewPane.addChangeListener(imageSizeChangeListener);
// init image file chooser.
imageFileChooser = new ImageFileChooser();
imageFileChooser.setMultiSelectionEnabled(false);
}
public JPanel initSelectFilePane() {
JPanel selectFilePane = FRGUIPaneFactory.createBorderLayout_L_Pane();
selectFilePane.setBorder(BorderFactory.createEmptyBorder(8, 2, 4, 0));
UIButton selectPictureButton = new UIButton(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Image_Select"));
selectFilePane.add(selectPictureButton, BorderLayout.NORTH);
selectPictureButton.setMnemonic('S');
selectPictureButton.addActionListener(selectPictureActionListener);
JPanel layoutPane = FRGUIPaneFactory.createMediumHGapHighTopFlowInnerContainer_M_Pane();
selectFilePane.add(layoutPane, BorderLayout.CENTER);
//布局
defaultRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Alignment_Layout_Default"));
tiledRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Alignment_Layout_Image_Titled"));
extendRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Alignment_Layout_Image_Extend"));
adjustRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Alignment_Layout_Image_Adjust"));
defaultRadioButton.addActionListener(layoutActionListener);
tiledRadioButton.addActionListener(layoutActionListener);
extendRadioButton.addActionListener(layoutActionListener);
adjustRadioButton.addActionListener(layoutActionListener);
JPanel jp = new JPanel(new GridLayout(4, 1, 15, 15));
for (UIRadioButton button : imageLayoutButtons()) {
jp.add(button);
}
layoutPane.add(jp);
ButtonGroup layoutBG = new ButtonGroup();
layoutBG.add(defaultRadioButton);
layoutBG.add(tiledRadioButton);
layoutBG.add(extendRadioButton);
layoutBG.add(adjustRadioButton);
defaultRadioButton.setSelected(true);
return selectFilePane;
}
protected UIRadioButton[] imageLayoutButtons() {
return new UIRadioButton[]{
defaultRadioButton,
tiledRadioButton,
extendRadioButton,
adjustRadioButton
};
}
/**
* Select picture.
*/
ActionListener selectPictureActionListener = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
int returnVal = imageFileChooser.showOpenDialog(ImageBackgroundPane.this);
setImageStyle();
ImgChooseWrapper.getInstance(previewPane, imageFileChooser, imageStyle, changeListener).dealWithImageFile(returnVal);
}
};
protected void setImageStyle() {
if (tiledRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED);
} else if (adjustRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_ADJUST);
} else if (extendRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_EXTEND);
} else {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER);
}
}
ActionListener layoutActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
setImageStyle();
changeImageStyle();
}
private void changeImageStyle() {
previewPane.setImageStyle(ImageBackgroundPane.this.imageStyle);
previewPane.repaint();
}
};
@Override
public void populate(Background background) {
if (background instanceof ImageBackground) {
ImageBackground imageBackground = (ImageBackground) background;
if (imageBackground.getLayout() == Constants.IMAGE_CENTER) {
defaultRadioButton.setSelected(true);
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER);
} else if (imageBackground.getLayout() == Constants.IMAGE_EXTEND) {
extendRadioButton.setSelected(true);
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_EXTEND);
} else if (imageBackground.getLayout() == Constants.IMAGE_ADJUST) {
adjustRadioButton.setSelected(true);
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_ADJUST);
} else {
tiledRadioButton.setSelected(true);
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED);
}
previewPane.setImageStyle(ImageBackgroundPane.this.imageStyle);
if (imageBackground.getImage() != null) {
previewPane.setImageWithSuffix(imageBackground.getImageWithSuffix());
imageSizeLabel.setText(previewPane.getImage().getWidth(null)
+ " X " + previewPane.getImage().getHeight(null));
}
if (imageBackground.getImage() != null) {
previewPane.setImage(imageBackground.getImage());
}
} else {
previewPane.setImage(null);
tiledRadioButton.setSelected(true);
imageSizeLabel.setText("");
}
fireChagneListener();
}
@Override
public Background update() throws Exception {
ImageBackground imageBackground = new ImageFileBackground(previewPane.getImageWithSuffix());
setImageStyle();
imageBackground.setLayout(imageStyle.getImageLayout());
return imageBackground;
}
@Override
public void addChangeListener(ChangeListener changeListener) {
this.changeListener = changeListener;
}
private void fireChagneListener() {
if (this.changeListener != null) {
ChangeEvent evt = new ChangeEvent(this);
this.changeListener.stateChanged(evt);
}
}
ChangeListener imageSizeChangeListener = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent evt) {
Image image = ((ImagePreviewPane) evt.getSource()).getImage();
if (image == null) {
imageSizeLabel.setText("");
} else {
imageSizeLabel.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Size_Detail", image.getWidth(null) + "x" + image.getHeight(null)));
}
}
};
}

28
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ImagePanel.java

@ -0,0 +1,28 @@
package com.fr.design.mainframe.share.ui.base;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
/**
* Created by kerry on 2020-10-23
*/
public class ImagePanel extends JPanel {
private Image image;
public ImagePanel(String imagePath) {
image = Toolkit.getDefaultToolkit().createImage(ImagePanel.class
.getResource(imagePath));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (image != null) {
g.drawImage(image, 0, 0, 45, 45, this);
}
}
}

129
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ImitationProgress.java

@ -0,0 +1,129 @@
package com.fr.design.mainframe.share.ui.base;
import java.util.concurrent.atomic.AtomicReference;
/**
* @Author: Yuan.Wang
* @Date: 2020/12/23
*/
public class ImitationProgress {
private final com.fr.design.extra.Process<Double> process;
private static final double TOTAL_NUM = 1000;
private static final double FIRST_STAGE_RATE = 0.8;
private static final int SLEEP_TIME = 600;
private final AtomicReference<ImitationState> state = new AtomicReference<>(ImitationState.NEW);
private final int num;
private final double initSpeed;
private int currentProgressRate = 0;
public ImitationProgress(com.fr.design.extra.Process<Double> process, int num) {
this.process = process;
this.num = num;
initSpeed = TOTAL_NUM * FIRST_STAGE_RATE / num;
}
public void start() {
if (!state.compareAndSet(ImitationState.NEW, ImitationState.FIRST_STAGE)) {
return;
}
firstState();
if (state.compareAndSet(ImitationState.FIRST_STAGE, ImitationState.SECOND_STATE)) {
secondState();
}
if (state.get() == ImitationState.COMPLETE) {
thirdState();
}
}
/**
* 按照预先估计的速度跑完80%
*/
private void firstState() {
int i = 0;
for (; i < num; i++) {
try {
Thread.sleep(SLEEP_TIME);
currentProgressRate += initSpeed;
process.process(currentProgressRate / TOTAL_NUM);
if (state.get() != ImitationState.FIRST_STAGE) {
return;
}
} catch (InterruptedException ignore) {
}
}
}
/**
* 第一阶段结束但是还没有下载完则减慢速度跑第二阶段
*/
private void secondState() {
double speed = TOTAL_NUM * 0.1 / 30;
//70%-90%,30s
int i = 0;
for (; i < 30; i++) {
try {
Thread.sleep(1000);
currentProgressRate += speed;
process.process(currentProgressRate / (TOTAL_NUM));
if (state.get() != ImitationState.SECOND_STATE) {
return;
}
} catch (InterruptedException ignore) {
return;
}
}
//90%-95%,三分钟
speed = TOTAL_NUM * 0.05 / 60;
for (i = 0; i < 60; i++) {
try {
Thread.sleep(3000);
currentProgressRate += speed;
process.process(currentProgressRate / (TOTAL_NUM));
} catch (InterruptedException ignore) {
return;
}
}
//线程睡眠1h
try {
Thread.sleep(1000 * 3600);
} catch (InterruptedException ignore) {
}
}
/**
* 下载完则跑第三阶段即1s内跑完剩下所有进度
*/
private void thirdState() {
int localSpeed = (int) (TOTAL_NUM - currentProgressRate) / 10;
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(100);
currentProgressRate += localSpeed;
process.process((currentProgressRate) / TOTAL_NUM);
} catch (InterruptedException ignore) {
return;
}
}
}
public void completed() {
state.set(ImitationState.COMPLETE);
}
public void stop() {
state.set(ImitationState.STOP);
}
private enum ImitationState {
NEW,
FIRST_STAGE,
SECOND_STATE,
COMPLETE,
STOP
}
}

44
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/LeftWordsTextArea.java

@ -0,0 +1,44 @@
package com.fr.design.mainframe.share.ui.base;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
/**
* created by Harrison on 2020/04/21
**/
public class LeftWordsTextArea extends PlaceholderTextArea {
/**
* 默认值 200
*/
private int limitedLen = 200;
public LeftWordsTextArea() {
}
public LeftWordsTextArea(String s, String placeholder) {
super(s, placeholder);
}
public void setLimitedLen(int len) {
this.limitedLen = len;
}
@Override
protected void paintComponent(Graphics pG) {
super.paintComponent(pG);
char[] text = getText().toCharArray();
int currentLen = text.length;
int leftLen = limitedLen - currentLen;
String leftWordsLen = String.valueOf(leftLen);
final Graphics2D g = (Graphics2D) pG;
g.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getDisabledTextColor());
g.drawString(leftWordsLen, getWidth() - getInsets().right - leftWordsLen.length() * 8 - 5, getHeight() - getInsets().bottom - 5);
}
}

49
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/LoadingPane.java

@ -0,0 +1,49 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
/**
* Created by kerry on 2020-10-23
*/
public class LoadingPane extends JPanel {
public LoadingPane() {
this(Toolkit.i18nText("Fine-Design_Share_Online_Loading"));
}
public LoadingPane(String message) {
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel borderPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
borderPane.setPreferredSize(new Dimension(120, 120));
ImagePanel imagePanel = new ImagePanel("/com/fr/base/images/share/loading.gif");
imagePanel.setPreferredSize(new Dimension(45, 45));
borderPane.setBorder(BorderFactory.createEmptyBorder(150, 95, 5, 75));
borderPane.add(imagePanel);
panel.add(borderPane, BorderLayout.CENTER);
JPanel labelPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
UILabel topLabel = new UILabel(Toolkit.i18nText(message), SwingConstants.CENTER);
topLabel.setForeground(Color.GRAY);
labelPanel.add(topLabel, BorderLayout.CENTER);
labelPanel.setPreferredSize(new Dimension(240, 20));
panel.add(labelPanel, BorderLayout.SOUTH);
panel.setPreferredSize(new Dimension(240, 230));
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(100, 0, 0, 0));
this.add(panel, BorderLayout.NORTH);
}
}

34
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/MouseClickListener.java

@ -0,0 +1,34 @@
package com.fr.design.mainframe.share.ui.base;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* Created by kerry on 2020-10-22
*/
public abstract class MouseClickListener implements MouseListener {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
}

41
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/NoMatchPane.java

@ -0,0 +1,41 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.base.BaseUtils;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
/**
* @Author: Yuan.Wang
* @Date: 2021/1/14
*/
public class NoMatchPane extends JPanel {
public NoMatchPane() {
init();
}
private void init() {
JPanel panel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 5);
UILabel picLabel = new UILabel();
picLabel.setIcon(BaseUtils.readIcon("com/fr/base/images/share/no_match_icon.png"));
picLabel.setHorizontalAlignment(SwingConstants.CENTER);
picLabel.setPreferredSize(new Dimension(240, 100));
UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Share_No_Match_Result"), SwingConstants.CENTER);
label.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
label.setForeground(Color.gray);
label.setPreferredSize(new Dimension(240, 20));
label.setHorizontalAlignment(SwingConstants.CENTER);
panel.add(picLabel);
panel.add(label);
panel.setBorder(BorderFactory.createEmptyBorder(250, 0, 0, 0));
this.setLayout(new BorderLayout());
this.add(panel, BorderLayout.CENTER);
}
}

128
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PageableButton.java

@ -0,0 +1,128 @@
package com.fr.design.mainframe.share.ui.base;
import javax.swing.SwingConstants;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.basic.BasicArrowButton;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Path2D;
import java.awt.geom.RoundRectangle2D;
public class PageableButton extends BasicArrowButton {
static final private Color BORDER_COLOR = new ColorUIResource(198, 198, 198);
static final private Color ARROW_DISABLED_COLOR = new ColorUIResource(193, 193, 193);
static final private Color ARROW_COLOR = new ColorUIResource(112, 112, 112);
static final private Color BUTTON_COLOR = new ColorUIResource(255, 255, 255);
static final private Color BUTTON_DISABLED_COLOR = new ColorUIResource(242, 242, 242);
static final private Color BUTTON_PRESS_COLOR = new ColorUIResource(96, 189, 246);
static final private Color BUTTON_ROLLOVER_COLOR = new ColorUIResource(0xd2d2d2);
static final private int CONNER = 2;
public PageableButton(int direction) {
super(direction);
}
public void paint(Graphics g) {
paintButton(g);
paintArrow(g);
paintButtonBorder(g);
}
private void paintButton(Graphics g) {
int width = this.getWidth();
int height = this.getHeight();
if (!isEnabled()) {
g.setColor(PageableButton.BUTTON_DISABLED_COLOR);
} else if (getModel().isPressed()) {
g.setColor(PageableButton.BUTTON_PRESS_COLOR);
} else if (getModel().isRollover()){
g.setColor(PageableButton.BUTTON_ROLLOVER_COLOR);
} else {
g.setColor(PageableButton.BUTTON_COLOR);
}
g.fillRoundRect(1, 1, width -2, height - 2, PageableButton.CONNER, PageableButton.CONNER);
}
private void paintArrow(Graphics g) {
if (!this.isEnabled()) {
g.setColor(PageableButton.ARROW_DISABLED_COLOR);
} else {
g.setColor(PageableButton.ARROW_COLOR);
}
switch (direction) {
case SwingConstants.NORTH:
g.drawLine(8, 5, 8, 5);
g.drawLine(7, 6, 9, 6);
g.drawLine(6, 7, 10, 7);
g.drawLine(5, 8, 7, 8);
g.drawLine(9, 8, 11, 8);
g.drawLine(4, 9, 6, 9);
g.drawLine(10, 9, 12, 9);
g.drawLine(5, 10, 5, 10);
g.drawLine(11, 10, 11, 10);
break;
case SwingConstants.SOUTH:
g.drawLine(5, 6, 5, 6);
g.drawLine(11, 6, 11, 6);
g.drawLine(4, 7, 6, 7);
g.drawLine(10, 7, 12, 7);
g.drawLine(5, 8, 7, 8);
g.drawLine(9, 8, 11, 8);
g.drawLine(6, 9, 10, 9);
g.drawLine(7, 10, 9, 10);
g.drawLine(8, 11, 8, 11);
break;
case SwingConstants.EAST:
g.drawLine(6, 5, 6, 5);
g.drawLine(6, 11, 6, 11);
g.drawLine(7, 4, 7, 6);
g.drawLine(7, 10, 7, 12);
g.drawLine(8, 5, 8, 7);
g.drawLine(8, 9, 8, 11);
g.drawLine(9, 6, 9, 10);
g.drawLine(10, 7, 10, 9);
g.drawLine(11, 8, 11, 8);
break;
case SwingConstants.WEST:
g.drawLine(4, 8, 4, 8);
g.drawLine(5, 7, 5, 9);
g.drawLine(6, 6, 6, 10);
g.drawLine(7, 5, 7, 7);
g.drawLine(7, 9, 7, 11);
g.drawLine(8, 4, 8, 6);
g.drawLine(8, 10, 8, 12);
g.drawLine(9, 5, 9, 5);
g.drawLine(9, 11, 9, 11);
break;
}
}
private void paintButtonBorder(Graphics g) {
int offs = 1;
int width = this.getWidth();
int height = this.getHeight();
Graphics2D g2d = (Graphics2D) g;
Color oldColor = g2d.getColor();
g2d.setColor(PageableButton.BORDER_COLOR);
Shape outer;
Shape inner;
int size = offs + offs;
outer = new RoundRectangle2D.Float(0, 0, width, height, offs, offs);
inner = new RoundRectangle2D.Float(offs, offs, width - size, height - size, PageableButton.CONNER, PageableButton.CONNER);
Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
path.append(outer, false);
path.append(inner, false);
g2d.fill(path);
g2d.setColor(oldColor);
}
}

213
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PagingFiledPane.java

@ -0,0 +1,213 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.base.BaseUtils;
import com.fr.design.event.ChangeEvent;
import com.fr.design.event.ChangeListener;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UINumberField;
import com.fr.stable.ArrayUtils;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
/**
* Created by kerry on 2020-10-20
*/
public class PagingFiledPane extends JPanel {
private static final Dimension PAGING_BTN_SIZE = new Dimension(20, 20);
private int currentPageNum = 1;
private int totalPageNum;
private int numPerPage;
private ChangeListener changeListener;
private UIButton lastPageBtn;
private UIButton nextPageBtn;
private UINumberField pagingEditField;
public PagingFiledPane(int totalItems, int numPerPage) {
this.setOpaque(false);
this.numPerPage = numPerPage;
this.totalPageNum = totalItems / numPerPage + ((totalItems % numPerPage) == 0 ? 0 : 1);
this.totalPageNum = this.totalPageNum > 0 ? this.totalPageNum : 1;
initPane(totalPageNum);
}
private void initPane(int totalPageNum) {
this.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 15));
initLastPageBtn();
JSeparator jSeparator1 = new JSeparator();
pagingEditField = new UINumberField();
registerPagingEditFieldListener();
pagingEditField.canFillNegativeNumber(false);
pagingEditField.setMinValue(1);
pagingEditField.setMaxValue(totalPageNum);
pagingEditField.setPreferredSize(new Dimension(50, 20));
UILabel totalPageLabel = new UILabel("/" + totalPageNum);
JSeparator jSeparator2 = new JSeparator();
initNextPageBtn();
checkPageStatus();
this.add(lastPageBtn);
this.add(jSeparator1);
this.add(pagingEditField);
this.add(totalPageLabel);
this.add(jSeparator2);
this.add(nextPageBtn);
}
public void setEnable(boolean enable) {
lastPageBtn.setEnabled(enable);
nextPageBtn.setEnabled(enable);
pagingEditField.setEnabled(enable);
}
private void initLastPageBtn() {
lastPageBtn = new UIButton(BaseUtils.readIcon("/com/fr/base/images/share/left_page_normal.png"));
lastPageBtn.setRolloverEnabled(true);
lastPageBtn.setFocusPainted(false);
lastPageBtn.setContentAreaFilled(true);
lastPageBtn.setMargin(new Insets(0, 0, 0, 0));
lastPageBtn.setPressedIcon(BaseUtils.readIcon("/com/fr/base/images/share/left_page_click.png"));
lastPageBtn.setRolloverIcon(BaseUtils.readIcon("/com/fr/base/images/share/left_page_hover.png"));
lastPageBtn.setDisabledIcon(BaseUtils.readIcon("/com/fr/base/images/share/left_page_disable.png"));
lastPageBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clickLastPage();
}
});
lastPageBtn.setPreferredSize(PAGING_BTN_SIZE);
}
private void initNextPageBtn() {
nextPageBtn = new UIButton(BaseUtils.readIcon("/com/fr/base/images/share/right_page_normal.png"));
nextPageBtn.setRolloverEnabled(true);
nextPageBtn.setFocusPainted(false);
nextPageBtn.setContentAreaFilled(true);
nextPageBtn.setMargin(new Insets(0, 0, 0, 0));
nextPageBtn.setPressedIcon(BaseUtils.readIcon("/com/fr/base/images/share/right_page_click.png"));
nextPageBtn.setRolloverIcon(BaseUtils.readIcon("/com/fr/base/images/share/right_page_hover.png"));
nextPageBtn.setDisabledIcon(BaseUtils.readIcon("/com/fr/base/images/share/right_page_disable.png"));
nextPageBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clickNextPage();
}
});
nextPageBtn.setPreferredSize(PAGING_BTN_SIZE);
}
private void registerPagingEditFieldListener() {
pagingEditField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent evt) {
int code = evt.getKeyCode();
if (code == KeyEvent.VK_ENTER) {
jumpPage((int) pagingEditField.getValue());
}
}
});
pagingEditField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
jumpPage((int) pagingEditField.getValue());
}
});
}
public int getCurrentPageNum() {
return currentPageNum;
}
public void registerChangeListener(ChangeListener changeListener) {
this.changeListener = changeListener;
}
private void checkPageStatus() {
lastPageBtn.setEnabled(currentPageNum > 1);
nextPageBtn.setEnabled(currentPageNum < totalPageNum);
pagingEditField.setText(String.valueOf(currentPageNum));
if (changeListener != null) {
changeListener.fireChanged(new ChangeEvent(currentPageNum));
}
}
private void clickNextPage() {
if (currentPageNum < totalPageNum) {
currentPageNum++;
checkPageStatus();
}
}
private void clickLastPage() {
if (currentPageNum > 1) {
currentPageNum--;
checkPageStatus();
}
}
private void jumpPage(int pageNum) {
if (pageNum > 0 && pageNum <= totalPageNum) {
currentPageNum = pageNum;
checkPageStatus();
}
}
public <T> T[] getShowItems(T[] items) {
int startIndex = Math.max(0, currentPageNum - 1);
T[] resultArr = ArrayUtils.subarray(items, startIndex * this.numPerPage, this.currentPageNum * this.numPerPage);
return resultArr;
}
/**
* 测试程序
*/
public static void main(String[] args) {
JFrame frame = new JFrame("");
frame.setSize(400, 320);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
PagingFiledPane tt = new PagingFiledPane(10, 3);
frame.getContentPane().add(tt);
frame.setVisible(true);
}
}

42
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PlaceholderTextArea.java

@ -0,0 +1,42 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.gui.itextarea.UITextArea;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
/**
* created by Harrison on 2020/04/21
**/
public class PlaceholderTextArea extends UITextArea {
private String placeholder;
public PlaceholderTextArea() {
}
public PlaceholderTextArea(String s, String placeholder) {
super(s);
this.placeholder = placeholder;
}
public void setPlaceholder(String placeholder) {
this.placeholder = placeholder;
}
@Override
protected void paintComponent(final Graphics pG) {
super.paintComponent(pG);
if (placeholder.length() == 0 || getText().length() > 0) {
return;
}
final Graphics2D g = (Graphics2D) pG;
g.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getDisabledTextColor());
g.drawString(placeholder, getInsets().left, pG.getFontMetrics()
.getMaxAscent() + getInsets().top + 1);
}}

31
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PopupMenuItem.java

@ -0,0 +1,31 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.constants.UIConstants;
import com.fr.design.mainframe.share.ui.base.ui.SharePopupMenuItemUI;
import com.fr.stable.StringUtils;
import javax.swing.Action;
import javax.swing.JMenuItem;
import java.awt.Dimension;
/**
* @Author: Yuan.Wang
* @Date: 2020/10/30
* 弹窗菜单项
*/
public class PopupMenuItem extends JMenuItem {
public PopupMenuItem(Action action) {
super(StringUtils.EMPTY, null);
setBackground(UIConstants.DEFAULT_BG_RULER);
setAction(action);
setUI(new SharePopupMenuItemUI());
this.setPreferredSize(new Dimension(60, 21));
}
@Override
public String getText() {
return StringUtils.EMPTY + super.getText();
}
}

83
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PopupPreviewPane.java

@ -0,0 +1,83 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.constants.UIConstants;
import com.fr.general.IOUtils;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
/**
* Created by kerry on 2020-06-23
*/
public class PopupPreviewPane extends JPopupMenu {
private Container contentPane;
private Image compImage;
private static final int WIDTH = 400;
private static final int STANDARD_DPI = 128;
private static final int MAX_HEIGHT = 400;
private static final int HEIGHT = 210;
public PopupPreviewPane() {
setFocusable(false);
contentPane = new JPanel();
contentPane.setBackground(Color.white);
this.setLayout(new BorderLayout());
this.add(contentPane, BorderLayout.CENTER);
this.setOpaque(false);
setPreferredSize(new Dimension(WIDTH, MAX_HEIGHT));
setBorder(BorderFactory.createLineBorder(UIConstants.LINE_COLOR));
}
public void setComp(Image compImage) {
try {
this.compImage = compImage;
this.updateSize();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (compImage != null) {
g.drawImage(compImage, 0, 0, getWidth(), getHeight(), null);
}
}
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
}
public void menuSelectionChanged(boolean isIncluded) {
}
// 根据控件内容,更新弹出框大小
private void updateSize() {
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
int width;
int height;
if (compImage == null) {
compImage = IOUtils.readImage("com/fr/base/images/share/component_error.png");
width = WIDTH;
height = HEIGHT;
} else {
width = compImage.getWidth(null);
height = compImage.getHeight(null);
}
double aspectRatio = (double) width / height;
width = (WIDTH * dpi) / STANDARD_DPI;
height = (int) (width / aspectRatio);
this.setPreferredSize(new Dimension(width, height));
}
}

231
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ShareProgressBar.java

@ -0,0 +1,231 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.gui.iprogressbar.ProgressDialog;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.ui.util.UIUtil;
import com.fr.stable.StringUtils;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
public class ShareProgressBar {
private static final int STEP = 20;
private ProgressDialog progressBar = null;
private LimitProgress loadingProgress = new LimitProgress();
/**
* 默认 40 ms更新进度
*/
private int stepHeartbeat = 40;
private volatile int progress = 0;
private final AtomicBoolean TERMINATE = new AtomicBoolean(false);
private final AtomicBoolean RUNNING = new AtomicBoolean(false);
private ShareProgressBar() {
}
private static class InstanceHolder {
private static final ShareProgressBar INSTANCE = new ShareProgressBar();
}
public static ShareProgressBar getInstance() {
return InstanceHolder.INSTANCE;
}
public void prepare(int stepHeartbeat) {
this.progressBar = createNewBar();
this.stepHeartbeat = stepHeartbeat;
}
public void updateProgress(double rate, String loadingText) throws Exception {
int maximum = progressBar.getProgressMaximum();
double progress = maximum * rate;
int maxProgress = (int) Math.floor(progress);
loadingProgress.lock(maxProgress, loadingText);
RUNNING.compareAndSet(false, true);
//终止条件
TERMINATE.compareAndSet(true, false);
loadingProgress.get();
}
public void monitor() {
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1,
new NamedThreadFactory("ShareProgressMonitor", true));
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
if (!isRunning()) {
return;
}
if (isComplete()) {
shutdown(scheduler);
return;
}
updateUI();
}
}, 0, stepHeartbeat, TimeUnit.MILLISECONDS);
}
/**
* 延迟关闭
*/
public void complete(String loadingText) throws Exception {
updateProgress(1.0, loadingText);
}
/**
* 立刻关闭
*/
public void completeNow() {
if (RUNNING.get()) {
this.progress = progressBar.getProgressMaximum();
this.TERMINATE.compareAndSet(false, true);
}
}
/**
* 完成条件不只是达到目标值还要确保当前已经可以终止了
*
* @return 是否终止了
*/
public boolean isComplete() {
return this.progress >= progressBar.getProgressMaximum() && this.TERMINATE.get();
}
private ProgressDialog createNewBar() {
return new ProgressDialog(DesignerContext.getDesignerFrame());
}
/**
* 小于当前最大时 每次递增 1
* 大于等于时 停止
*
* @return 当前最大值
*/
private int incrementProgress() {
if (progress >= loadingProgress.getLimitKey()) {
progress = loadingProgress.getLimitKey();
loadingProgress.release();
return progress;
} else {
progress += STEP;
return progress;
}
}
private String getLoadingText() {
return loadingProgress.getLimitText();
}
private boolean isRunning() {
return RUNNING.get();
}
private void shutdown(ScheduledExecutorService scheduler) {
//停止运行
RUNNING.compareAndSet(true, false);
reset();
scheduler.shutdown();
}
private void reset() {
this.progress = 0;
this.loadingProgress.reset();
this.progressBar.setVisible(false);
this.progressBar.dispose();
this.progressBar = null;
}
private void updateUI() {
String text = getLoadingText();
int value = incrementProgress();
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
if (!progressBar.isVisible()) {
progressBar.setVisible(true);
}
progressBar.updateLoadingText(text);
progressBar.setProgressValue(value);
}
});
}
private static class LimitProgress {
private int limitKey = 0;
private String limitText = StringUtils.EMPTY;
private FutureTask<Void> lock;
public void lock(int key, String loadingText) {
this.limitKey = key;
this.limitText = loadingText;
this.lock = new FutureTask<>(new Callable<Void>() {
@Override
public Void call() throws Exception {
return null;
}
});
}
public void release() {
this.lock.run();
}
public void get() throws Exception {
this.lock.get();
}
public void reset() {
this.limitKey = 0;
this.limitText = StringUtils.EMPTY;
//防止卡住。
this.lock.run();
}
public int getLimitKey() {
return limitKey;
}
public String getLimitText() {
return limitText;
}
}
}

104
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/SortPopupMenuItem.java

@ -0,0 +1,104 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.constants.UIConstants;
import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import sun.swing.SwingUtilities2;
import javax.swing.Action;
import javax.swing.ButtonModel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicMenuItemUI;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
/**
* Created by kerry on 2020-06-30
*/
public class SortPopupMenuItem extends JMenuItem {
public SortPopupMenuItem(Action action) {
super(StringUtils.EMPTY, null);
setBackground(UIConstants.DEFAULT_BG_RULER);
setAction(action);
setUI(new SortPopupMenuItemUI());
this.setPreferredSize(new Dimension(60, 21));
}
@Override
public String getText() {
return StringUtils.EMPTY + super.getText();
}
private class SortPopupMenuItemUI extends BasicMenuItemUI {
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
if (menuItem.getIcon() == null) {
super.paintBackground(g, menuItem, bgColor);
return;
}
ButtonModel model = menuItem.getModel();
Color oldColor = g.getColor();
int menuWidth = menuItem.getWidth();
int menuHeight = menuItem.getHeight();
g.setColor(UIConstants.DEFAULT_BG_RULER);
g.fillRect(0, 0, menuWidth, menuHeight);
if (menuItem.isOpaque()) {
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7);
} else {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7);
}
g.setColor(oldColor);
} else if (model.isArmed() || (menuItem instanceof JMenu &&
model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7);
g.setColor(oldColor);
}
}
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
ButtonModel model = menuItem.getModel();
FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
int mnemIndex = menuItem.getDisplayedMnemonicIndex();
if (!model.isEnabled()) {
// *** paint the text disabled
if (UIManager.get("MenuItem.disabledForeground") instanceof Color) {
g.setColor(UIManager.getColor("MenuItem.disabledForeground"));
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, textRect.x, textRect.y + fm.getAscent());
} else {
g.setColor(menuItem.getBackground().brighter());
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, textRect.x, textRect.y + fm.getAscent());
g.setColor(menuItem.getBackground().darker());
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, textRect.x - 1, textRect.y +
fm.getAscent() - 1);
}
} else {
// *** paint the text normally
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
g.setColor(Color.WHITE); // Uses protected field.
}
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, textRect.x, textRect.y + fm.getAscent());
}
}
}
}

48
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ui/PlaceHolderUI.java

@ -0,0 +1,48 @@
package com.fr.design.mainframe.share.ui.base.ui;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
/**
* created by Harrison on 2020/04/22
**/
public abstract class PlaceHolderUI<T extends JComponent> extends ComponentUI {
private static final Color DEFAULT_COLOR = new Color(143, 142, 139);
private String placeholder;
public PlaceHolderUI(String placeholder) {
this.placeholder = placeholder;
}
@Override
public void paint(Graphics pG, JComponent c) {
@SuppressWarnings("unchecked") T realType = (T) c;
if (placeholder.length() == 0 || validate(realType)) {
return;
}
final Graphics2D g = (Graphics2D) pG;
g.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(getDisabledTextColor());
g.drawString(placeholder, c.getInsets().left + 10, pG.getFontMetrics()
.getMaxAscent() + c.getInsets().top + 3);
}
protected abstract boolean validate(T t);
protected Color getDisabledTextColor() {
return DEFAULT_COLOR;
};
}

82
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/ui/SharePopupMenuItemUI.java

@ -0,0 +1,82 @@
package com.fr.design.mainframe.share.ui.base.ui;
import com.fr.design.constants.UIConstants;
import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.stable.Constants;
import sun.swing.SwingUtilities2;
import javax.swing.ButtonModel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicMenuItemUI;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
/**
* @Author: Yuan.Wang
* @Date: 2020/10/30
*/
public class SharePopupMenuItemUI extends BasicMenuItemUI {
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
if (menuItem.getIcon() == null) {
super.paintBackground(g, menuItem, bgColor);
return;
}
ButtonModel model = menuItem.getModel();
Color oldColor = g.getColor();
int menuWidth = menuItem.getWidth();
int menuHeight = menuItem.getHeight();
g.setColor(UIConstants.DEFAULT_BG_RULER);
g.fillRect(0, 0, menuWidth, menuHeight);
if (menuItem.isOpaque()) {
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7);
} else {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7);
}
g.setColor(oldColor);
} else if (model.isArmed() || (menuItem instanceof JMenu &&
model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7);
g.setColor(oldColor);
}
}
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
ButtonModel model = menuItem.getModel();
FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
if (!model.isEnabled()) {
// *** paint the text disabled
if (UIManager.get("MenuItem.disabledForeground") instanceof Color) {
g.setColor(UIManager.getColor("MenuItem.disabledForeground"));
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, textRect.x, textRect.y + fm.getAscent());
} else {
g.setColor(menuItem.getBackground().brighter());
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, textRect.x, textRect.y + fm.getAscent());
g.setColor(menuItem.getBackground().darker());
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, textRect.x - 1, textRect.y +
fm.getAscent() - 1);
}
} else {
g.setColor(Color.BLACK);
// *** paint the text normally
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
g.setColor(Color.WHITE); // Uses protected field.
}
SwingUtilities2.drawStringUnderlineCharAt(menuItem, g, text,
-1, textRect.x, textRect.y + fm.getAscent());
}
}
}

94
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java

@ -0,0 +1,94 @@
package com.fr.design.mainframe.share.ui.block;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.share.ui.online.OnlineResourceManager;
import com.fr.design.mainframe.share.ui.online.OnlineWidgetSelectPane;
import com.fr.design.mainframe.share.ui.online.ResourceLoader;
import com.fr.form.share.bean.OnlineShareWidget;
import com.fr.form.share.constants.ShareComponentConstants;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.EncodeConstants;
import com.fr.third.springframework.web.util.UriUtils;
import org.jetbrains.annotations.NotNull;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import java.awt.Dimension;
import java.awt.Image;
import java.io.IOException;
import java.net.URL;
/**
* Created by kerry on 2020-11-22
*/
public abstract class AbstractOnlineWidgetBlock extends PreviewWidgetBlock<OnlineShareWidget> implements ResourceLoader {
private final OnlineWidgetSelectPane parentPane;
private UILabel coverLabel;
public AbstractOnlineWidgetBlock(OnlineShareWidget widget, OnlineWidgetSelectPane parentPane) {
super(widget);
this.parentPane = parentPane;
}
protected UILabel initCoverLabel(Image image) {
coverLabel = new UILabel(new ImageIcon(image));
return coverLabel;
}
@Override
protected String getWidgetUuid() {
return widget.getUuid();
}
protected void showPreview(OnlineShareWidget widget) {
parentPane.showPreviewPane(this, widget.getId());
}
protected void hidePreview() {
parentPane.hidePreviewPane();
}
@Override
@NotNull
protected Image getCoverImage() {
OnlineResourceManager.getInstance().addLoader(this);
return getDefaultDisplayImage();
}
public Image getPreviewImage() {
try {
return ImageIO.read(new URL(UriUtils.encodePath(widget.getPicPath(), EncodeConstants.ENCODING_UTF_8)));
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return getDefaultDisplayImage();
}
}
public void load() {
Image image;
try {
Dimension coverDimension = getCoverDimension();
String previewURI = UriUtils.encodePath(widget.getPicPath(), EncodeConstants.ENCODING_UTF_8) + "?x-oss-process=image/resize,m_fixed," + "w_" + coverDimension.width +
",h_" + coverDimension.height;
image = ImageIO.read(new URL(previewURI));
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
image = getDefaultDisplayImage();
}
resetCover(image);
}
private Image getDefaultDisplayImage(){
return ShareComponentConstants.DEFAULT_COVER;
}
public void resetCover(Image image) {
coverLabel.setIcon(new ImageIcon(image));
this.parentPane.validate();
this.parentPane.repaint();
}
}

72
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/DragAndDropDragGestureListener.java

@ -0,0 +1,72 @@
package com.fr.design.mainframe.share.ui.block;
import com.fr.form.share.utils.ShareUtils;
import com.fr.form.ui.Widget;
import com.fr.general.ComparatorUtils;
import org.jetbrains.annotations.NotNull;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceAdapter;
import java.awt.dnd.DragSourceDragEvent;
/**
* @Author: Yuan.Wang
* @Date: 2021/1/15
*/
public class DragAndDropDragGestureListener extends DragSourceAdapter implements DragGestureListener {
private final PreviewWidgetBlock<?> block;
public DragAndDropDragGestureListener(PreviewWidgetBlock<?> tt, int actions) {
block = tt;
DragSource source = new DragSource();
source.createDefaultDragGestureRecognizer(tt, actions, this);
}
public void dragGestureRecognized(DragGestureEvent dge) {
PreviewWidgetBlock<?> onlineWidgetBlock = (PreviewWidgetBlock<?>) dge.getComponent();
if (onlineWidgetBlock != null) {
String uuid = block.getWidgetUuid();
Widget widget = ShareUtils.getElCaseEditorById(uuid);
if (widget != null) {
DragAndDropTransferable dragAndDropTransferable = new DragAndDropTransferable(widget);
dge.startDrag(DragSource.DefaultCopyDrop, dragAndDropTransferable, this);
}
}
}
@Override
public void dragEnter(DragSourceDragEvent dragSourceDragEvent) {
}
private static class DragAndDropTransferable implements Transferable {
private final Widget widget;
public DragAndDropTransferable(Widget widget) {
this.widget = widget;
}
DataFlavor[] flavors = {new DataFlavor(Widget.class, "Widget")};
public DataFlavor[] getTransferDataFlavors() {
return flavors;
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
for (DataFlavor df : flavors) {
if (ComparatorUtils.equals(df, flavor)) {
return true;
}
}
return false;
}
@NotNull
public Object getTransferData(DataFlavor df) {
return widget;
}
}
}

313
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java

@ -0,0 +1,313 @@
package com.fr.design.mainframe.share.ui.block;
import com.fr.base.GraphHelper;
import com.fr.base.iofile.attr.SharableAttrMark;
import com.fr.design.actions.UpdateAction;
import com.fr.design.base.mode.DesignModeContext;
import com.fr.design.constants.UIConstants;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.imenu.UIPopupMenu;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.WidgetToolBarPane;
import com.fr.design.mainframe.share.group.ui.GroupMoveDialog;
import com.fr.design.mainframe.share.ui.base.PopupMenuItem;
import com.fr.design.mainframe.share.ui.local.LocalWidgetRepoPane;
import com.fr.design.mainframe.share.ui.local.LocalWidgetSelectPane;
import com.fr.design.mainframe.share.ui.local.WidgetSelectedManager;
import com.fr.design.mainframe.share.util.ShareComponentUtils;
import com.fr.design.mainframe.share.util.ShareUIUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.form.share.DefaultSharableWidget;
import com.fr.form.share.SharableWidgetProvider;
import com.fr.form.share.constants.ShareComponentConstants;
import com.fr.form.share.Group;
import com.fr.form.share.record.ShareWidgetInfoManager;
import com.fr.form.ui.AbstractBorderStyleWidget;
import com.fr.form.ui.Widget;
import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.stable.Constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.dnd.DnDConstants;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.util.UUID;
/**
* created by Harrison on 2020/06/12
* 本地组件块
**/
public class LocalWidgetBlock extends PreviewWidgetBlock<DefaultSharableWidget> {
private static final int MARK_START_X = 83;
private boolean mouseHover = false;
private final LocalWidgetSelectPane parentPane;
private MouseEvent lastPressEvent;
private boolean isEdit;
private boolean isMarked;
private boolean pressed;
private boolean hover;
private final Icon markedMode = IOUtils.readIcon("/com/fr/base/images/share/marked.png");
private final Icon unMarkedMode = IOUtils.readIcon("/com/fr/base/images/share/unmarked.png");
public LocalWidgetBlock(DefaultSharableWidget provider, LocalWidgetSelectPane parentPane) {
super(provider);
this.parentPane = parentPane;
new DragAndDropDragGestureListener(this, DnDConstants.ACTION_COPY_OR_MOVE);
initUI();
}
private void initUI() {
JPanel labelPane = new JPanel(new BorderLayout());
UILabel label = new UILabel(this.getBindInfo().getName(), UILabel.CENTER);
label.setPreferredSize(new Dimension(ShareComponentConstants.SHARE_THUMB_WIDTH, ShareComponentConstants.SHARE_BLOCK_LABEL_HEIGHT));
labelPane.setBackground(Color.WHITE);
labelPane.add(label, BorderLayout.CENTER);
this.add(labelPane, BorderLayout.SOUTH);
}
public void setElementCaseEdit(boolean isEdit) {
this.isEdit = isEdit;
if (isEdit) {
isMarked = WidgetSelectedManager.getInstance().isSelected(getGroup().getGroupName(), this.getWidget().getId());
}
repaint();
}
public String getFileName() {
//插件里面, 所有的值都是插件值。可以强转的。
DefaultSharableWidget provider = (DefaultSharableWidget) getBindInfo();
return provider.getFileName();
}
public SharableWidgetProvider getBindInfo() {
return this.getWidget();
}
@Override
protected void showPreview(DefaultSharableWidget widget) {
this.parentPane.showPreviewPane(this, widget.getId());
}
@Override
protected void hidePreview() {
this.parentPane.hidePreviewPane();
}
@Override
@NotNull
public Image getCoverImage() {
return this.getWidget().getCover();
}
@Override
protected String getWidgetUuid() {
return widget.getId();
}
@Nullable
public Image getPreviewImage() {
String id = this.getWidget().getId();
return getGroup().getPreviewImage(id);
}
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
if (e.getButton() == MouseEvent.BUTTON3 && !isEdit) {
this.parentPane.hidePreviewPane();
UIPopupMenu popupMenu = new UIPopupMenu();
popupMenu.setOnlyText(true);
popupMenu.setBackground(UIConstants.DEFAULT_BG_RULER);
popupMenu.add(new PopupMenuItem(new MoveGroupAction()));
popupMenu.add(new PopupMenuItem(new RemoveAction()));
GUICoreUtils.showPopupMenu(popupMenu, this, e.getX(), e.getY());
}
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
lastPressEvent = e;
pressed = true;
}
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
if (pressed && hover) {
dealClickAction(e);
}
pressed = false;
}
@Override
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
this.mouseHover = true;
if (!isEdit) {
setCursor(new Cursor(Cursor.MOVE_CURSOR));
}
this.repaint();
}
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
hover = true;
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
this.mouseHover = false;
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
hover = false;
this.repaint();
}
@Override
public void mouseDragged(MouseEvent e) {
if (DesignModeContext.isAuthorityEditing() || lastPressEvent == null || isEdit) {
return;
}
hidePreview();
Object source = e.getSource();
Widget creatorSource;
String shareId;
if (source instanceof LocalWidgetBlock) {
LocalWidgetBlock no = (LocalWidgetBlock) e.getSource();
if (no == null) {
return;
}
shareId = no.getBindInfo().getId();
creatorSource = getGroup().getElCaseEditorById(shareId);
if (creatorSource == null) {
ShareUIUtils.showErrorMessageDialog(Toolkit.i18nText("Fine-Design_Share_Drag_Error_Info"));
return;
}
creatorSource.setWidgetID(UUID.randomUUID().toString());
((AbstractBorderStyleWidget) creatorSource).addWidgetAttrMark(new SharableAttrMark(true));
//tab布局WCardMainBorderLayout通过反射出来的大小是960*480
XCreator xCreator = ShareComponentUtils.createXCreator(creatorSource, shareId, no.getBindInfo());
WidgetToolBarPane.getTarget().startDraggingBean(xCreator);
lastPressEvent = null;
this.setBorder(null);
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
//绘制删除标志
if (isEdit) {
Icon icon = isMarked ? markedMode : unMarkedMode;
icon.paintIcon(this, g, MARK_START_X, 0);
}
if (ComparatorUtils.equals(this, this.parentPane.getSelectedBlock()) || this.mouseHover) {
g.setColor(XCreatorConstants.FORM_BORDER_COLOR);
Rectangle rectangle = new Rectangle();
rectangle.width = this.getWidth();
rectangle.height = this.getHeight();
GraphHelper.draw(g, rectangle, Constants.LINE_LARGE);
}
}
/**
* 由鼠标释放时调用该方法来触发左键点击事件
*/
private void dealClickAction(MouseEvent e) {
this.parentPane.setSelectBlock(this);
if (e.getButton() == MouseEvent.BUTTON1) {
if (isEdit) {
if (isMarked) {
WidgetSelectedManager.getInstance().removeSelect(getGroup().getGroupName(), this.getWidget().getId());
isMarked = false;
} else {
WidgetSelectedManager.getInstance().addSelect(getGroup().getGroupName(), this.getWidget().getId());
isMarked = true;
}
}
//没有组件被选择则禁用按钮
LocalWidgetRepoPane.getInstance().setManageButtonEnable(hasComponentSelected());
repaint();
}
}
private Group getGroup() {
return parentPane.getGroup();
}
private boolean hasComponentSelected() {
return !WidgetSelectedManager.getInstance().isSelectEmpty();
}
private class MoveGroupAction extends UpdateAction {
public MoveGroupAction() {
this.putValue(Action.SMALL_ICON, null);
this.setName(Toolkit.i18nText("Fine-Design_Share_Group_Move"));
}
@Override
public void actionPerformed(ActionEvent e) {
new GroupMoveDialog(DesignerContext.getDesignerFrame()) {
@Override
protected void confirmClose() {
this.dispose();
Group group = (Group) getSelectGroupBox().getSelectedItem();
assert group != null;
if (WidgetSelectedManager.getInstance().moveSelect(getGroup().getGroupName(), group.getGroupName(), getWidget().getId())) {
ShareWidgetInfoManager.getInstance().saveXmlInfo();
LocalWidgetRepoPane.getInstance().refreshShowPanel(false);
} else {
ShareUIUtils.showErrorMessageDialog(Toolkit.i18nText("Fine-Design_Share_Group_Move_Fail_Message"));
}
}
};
}
}
private class RemoveAction extends UpdateAction {
public RemoveAction() {
this.putValue(Action.SMALL_ICON, null);
this.setName(Toolkit.i18nText("Fine-Design_Share_Remove"));
}
@Override
public void actionPerformed(ActionEvent e) {
int rv = FineJOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Share_Remove_Info"),
Toolkit.i18nText("Fine-Design_Share_Group_Confirm"),
FineJOptionPane.YES_NO_OPTION
);
if (rv == FineJOptionPane.YES_OPTION) {
if (!WidgetSelectedManager.getInstance().unInstallSelect(getGroup().getGroupName(), getWidget().getId())) {
FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Share_Remove_Failure"));
}
LocalWidgetRepoPane.getInstance().refreshShowPanel(getGroup());
}
}
}
}

303
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java

@ -0,0 +1,303 @@
package com.fr.design.mainframe.share.ui.block;
import com.fr.base.iofile.attr.SharableAttrMark;
import com.fr.config.MarketConfig;
import com.fr.design.base.mode.DesignModeContext;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.extra.WebViewDlgHelper;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.WidgetToolBarPane;
import com.fr.design.mainframe.share.collect.ComponentCollector;
import com.fr.form.share.group.DefaultShareGroup;
import com.fr.design.mainframe.share.ui.local.LocalWidgetRepoPane;
import com.fr.design.mainframe.share.ui.online.OnlineWidgetRepoPane;
import com.fr.design.mainframe.share.ui.online.OnlineWidgetSelectPane;
import com.fr.design.mainframe.share.util.DownloadUtils;
import com.fr.design.mainframe.share.util.ShareComponentUtils;
import com.fr.design.mainframe.share.util.ShareUIUtils;
import com.fr.design.ui.util.UIUtil;
import com.fr.form.share.SharableWidgetProvider;
import com.fr.form.share.bean.OnlineShareWidget;
import com.fr.form.share.constants.ShareComponentConstants;
import com.fr.form.share.group.DefaultShareGroupManager;
import com.fr.form.share.Group;
import com.fr.form.share.utils.ShareUtils;
import com.fr.form.ui.AbstractBorderStyleWidget;
import com.fr.form.ui.Widget;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Stroke;
import java.awt.dnd.DnDConstants;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
/**
* Created by kerry on 2020-10-19
* 商城组件块
*/
public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
private boolean isMouseEnter = false;
private boolean downloading = false;
private static final Color COVER_COLOR = Color.decode("#333334");
protected MouseEvent lastPressEvent;
private double process = 0D;
private static final BufferedImage WIDGET_INSTALLED_ICON = IOUtils.readImage("/com/fr/base/images/share/widget_installed.png");
private static final BufferedImage WIDGET_DOWNLOAD_ICON = IOUtils.readImage("/com/fr/base/images/share/download.png");
private static final BufferedImage WIDGET_DOWNLOADING_ICON = IOUtils.readImage("/com/fr/base/images/share/downloading.png");
public OnlineWidgetBlock(OnlineShareWidget widget, OnlineWidgetSelectPane parentPane) {
super(widget, parentPane);
this.add(createSouthPane(widget), BorderLayout.SOUTH);
new DragAndDropDragGestureListener(this, DnDConstants.ACTION_COPY_OR_MOVE);
}
protected JPanel createSouthPane(OnlineShareWidget widget) {
JPanel southPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
UILabel label = new UILabel(widget.getName(), UILabel.CENTER);
label.setToolTipText(widget.getName());
label.setHorizontalTextPosition(SwingConstants.LEFT);
southPane.add(label, BorderLayout.CENTER);
UILabel emptyLabel = new UILabel();
emptyLabel.setPreferredSize(new Dimension(25, 20));
southPane.add(emptyLabel, BorderLayout.EAST);
southPane.setBackground(Color.WHITE);
return southPane;
}
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
this.isMouseEnter = true;
this.repaint();
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
this.isMouseEnter = false;
this.repaint();
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
this.lastPressEvent = e;
}
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
if (!checkWidgetInstalled() && getDownloadIconRec().contains(e.getX(), e.getY())) {
downLoadWidget();
}
}
@Override
public void mouseDragged(MouseEvent e) {
if (DesignModeContext.isAuthorityEditing() || !checkWidgetInstalled()) {
return;
}
if (lastPressEvent == null) {
return;
}
Object source = e.getSource();
Widget creatorSource;
String shareId;
if (source instanceof OnlineWidgetBlock) {
OnlineWidgetBlock no = (OnlineWidgetBlock) e.getSource();
if (no == null) {
return;
}
shareId = widget.getUuid();
creatorSource = ShareUtils.getElCaseEditorById(shareId);
if (creatorSource == null) {
ShareUIUtils.showErrorMessageDialog(Toolkit.i18nText("Fine-Design_Share_Drag_Error_Info"));
return;
}
creatorSource.setWidgetID(UUID.randomUUID().toString());
((AbstractBorderStyleWidget) creatorSource).addWidgetAttrMark(new SharableAttrMark(true));
SharableWidgetProvider bindInfo = ShareUtils.getElCaseBindInfoById(shareId);
//tab布局WCardMainBorderLayout通过反射出来的大小是960*480
XCreator xCreator = ShareComponentUtils.createXCreator(creatorSource, shareId, bindInfo);
WidgetToolBarPane.getTarget().startDraggingBean(xCreator);
lastPressEvent = null;
this.setBorder(null);
}
}
private void downLoadWidget() {
if (OnlineWidgetRepoPane.getInstance().isShowPackagePanel()) {
ComponentCollector.getInstance().collectDownloadPktNum();
}
final WidgetDownloadProcess process = new WidgetDownloadProcess();
downloading = true;
process.process(0.0D);
String userName = MarketConfig.getInstance().getBbsUsername();
if (StringUtils.isEmpty(userName)) {
WebViewDlgHelper.createLoginDialog();
downloading = false;
return;
}
new SwingWorker<Boolean, Void>() {
@Override
protected Boolean doInBackground() {
String filePath;
try {
filePath = DownloadUtils.download(widget.getId(), widget.getName() + "." + widget.getUuid(), process);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
}
ShareComponentUtils.checkReadMe();
//安装
File file = new File(filePath);
try {
if (file.exists() && getDefaultGroup().installModule(file)) {
ShareUtils.recordInstallTime(file.getName(), System.currentTimeMillis());
ComponentCollector.getInstance().collectCmpDownLoad(widget.getUuid());
}
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
//删掉下载组件的目录
StableUtils.deleteFile(file);
}
return true;
}
@Override
protected void done() {
downloading = false;
OnlineWidgetBlock.this.process = 0.0D;
try {
if (get()) {
LocalWidgetRepoPane.getInstance().refreshShowPanel();
} else {
ShareUIUtils.showErrorMessageDialog(Toolkit.i18nText("Fine-Design_Share_Download_Failed"));
}
} catch (InterruptedException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}.execute();
}
@Override
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
if (checkWidgetInstalled()) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
} else if (getDownloadIconRec().contains(e.getX(), e.getY())) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
} else {
this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
private Rectangle getDownloadIconRec() {
return new Rectangle(ShareComponentConstants.SHARE_THUMB_WIDTH / 2 - 12, ShareComponentConstants.SHARE_BLOCK_HEIGHT / 2 - 16, 24, 24);
}
private boolean checkWidgetInstalled() {
return ShareUtils.getElCaseBindInfoById(widget.getUuid()) != null;
}
private Group getDefaultGroup() {
return DefaultShareGroupManager.getInstance().getGroup(DefaultShareGroup.GROUP_NAME);
}
public void paint(Graphics g) {
super.paint(g);
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
int x = 0;
int y = 0;
int w = getWidth();
int h = getHeight();
if (process == 1 || checkWidgetInstalled()) {
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(
WIDGET_INSTALLED_ICON,
w - 20,
h - 20,
WIDGET_INSTALLED_ICON.getWidth(),
WIDGET_INSTALLED_ICON.getHeight(),
null,
this
);
return;
}
//如果鼠标移动到布局内且布局不可编辑,画出编辑蒙层
if (isMouseEnter || downloading) {
Graphics2D g2d = (Graphics2D) g;
Composite oldComposite = g2d.getComposite();
//画白色的编辑层
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 20 / 100.0F));
g2d.setColor(COVER_COLOR);
g2d.fillRect(x, y, w, h);
g2d.setComposite(oldComposite);
//画编辑按钮图标
BufferedImage image = (process > 0 || downloading) ? WIDGET_DOWNLOADING_ICON : WIDGET_DOWNLOAD_ICON;
g2d.drawImage(
image,
(x + w / 2 - 12),
(y + h / 2 - 16),
image.getWidth(),
image.getHeight(),
null,
this
);
Stroke oldStroke = g2d.getStroke();
g2d.setStroke(XCreatorConstants.STROKE);
g2d.setColor(Color.decode("#419BF9"));
double arcAngle = downloading ? (36 + 360 * 0.9 * process) : 0.0;
g2d.drawArc(x + w / 2 - 12, y + h / 2 - 16, 24, 24, 90, -(int) arcAngle);
g2d.setColor(Color.WHITE);
g2d.setStroke(oldStroke);
}
}
class WidgetDownloadProcess implements com.fr.design.extra.Process<Double> {
@Override
public void process(Double aDouble) {
OnlineWidgetBlock.this.process = aDouble;
final Dimension dimension = OnlineWidgetBlock.this.getSize();
UIUtil.invokeAndWaitIfNeeded(() -> OnlineWidgetBlock.this.paintImmediately(0, 0, dimension.width, dimension.height));
}
}
}

57
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetPackageBlock.java

@ -0,0 +1,57 @@
package com.fr.design.mainframe.share.ui.block;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.share.ui.base.MouseClickListener;
import com.fr.design.mainframe.share.ui.online.widgetpackage.OnlineWidgetPackageSelectPane;
import com.fr.form.share.bean.OnlineShareWidget;
import com.fr.form.share.constants.ShareComponentConstants;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
/**
* Created by kerry on 2020-10-21
* 商城组件包块
*/
public class OnlineWidgetPackageBlock extends AbstractOnlineWidgetBlock {
private static final int IMAGE_HEIGHT = 167;
private static final Color TEXT_COLOR = Color.decode("#419BF9");
protected JPanel createSouthPane(final OnlineShareWidget widget, final OnlineWidgetPackageSelectPane parentPane) {
JPanel southPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
southPane.setBackground(Color.WHITE);
UILabel label = new UILabel(widget.getName(), UILabel.CENTER);
label.setToolTipText(widget.getName());
southPane.add(label, BorderLayout.CENTER);
UILabel detailLabel = new UILabel(Toolkit.i18nText("Fine-Design_Share_Online_Package_Detail"));
detailLabel.setForeground(TEXT_COLOR);
detailLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
detailLabel.addMouseListener(new MouseClickListener() {
@Override
public void mouseClicked(MouseEvent e) {
parentPane.showWidgetDetailPane(widget.getId());
}
});
southPane.add(detailLabel, BorderLayout.EAST);
return southPane;
}
protected Dimension getCoverDimension() {
return new Dimension(ShareComponentConstants.SHARE_PACKAGE_BLOCK_WIDTH, IMAGE_HEIGHT);
}
public OnlineWidgetPackageBlock(OnlineShareWidget widget, OnlineWidgetPackageSelectPane parentPane) {
super(widget, parentPane);
this.setPreferredSize(new Dimension(ShareComponentConstants.SHARE_PACKAGE_BLOCK_WIDTH, ShareComponentConstants.SHARE_PACKAGE_BLOCK_HEIGHT));
this.add(createSouthPane(widget, parentPane), BorderLayout.SOUTH);
}
}

138
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/PreviewWidgetBlock.java

@ -0,0 +1,138 @@
package com.fr.design.mainframe.share.ui.block;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.form.share.constants.ShareComponentConstants;
import org.jetbrains.annotations.NotNull;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.Serializable;
/**
* Created by kerry on 2020-10-21
*/
public abstract class PreviewWidgetBlock<T> extends JPanel implements MouseListener, MouseMotionListener, Serializable {
protected T widget;
private boolean showing = false;
public PreviewWidgetBlock(T widget) {
this.widget = widget;
initPane();
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
protected void initPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setPreferredSize(new Dimension(ShareComponentConstants.SHARE_THUMB_WIDTH, ShareComponentConstants.SHARE_BLOCK_HEIGHT));
JPanel labelPane = new JPanel(new BorderLayout());
Image image = getCoverImage();
labelPane.add(initCoverLabel(image));
labelPane.setBackground(Color.WHITE);
this.add(labelPane, BorderLayout.CENTER);
}
protected UILabel initCoverLabel(Image image) {
return new UILabel(new ImageIcon(image));
}
public T getWidget() {
return widget;
}
@NotNull
protected abstract Image getCoverImage();
protected Dimension getCoverDimension() {
return new Dimension(ShareComponentConstants.SHARE_THUMB_WIDTH, ShareComponentConstants.SHARE_THUMB_HEIGHT);
}
private void showPreviewPane() {
synchronized (this) {
if (!showing) {
showPreview(widget);
showing = true;
}
}
}
protected abstract String getWidgetUuid();
protected abstract void showPreview(T widget);
protected abstract void hidePreview();
private void hidePreviewPane() {
if (showing) {
hidePreview();
showing = false;
}
}
public abstract Image getPreviewImage();
@Override
public void mouseClicked(MouseEvent e) {
this.hidePreviewPane();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
this.hidePreviewPane();
}
@Override
public void mouseDragged(MouseEvent e) {
}
@Override
public void mouseMoved(MouseEvent e) {
Dimension dimension = getCoverDimension();
Rectangle containerRec = new Rectangle(0, 0, dimension.width, dimension.height);
if (containerRec.contains(e.getX(), e.getY())) {
this.showPreviewPane();
} else {
this.hidePreviewPane();
}
}
@Override
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, getWidth(), getHeight());
super.paint(g);
}
protected void removeListener() {
this.removeMouseListener(this);
this.removeMouseMotionListener(this);
}
}

17
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/SimpleWidgetBlock.java

@ -0,0 +1,17 @@
package com.fr.design.mainframe.share.ui.block;
import com.fr.design.mainframe.share.ui.online.OnlineWidgetSelectPane;
import com.fr.form.share.bean.OnlineShareWidget;
/**
* @Author: Yuan.Wang
* @Date: 2020/12/22
* 只能显示无其他功能的组件块
*/
public class SimpleWidgetBlock extends OnlineWidgetBlock {
public SimpleWidgetBlock(OnlineShareWidget widget, OnlineWidgetSelectPane parentPane) {
super(widget, parentPane);
this.removeListener();
this.setFocusable(false);
}
}

380
designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/GroupPane.java

@ -0,0 +1,380 @@
package com.fr.design.mainframe.share.ui.local;
import com.fr.design.actions.UpdateAction;
import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.imenu.UIPopupMenu;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.share.group.ui.GroupFileDialog;
import com.fr.design.mainframe.share.sort.WidgetSortType;
import com.fr.design.mainframe.share.ui.base.PopupMenuItem;
import com.fr.design.mainframe.share.ui.widgetfilter.LocalWidgetFilter;
import com.fr.design.mainframe.share.util.ShareUIUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.form.share.SharableWidgetProvider;
import com.fr.form.share.group.DefaultShareGroupManager;
import com.fr.form.share.Group;
import com.fr.general.IOUtils;
import com.fr.stable.StringUtils;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
/**
* @Author: Yuan.Wang
* @Date: 2020/11/5
*/
class GroupPane extends JPanel {
private static final Icon downIcon = IOUtils.readIcon("/com/fr/base/images/share/arrow_down.png");
private static final Icon rightIcon = IOUtils.readIcon("/com/fr/base/images/share/arrow_right.png");
private static final int DEFAULT_HEIGHT = 24;
private final Group group;
private LocalWidgetSelectPane contentPanel;
private UIHeaderPane headerPanel;
private final int headHeight;
//是否展开
private boolean expendStatus;
private SharableWidgetProvider[] elCaseBindInfoList;
private GroupPane(Group group) {
this(group, DEFAULT_HEIGHT, group.isDefaultExpend());
}
private GroupPane(Group group, boolean expendStatus) {
this(group, DEFAULT_HEIGHT, expendStatus);
}
private GroupPane(Group group, int headHeight, boolean expendStatus) {
this.group = group;
this.headHeight = headHeight;
this.expendStatus = expendStatus;
initComponents();
}
public boolean isComponentEditable() {
return LocalWidgetRepoPane.getInstance().isEditable();
}
private void initComponents() {
this.setLayout(new BorderLayout());
this.setOpaque(false);
headerPanel = new UIHeaderPane(group.getGroupName(), headHeight);
JPanel head = new JPanel(new BorderLayout());
head.add(headerPanel, BorderLayout.NORTH);
head.setPreferredSize(new Dimension(240, 24));
this.add(head, BorderLayout.NORTH);
refreshShowPanel();
}
public void refreshShowPanel() {
this.setVisible(true);
refreshBindInfoList();
//按照筛选条件进行过滤
elCaseBindInfoList = LocalWidgetFilter.getInstance().filter(elCaseBindInfoList);
boolean needExpendGroup = expendStatus || (isFiltering() && elCaseBindInfoList.length > 0);
if (elCaseBindInfoList.length == 0 && isFiltering()) {
this.setVisible(false);
}
//刷新面板的时候可能还有查询条件,如果有的话走一遍查询的逻辑
String keyWord = LocalWidgetRepoPane.getInstance().getKeyWord4Searching();
if (StringUtils.isNotEmpty(keyWord)) {
searchByKeyword(keyWord);
return;
}
reCreateShowPane(elCaseBindInfoList);
expendGroup(needExpendGroup);
}
public void reCreateShowPane(SharableWidgetProvider[] widgets) {
if (contentPanel != null) {
contentPanel.hidePreviewPane();
GroupPane.this.remove(contentPanel);
}
contentPanel = new LocalWidgetSelectPane(group, widgets, isComponentEditable());
GroupPane.this.add(contentPanel, BorderLayout.CENTER);
headerPanel.setMenuItemVisible(!isComponentEditable());
validate();
repaint();
revalidate();
}
private void expendGroup(boolean expendStatus) {
headerPanel.showExpand(expendStatus);
contentPanel.setVisible(expendStatus);
}
protected void setExpendStatus(boolean expendStatus) {
//在筛选或者搜索状态,调用这个方法直接返回
if (isFiltering() || isSearching()) {
return;
}
this.expendStatus = expendStatus;
}
public SharableWidgetProvider[] getAllBindInfoList() {
SharableWidgetProvider[] widgetProviders = group.getAllBindInfoList();
if (widgetProviders == null) {
widgetProviders = new SharableWidgetProvider[0];
}
WidgetSortType.INSTALL_TIME.sort(widgetProviders);
return widgetProviders;
}
public void sortWidget(WidgetSortType sortType) {
sortType.sort(elCaseBindInfoList);
reCreateShowPane(elCaseBindInfoList);
}
public void searchByKeyword(String text) {
this.setVisible(true);
SharableWidgetProvider[] sharableWidgetArr = elCaseBindInfoList;
List<SharableWidgetProvider> widgets = new ArrayList<>();
if (StringUtils.isNotEmpty(text)) {
for (SharableWidgetProvider provider : elCaseBindInfoList) {
if (provider.getName().toLowerCase().contains(text)) {
widgets.add(provider);
}
}
sharableWidgetArr = widgets.toArray(new SharableWidgetProvider[widgets.size()]);
}
boolean needExpendGroup = expendStatus || (isSearching() && sharableWidgetArr.length > 0);
if (isSearching() && sharableWidgetArr.length == 0) {
setVisible(false);
}
reCreateShowPane(sharableWidgetArr);
expendGroup(needExpendGroup);
}
public void refreshBindInfoList() {
elCaseBindInfoList = getAllBindInfoList();
}
private boolean isFiltering() {
return LocalWidgetRepoPane.getInstance().isFiltering();
}
private boolean isSearching() {
return LocalWidgetRepoPane.getInstance().isSearching();
}
private class UIHeaderPane extends JPanel {
private static final long serialVersionUID = 1L;
private final UILabel arrow;
private final UILabel menuItem;
private final UILabel titleLabel;
private final int headHeight;
private boolean pressed;
private boolean hover;
private final MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3 && group.isEditable() && !GroupPane.this.isComponentEditable()) {
UIPopupMenu popupMenu = new UIPopupMenu();
popupMenu.setOnlyText(true);
popupMenu.setBackground(UIConstants.DEFAULT_BG_RULER);
popupMenu.add(new PopupMenuItem(new RenameAction()));
popupMenu.add(new PopupMenuItem(new RemoveAction()));
GUICoreUtils.showPopupMenu(popupMenu, UIHeaderPane.this, e.getX(), e.getY());
}
}
@Override
public void mousePressed(MouseEvent e) {
pressed = true;
}
@Override
public void mouseReleased(MouseEvent e) {
if (pressed && hover) {
dealClickAction(e);
}
pressed = false;
}
@Override
public void mouseEntered(MouseEvent e) {
hover = true;
}
@Override
public void mouseExited(MouseEvent e) {
hover = false;
}
};
public UIHeaderPane(String title, int headHeight) {
this.setLayout(new BorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(0, 10, 1, 2));
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane();
panel.setBackground(Color.decode("#EDEDEE"));
this.headHeight = headHeight;
arrow = new UILabel(downIcon);
arrow.setOpaque(false);
menuItem = createMenuItem();
titleLabel = new UILabel(title);
titleLabel.setOpaque(false);
JPanel leftPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
leftPanel.add(arrow);
leftPanel.add(titleLabel);
leftPanel.setOpaque(false);
panel.add(leftPanel, BorderLayout.CENTER);
if (group.isEditable()) {
panel.add(menuItem, BorderLayout.EAST);
}
add(panel, BorderLayout.CENTER);
addListener();
}
public void showExpand(boolean expend) {
Icon showIcon = expend ? downIcon : rightIcon;
arrow.setIcon(showIcon);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(this.getWidth(), headHeight);
}
@Override
public Dimension getSize() {
return new Dimension(this.getWidth(), headHeight);
}
public UILabel createMenuItem() {
UILabel label = new UILabel(IOUtils.readIcon("/com/fr/base/images/share/menu_item.png"));
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
UIPopupMenu popupMenu = new UIPopupMenu();
popupMenu.setOnlyText(true);
popupMenu.setBackground(UIConstants.DEFAULT_BG_RULER);
popupMenu.add(new PopupMenuItem(new RenameAction()));
popupMenu.add(new PopupMenuItem(new RemoveAction()));
GUICoreUtils.showPopupMenu(popupMenu, menuItem, 0, menuItem.getSize().height);
}
});
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
label.setOpaque(false);
return label;
}
protected void setMenuItemVisible(boolean visible) {
menuItem.setVisible(visible);
}
private void addListener() {
this.addMouseListener(mouseAdapter);
}
/**
* 由鼠标释放时调用该方法来触发左键点击事件
*/
private void dealClickAction(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
boolean isShow = contentPanel.isShowing();
contentPanel.setVisible(!isShow);
GroupPane.this.setExpendStatus(!isShow);
showExpand(!isShow);
getParent().validate();
getParent().repaint();
}
}
private class RenameAction extends UpdateAction {
public RenameAction() {
this.putValue(Action.SMALL_ICON, null);
this.setName(Toolkit.i18nText("Fine-Design_Share_Group_Rename"));
}
@Override
public void actionPerformed(ActionEvent e) {
new GroupFileDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Share_Group_Rename", group.getGroupName())) {
@Override
protected void confirmClose() {
this.dispose();
String groupName = getFileName().replaceAll("[\\\\/:*?\"<>|]", StringUtils.EMPTY);
if (DefaultShareGroupManager.getInstance().renameGroup(group, groupName)) {
titleLabel.setText(groupName);
repaint();
} else {
ShareUIUtils.showErrorMessageDialog(Toolkit.i18nText("Fine-Design_Share_Group_Rename_Failure"));
}
}
@Override
protected boolean isDuplicate(String fileName) {
return DefaultShareGroupManager.getInstance().exist(fileName);
}
};
}
}
private class RemoveAction extends UpdateAction {
public RemoveAction() {
this.putValue(Action.SMALL_ICON, null);
this.setName(Toolkit.i18nText("Fine-Design_Share_Group_Remove"));
}
@Override
public void actionPerformed(ActionEvent e) {
int rv = FineJOptionPane.showConfirmDialog(
DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Share_Group_Remove_Info"),
Toolkit.i18nText("Fine-Design_Share_Group_Confirm"),
FineJOptionPane.YES_NO_OPTION
);
if (rv == FineJOptionPane.YES_OPTION) {
if (DefaultShareGroupManager.getInstance().removeGroup(group)) {
LocalWidgetRepoPane.getInstance().removeGroup(group.getGroupName());
} else {
ShareUIUtils.showErrorMessageDialog(Toolkit.i18nText("Fine-Design_Share_Group_Remove_Failure"));
}
}
}
}
}
public enum GroupCreateStrategy {
DEFAULT {
@Override
public GroupPane creteGroupPane(Group group) {
return new GroupPane(group);
}
},
CLOSURE {
@Override
public GroupPane creteGroupPane(Group group) {
return new GroupPane(group, false);
}
};
abstract public GroupPane creteGroupPane(Group group);
}
}

87
designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/LocalPaneStatus.java

@ -0,0 +1,87 @@
package com.fr.design.mainframe.share.ui.local;
import com.fr.base.BaseUtils;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.share.ui.base.LoadingPane;
import com.fr.design.mainframe.share.ui.base.NoMatchPane;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
/**
* @Author: Yuan.Wang
* @Date: 2020/12/1
*/
enum LocalPaneStatus {
//无匹配
NO_MATCH {
@Override
public JPanel getPanel() {
return new NoMatchPane();
}
},
//正常
NORMAL {
@Override
public JPanel getPanel() {
return new JPanel();
}
},
//空
EMPTY {
@Override
public JPanel getPanel() {
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane();
UILabel picLabel = new UILabel();
picLabel.setIcon(BaseUtils.readIcon("com/fr/base/images/share/empty.png"));
picLabel.setHorizontalAlignment(SwingConstants.CENTER);
panel.add(picLabel, BorderLayout.CENTER);
JPanel labelPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
UILabel topLabel = new UILabel(Toolkit.i18nText("Fine-Design_Share_Empty_First"), SwingConstants.CENTER);
topLabel.setForeground(Color.GRAY);
UILabel bottomLabel = new UILabel(Toolkit.i18nText("Fine-Design_Share_Empty_Second"), SwingConstants.CENTER);
bottomLabel.setForeground(Color.GRAY);
labelPanel.add(topLabel, BorderLayout.CENTER);
labelPanel.add(bottomLabel, BorderLayout.SOUTH);
labelPanel.setPreferredSize(new Dimension(240, 40));
panel.add(labelPanel, BorderLayout.SOUTH);
panel.setPreferredSize(new Dimension(240, 180));
JPanel emptyPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
emptyPanel.setBorder(BorderFactory.createEmptyBorder(100, 0, 0, 0));
emptyPanel.add(panel, BorderLayout.NORTH);
return emptyPanel;
}
},
//加载
LOADING {
@Override
public JPanel getPanel() {
return new LoadingPane();
}
},
//安装
INSTALLING {
@Override
public JPanel getPanel() {
return new LoadingPane(Toolkit.i18nText("Fine-Design_Share_installing"));
}
};
public abstract JPanel getPanel();
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save