From 2372920230fbf6e880b6732e816558e51e96f86f Mon Sep 17 00:00:00 2001 From: WeiYanglu Date: Sat, 10 Aug 2019 21:09:59 +0800 Subject: [PATCH 01/60] =?UTF-8?q?MOBILE-21673=20&=20MOBILE-21669=20?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=AB=AF=E6=8E=A7=E4=BB=B6=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=8C=96=E6=8E=A5=E5=8F=A3=E8=AE=BE=E8=AE=A1=E5=99=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/ExtraDesignClassManager.java | 22 ++- .../design/fun/MobileWidgetStyleProvider.java | 24 ++++ .../AbstractMobileWidgetStyleProvider.java | 20 +++ .../DefaultMobileStyleCustomDefinePane.java | 39 ++++++ .../ui/DefaultMobileWidgetStyleProvider.java | 30 ++++ .../ui/MobileStyleCustomDefinePane.java | 22 +++ .../mobile/ui/MobileStyleDefinePane.java | 115 ++++++++++++++++ .../mainframe/mobile/ui/MobileStylePane.java | 130 ++++++++++++++++++ .../AccessibleMobileStyleEditor.java | 36 +++++ .../widget/wrappers/MobileStyleWrapper.java | 26 ++++ .../design/designer/creator/XChartEditor.java | 5 + .../fr/design/designer/creator/XCreator.java | 9 +- .../design/designer/creator/XElementCase.java | 5 + .../designer/creator/XLayoutContainer.java | 5 + .../designer/creator/XWScaleLayout.java | 5 + .../mobile/MobileStylePropertyUI.java | 31 +++++ .../design/mainframe/WidgetPropertyPane.java | 7 +- .../mobile/MobileWidgetStyleDefinePane.java | 85 ++++++++++++ 18 files changed, 608 insertions(+), 8 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/fun/MobileWidgetStyleProvider.java create mode 100644 designer-base/src/main/java/com/fr/design/fun/impl/AbstractMobileWidgetStyleProvider.java create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/DefaultMobileStyleCustomDefinePane.java create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/DefaultMobileWidgetStyleProvider.java create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleCustomDefinePane.java create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleDefinePane.java create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStylePane.java create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleMobileStyleEditor.java create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/widget/wrappers/MobileStyleWrapper.java create mode 100644 designer-form/src/main/java/com/fr/design/designer/properties/mobile/MobileStylePropertyUI.java create mode 100644 designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/MobileWidgetStyleDefinePane.java diff --git a/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java b/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java index beb62c06e4..874a8f8b1c 100644 --- a/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java +++ b/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java @@ -6,18 +6,14 @@ package com.fr.design; import com.fr.base.BaseUtils; import com.fr.design.data.datapane.TableDataNameObjectCreator; -import com.fr.design.fun.CellWidgetOptionProvider; -import com.fr.design.fun.FormWidgetOptionProvider; -import com.fr.design.fun.ParameterWidgetOptionProvider; -import com.fr.design.fun.ServerTableDataDefineProvider; -import com.fr.design.fun.TableDataDefineProvider; -import com.fr.design.fun.ToolbarItemProvider; +import com.fr.design.fun.*; import com.fr.design.gui.core.WidgetOption; import com.fr.design.gui.core.WidgetOptionFactory; import com.fr.design.menu.ShortCut; import com.fr.design.widget.Appearance; import com.fr.design.widget.mobile.WidgetMobilePane; import com.fr.form.ui.Widget; +import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; import com.fr.plugin.AbstractExtraClassManager; import com.fr.plugin.injectable.PluginModule; @@ -207,6 +203,20 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement return map; } + public MobileWidgetStyleProvider[] getMobileStyleOfWidget(String xType) { + Set set = getArray(MobileWidgetStyleProvider.XML_TAG); + if (set.isEmpty()) { + return new MobileWidgetStyleProvider[0]; + } + List providers = new ArrayList<>(); + for (MobileWidgetStyleProvider provider: set) { + if(ComparatorUtils.equalsIgnoreCase(provider.xTypeForWidget(), xType)) { + providers.add(provider); + } + } + return providers.toArray(new MobileWidgetStyleProvider[providers.size()]); + } + @Override protected boolean demountSpecific(PluginSingleInjection injection) { diff --git a/designer-base/src/main/java/com/fr/design/fun/MobileWidgetStyleProvider.java b/designer-base/src/main/java/com/fr/design/fun/MobileWidgetStyleProvider.java new file mode 100644 index 0000000000..bc01837ee7 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/MobileWidgetStyleProvider.java @@ -0,0 +1,24 @@ +package com.fr.design.fun; + +import com.fr.design.mainframe.mobile.ui.MobileStyleCustomDefinePane; +import com.fr.form.ui.mobile.MobileStyle; +import com.fr.stable.fun.mark.Mutable; + +/** + * 移动端组件样式扩展接口 + */ +public interface MobileWidgetStyleProvider extends Mutable { + + String XML_TAG = "MobileWidgetStyleProvider"; + + int CURRENT_LEVEL = 1; + + Class classForMobileStyle(); + + Class classForWidgetAppearance(); + + String xTypeForWidget(); + + String displayName(); + +} diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractMobileWidgetStyleProvider.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractMobileWidgetStyleProvider.java new file mode 100644 index 0000000000..407aa058c7 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractMobileWidgetStyleProvider.java @@ -0,0 +1,20 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.MobileWidgetStyleProvider; +import com.fr.stable.fun.impl.AbstractProvider; +import com.fr.stable.fun.mark.API; + +@API(level = MobileWidgetStyleProvider.CURRENT_LEVEL) +public abstract class AbstractMobileWidgetStyleProvider extends AbstractProvider implements MobileWidgetStyleProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public String mark4Provider() { + return getClass().getName(); + } + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/DefaultMobileStyleCustomDefinePane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/DefaultMobileStyleCustomDefinePane.java new file mode 100644 index 0000000000..62257fde53 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/DefaultMobileStyleCustomDefinePane.java @@ -0,0 +1,39 @@ +package com.fr.design.mainframe.mobile.ui; + +import com.fr.form.ui.Widget; +import com.fr.form.ui.mobile.MobileStyle; + +import javax.swing.*; + +public class DefaultMobileStyleCustomDefinePane extends MobileStyleCustomDefinePane { + + + public DefaultMobileStyleCustomDefinePane(Widget widget) { + super(widget); + } + + @Override + protected JPanel createPreviewPane() { + return null; + } + + @Override + public void populateBean(MobileStyle ob) { + + } + + @Override + public MobileStyle updateBean() { + return null; + } + + @Override + protected String title4PopupWindow() { + return null; + } + + @Override + protected void init() { + + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/DefaultMobileWidgetStyleProvider.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/DefaultMobileWidgetStyleProvider.java new file mode 100644 index 0000000000..b1710ff14d --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/DefaultMobileWidgetStyleProvider.java @@ -0,0 +1,30 @@ +package com.fr.design.mainframe.mobile.ui; + +import com.fr.design.fun.impl.AbstractMobileWidgetStyleProvider; +import com.fr.form.ui.mobile.DefaultMobileStyle; +import com.fr.form.ui.mobile.MobileStyle; +import com.fr.locale.InterProviderFactory; + +public class DefaultMobileWidgetStyleProvider extends AbstractMobileWidgetStyleProvider { + + @Override + public Class classForMobileStyle() { + return DefaultMobileStyle.class; + } + + @Override + public Class classForWidgetAppearance() { + return DefaultMobileStyleCustomDefinePane.class; + } + + @Override + public String xTypeForWidget() { + return null; + } + + @Override + public String displayName() { + return InterProviderFactory.getProvider().getLocText("Fine-Engine_Report_DEFAULT"); + } + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleCustomDefinePane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleCustomDefinePane.java new file mode 100644 index 0000000000..91729eb96d --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleCustomDefinePane.java @@ -0,0 +1,22 @@ +package com.fr.design.mainframe.mobile.ui; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.form.ui.Widget; +import com.fr.form.ui.mobile.MobileStyle; + +import javax.swing.*; + +public abstract class MobileStyleCustomDefinePane extends BasicBeanPane { + + protected Widget widget; + + public MobileStyleCustomDefinePane(Widget widget) { + this.widget = widget; + init(); + } + + protected abstract JPanel createPreviewPane(); + + protected abstract void init(); + +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleDefinePane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleDefinePane.java new file mode 100644 index 0000000000..ef1327ccfc --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleDefinePane.java @@ -0,0 +1,115 @@ +package com.fr.design.mainframe.mobile.ui; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.style.color.NewColorSelectBox; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.form.ui.Widget; +import com.fr.form.ui.mobile.MobileStyle; +import com.fr.general.FRFont; +import com.fr.invoke.Reflect; + +import javax.swing.*; +import javax.swing.border.TitledBorder; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; + +public class MobileStyleDefinePane extends BasicBeanPane { + + private Widget widget; + private MobileStyleCustomDefinePane customBeanPane; + private Class mobileStyleClazz; + private NewColorSelectBox colorSelectBox; + + MobileStyleDefinePane(Widget widget, Class customBeanPaneClass, + Class mobileStyleClazz) { + this.widget = widget; + this.customBeanPane = Reflect.on(customBeanPaneClass).create(widget).get(); + this.mobileStyleClazz = mobileStyleClazz; + init(); + } + + @Override + public void populateBean(MobileStyle ob) { + this.customBeanPane.populateBean(ob); + colorSelectBox.setSelectObject(ob.getBackground()); + } + + @Override + public MobileStyle updateBean() { + MobileStyle mobileStyle = Reflect.on(mobileStyleClazz).create().get(); + this.widget.setMobileStyle(mobileStyle); + this.customBeanPane.updateBean(); + mobileStyle.setBackground(colorSelectBox.getBackground()); + return mobileStyle; + } + + @Override + protected String title4PopupWindow() { + return null; + } + + private void init() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + createGeneralPane(); + createCustomPane(); + } + + private void createGeneralPane() { + createPreviewPane(); + createBackgroundPane(); + } + + private void createPreviewPane() { + JPanel mobileStylePreviewPane = this.customBeanPane.createPreviewPane(); + if(mobileStylePreviewPane != null) { + JPanel previewPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + TitledBorder titledBorder = GUICoreUtils.createTitledBorder(Toolkit.i18nText("Fine-Design_Basic_Widget_Style_Preview"), null); + titledBorder.setTitleFont(FRFont.getInstance("PingFangSC-Regular", Font.PLAIN, 12, new Color(0x2f8ef100))); + previewPane.setBorder(titledBorder); + previewPane.setPreferredSize(new Dimension(500, 83)); + previewPane.add(mobileStylePreviewPane, BorderLayout.CENTER); + this.add(previewPane, BorderLayout.NORTH); + } + } + + private void createBackgroundPane() { + + JPanel backgroundPane = new JPanel(); + backgroundPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 5)); + backgroundPane.setPreferredSize(new Dimension(500, 65)); + + TitledBorder titledBorder = GUICoreUtils.createTitledBorder(Toolkit.i18nText("Fine-Design_Mobile_Common_Attribute"), null); + titledBorder.setTitleFont(FRFont.getInstance("PingFangSC-Regular", Font.PLAIN, 12, Color.BLUE)); + backgroundPane.setBorder(titledBorder); + + UILabel colorSelectLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Mobile_Widget_Background"), UILabel.RIGHT); + colorSelectLabel.setPreferredSize(new Dimension(65, 20)); + + colorSelectBox = new NewColorSelectBox(152); + colorSelectBox.addSelectChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + } + }); + + backgroundPane.add(colorSelectLabel); + backgroundPane.add(colorSelectBox); + + this.add(backgroundPane, BorderLayout.NORTH); + } + + private void createCustomPane() { + JPanel configPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + TitledBorder titledBorder = GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Set"), null); + titledBorder.setTitleFont(FRFont.getInstance("PingFangSC-Regular", Font.PLAIN, 12, Color.BLUE)); + configPane.setBorder(titledBorder); + + configPane.add(this.customBeanPane, BorderLayout.CENTER); + + this.add(configPane, BorderLayout.CENTER); + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStylePane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStylePane.java new file mode 100644 index 0000000000..c048c0d214 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStylePane.java @@ -0,0 +1,130 @@ +package com.fr.design.mainframe.mobile.ui; + +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.dialog.BasicPane; +import com.fr.design.fun.MobileWidgetStyleProvider; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.form.ui.Widget; +import com.fr.form.ui.mobile.MobileStyle; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.ArrayUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.HashMap; +import java.util.Map; + +public class MobileStylePane extends BasicPane { + + private Widget widget; + private DefaultListModel listModel; + private JPanel right; + private CardLayout card; + private JList styleList; + private Map> map = new HashMap<>(); + + public MobileStylePane(Widget widget) { + this.widget = widget; + init(); + } + + @Override + protected String title4PopupWindow() { + return null; + } + + public void populate(MobileStyle mobileStyle) { + if(mobileStyle != null) { + MobileWidgetStyleProvider[] styleProviders = getMobileWidgetStyleProviders(); + for(int i = 0; i < styleProviders.length; i ++) { + if(mobileStyle.getClass() == styleProviders[i].classForMobileStyle()) { + String displayName = styleProviders[i].displayName(); + styleList.setSelectedIndex(i); + map.get(displayName).populateBean(mobileStyle); + card.show(right, displayName); + return; + } + } + } + styleList.setSelectedIndex(0); + } + + public MobileStyle update() { + return map.get(styleList.getSelectedValue()).updateBean(); + } + + private void init() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + listModel = new DefaultListModel<>(); + card = new CardLayout(); + right = FRGUIPaneFactory.createCardLayout_S_Pane(); + right.setLayout(card); + MobileWidgetStyleProvider[] styleProviders = getMobileWidgetStyleProviders(); + for(MobileWidgetStyleProvider styleProvider: styleProviders) { + this.addProvider2View(styleProvider); + } + this.addWestList(); + this.addCenterConfig(); + } + + private void addWestList() { + styleList = new JList<>(listModel); + styleList.setCellRenderer(render); + styleList.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + String selectedValue = (String)styleList.getSelectedValue(); + card.show(right, selectedValue); + } + }); + JPanel westPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + westPane.add(styleList, BorderLayout.CENTER); + westPane.setPreferredSize(new Dimension(100, 500)); + this.add(westPane, BorderLayout.WEST); + } + + private void addCenterConfig() { + JPanel centerPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + JPanel attrConfPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + centerPane.setPreferredSize(new Dimension(500, 500)); + attrConfPane.add(right, BorderLayout.CENTER); + centerPane.add(attrConfPane, BorderLayout.CENTER); + this.add(centerPane, BorderLayout.CENTER); + } + + private void addProvider2View(MobileWidgetStyleProvider styleProvider) { + String displayName = styleProvider.displayName(); + Class appearanceClazz = styleProvider.classForWidgetAppearance(); + Class mobileStyleClazz = styleProvider.classForMobileStyle(); + + listModel.addElement(displayName); + try { + BasicBeanPane mobileStyleBasicBeanPane = new MobileStyleDefinePane(widget, appearanceClazz, mobileStyleClazz); + right.add(displayName, mobileStyleBasicBeanPane); + map.put(displayName, mobileStyleBasicBeanPane); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + + private static ListCellRenderer render = new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof MobileStyle) { + MobileStyle l = (MobileStyle) value; + this.setText(l.toString()); + } + return this; + } + }; + + private MobileWidgetStyleProvider[] getMobileWidgetStyleProviders() { + DefaultMobileWidgetStyleProvider defaultMobileWidgetStyleProvider = new DefaultMobileWidgetStyleProvider(); + MobileWidgetStyleProvider[] styleProviders = ExtraDesignClassManager.getInstance().getMobileStyleOfWidget(widget.getXType()); + styleProviders = ArrayUtils.insert(0, styleProviders, defaultMobileWidgetStyleProvider); + return styleProviders; + } +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleMobileStyleEditor.java b/designer-base/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleMobileStyleEditor.java new file mode 100644 index 0000000000..e18e8e49dd --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleMobileStyleEditor.java @@ -0,0 +1,36 @@ +package com.fr.design.mainframe.widget.accessibles; + +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.mainframe.mobile.ui.MobileStylePane; +import com.fr.design.mainframe.widget.wrappers.MobileStyleWrapper; +import com.fr.form.ui.mobile.MobileStyle; + +import javax.swing.SwingUtilities; +import java.awt.Dimension; + +public class AccessibleMobileStyleEditor extends UneditableAccessibleEditor { + + private MobileStylePane stylePane; + private static final Dimension DEFAULT_DIMENSION = new Dimension(600, 400); + + public AccessibleMobileStyleEditor(MobileStylePane stylePane) { + super(new MobileStyleWrapper()); + this.stylePane = stylePane; + } + + @Override + protected void showEditorPane() { + stylePane.setPreferredSize(DEFAULT_DIMENSION); + BasicDialog dlg = stylePane.showWindow(SwingUtilities.getWindowAncestor(this)); + dlg.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + setValue(stylePane.update()); + fireStateChanged(); + } + }); + stylePane.populate((MobileStyle) getValue()); + dlg.setVisible(true); + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/widget/wrappers/MobileStyleWrapper.java b/designer-base/src/main/java/com/fr/design/mainframe/widget/wrappers/MobileStyleWrapper.java new file mode 100644 index 0000000000..a8ceb7c46b --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/widget/wrappers/MobileStyleWrapper.java @@ -0,0 +1,26 @@ +package com.fr.design.mainframe.widget.wrappers; + +import com.fr.design.Exception.ValidationException; +import com.fr.design.designer.properties.Decoder; +import com.fr.design.designer.properties.Encoder; +import com.fr.locale.InterProviderFactory; + +public class MobileStyleWrapper implements Encoder, Decoder { + @Override + public Object decode(String txt) { + return null; + } + + @Override + public void validate(String txt) throws ValidationException { + + } + + @Override + public String encode(Object v) { + if (v == null) { + return InterProviderFactory.getProvider().getLocText("Fine-Engine_Report_DEFAULT"); + } + return v.toString(); + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java b/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java index 29ce253f56..14a5e3c969 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java @@ -339,4 +339,9 @@ public class XChartEditor extends XBorderStyleWidgetCreator { public boolean isSupportShared() { return true; } + + @Override + public boolean supportMobileStyle() { + return false; + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java index b7d7b3a45d..bef18f96f0 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java @@ -3,7 +3,6 @@ */ package com.fr.design.designer.creator; -import com.fr.base.BaseUtils; import com.fr.base.GraphHelper; import com.fr.base.vcs.DesignerMode; import com.fr.design.actions.UpdateAction; @@ -591,6 +590,14 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo return; } + /** + * 是否支持定义移动端样式,默认true + * @return 是否支持定义移动端样式 + */ + public boolean supportMobileStyle() { + return true; + } + /** * 获取当前组件自定义的属性表tab * diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java b/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java index 480412287e..ec06a1597d 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java @@ -121,6 +121,11 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme return ArrayUtils.add(extraTableEditor, reportFitEditor); } + @Override + public boolean supportMobileStyle() { + return false; + } + private CRPropertyDescriptor getReportFitEditor() { this.designer = WidgetPropertyPane.getInstance().getEditingFormDesigner(); FitProvider wbTpl = designer.getTarget(); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java b/designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java index 45764e7464..9044d6c3cd 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XLayoutContainer.java @@ -572,4 +572,9 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme return false; } + @Override + public boolean supportMobileStyle() { + return false; + } + } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWScaleLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWScaleLayout.java index 1db5e40451..5225a3b4fe 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWScaleLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XWScaleLayout.java @@ -179,4 +179,9 @@ public class XWScaleLayout extends DedicateLayoutContainer { } return super.getWidgetPropertyUIProviders(); } + + @Override + public boolean supportMobileStyle() { + return true; + } } \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/designer/properties/mobile/MobileStylePropertyUI.java b/designer-form/src/main/java/com/fr/design/designer/properties/mobile/MobileStylePropertyUI.java new file mode 100644 index 0000000000..1f52694b83 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/properties/mobile/MobileStylePropertyUI.java @@ -0,0 +1,31 @@ +package com.fr.design.designer.properties.mobile; + +import com.fr.design.designer.creator.XCreator; +import com.fr.design.dialog.BasicPane; +import com.fr.design.fun.impl.AbstractWidgetPropertyUIProvider; +import com.fr.design.gui.itable.AbstractPropertyTable; +import com.fr.design.widget.ui.designer.mobile.MobileWidgetStyleDefinePane; + +public class MobileStylePropertyUI extends AbstractWidgetPropertyUIProvider { + + private XCreator xCreator; + + public MobileStylePropertyUI(XCreator xCreator) { + this.xCreator = xCreator; + } + + @Override + public AbstractPropertyTable createWidgetAttrTable() { + return null; + } + + @Override + public BasicPane createWidgetAttrPane() { + return new MobileWidgetStyleDefinePane(xCreator); + } + + @Override + public String tableTitle() { + return null; + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java b/designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java index af17389be0..8195fbb50c 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java @@ -7,6 +7,7 @@ import com.fr.design.designer.beans.events.DesignerEditListener; import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.creator.*; import com.fr.design.designer.properties.EventPropertyTable; +import com.fr.design.designer.properties.mobile.MobileStylePropertyUI; import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.gui.ibutton.UIHeadGroup; import com.fr.design.gui.icontainer.UIScrollPane; @@ -172,8 +173,12 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper private WidgetPropertyUIProvider[] getExtraPropertyUIProviders() { FormSelection selection = designer.getSelectionModel().getSelection(); WidgetPropertyUIProvider[] embeddedPropertyUIProviders = null; - if (selection != null && selection.getSelectedCreator() != null) { + XCreator xCreator = selection.getSelectedCreator(); + if (selection != null && xCreator != null) { embeddedPropertyUIProviders = selection.getSelectedCreator().getWidgetPropertyUIProviders(); + if(!designer.getDesignerMode().isFormParameterEditor() && xCreator.supportMobileStyle()) { + embeddedPropertyUIProviders = ArrayUtils.insert(0, embeddedPropertyUIProviders, new MobileStylePropertyUI(xCreator)); + } } Set set = ExtraDesignClassManager.getInstance().getArray(WidgetPropertyUIProvider.XML_TAG); return ArrayUtils.addAll(embeddedPropertyUIProviders, set.toArray(new WidgetPropertyUIProvider[set.size()])); diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/MobileWidgetStyleDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/MobileWidgetStyleDefinePane.java new file mode 100644 index 0000000000..fb6f81fe58 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/MobileWidgetStyleDefinePane.java @@ -0,0 +1,85 @@ +package com.fr.design.widget.ui.designer.mobile; + +import com.fr.design.constants.LayoutConstants; +import com.fr.design.designer.IntervalConstants; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.gui.frpane.AttributeChangeListener; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.widget.accessibles.AccessibleMobileStyleEditor; +import com.fr.design.mainframe.mobile.ui.MobileStylePane; +import com.fr.form.ui.mobile.MobileStyle; + +import javax.swing.*; +import java.awt.*; + +public class MobileWidgetStyleDefinePane extends MobileWidgetDefinePane { + + private XCreator xCreator; + private AccessibleMobileStyleEditor mobileStyleEditor; + private AttributeChangeListener changeListener; + + public MobileWidgetStyleDefinePane(XCreator xCreator) { + this.xCreator = xCreator; + } + + @Override + public void setPreferredSize(Dimension dimension) { + super.setPreferredSize(dimension); + } + + @Override + public void initPropertyGroups(Object source) { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Tab_Style_Template")); + mobileStyleEditor = new AccessibleMobileStyleEditor(new MobileStylePane(this.xCreator.toData())); + JPanel jPanel = TableLayoutHelper.createGapTableLayoutPane( + new Component[][]{new Component[]{label, mobileStyleEditor}}, + TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_L1, LayoutConstants.VGAP_LARGE + ); + JPanel holder = FRGUIPaneFactory.createBorderLayout_S_Pane(); + holder.add(jPanel, BorderLayout.NORTH); + + this.add(holder, BorderLayout.NORTH); + } + + @Override + public void populate(FormDesigner designer) { + mobileStyleEditor.setValue(xCreator.toData().getMobileStyle()); + this.bindListeners2Widgets(); + this.addAttributeChangeListener(changeListener); + } + + @Override + public void update() { + xCreator.toData().setMobileStyle((MobileStyle) mobileStyleEditor.getValue()); + DesignerContext.getDesignerFrame().getSelectedJTemplate().fireTargetModified(); + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, 30); + } + + @Override + public Dimension getMaximumSize() { + return new Dimension(400, 200); + } + + private void bindListeners2Widgets() { + reInitAllListeners(); + this.changeListener = new AttributeChangeListener() { + @Override + public void attributeChange() { + update(); + } + }; + } + + private void reInitAllListeners() { + initListener(this); + } +} From 2d8fef4603267b7a10e17ebb7ad35f6b7311440e Mon Sep 17 00:00:00 2001 From: WeiYanglu Date: Sun, 11 Aug 2019 02:05:27 +0800 Subject: [PATCH 02/60] =?UTF-8?q?=E6=97=A5=E5=8E=86=E3=80=81=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E6=A1=86=E7=AD=89=E5=85=A8=E8=A2=ABScale=E5=8C=85?= =?UTF-8?q?=E4=BD=8F=E4=BA=86=EF=BC=8C=E8=AE=BE=E7=BD=AE=E6=88=90=E7=9C=9F?= =?UTF-8?q?=E5=AE=9E=E7=9A=84=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/mobile/ui/MobileStylePane.java | 8 +++++++- .../designer/properties/mobile/MobileStylePropertyUI.java | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStylePane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStylePane.java index c048c0d214..d0e949fa9c 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStylePane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStylePane.java @@ -6,7 +6,9 @@ import com.fr.design.dialog.BasicPane; import com.fr.design.fun.MobileWidgetStyleProvider; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.form.ui.Widget; +import com.fr.form.ui.container.WScaleLayout; import com.fr.form.ui.mobile.MobileStyle; +import com.fr.form.ui.widget.CRBoundsWidget; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; @@ -27,7 +29,11 @@ public class MobileStylePane extends BasicPane { private Map> map = new HashMap<>(); public MobileStylePane(Widget widget) { - this.widget = widget; + if(widget instanceof WScaleLayout) { + this.widget = ((CRBoundsWidget)((WScaleLayout) widget).getBoundsWidget()).getWidget(); + } else { + this.widget = widget; + } init(); } diff --git a/designer-form/src/main/java/com/fr/design/designer/properties/mobile/MobileStylePropertyUI.java b/designer-form/src/main/java/com/fr/design/designer/properties/mobile/MobileStylePropertyUI.java index 1f52694b83..831f558cb1 100644 --- a/designer-form/src/main/java/com/fr/design/designer/properties/mobile/MobileStylePropertyUI.java +++ b/designer-form/src/main/java/com/fr/design/designer/properties/mobile/MobileStylePropertyUI.java @@ -1,6 +1,7 @@ package com.fr.design.designer.properties.mobile; import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XWScaleLayout; import com.fr.design.dialog.BasicPane; import com.fr.design.fun.impl.AbstractWidgetPropertyUIProvider; import com.fr.design.gui.itable.AbstractPropertyTable; @@ -11,7 +12,11 @@ public class MobileStylePropertyUI extends AbstractWidgetPropertyUIProvider { private XCreator xCreator; public MobileStylePropertyUI(XCreator xCreator) { - this.xCreator = xCreator; + if(xCreator instanceof XWScaleLayout) { + this.xCreator = xCreator.getEditingChildCreator(); + } else { + this.xCreator = xCreator; + } } @Override From 205d3149b26a0494494fc0d223558469472e85df Mon Sep 17 00:00:00 2001 From: WeiYanglu Date: Tue, 13 Aug 2019 00:00:55 +0800 Subject: [PATCH 03/60] =?UTF-8?q?MOBILE-21673=20&=20MOBILE-21669=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E5=A4=84=E9=A2=9C=E8=89=B2=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=A1=86=E8=AF=BB=E5=8F=96=E5=80=BC=E6=97=B6=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=BD=BF=E7=94=A8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/mobile/ui/MobileStyleDefinePane.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleDefinePane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleDefinePane.java index ef1327ccfc..82e1899434 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleDefinePane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileStyleDefinePane.java @@ -43,7 +43,7 @@ public class MobileStyleDefinePane extends BasicBeanPane { MobileStyle mobileStyle = Reflect.on(mobileStyleClazz).create().get(); this.widget.setMobileStyle(mobileStyle); this.customBeanPane.updateBean(); - mobileStyle.setBackground(colorSelectBox.getBackground()); + mobileStyle.setBackground(colorSelectBox.getSelectObject()); return mobileStyle; } From bc5f6a6cf3bb4e06ecc2e49aa5f50af57ed5ac1c Mon Sep 17 00:00:00 2001 From: Hades Date: Tue, 13 Aug 2019 11:53:17 +0800 Subject: [PATCH 04/60] =?UTF-8?q?REPORT-19465=20=E3=80=90=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=A7=BB=E5=8A=A8=E7=AB=AF=E3=80=91=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=BA=A7=E5=85=A8=E5=B1=80=E6=8E=A7=E5=88=B6=E7=BC=A9=E6=94=BE?= =?UTF-8?q?=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/form/mobile/FormMobileOthersPane.java | 5 +++++ .../java/com/fr/design/report/mobile/MobileOthersPane.java | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/designer-form/src/main/java/com/fr/design/form/mobile/FormMobileOthersPane.java b/designer-form/src/main/java/com/fr/design/form/mobile/FormMobileOthersPane.java index 03499286d7..60cc6d21f0 100644 --- a/designer-form/src/main/java/com/fr/design/form/mobile/FormMobileOthersPane.java +++ b/designer-form/src/main/java/com/fr/design/form/mobile/FormMobileOthersPane.java @@ -18,6 +18,7 @@ public class FormMobileOthersPane extends BasicBeanPane { private MobileRadioCheckPane appearRefreshCheckPane; // 页面再现时刷新 private MobileRadioCheckPane promptWhenLeaveWithoutSubmitCheckPane; // 数据未提交离开提示 + private MobileRadioCheckPane allowDoubleClickOrZoomCheckPane; // 允许双击/双指缩放 public FormMobileOthersPane() { this.initComponents(); @@ -32,6 +33,8 @@ public class FormMobileOthersPane extends BasicBeanPane { contentPane.add(appearRefreshCheckPane, BorderLayout.WEST); promptWhenLeaveWithoutSubmitCheckPane = new MobileRadioCheckPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Prompt_When_Leave_Without_Submit")); contentPane.add(promptWhenLeaveWithoutSubmitCheckPane, BorderLayout.CENTER); + allowDoubleClickOrZoomCheckPane = new MobileRadioCheckPane(com.fr.design.i18n.Toolkit.i18nText("允许双击/双指缩放")); + contentPane.add(allowDoubleClickOrZoomCheckPane, BorderLayout.EAST); borderPane.add(contentPane); this.add(borderPane); } @@ -43,6 +46,7 @@ public class FormMobileOthersPane extends BasicBeanPane { } this.appearRefreshCheckPane.populateBean(ob.isAppearRefresh()); this.promptWhenLeaveWithoutSubmitCheckPane.populateBean(ob.isPromptWhenLeaveWithoutSubmit()); + this.allowDoubleClickOrZoomCheckPane.populateBean(ob.isAllowDoubleClickOrZoom()); } @Override @@ -55,6 +59,7 @@ public class FormMobileOthersPane extends BasicBeanPane { if(mobileAttr != null) { mobileAttr.setAppearRefresh(this.appearRefreshCheckPane.updateBean()); mobileAttr.setPromptWhenLeaveWithoutSubmit(this.promptWhenLeaveWithoutSubmitCheckPane.updateBean()); + mobileAttr.setAllowDoubleClickOrZoom(this.allowDoubleClickOrZoomCheckPane.updateBean()); } } diff --git a/designer-realize/src/main/java/com/fr/design/report/mobile/MobileOthersPane.java b/designer-realize/src/main/java/com/fr/design/report/mobile/MobileOthersPane.java index 35c7da06d4..4f88dcaef2 100644 --- a/designer-realize/src/main/java/com/fr/design/report/mobile/MobileOthersPane.java +++ b/designer-realize/src/main/java/com/fr/design/report/mobile/MobileOthersPane.java @@ -18,6 +18,9 @@ public class MobileOthersPane extends BasicBeanPane { private MobileRadioCheckPane appearRefreshCheckPane; // 页面再现时刷新 + // 允许双击/双指缩放 + private MobileRadioCheckPane allowDoubleClickOrZoomCheckPane; + public MobileOthersPane() { this.initComponents(); } @@ -29,6 +32,8 @@ public class MobileOthersPane extends BasicBeanPane { contentPane.setBorder(BorderFactory.createEmptyBorder(0, IntervalConstants.INTERVAL_L1, 0, 0)); appearRefreshCheckPane = new MobileRadioCheckPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Appear_Refresh")); contentPane.add(appearRefreshCheckPane, BorderLayout.WEST); + allowDoubleClickOrZoomCheckPane = new MobileRadioCheckPane(com.fr.design.i18n.Toolkit.i18nText("允许双击/双指缩放")); + contentPane.add(allowDoubleClickOrZoomCheckPane, BorderLayout.CENTER); borderPane.add(contentPane); this.add(borderPane); } @@ -39,6 +44,7 @@ public class MobileOthersPane extends BasicBeanPane { ob = new ElementCaseMobileAttr(); } this.appearRefreshCheckPane.populateBean(ob.isAppearRefresh()); + this.allowDoubleClickOrZoomCheckPane.populateBean(ob.isAllowDoubleClickOrZoom()); } @Override @@ -50,6 +56,7 @@ public class MobileOthersPane extends BasicBeanPane { public void updateBean(ElementCaseMobileAttr mobileAttr) { if(mobileAttr != null) { mobileAttr.setAppearRefresh(this.appearRefreshCheckPane.updateBean()); + mobileAttr.setAllowDoubleClickOrZoom(this.allowDoubleClickOrZoomCheckPane.updateBean()); } } From f5400dd00ac9f03519ba46a563b952435b6fd2ce Mon Sep 17 00:00:00 2001 From: Hades Date: Wed, 14 Aug 2019 10:51:45 +0800 Subject: [PATCH 05/60] =?UTF-8?q?REPORT-19468=20=E3=80=90=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=A7=BB=E5=8A=A8=E7=AB=AF=E3=80=91H5=E8=B6=85?= =?UTF-8?q?=E9=93=BE=E6=A0=87=E9=A2=98=E6=98=BE=E7=A4=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/designer/creator/XWBorderLayout.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWBorderLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWBorderLayout.java index a7b74d0fd9..ff67634e4e 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWBorderLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XWBorderLayout.java @@ -42,6 +42,7 @@ public class XWBorderLayout extends XLayoutContainer { * 默认名称 * @return 名称 */ + @Override public String createDefaultName() { return "border"; } @@ -50,6 +51,7 @@ public class XWBorderLayout extends XLayoutContainer { * 转化成相应 WBorderLayout * @return 相应 WBorderLayout */ + @Override public WBorderLayout toData() { return (WBorderLayout) data; } @@ -62,6 +64,7 @@ public class XWBorderLayout extends XLayoutContainer { * 初始大小 * @return 初始大小 */ + @Override public Dimension initEditorSize() { return new Dimension(WBorderLayout.DEFAULT_WIDTH, WBorderLayout.DEFAULT_HEIGHT); } @@ -71,15 +74,18 @@ public class XWBorderLayout extends XLayoutContainer { * @return 属性名 * @throws java.beans.IntrospectionException 抛错 */ + @Override public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { return new CRPropertyDescriptor[] { - new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Toolkit.i18nText("Fine-Design_Form_Form_Widget_Name")) + new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Toolkit.i18nText("Fine-Design_Form_Form_Widget_Name")), + new CRPropertyDescriptor("customTitleName", this.data.getClass()).setI18NName(Toolkit.i18nText("Fine-Design_Form_Title")) }; } /** * 将WLayout转换为XLayoutContainer */ + @Override public void convert() { isRefreshing = true; WBorderLayout wb = this.toData(); @@ -101,6 +107,7 @@ public class XWBorderLayout extends XLayoutContainer { * 设计界面中有组件添加时,要通知WLayout容器重新paint * @param e 事件 */ + @Override public void componentAdded(ContainerEvent e) { if (isRefreshing) { return; @@ -158,6 +165,7 @@ public class XWBorderLayout extends XLayoutContainer { /** * 重新计算大小 */ + @Override public void recalculateChildrenSize() { Dimension d = getSize(); WBorderLayout layout = toData(); @@ -173,6 +181,7 @@ public class XWBorderLayout extends XLayoutContainer { * @param comp 组件 * @param constraints 方位 */ + @Override public void add(Component comp, Object constraints) { super.add(comp, constraints); if (comp == null) { From ca4adb9a4aa5d41b34abcf50e543d1177a7d3354 Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 16 Aug 2019 14:23:50 +0800 Subject: [PATCH 06/60] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20?= =?UTF-8?q?=E5=BC=80=E6=94=BESDK=E5=AF=B9=E9=9C=80=E8=A6=81=E5=BC=80?= =?UTF-8?q?=E6=94=BE=E7=9A=84=E7=B1=BB=E7=9A=84=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../env/DesignerWorkspaceGenerator.java | 26 +-- .../com/fr/sdk/designer/FineDesignUtils.java | 160 +++++++++--------- 2 files changed, 93 insertions(+), 93 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java b/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java index 1174a8a73b..7494bba258 100644 --- a/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java +++ b/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java @@ -11,20 +11,20 @@ public class DesignerWorkspaceGenerator { public static Workspace generate(DesignerWorkspaceInfo config) throws Exception { - if (config == null || config.getType() == null) { - return null; - } + if (config == null || config.getType() == null) { + return null; + } - Workspace workspace = null; - switch (config.getType()) { - case Local: { - workspace = WorkContext.getFactory().build(config.getPath()); - break; - } - case Remote: { - WorkspaceClient client = WorkContext.getConnector().connect(config.getConnection()); - if (client != null) { - workspace = new RemoteWorkspace(client, config.getConnection()); + Workspace workspace = null; + switch (config.getType()) { + case Local: { + workspace = WorkContext.getFactory().build(config.getPath()); + break; + } + case Remote: { + WorkspaceClient client = WorkContext.getConnector().connect(config.getConnection()); + if (client != null) { + workspace = new RemoteWorkspace(client, config.getConnection()); } break; } diff --git a/designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java b/designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java index ea60edf74f..7de2f3c2d5 100644 --- a/designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java +++ b/designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java @@ -1,80 +1,80 @@ -package com.fr.sdk.designer; - -import com.fr.config.activator.ConfigurationActivator; -import com.fr.design.env.DesignerWorkspaceGenerator; -import com.fr.design.env.RemoteDesignerWorkspaceInfo; -import com.fr.log.FineLoggerFactory; -import com.fr.module.Activator; -import com.fr.module.Module; -import com.fr.module.tool.ActivatorToolBox; -import com.fr.report.ReportActivator; -import com.fr.report.RestrictionActivator; -import com.fr.report.module.ReportBaseActivator; -import com.fr.scheduler.SchedulerActivator; -import com.fr.sdk.server.shell.ModuleShell; -import com.fr.serialization.SerializationActivator; -import com.fr.stable.StringUtils; -import com.fr.startup.WorkspaceRegister; -import com.fr.store.StateServerActivator; -import com.fr.workspace.WorkContext; -import com.fr.workspace.connect.WorkspaceConnectionInfo; -import com.fr.workspace.engine.WorkspaceActivator; -import com.fr.workspace.server.ServerWorkspaceRegister; - -/** - * 设计器SDK模块工具类,用来放一些设计器相关插件开发过程中常用的工具函数 - */ -public class FineDesignUtils { - - /** - * 创建一个连接远程服务器的模块 - * @param remoteUrl 远程服务器地址 - * @param username 用户名 - * @param password 密码 - * @return 模块代理对象 使用ModuleShell的start和stop控制模块启停 - */ - public static ModuleShell createRemoteServerModule(String remoteUrl, String username, String password) { - return createRemoteServerModule(remoteUrl, username, password, StringUtils.EMPTY, StringUtils.EMPTY); - } - - /** - * 创建一个连接远程服务器的模块 - * @param remoteUrl 远程服务器地址 - * @param username 用户名 - * @param password 密码 - * @param certPath https证书路径 - * @param certSecretKey 证书秘钥 - * @return 模块代理对象 使用ModuleShell的start和stop控制模块启停 - */ - public static ModuleShell createRemoteServerModule(final String remoteUrl, final String username, final String password, final String certPath, final String certSecretKey) { - Module module = ActivatorToolBox.simpleLink( - new WorkspaceActivator(), - new SerializationActivator(), - new Activator() { - @Override - public void start() { - WorkspaceConnectionInfo connectionInfo = new WorkspaceConnectionInfo(remoteUrl, username, password, certPath, certSecretKey); - try { - WorkContext.switchTo(DesignerWorkspaceGenerator.generate(RemoteDesignerWorkspaceInfo.create(connectionInfo))); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(),e); - } - } - - @Override - public void stop() { - - } - }, - new ConfigurationActivator(), - new StateServerActivator(), - new SchedulerActivator(), - new ReportBaseActivator(), - new RestrictionActivator(), - new ReportActivator(), - new WorkspaceRegister(), - new ServerWorkspaceRegister() - ); - return new ModuleShell(module); - } -} \ No newline at end of file +//package com.fr.sdk.designer; +// +//import com.fr.config.activator.ConfigurationActivator; +//import com.fr.design.env.DesignerWorkspaceGenerator; +//import com.fr.design.env.RemoteDesignerWorkspaceInfo; +//import com.fr.log.FineLoggerFactory; +//import com.fr.module.Activator; +//import com.fr.module.Module; +//import com.fr.module.tool.ActivatorToolBox; +//import com.fr.report.ReportActivator; +//import com.fr.report.RestrictionActivator; +//import com.fr.report.module.ReportBaseActivator; +//import com.fr.scheduler.SchedulerActivator; +//import com.fr.sdk.server.shell.ModuleShell; +//import com.fr.serialization.SerializationActivator; +//import com.fr.stable.StringUtils; +//import com.fr.startup.WorkspaceRegister; +//import com.fr.store.StateServerActivator; +//import com.fr.workspace.WorkContext; +//import com.fr.workspace.connect.WorkspaceConnectionInfo; +//import com.fr.workspace.engine.WorkspaceActivator; +//import com.fr.workspace.server.ServerWorkspaceRegister; +// +///** +// * 设计器SDK模块工具类,用来放一些设计器相关插件开发过程中常用的工具函数 +// */ +//public class FineDesignUtils { +// +// /** +// * 创建一个连接远程服务器的模块 +// * @param remoteUrl 远程服务器地址 +// * @param username 用户名 +// * @param password 密码 +// * @return 模块代理对象 使用ModuleShell的start和stop控制模块启停 +// */ +// public static ModuleShell createRemoteServerModule(String remoteUrl, String username, String password) { +// return createRemoteServerModule(remoteUrl, username, password, StringUtils.EMPTY, StringUtils.EMPTY); +// } +// +// /** +// * 创建一个连接远程服务器的模块 +// * @param remoteUrl 远程服务器地址 +// * @param username 用户名 +// * @param password 密码 +// * @param certPath https证书路径 +// * @param certSecretKey 证书秘钥 +// * @return 模块代理对象 使用ModuleShell的start和stop控制模块启停 +// */ +// public static ModuleShell createRemoteServerModule(final String remoteUrl, final String username, final String password, final String certPath, final String certSecretKey) { +// Module module = ActivatorToolBox.simpleLink( +// new WorkspaceActivator(), +// new SerializationActivator(), +// new Activator() { +// @Override +// public void start() { +// WorkspaceConnectionInfo connectionInfo = new WorkspaceConnectionInfo(remoteUrl, username, password, certPath, certSecretKey); +// try { +// WorkContext.switchTo(DesignerWorkspaceGenerator.generate(RemoteDesignerWorkspaceInfo.create(connectionInfo))); +// } catch (Exception e) { +// FineLoggerFactory.getLogger().error(e.getMessage(),e); +// } +// } +// +// @Override +// public void stop() { +// +// } +// }, +// new ConfigurationActivator(), +// new StateServerActivator(), +// new SchedulerActivator(), +// new ReportBaseActivator(), +// new RestrictionActivator(), +// new ReportActivator(), +// new WorkspaceRegister(), +// new ServerWorkspaceRegister() +// ); +// return new ModuleShell(module); +// } +//} \ No newline at end of file From 9d0ac48c96d511c85fe1c246c47f8a78198916d7 Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 16 Aug 2019 14:25:10 +0800 Subject: [PATCH 07/60] =?UTF-8?q?=E8=AF=AF=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../env/DesignerWorkspaceGenerator.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java b/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java index 7494bba258..1174a8a73b 100644 --- a/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java +++ b/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java @@ -11,20 +11,20 @@ public class DesignerWorkspaceGenerator { public static Workspace generate(DesignerWorkspaceInfo config) throws Exception { - if (config == null || config.getType() == null) { - return null; - } + if (config == null || config.getType() == null) { + return null; + } - Workspace workspace = null; - switch (config.getType()) { - case Local: { - workspace = WorkContext.getFactory().build(config.getPath()); - break; - } - case Remote: { - WorkspaceClient client = WorkContext.getConnector().connect(config.getConnection()); - if (client != null) { - workspace = new RemoteWorkspace(client, config.getConnection()); + Workspace workspace = null; + switch (config.getType()) { + case Local: { + workspace = WorkContext.getFactory().build(config.getPath()); + break; + } + case Remote: { + WorkspaceClient client = WorkContext.getConnector().connect(config.getConnection()); + if (client != null) { + workspace = new RemoteWorkspace(client, config.getConnection()); } break; } From 27de4a0d2926047a4b6b728e36a5c94e86cc2cb9 Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Fri, 16 Aug 2019 16:46:23 +0800 Subject: [PATCH 08/60] =?UTF-8?q?REPORT-19466=20=E3=80=90=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=A7=BB=E5=8A=A8=E7=AB=AF=E3=80=91=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=BA=A7=E6=8E=A7=E5=88=B6=E9=80=89=E4=B8=AD=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/designer/mobile/ChartEditorDefinePane.java | 15 ++++++++++++--- .../ui/designer/mobile/ElementCaseDefinePane.java | 8 ++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ChartEditorDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ChartEditorDefinePane.java index b9ae12e208..258be7d1b5 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ChartEditorDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ChartEditorDefinePane.java @@ -48,6 +48,7 @@ public class ChartEditorDefinePane extends MobileWidgetDefinePane { private AttributeChangeListener changeListener; private UILabel tipLabel; private UICheckBox allowFullCheckBox;//允许全屏 + private UICheckBox functionalWhenUnactivatedCheckBox;//组件未激活时可使用组件内功能 public ChartEditorDefinePane(XCreator xCreator) { this.xCreator = xCreator; @@ -88,6 +89,8 @@ public class ChartEditorDefinePane extends MobileWidgetDefinePane { panel.add(unavailableTipLabel, BorderLayout.NORTH); allowFullCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Allow_Full_Screen")); panel.add(allowFullCheckBox); + functionalWhenUnactivatedCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Functional_When_Unactivated")); + panel.add(functionalWhenUnactivatedCheckBox); return panel; } @@ -98,19 +101,21 @@ public class ChartEditorDefinePane extends MobileWidgetDefinePane { tipLabel.setForeground(Color.gray); updateTipLabel(); allowFullCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Allow_Full_Screen")); + functionalWhenUnactivatedCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Functional_When_Unactivated")); Component[][] components = new Component[][]{ new Component[] {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Zoom_In_Logic"), SwingConstants.LEFT), new UILabel(ChartMobileFitAttrState.PROPORTION.description())}, new Component[] {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Zoom_Out_Logic"), SwingConstants.LEFT), zoomOutComboBox}, new Component[] {tipLabel, null}, - new Component[] {allowFullCheckBox} + new Component[] {allowFullCheckBox}, + new Component[] {functionalWhenUnactivatedCheckBox} }; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; - double[] rowSize = {p, p, p, p}; + double[] rowSize = {p, p, p, p, p}; double[] columnSize = {p,f}; - int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}}; + int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; final JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, 30, LayoutConstants.VGAP_LARGE); panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); final JPanel panelWrapper = FRGUIPaneFactory.createBorderLayout_S_Pane(); @@ -154,6 +159,8 @@ public class ChartEditorDefinePane extends MobileWidgetDefinePane { BaseChartEditor chartEditor = (BaseChartEditor)xCreator.toData(); boolean allowFullScreen = chartEditor.getMobileAttr().isAllowFullScreen(); this.allowFullCheckBox.setSelected(allowFullScreen); + boolean isFunctionalWhenUnactivated = chartEditor.getMobileAttr().isFunctionalWhenUnactivated(); + this.functionalWhenUnactivatedCheckBox.setSelected(isFunctionalWhenUnactivated); this.bindListeners2Widgets(); this.addAttributeChangeListener(changeListener); @@ -188,8 +195,10 @@ public class ChartEditorDefinePane extends MobileWidgetDefinePane { mobileAttr.setZoomInAttr(ChartMobileFitAttrState.PROPORTION); mobileAttr.setZoomOutAttr((ChartMobileFitAttrState) ((Item) zoomOutComboBox.getSelectedItem()).getValue()); mobileAttr.setAllowFullScreen(allowFullCheckBox.isSelected()); + mobileAttr.setFunctionalWhenUnactivated(functionalWhenUnactivatedCheckBox.isSelected()); }else { mobileAttr.setAllowFullScreen(allowFullCheckBox.isSelected()); + mobileAttr.setFunctionalWhenUnactivated(functionalWhenUnactivatedCheckBox.isSelected()); } DesignerContext.getDesignerFrame().getSelectedJTemplate().fireTargetModified(); // 触发设计器保存按钮亮起来 } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java index 9e833f0ae4..43f063f4ad 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java @@ -50,6 +50,7 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane{ private UISpinner maxHeightSpinner; // 最大高度Spinner private AttributeChangeListener changeListener; private UICheckBox allowFullCheckBox; + private UICheckBox functionalWhenUnactivatedCheckBox; public ElementCaseDefinePane (XCreator xCreator) { this.xCreator = xCreator; @@ -87,11 +88,14 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane{ allowFullCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Allow_Full_Screen")); + functionalWhenUnactivatedCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Functional_When_Unactivated")); + Component[][] components = new Component[][]{ new Component[] {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Mobile_Horizontal"), SwingConstants.LEFT), hComboBox}, new Component[] {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Mobile_Vertical"), SwingConstants.LEFT), vComboBox}, new Component[] {heightRestrictCheckBox, null}, new Component[] {allowFullCheckBox}, + new Component[] {functionalWhenUnactivatedCheckBox}, new Component[] {maxHeightLabel, maxHeightSpinner} }; double f = TableLayout.FILL; @@ -139,6 +143,7 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane{ this.maxHeightSpinner.setVisible(elementCaseEditor.isHeightRestrict()); this.maxHeightSpinner.setValue(elementCaseEditor.getHeightPercent()); this.allowFullCheckBox.setSelected(elementCaseEditor.isAllowFullScreen()); + this.functionalWhenUnactivatedCheckBox.setSelected(elementCaseEditor.isFunctionalWhenUnactivated()); } @Override @@ -163,6 +168,8 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane{ break; case "allowFullCheckBox": ((ElementCaseEditor)xCreator.toData()).setAllowFullScreen(allowFullCheckBox.isSelected()); + case "functionalWhenUnactivatedCheckBox": + ((ElementCaseEditor)xCreator.toData()).setAllowFullScreen(functionalWhenUnactivatedCheckBox.isSelected()); } } @@ -172,6 +179,7 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane{ this.heightRestrictCheckBox.setGlobalName("heightRestrictCheckBox"); this.maxHeightSpinner.setGlobalName("maxHeightSpinner"); this.allowFullCheckBox.setGlobalName("allowFullCheckBox"); + this.functionalWhenUnactivatedCheckBox.setGlobalName("functionalWhenUnactivatedCheckBox"); } } From 603d0d2c8202f327fb630a9afd9f2a8bcd3a9c32 Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Sat, 17 Aug 2019 12:13:09 +0800 Subject: [PATCH 09/60] =?UTF-8?q?REPORT-19466=20=E3=80=90=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=A7=BB=E5=8A=A8=E7=AB=AF=E3=80=91=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=BA=A7=E6=8E=A7=E5=88=B6=E9=80=89=E4=B8=AD=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mobile/ChartEditorDefinePane.java | 4 +-- .../mobile/ElementCaseDefinePane.java | 36 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ChartEditorDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ChartEditorDefinePane.java index 258be7d1b5..a91ebd7492 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ChartEditorDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ChartEditorDefinePane.java @@ -107,8 +107,8 @@ public class ChartEditorDefinePane extends MobileWidgetDefinePane { new Component[] {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Zoom_In_Logic"), SwingConstants.LEFT), new UILabel(ChartMobileFitAttrState.PROPORTION.description())}, new Component[] {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Zoom_Out_Logic"), SwingConstants.LEFT), zoomOutComboBox}, new Component[] {tipLabel, null}, - new Component[] {allowFullCheckBox}, - new Component[] {functionalWhenUnactivatedCheckBox} + new Component[] {allowFullCheckBox, null}, + new Component[] {functionalWhenUnactivatedCheckBox, null} }; double f = TableLayout.FILL; diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java index 43f063f4ad..5f255bb60f 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java @@ -29,10 +29,10 @@ import java.awt.Component; /** * 报表块-移动端属性面板 - * + *

* Created by fanglei on 2017/8/8. */ -public class ElementCaseDefinePane extends MobileWidgetDefinePane{ +public class ElementCaseDefinePane extends MobileWidgetDefinePane { private static final double MAX_HEIGHT_LIMIT = 0.8; private static final Item[] ITEMS = { new Item(MobileFitAttrState.HORIZONTAL.description(), MobileFitAttrState.HORIZONTAL), @@ -52,7 +52,7 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane{ private UICheckBox allowFullCheckBox; private UICheckBox functionalWhenUnactivatedCheckBox; - public ElementCaseDefinePane (XCreator xCreator) { + public ElementCaseDefinePane(XCreator xCreator) { this.xCreator = xCreator; } @@ -94,16 +94,16 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane{ new Component[] {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Mobile_Horizontal"), SwingConstants.LEFT), hComboBox}, new Component[] {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Mobile_Vertical"), SwingConstants.LEFT), vComboBox}, new Component[] {heightRestrictCheckBox, null}, - new Component[] {allowFullCheckBox}, - new Component[] {functionalWhenUnactivatedCheckBox}, + new Component[] {allowFullCheckBox, null}, + new Component[] {functionalWhenUnactivatedCheckBox, null}, new Component[] {maxHeightLabel, maxHeightSpinner} }; double f = TableLayout.FILL; double p = TableLayout.PREFERRED; - double[] rowSize = {p, p, p, p, p}; - double[] columnSize = {p,f}; - int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; - final JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, 30, LayoutConstants.VGAP_LARGE); + double[] rowSize = {p, p, p, p, p, p}; + double[] columnSize = {p, f}; + int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; + final JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, 30, LayoutConstants.VGAP_LARGE); panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); final JPanel panelWrapper = FRGUIPaneFactory.createBorderLayout_S_Pane(); panelWrapper.add(panel, BorderLayout.NORTH); @@ -135,9 +135,9 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane{ public void populate(FormDesigner designer) { this.designer = designer; this.addAttributeChangeListener(changeListener); - ElementCaseEditor elementCaseEditor = (ElementCaseEditor)xCreator.toData(); - this.hComboBox.setSelectedItem(new Item (elementCaseEditor.getHorziontalAttr().description(), elementCaseEditor.getHorziontalAttr())); - this.vComboBox.setSelectedItem(new Item (elementCaseEditor.getVerticalAttr().description(), elementCaseEditor.getVerticalAttr())); + ElementCaseEditor elementCaseEditor = (ElementCaseEditor) xCreator.toData(); + this.hComboBox.setSelectedItem(new Item(elementCaseEditor.getHorziontalAttr().description(), elementCaseEditor.getHorziontalAttr())); + this.vComboBox.setSelectedItem(new Item(elementCaseEditor.getVerticalAttr().description(), elementCaseEditor.getVerticalAttr())); this.heightRestrictCheckBox.setSelected(elementCaseEditor.isHeightRestrict()); this.maxHeightLabel.setVisible(elementCaseEditor.isHeightRestrict()); this.maxHeightSpinner.setVisible(elementCaseEditor.isHeightRestrict()); @@ -152,24 +152,24 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane{ String globalName = this.getGlobalName(); switch (globalName) { case "hComboBox": - ((ElementCaseEditor)xCreator.toData()).setHorziontalAttr(((MobileFitAttrState)((Item)hComboBox.getSelectedItem()).getValue())); + ((ElementCaseEditor) xCreator.toData()).setHorziontalAttr(((MobileFitAttrState) ((Item) hComboBox.getSelectedItem()).getValue())); break; case "vComboBox": - ((ElementCaseEditor)xCreator.toData()).setVerticalAttr(((MobileFitAttrState)((Item)vComboBox.getSelectedItem()).getValue())); + ((ElementCaseEditor) xCreator.toData()).setVerticalAttr(((MobileFitAttrState) ((Item) vComboBox.getSelectedItem()).getValue())); break; case "heightRestrictCheckBox": boolean isHeightRestrict = heightRestrictCheckBox.isSelected(); - ((ElementCaseEditor)xCreator.toData()).setHeightRestrict(isHeightRestrict); + ((ElementCaseEditor) xCreator.toData()).setHeightRestrict(isHeightRestrict); maxHeightSpinner.setVisible(isHeightRestrict); maxHeightLabel.setVisible(isHeightRestrict); break; case "maxHeightSpinner": - ((ElementCaseEditor)xCreator.toData()).setHeightPercent(maxHeightSpinner.getValue()); + ((ElementCaseEditor) xCreator.toData()).setHeightPercent(maxHeightSpinner.getValue()); break; case "allowFullCheckBox": - ((ElementCaseEditor)xCreator.toData()).setAllowFullScreen(allowFullCheckBox.isSelected()); + ((ElementCaseEditor) xCreator.toData()).setAllowFullScreen(allowFullCheckBox.isSelected()); case "functionalWhenUnactivatedCheckBox": - ((ElementCaseEditor)xCreator.toData()).setAllowFullScreen(functionalWhenUnactivatedCheckBox.isSelected()); + ((ElementCaseEditor) xCreator.toData()).setFunctionalWhenUnactivated(functionalWhenUnactivatedCheckBox.isSelected()); } } From 70a4c79a8f8cb38ad0dc8a0d4e6f119a3eb76b85 Mon Sep 17 00:00:00 2001 From: zack Date: Sun, 18 Aug 2019 22:37:04 +0800 Subject: [PATCH 10/60] =?UTF-8?q?=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../update/ui/dialog/UpdateMainDialog.java | 23 +-- .../java/com/fr/design/utils/DesignUtils.java | 4 +- .../chart/DownloadOnlineSourcesHelper.java | 31 ++-- .../mainframe/InformationCollector.java | 153 ++++++++---------- 4 files changed, 100 insertions(+), 111 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java index 81239d84b2..525077d621 100644 --- a/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java +++ b/designer-base/src/main/java/com/fr/design/update/ui/dialog/UpdateMainDialog.java @@ -35,6 +35,7 @@ import com.fr.json.JSONArray; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; +import com.fr.stable.EncodeConstants; import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; @@ -362,10 +363,10 @@ public class UpdateMainDialog extends UIDialog { add(jarVersionInfoPane, BorderLayout.NORTH); //海外版本不显示更新信息 - if (GeneralContext.getLocale().equals(Locale.CHINA) || GeneralContext.getLocale().equals(Locale.TAIWAN)){ + if (GeneralContext.getLocale().equals(Locale.CHINA) || GeneralContext.getLocale().equals(Locale.TAIWAN)) { add(jarUpdateInfoPane, BorderLayout.CENTER); add(updateActionPane, BorderLayout.SOUTH); - }else { + } else { add(updateActionPane, BorderLayout.CENTER); } @@ -513,16 +514,15 @@ public class UpdateMainDialog extends UIDialog { if (endTime.equals(lastUpdateCacheTime) || jsonArray.length() == 0 || ComparatorUtils.compare(endTime, lastUpdateCacheTime) <= 0) { return; } - OutputStreamWriter writerStream = new OutputStreamWriter(new FileOutputStream(cacheFile), "UTF-8"); - BufferedWriter bufferWriter = new BufferedWriter(writerStream); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jo = (JSONObject) jsonArray.get(i); - bufferWriter.write((String) jo.get("update") + '\t' + jo.get("title")); - bufferWriter.newLine(); - bufferWriter.flush(); + try (OutputStreamWriter writerStream = new OutputStreamWriter(new FileOutputStream(cacheFile), EncodeConstants.ENCODING_UTF_8); + BufferedWriter bufferWriter = new BufferedWriter(writerStream)) { + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jo = (JSONObject) jsonArray.get(i); + bufferWriter.write((String) jo.get("update") + '\t' + jo.get("title")); + bufferWriter.newLine(); + bufferWriter.flush(); + } } - bufferWriter.close(); - writerStream.close(); lastUpdateCacheState = UPDATE_CACHE_STATE_SUCCESS; lastUpdateCacheTime = endTime; cacheProperty.updateProperty("updateTime", lastUpdateCacheTime); @@ -634,6 +634,7 @@ public class UpdateMainDialog extends UIDialog { /** * 获取当前jar的md5 + * * @param currentJAR * @return */ diff --git a/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java b/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java index befe47c55e..b312093816 100644 --- a/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/DesignUtils.java @@ -67,8 +67,7 @@ public class DesignUtils { * @return 启动了返回true */ public static boolean isStarted() { - try { - new Socket("localhost", port); + try (Socket socket = new Socket("localhost", port)) { return true; } catch (Exception ignored) { } @@ -116,6 +115,7 @@ public class DesignUtils { * @param startPort 端口 * @param suffixs 文件后缀 */ + @SuppressWarnings("squid:S2095") public static void createListeningServer(final int startPort, final String[] suffixs) { ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("DesignClientListener")); service.execute(new Runnable() { diff --git a/designer-chart/src/main/java/com/fr/van/chart/DownloadOnlineSourcesHelper.java b/designer-chart/src/main/java/com/fr/van/chart/DownloadOnlineSourcesHelper.java index bea3beba9a..8849cc17c9 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/DownloadOnlineSourcesHelper.java +++ b/designer-chart/src/main/java/com/fr/van/chart/DownloadOnlineSourcesHelper.java @@ -64,7 +64,7 @@ public class DownloadOnlineSourcesHelper implements DownloadSourcesEvent { } public void addSiteInfo(String siteKind, String localDir, double megaBits) { - + if (new File(StableUtils.pathJoin(WorkContext.getCurrent().getPath(), localDir)).exists()) { //本地有这个资源,不下载 return; @@ -86,12 +86,14 @@ public class DownloadOnlineSourcesHelper implements DownloadSourcesEvent { initDialog(); dialog.addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { //取消下载 result = false; exitDialog(); } + @Override public void windowOpened(WindowEvent e) { downloadAndInstallPluginDependenceFile(); exitDialog(); @@ -119,25 +121,22 @@ public class DownloadOnlineSourcesHelper implements DownloadSourcesEvent { httpClient = new HttpClient(CloudCenter.getInstance().acquireUrlByKind(siteInfo.siteKind)); if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { - InputStream reader = httpClient.getResponseStream(); String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE); File file = new File(temp); StableUtils.makesureFileExist(file); - FileOutputStream writer = new FileOutputStream(temp); - byte[] buffer = new byte[PluginConstants.BYTES_NUM]; - int bytesRead; - while ((bytesRead = reader.read(buffer)) > 0 && result) { - writer.write(buffer, 0, bytesRead); - buffer = new byte[PluginConstants.BYTES_NUM]; - - currentBytesRead += bytesRead; - setProgress(currentBytesRead); + try (InputStream reader = httpClient.getResponseStream(); + FileOutputStream writer = new FileOutputStream(temp)) { + byte[] buffer = new byte[PluginConstants.BYTES_NUM]; + int bytesRead; + while ((bytesRead = reader.read(buffer)) > 0 && result) { + writer.write(buffer, 0, bytesRead); + buffer = new byte[PluginConstants.BYTES_NUM]; + + currentBytesRead += bytesRead; + setProgress(currentBytesRead); + } + writer.flush(); } - reader.close(); - writer.flush(); - writer.close(); - - if (result) { //安装文件 IOUtils.unZipFilesGBK(temp, StableUtils.pathJoin(WorkContext.getCurrent().getPath(), siteInfo.localDir)); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java b/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java index 1489294953..25c8a493e3 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java @@ -54,7 +54,6 @@ import java.util.concurrent.TimeUnit; /** * @author neil - * * @date: 2015-4-8-下午5:11:46 */ public class InformationCollector implements XMLReadable, XMLWriter { @@ -83,17 +82,17 @@ public class InformationCollector implements XMLReadable, XMLWriter { private String lastTime; private StartStopTime current = new StartStopTime(); - public static InformationCollector getInstance(){ + public static InformationCollector getInstance() { if (collector == null) { collector = new InformationCollector(); - readEncodeXMLFile(collector, collector.getInfoFile()); + readEncodeXMLFile(collector, collector.getInfoFile()); } return collector; } - private static void readEncodeXMLFile(XMLReadable xmlReadable, File xmlFile){ + private static void readEncodeXMLFile(XMLReadable xmlReadable, File xmlFile) { if (xmlFile == null || !xmlFile.exists()) { return; } @@ -110,22 +109,22 @@ public class InformationCollector implements XMLReadable, XMLWriter { } xmlInputStream.close(); } catch (FileNotFoundException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); } catch (IOException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); } catch (XMLStreamException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); } } - private static String getDecodeFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException{ + private static String getDecodeFileContent(File xmlFile) throws FileNotFoundException, UnsupportedEncodingException { InputStream encodeInputStream = new FileInputStream(xmlFile); String encodeContent = IOUtils.inputStream2String(encodeInputStream); return DesUtils.getDecString(encodeContent); } - private long getLastTimeMillis(){ + private long getLastTimeMillis() { if (StringUtils.isEmpty(this.lastTime)) { return 0; } @@ -138,7 +137,7 @@ public class InformationCollector implements XMLReadable, XMLWriter { } - private JSONObject getJSONContentAsByte(){ + private JSONObject getJSONContentAsByte() { JSONObject content = new JSONObject(); JSONArray startStopArray = new JSONArray(); @@ -159,7 +158,7 @@ public class InformationCollector implements XMLReadable, XMLWriter { return content; } - private void sendUserInfo(){ + private void sendUserInfo() { long currentTime = new Date().getTime(); long lastTime = getLastTimeMillis(); @@ -178,7 +177,7 @@ public class InformationCollector implements XMLReadable, XMLWriter { } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } - if (success){ + if (success) { this.reset(); } } @@ -186,13 +185,13 @@ public class InformationCollector implements XMLReadable, XMLWriter { /** * 收集开始使用时间,发送信息 */ - public void collectStartTime(){ + public void collectStartTime() { this.current.setStartDate(dateToString()); sendUserInfoInOtherThread(); } - private void sendUserInfoInOtherThread(){ + private void sendUserInfoInOtherThread() { if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) { return; } @@ -209,67 +208,57 @@ public class InformationCollector implements XMLReadable, XMLWriter { }, SEND_DELAY, TimeUnit.MILLISECONDS); } - /** - * 收集结束使用时间 - */ - public void collectStopTime(){ + /** + * 收集结束使用时间 + */ + public void collectStopTime() { this.current.setStopDate(dateToString()); } - private String dateToString(){ + private String dateToString() { DateFormat df = FRContext.getDefaultValues().getDateTimeFormat(); return df.format(new Date()); } - private void reset(){ + private void reset() { this.startStop.clear(); this.lastTime = dateToString(); } - private File getInfoFile() { - return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME)); - } - - /** - * 保存xml文件 - */ - public void saveXMLFile() { - File xmlFile = this.getInfoFile(); - try{ - ByteArrayOutputStream out = new ByteArrayOutputStream(); + private File getInfoFile() { + return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME)); + } + + /** + * 保存xml文件 + */ + public void saveXMLFile() { + File xmlFile = this.getInfoFile(); + try { + ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLTools.writeOutputStreamXML(this, out); out.flush(); out.close(); String fileContent = new String(out.toByteArray(), EncodeConstants.ENCODING_UTF_8); String encodeCotent = DesUtils.getEncString(fileContent); writeEncodeContentToFile(encodeCotent, xmlFile); - }catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); } - } + } /** * 将文件内容写到输出流中 */ - private static void writeEncodeContentToFile(String fileContent, File file){ - BufferedWriter bw = null; - try { - FileOutputStream fos = new FileOutputStream(file); - OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8); - bw = new BufferedWriter(osw); + private static void writeEncodeContentToFile(String fileContent, File file) { + try (FileOutputStream fos = new FileOutputStream(file); + OutputStreamWriter osw = new OutputStreamWriter(fos, EncodeConstants.ENCODING_UTF_8); + BufferedWriter bw = new BufferedWriter(osw)) { bw.write(fileContent); } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } finally { - if(bw != null){ - try { - bw.close(); - } catch (IOException e) { - } - } + FineLoggerFactory.getLogger().error(e.getMessage(), e); } - } @Override @@ -284,56 +273,56 @@ public class InformationCollector implements XMLReadable, XMLWriter { writer.end(); } - private void writeStartStopList(XMLPrintWriter writer){ + private void writeStartStopList(XMLPrintWriter writer) { //启停 - writer.startTAG(XML_START_STOP_LIST); - for (int i = 0; i < startStop.size(); i++) { - startStop.get(i).writeXML(writer); + writer.startTAG(XML_START_STOP_LIST); + for (int i = 0; i < startStop.size(); i++) { + startStop.get(i).writeXML(writer); } - writer.end(); + writer.end(); } - private void writeTag(String tag, String content, XMLPrintWriter writer){ + private void writeTag(String tag, String content, XMLPrintWriter writer) { if (StringUtils.isEmpty(content)) { return; } - writer.startTAG(tag); - writer.textNode(content); - writer.end(); + writer.startTAG(tag); + writer.textNode(content); + writer.end(); } @Override public void readXML(XMLableReader reader) { - if (reader.isChildNode()) { - String name = reader.getTagName(); - if (XML_START_STOP_LIST.equals(name)) { - readStartStopList(reader); - } else if(XML_LAST_TIME.equals(name)){ - readLastTime(reader); + if (reader.isChildNode()) { + String name = reader.getTagName(); + if (XML_START_STOP_LIST.equals(name)) { + readStartStopList(reader); + } else if (XML_LAST_TIME.equals(name)) { + readLastTime(reader); } - } + } } - private void readLastTime(XMLableReader reader){ + private void readLastTime(XMLableReader reader) { String tmpVal; if (StringUtils.isNotBlank(tmpVal = reader.getElementValue())) { this.lastTime = tmpVal; } } - private void readStartStopList(XMLableReader reader){ - startStop.clear(); + private void readStartStopList(XMLableReader reader) { + startStop.clear(); reader.readXMLObject(new XMLReadable() { - public void readXML(XMLableReader reader) { - if (XML_START_STOP.equals(reader.getTagName())) { - StartStopTime startStopTime = new StartStopTime(); - reader.readXMLObject(startStopTime); - startStop.add(startStopTime); - } - } - }); + public void readXML(XMLableReader reader) { + if (XML_START_STOP.equals(reader.getTagName())) { + StartStopTime startStopTime = new StartStopTime(); + reader.readXMLObject(startStopTime); + startStop.add(startStopTime); + } + } + }); } private class StartStopTime implements XMLReadable, XMLWriter { @@ -358,14 +347,14 @@ public class InformationCollector implements XMLReadable, XMLWriter { } public void writeXML(XMLPrintWriter writer) { - writer.startTAG(XML_START_STOP); - if (StringUtils.isNotEmpty(startDate)) { - writer.attr(ATTR_START, this.startDate); + writer.startTAG(XML_START_STOP); + if (StringUtils.isNotEmpty(startDate)) { + writer.attr(ATTR_START, this.startDate); } - if (StringUtils.isNotEmpty(stopDate)) { - writer.attr(ATTR_STOP, this.stopDate); + if (StringUtils.isNotEmpty(stopDate)) { + writer.attr(ATTR_STOP, this.stopDate); } - writer.end(); + writer.end(); } public void readXML(XMLableReader reader) { From a5bb0bf8cd3693e0e9bfd4cae579ba01f9b4c625 Mon Sep 17 00:00:00 2001 From: zack Date: Sun, 18 Aug 2019 22:43:27 +0800 Subject: [PATCH 11/60] =?UTF-8?q?=E5=88=A0=E6=8E=89sdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designer-sdk/pom.xml | 5 -- .../com/fr/sdk/designer/FineDesignUtils.java | 80 ------------------- .../java/com/fr/sdk/FineDesignUtilsTest.java | 7 -- 3 files changed, 92 deletions(-) delete mode 100644 designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java delete mode 100644 designer-sdk/src/test/java/com/fr/sdk/FineDesignUtilsTest.java diff --git a/designer-sdk/pom.xml b/designer-sdk/pom.xml index 9702536e22..2fb53e1dc9 100644 --- a/designer-sdk/pom.xml +++ b/designer-sdk/pom.xml @@ -17,10 +17,5 @@ designer-realize 10.0 - - com.fr.report - sdk-base - 10.0 - \ No newline at end of file diff --git a/designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java b/designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java deleted file mode 100644 index 7de2f3c2d5..0000000000 --- a/designer-sdk/src/main/java/com/fr/sdk/designer/FineDesignUtils.java +++ /dev/null @@ -1,80 +0,0 @@ -//package com.fr.sdk.designer; -// -//import com.fr.config.activator.ConfigurationActivator; -//import com.fr.design.env.DesignerWorkspaceGenerator; -//import com.fr.design.env.RemoteDesignerWorkspaceInfo; -//import com.fr.log.FineLoggerFactory; -//import com.fr.module.Activator; -//import com.fr.module.Module; -//import com.fr.module.tool.ActivatorToolBox; -//import com.fr.report.ReportActivator; -//import com.fr.report.RestrictionActivator; -//import com.fr.report.module.ReportBaseActivator; -//import com.fr.scheduler.SchedulerActivator; -//import com.fr.sdk.server.shell.ModuleShell; -//import com.fr.serialization.SerializationActivator; -//import com.fr.stable.StringUtils; -//import com.fr.startup.WorkspaceRegister; -//import com.fr.store.StateServerActivator; -//import com.fr.workspace.WorkContext; -//import com.fr.workspace.connect.WorkspaceConnectionInfo; -//import com.fr.workspace.engine.WorkspaceActivator; -//import com.fr.workspace.server.ServerWorkspaceRegister; -// -///** -// * 设计器SDK模块工具类,用来放一些设计器相关插件开发过程中常用的工具函数 -// */ -//public class FineDesignUtils { -// -// /** -// * 创建一个连接远程服务器的模块 -// * @param remoteUrl 远程服务器地址 -// * @param username 用户名 -// * @param password 密码 -// * @return 模块代理对象 使用ModuleShell的start和stop控制模块启停 -// */ -// public static ModuleShell createRemoteServerModule(String remoteUrl, String username, String password) { -// return createRemoteServerModule(remoteUrl, username, password, StringUtils.EMPTY, StringUtils.EMPTY); -// } -// -// /** -// * 创建一个连接远程服务器的模块 -// * @param remoteUrl 远程服务器地址 -// * @param username 用户名 -// * @param password 密码 -// * @param certPath https证书路径 -// * @param certSecretKey 证书秘钥 -// * @return 模块代理对象 使用ModuleShell的start和stop控制模块启停 -// */ -// public static ModuleShell createRemoteServerModule(final String remoteUrl, final String username, final String password, final String certPath, final String certSecretKey) { -// Module module = ActivatorToolBox.simpleLink( -// new WorkspaceActivator(), -// new SerializationActivator(), -// new Activator() { -// @Override -// public void start() { -// WorkspaceConnectionInfo connectionInfo = new WorkspaceConnectionInfo(remoteUrl, username, password, certPath, certSecretKey); -// try { -// WorkContext.switchTo(DesignerWorkspaceGenerator.generate(RemoteDesignerWorkspaceInfo.create(connectionInfo))); -// } catch (Exception e) { -// FineLoggerFactory.getLogger().error(e.getMessage(),e); -// } -// } -// -// @Override -// public void stop() { -// -// } -// }, -// new ConfigurationActivator(), -// new StateServerActivator(), -// new SchedulerActivator(), -// new ReportBaseActivator(), -// new RestrictionActivator(), -// new ReportActivator(), -// new WorkspaceRegister(), -// new ServerWorkspaceRegister() -// ); -// return new ModuleShell(module); -// } -//} \ No newline at end of file diff --git a/designer-sdk/src/test/java/com/fr/sdk/FineDesignUtilsTest.java b/designer-sdk/src/test/java/com/fr/sdk/FineDesignUtilsTest.java deleted file mode 100644 index ec210321b9..0000000000 --- a/designer-sdk/src/test/java/com/fr/sdk/FineDesignUtilsTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.fr.sdk; - -import junit.framework.TestCase; - -public class FineDesignUtilsTest extends TestCase { - -} \ No newline at end of file From 0e875025d1645230b38e65993b4dbf5a6f4ba376 Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 15:23:24 +0800 Subject: [PATCH 12/60] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapters/layout/FRFitLayoutAdapter.java | 3 ++- .../layout/FRTabFitLayoutAdapter.java | 3 ++- .../creator/XBorderStyleWidgetCreator.java | 13 ++++++------ .../creator/cardlayout/XCardSwitchButton.java | 21 +++++-------------- .../creator/cardlayout/XWCardLayout.java | 9 ++++---- .../cardlayout/XWCardMainBorderLayout.java | 3 ++- .../creator/cardlayout/XWCardTagLayout.java | 12 ++++------- .../layout/WCardTagLayoutDefinePane.java | 4 ++-- 8 files changed, 29 insertions(+), 39 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java index 9aa9e5ab9c..f38e44f751 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java @@ -24,6 +24,7 @@ import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.WTabDisplayPosition; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.general.ComparatorUtils; +import com.fr.general.TextFetcher; import java.awt.Component; import java.awt.Dimension; @@ -284,7 +285,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { backupBound.x -= rec.x; backupBound.y -= rec.y; XWCardLayout cardLayout = mainLayout.getCardPart(); - LayoutBorderStyle style = cardLayout.toData().getBorderStyle(); + TextFetcher style = cardLayout.toData().getBorderStyle(); XWCardTitleLayout xwCardTitleLayout = mainLayout.getTitlePart(); Dimension titleDimension = xwCardTitleLayout.getSize(); diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java index b1ca803c6b..b280cb71a4 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java @@ -19,6 +19,7 @@ import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.general.ComparatorUtils; +import com.fr.general.TextFetcher; import java.awt.*; @@ -90,7 +91,7 @@ public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter { // TODO 可以直接在这边将x,y都变成相对坐标,这样在后面判断拖进来的新控件放置方式的时候就不用再判断了 private int adjustY(int y, XWTabFitLayout tabLayout) { XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent(); - LayoutBorderStyle style = cardLayout.toData().getBorderStyle(); + TextFetcher style = cardLayout.toData().getBorderStyle(); y = y - this.getParaEditorYOffset(); if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { y = y - WCardMainBorderLayout.TAB_HEIGHT; diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java index 0466631023..05d35c8212 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java @@ -11,6 +11,7 @@ import com.fr.form.ui.WidgetTitle; import com.fr.form.ui.WidgetValue; import com.fr.form.ui.container.WTitleLayout; import com.fr.general.ComparatorUtils; +import com.fr.general.TextFetcher; import com.fr.stable.Constants; import com.fr.stable.StringUtils; @@ -41,7 +42,7 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ } protected void initStyle() { - LayoutBorderStyle style = toData().getBorderStyle(); + TextFetcher style = toData().getBorderStyle(); initBorderStyle(); if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { initTitleStyle(style); @@ -52,7 +53,7 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ // 边框默认值设为NONE,不然像scalelayout这种只用默认边框的会不显示边框 protected void initBorderStyle() { - LayoutBorderStyle style = toData().getBorderStyle(); + TextFetcher style = toData().getBorderStyle(); if (style != null && style.getBorder() != Constants.LINE_NONE) { this.setBorder(new UIRoundedBorder(style.getBorder(), style.getColor(), style.getBorderRadius())); } else { @@ -74,8 +75,8 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ * 设置样式为标题样式时,对应组件加上标题 * @param style 样式 */ - protected void initTitleStyle(LayoutBorderStyle style){ - if (style.getTitle() == null) { + protected void initTitleStyle(TextFetcher style){ + if (style.getTextObject() == null) { return; } XWTitleLayout parent = (XWTitleLayout) this.getParent(); @@ -100,13 +101,13 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ /** * 更新标题控件所有的样式 */ - private void updateTitleWidgetStyle(Label title, LayoutBorderStyle style) { + private void updateTitleWidgetStyle(Label title, TextFetcher style) { //标题的边框样式目前是取对应的控件的边框样式 title.setBorder(style.getBorder()); title.setColor(style.getColor()); // title.setCorner(style.isCorner()); - WidgetTitle wTitle = style.getTitle(); + WidgetTitle wTitle = WidgetTitle.as(style); //设置成随机不重复的, 不然都用一个名字的话, 联动只能联动一个 title.setWidgetName(wTitle.TITLE_NAME_INDEX + this.toData().getWidgetName()); title.setWidgetValue(getTitleValue(wTitle)); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java index 72d0669c83..615c328aa1 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java @@ -22,7 +22,6 @@ import com.fr.design.mainframe.JForm; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.CardSwitchButton; -import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.WidgetTitle; import com.fr.form.ui.container.WTabTextDirection; import com.fr.form.ui.container.cardlayout.WCardTagLayout; @@ -30,23 +29,13 @@ import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.general.Background; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; - +import com.fr.general.TextFetcher; import com.fr.general.cardtag.TemplateStyle; import com.fr.stable.unit.PT; -import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JPopupMenu; -import javax.swing.SwingUtilities; +import javax.swing.*; import javax.swing.plaf.basic.BasicLabelUI; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; +import java.awt.*; import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; import java.util.ArrayList; @@ -355,8 +344,8 @@ public class XCardSwitchButton extends XButton { if (this.cardLayout == null) { initRelateLayout(); } - LayoutBorderStyle style = this.cardLayout.toData().getBorderStyle(); - return style.getTitle(); + TextFetcher style = this.cardLayout.toData().getBorderStyle(); + return WidgetTitle.as(style); } //删除tab布局 diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java index 107e31ed12..653416e12f 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java @@ -34,6 +34,7 @@ import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WCardTitleLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.general.ComparatorUtils; +import com.fr.general.TextFetcher; import com.fr.general.cardtag.DefaultTemplateStyle; import com.fr.general.cardtag.TemplateStyle; import com.fr.stable.ArrayUtils; @@ -165,7 +166,7 @@ public class XWCardLayout extends XLayoutContainer { WCardMainBorderLayout border = new WCardMainBorderLayout(); XWCardMainBorderLayout xMainBorder = new XWCardMainBorderLayout(border, dimension); //将子WCardBorder的style设置到父容器上 - LayoutBorderStyle style = (this.toData()).getBorderStyle(); + TextFetcher style = (this.toData()).getBorderStyle(); border.setBorderStyle(style); this.setBackupParent(xMainBorder); XWCardTitleLayout titlePart = this.initTitlePart(widgetName, xMainBorder); @@ -397,13 +398,13 @@ public class XWCardLayout extends XLayoutContainer { //初始化样式 @Override protected void initStyle() { - LayoutBorderStyle style = toData().getBorderStyle(); + TextFetcher style = toData().getBorderStyle(); initBorderTitleStyle(style); initBorderStyle(); clearOrShowTitleLayout(ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)); } - private void initBorderTitleStyle(LayoutBorderStyle style) { + private void initBorderTitleStyle(TextFetcher style) { //初始化默认标题样式 if (!initFlag) { return; @@ -411,7 +412,7 @@ public class XWCardLayout extends XLayoutContainer { style.setType(LayoutBorderStyle.TITLE); style.setBorder(Constants.LINE_THIN); - WidgetTitle widgetTitle = style.getTitle(); + WidgetTitle widgetTitle = WidgetTitle.as(style); widgetTitle.setBackground(ColorBackground.getInstance(TITLE_COLOR)); initFlag = false; } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java index c7f235154e..b0731e152b 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java @@ -38,6 +38,7 @@ import com.fr.form.ui.container.cardlayout.WCardTitleLayout; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; +import com.fr.general.TextFetcher; import com.fr.share.ShareConstants; import com.fr.stable.Constants; @@ -164,7 +165,7 @@ public class XWCardMainBorderLayout extends XWBorderLayout { String tabpaneName = cardLayout.getWidgetName(); if (!wCardTagLayout.isNewTab()) { wCardTagLayout.setWidgetName(tabpaneName); - LayoutBorderStyle borderStyle = cardLayout.getBorderStyle(); + TextFetcher borderStyle = cardLayout.getBorderStyle(); if(borderStyle != null){ //新tab默认都有标题 borderStyle.setType(LayoutBorderStyle.TITLE); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java index 1b9d2690e6..cc118001fb 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java @@ -27,21 +27,18 @@ import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.form.ui.CardSwitchButton; -import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.Widget; -import com.fr.form.ui.WidgetTitle; import com.fr.form.ui.container.WCardLayout; import com.fr.form.ui.container.WTabDisplayPosition; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; +import com.fr.general.TextFetcher; import com.fr.general.cardtag.DefaultTemplateStyle; import javax.swing.border.Border; -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.awt.Rectangle; +import java.awt.*; import java.awt.event.ContainerEvent; import java.awt.event.MouseEvent; import java.util.HashMap; @@ -363,9 +360,8 @@ public class XWCardTagLayout extends XWHorizontalBoxLayout { if (this.cardLayout == null) { initCardLayout(); } - LayoutBorderStyle borderStyle = this.cardLayout.toData().getBorderStyle(); - WidgetTitle title = borderStyle.getTitle(); - FRFont f = title.getFrFont(); + TextFetcher borderStyle = this.cardLayout.toData().getBorderStyle(); + FRFont f = borderStyle.getFrFont(); FontMetrics fm = GraphHelper.getFontMetrics(f); switch (wCardTagLayout.getTextDirection()) { diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/WCardTagLayoutDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/WCardTagLayoutDefinePane.java index 41ea1c1c7d..06a14c25a2 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/WCardTagLayoutDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/WCardTagLayoutDefinePane.java @@ -107,7 +107,7 @@ public class WCardTagLayoutDefinePane extends AbstractDataModify public void populateBean(WCardTagLayout ob) { //标题背景和字体属性设置在WCardLayout上做兼容 XLayoutContainer topLayout = creator.getTopLayout(); - LayoutBorderStyle layoutBorderStyle = ((XWCardMainBorderLayout) topLayout).getCardPart().toData().getBorderStyle(); + LayoutBorderStyle layoutBorderStyle = (LayoutBorderStyle) ((XWCardMainBorderLayout) topLayout).getCardPart().toData().getBorderStyle(); displayPositionGroup.setSelectedIndex(ob.getDisplayPosition().getType()); textDirectionGroup.setSelectedIndex(ob.getTextDirection().getType()); @@ -125,7 +125,7 @@ public class WCardTagLayoutDefinePane extends AbstractDataModify //标题背景和字体属性设置在WCardLayout上做兼容 XLayoutContainer topLayout = creator.getTopLayout(); XWCardLayout xCardLayout = ((XWCardMainBorderLayout) topLayout).getCardPart(); - LayoutBorderStyle layoutBorderStyle = xCardLayout.toData().getBorderStyle(); + LayoutBorderStyle layoutBorderStyle = (LayoutBorderStyle) xCardLayout.toData().getBorderStyle(); FRFont frFont = layoutBorderStyle.getTitle().getFrFont() == null ? FRFont.getInstance() : layoutBorderStyle.getTitle().getFrFont(); FRFont titleFont = frFontPane.update(frFont); layoutBorderStyle.getTitle().setFrFont(titleFont); From 84c585ed51c268305085275e08aaf15e95a3fb47 Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 16:32:01 +0800 Subject: [PATCH 13/60] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20?= =?UTF-8?q?=E6=8A=BD=E8=B1=A1=E5=AE=9E=E4=BD=93=E7=B1=BB=EF=BC=8C=E7=BB=99?= =?UTF-8?q?SDK=E5=81=9A=E5=87=86=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapters/layout/FRFitLayoutAdapter.java | 4 +-- .../layout/FRTabFitLayoutAdapter.java | 7 ++--- .../creator/XBorderStyleWidgetCreator.java | 23 +++++++------- .../creator/cardlayout/XCardSwitchButton.java | 18 +++++------ .../creator/cardlayout/XWCardLayout.java | 12 +++---- .../cardlayout/XWCardMainBorderLayout.java | 4 +-- .../creator/cardlayout/XWCardTagLayout.java | 6 ++-- .../fr/design/gui/xpane/LayoutBorderPane.java | 31 +++++-------------- .../gui/xpane/LayoutBorderPreviewPane.java | 6 ++-- 9 files changed, 47 insertions(+), 64 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java index f38e44f751..f2fc29ad52 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java @@ -24,7 +24,7 @@ import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.WTabDisplayPosition; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.general.ComparatorUtils; -import com.fr.general.TextFetcher; +import com.fr.general.act.BorderPacker; import java.awt.Component; import java.awt.Dimension; @@ -285,7 +285,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { backupBound.x -= rec.x; backupBound.y -= rec.y; XWCardLayout cardLayout = mainLayout.getCardPart(); - TextFetcher style = cardLayout.toData().getBorderStyle(); + BorderPacker style = cardLayout.toData().getBorderStyle(); XWCardTitleLayout xwCardTitleLayout = mainLayout.getTitlePart(); Dimension titleDimension = xwCardTitleLayout.getSize(); diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java index b280cb71a4..9b8effd0ad 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java @@ -7,19 +7,16 @@ package com.fr.design.designer.beans.adapters.layout; import com.fr.design.beans.GroupModel; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWParameterLayout; import com.fr.design.designer.creator.XWidgetCreator; import com.fr.design.designer.creator.cardlayout.XWCardLayout; import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.properties.FRTabFitLayoutPropertiesGroupModel; -import com.fr.design.mainframe.widget.editors.ParameterEditor; import com.fr.design.utils.ComponentUtils; import com.fr.form.ui.LayoutBorderStyle; -import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.general.ComparatorUtils; -import com.fr.general.TextFetcher; +import com.fr.general.act.BorderPacker; import java.awt.*; @@ -91,7 +88,7 @@ public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter { // TODO 可以直接在这边将x,y都变成相对坐标,这样在后面判断拖进来的新控件放置方式的时候就不用再判断了 private int adjustY(int y, XWTabFitLayout tabLayout) { XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent(); - TextFetcher style = cardLayout.toData().getBorderStyle(); + BorderPacker style = cardLayout.toData().getBorderStyle(); y = y - this.getParaEditorYOffset(); if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { y = y - WCardMainBorderLayout.TAB_HEIGHT; diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java index 05d35c8212..fdefc019ae 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java @@ -11,7 +11,8 @@ import com.fr.form.ui.WidgetTitle; import com.fr.form.ui.WidgetValue; import com.fr.form.ui.container.WTitleLayout; import com.fr.general.ComparatorUtils; -import com.fr.general.TextFetcher; +import com.fr.general.act.BorderPacker; +import com.fr.general.act.TitlePacker; import com.fr.stable.Constants; import com.fr.stable.StringUtils; @@ -42,7 +43,7 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ } protected void initStyle() { - TextFetcher style = toData().getBorderStyle(); + BorderPacker style = toData().getBorderStyle(); initBorderStyle(); if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { initTitleStyle(style); @@ -53,7 +54,7 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ // 边框默认值设为NONE,不然像scalelayout这种只用默认边框的会不显示边框 protected void initBorderStyle() { - TextFetcher style = toData().getBorderStyle(); + BorderPacker style = toData().getBorderStyle(); if (style != null && style.getBorder() != Constants.LINE_NONE) { this.setBorder(new UIRoundedBorder(style.getBorder(), style.getColor(), style.getBorderRadius())); } else { @@ -75,8 +76,8 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ * 设置样式为标题样式时,对应组件加上标题 * @param style 样式 */ - protected void initTitleStyle(TextFetcher style){ - if (style.getTextObject() == null) { + protected void initTitleStyle(BorderPacker style){ + if (style.getTitle() == null || style.getTitle().getTextObject() == null) { return; } XWTitleLayout parent = (XWTitleLayout) this.getParent(); @@ -101,25 +102,25 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ /** * 更新标题控件所有的样式 */ - private void updateTitleWidgetStyle(Label title, TextFetcher style) { + private void updateTitleWidgetStyle(Label title, BorderPacker style) { //标题的边框样式目前是取对应的控件的边框样式 title.setBorder(style.getBorder()); title.setColor(style.getColor()); // title.setCorner(style.isCorner()); - WidgetTitle wTitle = WidgetTitle.as(style); + TitlePacker wTitle = style.getTitle(); //设置成随机不重复的, 不然都用一个名字的话, 联动只能联动一个 - title.setWidgetName(wTitle.TITLE_NAME_INDEX + this.toData().getWidgetName()); + title.setWidgetName(WidgetTitle.TITLE_NAME_INDEX + this.toData().getWidgetName()); title.setWidgetValue(getTitleValue(wTitle)); title.setFont(wTitle.getFrFont()); title.setTextalign(wTitle.getPosition()); title.setBackground(wTitle.getBackground()); } - private WidgetValue getTitleValue(WidgetTitle wTitle){ + private WidgetValue getTitleValue(TitlePacker wTitle){ String content = String.valueOf(wTitle.getTextObject()); - Object vlaue = content.startsWith("=") ? BaseFormula.createFormulaBuilder().build(content) : content; - return new WidgetValue(vlaue); + Object value = content.startsWith("=") ? BaseFormula.createFormulaBuilder().build(content) : content; + return new WidgetValue(value); } @Override diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java index 615c328aa1..dc555e5d14 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java @@ -22,14 +22,14 @@ import com.fr.design.mainframe.JForm; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.CardSwitchButton; -import com.fr.form.ui.WidgetTitle; import com.fr.form.ui.container.WTabTextDirection; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.general.Background; +import com.fr.general.act.BorderPacker; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; -import com.fr.general.TextFetcher; +import com.fr.general.act.TitlePacker; import com.fr.general.cardtag.TemplateStyle; import com.fr.stable.unit.PT; @@ -297,7 +297,7 @@ public class XCardSwitchButton extends XButton { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; CardSwitchButton button = (CardSwitchButton) this.toData(); - WidgetTitle widgetTitle = getWidgetTitle(); + TitlePacker widgetTitle = getWidgetTitle(); drawBackground(button, widgetTitle); drawTitle(button, widgetTitle); Dimension panelSize = this.getContentLabel().getSize(); @@ -311,7 +311,7 @@ public class XCardSwitchButton extends XButton { } //画背景 - private void drawBackground(CardSwitchButton button, WidgetTitle widgetTitle){ + private void drawBackground(CardSwitchButton button, TitlePacker widgetTitle){ Background background = widgetTitle.getBackground() == null ? ColorBackground.getInstance(NORMAL_GRAL) : widgetTitle.getBackground(); TemplateStyle templateStyle = ((WCardTagLayout) tagLayout.toData()).getTemplateStyle(); //获取当前tab的index @@ -329,7 +329,7 @@ public class XCardSwitchButton extends XButton { } //画标题 - private void drawTitle(CardSwitchButton button, WidgetTitle widgetTitle) { + private void drawTitle(CardSwitchButton button, TitlePacker widgetTitle) { String titleText = button.getText(); this.setButtonText(titleText); FRFont font = widgetTitle.getFrFont(); @@ -340,12 +340,12 @@ public class XCardSwitchButton extends XButton { } - private WidgetTitle getWidgetTitle() { + private TitlePacker getWidgetTitle() { if (this.cardLayout == null) { initRelateLayout(); } - TextFetcher style = this.cardLayout.toData().getBorderStyle(); - return WidgetTitle.as(style); + BorderPacker style = this.cardLayout.toData().getBorderStyle(); + return style.getTitle(); } //删除tab布局 @@ -452,7 +452,7 @@ public class XCardSwitchButton extends XButton { String titleText = button.getText(); java.util.List verticalTextList = new ArrayList(); StringBuilder titleStringBuf = new StringBuilder(); - WidgetTitle title = getWidgetTitle(); + TitlePacker title = getWidgetTitle(); FRFont font = title.getFrFont(); FRFont newFont = FRFont.getInstance(font.getName(), font.getStyle(), font.getSize() + FONT_SIZE_ADJUST); FontMetrics fm = GraphHelper.getFontMetrics(newFont); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java index 653416e12f..c91d34654c 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardLayout.java @@ -25,7 +25,6 @@ import com.fr.form.ui.CardAddButton; import com.fr.form.ui.CardSwitchButton; import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.Widget; -import com.fr.form.ui.WidgetTitle; import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.WCardLayout; import com.fr.form.ui.container.WLayout; @@ -33,8 +32,9 @@ import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WCardTitleLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout; +import com.fr.general.act.BorderPacker; import com.fr.general.ComparatorUtils; -import com.fr.general.TextFetcher; +import com.fr.general.act.TitlePacker; import com.fr.general.cardtag.DefaultTemplateStyle; import com.fr.general.cardtag.TemplateStyle; import com.fr.stable.ArrayUtils; @@ -166,7 +166,7 @@ public class XWCardLayout extends XLayoutContainer { WCardMainBorderLayout border = new WCardMainBorderLayout(); XWCardMainBorderLayout xMainBorder = new XWCardMainBorderLayout(border, dimension); //将子WCardBorder的style设置到父容器上 - TextFetcher style = (this.toData()).getBorderStyle(); + BorderPacker style = (this.toData()).getBorderStyle(); border.setBorderStyle(style); this.setBackupParent(xMainBorder); XWCardTitleLayout titlePart = this.initTitlePart(widgetName, xMainBorder); @@ -398,13 +398,13 @@ public class XWCardLayout extends XLayoutContainer { //初始化样式 @Override protected void initStyle() { - TextFetcher style = toData().getBorderStyle(); + BorderPacker style = toData().getBorderStyle(); initBorderTitleStyle(style); initBorderStyle(); clearOrShowTitleLayout(ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)); } - private void initBorderTitleStyle(TextFetcher style) { + private void initBorderTitleStyle(BorderPacker style) { //初始化默认标题样式 if (!initFlag) { return; @@ -412,7 +412,7 @@ public class XWCardLayout extends XLayoutContainer { style.setType(LayoutBorderStyle.TITLE); style.setBorder(Constants.LINE_THIN); - WidgetTitle widgetTitle = WidgetTitle.as(style); + TitlePacker widgetTitle = style.getTitle(); widgetTitle.setBackground(ColorBackground.getInstance(TITLE_COLOR)); initFlag = false; } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java index b0731e152b..edbabeadf3 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java @@ -38,7 +38,7 @@ import com.fr.form.ui.container.cardlayout.WCardTitleLayout; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; -import com.fr.general.TextFetcher; +import com.fr.general.act.BorderPacker; import com.fr.share.ShareConstants; import com.fr.stable.Constants; @@ -165,7 +165,7 @@ public class XWCardMainBorderLayout extends XWBorderLayout { String tabpaneName = cardLayout.getWidgetName(); if (!wCardTagLayout.isNewTab()) { wCardTagLayout.setWidgetName(tabpaneName); - TextFetcher borderStyle = cardLayout.getBorderStyle(); + BorderPacker borderStyle = cardLayout.getBorderStyle(); if(borderStyle != null){ //新tab默认都有标题 borderStyle.setType(LayoutBorderStyle.TITLE); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java index cc118001fb..77282f63f9 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java @@ -32,9 +32,9 @@ import com.fr.form.ui.container.WCardLayout; import com.fr.form.ui.container.WTabDisplayPosition; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout; +import com.fr.general.act.BorderPacker; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; -import com.fr.general.TextFetcher; import com.fr.general.cardtag.DefaultTemplateStyle; import javax.swing.border.Border; @@ -360,8 +360,8 @@ public class XWCardTagLayout extends XWHorizontalBoxLayout { if (this.cardLayout == null) { initCardLayout(); } - TextFetcher borderStyle = this.cardLayout.toData().getBorderStyle(); - FRFont f = borderStyle.getFrFont(); + BorderPacker borderStyle = this.cardLayout.toData().getBorderStyle(); + FRFont f = borderStyle.getTitle().getFrFont(); FontMetrics fm = GraphHelper.getFontMetrics(f); switch (wCardTagLayout.getTextDirection()) { diff --git a/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPane.java b/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPane.java index a70431700a..cf460f9ceb 100644 --- a/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPane.java +++ b/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPane.java @@ -38,32 +38,17 @@ import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.WidgetTitle; import com.fr.general.Background; import com.fr.general.FRFont; - +import com.fr.general.act.TitlePacker; import com.fr.stable.Constants; -import javax.swing.AbstractButton; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.ButtonModel; -import javax.swing.Icon; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JToggleButton; +import javax.swing.*; import javax.swing.border.Border; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.plaf.basic.BasicToggleButtonUI; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; @@ -546,7 +531,7 @@ public class LayoutBorderPane extends BasicPane { style.setColor(currentLineColorPane.getColor()); style.setBackground(backgroundPane.update()); style.setAlpha((float)(numberDragPane.updateBean()/maxNumber)); - WidgetTitle title = style.getTitle() == null ? new WidgetTitle() : style.getTitle(); + TitlePacker title = style.getTitle() == null ? new WidgetTitle() : style.getTitle(); title.setTextObject(formulaPane.updateBean()); FRFont frFont = title.getFrFont(); frFont = frFont.applySize((Integer)fontSizeComboBox.getSelectedItem()); @@ -644,10 +629,10 @@ public class LayoutBorderPane extends BasicPane { } protected void populateTitle(){ - WidgetTitle widgetTitle = borderStyle == null ? new WidgetTitle() : borderStyle.getTitle(); + TitlePacker widgetTitle = borderStyle == null ? new WidgetTitle() : borderStyle.getTitle(); widgetTitle = widgetTitle == null ? new WidgetTitle() : widgetTitle; - populateFourmula(widgetTitle); + populateFormula(widgetTitle); populateFont(widgetTitle); underline.addMouseListener(new MouseAdapter() { @@ -683,7 +668,7 @@ public class LayoutBorderPane extends BasicPane { paintPreviewPane(); } - protected void populateFont(WidgetTitle widgetTitle){ + protected void populateFont(TitlePacker widgetTitle){ FRFont frFont = widgetTitle.getFrFont(); this.fontSizeComboBox.setSelectedItem(frFont.getSize()); this.fontSizeComboBox.addItemListener(new ItemListener() { @@ -756,7 +741,7 @@ public class LayoutBorderPane extends BasicPane { } - private void populateFourmula(WidgetTitle widgetTitle) { + private void populateFormula(TitlePacker widgetTitle) { this.formulaPane.populateBean(widgetTitle.getTextObject().toString()); this.formulaPane.getUITextField().getDocument() .addDocumentListener(new DocumentListener() { diff --git a/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPreviewPane.java b/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPreviewPane.java index 3d649f3b90..33470a33bc 100644 --- a/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPreviewPane.java +++ b/designer-form/src/main/java/com/fr/design/gui/xpane/LayoutBorderPreviewPane.java @@ -7,10 +7,10 @@ import com.fr.base.background.ColorBackground; import com.fr.design.designer.creator.cardlayout.XCardSwitchButton; import com.fr.design.gui.itextarea.UITextArea; import com.fr.form.ui.LayoutBorderStyle; -import com.fr.form.ui.WidgetTitle; import com.fr.general.Background; import com.fr.general.FRFont; +import com.fr.general.act.TitlePacker; import com.fr.stable.Constants; import javax.swing.JPanel; @@ -126,7 +126,7 @@ public class LayoutBorderPreviewPane extends JPanel{ g2d.setColor(new Color(237, 237, 237)); } g2d.setFont(frFont.applyResolutionNP(resolution)); - WidgetTitle title = borderStyle.getTitle(); + TitlePacker title = borderStyle.getTitle(); String paintText = title.getTextObject().toString(); int startX1 = 0; int startY = 0; @@ -158,7 +158,7 @@ public class LayoutBorderPreviewPane extends JPanel{ GraphHelper.draw(g,double2, borderStyle.getBorder()); } - private void drawTabBack(Graphics2D g2d, Graphics g, WidgetTitle title, FontMetrics fm, int startX1, int startY){ + private void drawTabBack(Graphics2D g2d, Graphics g, TitlePacker title, FontMetrics fm, int startX1, int startY){ Dimension d = getSize(); String paintText = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Title")+TAB_ZERO; From 7574a965388df153045fd737a230dd9d2867acf4 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Tue, 20 Aug 2019 09:37:07 +0800 Subject: [PATCH 14/60] =?UTF-8?q?REPORT-20329=20sonar=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/gui/frpane/UINumberSlidePane.java | 3 ++- .../src/main/java/com/fr/design/gui/frpane/UnitInputPane.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/frpane/UINumberSlidePane.java b/designer-base/src/main/java/com/fr/design/gui/frpane/UINumberSlidePane.java index 7585c09490..5faa21b3ca 100644 --- a/designer-base/src/main/java/com/fr/design/gui/frpane/UINumberSlidePane.java +++ b/designer-base/src/main/java/com/fr/design/gui/frpane/UINumberSlidePane.java @@ -14,6 +14,7 @@ import javax.swing.event.ChangeListener; import com.fr.design.beans.BasicBeanPane; import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.gui.style.NumberDragBar; +import com.fr.stable.AssistUtils; /** * 拖拽的滑条和对应滑条值的数字 @@ -65,7 +66,7 @@ public class UINumberSlidePane extends BasicBeanPane { public void checkValue(double value) { value = Math.max(value, minValue); value = Math.min(value, maxValue); - if (this.value == value) { + if (AssistUtils.equals(this.value, value)) { return; } double diff = Math.abs(value - this.value); diff --git a/designer-base/src/main/java/com/fr/design/gui/frpane/UnitInputPane.java b/designer-base/src/main/java/com/fr/design/gui/frpane/UnitInputPane.java index ca44c8a228..798b79af08 100644 --- a/designer-base/src/main/java/com/fr/design/gui/frpane/UnitInputPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/frpane/UnitInputPane.java @@ -10,6 +10,7 @@ import com.fr.design.gui.ispinner.UIBasicSpinner; import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.stable.AssistUtils; import com.fr.stable.StringUtils; import javax.swing.*; @@ -81,7 +82,7 @@ public abstract class UnitInputPane extends BasicPane { floatValue = de.floatValue(); } //选中多列, 并且列宽不完全一致的话, 就不显示值了. - temp.setText(floatValue == 0 ? StringUtils.EMPTY : Utils.convertNumberStringToString(new Float(floatValue))); + temp.setText(AssistUtils.equals(floatValue, 0) ? StringUtils.EMPTY : Utils.convertNumberStringToString(new Float(floatValue))); // denny:默认应该为选中,方便用户修改 temp.selectAll(); From 61cd191cb10de001c0e1d61e3b60314b003b65c9 Mon Sep 17 00:00:00 2001 From: Bryant Date: Tue, 20 Aug 2019 09:43:37 +0800 Subject: [PATCH 15/60] =?UTF-8?q?REPORT-20868=20sonar=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/gui/columnrow/ColumnRowPane.java | 2 ++ .../fr/design/gui/controlpane/ObjectUIControlPane.java | 4 ++-- .../main/java/com/fr/design/gui/date/UIDatePicker.java | 10 ++++++++-- .../java/com/fr/design/gui/demo/LoadingPaneDemo.java | 1 + .../com/fr/design/gui/frpane/LoadingBasicPaneTest.java | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java b/designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java index 615a17bcef..e94b182695 100644 --- a/designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/columnrow/ColumnRowPane.java @@ -146,6 +146,8 @@ public class ColumnRowPane extends JPanel implements UIObserver { if (cftf != null) { cftf.setColumns(3); // specify more width than we need cftf.setHorizontalAlignment(UITextField.LEFT); + }else { + throw new IllegalArgumentException("Spinner'Editor can not be null!"); } ((AbstractDocument) cftf.getDocument()).setDocumentFilter(new DocumentFilter() { diff --git a/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java b/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java index c5786b4c64..be169a744a 100644 --- a/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/controlpane/ObjectUIControlPane.java @@ -1,8 +1,8 @@ package com.fr.design.gui.controlpane; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import com.fr.design.beans.BasicBeanPane; +import com.fr.stable.AssistUtils; /** * Created by plough on 2017/8/1. @@ -48,7 +48,7 @@ public abstract class ObjectUIControlPane extends UIListControlPane { if (constructor != null) { return constructor; } else { - if (cls.getName() == Object.class.getName()) { + if (AssistUtils.equals(cls.getName(),Object.class.getName())) { return null; } return getConstructor(clazz, cls.getSuperclass()); diff --git a/designer-base/src/main/java/com/fr/design/gui/date/UIDatePicker.java b/designer-base/src/main/java/com/fr/design/gui/date/UIDatePicker.java index fb44f618f8..be3ef20a3a 100644 --- a/designer-base/src/main/java/com/fr/design/gui/date/UIDatePicker.java +++ b/designer-base/src/main/java/com/fr/design/gui/date/UIDatePicker.java @@ -157,7 +157,7 @@ public class UIDatePicker extends UIComboBox implements Serializable { /** * 设置当前选择的日期 */ - public void setSelectedDate(Date date) throws ParseException { + public synchronized void setSelectedDate(Date date) throws ParseException { if (date == null) { this.setSelectedItem(null); } else { @@ -165,6 +165,7 @@ public class UIDatePicker extends UIComboBox implements Serializable { } } + @Override public void setSelectedItem(Object anObject) { model.setSelectedItem(anObject); super.setSelectedItem(anObject); @@ -192,12 +193,14 @@ public class UIDatePicker extends UIComboBox implements Serializable { setBorder(BorderFactory.createEmptyBorder()); } + @Override public void hide() { if (isWillHide) { super.hide(); } } + @Override public void show() { if (isWillHide || UIDatePicker.this.isEnabled() == false) { return; @@ -211,6 +214,7 @@ public class UIDatePicker extends UIComboBox implements Serializable { /** * 显示弹出面板 */ + @Override protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { @@ -250,12 +254,14 @@ public class UIDatePicker extends UIComboBox implements Serializable { } } + @Override protected ComboBoxUI getUIComboBoxUI() { return new UIComboBoxUI() { + @Override protected ComboPopup createPopup() { return new DatePopup(comboBox); } - + @Override public void mousePressed(MouseEvent e) { if (UIDatePicker.this.isPopupVisible()) { isWillHide = true; diff --git a/designer-base/src/main/java/com/fr/design/gui/demo/LoadingPaneDemo.java b/designer-base/src/main/java/com/fr/design/gui/demo/LoadingPaneDemo.java index 2eb93ad3e0..b173237742 100644 --- a/designer-base/src/main/java/com/fr/design/gui/demo/LoadingPaneDemo.java +++ b/designer-base/src/main/java/com/fr/design/gui/demo/LoadingPaneDemo.java @@ -35,6 +35,7 @@ public class LoadingPaneDemo extends JPanel { Thread.sleep(500); } catch (InterruptedException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); + Thread.currentThread().interrupt(); } container.add(new UIButton(i + "adfadwdadawdwad")); } diff --git a/designer-base/src/main/java/com/fr/design/gui/frpane/LoadingBasicPaneTest.java b/designer-base/src/main/java/com/fr/design/gui/frpane/LoadingBasicPaneTest.java index 7c454ad715..e3a1ae7d7d 100644 --- a/designer-base/src/main/java/com/fr/design/gui/frpane/LoadingBasicPaneTest.java +++ b/designer-base/src/main/java/com/fr/design/gui/frpane/LoadingBasicPaneTest.java @@ -24,6 +24,7 @@ public class LoadingBasicPaneTest { Thread.sleep(500); } catch (InterruptedException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); + Thread.currentThread().interrupt(); } container.add(new UIButton(i + "adfadwdadawdwad")); } From dc0b27d09d4bc5a45fb276c8a27dbe2949b752a6 Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Tue, 20 Aug 2019 11:25:49 +0800 Subject: [PATCH 16/60] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=EF=BC=8Cs?= =?UTF-8?q?onar=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/gui/UIDefaultTheme.java | 3 --- .../gui/autocomplete/LanguageAwareCompletionProvider.java | 3 +++ .../gui/autocomplete/ParameterizedCompletionContext.java | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/UIDefaultTheme.java b/designer-base/src/main/java/com/fr/design/gui/UIDefaultTheme.java index 26030c47c9..78750e389a 100644 --- a/designer-base/src/main/java/com/fr/design/gui/UIDefaultTheme.java +++ b/designer-base/src/main/java/com/fr/design/gui/UIDefaultTheme.java @@ -76,7 +76,6 @@ public class UIDefaultTheme extends DefaultMetalTheme { table.put("Table.background", ThemeUtils.TEXT_BG_COLOR); table.put("Table.selectionForeground", ThemeUtils.NORMAL_FOREGROUND); table.put("Table.selectionBackground", new ColorUIResource(200, 221, 233)); - table.put("Table.gridColor", new ColorUIResource(200, 221, 233)); table.put("TableHeader.background", new ColorUIResource(229, 229, 229)); table.put("ProgressBar.foreground", ThemeUtils.PROCESS_COLOR); table.put("ProgressBar.background", ThemeUtils.TEXT_BG_COLOR); @@ -85,7 +84,6 @@ public class UIDefaultTheme extends DefaultMetalTheme { table.put("ProgressBar.selectionForeground", ThemeUtils.NORMAL_FOREGROUND); table.put("ProgressBar.selectionBackground", ThemeUtils.NORMAL_FOREGROUND); table.put("PopupMenu.background", ThemeUtils.NORMAL_BG); - table.put("TabbedPane.background", ThemeUtils.TEXT_BG_COLOR); table.put("TabbedPane.background", ThemeUtils.NORMAL_BG); table.put("TabbedPane.tabAreaInsets", new InsetsUIResource(4, 2, 0, 0)); table.put("TabbedPane.tabInsets", new InsetsUIResource(1, 6, 4, 6)); @@ -108,7 +106,6 @@ public class UIDefaultTheme extends DefaultMetalTheme { table.put("ComboBox.foreground", ThemeUtils.NORMAL_FOREGROUND); table.put("ComboBox.background", ThemeUtils.TEXT_BG_COLOR); table.put("ComboBox.disabledBackground", ThemeUtils.TEXT_DISABLED_BG_COLOR); - table.put("EditorPane.background", ThemeUtils.TEXT_BG_COLOR); table.put("EditorPane.foreground", ThemeUtils.NORMAL_FOREGROUND); table.put("PasswordField.background", ThemeUtils.TEXT_BG_COLOR); table.put("PasswordField.foreground", ThemeUtils.NORMAL_FOREGROUND); diff --git a/designer-base/src/main/java/com/fr/design/gui/autocomplete/LanguageAwareCompletionProvider.java b/designer-base/src/main/java/com/fr/design/gui/autocomplete/LanguageAwareCompletionProvider.java index b9d9afcc08..8bc805f464 100644 --- a/designer-base/src/main/java/com/fr/design/gui/autocomplete/LanguageAwareCompletionProvider.java +++ b/designer-base/src/main/java/com/fr/design/gui/autocomplete/LanguageAwareCompletionProvider.java @@ -195,6 +195,9 @@ public class LanguageAwareCompletionProvider extends CompletionProviderBase // provider. We do not do function/method completions while editing // strings or comments. CompletionProvider provider = getProviderFor(tc); + if (provider == null) { + return null; + } return provider==defaultProvider ? provider.getParameterizedCompletions(tc) : null; } diff --git a/designer-base/src/main/java/com/fr/design/gui/autocomplete/ParameterizedCompletionContext.java b/designer-base/src/main/java/com/fr/design/gui/autocomplete/ParameterizedCompletionContext.java index a9dd305b05..78d5e74a48 100644 --- a/designer-base/src/main/java/com/fr/design/gui/autocomplete/ParameterizedCompletionContext.java +++ b/designer-base/src/main/java/com/fr/design/gui/autocomplete/ParameterizedCompletionContext.java @@ -517,6 +517,10 @@ class ParameterizedCompletionContext { } } + if (currentNext == null) { + return; + } + // No params after caret - go to first one if (currentNext.getStartOffset() + 1 <= dot) { int nextIndex = getFirstHighlight(highlights); From ec9f79560fed24c0e1a8b0a5e31b8819718520a7 Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Wed, 21 Aug 2019 10:07:11 +0800 Subject: [PATCH 17/60] =?UTF-8?q?REPORT-19464=20=E3=80=90=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=A7=BB=E5=8A=A8=E7=AB=AF=E3=80=91TAB=E4=B8=8B?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=BC=8F=E5=9B=BE=E6=A0=87=E4=BC=98=E5=8C=96?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/layout/FRGUIPaneFactory.java | 2 +- .../mobile/ui/TabIconConfigPane.java | 26 ++++++++++++++++++- .../com/fr/design/web/CustomIconPane.java | 10 +++---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java b/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java index d906cc39e3..4f514477fa 100644 --- a/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java +++ b/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java @@ -213,7 +213,7 @@ public class FRGUIPaneFactory { public static JPanel createMediumHGapFlowInnerContainer_M_Pane_First0() { JPanel jp = new JPanel(); jp.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - jp.setLayout(new FRLeftFlowLayout(0, 20, 5)); + jp.setLayout(new FRLeftFlowLayout(0, 5, 0)); return jp; } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/TabIconConfigPane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/TabIconConfigPane.java index 724a9c9497..9fa9182d77 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/TabIconConfigPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/TabIconConfigPane.java @@ -11,6 +11,8 @@ import com.fr.design.web.CustomIconPane; import com.fr.form.ui.WidgetInfoConfig; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; +import com.fr.stable.StringUtils; + import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JPanel; @@ -33,6 +35,7 @@ import java.util.ArrayList; public class TabIconConfigPane extends JPanel { private UIButton editIconButton; + private UIButton deleteIconButton; private String curIconName; private IconButton selectIconButton; private ArrayList iconButtons = new ArrayList(); @@ -43,7 +46,7 @@ public class TabIconConfigPane extends JPanel { public void initComp(int count) { this.setLayout(FRGUIPaneFactory.createBorderLayout()); - JPanel panel = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + JPanel panel = FRGUIPaneFactory.createMediumHGapFlowInnerContainer_M_Pane_First0(); panel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); editIconButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit")); editIconButton.setFont(FRFont.getInstance("Helvetica", Font.PLAIN, 12, Color.decode("#3A383A"))); @@ -63,12 +66,28 @@ public class TabIconConfigPane extends JPanel { curIconName = cip.update(); setShowIconImage(); TabIconConfigPane.this.repaint(); + deleteIconButton.setEnabled(true); } }); editDialog.setVisible(true); } }); editIconButton.setEnabled(false); + + deleteIconButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Delete")); + deleteIconButton.setFont(FRFont.getInstance("Helvetica", Font.PLAIN, 12, Color.decode("#3A383A"))); + deleteIconButton.setPreferredSize(new Dimension(62, 20)); + panel.add(deleteIconButton); + deleteIconButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + curIconName = ""; + setShowIconImage(); + TabIconConfigPane.this.repaint(); + deleteIconButton.setEnabled(false); + } + }); + deleteIconButton.setEnabled(false); + this.add(panel, BorderLayout.CENTER); JPanel northPane = new JPanel(); @@ -163,6 +182,11 @@ public class TabIconConfigPane extends JPanel { public void actionPerformed(ActionEvent evt) { selectIconButton = this; editIconButton.setEnabled(true); + if (StringUtils.equals("", this.getIconName())) { + deleteIconButton.setEnabled(false); + } else { + deleteIconButton.setEnabled(true); + } TabIconConfigPane.this.repaint();// repaint } diff --git a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java index 74a4990300..35ff2afbaf 100644 --- a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java +++ b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java @@ -433,7 +433,7 @@ public class CustomIconPane extends BasicPane { JPanel imagePane = new JPanel(); imagePane.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 0)); showImageLabel = new UILabel(); - showImageLabel.setPreferredSize(new Dimension(20, 20)); + showImageLabel.setPreferredSize(new Dimension(50, 50)); imagePane.add(showImageLabel); imagePane.add(browseButton); Component[][] components = {{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Name") + ":"), nameTextField}, {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Icon") + ":"), imagePane}}; @@ -450,12 +450,12 @@ public class CustomIconPane extends BasicPane { if (JFileChooser.APPROVE_OPTION == jf.showOpenDialog(DesignerContext.getDesignerFrame())) { String path = jf.getSelectedFile().getAbsolutePath(); - // 将图片转化到16 × 16大小 + // 图片存储有最大值48*48限制,没有超过最大值时,按原图大小存储,超过最大值后,压缩至最大值存储 Image image = BaseUtils.readImage(path); - BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(IconManager.DEFAULT_ICONWIDTH, - IconManager.DEFAULT_ICONHEIGHT, BufferedImage.TYPE_INT_ARGB); + BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(image.getWidth(null) >= 48 ? IconManager.DEFAULT_ICONWIDTH + 32 : image.getWidth(null), + image.getHeight(null) >= 48 ? IconManager.DEFAULT_ICONHEIGHT + 32 : image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bufferedImage.createGraphics(); - g2d.drawImage(image, 0, 0, IconManager.DEFAULT_ICONWIDTH, IconManager.DEFAULT_ICONHEIGHT, null); + g2d.drawImage(image, 0, 0, image.getWidth(null) >= 48 ? IconManager.DEFAULT_ICONWIDTH + 32 : image.getWidth(null), image.getHeight(null) >= 48 ? IconManager.DEFAULT_ICONHEIGHT + 32 : image.getHeight(null), null); bufferedImage.flush(); g2d.dispose(); iconImage = bufferedImage; From 7800cc8235b3c13019146c32403b2b5581ac2837 Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Wed, 21 Aug 2019 10:51:21 +0800 Subject: [PATCH 18/60] =?UTF-8?q?REPORT-19464=20=E3=80=90=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=A7=BB=E5=8A=A8=E7=AB=AF=E3=80=91TAB=E4=B8=8B?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=BC=8F=E5=9B=BE=E6=A0=87=E4=BC=98=E5=8C=96?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/layout/FRGUIPaneFactory.java | 12 ++++++++++++ .../mainframe/mobile/ui/TabIconConfigPane.java | 8 ++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java b/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java index 4f514477fa..38097c2d91 100644 --- a/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java +++ b/designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java @@ -211,6 +211,18 @@ public class FRGUIPaneFactory { * @return JPanel对象 */ public static JPanel createMediumHGapFlowInnerContainer_M_Pane_First0() { + JPanel jp = new JPanel(); + jp.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + jp.setLayout(new FRLeftFlowLayout(0, 20, 5)); + return jp; + } + + /** + * 创建一个靠左空边框面板,间隔小,firsthgap 为0 + * + * @return JPanel对象 + */ + public static JPanel createTinyHGapFlowInnerContainer_M_Pane_First0() { JPanel jp = new JPanel(); jp.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); jp.setLayout(new FRLeftFlowLayout(0, 5, 0)); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/TabIconConfigPane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/TabIconConfigPane.java index 9fa9182d77..214156ef3f 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/TabIconConfigPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/TabIconConfigPane.java @@ -46,7 +46,7 @@ public class TabIconConfigPane extends JPanel { public void initComp(int count) { this.setLayout(FRGUIPaneFactory.createBorderLayout()); - JPanel panel = FRGUIPaneFactory.createMediumHGapFlowInnerContainer_M_Pane_First0(); + JPanel panel = FRGUIPaneFactory.createTinyHGapFlowInnerContainer_M_Pane_First0(); panel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); editIconButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Edit")); editIconButton.setFont(FRFont.getInstance("Helvetica", Font.PLAIN, 12, Color.decode("#3A383A"))); @@ -182,11 +182,7 @@ public class TabIconConfigPane extends JPanel { public void actionPerformed(ActionEvent evt) { selectIconButton = this; editIconButton.setEnabled(true); - if (StringUtils.equals("", this.getIconName())) { - deleteIconButton.setEnabled(false); - } else { - deleteIconButton.setEnabled(true); - } + deleteIconButton.setEnabled(StringUtils.isNotEmpty(this.getIconName())); TabIconConfigPane.this.repaint();// repaint } From d259b596fffa5d74ba3c3b6788b599fbf7b97942 Mon Sep 17 00:00:00 2001 From: jinbokai Date: Wed, 21 Aug 2019 10:52:41 +0800 Subject: [PATCH 19/60] REPORT-20328 sonar --- .../design/gui/iscrollbar/UIScrollBarUI.java | 16 ++++++++++----- .../com/fr/design/mainframe/JWorkBook.java | 12 +++++------ .../design/mainframe/errorinfo/ErrorInfo.java | 18 ++++++++++------- .../entity/FileEntityBuilder.java | 20 +++++++++++-------- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/iscrollbar/UIScrollBarUI.java b/designer-base/src/main/java/com/fr/design/gui/iscrollbar/UIScrollBarUI.java index da9aec9817..8054a29eac 100644 --- a/designer-base/src/main/java/com/fr/design/gui/iscrollbar/UIScrollBarUI.java +++ b/designer-base/src/main/java/com/fr/design/gui/iscrollbar/UIScrollBarUI.java @@ -1,5 +1,7 @@ package com.fr.design.gui.iscrollbar; +import com.fr.design.constants.UIConstants; +import com.fr.stable.StringUtils; import java.awt.Color; import java.awt.Component; import java.awt.Container; @@ -20,7 +22,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; - import javax.swing.BoundedRangeModel; import javax.swing.InputMap; import javax.swing.JComponent; @@ -38,8 +39,6 @@ import javax.swing.event.ChangeListener; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ScrollBarUI; import javax.swing.plaf.UIResource; - -import com.fr.design.constants.UIConstants; import sun.swing.DefaultLookup; /** @@ -148,6 +147,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo * * @param c */ + @Override public void installUI(JComponent c) { scrollbar = (JScrollBar) c; thumbRect = new Rectangle(0, 0, 0, 0); @@ -163,6 +163,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo * * @param c */ + @Override public void uninstallUI(JComponent c) { scrollbar = (JScrollBar) c; uninstallListeners(); @@ -357,6 +358,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo /** * 只画Thumb */ + @Override public void paint(Graphics g, JComponent c) { Rectangle thumbBounds = getThumbBounds(); if (thumbBounds.intersects(g.getClipBounds())) { @@ -380,6 +382,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo * @see #getMaximumSize * @see #getMinimumSize */ + @Override public Dimension getPreferredSize(JComponent c) { return (scrollbar.getOrientation() == JScrollBar.VERTICAL) ? new Dimension(scrollBarWidth, 48) : new Dimension(48, scrollBarWidth); } @@ -390,6 +393,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo * @see #getMinimumSize * @see #getPreferredSize */ + @Override public Dimension getMaximumSize(JComponent c) { return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); } @@ -937,6 +941,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo private transient int direction = +1; + @Override public void mouseReleased(MouseEvent e) { isPressing = false; if (isDragging) { @@ -968,6 +973,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo * one page. If there is no thumb then page up if the mouse is in the * upper half of the track. */ + @Override public void mousePressed(MouseEvent e) { boolean isMiddle = !isSupportsAbsolutePositioning() && SwingUtilities.isMiddleMouseButton(e); if (SwingUtilities.isRightMouseButton(e) || isMiddle) { @@ -1313,7 +1319,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo public void propertyChange(PropertyChangeEvent e) { String propertyName = e.getPropertyName(); - if ("model" == propertyName) { + if (StringUtils.equals("model", propertyName)) { BoundedRangeModel oldModel = (BoundedRangeModel) e.getOldValue(); BoundedRangeModel newModel = (BoundedRangeModel) e.getNewValue(); oldModel.removeChangeListener(modelListener); @@ -1329,4 +1335,4 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo } } } -} \ No newline at end of file +} diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java b/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java index 07136bc1ef..e5cb04b0fa 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java @@ -95,10 +95,6 @@ import com.fr.stable.module.Module; import com.fr.stable.project.ProjectConstants; import com.fr.web.controller.ViewRequestConstants; import com.fr.workspace.WorkContext; - -import javax.swing.Icon; -import javax.swing.JComponent; -import javax.swing.JPanel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileOutputStream; @@ -106,6 +102,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JPanel; /** * JWorkBook used to edit WorkBook. @@ -1103,9 +1102,8 @@ public class JWorkBook extends JTemplate { // 弹出输入参数 java.util.Map parameterMap = inputParameters(tpl); - try { - String fullPath = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), newFile.getPath()); - FileOutputStream fileOutputStream = new FileOutputStream(fullPath); + String fullPath = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), newFile.getPath()); + try (FileOutputStream fileOutputStream = new FileOutputStream(fullPath)) { EmbeddedTableDataExporter exporter = new EmbeddedTableDataExporter(); exporter.export(fileOutputStream, tpl, parameterMap); } catch (Exception e1) { diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java b/designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java index d22bcf75b9..4e733c7b1d 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java @@ -2,14 +2,17 @@ package com.fr.design.mainframe.errorinfo; import com.fr.base.FRContext; import com.fr.general.IOUtils; -import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.stable.EncodeConstants; import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.core.UUID; - -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.util.Date; @@ -124,13 +127,14 @@ public class ErrorInfo { String content = jo.toString(); String fileName = UUID.randomUUID() + ErrorInfoUploader.SUFFIX; File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), ErrorInfoUploader.FOLDER_NAME, fileName)); - try { + FileOutputStream out = null; + try (InputStream in = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) { StableUtils.makesureFileExist(file); - FileOutputStream out = new FileOutputStream(file); - InputStream in = new ByteArrayInputStream(content.getBytes(EncodeConstants.ENCODING_UTF_8)); + out = new FileOutputStream(file); IOUtils.copyBinaryTo(in, out); - out.close(); } catch (IOException ignore) { + } finally { + IOUtils.close(out); } } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java index 4497a0b28f..358672d232 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java @@ -19,7 +19,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.UUID; +import java.util.zip.ZipOutputStream; /** * @author alex sung @@ -52,13 +54,15 @@ public class FileEntityBuilder { return null; } File zipFile = null; + ZipOutputStream zipOut = null; try { zipFile = new File(pathName + ".zip"); - java.util.zip.ZipOutputStream zipOut = new java.util.zip.ZipOutputStream(new FileOutputStream(zipFile)); + zipOut = new ZipOutputStream(new FileOutputStream(zipFile)); IOUtils.zip(zipOut, new File(pathName)); - zipOut.close(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); + } finally { + IOUtils.close(zipOut); } return zipFile; } @@ -67,18 +71,18 @@ public class FileEntityBuilder { if (jsonArray.size() == 0) { return; } - try { - String content = jsonArray.toString(); + FileOutputStream out = null; + String content = jsonArray.toString(); + try (InputStream in = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) { String fileName = String.valueOf(UUID.randomUUID()); File file = new File(folderName + File.separator + fileName + ".json"); StableUtils.makesureFileExist(file); - FileOutputStream out = new FileOutputStream(file); - InputStream in = new ByteArrayInputStream(content.getBytes(EncodeConstants.ENCODING_UTF_8)); + out = new FileOutputStream(file); IOUtils.copyBinaryTo(in, out); - in.close(); - out.close(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); + } finally { + IOUtils.close(out); } } From c5e72eceb201dd3bbd99a850ea62a7ee6d5e467d Mon Sep 17 00:00:00 2001 From: Maksim Date: Wed, 21 Aug 2019 11:06:59 +0800 Subject: [PATCH 20/60] =?UTF-8?q?REPORT-20323=20sonar=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/gui/icombobox/UIComboBoxButton.java | 12 ------------ .../design/gui/icontainer/UIResizableContainer.java | 5 ----- .../com/fr/design/gui/ilable/MultilineLabel.java | 6 +++--- .../com/fr/design/gui/imenu/UIBasicMenuItemUI.java | 2 +- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBoxButton.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBoxButton.java index a5ebf7b56b..9f96f655eb 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBoxButton.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBoxButton.java @@ -127,10 +127,6 @@ public class UIComboBoxButton extends JButton { boolean savedOpaque = false; paintRender(g, c, mustResetOpaque, savedOpaque, leftToRight, width, insets, iconWidth, left, top, height); - if (mustResetOpaque) { - JComponent jc = (JComponent) c; - jc.setOpaque(savedOpaque); - } } private void paintRender(Graphics g, Component c, boolean mustResetOpaque, boolean savedOpaque, boolean leftToRight, @@ -152,14 +148,6 @@ public class UIComboBoxButton extends JButton { } else { rendererPane.paintComponent(g, c, this, left + iconWidth, top, cWidth, height, shouldValidate); } - if (paintFocus && ThemeUtils.COMBO_FOCUS) { - g.setColor(Color.black); - Graphics2D g2d = (Graphics2D) g; - Rectangle r = new Rectangle(left, top, 2, 2); - TexturePaint tp = new TexturePaint(focusImg, r); - g2d.setPaint(tp); - g2d.draw(new Rectangle(left, top, cWidth, height)); - } } } diff --git a/designer-base/src/main/java/com/fr/design/gui/icontainer/UIResizableContainer.java b/designer-base/src/main/java/com/fr/design/gui/icontainer/UIResizableContainer.java index 73199d2ab2..0a8529abf3 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icontainer/UIResizableContainer.java +++ b/designer-base/src/main/java/com/fr/design/gui/icontainer/UIResizableContainer.java @@ -438,11 +438,6 @@ public class UIResizableContainer extends JPanel { containerWidth = containerWidth > MAX_WIDTH ? MAX_WIDTH : containerWidth; containerWidth = containerWidth < MIN_WIDTH ? MIN_WIDTH : containerWidth; - if (containerWidth < MIN_WIDTH) { - upPane.setVisible(false); - downPane.setVisible(false); - containerWidth = toolPaneHeight; - } refreshContainer(); if (DesignerMode.isAuthorityEditing()) { DesignerContext.getDesignerFrame().doResize(); diff --git a/designer-base/src/main/java/com/fr/design/gui/ilable/MultilineLabel.java b/designer-base/src/main/java/com/fr/design/gui/ilable/MultilineLabel.java index bb890447fa..8934e862a4 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ilable/MultilineLabel.java +++ b/designer-base/src/main/java/com/fr/design/gui/ilable/MultilineLabel.java @@ -19,15 +19,15 @@ import com.fr.design.gui.itextarea.UITextArea; */ public class MultilineLabel extends UITextArea { public MultilineLabel() { - initComponents(); + initCurrentComponents(); } public MultilineLabel(String s) { super(s); - initComponents(); + initCurrentComponents(); } - private void initComponents() { + private void initCurrentComponents() { adjustUI(); } diff --git a/designer-base/src/main/java/com/fr/design/gui/imenu/UIBasicMenuItemUI.java b/designer-base/src/main/java/com/fr/design/gui/imenu/UIBasicMenuItemUI.java index 61587beef2..1c07c8260d 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenu/UIBasicMenuItemUI.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenu/UIBasicMenuItemUI.java @@ -579,7 +579,7 @@ public class UIBasicMenuItemUI extends MenuItemUI { */ private boolean isInternalFrameSystemMenu() { String actionCommand = menuItem.getActionCommand(); - return (actionCommand == "Close") || (actionCommand == "Minimize") || (actionCommand == "Restore") || (actionCommand == "Maximize"); + return (actionCommand.equals("Close")) || (actionCommand.equals("Minimize")) || (actionCommand.equals("Restore")) || (actionCommand.equals("Maximize")); } ////////////////////////////////////////////////////////// From 3d5a891ae6d3de7bac290b70b8f9992a636504aa Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Wed, 21 Aug 2019 15:23:24 +0800 Subject: [PATCH 21/60] =?UTF-8?q?REPORT-19464=20=E3=80=90=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=A7=BB=E5=8A=A8=E7=AB=AF=E3=80=91TAB=E4=B8=8B?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=BC=8F=E5=9B=BE=E6=A0=87=E4=BC=98=E5=8C=96?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/web/CustomIconPane.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java index 35ff2afbaf..bc21d4c731 100644 --- a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java +++ b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java @@ -452,10 +452,10 @@ public class CustomIconPane extends BasicPane { String path = jf.getSelectedFile().getAbsolutePath(); // 图片存储有最大值48*48限制,没有超过最大值时,按原图大小存储,超过最大值后,压缩至最大值存储 Image image = BaseUtils.readImage(path); - BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(image.getWidth(null) >= 48 ? IconManager.DEFAULT_ICONWIDTH + 32 : image.getWidth(null), - image.getHeight(null) >= 48 ? IconManager.DEFAULT_ICONHEIGHT + 32 : image.getHeight(null), BufferedImage.TYPE_INT_ARGB); + BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(image.getWidth(null) >= 48 ? IconManager.MAXSTORAGE_ICONWIDTH : image.getWidth(null), + image.getHeight(null) >= 48 ? IconManager.MAXSTORAGE_ICONHEIGHT : image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bufferedImage.createGraphics(); - g2d.drawImage(image, 0, 0, image.getWidth(null) >= 48 ? IconManager.DEFAULT_ICONWIDTH + 32 : image.getWidth(null), image.getHeight(null) >= 48 ? IconManager.DEFAULT_ICONHEIGHT + 32 : image.getHeight(null), null); + g2d.drawImage(image, 0, 0, image.getWidth(null) >= 48 ? IconManager.MAXSTORAGE_ICONWIDTH : image.getWidth(null), image.getHeight(null) >= 48 ? IconManager.MAXSTORAGE_ICONHEIGHT : image.getHeight(null), null); bufferedImage.flush(); g2d.dispose(); iconImage = bufferedImage; From d1b2e791e487dc66577fa19883dc9e27daaf0ea0 Mon Sep 17 00:00:00 2001 From: Hades Date: Wed, 21 Aug 2019 15:37:54 +0800 Subject: [PATCH 22/60] REPORT-19462 --- .../gui/icombocheckbox/UICheckListPopup.java | 51 +++++++--- .../gui/icombocheckbox/UIComboCheckBox.java | 27 +++++- .../designer/mobile/BodyMobileDefinePane.java | 40 +++++--- .../mobile/TabMobileWidgetDefinePane.java | 19 ++-- .../component/MobileComponentFrozenPane.java | 92 +++++++++++++++++++ .../MobileComponentLayoutIntervalPane.java | 18 +--- ...ne.java => MobileComponentMarginPane.java} | 10 +- 7 files changed, 200 insertions(+), 57 deletions(-) create mode 100644 designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentFrozenPane.java rename designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/{MobileComponentAdvancePane.java => MobileComponentMarginPane.java} (77%) diff --git a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java index a0f4420743..b0b57f29c3 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java @@ -7,12 +7,25 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.icon.IconPathConstants; import com.fr.design.layout.FRGUIPaneFactory; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; +import com.fr.general.IOUtils; + +import javax.swing.JCheckBox; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; public class UICheckListPopup extends UIPopupMenu { private List listeners = new ArrayList(); @@ -66,10 +79,10 @@ public class UICheckListPopup extends UIPopupMenu { } addSelectListener(); - jScrollPane.setPreferredSize(new Dimension(200, checkBoxList.size() * CHECKBOX_HEIGHT + 10)); + jScrollPane.setPreferredSize(new Dimension(130, checkBoxList.size() * CHECKBOX_HEIGHT + 10)); //超过1页的数量时显示滚动条 if (checkBoxList.size() > maxDisplayNumber) { - jScrollPane.setPreferredSize(new Dimension(200, maxDisplayNumber * CHECKBOX_HEIGHT)); + jScrollPane.setPreferredSize(new Dimension(130, maxDisplayNumber * CHECKBOX_HEIGHT)); } checkboxPane.repaint(); jScrollPane.repaint(); @@ -77,11 +90,11 @@ public class UICheckListPopup extends UIPopupMenu { private void addOneCheckValue(Object checkValue) { JPanel checkPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); - checkPane.setPreferredSize(new Dimension(185, CHECKBOX_HEIGHT)); + checkPane.setPreferredSize(new Dimension(120, CHECKBOX_HEIGHT)); final JCheckBox temp = createCheckbox(); final UILabel label = new UILabel(checkValue.toString()); label.setBackground(Color.WHITE); - label.setPreferredSize(new Dimension(156, 20)); + label.setPreferredSize(new Dimension(80, 20)); checkPane.setBackground(Color.WHITE); checkPane.add(temp); checkPane.add(label); @@ -95,8 +108,8 @@ public class UICheckListPopup extends UIPopupMenu { JCheckBox checkBox = new JCheckBox(); checkBox.setPreferredSize(new Dimension(20, 20)); checkBox.setBackground(Color.WHITE); - checkBox.setIcon(BaseUtils.readIcon(IconPathConstants.CHECKBOX_NORMAL)); - checkBox.setSelectedIcon(BaseUtils.readIcon(IconPathConstants.CHECKBOX_SELECTED)); + checkBox.setIcon(IOUtils.readIcon(IconPathConstants.CHECKBOX_NORMAL)); + checkBox.setSelectedIcon(IOUtils.readIcon(IconPathConstants.CHECKBOX_SELECTED)); return checkBox; } @@ -109,10 +122,12 @@ public class UICheckListPopup extends UIPopupMenu { */ private void addMouseListener(final JCheckBox checkBox, final UILabel label) { label.addMouseListener(new MouseAdapter() { + @Override public void mouseExited(MouseEvent e) { label.setBackground(Color.WHITE); } + @Override public void mouseEntered(MouseEvent e) { label.setOpaque(true); label.setBackground(mouseEnteredColor); @@ -133,6 +148,7 @@ public class UICheckListPopup extends UIPopupMenu { JCheckBox checkBox = checkBoxList.get(i); if (i == 0) { checkBox.addItemListener(new ItemListener() { + @Override public void itemStateChanged(ItemEvent e) { //全选checkbox事件 doSelectAll(checkBoxList.get(0).isSelected()); @@ -140,6 +156,7 @@ public class UICheckListPopup extends UIPopupMenu { }); } else { checkBox.addItemListener(new ItemListener() { + @Override public void itemStateChanged(ItemEvent e) { //do半选判断放在commit事件里 commit(); @@ -157,8 +174,17 @@ public class UICheckListPopup extends UIPopupMenu { private void doSelectAll(boolean isSelected) { for (int i = 1; i < checkBoxList.size(); i++) { //全选和反全选都不考虑全选按钮本身 - if (!SELECT_ALL.equals(checkBoxList.get(i).getText())) + if (!SELECT_ALL.equals(checkBoxList.get(i).getText())) { checkBoxList.get(i).setSelected(isSelected); + } + } + } + + public void setSelectedValue(Map selectedValues) { + List allValue = Arrays.asList(values); + for (Object value : selectedValues.keySet()) { + int index = allValue.indexOf(value); + checkBoxList.get(index + 1).setSelected(selectedValues.get(value)); } } @@ -214,8 +240,9 @@ public class UICheckListPopup extends UIPopupMenu { } public void addActionListener(ActionListener listener) { - if (!listeners.contains(listener)) + if (!listeners.contains(listener)) { listeners.add(listener); + } } public void removeActionListener(ActionListener listener) { diff --git a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java index 11cfeb6fe4..e570ee515d 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java @@ -11,14 +11,23 @@ import com.fr.design.icon.IconPathConstants; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.stable.StringUtils; -import javax.swing.*; -import java.awt.*; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.FontMetrics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * 设计器下拉复选框组件 @@ -125,7 +134,7 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam private UITextField createEditor() { UITextField editor = new UITextField(); editor.setEditable(false); - editor.setPreferredSize(new Dimension(180, 20)); + editor.setPreferredSize(new Dimension(110, 20)); addPopupListener(editor); return editor; @@ -138,6 +147,7 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam */ private void addPopupListener(Component component) { component.addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { togglePopup(); } @@ -166,6 +176,7 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam private class PopupAction implements ActionListener { + @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(UICheckListPopup.COMMIT_EVENT)) { selectedValues = popup.getSelectedValues(); @@ -292,13 +303,15 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam } public void addActionListener(ActionListener listener) { - if (!listeners.contains(listener)) + if (!listeners.contains(listener)) { listeners.add(listener); + } } public void removeActionListener(ActionListener listener) { - if (listeners.contains(listener)) + if (listeners.contains(listener)) { listeners.remove(listener); + } } protected void fireActionPerformed(ActionEvent e) { @@ -307,6 +320,10 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam } } + public void setSelectedValues(Map map) { + popup.setSelectedValue(map); + } + /** * 简单的测试demo * @param args diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/BodyMobileDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/BodyMobileDefinePane.java index b91e1d7b68..bfd0ea7ea7 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/BodyMobileDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/BodyMobileDefinePane.java @@ -11,7 +11,8 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.MobileWidgetListPane; import com.fr.design.mainframe.WidgetPropertyPane; -import com.fr.design.widget.ui.designer.mobile.component.MobileComponentAdvancePane; +import com.fr.design.widget.ui.designer.mobile.component.MobileComponentFrozenPane; +import com.fr.design.widget.ui.designer.mobile.component.MobileComponentMarginPane; import com.fr.design.widget.ui.designer.mobile.component.MobileComponentLayoutIntervalPane; import com.fr.form.ui.RichStyleWidgetProvider; import com.fr.form.ui.container.WFitLayout; @@ -30,8 +31,11 @@ public class BodyMobileDefinePane extends MobileWidgetDefinePane { private AttributeChangeListener changeListener; private UICheckBox appRelayoutCheck; private MobileWidgetListPane mobileWidgetListPane; - private MobileComponentAdvancePane advancePane; + private MobileComponentMarginPane marginPane; private MobileComponentLayoutIntervalPane intervalPane; + private MobileComponentFrozenPane frozenPane; + private UIExpandablePane advancePane; + private UIExpandablePane layoutPane; public BodyMobileDefinePane(XCreator xCreator) { this.bodyCreator = xCreator; @@ -89,16 +93,23 @@ public class BodyMobileDefinePane extends MobileWidgetDefinePane { private JPanel createNorthPane() { JPanel holder = FRGUIPaneFactory.createBorderLayout_S_Pane(); holder.add(getMobilePropertyPane(), BorderLayout.NORTH); - - advancePane = new MobileComponentAdvancePane(FormBodyPaddingAttrMark.XML_TAG); + marginPane = new MobileComponentMarginPane(FormBodyPaddingAttrMark.XML_TAG); intervalPane = new MobileComponentLayoutIntervalPane(FormBodyPaddingAttrMark.XML_TAG); + frozenPane = new MobileComponentFrozenPane(); + JPanel wrapLayoutPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + wrapLayoutPane.add(intervalPane, BorderLayout.NORTH); + wrapLayoutPane.add(frozenPane, BorderLayout.CENTER); + advancePane = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, marginPane); + layoutPane = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout"), 280, 20, wrapLayoutPane); //高级 holder.add(advancePane, BorderLayout.CENTER); //布局 - holder.add(intervalPane, BorderLayout.SOUTH); + holder.add(layoutPane, BorderLayout.SOUTH); - advancePane.setVisible(!shouldHidePadding(designer)); - intervalPane.setVisible(!shouldHidePadding(designer)); + boolean flag = !shouldHidePadding(designer); + advancePane.setVisible(flag); + layoutPane.setVisible(flag); + frozenPane.setVisible(appRelayoutCheck.isSelected()); return holder; } @@ -137,13 +148,12 @@ public class BodyMobileDefinePane extends MobileWidgetDefinePane { public void populate(FormDesigner designer) { this.designer = designer; appRelayoutCheck.setSelected(FormDesignerUtils.isAppRelayout(designer)); - // 数据 populate 完成后,再设置监听 this.bindListeners2Widgets(); this.addAttributeChangeListener(changeListener); - - advancePane.populate((RichStyleWidgetProvider) getBodyCreator().toData()); + marginPane.populate((RichStyleWidgetProvider) getBodyCreator().toData()); intervalPane.populate((RichStyleWidgetProvider) getBodyCreator().toData()); + frozenPane.populate(designer.getSelectionModel().getSelection().getSelectedCreator()); } @Override @@ -152,15 +162,19 @@ public class BodyMobileDefinePane extends MobileWidgetDefinePane { setAppRelayout(appRelayoutCheck.isSelected()); boolean appPaddingVisible = appRelayout || !FormDesignerUtils.isBodyAbsolute(designer); advancePane.setVisible(appPaddingVisible); - intervalPane.setVisible(appPaddingVisible); + layoutPane.setVisible(appPaddingVisible); + frozenPane.setVisible(appRelayout); mobileWidgetListPane.updateToDesigner(); designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_EDITED); if (advancePane.isVisible()) { - advancePane.update((RichStyleWidgetProvider) getBodyCreator().toData()); + marginPane.update((RichStyleWidgetProvider) getBodyCreator().toData()); } - if (intervalPane.isVisible()) { + if (layoutPane.isVisible()) { intervalPane.update((RichStyleWidgetProvider) getBodyCreator().toData()); } + if (appRelayout) { + frozenPane.update(designer.getSelectionModel().getSelection().getSelectedCreator()); + } } } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/TabMobileWidgetDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/TabMobileWidgetDefinePane.java index 8a795b8873..5cf7f74f78 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/TabMobileWidgetDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/TabMobileWidgetDefinePane.java @@ -4,6 +4,7 @@ import com.fr.base.iofile.attr.FormTabPaddingAttrMark; import com.fr.design.constants.LayoutConstants; import com.fr.design.designer.IntervalConstants; import com.fr.design.designer.creator.XCreator; +import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.gui.frpane.AttributeChangeListener; import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.FRGUIPaneFactory; @@ -13,7 +14,7 @@ import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.mainframe.widget.accessibles.AccessibleTemplateStyleEditor; import com.fr.design.mainframe.widget.accessibles.MobileTemplateStylePane; -import com.fr.design.widget.ui.designer.mobile.component.MobileComponentAdvancePane; +import com.fr.design.widget.ui.designer.mobile.component.MobileComponentMarginPane; import com.fr.design.widget.ui.designer.mobile.component.MobileComponentLayoutIntervalPane; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.general.cardtag.mobile.MobileTemplateStyle; @@ -27,7 +28,7 @@ public class TabMobileWidgetDefinePane extends MobileWidgetDefinePane { private FormDesigner designer; // 当前设计器 private AccessibleTemplateStyleEditor templateStyleEditor; private AttributeChangeListener changeListener; - private MobileComponentAdvancePane advancePane; + private MobileComponentMarginPane marginPane; private MobileComponentLayoutIntervalPane intervalPane; public TabMobileWidgetDefinePane(XCreator xCreator) { @@ -61,12 +62,14 @@ public class TabMobileWidgetDefinePane extends MobileWidgetDefinePane { JPanel holder = FRGUIPaneFactory.createBorderLayout_S_Pane(); holder.add(jPanel, BorderLayout.NORTH); if (!shouldHidePadding(designer)) { - advancePane = new MobileComponentAdvancePane(FormTabPaddingAttrMark.XML_TAG); + marginPane = new MobileComponentMarginPane(FormTabPaddingAttrMark.XML_TAG); intervalPane = new MobileComponentLayoutIntervalPane(FormTabPaddingAttrMark.XML_TAG); + UIExpandablePane advancePane = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, marginPane); + UIExpandablePane layoutPane = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout"), 280, 20, intervalPane); //高级 holder.add(advancePane, BorderLayout.CENTER); //布局 - holder.add(intervalPane, BorderLayout.SOUTH); + holder.add(layoutPane, BorderLayout.SOUTH); } this.add(holder, BorderLayout.NORTH); @@ -78,8 +81,8 @@ public class TabMobileWidgetDefinePane extends MobileWidgetDefinePane { // 数据 populate 完成后,再设置监听 this.bindListeners2Widgets(); this.addAttributeChangeListener(changeListener); - if (advancePane != null) {//业务层面可以写成shouldHidePadding但是这样写应该性能差点 - advancePane.populate((WCardTagLayout) xCreator.toData()); + if (marginPane != null) {//业务层面可以写成shouldHidePadding但是这样写应该性能差点 + marginPane.populate((WCardTagLayout) xCreator.toData()); } if (intervalPane != null) { intervalPane.populate((WCardTagLayout) xCreator.toData()); @@ -90,8 +93,8 @@ public class TabMobileWidgetDefinePane extends MobileWidgetDefinePane { public void update() { ((WCardTagLayout) xCreator.toData()).setMobileTemplateStyle((MobileTemplateStyle) templateStyleEditor.getValue()); DesignerContext.getDesignerFrame().getSelectedJTemplate().fireTargetModified(); // 触发设计器保存按钮亮起来 - if (advancePane != null) { - advancePane.update((WCardTagLayout) xCreator.toData()); + if (marginPane != null) { + marginPane.update((WCardTagLayout) xCreator.toData()); } if (intervalPane != null) { intervalPane.update((WCardTagLayout) xCreator.toData()); diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentFrozenPane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentFrozenPane.java new file mode 100644 index 0000000000..0d5ce4b711 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentFrozenPane.java @@ -0,0 +1,92 @@ +package com.fr.design.widget.ui.designer.mobile.component; + +import com.fr.design.designer.IntervalConstants; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.dialog.BasicPane; +import com.fr.design.gui.icombocheckbox.UIComboCheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.WidgetPropertyPane; +import com.fr.design.utils.gui.UIComponentUtils; +import com.fr.design.widget.FRWidgetFactory; +import com.fr.form.ui.Widget; +import com.fr.form.ui.container.WSortLayout; +import com.fr.stable.ArrayUtils; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Component; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Hades + * @date 2019/8/14 + */ +public class MobileComponentFrozenPane extends BasicPane { + + private UIComboCheckBox uiComboCheckBox; + + public MobileComponentFrozenPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + UILabel frozenLabel = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Component_Frozen")); + uiComboCheckBox = new UIComboCheckBox(initData()); + JPanel wrapJPanel = UIComponentUtils.wrapWithBorderLayoutPane(uiComboCheckBox); + Component[][] components = new Component[][]{ + new Component[]{frozenLabel, wrapJPanel} + }; + JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1); + centerPane.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L1, IntervalConstants.INTERVAL_L5, 10, 0)); + JPanel holder = FRGUIPaneFactory.createBorderLayout_S_Pane(); + holder.add(centerPane, BorderLayout.NORTH); + this.add(holder, BorderLayout.NORTH); + } + + private String[] initData() { + FormDesigner designer = WidgetPropertyPane.getInstance().getEditingFormDesigner(); + XCreator selectedCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); + Widget selectedModel = selectedCreator != null ? selectedCreator.toData() : null; + + if (selectedModel == null || !selectedModel.acceptType(WSortLayout.class)) { + return ArrayUtils.EMPTY_STRING_ARRAY; + } + + List widgetList = ((WSortLayout) selectedModel).getNonContainerWidgetList(); + return widgetList.toArray(new String[0]); + } + + public void update(XCreator xCreator) { + List selected = new ArrayList<>(); + WSortLayout wSortLayout = ((WSortLayout) xCreator.toData()); + Object[] values = uiComboCheckBox.getSelectedValues(); + for (Object widgetName : values) { + selected.add((String) widgetName); + } + wSortLayout.updateFrozenWidgets(selected); + } + + public void populate(XCreator xCreator) { + WSortLayout wSortLayout = ((WSortLayout) xCreator.toData()); + List all = wSortLayout.getNonContainerWidgetList(); + List selected = wSortLayout.getFrozenWidgets(); + Map map = new LinkedHashMap<>(); + for (String value : selected) { + map.put(value, true); + } + all.removeAll(selected); + for (String value : all) { + map.put(value, false); + } + uiComboCheckBox.setSelectedValues(map); + } + + @Override + protected String title4PopupWindow() { + return "ComponentFrozenPane"; + } +} diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentLayoutIntervalPane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentLayoutIntervalPane.java index 5a565373d9..169b014a0a 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentLayoutIntervalPane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentLayoutIntervalPane.java @@ -3,7 +3,6 @@ package com.fr.design.widget.ui.designer.mobile.component; import com.fr.base.iofile.attr.AttrMarkFactory; import com.fr.base.iofile.attr.FormBodyPaddingAttrMark; import com.fr.design.designer.IntervalConstants; -import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.layout.FRGUIPaneFactory; @@ -29,24 +28,17 @@ public class MobileComponentLayoutIntervalPane extends XmlRelationedBasicPane { super(xmlTag); this.setLayout(FRGUIPaneFactory.createBorderLayout()); UILabel intervalLabel = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Component_Interval")); - - double f = TableLayout.FILL; - double p = TableLayout.PREFERRED; - double[] rowSize = {p, p}; - double[] columnSize = {p, f}; - int[][] rowCount = {{1, 1}, {1, 1}}; componentIntervel = new UISpinner(0, Integer.MAX_VALUE, 1, FormBodyPaddingAttrMark.DEFAULT_SIZE); - JPanel componentIntervelPane = UIComponentUtils.wrapWithBorderLayoutPane(componentIntervel); + JPanel componentIntervalPane = UIComponentUtils.wrapWithBorderLayoutPane(componentIntervel); Component[][] components = new Component[][]{ - new Component[]{intervalLabel, componentIntervelPane} + new Component[]{intervalLabel, componentIntervalPane} }; - JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1); - centerPane.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L1, IntervalConstants.INTERVAL_L5, 0, 0)); + JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1); + centerPane.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L1, IntervalConstants.INTERVAL_L5, 10, 0)); JPanel holder = FRGUIPaneFactory.createBorderLayout_S_Pane(); holder.add(centerPane, BorderLayout.NORTH); - UIExpandablePane layoutExpandablePane = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout"), 280, 20, holder); - this.add(layoutExpandablePane, BorderLayout.NORTH); + this.add(holder, BorderLayout.NORTH); } @Override diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentAdvancePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentMarginPane.java similarity index 77% rename from designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentAdvancePane.java rename to designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentMarginPane.java index f94d579079..7a1bb34eee 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentAdvancePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/component/MobileComponentMarginPane.java @@ -2,7 +2,6 @@ package com.fr.design.widget.ui.designer.mobile.component; import com.fr.base.iofile.attr.AttrMarkFactory; import com.fr.base.iofile.attr.FormBodyPaddingAttrMark; -import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.widget.ui.designer.XmlRelationedBasicPane; import com.fr.design.widget.ui.designer.component.PaddingBoundPane; @@ -13,20 +12,19 @@ import java.awt.BorderLayout; /** * 只有内边距设置的高级设置 */ -public class MobileComponentAdvancePane extends XmlRelationedBasicPane { +public class MobileComponentMarginPane extends XmlRelationedBasicPane { private PaddingBoundPane paddingBound; - public MobileComponentAdvancePane(String xmlTag) { + public MobileComponentMarginPane(String xmlTag) { super(xmlTag); this.setLayout(FRGUIPaneFactory.createBorderLayout()); paddingBound = new PaddingBoundPane(FormBodyPaddingAttrMark.DEFAULT_SIZE, FormBodyPaddingAttrMark.DEFAULT_SIZE, FormBodyPaddingAttrMark.DEFAULT_SIZE, FormBodyPaddingAttrMark.DEFAULT_SIZE); - UIExpandablePane advanceExpandablePane = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), 280, 20, paddingBound); - this.add(advanceExpandablePane, BorderLayout.NORTH); + this.add(paddingBound, BorderLayout.NORTH); } @Override protected String title4PopupWindow() { - return "ComponentAdvancePane"; + return "ComponentMarginPane"; } public void update(RichStyleWidgetProvider marginWidget) { From 6e65fd6e0a9ee8190fad98dfbe6d35ff4d1baf2f Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Wed, 21 Aug 2019 18:28:07 +0800 Subject: [PATCH 23/60] =?UTF-8?q?REPORT-19464=20=E3=80=90=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=A7=BB=E5=8A=A8=E7=AB=AF=E3=80=91TAB=E4=B8=8B?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=BC=8F=E5=9B=BE=E6=A0=87=E4=BC=98=E5=8C=96?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/web/CustomIconPane.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java index bc21d4c731..0231963b9c 100644 --- a/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java +++ b/designer-base/src/main/java/com/fr/design/web/CustomIconPane.java @@ -452,10 +452,10 @@ public class CustomIconPane extends BasicPane { String path = jf.getSelectedFile().getAbsolutePath(); // 图片存储有最大值48*48限制,没有超过最大值时,按原图大小存储,超过最大值后,压缩至最大值存储 Image image = BaseUtils.readImage(path); - BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(image.getWidth(null) >= 48 ? IconManager.MAXSTORAGE_ICONWIDTH : image.getWidth(null), - image.getHeight(null) >= 48 ? IconManager.MAXSTORAGE_ICONHEIGHT : image.getHeight(null), BufferedImage.TYPE_INT_ARGB); + BufferedImage bufferedImage = CoreGraphHelper.createBufferedImage(Math.min(image.getWidth(null), IconManager.MAXSTORAGE_ICONWIDTH), + Math.min(image.getHeight(null), IconManager.MAXSTORAGE_ICONHEIGHT), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bufferedImage.createGraphics(); - g2d.drawImage(image, 0, 0, image.getWidth(null) >= 48 ? IconManager.MAXSTORAGE_ICONWIDTH : image.getWidth(null), image.getHeight(null) >= 48 ? IconManager.MAXSTORAGE_ICONHEIGHT : image.getHeight(null), null); + g2d.drawImage(image, 0, 0, Math.min(image.getWidth(null), IconManager.MAXSTORAGE_ICONWIDTH), Math.min(image.getHeight(null), IconManager.MAXSTORAGE_ICONHEIGHT), null); bufferedImage.flush(); g2d.dispose(); iconImage = bufferedImage; From ff6238a50f9d5717b2c789126a71232bcdb93b91 Mon Sep 17 00:00:00 2001 From: author Date: Thu, 22 Aug 2019 18:15:06 +0800 Subject: [PATCH 24/60] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=EF=BC=8Cs?= =?UTF-8?q?onar=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/gui/icheckbox/UICheckBox.java | 100 +++++++++--------- .../fr/design/gui/icheckbox/UICheckBoxUI.java | 2 +- .../fr/design/gui/icombobox/LazyComboBox.java | 1 + .../gui/icombobox/LazyComboBoxTest.java | 1 + 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java index 7489b4f592..10ea06a8ce 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java @@ -125,60 +125,58 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser private class UICheckBoxUI extends MetalCheckBoxUI { @Override - public void paint(Graphics g, JComponent c) { - synchronized (this) { - AbstractButton b = (AbstractButton) c; - ButtonModel model = b.getModel(); - Dimension size = c.getSize(); - Font f = c.getFont(); - g.setFont(f); - FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f); - - Rectangle viewRect = new Rectangle(size); - Rectangle iconRect = new Rectangle(); - Rectangle textRect = new Rectangle(); - - Insets i = c.getInsets(); - viewRect.x += i.left; - viewRect.y += i.top; - viewRect.width -= (i.right + viewRect.x); - viewRect.height -= (i.bottom + viewRect.y); - - Icon altIcon = b.getIcon(); - - String text = SwingUtilities.layoutCompoundLabel( - c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(), - b.getVerticalAlignment(), b.getHorizontalAlignment(), - b.getVerticalTextPosition(), b.getHorizontalTextPosition(), - viewRect, iconRect, textRect, b.getIconTextGap()); - - // fill background - if (c.isOpaque()) { - g.setColor(b.getBackground()); - g.fillRect(0, 0, size.width, size.height); - } - - Graphics2D g2d = (Graphics2D) g; - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - if (model.isSelected()) { - GUIPaintUtils.fillPaint(g2d, iconRect.x, iconRect.y, iconRect.width, iconRect.height, false, Constants.NULL, - model.isEnabled() ? UIConstants.CHECKBOX_HOVER_SELECTED : UIConstants.DISABLED_ICON_COLOR, 0); - } else if (model.isRollover() && !model.isSelected()) { - g.setColor(UIConstants.CHECKBOX_HOVER_SELECTED); - g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC); - } else { - g.setColor(UIConstants.LINE_COLOR); - g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC); - } + public synchronized void paint(Graphics g, JComponent c) { + AbstractButton b = (AbstractButton) c; + ButtonModel model = b.getModel(); + Dimension size = c.getSize(); + Font f = c.getFont(); + g.setFont(f); + FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f); + + Rectangle viewRect = new Rectangle(size); + Rectangle iconRect = new Rectangle(); + Rectangle textRect = new Rectangle(); + + Insets i = c.getInsets(); + viewRect.x += i.left; + viewRect.y += i.top; + viewRect.width -= (i.right + viewRect.x); + viewRect.height -= (i.bottom + viewRect.y); + + Icon altIcon = b.getIcon(); + + String text = SwingUtilities.layoutCompoundLabel( + c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(), + b.getVerticalAlignment(), b.getHorizontalAlignment(), + b.getVerticalTextPosition(), b.getHorizontalTextPosition(), + viewRect, iconRect, textRect, b.getIconTextGap()); + + // fill background + if (c.isOpaque()) { + g.setColor(b.getBackground()); + g.fillRect(0, 0, size.width, size.height); + } - if (model.isSelected()) { - UIConstants.YES_ICON.paintIcon(c, g, iconRect.x + 2, iconRect.y + 2); - } - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + if (model.isSelected()) { + GUIPaintUtils.fillPaint(g2d, iconRect.x, iconRect.y, iconRect.width, iconRect.height, false, Constants.NULL, + model.isEnabled() ? UIConstants.CHECKBOX_HOVER_SELECTED : UIConstants.DISABLED_ICON_COLOR, 0); + } else if (model.isRollover() && !model.isSelected()) { + g.setColor(UIConstants.CHECKBOX_HOVER_SELECTED); + g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC); + } else { + g.setColor(UIConstants.LINE_COLOR); + g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC); + } - // Draw the Text - drawLine(text, g, b, c, textRect, fm); + if (model.isSelected()) { + UIConstants.YES_ICON.paintIcon(c, g, iconRect.x + 2, iconRect.y + 2); } + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + + // Draw the Text + drawLine(text, g, b, c, textRect, fm); } private void drawLine(String text, Graphics g, AbstractButton b, JComponent c, Rectangle textRect, FontMetrics fm) { diff --git a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBoxUI.java b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBoxUI.java index 1a7bbb661f..9076d355d3 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBoxUI.java +++ b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBoxUI.java @@ -64,7 +64,7 @@ public class UICheckBoxUI extends MetalCheckBoxUI { } } - static BasicStroke focusStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, new float[]{1.0f / 1.0f}, 1.0f); + static BasicStroke focusStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, new float[]{1.0f}, 1.0f); protected void paintFocus(Graphics g, Rectangle t, Dimension arg2) { if (!ThemeUtils.BUTTON_FOCUS) { diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/LazyComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/LazyComboBox.java index be83cf5b1a..300790457a 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/LazyComboBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/LazyComboBox.java @@ -84,6 +84,7 @@ public abstract class LazyComboBox extends UIComboBox implements PopupMenuListen LazyComboBox.this.loadList(get()); } catch (InterruptedException | ExecutionException exception) { FineLoggerFactory.getLogger().debug(exception.getMessage()); + Thread.currentThread().interrupt(); } LazyComboBox.this.showPopup(); } diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/LazyComboBoxTest.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/LazyComboBoxTest.java index 4016a263ce..37e9db1546 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/LazyComboBoxTest.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/LazyComboBoxTest.java @@ -40,6 +40,7 @@ public class LazyComboBoxTest { Thread.sleep(3000); } catch (InterruptedException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); + Thread.currentThread().interrupt(); } return m; } From d5926c4328bf6335b4f32993e28373e41057f212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Fri, 23 Aug 2019 10:27:04 +0800 Subject: [PATCH 25/60] =?UTF-8?q?CHART-10247=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E9=80=89=E6=8B=A9=E7=95=8C=E9=9D=A2=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/chart/ChartTypePane.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java b/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java index 257fb8826e..046cd1960c 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java @@ -1,7 +1,6 @@ package com.fr.design.chart; /** * the Pane of the Chart - * */ import com.fr.chart.base.ChartInternationalNameContentBean; @@ -120,15 +119,16 @@ public class ChartTypePane extends ChartCommonWizardPane { ChartProvider[] sub_charts = ChartTypePane.this.charts4Icon[main_index]; ChartTypePane.this.iconListModel.clear(); for (int i = 0; i < sub_charts.length; i++) { - ChartTypePane.this.iconListModel.addElement(new ChartIcon(sub_charts[i])); + String ImagePath = sub_charts[i].demoImagePath(); + String chartName = sub_charts[i].getChartName(); + ChartTypePane.this.iconListModel.addElement(new ChartIcon(ImagePath, chartName)); } iconViewList.setSelectedIndex(0); } }; public String getChartName(ChartIcon chartIcon) { - ChartProvider chart = chartIcon.getChart(); - return ChartTypeManager.getInstanceWithCheck().getChartName(chart.getID()); + return chartIcon.getChartName(); } public void populate(ChartProvider chart) { @@ -146,10 +146,10 @@ public class ChartTypePane extends ChartCommonWizardPane { if (chart4Update == null) { String plotID = typeName[mainTypeList.getSelectedIndex()].getChartID(); ChartProvider chart = ChartTypeManager.getInstance().getChartTypes(plotID)[iconViewList.getSelectedIndex()]; - try{ + try { chart4Update = (ChartProvider) chart.clone(); cc.addChart(chart4Update); - }catch (CloneNotSupportedException ex){ + } catch (CloneNotSupportedException ex) { FineLoggerFactory.getLogger().error(ex.getMessage(), ex); } } From 924a8db115552f1aec84751c52515aa72f979c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Fri, 23 Aug 2019 11:14:37 +0800 Subject: [PATCH 26/60] =?UTF-8?q?CHART-10247=20ChartIcon=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0design?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/chart/ChartIcon.java | 116 ++++++++++++++++++ .../com/fr/design/chart/ChartTypePane.java | 1 - 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java b/designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java new file mode 100644 index 0000000000..7485d57973 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java @@ -0,0 +1,116 @@ +package com.fr.design.chart; + +import com.fr.base.GraphHelper; +import com.fr.general.IOUtils; +import com.fr.stable.Constants; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLable; +import com.fr.stable.xml.XMLableReader; + +import javax.swing.Icon; +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Paint; +import java.awt.image.BufferedImage; + +/** + * 图表的缩略图Icon, 在选择图表类型界面 用到. + */ +public class ChartIcon implements Icon, XMLable { + private static final int WIDTH = 400; + private static final int HEIGHT = 225; + /** + * 缩略图中的图片路径 + */ + private String imagePath; + + private String chartName; + + /** + * 构造Chart的缩略图Icon + */ + public ChartIcon(String imagePath, String chartName) { + this.imagePath = imagePath; + this.chartName = chartName; + } + + /** + * 画出缩略图Icon + * + * @param g 图形的上下文 + * @param c 所在的Component + * @param x 缩略图的起始坐标x + * @param y 缩略图的起始坐标y + */ + public void paintIcon(Component c, Graphics g, int x, int y) { + + Graphics2D g2d = (Graphics2D) g; + + Paint oldPaint = g2d.getPaint(); + + g.translate(x, y); + g2d.setPaint(Color.white); + + g2d.fillRect(0, 0, getIconWidth(), getIconHeight()); + BufferedImage demoImage = IOUtils.readImageWithCache(imagePath); + GraphHelper.paintImage(g, getIconWidth(), getIconHeight(), demoImage, Constants.IMAGE_ADJUST, Constants.NULL, Constants.NULL, -1, -1); + + g.translate(-x, -y); + g2d.setPaint(oldPaint); + } + + /** + * 返回缩略图的宽度 + * + * @return int 缩略图宽度 + */ + public int getIconWidth() { + return WIDTH; + } + + /** + * 返回缩略图的高度 + * + * @return int 缩略图高度 + */ + public int getIconHeight() { + return HEIGHT; + } + + + /** + * 返回缩略图中的图片路径 + * + * @return 缩略图中的图片路径 + */ + public String getImagePath() { + return imagePath; + } + + public String getChartName() { + return chartName; + } + + + public void readXML(XMLableReader reader) { + + } + + public void writeXML(XMLPrintWriter writer) { + + } + + /** + * @return 克隆后的对象 + * @throws CloneNotSupportedException 如果克隆失败则抛出此异常 + */ + public Object clone() throws CloneNotSupportedException { + ChartIcon cloned = (ChartIcon) super.clone(); + cloned.imagePath = this.imagePath; + cloned.chartName = this.chartName; + return cloned; + } + +} \ No newline at end of file diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java b/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java index 046cd1960c..599a70915f 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java @@ -5,7 +5,6 @@ package com.fr.design.chart; import com.fr.chart.base.ChartInternationalNameContentBean; import com.fr.chart.chartattr.ChartCollection; -import com.fr.chart.chartattr.ChartIcon; import com.fr.chart.charttypes.ChartTypeManager; import com.fr.chartx.attr.ChartProvider; import com.fr.design.gui.ilable.UILabel; From b38d273f33994b8682526043c3cd2b02bb05229b Mon Sep 17 00:00:00 2001 From: Lanlan Date: Fri, 23 Aug 2019 16:32:03 +0800 Subject: [PATCH 27/60] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20sonar?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/design/DesignerEnvManager.java | 4 +--- .../src/main/java/com/fr/design/layout/TableLayout.java | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java index ae06d6fa13..1f8ef8541e 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java @@ -263,6 +263,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { Thread.sleep(5000); } catch (InterruptedException e) { FineLoggerFactory.getLogger().error("Map Save Error"); + Thread.currentThread().interrupt(); } } } @@ -658,9 +659,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { */ public void saveXMLFile() { File xmlFile = this.getDesignerEnvFile(); - if (xmlFile == null) { - return; - } if (!xmlFile.getParentFile().exists()) {//建立目录. StableUtils.mkdirs(xmlFile.getParentFile()); } diff --git a/designer-base/src/main/java/com/fr/design/layout/TableLayout.java b/designer-base/src/main/java/com/fr/design/layout/TableLayout.java index 77696e553f..b812263c6b 100644 --- a/designer-base/src/main/java/com/fr/design/layout/TableLayout.java +++ b/designer-base/src/main/java/com/fr/design/layout/TableLayout.java @@ -1218,7 +1218,7 @@ public class TableLayout implements LayoutManager2, Serializable { * @param z indicates row or column * @param availableSize amount of space available in the container */ - + @SuppressWarnings("squid:S3518") protected void assignFillSize(int z, int availableSize) { // Skip if there is no more space to allocate if (availableSize <= 0) @@ -1290,7 +1290,7 @@ public class TableLayout implements LayoutManager2, Serializable { * @return the amount of space available after absolute crs have been assigned * sizes */ - + @SuppressWarnings("squid:S3518") protected int assignPrefMinSize (int z, int availableSize, double typeOfSize) { // Get variables referring to columns or rows (crs) @@ -1727,7 +1727,7 @@ public class TableLayout implements LayoutManager2, Serializable { * * @return a dimension indicating the container's preferred or minimum size */ - + @SuppressWarnings("squid:S3518") protected int calculateLayoutSize (Container container, int z, double typeOfSize, Entry entryList[], Dimension prefMinSize[]) { From d142338abffcc1e63221e5819032b97b9525ca75 Mon Sep 17 00:00:00 2001 From: zack Date: Sun, 25 Aug 2019 21:37:10 +0800 Subject: [PATCH 28/60] =?UTF-8?q?REPORT-20318=20sonar=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/extra/WebViewDlgHelper.java | 9 +++++---- .../java/com/fr/design/formula/JavaEditorPane.java | 1 + .../fr/design/formula/VariableResolverAdapter.java | 14 ++++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java b/designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java index fef7c51591..c6287bacfc 100644 --- a/designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java +++ b/designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java @@ -5,17 +5,15 @@ import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.UIDialog; import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.mainframe.DesignerContext; +import com.fr.general.CloudCenter; import com.fr.general.CommonIOUtils; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.IOUtils; - -import com.fr.general.CloudCenter; import com.fr.general.http.HttpClient; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import com.fr.plugin.PluginStoreConstants; -import com.fr.plugin.PluginVerifyException; import com.fr.stable.CommonUtils; import com.fr.stable.EnvChangedListener; import com.fr.stable.ProductConstants; @@ -280,7 +278,10 @@ public class WebViewDlgHelper { PluginStoreConstants.refreshProps(); // 下载完刷新一下版本号等 JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Shop_Installed"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), JOptionPane.INFORMATION_MESSAGE); } - } catch (InterruptedException | ExecutionException e) { + } catch (InterruptedException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + Thread.currentThread().interrupt(); + } catch (ExecutionException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } diff --git a/designer-base/src/main/java/com/fr/design/formula/JavaEditorPane.java b/designer-base/src/main/java/com/fr/design/formula/JavaEditorPane.java index 597ddbfd66..a3bdbae216 100644 --- a/designer-base/src/main/java/com/fr/design/formula/JavaEditorPane.java +++ b/designer-base/src/main/java/com/fr/design/formula/JavaEditorPane.java @@ -194,6 +194,7 @@ public class JavaEditorPane extends BasicPane { JOptionPane.showMessageDialog(null, message); } catch (InterruptedException e1) { FineLoggerFactory.getLogger().error(e1.getMessage(), e1); + Thread.currentThread().interrupt(); } catch (ExecutionException e1) { FineLoggerFactory.getLogger().error(e1.getMessage(), e1); } diff --git a/designer-base/src/main/java/com/fr/design/formula/VariableResolverAdapter.java b/designer-base/src/main/java/com/fr/design/formula/VariableResolverAdapter.java index e03fa0e186..5fd384be8e 100644 --- a/designer-base/src/main/java/com/fr/design/formula/VariableResolverAdapter.java +++ b/designer-base/src/main/java/com/fr/design/formula/VariableResolverAdapter.java @@ -23,6 +23,7 @@ public abstract class VariableResolverAdapter implements VariableResolver { * * @return 内置参数 */ + @Override public String[] resolveCurReportVariables() { String[] variables = new String[]{ ScriptConstants.SUMMARY_TAG + "page_number", @@ -38,10 +39,10 @@ public abstract class VariableResolverAdapter implements VariableResolver { CalculatorProvider.SERVER_PORT, CalculatorProvider.SERVER_URL, CalculatorProvider.CONTEXT_PATH, CalculatorProvider.SESSION_ID }; Set set = ExtraClassManager.getInstance().getArray(BuiltInParametersProvider.XML_TAG); - for (BuiltInParametersProvider provider : set) { - return (String[]) ArrayUtils.addAll(variables, new String[]{ - ScriptConstants.DETAIL_TAG + provider.getParametersName() - }); + for (BuiltInParametersProvider provider : set) { + ArrayUtils.addAll(variables, new String[]{ + ScriptConstants.DETAIL_TAG + provider.getParametersName() + }); } return variables; } @@ -65,6 +66,8 @@ public abstract class VariableResolverAdapter implements VariableResolver { * * @return 所有参数 */ + @Override + @SuppressWarnings("squid:S2259") public String[] resolveTableDataParameterVariables() { Parameter[] parameters = getCurrentModeParameters(TABLE_DATA_PARA); String[] parameterNames = new String[parameters.length]; @@ -79,6 +82,8 @@ public abstract class VariableResolverAdapter implements VariableResolver { * * @return 所有参数 */ + @Override + @SuppressWarnings("squid:S2259") public String[] resolveReportParameterVariables() { Parameter[] parameters = getCurrentModeParameters(REPORT_DATA_PARA); String[] parameterNames = new String[parameters.length]; @@ -93,6 +98,7 @@ public abstract class VariableResolverAdapter implements VariableResolver { * * @return 所有参数 */ + @Override public String[] resolveGlobalParameterVariables() { // 加上全局的参数 Parameter[] globalParameters = ParameterConfig.getInstance().getGlobalParameters(); From 99f8e654c0319d3969d877f13d84c46894b7a3d9 Mon Sep 17 00:00:00 2001 From: Maksim Date: Mon, 26 Aug 2019 09:46:49 +0800 Subject: [PATCH 29/60] =?UTF-8?q?REPORT-20323=20sonar=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/gui/imenu/UIBasicMenuItemUI.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/imenu/UIBasicMenuItemUI.java b/designer-base/src/main/java/com/fr/design/gui/imenu/UIBasicMenuItemUI.java index 1c07c8260d..844120c51b 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenu/UIBasicMenuItemUI.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenu/UIBasicMenuItemUI.java @@ -7,6 +7,7 @@ package com.fr.design.gui.imenu; import com.fr.design.utils.ColorRoutines; import com.fr.design.utils.ThemeUtils; import com.fr.general.ComparatorUtils; +import com.fr.stable.StringUtils; import javax.swing.AbstractAction; import javax.swing.ActionMap; @@ -579,7 +580,8 @@ public class UIBasicMenuItemUI extends MenuItemUI { */ private boolean isInternalFrameSystemMenu() { String actionCommand = menuItem.getActionCommand(); - return (actionCommand.equals("Close")) || (actionCommand.equals("Minimize")) || (actionCommand.equals("Restore")) || (actionCommand.equals("Maximize")); + return (StringUtils.equals(actionCommand,"Close") || StringUtils.equals(actionCommand,"Minimize") + || StringUtils.equals(actionCommand,"Restore") || StringUtils.equals(actionCommand,"Maximize")); } ////////////////////////////////////////////////////////// From ac92a719bd60aa21b64b5d67ddde76ca20629ffc Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Mon, 26 Aug 2019 10:47:54 +0800 Subject: [PATCH 30/60] =?UTF-8?q?REPORT-19008=20=E6=B0=B4=E5=8D=B0?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=86=E5=BA=A6=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/report/WatermarkPane.java | 74 +++++++++++++++++-- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java b/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java index 0caa7e8b6b..ef396c4cb0 100644 --- a/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java +++ b/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java @@ -6,6 +6,7 @@ import com.fr.design.formula.TinyFormulaPane; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.gui.style.FRFontPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; @@ -13,15 +14,14 @@ import com.fr.design.layout.TableLayoutHelper; import com.fr.design.style.color.NewColorSelectPane; import com.fr.design.utils.gui.GUICoreUtils; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JPanel; +import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import java.awt.BorderLayout; -import java.awt.Color; +import java.awt.*; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -37,9 +37,15 @@ public class WatermarkPane extends BasicPane { private TinyFormulaPane formulaPane; // 字号 private UIComboBox fontSizeComboBox; + //横向间距 + private UISpinner horizontalGapSpinner; + //横向间距 + private UISpinner verticalGapSpinner; // 文字颜色 private NewColorSelectPane colorPane; + private static final Dimension SPINNER_DIMENSION = new Dimension(75, 20); + public WatermarkPane() { initComponents(); } @@ -73,6 +79,7 @@ public class WatermarkPane extends BasicPane { } populateFourmula(watermark.getText()); populateFontSize(watermark.getFontSize()); + populateWatermarkGap(watermark); populateColor(watermark.getColor()); paintPreviewPane(); } @@ -81,6 +88,8 @@ public class WatermarkPane extends BasicPane { WatermarkAttr watermark = new WatermarkAttr(); watermark.setText(formulaPane.getUITextField().getText()); watermark.setFontSize((int)fontSizeComboBox.getSelectedItem()); + watermark.setHorizontalGap((int) horizontalGapSpinner.getValue()); + watermark.setVerticalGap((int) verticalGapSpinner.getValue()); watermark.setColor(colorPane.getColor()); colorPane.updateUsedColor(); return watermark; @@ -98,20 +107,39 @@ public class WatermarkPane extends BasicPane { formulaPane = new TinyFormulaPane(); fontSizeComboBox = new UIComboBox(FRFontPane.FONT_SIZES); fontSizeComboBox.setEditable(true); + horizontalGapSpinner = new UISpinner(0, Integer.MAX_VALUE, 1, 200); + verticalGapSpinner = new UISpinner(0, Integer.MAX_VALUE, 1, 100); + horizontalGapSpinner.setPreferredSize(SPINNER_DIMENSION); + verticalGapSpinner.setPreferredSize(SPINNER_DIMENSION); JPanel fontSizeTypePane = new JPanel(new BorderLayout(10,0)); fontSizeTypePane.add(fontSizeComboBox, BorderLayout.CENTER); + //水印间距面板 + JPanel watermarkGapPane = new JPanel(new BorderLayout(10, 0)); + JPanel jp = FRGUIPaneFactory.createNColumnGridInnerContainer_Pane(2, 10, 0); + jp.add(horizontalGapSpinner); + jp.add(verticalGapSpinner); + watermarkGapPane.add(jp, BorderLayout.CENTER); + + JPanel watermarkGapTipsPane = new JPanel(new BorderLayout()); + JPanel tipsJp = FRGUIPaneFactory.createNColumnGridInnerContainer_Pane(2, 10, 0); + tipsJp.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Direction_Horizontal"), SwingConstants.CENTER)); + tipsJp.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Direction_Vertical"), SwingConstants.CENTER)); + watermarkGapTipsPane.add(tipsJp, BorderLayout.CENTER); + colorPane = new NewColorSelectPane(); JPanel colorLabelPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); colorLabelPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Text_Color")), BorderLayout.NORTH); double p = TableLayout.PREFERRED; - double[] rowSize = {p,p,p}; - double[] columnSize = { p, MAX_WIDTH}; + double[] rowSize = {p, p, p, p, p}; + double[] columnSize = {p, MAX_WIDTH}; - JPanel rightContentPane = TableLayoutHelper.createCommonTableLayoutPane( new JComponent[][]{ + JPanel rightContentPane = TableLayoutHelper.createCommonTableLayoutPane(new JComponent[][]{ {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Watermark_Text")), formulaPane}, {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Font_Size")), fontSizeTypePane}, + {new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Watermark_Gap")),watermarkGapPane }, + {null,watermarkGapTipsPane }, {colorLabelPane, colorPane}, }, rowSize, columnSize, 10); rightContentPane.setBorder(BorderFactory.createEmptyBorder(15, 12, 10, 12)); @@ -131,6 +159,36 @@ public class WatermarkPane extends BasicPane { }); } + protected void populateWatermarkGap(WatermarkAttr watermark){ + this.horizontalGapSpinner.setValue(watermark.getHorizontalGap()); + this.horizontalGapSpinner.addUISpinnerFocusListenner(new FocusListener() { + + @Override + public void focusGained(FocusEvent e) { + paintPreviewPane(); + } + + @Override + public void focusLost(FocusEvent e) { + paintPreviewPane(); + } + }); + + this.verticalGapSpinner.setValue(watermark.getVerticalGap()); + this.verticalGapSpinner.addUISpinnerFocusListenner(new FocusListener() { + + @Override + public void focusGained(FocusEvent e) { + paintPreviewPane(); + } + + @Override + public void focusLost(FocusEvent e) { + paintPreviewPane(); + } + }); + } + protected void paintPreviewPane(){ watermarkPreviewPane.repaint(update()); } From 0d025f1e689829d4687b88de720459407197f585 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Mon, 26 Aug 2019 10:55:19 +0800 Subject: [PATCH 31/60] =?UTF-8?q?REPORT-19008=20=E6=B0=B4=E5=8D=B0?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=86=E5=BA=A6=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/report/WatermarkPane.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java b/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java index ef396c4cb0..e190d40382 100644 --- a/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java +++ b/designer-base/src/main/java/com/fr/design/report/WatermarkPane.java @@ -14,12 +14,17 @@ import com.fr.design.layout.TableLayoutHelper; import com.fr.design.style.color.NewColorSelectPane; import com.fr.design.utils.gui.GUICoreUtils; -import javax.swing.*; +import javax.swing.BorderFactory; +import javax.swing.SwingConstants; +import javax.swing.JComponent; +import javax.swing.JPanel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import java.awt.*; +import java.awt.Dimension; +import java.awt.BorderLayout; +import java.awt.Color; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.ItemEvent; From 518cd187764bd83d2b9786dc57ca172b0197c452 Mon Sep 17 00:00:00 2001 From: vito Date: Mon, 26 Aug 2019 11:54:42 +0800 Subject: [PATCH 32/60] =?UTF-8?q?REPORT-20320=20sonar=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/data/BasicTableDataTreePane.java | 8 +- .../data/datapane/TableDataSourceOP.java | 66 +++--- .../tabledatapane/FileTableDataPane.java | 201 ++++++++++-------- .../com/fr/design/extra/LoginWebBridge.java | 48 +---- .../fr/design/extra/PluginControlPane.java | 2 + .../fr/design/extra/PluginFromStorePane.java | 16 +- 6 files changed, 168 insertions(+), 173 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java index a18ae856eb..313ca0e2f7 100644 --- a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java +++ b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java @@ -46,6 +46,7 @@ import java.awt.event.KeyEvent; import java.util.EventObject; import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** * Coder: zack @@ -70,6 +71,7 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp * * @return 返回位置 */ + @Override public Location preferredLocation() { return Location.WEST_ABOVE; } @@ -97,6 +99,7 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp /** * 响应数据集改变 */ + @Override public void fireDSChanged() { fireDSChanged(new HashMap()); } @@ -107,6 +110,7 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp * * @param map 数据集变化Map */ + @Override public void fireDSChanged(Map map) { DesignTableDataManager.fireDSChanged(map); } @@ -151,6 +155,7 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp public abstract TableDataTree getDataTree(); + @Override public abstract void refreshDockingView(); protected void checkButtonEnabled(UpdateAction editAction, UpdateAction previewTableDataAction, UpdateAction removeAction, TableDataSourceOP op, TableDataTree dataTree) { @@ -320,6 +325,7 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp this.setSmallIcon(this.getTDIcon()); } + @Override public void actionPerformed(ActionEvent e) { dgEdit(getTableDataInstance().creatTableDataPane(), createDsName(getNamePrefix()), false); } @@ -400,7 +406,7 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp data = selectedNO.getObject(); } try { - if (((TableDataWrapper) data).getTableData() instanceof StoreProcedure) { + if (((TableDataWrapper) Objects.requireNonNull(data)).getTableData() instanceof StoreProcedure) { ((StoreProcedure) (((TableDataWrapper) data).getTableData())).resetDataModelList(); if (data instanceof StoreProcedureDataWrapper) { StoreProcedureDataWrapper oldSdw = ((StoreProcedureDataWrapper) data); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataSourceOP.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataSourceOP.java index 9c19013901..33e51100ea 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataSourceOP.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataSourceOP.java @@ -56,14 +56,18 @@ public class TableDataSourceOP implements UserObjectOP { return DesignTableDataManager.getEditingDataSet(tc.getBook()); } List> empty = new ArrayList>(); - empty.add(Collections.emptyMap());//数据集 - empty.add(Collections.emptyMap());//服务器数据集 - empty.add(Collections.emptyMap());//存储过程 + //数据集 + empty.add(Collections.emptyMap()); + //服务器数据集 + empty.add(Collections.emptyMap()); + //存储过程 + empty.add(Collections.emptyMap()); return empty; } /** * ButtonEnabled intercept + * * @return interceptbuttonEnabled */ @Override @@ -73,8 +77,10 @@ public class TableDataSourceOP implements UserObjectOP { /** * 移除名字是name的TableData + * * @param name tabledata name */ + @Override public void removeAction(String name) { if (tc != null) { TableDataSource tds = tc.getBook(); @@ -85,7 +91,7 @@ public class TableDataSourceOP implements UserObjectOP { } protected ExpandMutableTreeNode[] getNodeArrayFromMap(Map map) { - List dataList = new ArrayList(); + List dataList = new ArrayList<>(); Iterator> entryIt = map.entrySet().iterator(); while (entryIt.hasNext()) { Entry entry = entryIt.next(); @@ -96,7 +102,7 @@ public class TableDataSourceOP implements UserObjectOP { dataList.add(newChildTreeNode); newChildTreeNode.add(new ExpandMutableTreeNode()); } - return dataList.toArray(new ExpandMutableTreeNode[dataList.size()]); + return dataList.toArray(new ExpandMutableTreeNode[0]); } private ExpandMutableTreeNode initTemplateDataNode(Map templateDataMap) { @@ -124,22 +130,20 @@ public class TableDataSourceOP implements UserObjectOP { */ @Override public ExpandMutableTreeNode[] load() { - Map templateDataMap = null; - Map serverDataMap = null; - Map storeProcedureMap = null; - - if (this != null) { - templateDataMap = this.init().get(0); - serverDataMap = this.init().get(1); - storeProcedureMap = this.init().get(2); - } else { - templateDataMap = Collections.emptyMap(); - serverDataMap = Collections.emptyMap(); - storeProcedureMap = Collections.emptyMap(); - } - List list = new ArrayList(); //所有的数据集 - List templist = new ArrayList(); //模板数据集 - List serverlist = new ArrayList(); //服务器数据集 + Map templateDataMap; + Map serverDataMap; + Map storeProcedureMap; + + templateDataMap = this.init().get(0); + serverDataMap = this.init().get(1); + storeProcedureMap = this.init().get(2); + + //所有的数据集 + List list = new ArrayList<>(); + //模板数据集 + List templist = new ArrayList<>(); + //服务器数据集 + List serverlist = new ArrayList<>(); list.add(initTemplateDataNode(templateDataMap)); addNodeToList(templateDataMap, templist); @@ -160,11 +164,11 @@ public class TableDataSourceOP implements UserObjectOP { } switch (dataMode) { case TEMPLATE_TABLE_DATA: - return templist.toArray(new ExpandMutableTreeNode[templist.size()]); + return templist.toArray(new ExpandMutableTreeNode[0]); case SERVER_TABLE_DATA: - return serverlist.toArray(new ExpandMutableTreeNode[serverlist.size()]); + return serverlist.toArray(new ExpandMutableTreeNode[0]); default: - return list.toArray(new ExpandMutableTreeNode[list.size()]); + return list.toArray(new ExpandMutableTreeNode[0]); } } @@ -182,7 +186,7 @@ public class TableDataSourceOP implements UserObjectOP { } protected void setStoreProcedureTree(TableData tableData, ExpandMutableTreeNode tmpNode) { - ArrayList nodeName = new ArrayList(); + ArrayList nodeName = new ArrayList<>(); StoreProcedure storeProcedure = (StoreProcedure) tableData; String name = ((NameObject) tmpNode.getUserObject()).getName(); StoreProcedureParameter[] parameters = StoreProcedure.getSortPara(storeProcedure.getParameters()); @@ -208,13 +212,13 @@ public class TableDataSourceOP implements UserObjectOP { } if (!resultNames.isEmpty()) { - for (int i = 0; i < resultNames.size(); i++) { - if (!nodeName.contains(resultNames.get(i))) { - nodeName.add(resultNames.get(i)); + for (String resultName : resultNames) { + if (!nodeName.contains(resultName)) { + nodeName.add(resultName); hasChild = true; - String parameterName = name + "_" + resultNames.get(i); + String parameterName = name + "_" + resultName; TableDataWrapper newTwd = new StoreProcedureDataWrapper(storeProcedure, name, parameterName, false); - ExpandMutableTreeNode newChildNode = new ExpandMutableTreeNode(new NameObject(resultNames.get(i), newTwd)); + ExpandMutableTreeNode newChildNode = new ExpandMutableTreeNode(new NameObject(resultName, newTwd)); newChildNode.add(new ExpandMutableTreeNode()); tmpNode.add(newChildNode); } @@ -230,7 +234,7 @@ public class TableDataSourceOP implements UserObjectOP { public void setDataMode(int i) { - this.dataMode = i; + dataMode = i; } public int getDataMode() { diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/FileTableDataPane.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/FileTableDataPane.java index 0d8b05c401..215ba7588f 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/FileTableDataPane.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/FileTableDataPane.java @@ -76,6 +76,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class FileTableDataPane extends AbstractTableDataPane { private static final int TEXT = 0; @@ -126,12 +127,12 @@ public class FileTableDataPane extends AbstractTableDataPane { private static final int GAP = 23; - public FileTableDataPane(){ - this(SETPANELWIDTH,WIDTH,HEIGHT,GAP); + public FileTableDataPane() { + this(SETPANELWIDTH, WIDTH, HEIGHT, GAP); } - public FileTableDataPane(int setPanelWidth,int width,int height,int gap) { - this.setLayout(new BorderLayout(gap,0)); + public FileTableDataPane(int setPanelWidth, int width, int height, int gap) { + this.setLayout(new BorderLayout(gap, 0)); JPanel northPanel = new JPanel(new BorderLayout()); JPanel type = new JPanel(); type.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Utils_File_Type") + ":")); @@ -163,16 +164,16 @@ public class FileTableDataPane extends AbstractTableDataPane { southPanel.add(setPanel, BorderLayout.CENTER); setPanel.setPreferredSize(new Dimension(setPanelWidth, 460)); setPanel.setBorder(BorderFactory.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Set"))); - JPanel controlPane = textSetPanel(width,height); + JPanel controlPane = textSetPanel(width, height); setPanel.add(controlPane, BorderLayout.NORTH); - fileTypeComboBox.addActionListener(getFileTypeListener(setPanel,width,height)); + fileTypeComboBox.addActionListener(getFileTypeListener(setPanel, width, height)); this.add(northPanel, BorderLayout.NORTH); this.add(centerPanel, BorderLayout.CENTER); this.add(southPanel, BorderLayout.EAST); } - private void addToCenterPanel(JPanel centerPanel){ + private void addToCenterPanel(JPanel centerPanel) { localFileRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Local_File") + ":", true); urlFileRadioButton = new UIRadioButton("URL:", false); ButtonGroup bg = new ButtonGroup(); @@ -217,8 +218,9 @@ public class FileTableDataPane extends AbstractTableDataPane { } private ActionListener testConnectionListener = new ActionListener() { + @Override public void actionPerformed(ActionEvent arg0) { - String uri = ParameterHelper.analyze4Templatee( urlText.getText(), params); + String uri = ParameterHelper.analyze4Templatee(urlText.getText(), params); if (!checkURL(uri)) { JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(FileTableDataPane.this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Add_JS_warning")); return; @@ -245,10 +247,11 @@ public class FileTableDataPane extends AbstractTableDataPane { } }; - private void previewPanel(JPanel jPanel){ + private void previewPanel(JPanel jPanel) { JPanel previewPanel = new JPanel(new BorderLayout()); UIButton preview = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview")); preview.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { preview(); } @@ -257,48 +260,47 @@ public class FileTableDataPane extends AbstractTableDataPane { jPanel.add(previewPanel, BorderLayout.SOUTH); } - private JPanel xmlSetPanel(int width,int height) { + private JPanel xmlSetPanel(int width, int height) { // xml设置pane JPanel controlPane = new JPanel(); - JPanel northPane = new JPanel(new BorderLayout(8,8)); - JPanel northTopPane = new JPanel(new BorderLayout(8,8)); - JPanel southPane = new JPanel(new BorderLayout(8,8)); - JPanel southTopPane = new JPanel(new BorderLayout(8,8)); - JPanel westPane = new JPanel(new BorderLayout()); - controlPane.setLayout(new BorderLayout(8,8)); + JPanel northPane = new JPanel(new BorderLayout(8, 8)); + JPanel northTopPane = new JPanel(new BorderLayout(8, 8)); + JPanel southPane = new JPanel(new BorderLayout(8, 8)); + JPanel southTopPane = new JPanel(new BorderLayout(8, 8)); + controlPane.setLayout(new BorderLayout(8, 8)); controlPane.setPreferredSize(new Dimension(width, height)); - JPanel comboboxPanel = new JPanel(new BorderLayout(8,8)); + JPanel comboboxPanel = new JPanel(new BorderLayout(8, 8)); encodeLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Encoding_Type") + ":"); encodingComboBox = new UIComboBox(EncodeConstants.ALL_ENCODING_ARRAY); encodingComboBox.setSelectedIndex(4); encodingComboBox.setPreferredSize(new Dimension(90, 20)); JPanel treeContainerPane = new JPanel(); - treeContainerPane.setLayout(new BorderLayout(8,8)); + treeContainerPane.setLayout(new BorderLayout(8, 8)); nodeTreePane = new XMLNodeTreePane(); - treeContainerPane.add(nodeTreePane,BorderLayout.CENTER); + treeContainerPane.add(nodeTreePane, BorderLayout.CENTER); comboboxPanel.add(encodeLabel, BorderLayout.WEST); comboboxPanel.add(encodingComboBox, BorderLayout.CENTER); - northPane.add(comboboxPanel,BorderLayout.EAST); - northTopPane.add(northPane,BorderLayout.WEST); - southTopPane.add(southPane,BorderLayout.WEST); - southTopPane.add(treeContainerPane,BorderLayout.CENTER); + northPane.add(comboboxPanel, BorderLayout.EAST); + northTopPane.add(northPane, BorderLayout.WEST); + southTopPane.add(southPane, BorderLayout.WEST); + southTopPane.add(treeContainerPane, BorderLayout.CENTER); controlPane.add(northTopPane, BorderLayout.NORTH); - controlPane.add(southTopPane,BorderLayout.CENTER); + controlPane.add(southTopPane, BorderLayout.CENTER); previewPanel(controlPane); return controlPane; } - private JPanel excelSetPanel(int width,int height) { + private JPanel excelSetPanel(int width, int height) { // excel设置pane int checkBoxWidth = width - EIGHT; JPanel controlPane = new JPanel(); - JPanel northPane = new JPanel(new BorderLayout(8,8)); + JPanel northPane = new JPanel(new BorderLayout(8, 8)); controlPane.setLayout(new BorderLayout()); - controlPane.setPreferredSize(new Dimension(width,height)); + controlPane.setPreferredSize(new Dimension(width, height)); needColumnNameCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_FirstRow_IS_Column_Name"), false); needColumnNameCheckBox.setPreferredSize(new Dimension(checkBoxWidth, 20)); northPane.add(needColumnNameCheckBox, BorderLayout.EAST); @@ -321,6 +323,7 @@ public class FileTableDataPane extends AbstractTableDataPane { * * @throws Exception */ + @Override public void checkValid() throws Exception { if (urlFileRadioButton.isSelected()) { String url = urlText.getText().trim(); @@ -331,33 +334,33 @@ public class FileTableDataPane extends AbstractTableDataPane { } - private boolean checkURL(String uri){ + private boolean checkURL(String uri) { try { new URL(uri); return true; } catch (MalformedURLException e) { return false; } - // return (uri.matches("https*://.+|\\$\\{.+\\}.*")); + // return (uri.matches("https*://.+|\\$\\{.+\\}.*")); } - private JPanel textSetPanel(int width,int height) { + private JPanel textSetPanel(int width, int height) { // text设置pane JPanel controlPane = new JPanel(); controlPane.setLayout(new BorderLayout()); - controlPane.setPreferredSize(new Dimension(width,height)); - JPanel northPane = new JPanel(new BorderLayout(8,8)); + controlPane.setPreferredSize(new Dimension(width, height)); + JPanel northPane = new JPanel(new BorderLayout(8, 8)); addToNorthPane(northPane); - controlPane.add(northPane,BorderLayout.WEST); + controlPane.add(northPane, BorderLayout.WEST); previewPanel(controlPane); return controlPane; } - private void addToNorthPane(JPanel northPane){ + private void addToNorthPane(JPanel northPane) { double f = TableLayout.FILL; double p = TableLayout.PREFERRED; - double columnSize[] = {f, p, p}; - double rowSize[] = {B, B, B, B, B, B, B}; + double[] columnSize = {f, p, p}; + double[] rowSize = {B, B, B, B, B, B, B}; needColumnNameCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_FirstRow_IS_Column_Name"), true); dismenberLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dismenber") + ":"); tableDismemberRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Table_Dismember"), false); @@ -390,18 +393,19 @@ public class FileTableDataPane extends AbstractTableDataPane { encodeLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Encoding_Type") + ":"); charsetComboBox = new UIComboBox(EncodeConstants.ALL_ENCODING_ARRAY); Component[][] comps = { - {encodeLabel,charsetComboBox,null}, - {needColumnNameCheckBox,null,null}, - {dismenberLabel,tableDismemberRadioButton,null}, - {null,spaceDismenberRadioButton,null}, - {null,commaDismenberRadioButton,null}, - {null,otherDismenberRadioButton,otherDismenberTextField}, - {ignoreOneMoreDelimiterCheckBox,null,null} + {encodeLabel, charsetComboBox, null}, + {needColumnNameCheckBox, null, null}, + {dismenberLabel, tableDismemberRadioButton, null}, + {null, spaceDismenberRadioButton, null}, + {null, commaDismenberRadioButton, null}, + {null, otherDismenberRadioButton, otherDismenberTextField}, + {ignoreOneMoreDelimiterCheckBox, null, null} }; - northPane.add(TableLayoutHelper.createTableLayoutPane(comps, rowSize, columnSize),BorderLayout.EAST); + northPane.add(TableLayoutHelper.createTableLayoutPane(comps, rowSize, columnSize), BorderLayout.EAST); } private ActionListener radioActionListener = new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { if (localFileRadioButton.isSelected()) { localRadioSelectAction(); @@ -456,8 +460,8 @@ public class FileTableDataPane extends AbstractTableDataPane { private String[] getFileSuffix() { List suffixList = new ArrayList(); - String suffix = fileTypeComboBox.getSelectedItem().toString().toLowerCase(); - if (suffix.equalsIgnoreCase("excel")) { + String suffix = Objects.requireNonNull(fileTypeComboBox.getSelectedItem()).toString().toLowerCase(); + if ("excel".equalsIgnoreCase(suffix)) { suffixList.add("xls"); suffixList.add("xlsx"); } else { @@ -467,8 +471,8 @@ public class FileTableDataPane extends AbstractTableDataPane { } private String getFileSuffixToString() { - String suffixToString = fileTypeComboBox.getSelectedItem().toString().toLowerCase(); - if (suffixToString.equalsIgnoreCase("excel")) { + String suffixToString = Objects.requireNonNull(fileTypeComboBox.getSelectedItem()).toString().toLowerCase(); + if ("excel".equalsIgnoreCase(suffixToString)) { suffixToString = "xls"; } return suffixToString; @@ -476,16 +480,17 @@ public class FileTableDataPane extends AbstractTableDataPane { private ActionListener getFileTypeListener(final JPanel setPanel, final int width, final int height) { ActionListener fileTypeListener = new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { setPanel.removeAll(); localText.setText(""); urlText.setText(""); if (fileTypeComboBox.getSelectedIndex() == XML) { - setPanel.add(xmlSetPanel(width,height), BorderLayout.NORTH); + setPanel.add(xmlSetPanel(width, height), BorderLayout.NORTH); } else if (fileTypeComboBox.getSelectedIndex() == EXCEL) { - setPanel.add(excelSetPanel(width,height), BorderLayout.NORTH); + setPanel.add(excelSetPanel(width, height), BorderLayout.NORTH); } else { - setPanel.add(textSetPanel(width,height), BorderLayout.NORTH); + setPanel.add(textSetPanel(width, height), BorderLayout.NORTH); } String tipContent = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Type_Parameter") + "reportlets/excel/FineReport${abc}." + getFileSuffixToString() + "
" + "http://192.168.100.120:8080/XXServer/Report/excel${abc}.jsp
" + "  "; @@ -503,6 +508,7 @@ public class FileTableDataPane extends AbstractTableDataPane { this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/refresh.png")); } + @Override public void actionPerformed(ActionEvent e) { String[] paramTexts = new String[1]; paramTexts[0] = getFilePathFromUrlOrLocal(); @@ -545,25 +551,25 @@ public class FileTableDataPane extends AbstractTableDataPane { setTextField(xtd); editorPane.populate(xtd.getParams()); encodingComboBox.setSelectedItem(xtd.getCharSet()); - if (!ComparatorUtils.equals(xtd,new XMLTableData())) { + if (!ComparatorUtils.equals(xtd, new XMLTableData())) { xmlNodeTree.initData(); String[] path = xtd.getXPath(); String[] paths; if (path != null && path.length > 0) { - DefaultTreeModel treeModel = (DefaultTreeModel)xmlNodeTree.getModel(); + DefaultTreeModel treeModel = (DefaultTreeModel) xmlNodeTree.getModel(); ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); if (treeModel != null) { - if(!ComparatorUtils.equals(treeModel.getRoot().toString(),"")){ - paths = new String[path.length - 1]; - for(int i = 1;i< path.length;i++){ - paths[i -1] = path[i]; - } - }else{ + if (!ComparatorUtils.equals(treeModel.getRoot().toString(), "")) { + paths = new String[path.length - 1]; + for (int i = 1; i < path.length; i++) { + paths[i - 1] = path[i]; + } + } else { paths = path; root.setUserObject(ROOTTAG); } if (treeModel.getRoot() instanceof ExpandMutableTreeNode) { - selectNode((ExpandMutableTreeNode)treeModel.getRoot(), 0, paths); + selectNode((ExpandMutableTreeNode) treeModel.getRoot(), 0, paths); if (selectedNode != null) { TreePath treepath = new TreePath(treeModel.getPathToRoot(selectedNode)); xmlNodeTree.setSelectionPath(treepath); @@ -571,8 +577,8 @@ public class FileTableDataPane extends AbstractTableDataPane { } } //防止某种操作导致添加的tag作为root出现。 - if(ComparatorUtils.equals(root.toString(),ROOTTAG)){ - root.setUserObject(StringUtils.EMPTY); + if (ComparatorUtils.equals(root.toString(), ROOTTAG)) { + root.setUserObject(StringUtils.EMPTY); } } } @@ -638,7 +644,7 @@ public class FileTableDataPane extends AbstractTableDataPane { ttd.setDelimiter(this.showDelimiter()); ttd.setIgnoreOneMoreDelimiter(ignoreOneMoreDelimiterCheckBox.isSelected()); ttd.setNeedColumnName(needColumnNameCheckBox.isSelected()); - ttd.setCharset((String)charsetComboBox.getSelectedItem()); + ttd.setCharset((String) charsetComboBox.getSelectedItem()); fileTableData = ttd; return ttd; } @@ -667,12 +673,12 @@ public class FileTableDataPane extends AbstractTableDataPane { xmlColumnsList.clear(); ExpandMutableTreeNode treeNode; boolean flag = true; - for(int i = 0;i < selectedNode.getChildCount();i++){ + for (int i = 0; i < selectedNode.getChildCount(); i++) { treeNode = (ExpandMutableTreeNode) selectedNode.getChildAt(i); - if(treeNode.isLeaf()){ + if (treeNode.isLeaf()) { xmlColumnsList.add(treeNode.toString()); - }else{ - if(flag){ + } else { + if (flag) { flag = false; finalSelectedNode = treeNode; leafNode(treeNode); @@ -692,34 +698,34 @@ public class FileTableDataPane extends AbstractTableDataPane { } //wikky:构建树时为了美观把添加的根节点值赋为空显示,现在还得该回去使得预览时能够顺利取到数据。 - private String[] getPaths(){ + private String[] getPaths() { TreePath treePath = GUICoreUtils.getTreePath(finalSelectedNode); String path = StringUtils.EMPTY; if (treePath != null) { Object[] paths = treePath.getPath(); for (int i = 0; i < paths.length; i++) { - path+="/" + paths[i]; + path += "/" + paths[i]; } } if (path.startsWith("/")) { path = path.substring(1); } String[] paths = path.split("/"); - if(ComparatorUtils.equals(paths[0],StringUtils.EMPTY)){ + if (ComparatorUtils.equals(paths[0], StringUtils.EMPTY)) { paths[0] = ROOTTAG; } return paths; } - private void leafNode(ExpandMutableTreeNode treeNode){ + private void leafNode(ExpandMutableTreeNode treeNode) { boolean flag = true; ExpandMutableTreeNode firstNode; - for(int i = 0;i < treeNode.getChildCount();i++){ + for (int i = 0; i < treeNode.getChildCount(); i++) { firstNode = (ExpandMutableTreeNode) treeNode.getChildAt(i); - if(firstNode.isLeaf()){ + if (firstNode.isLeaf()) { xmlColumnsList.add(firstNode.toString()); - }else{ - if(flag){ + } else { + if (flag) { flag = false; finalSelectedNode = treeNode; leafNode(firstNode); @@ -729,16 +735,16 @@ public class FileTableDataPane extends AbstractTableDataPane { } private void selectNode(ExpandMutableTreeNode node, int layer, String[] paths) { - if (selectedNode != null || node == null){ + if (selectedNode != null || node == null) { return; } - if (layer < paths.length && paths[layer] != null && ComparatorUtils.equals(paths[layer],node.getUserObject())) { - if (layer == paths.length -1) { + if (layer < paths.length && paths[layer] != null && ComparatorUtils.equals(paths[layer], node.getUserObject())) { + if (layer == paths.length - 1) { selectedNode = node; return; } for (int i = 0; i < node.getChildCount(); i++) { - selectNode((ExpandMutableTreeNode)node.getChildAt(i), layer + 1, paths); + selectNode((ExpandMutableTreeNode) node.getChildAt(i), layer + 1, paths); } } } @@ -800,8 +806,8 @@ public class FileTableDataPane extends AbstractTableDataPane { toolbarDef.addShortCut(refreshAction); UIToolbar toolBar = ToolBarDef.createJToolBar(); toolbarDef.updateToolBar(toolBar); - toolbarPanel.add(keyPointLaber,BorderLayout.WEST); - toolbarPanel.add(toolBar,BorderLayout.EAST); + toolbarPanel.add(keyPointLaber, BorderLayout.WEST); + toolbarPanel.add(toolBar, BorderLayout.EAST); this.add(toolbarPanel, BorderLayout.NORTH); } @@ -817,6 +823,7 @@ public class FileTableDataPane extends AbstractTableDataPane { this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/refresh.png")); } + @Override public void actionPerformed(ActionEvent e) { xmlNodeTree.waitRefresh(); xmlNodeTree.refreshData(); @@ -845,8 +852,9 @@ public class FileTableDataPane extends AbstractTableDataPane { } private MouseListener treeMouseListener = new MouseAdapter() { + @Override public void mousePressed(MouseEvent e) { - if (XMLNodeTree.this.getModel() != treeModel){ + if (XMLNodeTree.this.getModel() != treeModel) { return; } int selRow = XMLNodeTree.this.getRowForLocation(e.getX(), e.getY()); @@ -858,12 +866,12 @@ public class FileTableDataPane extends AbstractTableDataPane { return;//没有选中某个树节点,就直接返回啦 } Object selObject = selPath.getLastPathComponent(); - if (selObject instanceof ExpandMutableTreeNode ) { + if (selObject instanceof ExpandMutableTreeNode) { ExpandMutableTreeNode expandMutableTreeNode = (ExpandMutableTreeNode) selObject; if (!expandMutableTreeNode.isLeaf()) { selectedNode = expandMutableTreeNode; } else { - selectedNode = (ExpandMutableTreeNode)expandMutableTreeNode.getParent(); + selectedNode = (ExpandMutableTreeNode) expandMutableTreeNode.getParent(); } } } @@ -906,7 +914,7 @@ public class FileTableDataPane extends AbstractTableDataPane { DataSource dataSource = null; if (localFileRadioButton.isSelected()) { String localTextString = StringUtils.trimToNull(localText.getText()); - if(StringUtils.isEmpty(localTextString)){ + if (StringUtils.isEmpty(localTextString)) { FineLoggerFactory.getLogger().info("The file path is empty."); loadedTreeModel(); return; @@ -914,7 +922,7 @@ public class FileTableDataPane extends AbstractTableDataPane { dataSource = new FileDataSource(localTextString, params); } else { String urlTextString = StringUtils.trimToNull(urlText.getText()); - if (StringUtils.isEmpty(urlTextString)){ + if (StringUtils.isEmpty(urlTextString)) { FineLoggerFactory.getLogger().info("The url path is empty."); loadedTreeModel(); return; @@ -922,7 +930,7 @@ public class FileTableDataPane extends AbstractTableDataPane { dataSource = new URLDataSource(urlTextString, params); } try { - InputStream in,input; + InputStream in, input; if ((in = dataSource.getSourceStream(params)) != null) { String xmlString = Utils.inputStream2String(in, (String) encodingComboBox.getSelectedItem()); String stringXml = addTag(xmlString); @@ -941,16 +949,20 @@ public class FileTableDataPane extends AbstractTableDataPane { FineLoggerFactory.getLogger().error(e.getMessage(), e); loadedTreeModel(); } - if(treeModel.getChildCount(treeModel.getRoot()) == 1){ - treeModel = new DefaultTreeModel((ExpandMutableTreeNode) treeModel.getChild(treeModel.getRoot(),0)); - }else{ + if (treeModel == null) { + FineLoggerFactory.getLogger().info("The file is wrong or bad, can not create the XMLReader."); + return; + } + if (treeModel.getChildCount(treeModel.getRoot()) == 1) { + treeModel = new DefaultTreeModel((ExpandMutableTreeNode) treeModel.getChild(treeModel.getRoot(), 0)); + } else { ExpandMutableTreeNode root = (ExpandMutableTreeNode) treeModel.getRoot(); root.setUserObject(StringUtils.EMPTY); } this.setModel(treeModel); } - private void loadedTreeModel(){ + private void loadedTreeModel() { ExpandMutableTreeNode rootTreeNode = new ExpandMutableTreeNode(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Loaded_Tree_Model")); rootTreeNode.setExpanded(false); rootTreeNode.setAllowsChildren(false); @@ -958,14 +970,14 @@ public class FileTableDataPane extends AbstractTableDataPane { XMLNodeTree.this.setModel(loadedTreeModel); } - private String addTag(String string){ + private String addTag(String string) { String stringWithTag; int beginIndex = 0; int firstIndex = string.indexOf(">"); int endIndex = string.length(); - String firstPart = string.substring(beginIndex,firstIndex + 1); + String firstPart = string.substring(beginIndex, firstIndex + 1); String secondPart = STARTTAG; - String thirdPart = string.substring(firstIndex + 1,endIndex); + String thirdPart = string.substring(firstIndex + 1, endIndex); String lastPart = ENDTAG; stringWithTag = firstPart + secondPart + thirdPart + lastPart; return stringWithTag; @@ -986,6 +998,7 @@ public class FileTableDataPane extends AbstractTableDataPane { this.layer = layer; } + @Override public void readXML(XMLableReader reader) { String nodeName; if (this.layer < 0) { diff --git a/designer-base/src/main/java/com/fr/design/extra/LoginWebBridge.java b/designer-base/src/main/java/com/fr/design/extra/LoginWebBridge.java index 43bb8131a4..50add423f4 100644 --- a/designer-base/src/main/java/com/fr/design/extra/LoginWebBridge.java +++ b/designer-base/src/main/java/com/fr/design/extra/LoginWebBridge.java @@ -1,6 +1,7 @@ package com.fr.design.extra; import com.fr.base.passport.FinePassportManager; +import com.fr.concurrent.NamedThreadFactory; import com.fr.config.MarketConfig; import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.PluginLoginExecutor; @@ -8,47 +9,30 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.general.CloudCenter; import com.fr.general.http.HttpClient; import com.fr.log.FineLoggerFactory; -import com.fr.stable.EncodeConstants; import com.fr.stable.StringUtils; import javafx.concurrent.Task; import javafx.scene.web.WebEngine; import netscape.javascript.JSObject; + import javax.swing.JDialog; import javax.swing.SwingUtilities; import java.awt.Color; import java.awt.Desktop; -import java.io.UnsupportedEncodingException; import java.net.URI; -import java.net.URLEncoder; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * @author vito */ public class LoginWebBridge { - //默认查询消息时间, 30s - private static final long CHECK_MESSAGE_TIME = 30 * 1000L; - //数据查询正常的标志 ok - private static final String SUCCESS_MESSAGE_STATUS = "ok"; - //数据通讯失败 - private static final String FAILED_MESSAGE_STATUS = "error"; //最低消息的条数 private static final int MIN_MESSAGE_COUNT = 0; - //登录成功 - private static final String LOGININ = "0"; - //用户名不存在 - private static final String USERNAME_NOT_EXSIT = "-1"; - //密码错误 - private static final String PASSWORD_ERROR = "-2"; - //未知错误 - private static final String UNKNOWN_ERROR = "-3"; //网络连接失败 private static final String NET_FAILED = "-4"; //用户名,密码为空 private static final String LOGIN_INFO_EMPTY = "-5"; - private static final int TIME_OUT = 10000; - private static final String LOGIN_SUCCESS = "ok"; - private static final String LOGIN_FAILED = "failed"; private static final Color LOGIN_BACKGROUND = new Color(184, 220, 242); private static LoginWebBridge helper; //消息条数 @@ -131,22 +115,6 @@ public class LoginWebBridge { return client.isServerAlive(); } - private String encode(String str) { - try { - return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8); - } catch (UnsupportedEncodingException e) { - return str; - } - } - - private void sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - } - /** * 注册页面 */ @@ -178,7 +146,9 @@ public class LoginWebBridge { */ public void defaultLogin(String username, String password, final JSObject callback) { Task task = new PluginTask<>(webEngine, callback, new PluginLoginExecutor(username, password)); - new Thread(task).start(); + ExecutorService es = Executors.newSingleThreadExecutor(new NamedThreadFactory("bbsDefaultLogin")); + es.submit(task); + es.shutdown(); } /** @@ -250,10 +220,6 @@ public class LoginWebBridge { } } - public void openUrlAtLocalWebBrowser(WebEngine eng, String url) { - if (url.indexOf("qqLogin.html") > 0) { - return; - } } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/extra/PluginControlPane.java b/designer-base/src/main/java/com/fr/design/extra/PluginControlPane.java index 393626ce01..e5b4feba28 100644 --- a/designer-base/src/main/java/com/fr/design/extra/PluginControlPane.java +++ b/designer-base/src/main/java/com/fr/design/extra/PluginControlPane.java @@ -15,6 +15,7 @@ import com.fr.plugin.manage.control.PluginTaskCallback; import com.fr.plugin.manage.control.PluginTaskResult; import com.fr.plugin.view.PluginView; import com.fr.stable.StringUtils; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -142,6 +143,7 @@ public class PluginControlPane extends BasicPane { } } + @Nullable public PluginView getSelectedPlugin() { return (PluginView) pluginList.getSelectedValue(); } diff --git a/designer-base/src/main/java/com/fr/design/extra/PluginFromStorePane.java b/designer-base/src/main/java/com/fr/design/extra/PluginFromStorePane.java index 0f78a562c5..115cc87dc1 100644 --- a/designer-base/src/main/java/com/fr/design/extra/PluginFromStorePane.java +++ b/designer-base/src/main/java/com/fr/design/extra/PluginFromStorePane.java @@ -28,8 +28,6 @@ import java.util.List; * @since 8.0 */ public class PluginFromStorePane extends PluginAbstractLoadingViewPane, Void> { - private static final int LISTNUM1 = 1; - private static final int LISTNUM100 = 100; private UILabel errorMsgLabel; private UITabbedPane tabbedPane; private PluginControlPane controlPane; @@ -45,6 +43,7 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane loadData() throws Exception { - //Thread.sleep(3000); return PluginsReaderFromStore.readPlugins(); } @@ -140,6 +139,7 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane plugins) { controlPane.loadPlugins(plugins); tabbedPane.setTitleAt(2, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_All_Plugins") + "(" + plugins.size() + ")"); @@ -150,10 +150,12 @@ public class PluginFromStorePane extends PluginAbstractLoadingViewPane Date: Mon, 26 Aug 2019 19:23:30 +0800 Subject: [PATCH 33/60] =?UTF-8?q?REPORT-19466=20=E3=80=90=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E7=A7=BB=E5=8A=A8=E7=AB=AF=E3=80=91=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=BA=A7=E6=8E=A7=E5=88=B6=E9=80=89=E4=B8=AD=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/widget/ui/designer/mobile/ElementCaseDefinePane.java | 1 + 1 file changed, 1 insertion(+) diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java index 5f255bb60f..88a8d3bffb 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/mobile/ElementCaseDefinePane.java @@ -168,6 +168,7 @@ public class ElementCaseDefinePane extends MobileWidgetDefinePane { break; case "allowFullCheckBox": ((ElementCaseEditor) xCreator.toData()).setAllowFullScreen(allowFullCheckBox.isSelected()); + break; case "functionalWhenUnactivatedCheckBox": ((ElementCaseEditor) xCreator.toData()).setFunctionalWhenUnactivated(functionalWhenUnactivatedCheckBox.isSelected()); } From 32b9a662e933b3e56942af836847d60860977af5 Mon Sep 17 00:00:00 2001 From: Bryant Date: Tue, 27 Aug 2019 09:11:57 +0800 Subject: [PATCH 34/60] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=20sonar?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/syntax/ui/rtextarea/RTextAreaEditorKit.java | 2 ++ .../VolatileImageBackgroundPainterStrategy.java | 10 ++++++---- .../src/main/java/com/fr/design/icon/LockIcon.java | 6 ++++++ .../src/main/java/com/fr/design/icon/WarningIcon.java | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaEditorKit.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaEditorKit.java index f95aa1260e..277064c2f9 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaEditorKit.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaEditorKit.java @@ -902,6 +902,8 @@ public class RTextAreaEditorKit extends DefaultEditorKit { } } catch (BadLocationException bl) { } + }else if (textArea == null) { + throw new IllegalArgumentException("RTextArea can not be null!"); } if (beep) diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java index 11aaca364a..c7be420de9 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java @@ -9,6 +9,8 @@ */ package com.fr.design.gui.syntax.ui.rtextarea; +import com.fr.log.FineLoggerFactory; + import java.awt.Graphics; import java.awt.Image; import java.awt.image.VolatileImage; @@ -95,9 +97,9 @@ public class VolatileImageBackgroundPainterStrategy try { tracker.waitForID(1); } catch (InterruptedException e) { - e.printStackTrace(); + FineLoggerFactory.getLogger().error(e.getMessage(),e); bgImage = null; - return; + Thread.currentThread().interrupt(); } finally { tracker.removeImage(i, 1); } @@ -106,9 +108,9 @@ public class VolatileImageBackgroundPainterStrategy try { tracker.waitForID(0); } catch (InterruptedException e) { - e.printStackTrace(); + FineLoggerFactory.getLogger().error(e.getMessage(),e); bgImage = null; - return; + Thread.currentThread().interrupt(); } finally { tracker.removeImage(bgImage, 0); } diff --git a/designer-base/src/main/java/com/fr/design/icon/LockIcon.java b/designer-base/src/main/java/com/fr/design/icon/LockIcon.java index 934d53b08e..ee54b6ea86 100644 --- a/designer-base/src/main/java/com/fr/design/icon/LockIcon.java +++ b/designer-base/src/main/java/com/fr/design/icon/LockIcon.java @@ -34,6 +34,7 @@ public class LockIcon extends ImageIcon { } } + @Override public void paintIcon(Component c, Graphics g, int x, int y) { if (mainImage != null) { g.drawImage(mainImage, x, y, c); @@ -48,6 +49,7 @@ public class LockIcon extends ImageIcon { * * @param image the image */ + @Override protected void loadImage(Image image) { synchronized (tracker) { tracker.addImage(image, 0); @@ -55,6 +57,7 @@ public class LockIcon extends ImageIcon { tracker.waitForID(0, 0); } catch (InterruptedException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); + Thread.currentThread().interrupt(); } loadStatus = tracker.statusID(0, false); @@ -70,6 +73,7 @@ public class LockIcon extends ImageIcon { * * @return the Image object for this ImageIcon */ + @Override public Image getImage() { return mainImage; } @@ -85,6 +89,7 @@ public class LockIcon extends ImageIcon { * * @return the width in pixels of this icon */ + @Override public int getIconWidth() { return width; } @@ -94,6 +99,7 @@ public class LockIcon extends ImageIcon { * * @return the height in pixels of this icon */ + @Override public int getIconHeight() { return height; } diff --git a/designer-base/src/main/java/com/fr/design/icon/WarningIcon.java b/designer-base/src/main/java/com/fr/design/icon/WarningIcon.java index 9b22b40358..d70d62225d 100644 --- a/designer-base/src/main/java/com/fr/design/icon/WarningIcon.java +++ b/designer-base/src/main/java/com/fr/design/icon/WarningIcon.java @@ -59,6 +59,7 @@ public class WarningIcon extends ImageIcon { tracker.waitForID(0, 0); } catch (InterruptedException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); + Thread.currentThread().interrupt(); } tracker.statusID(0, false); From f48ab9ba6d5b6810494b8db3c2f4b38560475d02 Mon Sep 17 00:00:00 2001 From: "Bruce.Deng" Date: Tue, 27 Aug 2019 09:33:48 +0800 Subject: [PATCH 35/60] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=EF=BC=8Cs?= =?UTF-8?q?onar=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntax/ui/rsyntaxtextarea/WrappedSyntaxView.java | 5 +++++ .../ui/rsyntaxtextarea/parser/TaskTagParser.java | 5 +++++ .../design/gui/syntax/ui/rtextarea/LineNumberList.java | 10 +++++++++- .../fr/design/gui/syntax/ui/rtextarea/RTextArea.java | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/WrappedSyntaxView.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/WrappedSyntaxView.java index 5f2f83337f..b08b0caf76 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/WrappedSyntaxView.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/WrappedSyntaxView.java @@ -1351,6 +1351,11 @@ System.err.println(">>> >>> calculated number of lines for this view (line " + l // Start at alloc.x since this chunk starts // at the beginning of a physical line. + if (tlist == null) { + p0 = (p == p0) ? p1 : p; + alloc.y += alloc.height; + continue; + } int n = tlist.getListOffset(textArea, WrappedSyntaxView.this, alloc.x, x); diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/parser/TaskTagParser.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/parser/TaskTagParser.java index 126193e829..7366c1d636 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/parser/TaskTagParser.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/parser/TaskTagParser.java @@ -18,6 +18,7 @@ import com.fr.design.gui.syntax.ui.rsyntaxtextarea.ErrorStrip; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxDocument; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.SyntaxConstants; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.Token; +import com.fr.stable.StringUtils; /** @@ -60,6 +61,7 @@ public class TaskTagParser extends AbstractParser { } + @SuppressWarnings("squid:S2259") public ParseResult parse(RSyntaxDocument doc, String style) { Element root = doc.getDefaultRootElement(); @@ -101,6 +103,9 @@ public class TaskTagParser extends AbstractParser { } if (start>-1) { + if (StringUtils.isEmpty(text)) { + continue; + } text = text.substring(start); // TODO: Strip off end of MLC's if they're there. int len = text.length(); diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/LineNumberList.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/LineNumberList.java index b6cf8edd5f..3fd4c75045 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/LineNumberList.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/LineNumberList.java @@ -2,7 +2,7 @@ * 02/11/2009 * * LineNumberList.java - Renders line numbers in an RTextScrollPane. - * + * * This library is distributed under a modified BSD license. See the included * RSyntaxTextArea.License.txt file for details. */ @@ -349,6 +349,10 @@ public class LineNumberList extends AbstractGutterComponent int width = metrics.stringWidth(number); g.drawString(number, rhs-width,y); y += cellHeight; + if (fm == null) { + line++; + continue; + } Fold fold = fm.getFoldForLine(line-1); // Skip to next line to paint, taking extra care for lines with // block ends and begins together, e.g. "} else {" @@ -371,6 +375,10 @@ public class LineNumberList extends AbstractGutterComponent String number = Integer.toString(line + getLineNumberingStartIndex() - 1); g.drawString(number, RHS_BORDER_WIDTH, y); y += cellHeight; + if (fm == null) { + line++; + continue; + } Fold fold = fm.getFoldForLine(line-1); // Skip to next line to paint, taking extra care for lines with // block ends and begins together, e.g. "} else {" diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextArea.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextArea.java index 9ea11b64d6..d2e3284d77 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextArea.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextArea.java @@ -635,6 +635,9 @@ public class RTextArea extends RTextAreaBase implements Printable { parent = parent.getParent(); } KeyStroke backspace = KeyStroke.getKeyStroke("BACK_SPACE"); + if (inputMap == null) { + return; + } inputMap.put(backspace, DefaultEditorKit.deletePrevCharAction); } From 0b870a726d5a6d18f06194f06b8d8909bb10ddb1 Mon Sep 17 00:00:00 2001 From: Maksim Date: Tue, 27 Aug 2019 10:28:34 +0800 Subject: [PATCH 36/60] =?UTF-8?q?REPORT-20323=20sonar=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/mainframe/chart/gui/type/AreaPlotPane.java | 4 +++- .../design/mainframe/chart/gui/type/BarPlotPane.java | 10 ++++++---- .../mainframe/chart/gui/type/ColumnPlotPane.java | 10 ++++++---- .../design/mainframe/chart/gui/type/MeterPlotPane.java | 10 ++++++---- .../com/fr/van/chart/area/VanChartAreaPlotPane.java | 10 ++++++---- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AreaPlotPane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AreaPlotPane.java index a50bc52b5e..483a4f09f7 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AreaPlotPane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AreaPlotPane.java @@ -114,7 +114,9 @@ public class AreaPlotPane extends AbstractDeprecatedChartTypePane { ((Area3DPlot)plot).setStacked(true); ((Area3DPlot)plot).getyAxis().setPercentage(true); } - createAreaCondition(plot); + if(plot != null) { + createAreaCondition(plot); + } return plot; } diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/BarPlotPane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/BarPlotPane.java index cd5e1b4d66..1a3808a6a6 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/BarPlotPane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/BarPlotPane.java @@ -97,10 +97,12 @@ public class BarPlotPane extends AbstractBarPane{ } Plot cloned = null; - try { - cloned = (Plot)newPlot.clone(); - } catch (CloneNotSupportedException e) { - FineLoggerFactory.getLogger().error("Error In ColumnChart"); + if(newPlot != null) { + try { + cloned = (Plot) newPlot.clone(); + } catch (CloneNotSupportedException e) { + FineLoggerFactory.getLogger().error("Error In ColumnChart"); + } } return cloned; } diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/ColumnPlotPane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/ColumnPlotPane.java index 55de24714b..e421bdeba2 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/ColumnPlotPane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/ColumnPlotPane.java @@ -94,10 +94,12 @@ public class ColumnPlotPane extends AbstractBarPane{ } Plot cloned = null; - try { - cloned = (Plot)newPlot.clone(); - } catch (CloneNotSupportedException e) { - FineLoggerFactory.getLogger().error("Error In ColumnChart"); + if(newPlot != null) { + try { + cloned = (Plot) newPlot.clone(); + } catch (CloneNotSupportedException e) { + FineLoggerFactory.getLogger().error("Error In ColumnChart"); + } } return cloned; } diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/MeterPlotPane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/MeterPlotPane.java index a02bcf5d10..94527c04bb 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/MeterPlotPane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/MeterPlotPane.java @@ -66,10 +66,12 @@ public class MeterPlotPane extends AbstractDeprecatedChartTypePane { } Plot cloned = null; - try { - cloned = (Plot)newPlot.clone(); - } catch (CloneNotSupportedException e) { - FineLoggerFactory.getLogger().error("Error In ColumnChart"); + if(newPlot != null) { + try { + cloned = (Plot) newPlot.clone(); + } catch (CloneNotSupportedException e) { + FineLoggerFactory.getLogger().error("Error In ColumnChart"); + } } return cloned; } diff --git a/designer-chart/src/main/java/com/fr/van/chart/area/VanChartAreaPlotPane.java b/designer-chart/src/main/java/com/fr/van/chart/area/VanChartAreaPlotPane.java index 2642daa288..3d655d005e 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/area/VanChartAreaPlotPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/area/VanChartAreaPlotPane.java @@ -68,10 +68,12 @@ public class VanChartAreaPlotPane extends AbstractVanChartTypePane { } } Plot cloned = null; - try { - cloned = (Plot) newPlot.clone(); - } catch (CloneNotSupportedException e) { - FineLoggerFactory.getLogger().error("Error In AreaChart"); + if(newPlot != null) { + try { + cloned = (Plot) newPlot.clone(); + } catch (CloneNotSupportedException e) { + FineLoggerFactory.getLogger().error("Error In AreaChart"); + } } return cloned; } From a6c1ce1a6facac2e9d22bbd8f86cf49739d2bd70 Mon Sep 17 00:00:00 2001 From: jinbokai Date: Tue, 27 Aug 2019 10:33:28 +0800 Subject: [PATCH 37/60] REPORT-20328 sonar --- .../gui/itable/AbstractPropertyTable.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/itable/AbstractPropertyTable.java b/designer-base/src/main/java/com/fr/design/gui/itable/AbstractPropertyTable.java index 4367d8f6b5..ccdd8eb647 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itable/AbstractPropertyTable.java +++ b/designer-base/src/main/java/com/fr/design/gui/itable/AbstractPropertyTable.java @@ -3,11 +3,15 @@ */ package com.fr.design.gui.itable; -import java.awt.*; +import com.fr.general.ComparatorUtils; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; - import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.table.AbstractTableModel; @@ -16,9 +20,6 @@ import javax.swing.table.JTableHeader; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; -import com.fr.general.ComparatorUtils; - - /** * @author richer * @since 6.5.3 @@ -109,8 +110,8 @@ public abstract class AbstractPropertyTable extends JTable { @Override public TableCellEditor getCellEditor(int row, int column) { - if (groups != null) { - Point pIndex = getGroupIndex(row); + Point pIndex = getGroupIndex(row); + if (groups != null && pIndex != null) { PropertyGroup group = groups.get(pIndex.x); if (pIndex.y == 0) { return super.getCellEditor(row, column); @@ -162,7 +163,7 @@ public abstract class AbstractPropertyTable extends JTable { int row = AbstractPropertyTable.super.rowAtPoint(e.getPoint()); if (row != -1) { Point pIndex = getGroupIndex(row); - if (pIndex.y == 0 && e.getClickCount() > 1) { + if (pIndex != null && pIndex.y == 0 && e.getClickCount() > 1) { toggleCollapse(pIndex.x); } } @@ -180,7 +181,7 @@ public abstract class AbstractPropertyTable extends JTable { int row = AbstractPropertyTable.super.rowAtPoint(e.getPoint()); if (row != -1) { Point pIndex = getGroupIndex(row); - if (pIndex.y == 0 && e.getClickCount() == 1 && e.getX() < PROPERTY_ICON_WIDTH) { + if (pIndex != null && pIndex.y == 0 && e.getClickCount() == 1 && e.getX() < PROPERTY_ICON_WIDTH) { toggleCollapse(pIndex.x); } } @@ -263,6 +264,9 @@ public abstract class AbstractPropertyTable extends JTable { @Override public void setValueAt(Object aValue, int row, int column) { Point pIndex = getGroupIndex(row); + if (pIndex == null) { + return; + } PropertyGroup group = groups.get(pIndex.x); if (pIndex.y != 0) { Object old_value = getValueAt(row, column); @@ -276,16 +280,11 @@ public abstract class AbstractPropertyTable extends JTable { @Override public boolean isCellEditable(int row, int column) { Point pIndex = getGroupIndex(row); - PropertyGroup group = groups.get(pIndex.x); - if (pIndex.y == 0) { - if (column == 0) { - return false; - } else { - return false; - } - } else { - return column == 1 && group.getModel().isEditable(pIndex.y - 1); + if (pIndex == null) { + return false; } + PropertyGroup group = groups.get(pIndex.x); + return pIndex.y != 0 && (column == 1 && group.getModel().isEditable(pIndex.y - 1)); } } -} \ No newline at end of file +} From 7937140272a46da879b05a99677b269c487f330e Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 27 Aug 2019 11:34:00 +0800 Subject: [PATCH 38/60] =?UTF-8?q?=E6=8A=A5=E8=A1=A8REPORT-20320=20sonar?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RSyntaxTextAreaEditorKit.java | 3808 ++++++++--------- .../ui/rsyntaxtextarea/RSyntaxUtilities.java | 2565 +++++------ 2 files changed, 3192 insertions(+), 3181 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextAreaEditorKit.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextAreaEditorKit.java index c431e329c8..6aa0cd8e4f 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextAreaEditorKit.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextAreaEditorKit.java @@ -2,29 +2,39 @@ * 08/29/2004 * * RSyntaxTextAreaEditorKit.java - The editor kit used by RSyntaxTextArea. - * + * * This library is distributed under a modified BSD license. See the included * RSyntaxTextArea.License.txt file for details. */ package com.fr.design.gui.syntax.ui.rsyntaxtextarea; -import java.awt.*; -import java.awt.event.*; -import java.util.ResourceBundle; -import java.util.Stack; -import javax.swing.*; -import javax.swing.text.*; - import com.fr.design.gui.syntax.ui.rsyntaxtextarea.folding.Fold; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.folding.FoldCollapser; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.folding.FoldManager; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.templates.CodeTemplate; import com.fr.design.gui.syntax.ui.rtextarea.Gutter; import com.fr.design.gui.syntax.ui.rtextarea.IconRowHeader; -import com.fr.design.gui.syntax.ui.rtextarea.RecordableTextAction; import com.fr.design.gui.syntax.ui.rtextarea.RTextArea; import com.fr.design.gui.syntax.ui.rtextarea.RTextAreaEditorKit; +import com.fr.design.gui.syntax.ui.rtextarea.RecordableTextAction; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JScrollPane; +import javax.swing.KeyStroke; +import javax.swing.UIManager; +import javax.swing.text.BadLocationException; +import javax.swing.text.Caret; +import javax.swing.text.Document; +import javax.swing.text.Element; +import javax.swing.text.Segment; +import javax.swing.text.TextAction; +import java.awt.Component; +import java.awt.Font; +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.util.Objects; +import java.util.Stack; /** @@ -32,24 +42,24 @@ import com.fr.design.gui.syntax.ui.rtextarea.RTextAreaEditorKit; * programming-specific stuff. There are currently subclasses to handle: * *
    - *
  • Toggling code folds.
  • - *
  • Aligning "closing" curly braces with their matches, if the current - * programming language uses curly braces to identify code blocks.
  • - *
  • Copying the current selection as RTF.
  • - *
  • Block indentation (increasing the indent of one or multiple lines)
  • - *
  • Block un-indentation (decreasing the indent of one or multiple lines) - *
  • - *
  • Inserting a "code template" when a configurable key (e.g. a space) is - * pressed
  • - *
  • Decreasing the point size of all fonts in the text area
  • - *
  • Increasing the point size of all fonts in the text area
  • - *
  • Moving the caret to the "matching bracket" of the one at the current - * caret position
  • - *
  • Toggling whether the currently selected lines are commented out.
  • - *
  • Better selection of "words" on mouse double-clicks for programming - * languages.
  • - *
  • Better keyboard navigation via Ctrl+arrow keys for programming - * languages.
  • + *
  • Toggling code folds.
  • + *
  • Aligning "closing" curly braces with their matches, if the current + * programming language uses curly braces to identify code blocks.
  • + *
  • Copying the current selection as RTF.
  • + *
  • Block indentation (increasing the indent of one or multiple lines)
  • + *
  • Block un-indentation (decreasing the indent of one or multiple lines) + *
  • + *
  • Inserting a "code template" when a configurable key (e.g. a space) is + * pressed
  • + *
  • Decreasing the point size of all fonts in the text area
  • + *
  • Increasing the point size of all fonts in the text area
  • + *
  • Moving the caret to the "matching bracket" of the one at the current + * caret position
  • + *
  • Toggling whether the currently selected lines are commented out.
  • + *
  • Better selection of "words" on mouse double-clicks for programming + * languages.
  • + *
  • Better keyboard navigation via Ctrl+arrow keys for programming + * languages.
  • *
* * @author Robert Futrell @@ -57,1884 +67,1872 @@ import com.fr.design.gui.syntax.ui.rtextarea.RTextAreaEditorKit; */ public class RSyntaxTextAreaEditorKit extends RTextAreaEditorKit { - private static final long serialVersionUID = 1L; - - public static final String rstaCloseCurlyBraceAction = "RSTA.CloseCurlyBraceAction"; - public static final String rstaCloseMarkupTagAction = "RSTA.CloseMarkupTagAction"; - public static final String rstaCollapseAllFoldsAction = "RSTA.CollapseAllFoldsAction"; - public static final String rstaCollapseAllCommentFoldsAction = "RSTA.CollapseAllCommentFoldsAction"; - public static final String rstaCollapseFoldAction = "RSTA.CollapseFoldAction"; - public static final String rstaCopyAsRtfAction = "RSTA.CopyAsRtfAction"; - public static final String rstaDecreaseIndentAction = "RSTA.DecreaseIndentAction"; - public static final String rstaExpandAllFoldsAction = "RSTA.ExpandAllFoldsAction"; - public static final String rstaExpandFoldAction = "RSTA.ExpandFoldAction"; - public static final String rstaGoToMatchingBracketAction = "RSTA.GoToMatchingBracketAction"; - public static final String rstaPossiblyInsertTemplateAction = "RSTA.TemplateAction"; - public static final String rstaToggleCommentAction = "RSTA.ToggleCommentAction"; - public static final String rstaToggleCurrentFoldAction = "RSTA.ToggleCurrentFoldAction"; - - /** - * The actions that RSyntaxTextAreaEditorKit adds to those of - * RTextAreaEditorKit. - */ - private static final Action[] defaultActions = { - new CloseCurlyBraceAction(), - new CloseMarkupTagAction(), - new BeginWordAction(beginWordAction, false), - new BeginWordAction(selectionBeginWordAction, true), - new ChangeFoldStateAction(rstaCollapseFoldAction, true), - new ChangeFoldStateAction(rstaExpandFoldAction, false), - new CollapseAllFoldsAction(), - new CopyAsRtfAction(), - //new DecreaseFontSizeAction(), - new DecreaseIndentAction(), - new DeletePrevWordAction(), - new EndAction(endAction, false), - new EndAction(selectionEndAction, true), - new EndWordAction(endWordAction, false), - new EndWordAction(endWordAction, true), - new ExpandAllFoldsAction(), - new GoToMatchingBracketAction(), - new InsertBreakAction(), - //new IncreaseFontSizeAction(), - new InsertTabAction(), - new NextWordAction(nextWordAction, false), - new NextWordAction(selectionNextWordAction, true), - new PossiblyInsertTemplateAction(), - new PreviousWordAction(previousWordAction, false), - new PreviousWordAction(selectionPreviousWordAction, true), - new SelectWordAction(), - new ToggleCommentAction(), - }; - - - /** - * Constructor. - */ - public RSyntaxTextAreaEditorKit() { - } - - - /** - * Returns the default document used by RSyntaxTextAreas. - * - * @return The document. - */ - @Override - public Document createDefaultDocument() { - return new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_NONE); - } - - - /** - * Overridden to return a row header that is aware of folding. - * - * @param textArea The text area. - * @return The icon row header. - */ - @Override - public IconRowHeader createIconRowHeader(RTextArea textArea) { - return new FoldingAwareIconRowHeader((RSyntaxTextArea)textArea); - } - - - /** - * Fetches the set of commands that can be used - * on a text component that is using a model and - * view produced by this kit. - * - * @return the command list - */ - @Override - public Action[] getActions() { - return TextAction.augmentList(super.getActions(), - RSyntaxTextAreaEditorKit.defaultActions); - } - - - /** - * Returns localized text for an action. There's definitely a better place - * for this functionality. - * - * @param key The key into the action resource bundle. - * @return The localized text. - */ - public static String getString(String key) { - return com.fr.design.i18n.Toolkit.i18nText(key); - } - - - /** - * Positions the caret at the beginning of the word. This class is here - * to better handle finding the "beginning of the word" for programming - * languages. - */ - protected static class BeginWordAction - extends RTextAreaEditorKit.BeginWordAction { - - private Segment seg; - - protected BeginWordAction(String name, boolean select) { - super(name, select); - seg = new Segment(); - } - - @Override - protected int getWordStart(RTextArea textArea, int offs) - throws BadLocationException { - - if (offs==0) { - return offs; - } - - RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); - int line = textArea.getLineOfOffset(offs); - int start = textArea.getLineStartOffset(line); - if (offs==start) { - return start; - } - int end = textArea.getLineEndOffset(line); - if (line!=textArea.getLineCount()-1) { - end--; - } - doc.getText(start, end-start, seg); - - // Determine the "type" of char at offs - lower case, upper case, - // whitespace or other. We take special care here as we're starting - // in the middle of the Segment to check whether we're already at - // the "beginning" of a word. - int firstIndex = seg.getBeginIndex() + (offs-start) - 1; - seg.setIndex(firstIndex); - char ch = seg.current(); - char nextCh = offs==end ? 0 : seg.array[seg.getIndex() + 1]; - - // The "word" is a group of letters and/or digits - if (Character.isLetterOrDigit(ch)) { - if (offs!=end && !Character.isLetterOrDigit(nextCh)) { - return offs; - } - do { - ch = seg.previous(); - } while (Character.isLetterOrDigit(ch)); - } - - // The "word" is whitespace - else if (Character.isWhitespace(ch)) { - if (offs!=end && !Character.isWhitespace(nextCh)) { - return offs; - } - do { - ch = seg.previous(); - } while (Character.isWhitespace(ch)); - } - - // Otherwise, the "word" a single "something else" char (operator, - // etc.). - - offs -= firstIndex - seg.getIndex() + 1;//seg.getEndIndex() - seg.getIndex(); - if (ch!=Segment.DONE && nextCh!='\n') { - offs++; - } - - return offs; - - } - - } - - - /** - * Expands or collapses the nearest fold. - */ - public static class ChangeFoldStateAction extends FoldRelatedAction { - - private boolean collapse; - - public ChangeFoldStateAction(String name, boolean collapse) { - super(name); - this.collapse = collapse; - } - - public ChangeFoldStateAction(String name, Icon icon, - String desc, Integer mnemonic, KeyStroke accelerator) { - super(name, icon, desc, mnemonic, accelerator); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; - if (rsta.isCodeFoldingEnabled()) { - Fold fold = getClosestFold(rsta); - if (fold!=null) { - fold.setCollapsed(collapse); - } - possiblyRepaintGutter(textArea); - } - else { - UIManager.getLookAndFeel().provideErrorFeedback(rsta); - } - } - - @Override - public final String getMacroID() { - return getName(); - } - - } - - - /** - * Action that (optionally) aligns a closing curly brace with the line - * containing its matching opening curly brace. - */ - public static class CloseCurlyBraceAction extends RecordableTextAction { - - private static final long serialVersionUID = 1L; - - private Point bracketInfo; - private Segment seg; - - public CloseCurlyBraceAction() { - super(rstaCloseCurlyBraceAction); - seg = new Segment(); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - - RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; - RSyntaxDocument doc = (RSyntaxDocument)rsta.getDocument(); - boolean alignCurlyBraces = rsta.isAutoIndentEnabled() && - doc.getCurlyBracesDenoteCodeBlocks(); - - if (alignCurlyBraces) { - textArea.beginAtomicEdit(); - } - - try { - - textArea.replaceSelection("}"); - - // If the user wants to align curly braces... - if (alignCurlyBraces) { - - Element root = doc.getDefaultRootElement(); - int dot = rsta.getCaretPosition() - 1; // Start before '{' - int line = root.getElementIndex(dot); - Element elem = root.getElement(line); - int start = elem.getStartOffset(); - - // Get the current line's text up to the '}' entered. - try { - doc.getText(start, dot-start, seg); - } catch (BadLocationException ble) { // Never happens - ble.printStackTrace(); - return; - } - - // Only attempt to align if there's only whitespace up to - // the '}' entered. - for (int i=0; i-1) { - try { - String ws = RSyntaxUtilities.getLeadingWhitespace( - doc, bracketInfo.y); - rsta.replaceRange(ws, start, dot); - } catch (BadLocationException ble) { - ble.printStackTrace(); - return; - } - } - - } - - } finally { - if (alignCurlyBraces) { - textArea.endAtomicEdit(); - } - } - - } - - @Override - public final String getMacroID() { - return rstaCloseCurlyBraceAction; - } - - } - - - /** - * (Optionally) completes a closing markup tag. - */ - public static class CloseMarkupTagAction extends RecordableTextAction { - - private static final long serialVersionUID = 1L; - - public CloseMarkupTagAction() { - super(rstaCloseMarkupTagAction); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - - if (!textArea.isEditable() || !textArea.isEnabled()) { - UIManager.getLookAndFeel().provideErrorFeedback(textArea); - return; - } - - RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; - RSyntaxDocument doc = (RSyntaxDocument)rsta.getDocument(); - - Caret c = rsta.getCaret(); - boolean selection = c.getDot()!=c.getMark(); - rsta.replaceSelection("/"); - - // Don't automatically complete a tag if there was a selection - int dot = c.getDot(); - - if (doc.getLanguageIsMarkup() && - doc.getCompleteMarkupCloseTags() && - !selection && rsta.getCloseMarkupTags() && dot>1) { - - try { - - // Check actual char before token type, since it's quicker - char ch = doc.charAt(dot-2); - if (ch=='<' || ch=='[') { - - Token t = doc.getTokenListForLine( - rsta.getCaretLineNumber()); - t = RSyntaxUtilities.getTokenAtOffset(t, dot-1); - if (t!=null && t.getType()==Token.MARKUP_TAG_DELIMITER) { - //System.out.println("Huzzah - closing tag!"); - String tagName = discoverTagName(doc, dot); - if (tagName!=null) { - rsta.replaceSelection(tagName + (char)(ch+2)); - } - } - - } - - } catch (BadLocationException ble) { // Never happens - UIManager.getLookAndFeel().provideErrorFeedback(rsta); - ble.printStackTrace(); - } - - } - - } - - /** - * Discovers the name of the tag being closed. Assumes standard - * SGML-style markup tags. - * - * @param doc The document to parse. - * @param dot The location of the caret. This should be right after - * the start of a closing tag token (e.g. "</" - * or "[" in the case of BBCode). - * @return The name of the tag to close, or null if it - * could not be determined. - */ - private String discoverTagName(RSyntaxDocument doc, int dot) { - - Stack stack = new Stack(); - - Element root = doc.getDefaultRootElement(); - int curLine = root.getElementIndex(dot); - - for (int i=0; i<=curLine; i++) { - - Token t = doc.getTokenListForLine(i); - while (t!=null && t.isPaintable()) { - - if (t.getType()==Token.MARKUP_TAG_DELIMITER) { - if (t.isSingleChar('<') || t.isSingleChar('[')) { - t = t.getNextToken(); - while (t!=null && t.isPaintable()) { - if (t.getType()==Token.MARKUP_TAG_NAME || - // Being lenient here and also checking - // for attributes, in case they - // (incorrectly) have whitespace between - // the '<' char and the element name. - t.getType()==Token.MARKUP_TAG_ATTRIBUTE) { - stack.push(t.getLexeme()); - break; - } - t = t.getNextToken(); - } - } - else if (t.length()==2 && t.charAt(0)=='/' && - (t.charAt(1)=='>' || - t.charAt(1)==']')) { - if (!stack.isEmpty()) { // Always true for valid XML - stack.pop(); - } - } - else if (t.length()==2 && - (t.charAt(0)=='<' || t.charAt(0)=='[') && - t.charAt(1)=='/') { - String tagName = null; - if (!stack.isEmpty()) { // Always true for valid XML - tagName = stack.pop(); - } - if (t.getEndOffset()>=dot) { - return tagName; - } - } - } - - t = t.getNextToken(); - - } - - } - - return null; // Should never happen - - } - - @Override - public String getMacroID() { - return getName(); - } - - } - - - /** - * Collapses all comment folds. - */ - public static class CollapseAllCommentFoldsAction extends FoldRelatedAction{ - - private static final long serialVersionUID = 1L; - - public CollapseAllCommentFoldsAction() { - super(rstaCollapseAllCommentFoldsAction); - setProperties("Action.CollapseCommentFolds"); - } - - public CollapseAllCommentFoldsAction(String name, Icon icon, - String desc, Integer mnemonic, KeyStroke accelerator) { - super(name, icon, desc, mnemonic, accelerator); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; - if (rsta.isCodeFoldingEnabled()) { - FoldCollapser collapser = new FoldCollapser(); - collapser.collapseFolds(rsta.getFoldManager()); - possiblyRepaintGutter(textArea); - } - else { - UIManager.getLookAndFeel().provideErrorFeedback(rsta); - } - } - - @Override - public final String getMacroID() { - return rstaCollapseAllCommentFoldsAction; - } - - } - - - /** - * Collapses all folds. - */ - public static class CollapseAllFoldsAction extends FoldRelatedAction { - - private static final long serialVersionUID = 1L; - - public CollapseAllFoldsAction() { - this(false); - } - - public CollapseAllFoldsAction(boolean localizedName) { - super(rstaCollapseAllFoldsAction); - if (localizedName) { - setProperties("Action.CollapseAllFolds"); - } - } - - public CollapseAllFoldsAction(String name, Icon icon, - String desc, Integer mnemonic, KeyStroke accelerator) { - super(name, icon, desc, mnemonic, accelerator); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; - if (rsta.isCodeFoldingEnabled()) { - FoldCollapser collapser = new FoldCollapser() { - @Override - public boolean getShouldCollapse(Fold fold) { - return true; - } - }; - collapser.collapseFolds(rsta.getFoldManager()); - possiblyRepaintGutter(textArea); - } - else { - UIManager.getLookAndFeel().provideErrorFeedback(rsta); - } - } - - @Override - public final String getMacroID() { - return rstaCollapseAllFoldsAction; - } - - } - - - /** - * Action for copying text as RTF. - */ - public static class CopyAsRtfAction extends RecordableTextAction { - - private static final long serialVersionUID = 1L; - - public CopyAsRtfAction() { - super(rstaCopyAsRtfAction); - } - - public CopyAsRtfAction(String name, Icon icon, String desc, - Integer mnemonic, KeyStroke accelerator) { - super(name, icon, desc, mnemonic, accelerator); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - ((RSyntaxTextArea)textArea).copyAsRtf(); - textArea.requestFocusInWindow(); - } - - @Override - public final String getMacroID() { - return getName(); - } - - } - - - /** - * Action for decreasing the font size of all fonts in the text area. - */ - public static class DecreaseFontSizeAction - extends RTextAreaEditorKit.DecreaseFontSizeAction { - - private static final long serialVersionUID = 1L; - - public DecreaseFontSizeAction() { - super(); - } - - public DecreaseFontSizeAction(String name, Icon icon, String desc, - Integer mnemonic, KeyStroke accelerator) { - super(name, icon, desc, mnemonic, accelerator); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - - RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; - SyntaxScheme scheme = rsta.getSyntaxScheme(); - - // All we need to do is update all of the fonts in syntax - // schemes, then call setSyntaxHighlightingColorScheme with the - // same scheme already being used. This relies on the fact that - // that method does not check whether the new scheme is different - // from the old scheme before updating. - - boolean changed = false; - int count = scheme.getStyleCount(); - for (int i=0; i=MINIMUM_SIZE) { - // Shrink by decreaseAmount. - ss.font = font.deriveFont(newSize); - changed = true; - } - else if (oldSize>MINIMUM_SIZE) { - // Can't shrink by full decreaseAmount, but - // can shrink a little bit. - ss.font = font.deriveFont(MINIMUM_SIZE); - changed = true; - } - } - } - } - - // Do the text area's font also. - Font font = rsta.getFont(); - float oldSize = font.getSize2D(); - float newSize = oldSize - decreaseAmount; - if (newSize>=MINIMUM_SIZE) { - // Shrink by decreaseAmount. - rsta.setFont(font.deriveFont(newSize)); - changed = true; - } - else if (oldSize>MINIMUM_SIZE) { - // Can't shrink by full decreaseAmount, but - // can shrink a little bit. - rsta.setFont(font.deriveFont(MINIMUM_SIZE)); - changed = true; - } - - // If we updated at least one font, update the screen. If - // all of the fonts were already the minimum size, beep. - if (changed) { - rsta.setSyntaxScheme(scheme); - // NOTE: This is a hack to get an encompassing - // RTextScrollPane to repaint its line numbers to account - // for a change in line height due to a font change. I'm - // not sure why we need to do this here but not when we - // change the syntax highlighting color scheme via the - // Options dialog... setSyntaxHighlightingColorScheme() - // calls revalidate() which won't repaint the scroll pane - // if scrollbars don't change, which is why we need this. - Component parent = rsta.getParent(); - if (parent instanceof javax.swing.JViewport) { - parent = parent.getParent(); - if (parent instanceof JScrollPane) { - parent.repaint(); - } - } - } - else - UIManager.getLookAndFeel().provideErrorFeedback(rsta); - - } - - } - - - /** - * Action for when un-indenting lines (either the current line if there is - * selection, or all selected lines if there is one). - */ - public static class DecreaseIndentAction extends RecordableTextAction { - - private static final long serialVersionUID = 1L; - - private Segment s; - - public DecreaseIndentAction() { - this(rstaDecreaseIndentAction); - } - - public DecreaseIndentAction(String name) { - super(name); - s = new Segment(); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - - if (!textArea.isEditable() || !textArea.isEnabled()) { - UIManager.getLookAndFeel().provideErrorFeedback(textArea); - return; - } - - Document document = textArea.getDocument(); - Element map = document.getDefaultRootElement(); - Caret c = textArea.getCaret(); - int dot = c.getDot(); - int mark = c.getMark(); - int line1 = map.getElementIndex(dot); - int tabSize = textArea.getTabSize(); - - // If there is a selection, indent all lines in the selection. - // Otherwise, indent the line the caret is on. - if (dot!=mark) { - // Note that we cheaply reuse variables here, so don't - // take their names to mean what they are. - int line2 = map.getElementIndex(mark); - dot = Math.min(line1, line2); - mark = Math.max(line1, line2); - Element elem; - try { - for (line1=dot; line1i) { - // If the first character is a tab, remove it. - if (s.array[i]=='\t') { - doc.remove(start, 1); - } - // Otherwise, see if the first character is a space. If it - // is, remove all contiguous whitespaces at the beginning of - // this line, up to the tab size. - else if (s.array[i]==' ') { - i++; - int toRemove = 1; - while (i-1) { - // Go to the position AFTER the bracket so the previous - // bracket (which we were just on) is highlighted. - rsta.setCaretPosition(bracketInfo.y+1); - } - else { - UIManager.getLookAndFeel().provideErrorFeedback(rsta); - } - } - - @Override - public final String getMacroID() { - return rstaGoToMatchingBracketAction; - } - - } - - - /** - * Action for increasing the font size of all fonts in the text area. - */ - public static class IncreaseFontSizeAction - extends RTextAreaEditorKit.IncreaseFontSizeAction { - - private static final long serialVersionUID = 1L; - - public IncreaseFontSizeAction() { - super(); - } - - public IncreaseFontSizeAction(String name, Icon icon, String desc, - Integer mnemonic, KeyStroke accelerator) { - super(name, icon, desc, mnemonic, accelerator); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - - RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; - SyntaxScheme scheme = rsta.getSyntaxScheme(); - - // All we need to do is update all of the fonts in syntax - // schemes, then call setSyntaxHighlightingColorScheme with the - // same scheme already being used. This relies on the fact that - // that method does not check whether the new scheme is different - // from the old scheme before updating. - - boolean changed = false; - int count = scheme.getStyleCount(); - for (int i=0; ipos that - * is NOT a whitespace char, or -1 if only - * whitespace chars follow pos (or it is the end - * position in the string). - */ - private static final int atEndOfLine(int pos, String s, int sLen) { - for (int i=pos; i0) { - StringBuilder sb = new StringBuilder(); - if (line==textArea.getLineCount()-1) { - sb.append('\n'); - } - if (leadingWS!=null) { - sb.append(leadingWS); - } - sb.append("}\n"); - int dot = textArea.getCaretPosition(); - int end = textArea.getLineEndOffsetOfCurrentLine(); - // Insert at end of line, not at dot: they may have - // pressed Enter in the middle of the line and brought - // some text (though it must be whitespace and/or - // comments) down onto the new line. - textArea.insert(sb.toString(), end); - textArea.setCaretPosition(dot); // Caret may have moved - } - - } - - } - - } - - } - - - /** - * Action for inserting tabs. This is extended to "block indent" a - * group of contiguous lines if they are selected. - */ - public static class InsertTabAction extends RecordableTextAction { - - private static final long serialVersionUID = 1L; - - public InsertTabAction() { - super(insertTabAction); - } - - public InsertTabAction(String name) { - super(name); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - - if (!textArea.isEditable() || !textArea.isEnabled()) { - UIManager.getLookAndFeel().provideErrorFeedback(textArea); - return; - } - - Document document = textArea.getDocument(); - Element map = document.getDefaultRootElement(); - Caret c = textArea.getCaret(); - int dot = c.getDot(); - int mark = c.getMark(); - int dotLine = map.getElementIndex(dot); - int markLine = map.getElementIndex(mark); - - // If there is a multi-line selection, indent all lines in - // the selection. - if (dotLine!=markLine) { - int first = Math.min(dotLine, markLine); - int last = Math.max(dotLine, markLine); - Element elem; int start; - - // Since we're using Document.insertString(), we must mimic the - // soft tab behavior provided by RTextArea.replaceSelection(). - String replacement = "\t"; - if (textArea.getTabsEmulated()) { - StringBuilder sb = new StringBuilder(); - int temp = textArea.getTabSize(); - for (int i=0; i0 && - // ((mod&ActionEvent.ALT_MASK)==(mod&ActionEvent.CTRL_MASK))) { - // char ch = str.charAt(0); - // if (ch>=0x20 && ch!=0x7F) - // textArea.replaceSelection(str); - //} - textArea.replaceSelection(" "); - } - - @Override - public final String getMacroID() { - return rstaPossiblyInsertTemplateAction; - } - - } - - - /** - * Action to move the selection and/or caret. Constructor indicates - * direction to use. This class overrides the behavior defined in - * {@link RTextAreaEditorKit} to better skip "words" in source code. - */ - public static class PreviousWordAction - extends RTextAreaEditorKit.PreviousWordAction { - - private Segment seg; - - public PreviousWordAction(String nm, boolean select) { - super(nm, select); - seg = new Segment(); - } - - /** - * Overridden to do better with skipping "words" in code. - */ - @Override - protected int getPreviousWord(RTextArea textArea, int offs) - throws BadLocationException { - - if (offs==0) { - return offs; - } - - RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); - Element root = doc.getDefaultRootElement(); - int line = root.getElementIndex(offs); - int start = root.getElement(line).getStartOffset(); - if (offs==start) {// If we're already at the start of the line... - RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; - if (rsta.isCodeFoldingEnabled()) { // End of next visible line - FoldManager fm = rsta.getFoldManager(); - while (--line>=0 && fm.isLineHidden(line)); - if (line>=0) { // Found an earlier visible line - offs = root.getElement(line).getEndOffset() - 1; - } - // No earlier visible line - we must be at offs==0... - return offs; - } - else { - return start-1; // End of previous line. - } - } - doc.getText(start, offs-start, seg); - - // Determine the "type" of char at offs - lower case, upper case, - // whitespace or other - char ch = seg.last(); - - // Skip any "leading" whitespace - while (Character.isWhitespace(ch)) { - ch = seg.previous(); - } - - // Skip the group of letters and/or digits - if (Character.isLetterOrDigit(ch)) { - do { - ch = seg.previous(); - } while (Character.isLetterOrDigit(ch)); - } - - // Skip groups of "anything else" (operators, etc.). - else if (!Character.isWhitespace(ch)) { - do { - ch = seg.previous(); - } while (ch!=Segment.DONE && - !(Character.isLetterOrDigit(ch) || - Character.isWhitespace(ch))); - } - - offs -= seg.getEndIndex() - seg.getIndex(); - if (ch!=Segment.DONE) { - offs++; - } - - return offs; - - } - - } - - - /** - * Selects the word around the caret. This class is here to better - * handle selecting "words" in programming languages. - */ - public static class SelectWordAction - extends RTextAreaEditorKit.SelectWordAction { - - @Override - protected void createActions() { - start = new BeginWordAction("pigdog", false); - end = new EndWordAction("pigdog", true); - } - - } - - - /** - * Action that toggles whether the currently selected lines are - * commented. - */ - public static class ToggleCommentAction extends RecordableTextAction { - - public ToggleCommentAction() { - super(rstaToggleCommentAction); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - - if (!textArea.isEditable() || !textArea.isEnabled()) { - UIManager.getLookAndFeel().provideErrorFeedback(textArea); - return; - } - - RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); - String[] startEnd = doc.getLineCommentStartAndEnd(); - - if (startEnd==null) { - UIManager.getLookAndFeel().provideErrorFeedback(textArea); - return; - } - - Element map = doc.getDefaultRootElement(); - Caret c = textArea.getCaret(); - int dot = c.getDot(); - int mark = c.getMark(); - int line1 = map.getElementIndex(dot); - int line2 = map.getElementIndex(mark); - int start = Math.min(line1, line2); - int end = Math.max(line1, line2); - - // Don't toggle comment on last line if there is no - // text selected on it. - if (start!=end) { - Element elem = map.getElement(end); - if (Math.max(dot, mark)==elem.getStartOffset()) { - end--; - } - } - - textArea.beginAtomicEdit(); - try { - boolean add = getDoAdd(doc,map, start,end, startEnd); - for (line1=start; line1<=end; line1++) { - Element elem = map.getElement(line1); - handleToggleComment(elem, doc, startEnd, add); - } - } catch (BadLocationException ble) { - ble.printStackTrace(); - UIManager.getLookAndFeel().provideErrorFeedback(textArea); - } finally { - textArea.endAtomicEdit(); - } - - } - - private boolean getDoAdd(Document doc, Element map, int startLine, - int endLine, String[] startEnd) - throws BadLocationException { - boolean doAdd = false; - for (int i=startLine; i<=endLine; i++) { - Element elem = map.getElement(i); - int start = elem.getStartOffset(); - String t = doc.getText(start, elem.getEndOffset()-start-1); - if (!t.startsWith(startEnd[0]) || - (startEnd[1]!=null && !t.endsWith(startEnd[1]))) { - doAdd = true; - break; - } - } - return doAdd; - } - - private void handleToggleComment(Element elem, Document doc, - String[] startEnd, boolean add) throws BadLocationException { - int start = elem.getStartOffset(); - int end = elem.getEndOffset() - 1; - if (add) { - doc.insertString(start, startEnd[0], null); - if (startEnd[1]!=null) { - doc.insertString(end+startEnd[0].length(), startEnd[1], - null); - } - } - else { - doc.remove(start, startEnd[0].length()); - if (startEnd[1]!=null) { - int temp = startEnd[1].length(); - doc.remove(end-startEnd[0].length()-temp, temp); - } - } - } - - @Override - public final String getMacroID() { - return rstaToggleCommentAction; - } - - } - - - /** - * Toggles the fold at the current caret position or line. - */ - public static class ToggleCurrentFoldAction extends FoldRelatedAction { - - private static final long serialVersionUID = 1L; - - public ToggleCurrentFoldAction() { - super(rstaToggleCurrentFoldAction); - setProperties("Action.ToggleCurrentFold"); - } - - public ToggleCurrentFoldAction(String name, Icon icon, String desc, - Integer mnemonic, KeyStroke accelerator) { - super(name, icon, desc, mnemonic, accelerator); - } - - @Override - public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { - RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; - if (rsta.isCodeFoldingEnabled()) { - Fold fold = getClosestFold(rsta); - if (fold!=null) { - fold.toggleCollapsedState(); - } - possiblyRepaintGutter(textArea); - } - else { - UIManager.getLookAndFeel().provideErrorFeedback(rsta); - } - } - - @Override - public final String getMacroID() { - return rstaToggleCurrentFoldAction; - } - - } + private static final long serialVersionUID = 1L; + + public static final String rstaCloseCurlyBraceAction = "RSTA.CloseCurlyBraceAction"; + public static final String rstaCloseMarkupTagAction = "RSTA.CloseMarkupTagAction"; + public static final String rstaCollapseAllFoldsAction = "RSTA.CollapseAllFoldsAction"; + public static final String rstaCollapseAllCommentFoldsAction = "RSTA.CollapseAllCommentFoldsAction"; + public static final String rstaCollapseFoldAction = "RSTA.CollapseFoldAction"; + public static final String rstaCopyAsRtfAction = "RSTA.CopyAsRtfAction"; + public static final String rstaDecreaseIndentAction = "RSTA.DecreaseIndentAction"; + public static final String rstaExpandAllFoldsAction = "RSTA.ExpandAllFoldsAction"; + public static final String rstaExpandFoldAction = "RSTA.ExpandFoldAction"; + public static final String rstaGoToMatchingBracketAction = "RSTA.GoToMatchingBracketAction"; + public static final String rstaPossiblyInsertTemplateAction = "RSTA.TemplateAction"; + public static final String rstaToggleCommentAction = "RSTA.ToggleCommentAction"; + public static final String rstaToggleCurrentFoldAction = "RSTA.ToggleCurrentFoldAction"; + + /** + * The actions that RSyntaxTextAreaEditorKit adds to those of + * RTextAreaEditorKit. + */ + private static final Action[] defaultActions = { + new CloseCurlyBraceAction(), + new CloseMarkupTagAction(), + new BeginWordAction(beginWordAction, false), + new BeginWordAction(selectionBeginWordAction, true), + new ChangeFoldStateAction(rstaCollapseFoldAction, true), + new ChangeFoldStateAction(rstaExpandFoldAction, false), + new CollapseAllFoldsAction(), + new CopyAsRtfAction(), + //new DecreaseFontSizeAction(), + new DecreaseIndentAction(), + new DeletePrevWordAction(), + new EndAction(endAction, false), + new EndAction(selectionEndAction, true), + new EndWordAction(endWordAction, false), + new EndWordAction(endWordAction, true), + new ExpandAllFoldsAction(), + new GoToMatchingBracketAction(), + new InsertBreakAction(), + //new IncreaseFontSizeAction(), + new InsertTabAction(), + new NextWordAction(nextWordAction, false), + new NextWordAction(selectionNextWordAction, true), + new PossiblyInsertTemplateAction(), + new PreviousWordAction(previousWordAction, false), + new PreviousWordAction(selectionPreviousWordAction, true), + new SelectWordAction(), + new ToggleCommentAction(), + }; + + + /** + * Constructor. + */ + public RSyntaxTextAreaEditorKit() { + } + + + /** + * Returns the default document used by RSyntaxTextAreas. + * + * @return The document. + */ + @Override + public Document createDefaultDocument() { + return new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_NONE); + } + + + /** + * Overridden to return a row header that is aware of folding. + * + * @param textArea The text area. + * @return The icon row header. + */ + @Override + public IconRowHeader createIconRowHeader(RTextArea textArea) { + return new FoldingAwareIconRowHeader((RSyntaxTextArea) textArea); + } + + + /** + * Fetches the set of commands that can be used + * on a text component that is using a model and + * view produced by this kit. + * + * @return the command list + */ + @Override + public Action[] getActions() { + return TextAction.augmentList(super.getActions(), + RSyntaxTextAreaEditorKit.defaultActions); + } + + + /** + * Returns localized text for an action. There's definitely a better place + * for this functionality. + * + * @param key The key into the action resource bundle. + * @return The localized text. + */ + public static String getString(String key) { + return com.fr.design.i18n.Toolkit.i18nText(key); + } + + + /** + * Positions the caret at the beginning of the word. This class is here + * to better handle finding the "beginning of the word" for programming + * languages. + */ + protected static class BeginWordAction + extends RTextAreaEditorKit.BeginWordAction { + + private Segment seg; + + protected BeginWordAction(String name, boolean select) { + super(name, select); + seg = new Segment(); + } + + @Override + protected int getWordStart(RTextArea textArea, int offs) + throws BadLocationException { + + if (offs == 0) { + return offs; + } + + RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument(); + int line = textArea.getLineOfOffset(offs); + int start = textArea.getLineStartOffset(line); + if (offs == start) { + return start; + } + int end = textArea.getLineEndOffset(line); + if (line != textArea.getLineCount() - 1) { + end--; + } + doc.getText(start, end - start, seg); + + // Determine the "type" of char at offs - lower case, upper case, + // whitespace or other. We take special care here as we're starting + // in the middle of the Segment to check whether we're already at + // the "beginning" of a word. + int firstIndex = seg.getBeginIndex() + (offs - start) - 1; + seg.setIndex(firstIndex); + char ch = seg.current(); + char nextCh = offs == end ? 0 : seg.array[seg.getIndex() + 1]; + + // The "word" is a group of letters and/or digits + if (Character.isLetterOrDigit(ch)) { + if (offs != end && !Character.isLetterOrDigit(nextCh)) { + return offs; + } + do { + ch = seg.previous(); + } while (Character.isLetterOrDigit(ch)); + } + + // The "word" is whitespace + else if (Character.isWhitespace(ch)) { + if (offs != end && !Character.isWhitespace(nextCh)) { + return offs; + } + do { + ch = seg.previous(); + } while (Character.isWhitespace(ch)); + } + + // Otherwise, the "word" a single "something else" char (operator, + // etc.). + + offs -= firstIndex - seg.getIndex() + 1;//seg.getEndIndex() - seg.getIndex(); + if (ch != Segment.DONE && nextCh != '\n') { + offs++; + } + + return offs; + + } + + } + + + /** + * Expands or collapses the nearest fold. + */ + public static class ChangeFoldStateAction extends FoldRelatedAction { + + private boolean collapse; + + public ChangeFoldStateAction(String name, boolean collapse) { + super(name); + this.collapse = collapse; + } + + public ChangeFoldStateAction(String name, Icon icon, + String desc, Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + if (rsta.isCodeFoldingEnabled()) { + Fold fold = getClosestFold(rsta); + if (fold != null) { + fold.setCollapsed(collapse); + } + possiblyRepaintGutter(textArea); + } else { + UIManager.getLookAndFeel().provideErrorFeedback(rsta); + } + } + + @Override + public final String getMacroID() { + return getName(); + } + + } + + + /** + * Action that (optionally) aligns a closing curly brace with the line + * containing its matching opening curly brace. + */ + public static class CloseCurlyBraceAction extends RecordableTextAction { + + private static final long serialVersionUID = 1L; + + private Point bracketInfo; + private Segment seg; + + public CloseCurlyBraceAction() { + super(rstaCloseCurlyBraceAction); + seg = new Segment(); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + RSyntaxDocument doc = (RSyntaxDocument) rsta.getDocument(); + boolean alignCurlyBraces = rsta.isAutoIndentEnabled() && + doc.getCurlyBracesDenoteCodeBlocks(); + + if (alignCurlyBraces) { + textArea.beginAtomicEdit(); + } + + try { + + textArea.replaceSelection("}"); + + // If the user wants to align curly braces... + if (alignCurlyBraces) { + + Element root = doc.getDefaultRootElement(); + int dot = rsta.getCaretPosition() - 1; // Start before '{' + int line = root.getElementIndex(dot); + Element elem = root.getElement(line); + int start = elem.getStartOffset(); + + // Get the current line's text up to the '}' entered. + try { + doc.getText(start, dot - start, seg); + } catch (BadLocationException ble) { // Never happens + ble.printStackTrace(); + return; + } + + // Only attempt to align if there's only whitespace up to + // the '}' entered. + for (int i = 0; i < seg.count; i++) { + char ch = seg.array[seg.offset + i]; + if (!Character.isWhitespace(ch)) { + return; + } + } + + // Locate the matching '{' bracket, and replace the leading + // whitespace for the '}' to match that of the '{' char's line. + bracketInfo = RSyntaxUtilities.getMatchingBracketPosition( + rsta, bracketInfo); + if (bracketInfo.y > -1) { + try { + String ws = RSyntaxUtilities.getLeadingWhitespace( + doc, bracketInfo.y); + rsta.replaceRange(ws, start, dot); + } catch (BadLocationException ble) { + ble.printStackTrace(); + return; + } + } + + } + + } finally { + if (alignCurlyBraces) { + textArea.endAtomicEdit(); + } + } + + } + + @Override + public final String getMacroID() { + return rstaCloseCurlyBraceAction; + } + + } + + + /** + * (Optionally) completes a closing markup tag. + */ + public static class CloseMarkupTagAction extends RecordableTextAction { + + private static final long serialVersionUID = 1L; + + public CloseMarkupTagAction() { + super(rstaCloseMarkupTagAction); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + + if (!textArea.isEditable() || !textArea.isEnabled()) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + return; + } + + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + RSyntaxDocument doc = (RSyntaxDocument) rsta.getDocument(); + + Caret c = rsta.getCaret(); + boolean selection = c.getDot() != c.getMark(); + rsta.replaceSelection("/"); + + // Don't automatically complete a tag if there was a selection + int dot = c.getDot(); + + if (doc.getLanguageIsMarkup() && + doc.getCompleteMarkupCloseTags() && + !selection && rsta.getCloseMarkupTags() && dot > 1) { + + try { + + // Check actual char before token type, since it's quicker + char ch = doc.charAt(dot - 2); + if (ch == '<' || ch == '[') { + + Token t = doc.getTokenListForLine( + rsta.getCaretLineNumber()); + t = RSyntaxUtilities.getTokenAtOffset(t, dot - 1); + if (t != null && t.getType() == Token.MARKUP_TAG_DELIMITER) { + //System.out.println("Huzzah - closing tag!"); + String tagName = discoverTagName(doc, dot); + if (tagName != null) { + rsta.replaceSelection(tagName + (char) (ch + 2)); + } + } + + } + + } catch (BadLocationException ble) { // Never happens + UIManager.getLookAndFeel().provideErrorFeedback(rsta); + ble.printStackTrace(); + } + + } + + } + + /** + * Discovers the name of the tag being closed. Assumes standard + * SGML-style markup tags. + * + * @param doc The document to parse. + * @param dot The location of the caret. This should be right after + * the start of a closing tag token (e.g. "</" + * or "[" in the case of BBCode). + * @return The name of the tag to close, or null if it + * could not be determined. + */ + private String discoverTagName(RSyntaxDocument doc, int dot) { + + Stack stack = new Stack(); + + Element root = doc.getDefaultRootElement(); + int curLine = root.getElementIndex(dot); + + for (int i = 0; i <= curLine; i++) { + + Token t = doc.getTokenListForLine(i); + while (t != null && t.isPaintable()) { + + if (t.getType() == Token.MARKUP_TAG_DELIMITER) { + if (t.isSingleChar('<') || t.isSingleChar('[')) { + t = t.getNextToken(); + while (t != null && t.isPaintable()) { + if (t.getType() == Token.MARKUP_TAG_NAME || + // Being lenient here and also checking + // for attributes, in case they + // (incorrectly) have whitespace between + // the '<' char and the element name. + t.getType() == Token.MARKUP_TAG_ATTRIBUTE) { + stack.push(t.getLexeme()); + break; + } + t = t.getNextToken(); + } + } else if (t.length() == 2 && t.charAt(0) == '/' && + (t.charAt(1) == '>' || + t.charAt(1) == ']')) { + if (!stack.isEmpty()) { // Always true for valid XML + stack.pop(); + } + } else if (t.length() == 2 && + (t.charAt(0) == '<' || t.charAt(0) == '[') && + t.charAt(1) == '/') { + String tagName = null; + if (!stack.isEmpty()) { // Always true for valid XML + tagName = stack.pop(); + } + if (t.getEndOffset() >= dot) { + return tagName; + } + } + } + + t = Objects.requireNonNull(t).getNextToken(); + + } + + } + + return null; // Should never happen + + } + + @Override + public String getMacroID() { + return getName(); + } + + } + + + /** + * Collapses all comment folds. + */ + public static class CollapseAllCommentFoldsAction extends FoldRelatedAction { + + private static final long serialVersionUID = 1L; + + public CollapseAllCommentFoldsAction() { + super(rstaCollapseAllCommentFoldsAction); + setProperties("Action.CollapseCommentFolds"); + } + + public CollapseAllCommentFoldsAction(String name, Icon icon, + String desc, Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + if (rsta.isCodeFoldingEnabled()) { + FoldCollapser collapser = new FoldCollapser(); + collapser.collapseFolds(rsta.getFoldManager()); + possiblyRepaintGutter(textArea); + } else { + UIManager.getLookAndFeel().provideErrorFeedback(rsta); + } + } + + @Override + public final String getMacroID() { + return rstaCollapseAllCommentFoldsAction; + } + + } + + + /** + * Collapses all folds. + */ + public static class CollapseAllFoldsAction extends FoldRelatedAction { + + private static final long serialVersionUID = 1L; + + public CollapseAllFoldsAction() { + this(false); + } + + public CollapseAllFoldsAction(boolean localizedName) { + super(rstaCollapseAllFoldsAction); + if (localizedName) { + setProperties("Action.CollapseAllFolds"); + } + } + + public CollapseAllFoldsAction(String name, Icon icon, + String desc, Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + if (rsta.isCodeFoldingEnabled()) { + FoldCollapser collapser = new FoldCollapser() { + @Override + public boolean getShouldCollapse(Fold fold) { + return true; + } + }; + collapser.collapseFolds(rsta.getFoldManager()); + possiblyRepaintGutter(textArea); + } else { + UIManager.getLookAndFeel().provideErrorFeedback(rsta); + } + } + + @Override + public final String getMacroID() { + return rstaCollapseAllFoldsAction; + } + + } + + + /** + * Action for copying text as RTF. + */ + public static class CopyAsRtfAction extends RecordableTextAction { + + private static final long serialVersionUID = 1L; + + public CopyAsRtfAction() { + super(rstaCopyAsRtfAction); + } + + public CopyAsRtfAction(String name, Icon icon, String desc, + Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + ((RSyntaxTextArea) textArea).copyAsRtf(); + textArea.requestFocusInWindow(); + } + + @Override + public final String getMacroID() { + return getName(); + } + + } + + + /** + * Action for decreasing the font size of all fonts in the text area. + */ + public static class DecreaseFontSizeAction + extends RTextAreaEditorKit.DecreaseFontSizeAction { + + private static final long serialVersionUID = 1L; + + public DecreaseFontSizeAction() { + super(); + } + + public DecreaseFontSizeAction(String name, Icon icon, String desc, + Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + SyntaxScheme scheme = rsta.getSyntaxScheme(); + + // All we need to do is update all of the fonts in syntax + // schemes, then call setSyntaxHighlightingColorScheme with the + // same scheme already being used. This relies on the fact that + // that method does not check whether the new scheme is different + // from the old scheme before updating. + + boolean changed = false; + int count = scheme.getStyleCount(); + for (int i = 0; i < count; i++) { + Style ss = scheme.getStyle(i); + if (ss != null) { + Font font = ss.font; + if (font != null) { + float oldSize = font.getSize2D(); + float newSize = oldSize - decreaseAmount; + if (newSize >= MINIMUM_SIZE) { + // Shrink by decreaseAmount. + ss.font = font.deriveFont(newSize); + changed = true; + } else if (oldSize > MINIMUM_SIZE) { + // Can't shrink by full decreaseAmount, but + // can shrink a little bit. + ss.font = font.deriveFont(MINIMUM_SIZE); + changed = true; + } + } + } + } + + // Do the text area's font also. + Font font = rsta.getFont(); + float oldSize = font.getSize2D(); + float newSize = oldSize - decreaseAmount; + if (newSize >= MINIMUM_SIZE) { + // Shrink by decreaseAmount. + rsta.setFont(font.deriveFont(newSize)); + changed = true; + } else if (oldSize > MINIMUM_SIZE) { + // Can't shrink by full decreaseAmount, but + // can shrink a little bit. + rsta.setFont(font.deriveFont(MINIMUM_SIZE)); + changed = true; + } + + // If we updated at least one font, update the screen. If + // all of the fonts were already the minimum size, beep. + if (changed) { + rsta.setSyntaxScheme(scheme); + // NOTE: This is a hack to get an encompassing + // RTextScrollPane to repaint its line numbers to account + // for a change in line height due to a font change. I'm + // not sure why we need to do this here but not when we + // change the syntax highlighting color scheme via the + // Options dialog... setSyntaxHighlightingColorScheme() + // calls revalidate() which won't repaint the scroll pane + // if scrollbars don't change, which is why we need this. + Component parent = rsta.getParent(); + if (parent instanceof javax.swing.JViewport) { + parent = parent.getParent(); + if (parent instanceof JScrollPane) { + parent.repaint(); + } + } + } else { + UIManager.getLookAndFeel().provideErrorFeedback(rsta); + } + + } + + } + + + /** + * Action for when un-indenting lines (either the current line if there is + * selection, or all selected lines if there is one). + */ + public static class DecreaseIndentAction extends RecordableTextAction { + + private static final long serialVersionUID = 1L; + + private Segment s; + + public DecreaseIndentAction() { + this(rstaDecreaseIndentAction); + } + + public DecreaseIndentAction(String name) { + super(name); + s = new Segment(); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + + if (!textArea.isEditable() || !textArea.isEnabled()) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + return; + } + + Document document = textArea.getDocument(); + Element map = document.getDefaultRootElement(); + Caret c = textArea.getCaret(); + int dot = c.getDot(); + int mark = c.getMark(); + int line1 = map.getElementIndex(dot); + int tabSize = textArea.getTabSize(); + + // If there is a selection, indent all lines in the selection. + // Otherwise, indent the line the caret is on. + if (dot != mark) { + // Note that we cheaply reuse variables here, so don't + // take their names to mean what they are. + int line2 = map.getElementIndex(mark); + dot = Math.min(line1, line2); + mark = Math.max(line1, line2); + Element elem; + try { + for (line1 = dot; line1 < mark; line1++) { + elem = map.getElement(line1); + handleDecreaseIndent(elem, document, tabSize); + } + // Don't do the last line if the caret is at its + // beginning. We must call getDot() again and not just + // use 'dot' as the caret's position may have changed + // due to the insertion of the tabs above. + elem = map.getElement(mark); + int start = elem.getStartOffset(); + if (Math.max(c.getDot(), c.getMark()) != start) { + handleDecreaseIndent(elem, document, tabSize); + } + } catch (BadLocationException ble) { + ble.printStackTrace(); + UIManager.getLookAndFeel(). + provideErrorFeedback(textArea); + } + } else { + Element elem = map.getElement(line1); + try { + handleDecreaseIndent(elem, document, tabSize); + } catch (BadLocationException ble) { + ble.printStackTrace(); + UIManager.getLookAndFeel(). + provideErrorFeedback(textArea); + } + } + + } + + @Override + public final String getMacroID() { + return rstaDecreaseIndentAction; + } + + /** + * Actually does the "de-indentation." This method finds where the + * given element's leading whitespace ends, then, if there is indeed + * leading whitespace, removes either the last char in it (if it is a + * tab), or removes up to the number of spaces equal to a tab in the + * specified document (i.e., if the tab size was 5 and there were 3 + * spaces at the end of the leading whitespace, the three will be + * removed; if there were 8 spaces, only the first 5 would be + * removed). + * + * @param elem The element to "de-indent." + * @param doc The document containing the specified element. + * @param tabSize The size of a tab, in spaces. + */ + private final void handleDecreaseIndent(Element elem, Document doc, + int tabSize) + throws BadLocationException { + int start = elem.getStartOffset(); + int end = elem.getEndOffset() - 1; // Why always true?? + doc.getText(start, end - start, s); + int i = s.offset; + end = i + s.count; + if (end > i) { + // If the first character is a tab, remove it. + if (s.array[i] == '\t') { + doc.remove(start, 1); + } + // Otherwise, see if the first character is a space. If it + // is, remove all contiguous whitespaces at the beginning of + // this line, up to the tab size. + else if (s.array[i] == ' ') { + i++; + int toRemove = 1; + while (i < end && s.array[i] == ' ' && toRemove < tabSize) { + i++; + toRemove++; + } + doc.remove(start, toRemove); + } + } + } + + } + + + /** + * Deletes the previous word, but differentiates symbols from "words" to + * match the behavior of code editors. + */ + public static class DeletePrevWordAction + extends RTextAreaEditorKit.DeletePrevWordAction { + + private Segment seg = new Segment(); + + @Override + protected int getPreviousWordStart(RTextArea textArea, int offs) + throws BadLocationException { + + if (offs == 0) { + return offs; + } + + RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument(); + int line = textArea.getLineOfOffset(offs); + int start = textArea.getLineStartOffset(line); + if (offs == start) { + return start - 1; // Just delete the newline + } + int end = textArea.getLineEndOffset(line); + if (line != textArea.getLineCount() - 1) { + end--; + } + doc.getText(start, end - start, seg); + + // Determine the "type" of char at offs - lower case, upper case, + // whitespace or other. We take special care here as we're starting + // in the middle of the Segment to check whether we're already at + // the "beginning" of a word. + int firstIndex = seg.getBeginIndex() + (offs - start) - 1; + seg.setIndex(firstIndex); + char ch = seg.current(); + + // Always strip off whitespace first + if (Character.isWhitespace(ch)) { + do { + ch = seg.previous(); + } while (Character.isWhitespace(ch)); + } + + // The "word" is a group of letters and/or digits + if (Character.isLetterOrDigit(ch)) { + do { + ch = seg.previous(); + } while (Character.isLetterOrDigit(ch)); + } + + // The "word" is a series of symbols. + else { + while (!Character.isWhitespace(ch) && + !Character.isLetterOrDigit(ch) + && ch != Segment.DONE) { + ch = seg.previous(); + } + } + + if (ch == Segment.DONE) { + return start; // Removed last "token" of the line + } + offs -= firstIndex - seg.getIndex(); + return offs; + + } + + } + + + /** + * Moves the caret to the end of the document, taking into account code + * folding. + */ + public static class EndAction extends RTextAreaEditorKit.EndAction { + + public EndAction(String name, boolean select) { + super(name, select); + } + + @Override + protected int getVisibleEnd(RTextArea textArea) { + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + return rsta.getLastVisibleOffset(); + } + + } + + + /** + * Positions the caret at the end of the word. This class is here to + * better handle finding the "end of the word" in programming languages. + */ + protected static class EndWordAction + extends RTextAreaEditorKit.EndWordAction { + + private Segment seg; + + protected EndWordAction(String name, boolean select) { + super(name, select); + seg = new Segment(); + } + + @Override + protected int getWordEnd(RTextArea textArea, int offs) + throws BadLocationException { + + RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument(); + if (offs == doc.getLength()) { + return offs; + } + + int line = textArea.getLineOfOffset(offs); + int end = textArea.getLineEndOffset(line); + if (line != textArea.getLineCount() - 1) { + end--; // Hide newline + } + if (offs == end) { + return end; + } + doc.getText(offs, end - offs, seg); + + // Determine the "type" of char at offs - letter/digit, + // whitespace or other + char ch = seg.first(); + + // The "word" is a group of letters and/or digits + if (Character.isLetterOrDigit(ch)) { + do { + ch = seg.next(); + } while (Character.isLetterOrDigit(ch)); + } + + // The "word" is whitespace. + else if (Character.isWhitespace(ch)) { + + do { + ch = seg.next(); + } while (Character.isWhitespace(ch)); + } + + // Otherwise, the "word" is a single character of some other type + // (operator, etc.). + + offs += seg.getIndex() - seg.getBeginIndex(); + return offs; + + } + + } + + + /** + * Expands all folds. + */ + public static class ExpandAllFoldsAction extends FoldRelatedAction { + + private static final long serialVersionUID = 1L; + + public ExpandAllFoldsAction() { + this(false); + } + + public ExpandAllFoldsAction(boolean localizedName) { + super(rstaExpandAllFoldsAction); + if (localizedName) { + setProperties("Action.ExpandAllFolds"); + } + } + + public ExpandAllFoldsAction(String name, Icon icon, + String desc, Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + if (rsta.isCodeFoldingEnabled()) { + FoldManager fm = rsta.getFoldManager(); + for (int i = 0; i < fm.getFoldCount(); i++) { + expand(fm.getFold(i)); + } + possiblyRepaintGutter(rsta); + } else { + UIManager.getLookAndFeel().provideErrorFeedback(rsta); + } + } + + private void expand(Fold fold) { + fold.setCollapsed(false); + for (int i = 0; i < fold.getChildCount(); i++) { + expand(fold.getChild(i)); + } + } + + @Override + public final String getMacroID() { + return rstaExpandAllFoldsAction; + } + + } + + + /** + * Base class for folding-related actions. + */ + static abstract class FoldRelatedAction extends RecordableTextAction { + + public FoldRelatedAction(String name) { + super(name); + } + + public FoldRelatedAction(String name, Icon icon, + String desc, Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + protected Fold getClosestFold(RSyntaxTextArea textArea) { + int offs = textArea.getCaretPosition(); + int line = textArea.getCaretLineNumber(); + FoldManager fm = textArea.getFoldManager(); + Fold fold = fm.getFoldForLine(line); + if (fold == null) { + fold = fm.getDeepestOpenFoldContaining(offs); + } + return fold; + } + + /** + * Repaints the gutter in a text area's scroll pane, if necessary. + * + * @param textArea The text area. + */ + protected void possiblyRepaintGutter(RTextArea textArea) { + Gutter gutter = RSyntaxUtilities.getGutter(textArea); + if (gutter != null) { + gutter.repaint(); + } + } + + } + + + /** + * Action for moving the caret to the "matching bracket" of the bracket + * at the caret position (either before or after). + */ + public static class GoToMatchingBracketAction + extends RecordableTextAction { + + private static final long serialVersionUID = 1L; + + private Point bracketInfo; + + public GoToMatchingBracketAction() { + super(rstaGoToMatchingBracketAction); + } + + public GoToMatchingBracketAction(String name, Icon icon, String desc, + Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + bracketInfo = RSyntaxUtilities.getMatchingBracketPosition(rsta, + bracketInfo); + if (bracketInfo.y > -1) { + // Go to the position AFTER the bracket so the previous + // bracket (which we were just on) is highlighted. + rsta.setCaretPosition(bracketInfo.y + 1); + } else { + UIManager.getLookAndFeel().provideErrorFeedback(rsta); + } + } + + @Override + public final String getMacroID() { + return rstaGoToMatchingBracketAction; + } + + } + + + /** + * Action for increasing the font size of all fonts in the text area. + */ + public static class IncreaseFontSizeAction + extends RTextAreaEditorKit.IncreaseFontSizeAction { + + private static final long serialVersionUID = 1L; + + public IncreaseFontSizeAction() { + super(); + } + + public IncreaseFontSizeAction(String name, Icon icon, String desc, + Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + SyntaxScheme scheme = rsta.getSyntaxScheme(); + + // All we need to do is update all of the fonts in syntax + // schemes, then call setSyntaxHighlightingColorScheme with the + // same scheme already being used. This relies on the fact that + // that method does not check whether the new scheme is different + // from the old scheme before updating. + + boolean changed = false; + int count = scheme.getStyleCount(); + for (int i = 0; i < count; i++) { + Style ss = scheme.getStyle(i); + if (ss != null) { + Font font = ss.font; + if (font != null) { + float oldSize = font.getSize2D(); + float newSize = oldSize + increaseAmount; + if (newSize <= MAXIMUM_SIZE) { + // Grow by increaseAmount. + ss.font = font.deriveFont(newSize); + changed = true; + } else if (oldSize < MAXIMUM_SIZE) { + // Can't grow by full increaseAmount, but + // can grow a little bit. + ss.font = font.deriveFont(MAXIMUM_SIZE); + changed = true; + } + } + } + } + + // Do the text area's font also. + Font font = rsta.getFont(); + float oldSize = font.getSize2D(); + float newSize = oldSize + increaseAmount; + if (newSize <= MAXIMUM_SIZE) { + // Grow by increaseAmount. + rsta.setFont(font.deriveFont(newSize)); + changed = true; + } else if (oldSize < MAXIMUM_SIZE) { + // Can't grow by full increaseAmount, but + // can grow a little bit. + rsta.setFont(font.deriveFont(MAXIMUM_SIZE)); + changed = true; + } + + // If we updated at least one font, update the screen. If + // all of the fonts were already the minimum size, beep. + if (changed) { + rsta.setSyntaxScheme(scheme); + // NOTE: This is a hack to get an encompassing + // RTextScrollPane to repaint its line numbers to account + // for a change in line height due to a font change. I'm + // not sure why we need to do this here but not when we + // change the syntax highlighting color scheme via the + // Options dialog... setSyntaxHighlightingColorScheme() + // calls revalidate() which won't repaint the scroll pane + // if scrollbars don't change, which is why we need this. + Component parent = rsta.getParent(); + if (parent instanceof javax.swing.JViewport) { + parent = parent.getParent(); + if (parent instanceof JScrollPane) { + parent.repaint(); + } + } + } else { + UIManager.getLookAndFeel().provideErrorFeedback(rsta); + } + + } + + } + + + /** + * Action for when the user presses the Enter key. This is here so we can + * be smart and "auto-indent" for programming languages. + */ + public static class InsertBreakAction + extends RTextAreaEditorKit.InsertBreakAction { + + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + + if (!textArea.isEditable() || !textArea.isEnabled()) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + return; + } + + RSyntaxTextArea sta = (RSyntaxTextArea) textArea; + boolean noSelection = sta.getSelectionStart() == sta.getSelectionEnd(); + + // First, see if this language wants to handle inserting newlines + // itself. + boolean handled = false; + if (noSelection) { + RSyntaxDocument doc = (RSyntaxDocument) sta.getDocument(); + handled = doc.insertBreakSpecialHandling(e); + } + + // If not... + if (!handled) { + handleInsertBreak(sta, noSelection); + } + + } + + /** + * @return The first location in the string past pos that + * is NOT a whitespace char, or -1 if only + * whitespace chars follow pos (or it is the end + * position in the string). + */ + private static final int atEndOfLine(int pos, String s, int sLen) { + for (int i = pos; i < sLen; i++) { + if (!RSyntaxUtilities.isWhitespace(s.charAt(i))) { + return i; + } + } + return -1; + } + + private static final int getOpenBraceCount(RSyntaxDocument doc) { + int openCount = 0; + Element root = doc.getDefaultRootElement(); + int lineCount = root.getElementCount(); + for (int i = 0; i < lineCount; i++) { + Token t = doc.getTokenListForLine(i); + while (t != null && t.isPaintable()) { + if (t.getType() == Token.SEPARATOR && t.length() == 1) { + char ch = t.charAt(0); + if (ch == '{') { + openCount++; + } else if (ch == '}') { + openCount--; + } + } + t = t.getNextToken(); + } + } + return openCount; + } + + /** + * Actually inserts the newline into the document, and auto-indents + * if appropriate. This method can be called by token makers who + * implement a custom action for inserting newlines. + * + * @param textArea + * @param noSelection Whether there is no selection. + */ + protected void handleInsertBreak(RSyntaxTextArea textArea, + boolean noSelection) { + // If we're auto-indenting... + if (noSelection && textArea.isAutoIndentEnabled()) { + insertNewlineWithAutoIndent(textArea); + } else { + textArea.replaceSelection("\n"); + if (noSelection) { + possiblyCloseCurlyBrace(textArea, null); + } + } + } + + private void insertNewlineWithAutoIndent(RSyntaxTextArea sta) { + + try { + + int caretPos = sta.getCaretPosition(); + Document doc = sta.getDocument(); + Element map = doc.getDefaultRootElement(); + int lineNum = map.getElementIndex(caretPos); + Element line = map.getElement(lineNum); + int start = line.getStartOffset(); + int end = line.getEndOffset() - 1; // Why always "-1"? + int len = end - start; + String s = doc.getText(start, len); + + // endWS is the end of the leading whitespace of the + // current line. + String leadingWS = RSyntaxUtilities.getLeadingWhitespace(s); + StringBuilder sb = new StringBuilder("\n"); + sb.append(leadingWS); + + // If there is only whitespace between the caret and + // the EOL, pressing Enter auto-indents the new line to + // the same place as the previous line. + int nonWhitespacePos = atEndOfLine(caretPos - start, s, len); + if (nonWhitespacePos == -1) { + if (leadingWS.length() == len && + sta.isClearWhitespaceLinesEnabled()) { + // If the line was nothing but whitespace, select it + // so its contents get removed. + sta.setSelectionStart(start); + sta.setSelectionEnd(end); + } + sta.replaceSelection(sb.toString()); + } + + // If there is non-whitespace between the caret and the + // EOL, pressing Enter takes that text to the next line + // and auto-indents it to the same place as the last + // line. + else { + sb.append(s.substring(nonWhitespacePos)); + sta.replaceRange(sb.toString(), caretPos, end); + sta.setCaretPosition(caretPos + leadingWS.length() + 1); + } + + // Must do it after everything else, as the "smart indent" + // calculation depends on the previous line's state + // AFTER the Enter press (stuff may have been moved down). + if (sta.getShouldIndentNextLine(lineNum)) { + sta.replaceSelection("\t"); + } + + possiblyCloseCurlyBrace(sta, leadingWS); + + } catch (BadLocationException ble) { // Never happens + sta.replaceSelection("\n"); + ble.printStackTrace(); + } + + } + + private void possiblyCloseCurlyBrace(RSyntaxTextArea textArea, + String leadingWS) { + + RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument(); + + if (textArea.getCloseCurlyBraces() && + doc.getCurlyBracesDenoteCodeBlocks()) { + + int line = textArea.getCaretLineNumber(); + Token t = doc.getTokenListForLine(line - 1); + t = t.getLastNonCommentNonWhitespaceToken(); + + if (t != null && t.isLeftCurly()) { + + if (getOpenBraceCount(doc) > 0) { + StringBuilder sb = new StringBuilder(); + if (line == textArea.getLineCount() - 1) { + sb.append('\n'); + } + if (leadingWS != null) { + sb.append(leadingWS); + } + sb.append("}\n"); + int dot = textArea.getCaretPosition(); + int end = textArea.getLineEndOffsetOfCurrentLine(); + // Insert at end of line, not at dot: they may have + // pressed Enter in the middle of the line and brought + // some text (though it must be whitespace and/or + // comments) down onto the new line. + textArea.insert(sb.toString(), end); + textArea.setCaretPosition(dot); // Caret may have moved + } + + } + + } + + } + + } + + + /** + * Action for inserting tabs. This is extended to "block indent" a + * group of contiguous lines if they are selected. + */ + public static class InsertTabAction extends RecordableTextAction { + + private static final long serialVersionUID = 1L; + + public InsertTabAction() { + super(insertTabAction); + } + + public InsertTabAction(String name) { + super(name); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + + if (!textArea.isEditable() || !textArea.isEnabled()) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + return; + } + + Document document = textArea.getDocument(); + Element map = document.getDefaultRootElement(); + Caret c = textArea.getCaret(); + int dot = c.getDot(); + int mark = c.getMark(); + int dotLine = map.getElementIndex(dot); + int markLine = map.getElementIndex(mark); + + // If there is a multi-line selection, indent all lines in + // the selection. + if (dotLine != markLine) { + int first = Math.min(dotLine, markLine); + int last = Math.max(dotLine, markLine); + Element elem; + int start; + + // Since we're using Document.insertString(), we must mimic the + // soft tab behavior provided by RTextArea.replaceSelection(). + String replacement = "\t"; + if (textArea.getTabsEmulated()) { + StringBuilder sb = new StringBuilder(); + int temp = textArea.getTabSize(); + for (int i = 0; i < temp; i++) { + sb.append(' '); + } + replacement = sb.toString(); + } + + textArea.beginAtomicEdit(); + try { + for (int i = first; i < last; i++) { + elem = map.getElement(i); + start = elem.getStartOffset(); + document.insertString(start, replacement, null); + } + // Don't do the last line if the caret is at its + // beginning. We must call getDot() again and not just + // use 'dot' as the caret's position may have changed + // due to the insertion of the tabs above. + elem = map.getElement(last); + start = elem.getStartOffset(); + if (Math.max(c.getDot(), c.getMark()) != start) { + document.insertString(start, replacement, null); + } + } catch (BadLocationException ble) { // Never happens. + ble.printStackTrace(); + UIManager.getLookAndFeel(). + provideErrorFeedback(textArea); + } finally { + textArea.endAtomicEdit(); + } + } else { + textArea.replaceSelection("\t"); + } + + } + + @Override + public final String getMacroID() { + return insertTabAction; + } + + } + + + /** + * Action to move the selection and/or caret. Constructor indicates + * direction to use. This class overrides the behavior defined in + * {@link RTextAreaEditorKit} to better skip "words" in source code. + */ + public static class NextWordAction + extends RTextAreaEditorKit.NextWordAction { + + private Segment seg; + + public NextWordAction(String nm, boolean select) { + super(nm, select); + seg = new Segment(); + } + + /** + * Overridden to do better with skipping "words" in code. + */ + @Override + protected int getNextWord(RTextArea textArea, int offs) + throws BadLocationException { + + RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument(); + if (offs == doc.getLength()) { + return offs; + } + + Element root = doc.getDefaultRootElement(); + int line = root.getElementIndex(offs); + int end = root.getElement(line).getEndOffset() - 1; + if (offs == end) {// If we're already at the end of the line... + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + if (rsta.isCodeFoldingEnabled()) { // Start of next visible line + FoldManager fm = rsta.getFoldManager(); + int lineCount = root.getElementCount(); + while (++line < lineCount && fm.isLineHidden(line)) { + ; + } + if (line < lineCount) { // Found a lower visible line + offs = root.getElement(line).getStartOffset(); + } + // No lower visible line - we're already at last visible offset + return offs; + } else { + return offs + 1; // Start of next line. + } + } + doc.getText(offs, end - offs, seg); + + // Determine the "type" of char at offs - letter/digit, + // whitespace or other + char ch = seg.first(); + + // Skip the group of letters and/or digits + if (Character.isLetterOrDigit(ch)) { + do { + ch = seg.next(); + } while (Character.isLetterOrDigit(ch)); + } + + // Skip groups of "anything else" (operators, etc.). + else if (!Character.isWhitespace(ch)) { + do { + ch = seg.next(); + } while (ch != Segment.DONE && + !(Character.isLetterOrDigit(ch) || + Character.isWhitespace(ch))); + } + + // Skip any trailing whitespace + while (Character.isWhitespace(ch)) { + ch = seg.next(); + } + + offs += seg.getIndex() - seg.getBeginIndex(); + return offs; + + } + + } + + + /** + * Action for when the user tries to insert a template (that is, + * they've typed a template ID and pressed the trigger character + * (a space) in an attempt to do the substitution). + */ + public static class PossiblyInsertTemplateAction extends RecordableTextAction { + + private static final long serialVersionUID = 1L; + + public PossiblyInsertTemplateAction() { + super(rstaPossiblyInsertTemplateAction); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + + if (!textArea.isEditable() || !textArea.isEnabled()) { + return; + } + + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + + if (RSyntaxTextArea.getTemplatesEnabled()) { + + Document doc = textArea.getDocument(); + if (doc != null) { + + try { + + CodeTemplateManager manager = RSyntaxTextArea. + getCodeTemplateManager(); + CodeTemplate template = manager == null ? null : + manager.getTemplate(rsta); + + // A non-null template means modify the text to insert! + if (template != null) { + template.invoke(rsta); + } + + // No template - insert default text. This is + // exactly what DefaultKeyTypedAction does. + else { + doDefaultInsert(rsta); + } + + } catch (BadLocationException ble) { + UIManager.getLookAndFeel(). + provideErrorFeedback(textArea); + } + + + } // End of if (doc!=null). + + } // End of if (textArea.getTemplatesEnabled()). + + // If templates aren't enabled, just insert the text as usual. + else { + doDefaultInsert(rsta); + } + + } + + private final void doDefaultInsert(RTextArea textArea) { + // FIXME: We need a way to get the "trigger string" (i.e., + // the text that was just typed); however, the text area's + // template manager might be null (if templates are disabled). + // Also, the manager's trigger string doesn't yet match up with + // that defined in RSyntaxTextAreaEditorKit.java (which is + // hardcoded as a space)... + //String str = manager.getInsertTriggerString(); + //int mod = manager.getInsertTrigger().getModifiers(); + //if (str!=null && str.length()>0 && + // ((mod&ActionEvent.ALT_MASK)==(mod&ActionEvent.CTRL_MASK))) { + // char ch = str.charAt(0); + // if (ch>=0x20 && ch!=0x7F) + // textArea.replaceSelection(str); + //} + textArea.replaceSelection(" "); + } + + @Override + public final String getMacroID() { + return rstaPossiblyInsertTemplateAction; + } + + } + + + /** + * Action to move the selection and/or caret. Constructor indicates + * direction to use. This class overrides the behavior defined in + * {@link RTextAreaEditorKit} to better skip "words" in source code. + */ + public static class PreviousWordAction + extends RTextAreaEditorKit.PreviousWordAction { + + private Segment seg; + + public PreviousWordAction(String nm, boolean select) { + super(nm, select); + seg = new Segment(); + } + + /** + * Overridden to do better with skipping "words" in code. + */ + @Override + protected int getPreviousWord(RTextArea textArea, int offs) + throws BadLocationException { + + if (offs == 0) { + return offs; + } + + RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument(); + Element root = doc.getDefaultRootElement(); + int line = root.getElementIndex(offs); + int start = root.getElement(line).getStartOffset(); + if (offs == start) {// If we're already at the start of the line... + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + if (rsta.isCodeFoldingEnabled()) { // End of next visible line + FoldManager fm = rsta.getFoldManager(); + while (--line >= 0 && fm.isLineHidden(line)) { + ; + } + if (line >= 0) { // Found an earlier visible line + offs = root.getElement(line).getEndOffset() - 1; + } + // No earlier visible line - we must be at offs==0... + return offs; + } else { + return start - 1; // End of previous line. + } + } + doc.getText(start, offs - start, seg); + + // Determine the "type" of char at offs - lower case, upper case, + // whitespace or other + char ch = seg.last(); + + // Skip any "leading" whitespace + while (Character.isWhitespace(ch)) { + ch = seg.previous(); + } + + // Skip the group of letters and/or digits + if (Character.isLetterOrDigit(ch)) { + do { + ch = seg.previous(); + } while (Character.isLetterOrDigit(ch)); + } + + // Skip groups of "anything else" (operators, etc.). + else if (!Character.isWhitespace(ch)) { + do { + ch = seg.previous(); + } while (ch != Segment.DONE && + !(Character.isLetterOrDigit(ch) || + Character.isWhitespace(ch))); + } + + offs -= seg.getEndIndex() - seg.getIndex(); + if (ch != Segment.DONE) { + offs++; + } + + return offs; + + } + + } + + + /** + * Selects the word around the caret. This class is here to better + * handle selecting "words" in programming languages. + */ + public static class SelectWordAction + extends RTextAreaEditorKit.SelectWordAction { + + @Override + protected void createActions() { + start = new BeginWordAction("pigdog", false); + end = new EndWordAction("pigdog", true); + } + + } + + + /** + * Action that toggles whether the currently selected lines are + * commented. + */ + public static class ToggleCommentAction extends RecordableTextAction { + + public ToggleCommentAction() { + super(rstaToggleCommentAction); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + + if (!textArea.isEditable() || !textArea.isEnabled()) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + return; + } + + RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument(); + String[] startEnd = doc.getLineCommentStartAndEnd(); + + if (startEnd == null) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + return; + } + + Element map = doc.getDefaultRootElement(); + Caret c = textArea.getCaret(); + int dot = c.getDot(); + int mark = c.getMark(); + int line1 = map.getElementIndex(dot); + int line2 = map.getElementIndex(mark); + int start = Math.min(line1, line2); + int end = Math.max(line1, line2); + + // Don't toggle comment on last line if there is no + // text selected on it. + if (start != end) { + Element elem = map.getElement(end); + if (Math.max(dot, mark) == elem.getStartOffset()) { + end--; + } + } + + textArea.beginAtomicEdit(); + try { + boolean add = getDoAdd(doc, map, start, end, startEnd); + for (line1 = start; line1 <= end; line1++) { + Element elem = map.getElement(line1); + handleToggleComment(elem, doc, startEnd, add); + } + } catch (BadLocationException ble) { + ble.printStackTrace(); + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + } finally { + textArea.endAtomicEdit(); + } + + } + + private boolean getDoAdd(Document doc, Element map, int startLine, + int endLine, String[] startEnd) + throws BadLocationException { + boolean doAdd = false; + for (int i = startLine; i <= endLine; i++) { + Element elem = map.getElement(i); + int start = elem.getStartOffset(); + String t = doc.getText(start, elem.getEndOffset() - start - 1); + if (!t.startsWith(startEnd[0]) || + (startEnd[1] != null && !t.endsWith(startEnd[1]))) { + doAdd = true; + break; + } + } + return doAdd; + } + + private void handleToggleComment(Element elem, Document doc, + String[] startEnd, boolean add) throws BadLocationException { + int start = elem.getStartOffset(); + int end = elem.getEndOffset() - 1; + if (add) { + doc.insertString(start, startEnd[0], null); + if (startEnd[1] != null) { + doc.insertString(end + startEnd[0].length(), startEnd[1], + null); + } + } else { + doc.remove(start, startEnd[0].length()); + if (startEnd[1] != null) { + int temp = startEnd[1].length(); + doc.remove(end - startEnd[0].length() - temp, temp); + } + } + } + + @Override + public final String getMacroID() { + return rstaToggleCommentAction; + } + + } + + + /** + * Toggles the fold at the current caret position or line. + */ + public static class ToggleCurrentFoldAction extends FoldRelatedAction { + + private static final long serialVersionUID = 1L; + + public ToggleCurrentFoldAction() { + super(rstaToggleCurrentFoldAction); + setProperties("Action.ToggleCurrentFold"); + } + + public ToggleCurrentFoldAction(String name, Icon icon, String desc, + Integer mnemonic, KeyStroke accelerator) { + super(name, icon, desc, mnemonic, accelerator); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + RSyntaxTextArea rsta = (RSyntaxTextArea) textArea; + if (rsta.isCodeFoldingEnabled()) { + Fold fold = getClosestFold(rsta); + if (fold != null) { + fold.toggleCollapsedState(); + } + possiblyRepaintGutter(textArea); + } else { + UIManager.getLookAndFeel().provideErrorFeedback(rsta); + } + } + + @Override + public final String getMacroID() { + return rstaToggleCurrentFoldAction; + } + + } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxUtilities.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxUtilities.java index 87be458925..ddb3ddfa3c 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxUtilities.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxUtilities.java @@ -3,12 +3,30 @@ * * RSyntaxUtilities.java - Utility methods used by RSyntaxTextArea and its * views. - * + * * This library is distributed under a modified BSD license. See the included * RSyntaxTextArea.License.txt file for details. */ package com.fr.design.gui.syntax.ui.rsyntaxtextarea; +import com.fr.design.gui.syntax.ui.rsyntaxtextarea.TokenUtils.TokenSubList; +import com.fr.design.gui.syntax.ui.rsyntaxtextarea.folding.FoldManager; +import com.fr.design.gui.syntax.ui.rtextarea.Gutter; +import com.fr.design.gui.syntax.ui.rtextarea.RTextArea; +import com.fr.design.gui.syntax.ui.rtextarea.RTextScrollPane; + +import javax.swing.JLabel; +import javax.swing.JViewport; +import javax.swing.SwingConstants; +import javax.swing.UIManager; +import javax.swing.text.BadLocationException; +import javax.swing.text.Caret; +import javax.swing.text.Document; +import javax.swing.text.Element; +import javax.swing.text.Position; +import javax.swing.text.Segment; +import javax.swing.text.TabExpander; +import javax.swing.text.View; import java.awt.Color; import java.awt.Container; import java.awt.Point; @@ -16,23 +34,9 @@ import java.awt.Rectangle; import java.awt.Shape; import java.awt.Toolkit; import java.util.Map; +import java.util.Objects; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import javax.swing.*; -import javax.swing.text.BadLocationException; -import javax.swing.text.Caret; -import javax.swing.text.Document; -import javax.swing.text.Element; -import javax.swing.text.Position; -import javax.swing.text.Segment; -import javax.swing.text.TabExpander; -import javax.swing.text.View; - -import com.fr.design.gui.syntax.ui.rsyntaxtextarea.TokenUtils.TokenSubList; -import com.fr.design.gui.syntax.ui.rsyntaxtextarea.folding.FoldManager; -import com.fr.design.gui.syntax.ui.rtextarea.Gutter; -import com.fr.design.gui.syntax.ui.rtextarea.RTextArea; -import com.fr.design.gui.syntax.ui.rtextarea.RTextScrollPane; /** @@ -44,1267 +48,1276 @@ import com.fr.design.gui.syntax.ui.rtextarea.RTextScrollPane; */ public class RSyntaxUtilities implements SwingConstants { - /** - * Integer constant representing a Windows-variant OS. - */ - public static final int OS_WINDOWS = 1; - - /** - * Integer constant representing Mac OS X. - */ - public static final int OS_MAC_OSX = 2; - - /** - * Integer constant representing Linux. - */ - public static final int OS_LINUX = 4; - - /** - * Integer constant representing an "unknown" OS. 99.99% of the - * time, this means some UNIX variant (AIX, SunOS, etc.). - */ - public static final int OS_OTHER = 8; - - /** - * Used for the color of hyperlinks when a LookAndFeel uses light text - * against a dark background. - */ - private static final Color LIGHT_HYPERLINK_FG = new Color(0xd8ffff); - - private static final int OS = getOSImpl(); - - //private static final int DIGIT_MASK = 1; - private static final int LETTER_MASK = 2; - //private static final int WHITESPACE_MASK = 4; - //private static final int UPPER_CASE_MASK = 8; - private static final int HEX_CHARACTER_MASK = 16; - private static final int LETTER_OR_DIGIT_MASK = 32; - private static final int BRACKET_MASK = 64; - private static final int JAVA_OPERATOR_MASK = 128; - - /** - * A lookup table used to quickly decide if a 16-bit Java char is a - * US-ASCII letter (A-Z or a-z), a digit, a whitespace char (either space - * (0x0020) or tab (0x0009)), etc. This method should be faster - * than Character.isLetter, Character.isDigit, - * and Character.isWhitespace because we know we are dealing - * with ASCII chars and so don't have to worry about code planes, etc. - */ - private static final int[] dataTable = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, // 0-15 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31 - 4, 128, 0, 0, 0, 128, 128, 0, 64, 64, 128, 128, 0, 128, 0, 128, // 32-47 - 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 128, 0, 128, 128, 128, 128, // 48-63 - 0, 58, 58, 58, 58, 58, 58, 42, 42, 42, 42, 42, 42, 42, 42, 42, // 64-79 - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 64, 0, 64, 128, 0, // 80-95 - 0, 50, 50, 50, 50, 50, 50, 34, 34, 34, 34, 34, 34, 34, 34, 34, // 96-111 - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 64, 128, 64, 128, 0, // 112-127 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 128-143 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 144- - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160- - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 176- - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 192- - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 208- - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 224- - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 240-255. - }; - - /** - * Used in bracket matching methods. - */ - private static Segment charSegment = new Segment(); - - /** - * Used in token list manipulation methods. - */ - private static final TokenImpl tempToken = new TokenImpl(); - - /** - * Used internally. - */ - private static final char[] JS_KEYWORD_RETURN = { 'r', 'e', 't', 'u', 'r', 'n' }; - - /** - * Used internally. - */ - private static final String BRACKETS = "{([})]"; - - - /** - * Returns a string with characters that are special to HTML (such as - * <, > and &) replaced - * by their HTML escape sequences. - * - * @param s The input string. - * @param newlineReplacement What to replace newline characters with. - * If this is null, they are simply removed. - * @param inPreBlock Whether this HTML will be in within pre - * tags. If this is true, spaces will be kept as-is; - * otherwise, they will be converted to " ". - * @return The escaped version of s. - */ - public static final String escapeForHtml(String s, - String newlineReplacement, boolean inPreBlock) { - - if (s==null) { - return null; - } - if (newlineReplacement==null) { - newlineReplacement = ""; - } - final String tabString = " "; - boolean lastWasSpace = false; - - StringBuilder sb = new StringBuilder(); - - for (int i=0; i': - sb.append(">"); - lastWasSpace = false; - break; - default: - sb.append(ch); - lastWasSpace = false; - break; - } - } - - return sb.toString(); - - } - - - /** - * Returns the rendering hints for text that will most accurately reflect - * those of the native windowing system. - * - * @return The rendering hints, or null if they cannot be - * determined. - */ - public static Map getDesktopAntiAliasHints() { - return (Map)Toolkit.getDefaultToolkit(). - getDesktopProperty("awt.font.desktophints"); - } - - - /** - * Returns the color to use for the line underneath a folded region line. - * - * @param textArea The text area. - * @return The color to use. - */ - public static Color getFoldedLineBottomColor(RSyntaxTextArea textArea) { - Color color = Color.gray; - Gutter gutter = RSyntaxUtilities.getGutter(textArea); - if (gutter!=null) { - color = gutter.getFoldIndicatorForeground(); - } - return color; - } - - - /** - * Returns the gutter component of the scroll pane containing a text - * area, if any. - * - * @param textArea The text area. - * @return The gutter, or null if the text area is not in - * an {@link RTextScrollPane}. - * @see RTextScrollPane#getGutter() - */ - public static Gutter getGutter(RTextArea textArea) { - Gutter gutter = null; - Container parent = textArea.getParent(); - if (parent instanceof JViewport) { - parent = parent.getParent(); - if (parent instanceof RTextScrollPane) { - RTextScrollPane sp = (RTextScrollPane)parent; - gutter = sp.getGutter(); // Should always be non-null - } - } - return gutter; - } - - - /** - * Returns the color to use for hyperlink-style components. This method - * will return Color.blue unless it appears that the current - * LookAndFeel uses light text on a dark background, in which case a - * brighter alternative is returned. - * - * @return The color to use for hyperlinks. - * @see #isLightForeground(Color) - */ - public static final Color getHyperlinkForeground() { - - // This property is defined by all standard LaFs, even Nimbus (!), - // but you never know what crazy LaFs there are... - Color fg = UIManager.getColor("Label.foreground"); - if (fg==null) { - fg = new JLabel().getForeground(); - } - - return isLightForeground(fg) ? LIGHT_HYPERLINK_FG : Color.blue; - - } - - - /** - * Returns the leading whitespace of a string. - * - * @param text The String to check. - * @return The leading whitespace. - * @see #getLeadingWhitespace(Document, int) - */ - public static String getLeadingWhitespace(String text) { - int count = 0; - int len = text.length(); - while (countoffs is not a valid offset - * in the document. - * @see #getLeadingWhitespace(String) - */ - public static String getLeadingWhitespace(Document doc, int offs) - throws BadLocationException { - Element root = doc.getDefaultRootElement(); - int line = root.getElementIndex(offs); - Element elem = root.getElement(line); - int startOffs = elem.getStartOffset(); - int endOffs = elem.getEndOffset() - 1; - String text = doc.getText(startOffs, endOffs-startOffs); - return getLeadingWhitespace(text); - } - - - private static final Element getLineElem(Document d, int offs) { - Element map = d.getDefaultRootElement(); - int index = map.getElementIndex(offs); - Element elem = map.getElement(index); - if ((offs>=elem.getStartOffset()) && (offsp0, as this is - * the character where the x-pixel value is 0. - * - * @param textArea The text area containing the text. - * @param s A segment in which to load the line. This is passed in so we - * don't have to reallocate a new Segment for each - * call. - * @param p0 The starting position in the physical line in the document. - * @param p1 The position for which to get the bounding box in the view. - * @param e How to expand tabs. - * @param rect The rectangle whose x- and width-values are changed to - * represent the bounding box of p1. This is reused - * to keep from needlessly reallocating Rectangles. - * @param x0 The x-coordinate (pixel) marking the left-hand border of the - * text. This is useful if the text area has a border, for example. - * @return The bounding box in the view of the character p1. - * @throws BadLocationException If p0 or p1 is - * not a valid location in the specified text area's document. - * @throws IllegalArgumentException If p0 and p1 - * are not on the same line. - */ - public static Rectangle getLineWidthUpTo(RSyntaxTextArea textArea, - Segment s, int p0, int p1, - TabExpander e, Rectangle rect, - int x0) - throws BadLocationException { - - RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); - - // Ensure p0 and p1 are valid document positions. - if (p0<0) - throw new BadLocationException("Invalid document position", p0); - else if (p1>doc.getLength()) - throw new BadLocationException("Invalid document position", p1); - - // Ensure p0 and p1 are in the same line, and get the start/end - // offsets for that line. - Element map = doc.getDefaultRootElement(); - int lineNum = map.getElementIndex(p0); - // We do ">1" because p1 might be the first position on the next line - // or the last position on the previous one. - // if (lineNum!=map.getElementIndex(p1)) - if (Math.abs(lineNum-map.getElementIndex(p1))>1) - throw new IllegalArgumentException("p0 and p1 are not on the " + - "same line (" + p0 + ", " + p1 + ")."); - - // Get the token list. - Token t = doc.getTokenListForLine(lineNum); - - // Modify the token list 't' to begin at p0 (but still have correct - // token types, etc.), and get the x-location (in pixels) of the - // beginning of this new token list. - TokenSubList subList = TokenUtils.getSubTokenList(t, p0, e, textArea, - 0, tempToken); - t = subList.tokenList; - - rect = t.listOffsetToView(textArea, e, p1, x0, rect); - return rect; - - } - - - /** - * Returns the location of the bracket paired with the one at the current - * caret position. - * - * @param textArea The text area. - * @param input A point to use as the return value. If this is - * null, a new object is created and returned. - * @return A point representing the matched bracket info. The "x" field - * is the offset of the bracket at the caret position (either just - * before or just after the caret), and the "y" field is the offset - * of the matched bracket. Both "x" and "y" will be - * -1 if there isn't a matching bracket (or the caret - * isn't on a bracket). - */ - public static Point getMatchingBracketPosition(RSyntaxTextArea textArea, - Point input) { - - if (input==null) { - input = new Point(); - } - input.setLocation(-1, -1); - - try { - - // Actually position just BEFORE caret. - int caretPosition = textArea.getCaretPosition() - 1; - RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); - char bracket = 0; - - // If the caret was at offset 0, we can't check "to its left." - if (caretPosition>=0) { - bracket = doc.charAt(caretPosition); - } - - // Try to match a bracket "to the right" of the caret if one - // was not found on the left. - int index = BRACKETS.indexOf(bracket); - if (index==-1 && caretPosition