Browse Source

Merge remote-tracking branch 'origin/final/11.0' into final/11.0

# Conflicts:
#	designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/FRAbsoluteBodyLayoutDefinePane.java
#	designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/FRFitLayoutDefinePane.java
new-design
Hoky 3 years ago
parent
commit
81b629180f
  1. 7
      build.gradle
  2. 3
      designer-base/src/main/java/com/fr/base/svg/IconUtils.java
  3. 6
      designer-base/src/main/java/com/fr/base/svg/SVGIcon.java
  4. 92
      designer-base/src/main/java/com/fr/base/svg/SVGLoader.java
  5. 181
      designer-base/src/main/java/com/fr/base/svg/SVGTranscoder.java
  6. 101
      designer-base/src/main/java/com/fr/base/svg/SystemScaleUtils.java
  7. 2
      designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java
  8. 14
      designer-base/src/main/java/com/fr/design/data/datapane/connect/AdvancePane.java
  9. 44
      designer-base/src/main/java/com/fr/design/data/datapane/connect/DatabaseConnectionPane.java
  10. 19
      designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java
  11. 301
      designer-base/src/main/java/com/fr/design/data/datapane/connect/SshPane.java
  12. 164
      designer-base/src/main/java/com/fr/design/data/datapane/connect/SslPane.java
  13. 15
      designer-base/src/main/java/com/fr/design/deeplink/DeepLink.java
  14. 184
      designer-base/src/main/java/com/fr/design/deeplink/DeepLinkCore.java
  15. 33
      designer-base/src/main/java/com/fr/design/editor/editor/NotNegativeIntegerEditor.java
  16. 10
      designer-base/src/main/java/com/fr/design/formula/FormulaPane.java
  17. 2
      designer-base/src/main/java/com/fr/design/formula/exception/function/MismatchedTokenFunction.java
  18. 5
      designer-base/src/main/java/com/fr/design/gui/autocomplete/AutoCompleteExtraRefreshComponent.java
  19. 982
      designer-base/src/main/java/com/fr/design/gui/autocomplete/AutoCompleteWithExtraRefreshPopupWindow.java
  20. 1260
      designer-base/src/main/java/com/fr/design/gui/autocomplete/AutoCompletionWithExtraRefresh.java
  21. 976
      designer-base/src/main/java/com/fr/design/gui/autocomplete/FormulaAutoCompletePopupWindow.java
  22. 1241
      designer-base/src/main/java/com/fr/design/gui/autocomplete/FormulaPaneAutoCompletion.java
  23. 16
      designer-base/src/main/java/com/fr/design/gui/autocomplete/JSAutoCompletePopupWindow.java
  24. 31
      designer-base/src/main/java/com/fr/design/gui/autocomplete/JSImplPaneAutoCompletion.java
  25. 78
      designer-base/src/main/java/com/fr/design/gui/ilable/UIAutoChangeLineLabel.java
  26. 169
      designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java
  27. 924
      designer-base/src/main/java/com/fr/design/javascript/JSContentWithDescriptionPane.java
  28. 95
      designer-base/src/main/java/com/fr/design/javascript/JavaScriptImplPane.java
  29. 23
      designer-base/src/main/java/com/fr/design/javascript/NewJavaScriptImplPane.java
  30. 21
      designer-base/src/main/java/com/fr/design/javascript/jsapi/CategoryTreeNodesUserObject.java
  31. 155
      designer-base/src/main/java/com/fr/design/javascript/jsapi/JSAPITreeHelper.java
  32. 9
      designer-base/src/main/java/com/fr/design/javascript/jsapi/JSAPIUserObject.java
  33. 7
      designer-base/src/main/java/com/fr/design/javascript/jsapi/JSImplPopulateAction.java
  34. 7
      designer-base/src/main/java/com/fr/design/javascript/jsapi/JSImplUpdateAction.java
  35. 7
      designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java
  36. 16
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  37. 12
      designer-base/src/main/java/com/fr/design/mainframe/form/FormECDesignerProvider.java
  38. 186
      designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java
  39. 40
      designer-base/src/main/java/com/fr/design/mainframe/predefined/PatternStyle.java
  40. 143
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleBlock.java
  41. 374
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleEditPane.java
  42. 102
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleSelectPane.java
  43. 159
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleSettingPane.java
  44. 51
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/ReportPredefinedStylePane.java
  45. 218
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/ServerPredefinedStylePane.java
  46. 308
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleListControlPane.java
  47. 94
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/ChartStyleSettingPane.java
  48. 63
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/ComponentStyleSettingPane.java
  49. 81
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/PredefinedBackgroundSettingPane.java
  50. 51
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/AbstractBackgroundDetailPane.java
  51. 135
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/BackgroundSettingPane.java
  52. 76
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/BackgroundWithAlphaSettingPane.java
  53. 56
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/ColorDetailPane.java
  54. 34
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/EmptyBackgroundPane.java
  55. 48
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/FormBackgroundSettingPane.java
  56. 159
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/GradientDetailPane.java
  57. 215
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/ImageDetailPane.java
  58. 119
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/PatternDetailPane.java
  59. 97
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/TextureDetailObservePane.java
  60. 223
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/cell/CustomPredefinedStylePane.java
  61. 49
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/AbstractChartStylePane.java
  62. 69
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartAxisStylePane.java
  63. 113
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartBackgroundStylePane.java
  64. 58
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartDataSheetStylePane.java
  65. 160
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartFontPane.java
  66. 78
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartLabelStylePane.java
  67. 49
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartLegendStylePane.java
  68. 49
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartTitleStylePane.java
  69. 148
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/component/ComponentFrameStylePane.java
  70. 93
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/component/ComponentMarginStylePane.java
  71. 15
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/component/ComponentStylePane.java
  72. 253
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/component/ComponentTitleStylePane.java
  73. 193
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/dialog/PredefinedStyleEditDialog.java
  74. 97
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/dialog/ReportPredefinedStyleDialog.java
  75. 68
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/dialog/ServerPredefinedStyleDialog.java
  76. 108
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/ChartPreStylePreView.java
  77. 142
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/ComponentPreviewPane.java
  78. 171
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/ElementCasePreview.java
  79. 157
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/PredefinedStylePreviewPane.java
  80. 17
      designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/StyleSettingPreviewPane.java
  81. 4
      designer-base/src/main/java/com/fr/design/mainframe/share/ComponentShareUtil.java
  82. 37
      designer-base/src/main/java/com/fr/design/mainframe/share/mini/MiniShopDisposingChecker.java
  83. 11
      designer-base/src/main/java/com/fr/design/mainframe/share/mini/MiniShopNativeTask.java
  84. 42
      designer-base/src/main/java/com/fr/design/mainframe/share/mini/MiniShopNativeTaskManager.java
  85. 3
      designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java
  86. 9
      designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeGridPagesDialog.java
  87. 2
      designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeProfileDialog.java
  88. 7
      designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeUsingDialog.java
  89. 2
      designer-base/src/main/java/com/fr/design/mainframe/theme/edit/ReportBodyStyleEditPane.java
  90. 6
      designer-base/src/main/java/com/fr/design/report/fit/AdaptiveFrmFitAttrModel.java
  91. 130
      designer-base/src/main/java/com/fr/design/report/fit/BaseFitAttrPane.java
  92. 9
      designer-base/src/main/java/com/fr/design/report/fit/FitAttrModel.java
  93. 11
      designer-base/src/main/java/com/fr/design/report/fit/FitType.java
  94. 128
      designer-base/src/main/java/com/fr/design/report/fit/FormFitAttrModelType.java
  95. 163
      designer-base/src/main/java/com/fr/design/report/fit/FormFitConfigPane.java
  96. 9
      designer-base/src/main/java/com/fr/design/report/fit/FrmFitAttrModel.java
  97. 79
      designer-base/src/main/java/com/fr/design/report/fit/NewFitPreviewPane.java
  98. 172
      designer-base/src/main/java/com/fr/design/report/fit/ReportFitConfigPane.java
  99. 28
      designer-base/src/main/java/com/fr/design/selection/Selectedable.java
  100. 33
      designer-base/src/main/java/com/fr/design/startup/FineStartupNotificationFactory.java
  101. Some files were not shown because too many files have changed in this diff Show More

7
build.gradle

@ -9,6 +9,7 @@ plugins {
//
ext {
frVersion = ""
cbbVersion = ""
outputPath = "build"
ignoreTestFailureSetting = true
languageLevelSetting = 1.8
@ -44,6 +45,9 @@ allprojects {
repositories {
mavenLocal()
maven {
url 'https://maven.ej-technologies.com/repository'
}
}
idea {
@ -57,6 +61,9 @@ allprojects {
}
dependencies {
implementation 'com.fr.essential:fine-essential:' + cbbVersion
implementation 'com.fr.cbb:fine-universal-skeleton:' + cbbVersion
implementation 'com.install4j:install4j-runtime:8.0.4'
implementation 'com.fr.third:jxbrowser:6.23'
implementation 'com.fr.third:jxbrowser-mac:6.23'
implementation 'com.fr.third:jxbrowser-win64:6.23'

3
designer-base/src/main/java/com/fr/base/svg/IconUtils.java

@ -6,8 +6,7 @@ import com.fr.stable.bridge.StableFactory;
import com.fr.stable.fun.ResourcePathTransformer;
import com.fr.stable.plugin.ExtraClassManagerProvider;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

6
designer-base/src/main/java/com/fr/base/svg/SVGIcon.java

@ -2,10 +2,8 @@ package com.fr.base.svg;
import com.fr.general.IOUtils;
import javax.swing.Icon;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

92
designer-base/src/main/java/com/fr/base/svg/SVGLoader.java

@ -1,92 +0,0 @@
package com.fr.base.svg;
import com.fr.general.IOUtils;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.xmlgraphics.java2d.Dimension2DDouble;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.Image;
import java.io.IOException;
import java.net.URL;
/**
* SVG图标加载器
* @author Yvan
* @version 10.0
* Created by Yvan on 2020/12/17
*/
public class SVGLoader {
public static final int ICON_DEFAULT_SIZE = 16;
public SVGLoader() {
}
@Nullable
public static Image load(@NotNull String url) {
try {
URL resource = IOUtils.getResource(url, SVGLoader.class);
if (resource == null) {
return null;
}
return load(resource, SVGIcon.SYSTEM_SCALE);
} catch (IOException ignore) {
return null;
}
}
@Nullable
public static Image load(@NotNull URL url) throws IOException {
return load(url, SVGIcon.SYSTEM_SCALE);
}
@Nullable
public static Image load(@NotNull URL url, double scale) throws IOException {
try {
String svgUri = url.toString();
TranscoderInput input = new TranscoderInput(svgUri);
return SVGTranscoder.createImage(scale, input).getImage();
} catch (TranscoderException ignore) {
return null;
}
}
@Nullable
public static Image load(@NotNull URL url, double scale, Dimension2DDouble dimension) throws IOException {
try {
String svgUri = url.toString();
TranscoderInput input = new TranscoderInput(svgUri);
return SVGTranscoder.createImage(scale, input,
(float) (dimension.getWidth() * scale), (float) (dimension.getHeight() * scale)).getImage();
} catch (TranscoderException ignore) {
return null;
}
}
@Nullable
public static Image load(@NotNull URL url, double scale, double overriddenWidth, double overriddenHeight) throws IOException {
try {
String svgUri = url.toString();
TranscoderInput input = new TranscoderInput(svgUri);
return SVGTranscoder.createImage(scale, input, (float) (overriddenWidth * scale), (float) (overriddenHeight * scale)).getImage();
} catch (TranscoderException ignore) {
return null;
}
}
@Nullable
public static Image load(@NotNull String url, float width, float height) {
try {
URL resource = IOUtils.getResource(url, SVGLoader.class);
if (resource == null) {
return null;
}
TranscoderInput input = new TranscoderInput(resource.toString());
return SVGTranscoder.createImage(SVGIcon.SYSTEM_SCALE, input, -1, -1, width, height).getImage();
} catch (TranscoderException ignore) {
return null;
}
}
}

181
designer-base/src/main/java/com/fr/base/svg/SVGTranscoder.java

@ -1,181 +0,0 @@
package com.fr.base.svg;
import com.fr.stable.AssistUtils;
import com.fr.value.AtomicNotNullLazyValue;
import org.apache.batik.anim.dom.SAXSVGDocumentFactory;
import org.apache.batik.anim.dom.SVGOMDocument;
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.UserAgent;
import org.apache.batik.transcoder.SVGAbstractTranscoder;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.batik.util.XMLResourceDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.StringReader;
/**
* 可以根据某个缩放倍数scale将SVG图片转化为Image对象
* @author Yvan
* @version 10.0
* Created by Yvan on 2020/12/17
*/
public class SVGTranscoder extends ImageTranscoder {
private static final float DEFAULT_VALUE = -1.0F;
public static final float ICON_DEFAULT_SIZE = 16F;
private float origDocWidth;
private float origDocHeight;
@Nullable
private BufferedImage image;
private final double scale;
@NotNull
private static AtomicNotNullLazyValue<Double> iconMaxSize = new AtomicNotNullLazyValue<Double>() {
@NotNull
@Override
protected Double compute() {
double maxSize = Double.MAX_VALUE;
if (!GraphicsEnvironment.isHeadless()) {
GraphicsDevice defaultScreenDevice = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
Rectangle bounds = defaultScreenDevice.getDefaultConfiguration().getBounds();
AffineTransform tx = defaultScreenDevice
.getDefaultConfiguration()
.getDefaultTransform();
maxSize = Math.max(bounds.width * tx.getScaleX(), bounds.height * tx.getScaleY());
}
return maxSize;
}
};
public SVGTranscoder(double scale) {
this.scale = scale;
this.width = ICON_DEFAULT_SIZE;
this.height = ICON_DEFAULT_SIZE;
}
public SVGTranscoder(double scale, float width, float height) {
this.scale = scale;
this.width = width;
this.height = height;
}
public final float getOrigDocWidth() {
return this.origDocWidth;
}
public final void setOrigDocWidth(float origDocWidth) {
this.origDocWidth = origDocWidth;
}
public final float getOrigDocHeight() {
return this.origDocHeight;
}
public final void setOrigDocHeight(float origDocHeight) {
this.origDocHeight = origDocHeight;
}
public static double getIconMaxSize() {
return iconMaxSize.getValue();
}
@Nullable
public final BufferedImage getImage() {
return this.image;
}
@NotNull
public static SVGTranscoder createImage(double scale, @NotNull TranscoderInput input) throws TranscoderException {
return createImage(scale, input, -1, -1);
}
@NotNull
public static SVGTranscoder createImage(double scale, @NotNull TranscoderInput input, float overriddenWidth, float overriddenHeight) throws TranscoderException {
return createImage(scale, input, overriddenWidth, overriddenHeight, ICON_DEFAULT_SIZE, ICON_DEFAULT_SIZE);
}
@NotNull
public static SVGTranscoder createImage(double scale, @NotNull TranscoderInput input, float overriddenWidth, float overriddenHeight, float width, float height) throws TranscoderException {
SVGTranscoder transcoder = new SVGTranscoder(scale, width, height);
if (!AssistUtils.equals(overriddenWidth, DEFAULT_VALUE)) {
transcoder.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, overriddenWidth);
}
if (!AssistUtils.equals(overriddenHeight, DEFAULT_VALUE)) {
transcoder.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, overriddenHeight);
}
double iconMaxSize = SVGTranscoder.iconMaxSize.getValue();
transcoder.addTranscodingHint(SVGAbstractTranscoder.KEY_MAX_WIDTH, (float) iconMaxSize);
transcoder.addTranscodingHint(SVGAbstractTranscoder.KEY_MAX_HEIGHT, (float) iconMaxSize);
transcoder.transcode(input, null);
return transcoder;
}
private static SVGDocument createFallbackPlaceholder() {
try {
String fallbackIcon = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\">\n" +
" <rect x=\"1\" y=\"1\" width=\"14\" height=\"14\" fill=\"none\" stroke=\"red\" stroke-width=\"2\"/>\n" +
" <line x1=\"1\" y1=\"1\" x2=\"15\" y2=\"15\" stroke=\"red\" stroke-width=\"2\"/>\n" +
" <line x1=\"1\" y1=\"15\" x2=\"15\" y2=\"1\" stroke=\"red\" stroke-width=\"2\"/>\n" +
"</svg>\n";
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName());
return (SVGDocument) factory.createDocument(null, new StringReader(fallbackIcon));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
protected void setImageSize(float docWidth, float docHeight) {
super.setImageSize((float) (docWidth * this.scale), (float) (docHeight * this.scale));
this.origDocWidth = docWidth;
this.origDocHeight = docHeight;
}
@Override
@NotNull
public BufferedImage createImage(int width, int height) {
return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
}
@Override
public void writeImage(@NotNull BufferedImage image, @Nullable TranscoderOutput output) {
this.image = image;
}
@Override
@NotNull
protected UserAgent createUserAgent() {
return new SVGAbstractTranscoderUserAgent() {
@Override
@NotNull
public SVGDocument getBrokenLinkDocument(@NotNull Element e, @NotNull String url, @NotNull String message) {
return createFallbackPlaceholder();
}
};
}
/**
* 开放访问权限
*/
@Override
public BridgeContext createBridgeContext(SVGOMDocument doc) {
return super.createBridgeContext(doc);
}
}

101
designer-base/src/main/java/com/fr/base/svg/SystemScaleUtils.java

@ -1,101 +0,0 @@
package com.fr.base.svg;
import com.bulenkov.iconloader.util.UIUtil;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StableUtils;
import com.fr.stable.os.OperatingSystem;
import org.jetbrains.annotations.NotNull;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicReference;
/**
* 获取系统Scale相关的工具类
* @author Yvan
* @version 10.0
* Created by Yvan on 2020/12/17
*/
public class SystemScaleUtils {
private static final AtomicReference<Boolean> JRE_HIDPI = new AtomicReference<>();
private static final String HI_DPI = "hidpi";
/**
* 判断是否支持高清
* @return
*/
public static boolean isJreHiDPIEnabled() {
if (JRE_HIDPI.get() != null) {
return JRE_HIDPI.get();
}
if (OperatingSystem.isMacos()) {
// 如果是mac os系统,直接返回true
return true;
}
if (OperatingSystem.isWindows() && StableUtils.getMajorJavaVersion() <= 8) {
// 如果是jdk8 + Windows系统,直接返回false
return false;
}
synchronized (JRE_HIDPI) {
if (JRE_HIDPI.get() != null) {
return JRE_HIDPI.get();
}
boolean result = false;
if (getBooleanProperty(HI_DPI, true)) {
try {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Class<?> sunGraphicsEnvironmentClass = Class.forName("sun.java2d.SunGraphicsEnvironment");
if (sunGraphicsEnvironmentClass.isInstance(ge)) {
try {
Method method = sunGraphicsEnvironmentClass.getDeclaredMethod("isUIScaleEnabled");
method.setAccessible(true);
result = (Boolean)method.invoke(ge);
}
catch (NoSuchMethodException e) {
FineLoggerFactory.getLogger().error(e.getMessage());
}
}
}
catch (Throwable ignore) {
}
}
JRE_HIDPI.set(result);
return result;
}
}
public static boolean getBooleanProperty(@NotNull final String key, final boolean defaultValue) {
final String value = System.getProperty(key);
return value == null ? defaultValue : Boolean.parseBoolean(value);
}
/**
* 获取系统Scale
* @return
*/
public static float sysScale() {
// 如果检测到是retina,直接返回2
if (UIUtil.isRetina()) {
return 2.0f;
}
float scale = 1.0f;
// 先判断是否支持高清,不支持代表此时是Windows + jdk8 的设计器,返回的scale值为1.0
if (isJreHiDPIEnabled()) {
// 获取屏幕图形设备对象
GraphicsDevice graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (graphicsDevice != null) {
// 获取图形配置对象
GraphicsConfiguration configuration = graphicsDevice.getDefaultConfiguration();
if (configuration != null && configuration.getDevice().getType() != GraphicsDevice.TYPE_PRINTER) {
// 获取屏幕缩放率,Windows+jdk11环境下会得到用户设置的dpi值
scale = (float) configuration.getDefaultTransform().getScaleX();
}
}
}
return scale;
}
}

2
designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java

@ -108,7 +108,7 @@ public class PreferencePane extends BasicPane {
private static final int CACHING_DEFAULT = 5;
private static final int CACHING_GAP = 5;
private static final int MEMORY_TIP_LABEL_MAX_WIDTH = 230;
private static final int OFFSET_HEIGHT = 50;
private static final int OFFSET_HEIGHT = 60;
private static final String TYPE = "pressed";
private static final String DISPLAY_TYPE = "+";

14
designer-base/src/main/java/com/fr/design/data/datapane/connect/AdvancePane.java

@ -15,9 +15,9 @@ import com.fr.stable.StringUtils;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
@ -34,13 +34,12 @@ public class AdvancePane extends BasicPane {
public AdvancePane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
DBCP_VALIDATION_QUERY.addFocusListener(new JTextFieldHintListener(DBCP_VALIDATION_QUERY));
;
double p = TableLayout.PREFERRED;
DBCP_VALIDATION_QUERY.setColumns(15);
DBCP_VALIDATION_QUERY.setColumns(20);
double[] rowSizeDbcp = {p, p, p, p};
double[] columnDbcp = {p, p};
double[] columnDbcp = {190, p};
Component[][] comps = {
{new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Max_Active") + ":", SwingConstants.RIGHT), DBCP_MAX_ACTIVE},
{new UILabel(Toolkit.i18nText("Fine-Design_Basic_Dbcp_Validation_Query") + ":", SwingConstants.RIGHT), DBCP_VALIDATION_QUERY},
@ -49,9 +48,8 @@ public class AdvancePane extends BasicPane {
};
JPanel contextPane = TableLayoutHelper.createGapTableLayoutPane(comps, rowSizeDbcp, columnDbcp, 11, 11);
this.add(contextPane);
this.setPreferredSize(new Dimension(630, 120));
this.setLayout(FRGUIPaneFactory.createLeftZeroVgapNormalHgapLayout());
jPanel.add(contextPane, BorderLayout.CENTER);
this.add(jPanel);
}

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

@ -7,6 +7,7 @@ import com.fr.data.impl.Connection;
import com.fr.data.impl.JDBCDatabaseConnection;
import com.fr.data.impl.JNDIDatabaseConnection;
import com.fr.data.operator.DataOperatorProvider;
import com.fr.data.security.ssl.impl.NormalSsl;
import com.fr.data.solution.ExceptionSolutionSelector;
import com.fr.data.solution.entity.DriverPage;
import com.fr.data.solution.processor.ClassNotFoundExceptionSolutionProcessor;
@ -61,7 +62,7 @@ import java.util.concurrent.ExecutionException;
* Database Connection pane.
*/
public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connection> extends BasicBeanPane<com.fr.data.impl.Connection> {
private static int MAX_MAIN_PANEL_HEIGHT = 430;
private static int MAX_MAIN_PANEL_HEIGHT = 410;
private static int MAX_MAIN_PANEL_WIDTH = 675;
private UILabel message;
@ -312,6 +313,15 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
throw new UnsupportedOperationException();
}
protected SslPane getSslPane() {
throw new UnsupportedOperationException();
}
protected SshPane getSshPane() {
throw new UnsupportedOperationException();
}
protected void initComponents() {
message = new UILabel();
uiLabel = new UILabel();
@ -325,7 +335,8 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
cancelButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel"));
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel northPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane();
this.add(northPane, BorderLayout.NORTH);
UIScrollPane uiScrollPane = new UIScrollPane(northPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
this.add(uiScrollPane, BorderLayout.CENTER);
// 按钮.
JPanel testPane = FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane();
@ -339,8 +350,6 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
mainPanel = mainPanel();
JPanel advancedPanel = FRGUIPaneFactory.createTopVerticalTitledBorderPane(Toolkit.i18nText("Fine-Design_Basic_Advanced"));
if (mainPanel instanceof JDBCDefPane) {
mainPanel.setPreferredSize(new Dimension(MAX_MAIN_PANEL_WIDTH, 280));
advancedPanel.setPreferredSize(new Dimension(MAX_MAIN_PANEL_WIDTH, 210));
northPane.add(mainPanel, BorderLayout.CENTER);
ActionLabel actionLabel = new ActionLabel(Toolkit.i18nText("Fine-Design_Advanced_More_Settings"));
actionLabel.addActionListener(new ActionListener() {
@ -360,7 +369,8 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
advancedPanel.add(advancePane);
}
advancedPanel.add(actionLabelPanel);
northPane.add(getSshPane());
northPane.add(getSslPane());
} else {
//非jdbc配置布局保持不变
advancedPanel.setPreferredSize(new Dimension(MAX_MAIN_PANEL_WIDTH, 60));
@ -427,6 +437,12 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
private static JDBCDefPane jdbcDefPane = new JDBCDefPane();
private static DBCPAttrPane dbcpAttrPane = new DBCPAttrPane();
private static AdvancePane advancePane = new AdvancePane();
private static SslPane sslPane = new SslPane();
private static SshPane sshPane = new SshPane();
static {
jdbcDefPane.addLinkPane(sslPane);
}
@Override
protected JPanel mainPanel() {
@ -447,6 +463,8 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
jdbcDefPane.populate(ob);
dbcpAttrPane.populate(jdbcDefPane.getJDBCDatabase());
advancePane.populate(jdbcDefPane.getJDBCDatabase());
sshPane.populate(jdbcDefPane.getJDBCDatabase());
sslPane.populate(jdbcDefPane.getJDBCDatabase());
}
@Override
@ -454,6 +472,12 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
JDBCDatabaseConnection jdbcDatabaseConnection = jdbcDefPane.update();
dbcpAttrPane.update(jdbcDatabaseConnection);
advancePane.update(jdbcDatabaseConnection);
sshPane.update(jdbcDatabaseConnection);
if (sslPane.isVisible()) {
sslPane.update(jdbcDatabaseConnection);
} else {
jdbcDatabaseConnection.setSsl(new NormalSsl());
}
return jdbcDatabaseConnection;
}
@ -462,6 +486,16 @@ public abstract class DatabaseConnectionPane<E extends com.fr.data.impl.Connecti
return advancePane;
}
@Override
protected SslPane getSslPane() {
return sslPane;
}
@Override
protected SshPane getSshPane() {
return sshPane;
}
@Override
protected String title4PopupWindow() {
return "JDBC";

19
designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java

@ -4,7 +4,9 @@ import com.fr.base.GraphHelper;
import com.fr.data.driver.DriverLoader;
import com.fr.data.driver.config.DriverLoaderConfig;
import com.fr.data.impl.JDBCDatabaseConnection;
import com.fr.data.solution.entity.DriverClasses;
import com.fr.design.border.UITitledBorder;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icombobox.UIComboBoxUI;
@ -28,6 +30,7 @@ import com.fr.third.guava.collect.HashBiMap;
import com.fr.workspace.WorkContext;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
@ -67,6 +70,7 @@ public class JDBCDefPane extends JPanel {
// 编码转换.
private String originalCharSet = null;
private static Map<String, DriverURLName[]> jdbcMap = new HashMap<String, DriverURLName[]>();
private JPanel linkPanel;
static {
jdbcMap.put(OTHER_DB, new DriverURLName[]{new DriverURLName("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:"),
@ -193,7 +197,9 @@ public class JDBCDefPane extends JPanel {
userNameTextField = new UITextField(15);
userNameTextField.setName(USER_NAME);
passwordTextField = new UIPasswordFieldWithFixedLength(15);
dbtypeButton = new UIButton(".");
dbtypeButton = new UIButton();
dbtypeButton.setIcon(new ImageIcon(UIConstants.ACCESSIBLE_EDITOR_DOT));
dbtypeButton.setPreferredSize(new Dimension(20, 20));
dbtypeButton.setToolTipText(Toolkit.i18nText("Fine-Design_Basic_Click_Get_Default_URL"));
dbtypeButton.addActionListener(dbtypeButtonActionListener);
@ -477,11 +483,16 @@ public class JDBCDefPane extends JPanel {
}
ActionListener driverListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
linkPanel.setVisible(DriverClasses.MYSQL.toString().equalsIgnoreCase((String) dbtypeComboBox.getSelectedItem())
&& driverComboBox.getSelectedItem() != null
&& ComparatorUtils.equals(DriverClasses.MYSQL.getDriverClass(), driverComboBox.getSelectedItem().toString().trim()));
odbcTipsLink.setVisible(driverComboBox.getSelectedItem() != null
&& ComparatorUtils.equals("sun.jdbc.odbc.JdbcOdbcDriver", driverComboBox.getSelectedItem().toString().trim())); // 选择的如果是ODBC就显示提示
if (driverComboBox.getSelectedItem() == null || ComparatorUtils.equals(driverComboBox.getSelectedItem(), StringUtils.EMPTY)) {
return;
}
odbcTipsLink.setVisible(ComparatorUtils.equals("sun.jdbc.odbc.JdbcOdbcDriver", driverComboBox.getSelectedItem())); // 选择的如果是ODBC就显示提示
Iterator<Entry<String, DriverURLName[]>> jdbc = jdbcMap.entrySet().iterator();
while (jdbc.hasNext()) {
Entry<String, DriverURLName[]> entry = jdbc.next();
@ -494,7 +505,6 @@ public class JDBCDefPane extends JPanel {
}
}
}
};
ActionListener dbtypeButtonActionListener = new ActionListener() {
@ -738,4 +748,7 @@ public class JDBCDefPane extends JPanel {
}
public void addLinkPane(JPanel panel) {
linkPanel = panel;
}
}

301
designer-base/src/main/java/com/fr/design/data/datapane/connect/SshPane.java

@ -0,0 +1,301 @@
package com.fr.design.data.datapane.connect;
import com.fr.data.impl.JDBCDatabaseConnection;
import com.fr.data.security.ssh.BaseSsh;
import com.fr.data.security.ssh.Ssh;
import com.fr.data.security.ssh.SshException;
import com.fr.data.security.ssh.SshType;
import com.fr.data.security.ssh.impl.KeyVerifySsh;
import com.fr.data.security.ssh.impl.NormalSsh;
import com.fr.design.border.UITitledBorder;
import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.BasicPane;
import com.fr.design.editor.editor.NotNegativeIntegerEditor;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ipasswordfield.UIPasswordFieldWithFixedLength;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.file.FILE;
import com.fr.file.FILEChooserPane;
import com.fr.file.filter.ChooseFileFilter;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.third.guava.collect.HashBiMap;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.fr.design.i18n.Toolkit.i18nText;
/**
* @author xiqiu
* @date 2021/12/23
* @description
*/
public class SshPane extends BasicPane {
private static HashBiMap<String, SshType> typeMap;
static {
typeMap = HashBiMap.create();
typeMap.put(Toolkit.i18nText("Fine-Design_Basic_Password"), SshType.NORMAL);
typeMap.put(Toolkit.i18nText("Fine-Design_Basic_Ssh_Public_Key"), SshType.KEY);
}
private UICheckBox usingSsh = new UICheckBox(i18nText("Fine-Design_Basic_Ssh_Using"));
private NotNegativeIntegerEditor port = new NotNegativeIntegerEditor(20);
private UITextField ip = new UITextField(20);
private UIComboBox type = new UIComboBox();
private UITextField user = new UITextField(20);
private JPasswordField password = new UIPasswordFieldWithFixedLength(20);
private JPasswordField secret = new UIPasswordFieldWithFixedLength(20);
private KeyFileUITextField keyPath = new KeyFileUITextField(18);
private JPanel contextPane;
private Component[][] passwordComps;
private Component[][] keyComps;
private double p = TableLayout.PREFERRED;
private double f = TableLayout.FILL;
private JPanel jPanel;
private UIButton fileChooserButton = new UIButton();
private double[] columnSize = new double[]{195, p};
public SshPane() {
fileChooserButton.setIcon(new ImageIcon(UIConstants.ACCESSIBLE_EDITOR_DOT));
this.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Basic_Ssh_Settings")));
this.setLayout(FRGUIPaneFactory.createLabelFlowLayout());
typeMap.keySet().forEach(key -> type.addItem(key));
type.setSelectedItem(typeMap.inverse().get(SshType.KEY));
jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
fileChooserButton.setPreferredSize(new Dimension(20, 20));
type.setEditable(false);
type.setSelectedItem(Toolkit.i18nText("Fine-Design_Basic_Ssh_Private_Key"));
JPanel filePanel = TableLayoutHelper.createCommonTableLayoutPane(new Component[][]{{keyPath, fileChooserButton}}, new double[]{p}, new double[]{f, 20}, 0);
Component[] compIp = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Host") + ":", SwingConstants.RIGHT), ip};
Component[] compPort = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Port") + ":", SwingConstants.RIGHT), port};
Component[] compUserName = {new UILabel(Toolkit.i18nText("Fine-Design_Report_UserName") + ":", SwingConstants.RIGHT), user};
Component[] compMethod = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssh_Verify_Method") + ":", SwingConstants.RIGHT), type};
Component[] compPassword = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Password") + ":", SwingConstants.RIGHT), password};
Component[] compKey = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssh_Private_Key") + ":", SwingConstants.RIGHT), filePanel};
Component[] comSecret = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssh_Secret") + ":", SwingConstants.RIGHT), secret};
passwordComps = new Component[][]{
compIp,
compPort,
compUserName,
compMethod,
compPassword
};
keyComps = new Component[][]{
compIp,
compPort,
compUserName,
compMethod,
compKey,
comSecret
};
usingSsh.setSelected(true);
contextPane = TableLayoutHelper.createGapTableLayoutPane(keyComps, new double[]{p, p, p, p, p, p}, columnSize, 11, 11);
jPanel.add(usingSsh, BorderLayout.NORTH);
jPanel.add(contextPane, BorderLayout.CENTER);
this.add(jPanel);
usingSsh.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changePane();
}
});
type.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changePaneForType();
}
});
fileChooserButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
FILEChooserPane fileChooser = FILEChooserPane.getInstanceWithDesignatePath(ProjectConstants.RESOURCES_NAME, new ChooseFileFilter(true));
int type = fileChooser.showOpenDialog(SshPane.this, StringUtils.EMPTY);
if (type == FILEChooserPane.OK_OPTION) {
final FILE file = fileChooser.getSelectedFILE();
if (file == null) {
keyPath.setText(StringUtils.EMPTY);
} else {
keyPath.setText(file.getPath());
}
}
fileChooser.removeAllFilter();
}
});
}
private void changePane() {
contextPane.setVisible(usingSsh.isSelected());
}
private void changePaneForType() {
contextPane.removeAll();
switch (typeMap.get(type.getSelectedItem())) {
case NORMAL:
TableLayoutHelper.addComponent2ResultPane(passwordComps, new double[]{p, p, p, p, p}, columnSize, contextPane);
break;
case KEY:
TableLayoutHelper.addComponent2ResultPane(keyComps, new double[]{p, p, p, p, p, p}, columnSize, contextPane);
break;
default:
throw new SshException("un support ssh type");
}
jPanel.revalidate();
jPanel.repaint();
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Basic_Ssh_Settings");
}
public void populate(JDBCDatabaseConnection jdbcDatabase) {
if (jdbcDatabase.getSsh() == null) {
jdbcDatabase.setSsh(new NormalSsh());
}
Ssh ssh = jdbcDatabase.getSsh();
switch (ssh.getSshType()) {
case KEY:
type.setSelectedItem(typeMap.inverse().get(ssh.getSshType()));
KeyVerifySsh keyVerifySsh = (KeyVerifySsh) ssh;
keyPath.setText(keyVerifySsh.getPrivateKeyPath());
secret.setText(keyVerifySsh.getSecret());
password.setText(StringUtils.EMPTY);
setCommonConfig(keyVerifySsh);
break;
case NORMAL:
type.setSelectedItem(typeMap.inverse().get(ssh.getSshType()));
NormalSsh normalSsh = (NormalSsh) ssh;
password.setText(normalSsh.getSecret());
keyPath.setText(StringUtils.EMPTY);
secret.setText(StringUtils.EMPTY);
setCommonConfig(normalSsh);
break;
default:
throw new SshException("un support ssh type");
}
usingSsh.setSelected(ssh.isUsingSsh());
changePane();
}
private void setCommonConfig(BaseSsh baseSsh) {
ip.setText(baseSsh.getIp());
port.setValue(baseSsh.getPort());
user.setText(baseSsh.getUser());
}
public void update(JDBCDatabaseConnection jdbcDatabase) {
Ssh ssh;
switch (typeMap.get(type.getSelectedItem())) {
case NORMAL:
NormalSsh normalSsh = new NormalSsh();
normalSsh.setSecret(new String(password.getPassword()).trim());
getCommonConfig(normalSsh);
ssh = normalSsh;
break;
case KEY:
KeyVerifySsh keyVerifySsh = new KeyVerifySsh();
keyVerifySsh.setPrivateKeyPath(keyPath.getText().trim());
keyVerifySsh.setSecret(new String(secret.getPassword()).trim());
getCommonConfig(keyVerifySsh);
ssh = keyVerifySsh;
break;
default:
throw new SshException("un support ssh type");
}
jdbcDatabase.setSsh(ssh);
}
private void getCommonConfig(BaseSsh baseSsh) {
baseSsh.setUsingSsh(usingSsh.isSelected());
baseSsh.setIp(ip.getText().trim());
baseSsh.setPort(port.getValue());
baseSsh.setUser(user.getText().trim());
}
public static class KeyFileUITextField extends UITextField {
private static final Pattern ERROR_START = Pattern.compile("^([/\\\\.]+).*");
private static final Pattern MUTI_DOT = Pattern.compile("\\.+");
private static final String PREFIX = ProjectConstants.RESOURCES_NAME + "/";
private static final String UPPER = "..";
public KeyFileUITextField(int columns) {
this();
this.setColumns(columns);
}
public KeyFileUITextField() {
super();
this.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
String text = KeyFileUITextField.this.getTextOrigin();
if (!StringUtils.isEmpty(text)) {
if (text.contains(UPPER)) {
text = MUTI_DOT.matcher(text).replaceAll(".");
KeyFileUITextField.this.setTextOrigin(text);
}
Matcher matcher = ERROR_START.matcher(text);
if (matcher.matches()) {
text = text.substring(matcher.group(1).length());
KeyFileUITextField.this.setTextOrigin(text);
}
}
}
});
}
public String getTextOrigin() {
return super.getText();
}
public void setTextOrigin(String text) {
super.setText(text);
}
@Override
public String getText() {
// 获取的时候,不为空,给他加上前缀就好了,否则还是空
if (!StringUtils.isEmpty(super.getText())) {
return PREFIX + super.getText();
}
return StringUtils.EMPTY;
}
@Override
public void setText(String text) {
// 设置的时候,不为空,说明文件指定了(文件需要是resource下),替换掉前缀
if (!StringUtils.isEmpty(text) && text.startsWith(PREFIX)) {
super.setText(text.replaceFirst(PREFIX, ""));
} else {
super.setText(text);
}
}
}
}

164
designer-base/src/main/java/com/fr/design/data/datapane/connect/SslPane.java

@ -0,0 +1,164 @@
package com.fr.design.data.datapane.connect;
import com.fr.data.impl.JDBCDatabaseConnection;
import com.fr.data.security.ssl.Ssl;
import com.fr.data.security.ssl.SslException;
import com.fr.data.security.ssl.SslType;
import com.fr.data.security.ssl.impl.NormalSsl;
import com.fr.design.border.UITitledBorder;
import com.fr.design.constants.UIConstants;
import com.fr.design.data.datapane.connect.SshPane.KeyFileUITextField;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.file.FILE;
import com.fr.file.FILEChooserPane;
import com.fr.file.filter.ChooseFileFilter;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import static com.fr.design.i18n.Toolkit.i18nText;
/**
* @author xiqiu
* @date 2022/1/4
* @description
*/
public class SslPane extends BasicPane {
UICheckBox usingSsl = new UICheckBox(i18nText("Fine-Design_Basic_Ssl_Using"));
private KeyFileUITextField keyPathCa = new KeyFileUITextField(18);
private UIButton fileChooserButtonCa = new UIButton();
private KeyFileUITextField keyPathClientCert = new KeyFileUITextField(18);
private UIButton fileChooserButtonClientCert = new UIButton();
private KeyFileUITextField keyPathClientKey = new KeyFileUITextField(18);
private UIButton fileChooserButtonClientKey = new UIButton();
private UICheckBox verifyCa = new UICheckBox(i18nText("Fine-Design_Basic_Ssl_Verify_Ca"));
// private UITextField cipher = new UITextField(20);
private JPanel jPanel;
private Component[][] usingComps;
private double p = TableLayout.PREFERRED;
private double f = TableLayout.FILL;
private JPanel contextPane;
private double[] columnSize = new double[]{195, p};
public SslPane() {
fileChooserButtonCa.setIcon(new ImageIcon(UIConstants.ACCESSIBLE_EDITOR_DOT));
fileChooserButtonClientCert.setIcon(new ImageIcon(UIConstants.ACCESSIBLE_EDITOR_DOT));
fileChooserButtonClientKey.setIcon(new ImageIcon(UIConstants.ACCESSIBLE_EDITOR_DOT));
this.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Basic_Ssl_Settings")));
this.setLayout(FRGUIPaneFactory.createLabelFlowLayout());
jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
Dimension dimension = new Dimension(20, 20);
fileChooserButtonCa.setPreferredSize(dimension);
fileChooserButtonClientCert.setPreferredSize(dimension);
fileChooserButtonClientKey.setPreferredSize(dimension);
JPanel filePanelCa = TableLayoutHelper.createCommonTableLayoutPane(new Component[][]{{keyPathCa, fileChooserButtonCa}}, new double[]{p}, new double[]{f, 20}, 0);
Component[] compCa = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssl_Ca") + ":", SwingConstants.RIGHT), filePanelCa};
Component[] compVerifyCa = {null, verifyCa};
JPanel filePanelClientCert = TableLayoutHelper.createCommonTableLayoutPane(new Component[][]{{keyPathClientCert, fileChooserButtonClientCert}}, new double[]{p}, new double[]{f, 20}, 0);
Component[] compClientCert = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssl_Client_Cert") + ":", SwingConstants.RIGHT), filePanelClientCert};
JPanel filePanelClientKey = TableLayoutHelper.createCommonTableLayoutPane(new Component[][]{{keyPathClientKey, fileChooserButtonClientKey}}, new double[]{p}, new double[]{f, 20}, 0);
Component[] compClientKey = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssl_Client_Key") + ":", SwingConstants.RIGHT), filePanelClientKey};
// Component[] comCipher = {new UILabel(Toolkit.i18nText("Fine-Design_Basic_Ssl_Cipher") + ":", SwingConstants.RIGHT), cipher};
usingComps = new Component[][]{
compCa,
compVerifyCa,
compClientCert,
compClientKey,
// comCipher
};
usingSsl.setSelected(true);
contextPane = TableLayoutHelper.createGapTableLayoutPane(usingComps, new double[]{p, p, p, p}, columnSize, 11, 11);
jPanel.add(usingSsl, BorderLayout.NORTH);
jPanel.add(contextPane, BorderLayout.CENTER);
this.add(jPanel);
usingSsl.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changePane();
}
});
fileChooserButtonCa.addActionListener(new TextFieldActionListener(keyPathCa));
fileChooserButtonClientCert.addActionListener(new TextFieldActionListener(keyPathClientCert));
fileChooserButtonClientKey.addActionListener(new TextFieldActionListener(keyPathClientKey));
}
private void changePane() {
contextPane.setVisible(usingSsl.isSelected());
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Basic_Ssl_Settings");
}
public void populate(JDBCDatabaseConnection jdbcDatabase) {
Ssl ssl = jdbcDatabase.getSsl();
if (ssl == null) {
ssl = new NormalSsl();
jdbcDatabase.setSsl(ssl);
}
if (ssl.getSslType() == SslType.NORMAL) {
NormalSsl normalSsl = (NormalSsl) ssl;
keyPathCa.setText(normalSsl.getCaCertificate());
keyPathClientCert.setText(normalSsl.getClientCertificate());
keyPathClientKey.setText(normalSsl.getClientPrivateKey());
verifyCa.setSelected(normalSsl.isVerifyCa());
// cipher.setText(normalSsl.getCipher());
} else {
throw new SslException("un support ssl type");
}
usingSsl.setSelected(ssl.isUsingSsl());
changePane();
}
public void update(JDBCDatabaseConnection jdbcDatabase) {
NormalSsl normalSsl = new NormalSsl();
// normalSsl.setCipher(cipher.getText().trim());
normalSsl.setVerifyCa(verifyCa.isSelected());
normalSsl.setCaCertificate(keyPathCa.getText().trim());
normalSsl.setClientCertificate(keyPathClientCert.getText().trim());
normalSsl.setClientPrivateKey(keyPathClientKey.getText().trim());
normalSsl.setUsingSsl(usingSsl.isSelected());
jdbcDatabase.setSsl(normalSsl);
}
private class TextFieldActionListener implements ActionListener {
private UITextField textField;
public TextFieldActionListener(UITextField textField) {
this.textField = textField;
}
@Override
public void actionPerformed(ActionEvent e) {
FILEChooserPane fileChooser = FILEChooserPane.getInstanceWithDesignatePath(ProjectConstants.RESOURCES_NAME, new ChooseFileFilter(true));
int type = fileChooser.showOpenDialog(SslPane.this, StringUtils.EMPTY);
if (type == FILEChooserPane.OK_OPTION) {
final FILE file = fileChooser.getSelectedFILE();
if (file == null) {
textField.setText(StringUtils.EMPTY);
} else {
textField.setText(file.getPath());
}
}
fileChooser.removeAllFilter();
}
}
}

15
designer-base/src/main/java/com/fr/design/deeplink/DeepLink.java

@ -0,0 +1,15 @@
package com.fr.design.deeplink;
import java.util.Map;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2022/1/6
*/
public abstract class DeepLink {
public abstract boolean accept(String url, String host, String path, Map<String, Object> params);
public abstract void run(String url, String host, String path, Map<String, Object> params);
}

184
designer-base/src/main/java/com/fr/design/deeplink/DeepLinkCore.java

@ -0,0 +1,184 @@
package com.fr.design.deeplink;
import com.fr.design.constants.DesignerLaunchStatus;
import com.fr.design.startup.FineStartupNotificationFactory;
import com.fr.design.startup.FineStartupNotificationProvider;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
import com.fr.event.Null;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import com.fr.stable.os.OperatingSystem;
import com.fr.third.org.apache.http.NameValuePair;
import com.fr.web.URLUtils;
import javax.swing.SwingUtilities;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2022/1/6
*/
public class DeepLinkCore {
protected DeepLinkCore(){}
private static final DeepLinkCore instance = new DeepLinkCore();
public static DeepLinkCore getInstance(){
return instance;
}
private String pendingURL;
private final List<DeepLink> deepLinkList = new ArrayList<>();
private boolean isDesignerStartupCompleted = false;
public void register(DeepLink deepLink) {
if (deepLink != null) {
deepLinkList.add(deepLink);
}
}
public void start(String[] args) {
if (OperatingSystem.isWindows()) {
if (args.length > 0) {
receiveDeeplink(args[0]);
}
}
if (OperatingSystem.isWindows() && args.length > 0) {
receiveDeeplink(args[0]);
}
FineStartupNotificationFactory.getNotification()
.registerStartupListener(new FineStartupNotificationProvider.Listener() {
@Override
public void startupPerformed(String parameters) {
receiveDeeplink(parameters);
}
});
EventDispatcher.listen(DesignerLaunchStatus.STARTUP_COMPLETE, new Listener<Null>() {
@Override
public void on(Event event, Null param) {
EventDispatcher.stopListen(this);
isDesignerStartupCompleted = true;
if (canConsumePendingURL()) {
consumePendingURL();
}
}
});
}
public void receiveDeeplink(String url) {
if (canAcceptNewURL()) {
acceptNewURL(url);
if (canConsumePendingURL()) {
consumePendingURL();
}
}
}
public void receiveDeeplink2(String url) {
if (canAcceptNewURL()) {
acceptNewURL(url);
if (canConsumePendingURL()) {
consumePendingURL();
} else {
Frame frame = new Frame("can not ConsumePendingURL");
frame.setSize(400, 400);
frame.setBackground(Color.BLACK);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
frame.dispose();
}
});
frame.setVisible(true);
}
} else {
Frame frame = new Frame("can not AcceptNewURL");
frame.setSize(400, 400);
frame.setBackground(Color.BLACK);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
frame.dispose();
}
});
frame.setVisible(true);
}
}
private boolean canAcceptNewURL() {
return StringUtils.isEmpty(this.pendingURL);
}
private void acceptNewURL(String url) {
this.pendingURL = url;
}
private boolean canConsumePendingURL() {
return StringUtils.isNotEmpty(this.pendingURL) && isDesignerStartupCompleted;
}
private void consumePendingURL() {
String host = null;
String path = null;
Map<String, Object> params = new HashMap<>();
URL url = null;
try {
url = new URL(null, this.pendingURL, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
return null;
}
});
} catch (MalformedURLException ignored) {}
if (url != null) {
host = url.getHost();
path = url.getPath();
List<NameValuePair> pairs = URLUtils.parse(url.getQuery());
for (NameValuePair pair: pairs) {
params.put(pair.getName(), pair.getValue());
}
}
FineLoggerFactory.getLogger().info("consume deep link: " + this.pendingURL);
performDeepLinks(this.pendingURL, host, path, params);
markPendingURLConsumed();
}
private void performDeepLinks(String url, String host, String path, Map<String, Object> params) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeepLink deepLink: deepLinkList) {
if (deepLink.accept(url, host, path, params)) {
deepLink.run(url, host, path, params);
}
}
}
});
}
private void markPendingURLConsumed() {
this.pendingURL = null;
}
}

33
designer-base/src/main/java/com/fr/design/editor/editor/NotNegativeIntegerEditor.java

@ -0,0 +1,33 @@
package com.fr.design.editor.editor;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
/**
* @author xiqiu
* @date 2022/1/10
* @description 一个简单的非负整数框
*/
public class NotNegativeIntegerEditor extends IntegerEditor {
private static final String NEG = "-";
public NotNegativeIntegerEditor(int columns) {
this();
this.setColumns(columns);
}
public NotNegativeIntegerEditor() {
super();
this.numberField.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent evt) {
char keyChar = evt.getKeyChar();
if (NEG.equals(keyChar + "")) {
numberField.setText(numberField.getTextValue().replace(NEG, ""));
}
}
});
}
}

10
designer-base/src/main/java/com/fr/design/formula/FormulaPane.java

@ -16,6 +16,7 @@ import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.autocomplete.AutoCompleteExtraRefreshComponent;
import com.fr.design.gui.autocomplete.CompletionCellRenderer;
import com.fr.design.gui.autocomplete.CompletionProvider;
import com.fr.design.gui.autocomplete.DefaultCompletionProvider;
@ -416,7 +417,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
autoCompletion = new FormulaPaneAutoCompletion(provider);
autoCompletion.setListCellRenderer(new CompletionCellRenderer());
autoCompletion.install(formulaTextArea);
autoCompletion.installVariableTree(variableTreeAndDescriptionArea);
autoCompletion.installExtraRefreshComponent(variableTreeAndDescriptionArea);
}
@ -1044,7 +1045,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
}
}
public class VariableTreeAndDescriptionArea extends JPanel {
public class VariableTreeAndDescriptionArea extends JPanel implements AutoCompleteExtraRefreshComponent {
private JTree variablesTree;
private UITextArea descriptionTextArea;
@ -1285,6 +1286,11 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
functionTypeList.setSelectedIndex(0);
}
@Override
public void refresh(String replacementText) {
refreshText(replacementText);
}
/*
* 查看函数的详细信息
*/

2
designer-base/src/main/java/com/fr/design/formula/exception/function/MismatchedTokenFunction.java

@ -90,6 +90,8 @@ public class MismatchedTokenFunction implements Function<Exception, FormulaCheck
private String tokenName(int tokenType, MismatchedTokenException exception) {
if (tokenType == 0) {
return "<Set of tokens>";
} else if (tokenType == 33 || tokenType == 26 || tokenType == 31) {
return Toolkit.i18nText("Fine-Design_Basic_Formula_Right_Closing_Symbol");
} else {
String[] tokenNames = (String[]) getFieldValue(exception, "tokenNames");
return tokenType >= 0 && tokenType < tokenNames.length ? TranslateTokenUtils.translateToken(tokenNames[tokenType]) : "<" + tokenType + ">";

5
designer-base/src/main/java/com/fr/design/gui/autocomplete/AutoCompleteExtraRefreshComponent.java

@ -0,0 +1,5 @@
package com.fr.design.gui.autocomplete;
public interface AutoCompleteExtraRefreshComponent {
void refresh(String replacementText);
}

982
designer-base/src/main/java/com/fr/design/gui/autocomplete/AutoCompleteWithExtraRefreshPopupWindow.java

@ -0,0 +1,982 @@
package com.fr.design.gui.autocomplete;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.PopupWindowDecorator;
import com.fr.log.FineLoggerFactory;
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JWindow;
import javax.swing.KeyStroke;
import javax.swing.ListCellRenderer;
import javax.swing.SwingUtilities;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.ListUI;
import javax.swing.text.Caret;
import javax.swing.text.JTextComponent;
public abstract class AutoCompleteWithExtraRefreshPopupWindow extends JWindow implements CaretListener,
ListSelectionListener, MouseListener {
private final static int DIS = 5;
/**
* The parent AutoCompletion instance.
*/
private AutoCompletion ac;
/**
* The list of completion choices.
*/
private JList list;
/**
* The contents of {@link #list()}.
*/
private CompletionListModel model;
/**
* A hack to work around the fact that we clear our completion model (and
* our selection) when hiding the completion window. This allows us to
* still know what the user selected after the popup is hidden.
*/
private Completion lastSelection;
/**
* Optional popup window containing a description of the currently
* selected completion.
*/
private AutoCompleteDescWindow descWindow;
/**
* The preferred size of the optional description window. This field
* only exists because the user may (and usually will) set the size of
* the description window before it exists (it must be parented to a
* Window).
*/
private Dimension preferredDescWindowSize;
/**
* Whether the completion window and the optional description window
* should be displayed above the current caret position (as opposed to
* underneath it, which is preferred unless there is not enough space).
*/
private boolean aboveCaret;
private int lastLine;
private KeyActionPair escapeKap;
private KeyActionPair upKap;
private KeyActionPair downKap;
private KeyActionPair leftKap;
private KeyActionPair rightKap;
private KeyActionPair enterKap;
private KeyActionPair tabKap;
private KeyActionPair homeKap;
private KeyActionPair endKap;
private KeyActionPair pageUpKap;
private KeyActionPair pageDownKap;
private KeyActionPair ctrlCKap;
private KeyActionPair oldEscape, oldUp, oldDown, oldLeft, oldRight,
oldEnter, oldTab, oldHome, oldEnd, oldPageUp, oldPageDown,
oldCtrlC;
/**
* The space between the caret and the completion popup.
*/
private static final int VERTICAL_SPACE = 1;
/**
* The class name of the Substance List UI.
*/
private static final String SUBSTANCE_LIST_UI =
"org.pushingpixels.substance.internal.ui.SubstanceListUI";
protected AutoCompleteExtraRefreshComponent component;
/**
* Constructor.
*
* @param parent The parent window (hosting the text component).
* @param ac The auto-completion instance.
*/
public AutoCompleteWithExtraRefreshPopupWindow(Window parent, final AutoCompletion ac) {
super(parent);
ComponentOrientation o = ac.getTextComponentOrientation();
this.ac = ac;
model = new CompletionListModel();
list = new PopupList(model);
list.setCellRenderer(new DelegatingCellRenderer());
list.addListSelectionListener(this);
list.addMouseListener(this);
JPanel contentPane = new JPanel(new BorderLayout());
JScrollPane sp = new JScrollPane(list,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// In 1.4, JScrollPane.setCorner() has a bug where it won't accept
// JScrollPane.LOWER_TRAILING_CORNER, even though that constant is
// defined. So we have to put the logic added in 1.5 to handle it
// here.
JPanel corner = new SizeGrip();
//sp.setCorner(JScrollPane.LOWER_TRAILING_CORNER, corner);
boolean isLeftToRight = o.isLeftToRight();
String str = isLeftToRight ? JScrollPane.LOWER_RIGHT_CORNER :
JScrollPane.LOWER_LEFT_CORNER;
sp.setCorner(str, corner);
contentPane.add(sp);
setContentPane(contentPane);
applyComponentOrientation(o);
// Give apps a chance to decorate us with drop shadows, etc.
if (Util.getShouldAllowDecoratingMainAutoCompleteWindows()) {
PopupWindowDecorator decorator = PopupWindowDecorator.get();
if (decorator != null) {
decorator.decorate(this);
}
}
pack();
setFocusableWindowState(false);
lastLine = -1;
}
public void caretUpdate(CaretEvent e) {
if (isVisible()) { // Should always be true
int line = ac.getLineOfCaret();
if (line != lastLine) {
lastLine = -1;
setVisible(false);
} else {
doAutocomplete();
}
} else if (AutoCompletion.isDebug()) {
Thread.dumpStack();
}
}
/**
* Creates the description window.
*
* @return The description window.
*/
private AutoCompleteDescWindow createDescriptionWindow() {
AutoCompleteDescWindow dw = new AutoCompleteDescWindow(this, ac);
dw.applyComponentOrientation(ac.getTextComponentOrientation());
Dimension size = preferredDescWindowSize;
if (size == null) {
size = getSize();
}
dw.setSize(size);
return dw;
}
/**
* Creates the mappings from keys to Actions we'll be putting into the
* text component's ActionMap and InputMap.
*/
private void createKeyActionPairs() {
// Actions we'll install.
EnterAction enterAction = new EnterAction();
escapeKap = new KeyActionPair("Escape", new EscapeAction());
upKap = new KeyActionPair("Up", new UpAction());
downKap = new KeyActionPair("Down", new DownAction());
leftKap = new KeyActionPair("Left", new LeftAction());
rightKap = new KeyActionPair("Right", new RightAction());
enterKap = new KeyActionPair("Enter", enterAction);
tabKap = new KeyActionPair("Tab", enterAction);
homeKap = new KeyActionPair("Home", new HomeAction());
endKap = new KeyActionPair("End", new EndAction());
pageUpKap = new KeyActionPair("PageUp", new PageUpAction());
pageDownKap = new KeyActionPair("PageDown", new PageDownAction());
ctrlCKap = new KeyActionPair("CtrlC", new CopyAction());
// Buffers for the actions we replace.
oldEscape = new KeyActionPair();
oldUp = new KeyActionPair();
oldDown = new KeyActionPair();
oldLeft = new KeyActionPair();
oldRight = new KeyActionPair();
oldEnter = new KeyActionPair();
oldTab = new KeyActionPair();
oldHome = new KeyActionPair();
oldEnd = new KeyActionPair();
oldPageUp = new KeyActionPair();
oldPageDown = new KeyActionPair();
oldCtrlC = new KeyActionPair();
}
protected void doAutocomplete() {
lastLine = ac.refreshPopupWindow();
}
/**
* Returns the copy keystroke to use for this platform.
*
* @return The copy keystroke.
*/
private static final KeyStroke getCopyKeyStroke() {
int key = KeyEvent.VK_C;
int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
return KeyStroke.getKeyStroke(key, mask);
}
/**
* Returns the default list cell renderer used when a completion provider
* does not supply its own.
*
* @return The default list cell renderer.
* @see #setListCellRenderer(ListCellRenderer)
*/
public ListCellRenderer getListCellRenderer() {
DelegatingCellRenderer dcr = (DelegatingCellRenderer) list.
getCellRenderer();
return dcr.getFallbackCellRenderer();
}
/**
* Returns the selected value, or <code>null</code> if nothing is selected.
*
* @return The selected value.
*/
public Completion getSelection() {
return isShowing() ? (Completion) list.getSelectedValue() : lastSelection;
}
/**
* Inserts the currently selected completion.
*
* @see #getSelection()
*/
private void insertSelectedCompletion() {
Completion comp = getSelection();
ac.insertCompletion(comp);
}
public void installComp(AutoCompleteExtraRefreshComponent component){
this.component = component;
}
public void refreshInstallComp() {
component.refresh(getSelection().getReplacementText());
}
/**
* Registers keyboard actions to listen for in the text component and
* intercept.
*
* @see #uninstallKeyBindings()
*/
private void installKeyBindings() {
if (AutoCompletion.isDebug()) {
FineLoggerFactory.getLogger().debug("PopupWindow: Installing keybindings");
}
if (escapeKap == null) { // Lazily create actions.
createKeyActionPairs();
}
JTextComponent comp = ac.getTextComponent();
InputMap im = comp.getInputMap();
ActionMap am = comp.getActionMap();
replaceAction(im, am, KeyEvent.VK_ESCAPE, escapeKap, oldEscape);
if (AutoCompletion.isDebug() && oldEscape.action == escapeKap.action) {
Thread.dumpStack();
}
replaceAction(im, am, KeyEvent.VK_UP, upKap, oldUp);
replaceAction(im, am, KeyEvent.VK_LEFT, leftKap, oldLeft);
replaceAction(im, am, KeyEvent.VK_DOWN, downKap, oldDown);
replaceAction(im, am, KeyEvent.VK_RIGHT, rightKap, oldRight);
replaceAction(im, am, KeyEvent.VK_ENTER, enterKap, oldEnter);
replaceAction(im, am, KeyEvent.VK_TAB, tabKap, oldTab);
replaceAction(im, am, KeyEvent.VK_HOME, homeKap, oldHome);
replaceAction(im, am, KeyEvent.VK_END, endKap, oldEnd);
replaceAction(im, am, KeyEvent.VK_PAGE_UP, pageUpKap, oldPageUp);
replaceAction(im, am, KeyEvent.VK_PAGE_DOWN, pageDownKap, oldPageDown);
// Make Ctrl+C copy from description window. This isn't done
// automagically because the desc. window is not focusable, and copying
// from text components can only be done from focused components.
KeyStroke ks = getCopyKeyStroke();
oldCtrlC.key = im.get(ks);
im.put(ks, ctrlCKap.key);
oldCtrlC.action = am.get(ctrlCKap.key);
am.put(ctrlCKap.key, ctrlCKap.action);
comp.addCaretListener(this);
}
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && e.getButton() == 1) {
insertSelectedCompletion();
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
refreshInstallComp();
}
public void mouseReleased(MouseEvent e) {
}
/**
* Positions the description window relative to the completion choices
* window. We assume there is room on one side of the other for this
* entire window to fit.
*/
private void positionDescWindow() {
boolean showDescWindow = descWindow != null && ac.isShowDescWindow();
if (!showDescWindow) {
return;
}
// Don't use getLocationOnScreen() as this throws an exception if
// window isn't visible yet, but getLocation() doesn't, and is in
// screen coordinates!
Point p = getLocation();
Rectangle screenBounds = Util.getScreenBoundsForPoint(p.x, p.y);
//Dimension screenSize = getToolkit().getScreenSize();
//int totalH = Math.max(getHeight(), descWindow.getHeight());
// Try to position to the right first (LTR)
int x;
if (ac.getTextComponentOrientation().isLeftToRight()) {
x = getX() + getWidth() + DIS;
if (x + descWindow.getWidth() > screenBounds.x + screenBounds.width) { // doesn't fit
x = getX() - DIS - descWindow.getWidth();
}
} else { // RTL
x = getX() - DIS - descWindow.getWidth();
if (x < screenBounds.x) { // Doesn't fit
x = getX() + getWidth() + DIS;
}
}
int y = getY();
if (aboveCaret) {
y = y + getHeight() - descWindow.getHeight();
}
if (x != descWindow.getX() || y != descWindow.getY()) {
descWindow.setLocation(x, y);
}
}
/**
* "Puts back" the original key/Action pair for a keystroke. This is used
* when this popup is hidden.
*
* @param im The input map.
* @param am The action map.
* @param key The keystroke whose key/Action pair to change.
* @param kap The (original) key/Action pair.
* @see #replaceAction(InputMap, ActionMap, int, KeyActionPair, KeyActionPair)
*/
private void putBackAction(InputMap im, ActionMap am, int key,
KeyActionPair kap) {
KeyStroke ks = KeyStroke.getKeyStroke(key, 0);
am.put(im.get(ks), kap.action); // Original action for the "new" key
im.put(ks, kap.key); // Original key for the keystroke.
}
/**
* Replaces a key/Action pair in an InputMap and ActionMap with a new
* pair.
*
* @param im The input map.
* @param am The action map.
* @param key The keystroke whose information to replace.
* @param kap The new key/Action pair for <code>key</code>.
* @param old A buffer in which to place the old key/Action pair.
* @see #putBackAction(InputMap, ActionMap, int, KeyActionPair)
*/
private void replaceAction(InputMap im, ActionMap am, int key,
KeyActionPair kap, KeyActionPair old) {
KeyStroke ks = KeyStroke.getKeyStroke(key, 0);
old.key = im.get(ks);
im.put(ks, kap.key);
old.action = am.get(kap.key);
am.put(kap.key, kap.action);
}
/**
* Selects the first item in the completion list.
*
* @see #selectLastItem()
*/
private void selectFirstItem() {
if (model.getSize() > 0) {
list.setSelectedIndex(0);
list.ensureIndexIsVisible(0);
}
}
/**
* Selects the last item in the completion list.
*
* @see #selectFirstItem()
*/
private void selectLastItem() {
int index = model.getSize() - 1;
if (index > -1) {
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
}
/**
* Selects the next item in the completion list.
*
* @see #selectPreviousItem()
*/
private void selectNextItem() {
int index = list.getSelectedIndex();
if (index > -1) {
index = (index + 1) % model.getSize();
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
}
/**
* Selects the completion item one "page down" from the currently selected
* one.
*
* @see #selectPageUpItem()
*/
private void selectPageDownItem() {
int visibleRowCount = list.getVisibleRowCount();
int i = Math.min(list.getModel().getSize() - 1,
list.getSelectedIndex() + visibleRowCount);
list.setSelectedIndex(i);
list.ensureIndexIsVisible(i);
}
/**
* Selects the completion item one "page up" from the currently selected
* one.
*
* @see #selectPageDownItem()
*/
private void selectPageUpItem() {
int visibleRowCount = list.getVisibleRowCount();
int i = Math.max(0, list.getSelectedIndex() - visibleRowCount);
list.setSelectedIndex(i);
list.ensureIndexIsVisible(i);
}
/**
* Selects the previous item in the completion list.
*
* @see #selectNextItem()
*/
private void selectPreviousItem() {
int index = list.getSelectedIndex();
switch (index) {
case 0:
index = list.getModel().getSize() - 1;
break;
case -1: // Check for an empty list (would be an error)
index = list.getModel().getSize() - 1;
if (index == -1) {
return;
}
break;
default:
index = index - 1;
break;
}
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
/**
* Sets the completions to display in the choices list. The first
* completion is selected.
*
* @param completions The completions to display.
*/
public void setCompletions(List<Completion> completions) {
model.setContents(completions);
selectFirstItem();
}
/**
* Sets the size of the description window.
*
* @param size The new size. This cannot be <code>null</code>.
*/
public void setDescriptionWindowSize(Dimension size) {
if (descWindow != null) {
descWindow.setSize(size);
} else {
preferredDescWindowSize = size;
}
}
/**
* Sets the default list cell renderer to use when a completion provider
* does not supply its own.
*
* @param renderer The renderer to use. If this is <code>null</code>,
* a default renderer is used.
* @see #getListCellRenderer()
*/
public void setListCellRenderer(ListCellRenderer renderer) {
DelegatingCellRenderer dcr = (DelegatingCellRenderer) list.
getCellRenderer();
dcr.setFallbackCellRenderer(renderer);
}
/**
* Sets the location of this window to be "good" relative to the specified
* rectangle. That rectangle should be the location of the text
* component's caret, in screen coordinates.
*
* @param r The text component's caret position, in screen coordinates.
*/
public void setLocationRelativeTo(Rectangle r) {
// Multi-monitor support - make sure the completion window (and
// description window, if applicable) both fit in the same window in
// a multi-monitor environment. To do this, we decide which monitor
// the rectangle "r" is in, and use that one (just pick top-left corner
// as the defining point).
Rectangle screenBounds = Util.getScreenBoundsForPoint(r.x, r.y);
//Dimension screenSize = getToolkit().getScreenSize();
boolean showDescWindow = descWindow != null && ac.isShowDescWindow();
int totalH = getHeight();
if (showDescWindow) {
totalH = Math.max(totalH, descWindow.getHeight());
}
// Try putting our stuff "below" the caret first. We assume that the
// entire height of our stuff fits on the screen one way or the other.
aboveCaret = false;
int y = r.y + r.height + VERTICAL_SPACE;
if (y + totalH > screenBounds.height) {
y = r.y - VERTICAL_SPACE - getHeight();
aboveCaret = true;
}
// Get x-coordinate of completions. Try to align left edge with the
// caret first.
int x = r.x;
if (!ac.getTextComponentOrientation().isLeftToRight()) {
x -= getWidth(); // RTL => align right edge
}
if (x < screenBounds.x) {
x = screenBounds.x;
} else if (x + getWidth() > screenBounds.x + screenBounds.width) { // completions don't fit
x = screenBounds.x + screenBounds.width - getWidth();
}
setLocation(x, y);
// Position the description window, if necessary.
if (showDescWindow) {
positionDescWindow();
}
}
/**
* Toggles the visibility of this popup window.
*
* @param visible Whether this window should be visible.
*/
@Override
public void setVisible(boolean visible) {
if (visible != isVisible()) {
if (visible) {
installKeyBindings();
lastLine = ac.getLineOfCaret();
selectFirstItem();
if (descWindow == null && ac.isShowDescWindow()) {
descWindow = createDescriptionWindow();
positionDescWindow();
}
// descWindow needs a kick-start the first time it's displayed.
// Also, the newly-selected item in the choices list is
// probably different from the previous one anyway.
if (descWindow != null) {
Completion c = (Completion) list.getSelectedValue();
if (c != null) {
descWindow.setDescriptionFor(c);
}
}
} else {
uninstallKeyBindings();
}
super.setVisible(visible);
// Some languages, such as Java, can use quite a lot of memory
// when displaying hundreds of completion choices. We pro-actively
// clear our list model here to make them available for GC.
// Otherwise, they stick around, and consider the following: a
// user starts code-completion for Java 5 SDK classes, then hides
// the dialog, then changes the "class path" to use a Java 6 SDK
// instead. On pressing Ctrl+space, a new array of Completions is
// created. If this window holds on to the previous Completions,
// you're getting roughly 2x the necessary Completions in memory
// until the Completions are actually passed to this window.
if (!visible) { // Do after super.setVisible(false)
lastSelection = (Completion) list.getSelectedValue();
model.clear();
}
// Must set descWindow's visibility one way or the other each time,
// because of the way child JWindows' visibility is handled - in
// some ways it's dependent on the parent, in other ways it's not.
if (descWindow != null) {
descWindow.setVisible(visible && ac.isShowDescWindow());
}
}
}
/**
* Stops intercepting certain keystrokes from the text component.
*
* @see #installKeyBindings()
*/
private void uninstallKeyBindings() {
if (AutoCompletion.isDebug()) {
FineLoggerFactory.getLogger().debug("PopupWindow: Removing keybindings");
}
JTextComponent comp = ac.getTextComponent();
InputMap im = comp.getInputMap();
ActionMap am = comp.getActionMap();
putBackAction(im, am, KeyEvent.VK_ESCAPE, oldEscape);
putBackAction(im, am, KeyEvent.VK_UP, oldUp);
putBackAction(im, am, KeyEvent.VK_DOWN, oldDown);
putBackAction(im, am, KeyEvent.VK_LEFT, oldLeft);
putBackAction(im, am, KeyEvent.VK_RIGHT, oldRight);
putBackAction(im, am, KeyEvent.VK_ENTER, oldEnter);
putBackAction(im, am, KeyEvent.VK_TAB, oldTab);
putBackAction(im, am, KeyEvent.VK_HOME, oldHome);
putBackAction(im, am, KeyEvent.VK_END, oldEnd);
putBackAction(im, am, KeyEvent.VK_PAGE_UP, oldPageUp);
putBackAction(im, am, KeyEvent.VK_PAGE_DOWN, oldPageDown);
// Ctrl+C
KeyStroke ks = getCopyKeyStroke();
am.put(im.get(ks), oldCtrlC.action); // Original action
im.put(ks, oldCtrlC.key); // Original key
comp.removeCaretListener(this);
}
/**
* Updates the <tt>LookAndFeel</tt> of this window and the description
* window.
*/
public void updateUI() {
SwingUtilities.updateComponentTreeUI(this);
if (descWindow != null) {
descWindow.updateUI();
}
}
/**
* Called when a new item is selected in the popup list.
*
* @param e The event.
*/
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
Object value = list.getSelectedValue();
if (value != null && descWindow != null) {
descWindow.setDescriptionFor((Completion) value);
positionDescWindow();
}
}
}
class CopyAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
boolean doNormalCopy = false;
if (descWindow != null && descWindow.isVisible()) {
doNormalCopy = !descWindow.copy();
}
if (doNormalCopy) {
ac.getTextComponent().copy();
}
}
}
class DownAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectNextItem();
refreshInstallComp();
}
}
}
class EndAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectLastItem();
}
}
}
class EnterAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
insertSelectedCompletion();
refreshInstallComp();
}
}
}
class EscapeAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
setVisible(false);
}
}
}
class HomeAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectFirstItem();
}
}
}
/**
* A mapping from a key (an Object) to an Action.
*/
private static class KeyActionPair {
public Object key;
public Action action;
public KeyActionPair() {
}
public KeyActionPair(Object key, Action a) {
this.key = key;
this.action = a;
}
}
class LeftAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
JTextComponent comp = ac.getTextComponent();
Caret c = comp.getCaret();
int dot = c.getDot();
if (dot > 0) {
c.setDot(--dot);
// Ensure moving left hasn't moved us up a line, thus
// hiding the popup window.
if (comp.isVisible()) {
if (lastLine != -1) {
doAutocomplete();
}
}
}
}
}
}
class PageDownAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectPageDownItem();
}
}
}
class PageUpAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectPageUpItem();
}
}
}
/**
* The actual list of completion choices in this popup window.
*/
private class PopupList extends JList {
public PopupList(CompletionListModel model) {
super(model);
}
@Override
public void setUI(ListUI ui) {
if (Util.getUseSubstanceRenderers() &&
SUBSTANCE_LIST_UI.equals(ui.getClass().getName())) {
// Substance requires its special ListUI be installed for
// its renderers to actually render (!), but long completion
// lists (e.g. PHPCompletionProvider in RSTALanguageSupport)
// will simply populate too slowly on initial display (when
// calculating preferred size of all items), so in this case
// we give a prototype cell value.
CompletionProvider p = ac.getCompletionProvider();
BasicCompletion bc = new BasicCompletion(p, "Hello world");
setPrototypeCellValue(bc);
} else {
// Our custom UI that is faster for long HTML completion lists.
ui = new FastListUI();
setPrototypeCellValue(null);
}
super.setUI(ui);
}
}
class RightAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
JTextComponent comp = ac.getTextComponent();
Caret c = comp.getCaret();
int dot = c.getDot();
if (dot < comp.getDocument().getLength()) {
c.setDot(++dot);
// Ensure moving right hasn't moved us up a line, thus
// hiding the popup window.
if (comp.isVisible()) {
if (lastLine != -1) {
doAutocomplete();
}
}
}
}
}
}
class UpAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectPreviousItem();
refreshInstallComp();
}
}
}
}

1260
designer-base/src/main/java/com/fr/design/gui/autocomplete/AutoCompletionWithExtraRefresh.java

File diff suppressed because it is too large Load Diff

976
designer-base/src/main/java/com/fr/design/gui/autocomplete/FormulaAutoCompletePopupWindow.java

@ -9,41 +9,7 @@
*/
package com.fr.design.gui.autocomplete;
import com.fr.design.formula.FormulaPane;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.PopupWindowDecorator;
import com.fr.log.FineLoggerFactory;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JWindow;
import javax.swing.KeyStroke;
import javax.swing.ListCellRenderer;
import javax.swing.SwingUtilities;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.ListUI;
import javax.swing.text.Caret;
import javax.swing.text.JTextComponent;
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
/**
* The actual popup window of choices. When visible, this window intercepts
@ -55,949 +21,11 @@ import java.util.List;
* @author Robert Futrell
* @version 1.0
*/
class FormulaAutoCompletePopupWindow extends JWindow implements CaretListener,
ListSelectionListener, MouseListener {
private final static int DIS = 5;
/**
* The parent AutoCompletion instance.
*/
private FormulaPaneAutoCompletion ac;
/**
* The list of completion choices.
*/
private JList list;
/**
* The contents of {@link #list()}.
*/
private CompletionListModel model;
/**
* A hack to work around the fact that we clear our completion model (and
* our selection) when hiding the completion window. This allows us to
* still know what the user selected after the popup is hidden.
*/
private Completion lastSelection;
/**
* Optional popup window containing a description of the currently
* selected completion.
*/
private AutoCompleteDescWindow descWindow;
/**
* The preferred size of the optional description window. This field
* only exists because the user may (and usually will) set the size of
* the description window before it exists (it must be parented to a
* Window).
*/
private Dimension preferredDescWindowSize;
private FormulaPane.VariableTreeAndDescriptionArea component;
/**
* Whether the completion window and the optional description window
* should be displayed above the current caret position (as opposed to
* underneath it, which is preferred unless there is not enough space).
*/
private boolean aboveCaret;
private int lastLine;
private KeyActionPair escapeKap;
private KeyActionPair upKap;
private KeyActionPair downKap;
private KeyActionPair leftKap;
private KeyActionPair rightKap;
private KeyActionPair enterKap;
private KeyActionPair tabKap;
private KeyActionPair homeKap;
private KeyActionPair endKap;
private KeyActionPair pageUpKap;
private KeyActionPair pageDownKap;
private KeyActionPair ctrlCKap;
private KeyActionPair oldEscape, oldUp, oldDown, oldLeft, oldRight,
oldEnter, oldTab, oldHome, oldEnd, oldPageUp, oldPageDown,
oldCtrlC;
/**
* The space between the caret and the completion popup.
*/
private static final int VERTICAL_SPACE = 1;
/**
* The class name of the Substance List UI.
*/
private static final String SUBSTANCE_LIST_UI =
"org.pushingpixels.substance.internal.ui.SubstanceListUI";
class FormulaAutoCompletePopupWindow extends AutoCompleteWithExtraRefreshPopupWindow {
/**
* Constructor.
*
* @param parent The parent window (hosting the text component).
* @param ac The auto-completion instance.
*/
public FormulaAutoCompletePopupWindow(Window parent, final FormulaPaneAutoCompletion ac) {
super(parent);
ComponentOrientation o = ac.getTextComponentOrientation();
this.ac = ac;
model = new CompletionListModel();
list = new PopupList(model);
list.setCellRenderer(new DelegatingCellRenderer());
list.addListSelectionListener(this);
list.addMouseListener(this);
JPanel contentPane = new JPanel(new BorderLayout());
JScrollPane sp = new JScrollPane(list,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
// In 1.4, JScrollPane.setCorner() has a bug where it won't accept
// JScrollPane.LOWER_TRAILING_CORNER, even though that constant is
// defined. So we have to put the logic added in 1.5 to handle it
// here.
JPanel corner = new SizeGrip();
//sp.setCorner(JScrollPane.LOWER_TRAILING_CORNER, corner);
boolean isLeftToRight = o.isLeftToRight();
String str = isLeftToRight ? JScrollPane.LOWER_RIGHT_CORNER :
JScrollPane.LOWER_LEFT_CORNER;
sp.setCorner(str, corner);
contentPane.add(sp);
setContentPane(contentPane);
applyComponentOrientation(o);
// Give apps a chance to decorate us with drop shadows, etc.
if (Util.getShouldAllowDecoratingMainAutoCompleteWindows()) {
PopupWindowDecorator decorator = PopupWindowDecorator.get();
if (decorator != null) {
decorator.decorate(this);
}
}
pack();
setFocusableWindowState(false);
lastLine = -1;
}
public void caretUpdate(CaretEvent e) {
if (isVisible()) { // Should always be true
int line = ac.getLineOfCaret();
if (line != lastLine) {
lastLine = -1;
setVisible(false);
} else {
doAutocomplete();
}
} else if (AutoCompletion.isDebug()) {
Thread.dumpStack();
}
}
/**
* Creates the description window.
*
* @return The description window.
*/
private AutoCompleteDescWindow createDescriptionWindow() {
AutoCompleteDescWindow dw = new AutoCompleteDescWindow(this, ac);
dw.applyComponentOrientation(ac.getTextComponentOrientation());
Dimension size = preferredDescWindowSize;
if (size == null) {
size = getSize();
}
dw.setSize(size);
return dw;
}
/**
* Creates the mappings from keys to Actions we'll be putting into the
* text component's ActionMap and InputMap.
*/
private void createKeyActionPairs() {
// Actions we'll install.
EnterAction enterAction = new EnterAction();
escapeKap = new KeyActionPair("Escape", new EscapeAction());
upKap = new KeyActionPair("Up", new UpAction());
downKap = new KeyActionPair("Down", new DownAction());
leftKap = new KeyActionPair("Left", new LeftAction());
rightKap = new KeyActionPair("Right", new RightAction());
enterKap = new KeyActionPair("Enter", enterAction);
tabKap = new KeyActionPair("Tab", enterAction);
homeKap = new KeyActionPair("Home", new HomeAction());
endKap = new KeyActionPair("End", new EndAction());
pageUpKap = new KeyActionPair("PageUp", new PageUpAction());
pageDownKap = new KeyActionPair("PageDown", new PageDownAction());
ctrlCKap = new KeyActionPair("CtrlC", new CopyAction());
// Buffers for the actions we replace.
oldEscape = new KeyActionPair();
oldUp = new KeyActionPair();
oldDown = new KeyActionPair();
oldLeft = new KeyActionPair();
oldRight = new KeyActionPair();
oldEnter = new KeyActionPair();
oldTab = new KeyActionPair();
oldHome = new KeyActionPair();
oldEnd = new KeyActionPair();
oldPageUp = new KeyActionPair();
oldPageDown = new KeyActionPair();
oldCtrlC = new KeyActionPair();
}
protected void doAutocomplete() {
lastLine = ac.refreshPopupWindow();
}
/**
* Returns the copy keystroke to use for this platform.
*
* @return The copy keystroke.
*/
private static final KeyStroke getCopyKeyStroke() {
int key = KeyEvent.VK_C;
int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
return KeyStroke.getKeyStroke(key, mask);
}
/**
* Returns the default list cell renderer used when a completion provider
* does not supply its own.
*
* @return The default list cell renderer.
* @see #setListCellRenderer(ListCellRenderer)
*/
public ListCellRenderer getListCellRenderer() {
DelegatingCellRenderer dcr = (DelegatingCellRenderer) list.
getCellRenderer();
return dcr.getFallbackCellRenderer();
}
/**
* Returns the selected value, or <code>null</code> if nothing is selected.
*
* @return The selected value.
*/
public Completion getSelection() {
return isShowing() ? (Completion) list.getSelectedValue() : lastSelection;
}
/**
* Inserts the currently selected completion.
*
* @see #getSelection()
*/
private void insertSelectedCompletion() {
Completion comp = getSelection();
ac.insertCompletion(comp);
}
public void installComp(FormulaPane.VariableTreeAndDescriptionArea component) {
this.component = component;
}
private void refreshInstallComp() {
component.refreshText(getSelection().getReplacementText());
}
/**
* Registers keyboard actions to listen for in the text component and
* intercept.
*
* @see #uninstallKeyBindings()
*/
private void installKeyBindings() {
if (AutoCompletion.isDebug()) {
FineLoggerFactory.getLogger().debug("PopupWindow: Installing keybindings");
}
if (escapeKap == null) { // Lazily create actions.
createKeyActionPairs();
}
JTextComponent comp = ac.getTextComponent();
InputMap im = comp.getInputMap();
ActionMap am = comp.getActionMap();
replaceAction(im, am, KeyEvent.VK_ESCAPE, escapeKap, oldEscape);
if (AutoCompletion.isDebug() && oldEscape.action == escapeKap.action) {
Thread.dumpStack();
}
replaceAction(im, am, KeyEvent.VK_UP, upKap, oldUp);
replaceAction(im, am, KeyEvent.VK_LEFT, leftKap, oldLeft);
replaceAction(im, am, KeyEvent.VK_DOWN, downKap, oldDown);
replaceAction(im, am, KeyEvent.VK_RIGHT, rightKap, oldRight);
replaceAction(im, am, KeyEvent.VK_ENTER, enterKap, oldEnter);
replaceAction(im, am, KeyEvent.VK_TAB, tabKap, oldTab);
replaceAction(im, am, KeyEvent.VK_HOME, homeKap, oldHome);
replaceAction(im, am, KeyEvent.VK_END, endKap, oldEnd);
replaceAction(im, am, KeyEvent.VK_PAGE_UP, pageUpKap, oldPageUp);
replaceAction(im, am, KeyEvent.VK_PAGE_DOWN, pageDownKap, oldPageDown);
// Make Ctrl+C copy from description window. This isn't done
// automagically because the desc. window is not focusable, and copying
// from text components can only be done from focused components.
KeyStroke ks = getCopyKeyStroke();
oldCtrlC.key = im.get(ks);
im.put(ks, ctrlCKap.key);
oldCtrlC.action = am.get(ctrlCKap.key);
am.put(ctrlCKap.key, ctrlCKap.action);
comp.addCaretListener(this);
}
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && e.getButton() == 1) {
insertSelectedCompletion();
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
refreshInstallComp();
}
public void mouseReleased(MouseEvent e) {
}
/**
* Positions the description window relative to the completion choices
* window. We assume there is room on one side of the other for this
* entire window to fit.
*/
private void positionDescWindow() {
boolean showDescWindow = descWindow != null && ac.isShowDescWindow();
if (!showDescWindow) {
return;
}
// Don't use getLocationOnScreen() as this throws an exception if
// window isn't visible yet, but getLocation() doesn't, and is in
// screen coordinates!
Point p = getLocation();
Rectangle screenBounds = Util.getScreenBoundsForPoint(p.x, p.y);
//Dimension screenSize = getToolkit().getScreenSize();
//int totalH = Math.max(getHeight(), descWindow.getHeight());
// Try to position to the right first (LTR)
int x;
if (ac.getTextComponentOrientation().isLeftToRight()) {
x = getX() + getWidth() + DIS;
if (x + descWindow.getWidth() > screenBounds.x + screenBounds.width) { // doesn't fit
x = getX() - DIS - descWindow.getWidth();
}
} else { // RTL
x = getX() - DIS - descWindow.getWidth();
if (x < screenBounds.x) { // Doesn't fit
x = getX() + getWidth() + DIS;
}
}
int y = getY();
if (aboveCaret) {
y = y + getHeight() - descWindow.getHeight();
}
if (x != descWindow.getX() || y != descWindow.getY()) {
descWindow.setLocation(x, y);
}
}
/**
* "Puts back" the original key/Action pair for a keystroke. This is used
* when this popup is hidden.
*
* @param im The input map.
* @param am The action map.
* @param key The keystroke whose key/Action pair to change.
* @param kap The (original) key/Action pair.
* @see #replaceAction(InputMap, ActionMap, int, KeyActionPair, KeyActionPair)
*/
private void putBackAction(InputMap im, ActionMap am, int key,
KeyActionPair kap) {
KeyStroke ks = KeyStroke.getKeyStroke(key, 0);
am.put(im.get(ks), kap.action); // Original action for the "new" key
im.put(ks, kap.key); // Original key for the keystroke.
}
/**
* Replaces a key/Action pair in an InputMap and ActionMap with a new
* pair.
*
* @param im The input map.
* @param am The action map.
* @param key The keystroke whose information to replace.
* @param kap The new key/Action pair for <code>key</code>.
* @param old A buffer in which to place the old key/Action pair.
* @see #putBackAction(InputMap, ActionMap, int, KeyActionPair)
*/
private void replaceAction(InputMap im, ActionMap am, int key,
KeyActionPair kap, KeyActionPair old) {
KeyStroke ks = KeyStroke.getKeyStroke(key, 0);
old.key = im.get(ks);
im.put(ks, kap.key);
old.action = am.get(kap.key);
am.put(kap.key, kap.action);
}
/**
* Selects the first item in the completion list.
*
* @see #selectLastItem()
*/
private void selectFirstItem() {
if (model.getSize() > 0) {
list.setSelectedIndex(0);
list.ensureIndexIsVisible(0);
}
}
/**
* Selects the last item in the completion list.
*
* @see #selectFirstItem()
*/
private void selectLastItem() {
int index = model.getSize() - 1;
if (index > -1) {
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
}
/**
* Selects the next item in the completion list.
*
* @see #selectPreviousItem()
*/
private void selectNextItem() {
int index = list.getSelectedIndex();
if (index > -1) {
index = (index + 1) % model.getSize();
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
}
/**
* Selects the completion item one "page down" from the currently selected
* one.
*
* @see #selectPageUpItem()
*/
private void selectPageDownItem() {
int visibleRowCount = list.getVisibleRowCount();
int i = Math.min(list.getModel().getSize() - 1,
list.getSelectedIndex() + visibleRowCount);
list.setSelectedIndex(i);
list.ensureIndexIsVisible(i);
}
/**
* Selects the completion item one "page up" from the currently selected
* one.
*
* @see #selectPageDownItem()
*/
private void selectPageUpItem() {
int visibleRowCount = list.getVisibleRowCount();
int i = Math.max(0, list.getSelectedIndex() - visibleRowCount);
list.setSelectedIndex(i);
list.ensureIndexIsVisible(i);
}
/**
* Selects the previous item in the completion list.
*
* @see #selectNextItem()
*/
private void selectPreviousItem() {
int index = list.getSelectedIndex();
switch (index) {
case 0:
index = list.getModel().getSize() - 1;
break;
case -1: // Check for an empty list (would be an error)
index = list.getModel().getSize() - 1;
if (index == -1) {
return;
}
break;
default:
index = index - 1;
break;
}
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
/**
* Sets the completions to display in the choices list. The first
* completion is selected.
*
* @param completions The completions to display.
*/
public void setCompletions(List<Completion> completions) {
model.setContents(completions);
selectFirstItem();
}
/**
* Sets the size of the description window.
*
* @param size The new size. This cannot be <code>null</code>.
*/
public void setDescriptionWindowSize(Dimension size) {
if (descWindow != null) {
descWindow.setSize(size);
} else {
preferredDescWindowSize = size;
}
}
/**
* Sets the default list cell renderer to use when a completion provider
* does not supply its own.
*
* @param renderer The renderer to use. If this is <code>null</code>,
* a default renderer is used.
* @see #getListCellRenderer()
*/
public void setListCellRenderer(ListCellRenderer renderer) {
DelegatingCellRenderer dcr = (DelegatingCellRenderer) list.
getCellRenderer();
dcr.setFallbackCellRenderer(renderer);
}
/**
* Sets the location of this window to be "good" relative to the specified
* rectangle. That rectangle should be the location of the text
* component's caret, in screen coordinates.
*
* @param r The text component's caret position, in screen coordinates.
*/
public void setLocationRelativeTo(Rectangle r) {
// Multi-monitor support - make sure the completion window (and
// description window, if applicable) both fit in the same window in
// a multi-monitor environment. To do this, we decide which monitor
// the rectangle "r" is in, and use that one (just pick top-left corner
// as the defining point).
Rectangle screenBounds = Util.getScreenBoundsForPoint(r.x, r.y);
//Dimension screenSize = getToolkit().getScreenSize();
boolean showDescWindow = descWindow != null && ac.isShowDescWindow();
int totalH = getHeight();
if (showDescWindow) {
totalH = Math.max(totalH, descWindow.getHeight());
}
// Try putting our stuff "below" the caret first. We assume that the
// entire height of our stuff fits on the screen one way or the other.
aboveCaret = false;
int y = r.y + r.height + VERTICAL_SPACE;
if (y + totalH > screenBounds.height) {
y = r.y - VERTICAL_SPACE - getHeight();
aboveCaret = true;
}
// Get x-coordinate of completions. Try to align left edge with the
// caret first.
int x = r.x;
if (!ac.getTextComponentOrientation().isLeftToRight()) {
x -= getWidth(); // RTL => align right edge
}
if (x < screenBounds.x) {
x = screenBounds.x;
} else if (x + getWidth() > screenBounds.x + screenBounds.width) { // completions don't fit
x = screenBounds.x + screenBounds.width - getWidth();
}
setLocation(x, y);
// Position the description window, if necessary.
if (showDescWindow) {
positionDescWindow();
}
}
/**
* Toggles the visibility of this popup window.
*
* @param visible Whether this window should be visible.
*/
@Override
public void setVisible(boolean visible) {
if (visible != isVisible()) {
if (visible) {
installKeyBindings();
lastLine = ac.getLineOfCaret();
selectFirstItem();
if (descWindow == null && ac.isShowDescWindow()) {
descWindow = createDescriptionWindow();
positionDescWindow();
}
// descWindow needs a kick-start the first time it's displayed.
// Also, the newly-selected item in the choices list is
// probably different from the previous one anyway.
if (descWindow != null) {
Completion c = (Completion) list.getSelectedValue();
if (c != null) {
descWindow.setDescriptionFor(c);
}
}
} else {
uninstallKeyBindings();
}
super.setVisible(visible);
// Some languages, such as Java, can use quite a lot of memory
// when displaying hundreds of completion choices. We pro-actively
// clear our list model here to make them available for GC.
// Otherwise, they stick around, and consider the following: a
// user starts code-completion for Java 5 SDK classes, then hides
// the dialog, then changes the "class path" to use a Java 6 SDK
// instead. On pressing Ctrl+space, a new array of Completions is
// created. If this window holds on to the previous Completions,
// you're getting roughly 2x the necessary Completions in memory
// until the Completions are actually passed to this window.
if (!visible) { // Do after super.setVisible(false)
lastSelection = (Completion) list.getSelectedValue();
model.clear();
}
// Must set descWindow's visibility one way or the other each time,
// because of the way child JWindows' visibility is handled - in
// some ways it's dependent on the parent, in other ways it's not.
if (descWindow != null) {
descWindow.setVisible(visible && ac.isShowDescWindow());
}
}
}
/**
* Stops intercepting certain keystrokes from the text component.
*
* @see #installKeyBindings()
*/
private void uninstallKeyBindings() {
if (AutoCompletion.isDebug()) {
FineLoggerFactory.getLogger().debug("PopupWindow: Removing keybindings");
}
JTextComponent comp = ac.getTextComponent();
InputMap im = comp.getInputMap();
ActionMap am = comp.getActionMap();
putBackAction(im, am, KeyEvent.VK_ESCAPE, oldEscape);
putBackAction(im, am, KeyEvent.VK_UP, oldUp);
putBackAction(im, am, KeyEvent.VK_DOWN, oldDown);
putBackAction(im, am, KeyEvent.VK_LEFT, oldLeft);
putBackAction(im, am, KeyEvent.VK_RIGHT, oldRight);
putBackAction(im, am, KeyEvent.VK_ENTER, oldEnter);
putBackAction(im, am, KeyEvent.VK_TAB, oldTab);
putBackAction(im, am, KeyEvent.VK_HOME, oldHome);
putBackAction(im, am, KeyEvent.VK_END, oldEnd);
putBackAction(im, am, KeyEvent.VK_PAGE_UP, oldPageUp);
putBackAction(im, am, KeyEvent.VK_PAGE_DOWN, oldPageDown);
// Ctrl+C
KeyStroke ks = getCopyKeyStroke();
am.put(im.get(ks), oldCtrlC.action); // Original action
im.put(ks, oldCtrlC.key); // Original key
comp.removeCaretListener(this);
}
/**
* Updates the <tt>LookAndFeel</tt> of this window and the description
* window.
*/
public void updateUI() {
SwingUtilities.updateComponentTreeUI(this);
if (descWindow != null) {
descWindow.updateUI();
}
}
/**
* Called when a new item is selected in the popup list.
*
* @param e The event.
*/
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
Object value = list.getSelectedValue();
if (value != null && descWindow != null) {
descWindow.setDescriptionFor((Completion) value);
positionDescWindow();
}
}
}
class CopyAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
boolean doNormalCopy = false;
if (descWindow != null && descWindow.isVisible()) {
doNormalCopy = !descWindow.copy();
}
if (doNormalCopy) {
ac.getTextComponent().copy();
}
}
}
class DownAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectNextItem();
refreshInstallComp();
}
}
}
class EndAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectLastItem();
}
}
}
class EnterAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
insertSelectedCompletion();
refreshInstallComp();
}
}
super(parent,ac);
}
class EscapeAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
setVisible(false);
}
}
}
class HomeAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectFirstItem();
}
}
}
/**
* A mapping from a key (an Object) to an Action.
*/
private static class KeyActionPair {
public Object key;
public Action action;
public KeyActionPair() {
}
public KeyActionPair(Object key, Action a) {
this.key = key;
this.action = a;
}
}
class LeftAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
JTextComponent comp = ac.getTextComponent();
Caret c = comp.getCaret();
int dot = c.getDot();
if (dot > 0) {
c.setDot(--dot);
// Ensure moving left hasn't moved us up a line, thus
// hiding the popup window.
if (comp.isVisible()) {
if (lastLine != -1) {
doAutocomplete();
}
}
}
}
}
}
class PageDownAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectPageDownItem();
}
}
}
class PageUpAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectPageUpItem();
}
}
}
/**
* The actual list of completion choices in this popup window.
*/
private class PopupList extends JList {
public PopupList(CompletionListModel model) {
super(model);
}
@Override
public void setUI(ListUI ui) {
if (Util.getUseSubstanceRenderers() &&
SUBSTANCE_LIST_UI.equals(ui.getClass().getName())) {
// Substance requires its special ListUI be installed for
// its renderers to actually render (!), but long completion
// lists (e.g. PHPCompletionProvider in RSTALanguageSupport)
// will simply populate too slowly on initial display (when
// calculating preferred size of all items), so in this case
// we give a prototype cell value.
CompletionProvider p = ac.getCompletionProvider();
BasicCompletion bc = new BasicCompletion(p, "Hello world");
setPrototypeCellValue(bc);
} else {
// Our custom UI that is faster for long HTML completion lists.
ui = new FastListUI();
setPrototypeCellValue(null);
}
super.setUI(ui);
}
}
class RightAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
JTextComponent comp = ac.getTextComponent();
Caret c = comp.getCaret();
int dot = c.getDot();
if (dot < comp.getDocument().getLength()) {
c.setDot(++dot);
// Ensure moving right hasn't moved us up a line, thus
// hiding the popup window.
if (comp.isVisible()) {
if (lastLine != -1) {
doAutocomplete();
}
}
}
}
}
}
class UpAction extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (isVisible()) {
selectPreviousItem();
refreshInstallComp();
}
}
}
}

1241
designer-base/src/main/java/com/fr/design/gui/autocomplete/FormulaPaneAutoCompletion.java

File diff suppressed because it is too large Load Diff

16
designer-base/src/main/java/com/fr/design/gui/autocomplete/JSAutoCompletePopupWindow.java

@ -0,0 +1,16 @@
package com.fr.design.gui.autocomplete;
import java.awt.Window;
public class JSAutoCompletePopupWindow extends AutoCompleteWithExtraRefreshPopupWindow {
/**
* Constructor.
*
* @param parent The parent window (hosting the text component).
* @param ac The auto-completion instance.
*/
public JSAutoCompletePopupWindow(Window parent, AutoCompletion ac) {
super(parent, ac);
}
}

31
designer-base/src/main/java/com/fr/design/gui/autocomplete/JSImplPaneAutoCompletion.java

@ -0,0 +1,31 @@
package com.fr.design.gui.autocomplete;
public class JSImplPaneAutoCompletion extends AutoCompletionWithExtraRefresh{
/**
* Constructor.
*
* @param provider The completion provider. This cannot be
* <code>null</code>.
*/
public JSImplPaneAutoCompletion(CompletionProvider provider) {
super(provider);
}
@Override
protected AutoCompleteWithExtraRefreshPopupWindow createAutoCompletePopupWindow() {
JSAutoCompletePopupWindow popupWindow = new JSAutoCompletePopupWindow(getParentWindow(),this);
popupWindow.applyComponentOrientation(
getTextComponentOrientation());
if (getCellRender() != null) {
popupWindow.setListCellRenderer(getCellRender());
}
if (getPreferredChoicesWindowSize() != null) {
popupWindow.setSize(getPreferredChoicesWindowSize());
}
if (getPreferredDescWindowSize() != null) {
popupWindow.setDescriptionWindowSize(
getPreferredDescWindowSize());
}
return popupWindow;
}
}

78
designer-base/src/main/java/com/fr/design/gui/ilable/UIAutoChangeLineLabel.java

@ -0,0 +1,78 @@
package com.fr.design.gui.ilable;
import javax.swing.JLabel;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.util.ArrayList;
import java.util.List;
public class UIAutoChangeLineLabel extends JLabel {
private final String text;
private final int width;
public UIAutoChangeLineLabel(String text, int width) {
super(text);
this.text = text;
this.width = width;
}
@Override
public void doLayout() {
super.doLayout();
this.setText(wrapperHtmlText());
}
private String wrapperHtmlText() {
List<String> stringList = autoChangeLine(this.getWidth());
StringBuilder builder = new StringBuilder("<html>");
for (String s : stringList) {
//用THML标签进行拼接,以实现自动换行
builder.append(s).append("<br/>");
}
builder.append("</html>");
return builder.toString();
}
private List<String> autoChangeLine(int width) {
List<String> result = new ArrayList<>();
if (width <= 0) {
result.add(this.text);
} else {
char[] chars = this.text.toCharArray();
//获取字体计算大小
FontMetrics fontMetrics = this.getFontMetrics(this.getFont());
int start = 0;
int len = 0;
while (start + len < this.text.length()) {
while (true) {
len++;
if (start + len > this.text.length())
break;
if (fontMetrics.charsWidth(chars, start, len)
> width) {
break;
}
}
result.add(String.copyValueOf(chars, start, len - 1));
start = start + len - 1;
len = 0;
}
if (this.text.length() - start > 0) {
result.add(String.copyValueOf(chars, start, this.text.length() - start));
}
}
return result;
}
@Override
public Dimension getPreferredSize() {
Dimension preferredSize = super.getPreferredSize();
List<String> stringList = autoChangeLine(width);
FontMetrics fontMetrics = this.getFontMetrics(this.getFont());
return new Dimension(preferredSize.width, fontMetrics.getHeight() * stringList.size());
}
}

169
designer-base/src/main/java/com/fr/design/javascript/JSContentPane.java

@ -1,10 +1,13 @@
package com.fr.design.javascript;
import com.fr.base.svg.IconUtils;
import com.fr.design.DesignerEnvManager;
import com.fr.design.border.UIRoundedBorder;
import com.fr.design.constants.KeyWords;
import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.autocomplete.AutoCompletion;
import com.fr.design.gui.autocomplete.BasicCompletion;
import com.fr.design.gui.autocomplete.CompletionProvider;
@ -14,32 +17,147 @@ import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.SyntaxConstants;
import com.fr.design.i18n.Toolkit;
import com.fr.design.javascript.beautify.JavaScriptFormatHelper;
import com.fr.design.javascript.jsapi.JSImplPopulateAction;
import com.fr.design.javascript.jsapi.JSImplUpdateAction;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.general.IOUtils;
import com.fr.js.JavaScriptImpl;
import javax.swing.*;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
public class JSContentPane extends BasicPane {
private RSyntaxTextArea contentTextArea;
private UILabel funNameLabel;
protected RSyntaxTextArea contentTextArea;
private UILabel funNameLabel = new UILabel();
private AutoCompletion ac;
private static final Dimension FUNCTION_NAME_LABEL_SIZE = new Dimension(300, 80);
private String[] defaultArgs;
private int titleWidth = 180;
private JPanel labelPane = new JPanel(new BorderLayout(6, 4));;
private NewJavaScriptImplPane newJavaScriptImplPane = null;
private JavaScriptImpl javaScript;
private JSImplUpdateAction jsImplUpdateAction;
private JSImplPopulateAction jsImplPopulateAction;
private boolean modal;
BasicDialog advancedEditorDialog ;
public JSContentPane(){}
public JSContentPane(String[] args) {
defaultArgs = args;
this.setLayout(FRGUIPaneFactory.createBorderLayout());
funNameLabel = new UILabel();
this.setFunctionTitle(args);
initFunctionTitle(args);
JPanel jsParaPane = createJSParaPane();
addNewPaneLabel();
this.add(jsParaPane, BorderLayout.NORTH);
UIScrollPane sp = createContentTextAreaPanel();
initContentTextAreaListener();
this.add(sp, BorderLayout.CENTER);
UILabel funNameLabel2 = new UILabel();
funNameLabel2.setText("}");
this.add(funNameLabel2, BorderLayout.SOUTH);
}
public JSContentPane(String[] args,boolean modal) {
this(args);
this.modal = modal;
}
public void setJsImplUpdateAction(JSImplUpdateAction jsImplUpdateAction){
this.jsImplUpdateAction = jsImplUpdateAction;
}
public void setJsImplPopulateAction(JSImplPopulateAction jsImplPopulateAction){
this.jsImplPopulateAction = jsImplPopulateAction;
}
public void updateJSImpl(JavaScriptImpl javaScript){
this.javaScript = javaScript;
}
private void addNewPaneLabel(){
UILabel advancedEditorLabel = new UILabel(Toolkit.i18nText("Fine-Design_Advanced_Editor"), IconUtils.readIcon("com/fr/design/images/edit/advancedEditor.svg"), SwingConstants.LEFT);
advancedEditorLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
advancedEditorLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(newJavaScriptImplPane == null){
newJavaScriptImplPane = new NewJavaScriptImplPane(defaultArgs);
}
jsImplUpdateAction.update(javaScript);
newJavaScriptImplPane.populate(javaScript);
if(advancedEditorDialog == null || !advancedEditorDialog.isVisible()) {
advancedEditorDialog = newJavaScriptImplPane.showWindowWithCustomSize(DesignerContext.getDesignerFrame(), new DialogActionAdapter() {
@Override
public void doOk() {
if (javaScript != null) {
newJavaScriptImplPane.updateBean(javaScript);
jsImplPopulateAction.populate(javaScript);
}
}
@Override
public void doCancel() {
super.doCancel();
}
},new Dimension(900,800));
advancedEditorDialog.setModal(modal);
advancedEditorDialog.setResizable(true);
advancedEditorDialog.pack();
advancedEditorDialog.setVisible(true);
}
advancedEditorDialog.requestFocus();
}
});
labelPane.add(advancedEditorLabel,BorderLayout.EAST);
}
protected UIScrollPane createContentTextAreaPanel(){
contentTextArea = new RSyntaxTextArea();
contentTextArea.setCloseCurlyBraces(true);
contentTextArea.setLineWrap(true);
contentTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
contentTextArea.setCodeFoldingEnabled(true);
contentTextArea.setAntiAliasingEnabled(true);
return new UIScrollPane(contentTextArea);
}
private void initContentTextAreaListener(){
contentTextArea.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
// 获得焦点时 安装
installAutoCompletion();
}
@Override
public void focusLost(FocusEvent e) {
// 失去焦点时 卸载
uninstallAutoCompletion();
}
});
}
protected JPanel createJSParaPane(){
UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Format_JavaScript"), IOUtils.readIcon("com/fr/design/images/edit/format.png"), SwingConstants.LEFT);
label.setCursor(new Cursor(Cursor.HAND_CURSOR));
label.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Format_JavaScript"));
@ -65,43 +183,20 @@ public class JSContentPane extends BasicPane {
}
});
//REPORT-10533 用户参数多达25个,导致JS没地方写,增加滚动条显示
labelPane.add(label,BorderLayout.CENTER);
JPanel jsParaPane = new JPanel(new BorderLayout(4, 4));
jsParaPane.setPreferredSize(new Dimension(300, 80));
UIScrollPane scrollPane = new UIScrollPane(funNameLabel);
scrollPane.setPreferredSize(FUNCTION_NAME_LABEL_SIZE);
scrollPane.setBorder(new UIRoundedBorder(UIConstants.TITLED_BORDER_COLOR, 1, UIConstants.ARC));
jsParaPane.add(scrollPane, BorderLayout.WEST);
jsParaPane.add(label, BorderLayout.EAST);
this.add(jsParaPane, BorderLayout.NORTH);
contentTextArea = new RSyntaxTextArea();
contentTextArea.setCloseCurlyBraces(true);
contentTextArea.setLineWrap(true);
contentTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
contentTextArea.setCodeFoldingEnabled(true);
contentTextArea.setAntiAliasingEnabled(true);
UIScrollPane sp = new UIScrollPane(contentTextArea);
this.add(sp, BorderLayout.CENTER);
contentTextArea.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
// 获得焦点时 安装
installAutoCompletion();
}
@Override
public void focusLost(FocusEvent e) {
// 失去焦点时 卸载
uninstallAutoCompletion();
}
});
jsParaPane.add(labelPane, BorderLayout.EAST);
return jsParaPane;
}
UILabel funNameLabel2 = new UILabel();
funNameLabel2.setText("}");
this.add(funNameLabel2, BorderLayout.SOUTH);
protected void initFunctionTitle(String[] args){
funNameLabel = new UILabel();
this.setFunctionTitle(args);
}
private KeyStroke convert2KeyStroke(String ks) {

924
designer-base/src/main/java/com/fr/design/javascript/JSContentWithDescriptionPane.java

@ -0,0 +1,924 @@
package com.fr.design.javascript;
import com.fr.base.svg.IconUtils;
import com.fr.design.border.UIRoundedBorder;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.autocomplete.AutoCompleteExtraRefreshComponent;
import com.fr.design.gui.autocomplete.BasicCompletion;
import com.fr.design.gui.autocomplete.CompletionCellRenderer;
import com.fr.design.gui.autocomplete.CompletionProvider;
import com.fr.design.gui.autocomplete.DefaultCompletionProvider;
import com.fr.design.gui.autocomplete.JSImplPaneAutoCompletion;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextarea.UITextArea;
import com.fr.design.gui.itextfield.PlaceholderTextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.javascript.jsapi.JSAPITreeHelper;
import com.fr.design.javascript.jsapi.JSAPIUserObject;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
public class JSContentWithDescriptionPane extends JSContentPane implements KeyListener {
//搜索关键词输入框
private PlaceholderTextField keyWordTextField = new PlaceholderTextField(16);
//搜索出的提示列表
private JList tipsList;
private DefaultListModel tipsListModel = new DefaultListModel();
private JList interfaceNameList;
private DefaultListModel interfaceNameModel;
private JTree moduleTree;
private DefaultCompletionProvider completionProvider;
private JSImplPaneAutoCompletion autoCompletion;
//函数说明文本框
private UITextArea descriptionTextArea;
private JPopupMenu popupMenu;
private InterfaceAndDescriptionPanel interfaceAndDescriptionPanel;
private JList helpDOCList;
private int ifHasBeenWriten = 0;
private int currentPosition = 0;
private int beginPosition = 0;
private int insertPosition = 0;
private static final String SEPARATOR = "_";
private static final int KEY_10 = 10;
//上下左右
private static final int KEY_37 = 37;
private static final int KEY_38 = 38;
private static final int KEY_39 = 39;
private static final int KEY_40 = 40;
private static final String URL_FOR_TEST_NETWORK = "https://www.baidu.com";
private static final String DOCUMENT_SEARCH_URL = "https://help.fanruan.com/finereport/api-helpdoc-title-";
private String currentValue;
private static CardLayout card;
private static final String RELOAD_CARD = "reloadCard";
private static final String DOC_LIST_CARD = "docListCard";
public JSContentWithDescriptionPane(String[] args) {
this.setLayout(new BorderLayout());
//===============================
this.initFunctionTitle(args);
JPanel jsParaAndSearchPane = new JPanel(new BorderLayout());
//js函数声明面板
JPanel jsParaPane = createJSParaPane();
jsParaPane.setPreferredSize(new Dimension(650, 80));
//右上角的搜索提示面板
JPanel tipsPane = createTipsPane();
jsParaAndSearchPane.add(jsParaPane, BorderLayout.CENTER);
jsParaAndSearchPane.add(tipsPane, BorderLayout.EAST);
initPopTips();
//js文本编辑面板
UIScrollPane contentTextAreaPanel = createContentTextAreaPanel();
initContextAreaListener();
contentTextAreaPanel.setPreferredSize(new Dimension(850, 250));
//js函数结束标签
UILabel endBracketsLabel = new UILabel();
endBracketsLabel.setText("}");
//结尾括号和复用函数按钮面板
JPanel endBracketsPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
endBracketsPanel.add(endBracketsLabel, BorderLayout.WEST);
JPanel northPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
northPanel.add(jsParaAndSearchPane, BorderLayout.NORTH);
northPanel.add(contentTextAreaPanel, BorderLayout.CENTER);
northPanel.add(endBracketsPanel, BorderLayout.SOUTH);
//主编辑框,也就是面板的正中间部分
this.add(northPanel, BorderLayout.CENTER);
//函数分类和函数说明面板==================================
JPanel functionNameAndDescriptionPanel = createInterfaceAndDescriptionPanel();
functionNameAndDescriptionPanel.setPreferredSize(new Dimension(880, 220));
this.add(functionNameAndDescriptionPanel, BorderLayout.SOUTH);
}
public void populate(String js) {
contentTextArea.setText(js);
ifHasBeenWriten = 1;
currentPosition = contentTextArea.getCaretPosition();
beginPosition = getBeginPosition();
insertPosition = beginPosition;
}
private void initContextAreaListener() {
contentTextArea.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if ((e.getKeyChar() >= 'A' && e.getKeyChar() <= 'z') || e.getKeyChar() == '_') {
if (autoCompletion != null) {
autoCompletion.doCompletion();
}
}
}
@Override
public void keyReleased(KeyEvent e) {
contentTextArea.setForeground(Color.black);
}
});
contentTextArea.addKeyListener(this);
contentTextArea.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
if (autoCompletion == null) {
installAutoCompletion();
}
}
@Override
public void focusLost(FocusEvent e) {
uninstallAutoCompletion();
}
});
contentTextArea.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
insertPosition = contentTextArea.getCaretPosition();
if (ifHasBeenWriten == 0) {
contentTextArea.setText(StringUtils.EMPTY);
ifHasBeenWriten = 1;
contentTextArea.setForeground(Color.black);
insertPosition = 0;
}
}
@Override
public void mouseReleased(MouseEvent e) {
currentPosition = contentTextArea.getCaretPosition();
if (currentPosition == insertPosition) {
beginPosition = getBeginPosition();
insertPosition = beginPosition;
}
}
});
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (ifHasBeenWriten == 0) {
this.contentTextArea.setText(StringUtils.EMPTY);
}
}
@Override
public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
if (key == KEY_38 || key == KEY_40 || key == KEY_37 || key == KEY_39 || key == KEY_10) //如果是删除符号 ,为了可读性 没有和其他按键的程序相融合
{
currentPosition = contentTextArea.getCaretPosition();
insertPosition = currentPosition;
beginPosition = getBeginPosition();
} else {
if (contentTextArea.getText().trim().length() == 0) {
insertPosition = 0;
} else {
contentTextArea.setForeground(Color.black);
currentPosition = contentTextArea.getCaretPosition();
beginPosition = getBeginPosition();
insertPosition = beginPosition;
ifHasBeenWriten = 1;
}
}
}
private int getBeginPosition() {
int i = currentPosition;
String textArea = contentTextArea.getText();
for (; i > 0; i--) {
String tested = textArea.substring(i - 1, i).toUpperCase();
char[] testedChar = tested.toCharArray();
if (isChar(testedChar[0]) || isNum(testedChar[0])) {
continue;
} else {
break;
}
}
return i;
}
private static boolean isNum(char tested) {
return tested >= '0' && tested <= '9';
}
private boolean isChar(char tested) {
return tested >= 'A' && tested <= 'Z' || tested >= 'a' && tested < 'z';
}
public class InterfaceAndDescriptionPanel extends JPanel implements AutoCompleteExtraRefreshComponent {
@Override
public void refresh(String replacementText) {
fixInterfaceNameList(replacementText);
}
}
private void fixInterfaceNameList(String interfaceName) {
DefaultTreeModel defaultTreeModel = (DefaultTreeModel) moduleTree.getModel();
TreeNode root = (TreeNode) defaultTreeModel.getRoot();
String directCategory = JSAPITreeHelper.getDirectCategory(interfaceName);
if (directCategory == null) {
return;
}
setModuleTreeSelection(root, directCategory, defaultTreeModel);
interfaceNameModel = (DefaultListModel) interfaceNameList.getModel();
interfaceNameModel.clear();
List<String> interfaceNames = JSAPITreeHelper.getNames(directCategory);
int index = 0;
for (int i = 0; i < interfaceNames.size(); i++) {
interfaceNameModel.addElement(interfaceNames.get(i));
if (StringUtils.equals(interfaceNames.get(i), interfaceName)) {
index = i;
}
}
interfaceNameList.setSelectedIndex(index);
interfaceNameList.ensureIndexIsVisible(index);
}
private boolean setModuleTreeSelection(TreeNode node, String directCategory, DefaultTreeModel treeModel) {
DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) node;
Object userObject = defaultMutableTreeNode.getUserObject();
if (userObject instanceof JSAPIUserObject) {
String value = ((JSAPIUserObject) userObject).getValue();
if (StringUtils.equals(value, directCategory)) {
moduleTree.setSelectionPath(new TreePath(treeModel.getPathToRoot(node)));
moduleTree.scrollPathToVisible(moduleTree.getSelectionPath());
return true;
}
}
for (int i = 0; i < node.getChildCount(); i++) {
if (setModuleTreeSelection(node.getChildAt(i), directCategory, treeModel)) {
return true;
}
}
return false;
}
private JPanel createInterfaceAndDescriptionPanel() {
interfaceAndDescriptionPanel = new InterfaceAndDescriptionPanel();
interfaceAndDescriptionPanel.setLayout(new BorderLayout(4, 4));
JPanel interfacePanel = new JPanel(new BorderLayout(4, 4));
interfaceAndDescriptionPanel.add(interfacePanel, BorderLayout.WEST);
JPanel descriptionAndDocumentPanel = new JPanel(new BorderLayout(4, 4));
//函数说明和帮助文档框
initDescriptionArea(descriptionAndDocumentPanel);
//模块和接口面板
initInterfaceModuleTree(interfacePanel);
initInterfaceNameList(interfacePanel);
initHelpDocumentPane(descriptionAndDocumentPanel);
interfaceAndDescriptionPanel.add(descriptionAndDocumentPanel, BorderLayout.CENTER);
return interfaceAndDescriptionPanel;
}
private void doHelpDocumentSearch() {
Object value = interfaceNameList.getSelectedValue();
if (value != null) {
String url = CloudCenter.getInstance().acquireUrlByKind("af.doc_search", DOCUMENT_SEARCH_URL) + value.toString();
try {
String result = HttpToolbox.get(url);
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.optJSONArray("list");
if (jsonArray != null) {
DefaultListModel helpDOCModel = (DefaultListModel) helpDOCList.getModel();
helpDOCModel.clear();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject resultJSONObject = jsonArray.optJSONObject(i);
String docURL = resultJSONObject.optString("url");
String name = resultJSONObject.optString("title").trim();
HelpDocument helpDocument = new HelpDocument(docURL, name);
helpDOCModel.addElement(helpDocument);
}
}
} catch (JSONException e) {
FineLoggerFactory.getLogger().debug(e.getMessage(), e);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
private void initHelpDocumentPane(JPanel descriptionAndDocumentPanel) {
card = new CardLayout();
JPanel mainPane = new JPanel(card);
initHelpDocumentList();
UIScrollPane helpDOCScrollPane = new UIScrollPane(helpDOCList);
helpDOCScrollPane.setPreferredSize(new Dimension(200, 200));
helpDOCScrollPane.setBorder(null);
mainPane.add(helpDOCScrollPane, DOC_LIST_CARD);
UILabel imageLabel = new UILabel();
imageLabel.setIcon(IconUtils.readIcon("com/fr/design/javascript/jsapi/images/connectFailed.svg"));
imageLabel.setPreferredSize(new Dimension(180, 65));
JPanel imagePane = FRGUIPaneFactory.createBorderLayout_S_Pane();
imagePane.setBorder(BorderFactory.createEmptyBorder(0, 42, 0, 0));
imagePane.add(imageLabel);
imagePane.setBackground(Color.WHITE);
UILabel failedLabel = new UILabel(Toolkit.i18nText("Fine-Design_Net_Connect_Failed"), 0);
failedLabel.setPreferredSize(new Dimension(180, 20));
UILabel reloadLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Reload"), 0);
reloadLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
reloadLabel.setPreferredSize(new Dimension(180, 20));
reloadLabel.setForeground(Color.blue);
JPanel labelPane = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, 0, 0, 0);
labelPane.setBorder(BorderFactory.createEmptyBorder(35, 45, 0, 0));
labelPane.setBackground(Color.WHITE);
labelPane.add(imagePane);
labelPane.add(failedLabel);
labelPane.add(reloadLabel);
JPanel containerPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
containerPanel.add(labelPane, BorderLayout.CENTER);
reloadLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (isNetworkOk()) {
doHelpDocumentSearch();
card.show(mainPane, DOC_LIST_CARD);
}
}
});
mainPane.add(containerPanel, RELOAD_CARD);
if (isNetworkOk()) {
doHelpDocumentSearch();
card.show(mainPane, DOC_LIST_CARD);
} else {
card.show(mainPane, RELOAD_CARD);
}
descriptionAndDocumentPanel.add(this.createNamePane(Toolkit.i18nText("Fine-Design_Relevant_Cases"), mainPane), BorderLayout.EAST);
}
private void initHelpDocumentList() {
helpDOCList = new JList(new DefaultListModel());
initHelpDOCListRender();
initHelpDOCListListener();
}
private void initHelpDOCListListener() {
helpDOCList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
Object value = helpDOCList.getSelectedValue();
if (value instanceof HelpDocument) {
String url = ((HelpDocument) value).getDocumentUrl();
browse(url);
}
}
}
});
}
private void browse(String url){
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException | URISyntaxException ex) {
FineLoggerFactory.getLogger().error(ex.getMessage(), ex);
}
}
private void initHelpDOCListRender() {
helpDOCList.setCellRenderer(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 HelpDocument) {
this.setText(((HelpDocument) value).getName());
this.setForeground(Color.BLUE);
}
return this;
}
});
}
private static boolean isNetworkOk() {
try {
HttpToolbox.get(URL_FOR_TEST_NETWORK);
return true;
} catch (Exception ignore) {
// 网络异常
return false;
}
}
private static class HelpDocument {
private String documentUrl;
private String name;
public HelpDocument(String documentUrl, String name) {
this.documentUrl = documentUrl;
this.name = name;
}
public String getDocumentUrl() {
return documentUrl;
}
public String getName() {
return name;
}
}
private void initDescriptionArea(JPanel descriptionPanel) {
descriptionTextArea = new UITextArea();
UIScrollPane descriptionScrollPane = new UIScrollPane(descriptionTextArea);
descriptionScrollPane.setPreferredSize(new Dimension(300, 200));
descriptionPanel.add(this.createNamePane(Toolkit.i18nText("Fine-Design_Interface_Description"), descriptionScrollPane), BorderLayout.CENTER);
descriptionTextArea.setBackground(Color.white);
descriptionTextArea.setLineWrap(true);
descriptionTextArea.setWrapStyleWord(true);
descriptionTextArea.setEditable(false);
}
private void installAutoCompletion() {
CompletionProvider provider = createCompletionProvider();
autoCompletion = new JSImplPaneAutoCompletion(provider);
autoCompletion.setListCellRenderer(new CompletionCellRenderer());
autoCompletion.install(contentTextArea);
autoCompletion.installExtraRefreshComponent(interfaceAndDescriptionPanel);
}
private void uninstallAutoCompletion() {
if (autoCompletion != null) {
autoCompletion.uninstall();
autoCompletion = null;
}
}
private CompletionProvider createCompletionProvider() {
if (completionProvider == null) {
completionProvider = new DefaultCompletionProvider();
for (String name : JSAPITreeHelper.getAllNames()) {
completionProvider.addCompletion(new BasicCompletion(completionProvider, name));
}
}
return completionProvider;
}
private void initInterfaceModuleTree(JPanel interfacePanel) {
moduleTree = new JTree();
UIScrollPane moduleTreePane = new UIScrollPane(moduleTree);
moduleTreePane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC));
interfacePanel.add(this.createNamePane(Toolkit.i18nText("Fine-Design_Module"), moduleTreePane), BorderLayout.WEST);
moduleTreePane.setPreferredSize(new Dimension(180, 200));
moduleTree.setRootVisible(false);
moduleTree.setShowsRootHandles(true);
moduleTree.setCellRenderer(moduleTreeCellRender);
DefaultTreeModel moduleTreeModel = (DefaultTreeModel) moduleTree.getModel();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) moduleTreeModel.getRoot();
rootNode.removeAllChildren();
JSAPITreeHelper.createJSAPITree(rootNode);
moduleTreeModel.reload();
initModuleTreeSelectionListener();
}
private void initModuleTreeSelectionListener() {
moduleTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) moduleTree.getLastSelectedPathComponent();
Object selectedValue = selectedTreeNode.getUserObject();
if (null == selectedValue) {
return;
}
if (selectedValue instanceof JSAPIUserObject) {
interfaceNameModel = (DefaultListModel) interfaceNameList.getModel();
interfaceNameModel.clear();
String text = ((JSAPIUserObject) selectedValue).getValue();
List<String> allInterfaceNames = JSAPITreeHelper.getNames(text);
for (String interfaceName : allInterfaceNames) {
interfaceNameModel.addElement(interfaceName);
}
if (interfaceNameModel.size() > 0) {
interfaceNameList.setSelectedIndex(0);
setDescription(interfaceNameList.getSelectedValue().toString());
interfaceNameList.ensureIndexIsVisible(0);
}
}
}
});
}
private DefaultTreeCellRenderer moduleTreeCellRender = new DefaultTreeCellRenderer() {
public Component getTreeCellRendererComponent(JTree tree,
Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected,
expanded, leaf, row, hasFocus);
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
Object userObj = treeNode.getUserObject();
if (userObj instanceof JSAPIUserObject) {
this.setText(((JSAPIUserObject) userObj).getDisplayText());
this.setIcon(null);
}
return this;
}
};
private void initInterfaceNameList(JPanel interfacePanel) {
interfaceNameList = new JList(new DefaultListModel());
UIScrollPane interfaceNamePanelScrollPane = new UIScrollPane(interfaceNameList);
interfaceNamePanelScrollPane.setPreferredSize(new Dimension(180, 200));
interfacePanel.add(
this.createNamePane(Toolkit.i18nText("Fine-Design_Interface") + ":", interfaceNamePanelScrollPane),
BorderLayout.CENTER);
interfaceNamePanelScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC));
initInterfaceNameModule();
initInterfaceNameListSelectionListener();
initInterfaceNameListMouseListener();
}
private void initInterfaceNameModule() {
DefaultTreeModel defaultTreeModel = (DefaultTreeModel) moduleTree.getModel();
TreeNode root = (TreeNode) defaultTreeModel.getRoot();
while (root.getChildCount() > 0){
root = root.getChildAt(0);
}
moduleTree.setSelectionPath(new TreePath(defaultTreeModel.getPathToRoot(root)));
}
private void setDescription(String interfaceName) {
StringBuilder il8Key = new StringBuilder();
moduleTree.getSelectionPath().getPath();
Object obj = moduleTree.getSelectionPath().getPath()[moduleTree.getSelectionPath().getPath().length - 1];
Object userObject = ((DefaultMutableTreeNode) obj).getUserObject();
if (userObject instanceof JSAPIUserObject) {
il8Key.append(JSAPITreeHelper.getDirectCategory(interfaceName));
}
interfaceName = interfaceName.toUpperCase();
if (!interfaceName.startsWith(SEPARATOR)) {
interfaceName = SEPARATOR + interfaceName;
}
il8Key.append(interfaceName);
descriptionTextArea.setText(Toolkit.i18nText(il8Key.toString()));
descriptionTextArea.moveCaretPosition(0);
}
private void initInterfaceNameListSelectionListener() {
interfaceNameList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
Object selectedValue = interfaceNameList.getSelectedValue();
if (selectedValue == null) {
return;
}
String interfaceName = selectedValue.toString();
if (!StringUtils.equals(interfaceName, currentValue)) {
setDescription(interfaceName);
doHelpDocumentSearch();
currentValue = interfaceName;
}
}
});
}
private void initInterfaceNameListMouseListener() {
interfaceNameList.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() >= 2) {
Object selectedValue = interfaceNameList.getSelectedValue();
String interfaceName = selectedValue.toString();
applyText(interfaceName);
}
}
});
}
private void applyText(String text) {
if (text == null || text.length() <= 0) {
return;
}
if (ifHasBeenWriten == 0) {
contentTextArea.setForeground(Color.black);
contentTextArea.setText(StringUtils.EMPTY);
ifHasBeenWriten = 1;
insertPosition = 0;
}
String textAll = contentTextArea.getText();
currentPosition = contentTextArea.getCaretPosition();
int insert = 0;
int current = 0;
if (insertPosition <= currentPosition) {
insert = insertPosition;
current = currentPosition;
} else {
insert = currentPosition;
current = insertPosition;
}
String beforeIndexOfInsertString = textAll.substring(0, insert);
String afterIndexofInsertString = textAll.substring(current);
contentTextArea.setText(beforeIndexOfInsertString + text + afterIndexofInsertString);
contentTextArea.getText();
contentTextArea.requestFocus();
insertPosition = contentTextArea.getCaretPosition();
}
private JPanel createNamePane(String name, JComponent comp) {
JPanel namePane = new JPanel(new BorderLayout(4, 4));
namePane.add(new UILabel(name), BorderLayout.NORTH);
namePane.add(comp, BorderLayout.CENTER);
return namePane;
}
private JPanel createTipsPane() {
JPanel tipsPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
tipsPane.setLayout(new BorderLayout(4, 4));
tipsPane.setBorder(BorderFactory.createEmptyBorder(30, 2, 0, 0));
JPanel searchPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
searchPane.setLayout(new BorderLayout(4, 4));
keyWordTextField.setPlaceholder(Toolkit.i18nText("Fine-Design_Search_Interface"));
searchPane.add(keyWordTextField, BorderLayout.CENTER);
//搜索按钮
UIButton searchButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Search"));
searchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String toFind = keyWordTextField.getText();
search(toFind);
popTips();
tipsList.requestFocusInWindow();
}
});
keyWordTextField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
e.consume();
String toFind = keyWordTextField.getText();
search(toFind);
popTips();
tipsList.requestFocusInWindow();
}
}
});
searchPane.add(searchButton, BorderLayout.EAST);
tipsPane.add(searchPane, BorderLayout.NORTH);
tipsList = new JList(tipsListModel);
tipsList.addMouseListener(tipsListMouseListener);
tipsList.addListSelectionListener(tipsListSelectionListener);
tipsList.addKeyListener(tipListKeyListener);
return tipsPane;
}
private void search(String key) {
tipsListModel.removeAllElements();
tipsListModel.clear();
key = key.replaceAll(StringUtils.BLANK, StringUtils.EMPTY);
ArrayList<String> list = new ArrayList<>();
if (!StringUtils.isEmpty(key)) {
List<String> allNames = JSAPITreeHelper.getAllNames();
for (String name : allNames) {
if (searchResult(key, name)) {
list.add(name);
}
}
String finalKey = key;
Collections.sort(list, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
int result;
boolean o1StartWidth = o1.toLowerCase().startsWith(finalKey.toLowerCase());
boolean o2StartWidth = o2.toLowerCase().startsWith(finalKey.toLowerCase());
if (o1StartWidth) {
result = o2StartWidth ? o1.compareTo(o2) : -1;
} else {
result = o2StartWidth ? 1 : o1.compareTo(o2);
}
return result;
}
});
for (String name : list) {
tipsListModel.addElement(name);
}
if (!tipsListModel.isEmpty()) {
tipsList.setSelectedIndex(0);
}
}
}
private boolean searchResult(String key, String interfaceName) {
if (StringUtils.isBlank(key) || StringUtils.isBlank(interfaceName)) {
return false;
}
int length = key.length();
String temp = interfaceName.toUpperCase();
for (int i = 0; i < length; i++) {
String check = key.substring(i, i + 1);
int index = temp.indexOf(check.toUpperCase());
if (index == -1) {
return false;
} else {
temp = temp.substring(index + 1);
}
}
return true;
}
private void initPopTips() {
popupMenu = new JPopupMenu();
JScrollPane tipsScrollPane = new JScrollPane(tipsList);
popupMenu.add(tipsScrollPane);
tipsScrollPane.setPreferredSize(new Dimension(220, 146));
tipsScrollPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, UIConstants.ARC));
}
private void popTips() {
popupMenu.show(keyWordTextField, 0, 23);
}
private ListSelectionListener tipsListSelectionListener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Object selectValue = tipsList.getSelectedValue();
if (selectValue == null) {
return;
}
String interfaceName = selectValue.toString();
fixInterfaceNameList(interfaceName);
}
};
private KeyListener tipListKeyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
Object selectValue = tipsList.getSelectedValue();
if (selectValue == null) {
return;
}
tipListValueSelectAction(selectValue.toString());
if (popupMenu != null) {
popupMenu.setVisible(false);
}
contentTextArea.requestFocusInWindow();
}
}
};
private void tipListValueSelectAction(String value) {
if (ifHasBeenWriten == 0) {
contentTextArea.setForeground(Color.black);
contentTextArea.setText(StringUtils.EMPTY);
}
contentTextArea.setForeground(Color.black);
currentPosition = contentTextArea.getCaretPosition();
String output = value;
String textAll = contentTextArea.getText();
String textReplaced;
int position = 0;
if (insertPosition <= currentPosition) {
textReplaced = textAll.substring(0, insertPosition) + output + textAll.substring(currentPosition);
position = insertPosition + output.length();
} else {
textReplaced = textAll.substring(0, currentPosition) + output + textAll.substring(insertPosition);
position = currentPosition + output.length();
}
contentTextArea.setText(textReplaced);
contentTextArea.setCaretPosition(position);
insertPosition = position;
ifHasBeenWriten = 1;
tipsListModel.removeAllElements();
}
private MouseListener tipsListMouseListener = new MouseAdapter() {
String singlePressContent;
String doublePressContent;
@Override
public void mousePressed(MouseEvent e) {
int index = tipsList.getSelectedIndex();
if (index != -1) {
if (e.getClickCount() == 1) {
singlePressContent = (String) tipsListModel.getElementAt(index);
} else if (e.getClickCount() == 2) {
doublePressContent = (String) tipsListModel.getElementAt(index);
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
int index = tipsList.getSelectedIndex();
if (index != -1) {
if (e.getClickCount() == 1) {
if (ComparatorUtils.equals((String) tipsListModel.getElementAt(index), singlePressContent)) {
singleClickActuator(singlePressContent);
}
} else if (e.getClickCount() == 2) {
if (ComparatorUtils.equals((String) tipsListModel.getElementAt(index), doublePressContent)) {
doubleClickActuator(doublePressContent);
}
if (popupMenu != null) {
popupMenu.setVisible(false);
}
}
}
}
private void singleClickActuator(String currentLineContent) {
setDescription(currentLineContent);
fixInterfaceNameList(currentLineContent);
}
private void doubleClickActuator(String currentLineContent) {
tipListValueSelectAction(currentLineContent);
}
};
}

95
designer-base/src/main/java/com/fr/design/javascript/JavaScriptImplPane.java

@ -9,6 +9,8 @@ import com.fr.design.gui.itableeditorpane.UITableEditAction;
import com.fr.design.gui.itableeditorpane.UITableEditorPane;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.hyperlink.AbstractHyperLinkPane;
import com.fr.design.javascript.jsapi.JSImplPopulateAction;
import com.fr.design.javascript.jsapi.JSImplUpdateAction;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.scrollruler.ModLineBorder;
import com.fr.design.utils.gui.GUICoreUtils;
@ -17,10 +19,16 @@ import com.fr.js.JavaScriptImpl;
import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import java.awt.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -28,11 +36,11 @@ import java.util.List;
public class JavaScriptImplPane extends AbstractHyperLinkPane<JavaScriptImpl> {
private static final int BOTTOM_BORDER = 12;
private UITextField itemNameTextField;
private JSContentPane jsPane;
protected JSContentPane jsPane;
private UITableEditorPane<String> importedJsPane;
private ReportletParameterViewPane parameterPane;
private String[] defaultArgs;
private boolean modal;
public JavaScriptImplPane() {
this(new String[0]);
@ -50,8 +58,57 @@ public class JavaScriptImplPane extends AbstractHyperLinkPane<JavaScriptImpl> {
initComponents();
}
public JavaScriptImplPane(String[] args, boolean modal) {
this.modal = modal;
this.defaultArgs = args;
initComponents();
}
protected void initComponents() {
parameterPane = new ReportletParameterViewPane(getChartParaType(), getValueEditorPane(), getValueEditorPane());
parameterPane = createParameterViewPane();
importedJsPane = createImportedJsPane();
importedJsPane.setPreferredSize(new Dimension(265, 150));
jsPane = createJSContentPane(defaultArgs);
jsPane.setBorder(BorderFactory.createTitledBorder(new ModLineBorder(ModLineBorder.TOP), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_JavaScript")));
parameterPane.setPreferredSize(new Dimension(265, 150));
JPanel topPane = new JPanel(new GridLayout(1,2));
topPane.add(importedJsPane);
topPane.add(parameterPane);
topPane.setBorder(BorderFactory.createEmptyBorder(0, 0, BOTTOM_BORDER, 0));
this.setLayout(new BorderLayout());
this.add(topPane, BorderLayout.NORTH);
this.add(jsPane, BorderLayout.CENTER);
this.reLayoutForChart();
}
protected JSContentPane createJSContentPane(String[] defaultArgs){
JSContentPane jsContentPane= new JSContentPane(defaultArgs,modal);
jsContentPane.setJsImplUpdateAction(new JSImplUpdateAction() {
@Override
public void update(JavaScriptImpl javaScript) {
if(javaScript != null){
updateBean(javaScript);
}
}
});
jsContentPane.setJsImplPopulateAction(new JSImplPopulateAction() {
@Override
public void populate(JavaScriptImpl javaScript) {
if(javaScript != null){
populateBean(javaScript);
}
}
});
return jsContentPane;
}
protected ReportletParameterViewPane createParameterViewPane(){
ReportletParameterViewPane parameterPane = new ReportletParameterViewPane(getChartParaType(), getValueEditorPane(), getValueEditorPane());
parameterPane.setBorder(BorderFactory.createTitledBorder(new ModLineBorder(ModLineBorder.TOP), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Parameter")));
parameterPane.addTableEditorListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
@ -72,7 +129,10 @@ public class JavaScriptImplPane extends AbstractHyperLinkPane<JavaScriptImpl> {
parameterChanger(list);
}
});
return parameterPane;
}
protected UITableEditorPane<String> createImportedJsPane(){
OneListTableModel<String> model = new OneListTableModel<String>(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_ReportServerP_Import_JavaScript"), this) {
public UITableEditAction[] createAction() {
@ -84,26 +144,12 @@ public class JavaScriptImplPane extends AbstractHyperLinkPane<JavaScriptImpl> {
return new AddJsAction();
}
};
importedJsPane = new UITableEditorPane<String>(model);
UITableEditorPane<String> importedJsPane = new UITableEditorPane<String>(model);
importedJsPane.setBorder(BorderFactory.createTitledBorder(new ModLineBorder(ModLineBorder.TOP), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_ReportServerP_Import_JavaScript")));
importedJsPane.setPreferredSize(new Dimension(265, 150));
jsPane = new JSContentPane(defaultArgs);
jsPane.setBorder(BorderFactory.createTitledBorder(new ModLineBorder(ModLineBorder.TOP), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_JavaScript")));
return importedJsPane;
}
parameterPane.setPreferredSize(new Dimension(265, 150));
JPanel topPane = GUICoreUtils.createBorderLayoutPane(
importedJsPane, BorderLayout.CENTER,
parameterPane, BorderLayout.EAST
);
topPane.setPreferredSize(new Dimension(300, 150));
topPane.setBorder(BorderFactory.createEmptyBorder(0, 0, BOTTOM_BORDER, 0));
this.setLayout(new BorderLayout());
this.add(topPane, BorderLayout.NORTH);
this.add(jsPane, BorderLayout.CENTER);
this.reLayoutForChart();
}
/**
* 参数改变
@ -140,10 +186,10 @@ public class JavaScriptImplPane extends AbstractHyperLinkPane<JavaScriptImpl> {
if (javaScriptImpl == null) {
javaScriptImpl = new JavaScriptImpl();
jsPane.reset();
}else{
} else {
jsPane.populate(javaScriptImpl.getContent());
}
jsPane.updateJSImpl(javaScriptImpl);
int rowCount = javaScriptImpl.getJSImportSize();
String[] value = new String[rowCount];
for (int i = 0; i < rowCount; i++) {
@ -160,6 +206,7 @@ public class JavaScriptImplPane extends AbstractHyperLinkPane<JavaScriptImpl> {
public JavaScriptImpl updateBean() {
JavaScriptImpl javaScript = new JavaScriptImpl();
updateBean(javaScript);
jsPane.updateJSImpl(javaScript);
return javaScript;
}

23
designer-base/src/main/java/com/fr/design/javascript/NewJavaScriptImplPane.java

@ -0,0 +1,23 @@
package com.fr.design.javascript;
import com.fr.js.JavaScriptImpl;
public class NewJavaScriptImplPane extends JavaScriptImplPane {
public NewJavaScriptImplPane(String[] args) {
super(args);
}
protected JSContentPane createJSContentPane(String[] defaultArgs){
return new JSContentWithDescriptionPane(defaultArgs);
}
public void populate(JavaScriptImpl javaScript) {
if (javaScript != null) {
populateBean(javaScript);
} else {
jsPane.reset();
}
}
}

21
designer-base/src/main/java/com/fr/design/javascript/jsapi/CategoryTreeNodesUserObject.java

@ -0,0 +1,21 @@
package com.fr.design.javascript.jsapi;
import com.fr.design.i18n.Toolkit;
public class CategoryTreeNodesUserObject implements JSAPIUserObject {
private String value;
public CategoryTreeNodesUserObject(String value) {
this.value = value;
}
@Override
public String getValue() {
return value;
}
@Override
public String getDisplayText() {
return Toolkit.i18nText(value);
}
}

155
designer-base/src/main/java/com/fr/design/javascript/jsapi/JSAPITreeHelper.java

@ -0,0 +1,155 @@
package com.fr.design.javascript.jsapi;
import com.fr.general.IOUtils;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.tree.DefaultMutableTreeNode;
public class JSAPITreeHelper {
private static final String JSAPI_PATH = "com/fr/design/javascript/jsapi/jsapi.json";
private static final String CATEGORY_PATH = "com/fr/design/javascript/jsapi/category.json";
private static JSONObject categoryJSON ;
private static JSONObject jsapiJSON ;
static {
jsapiJSON = createJSON(JSAPI_PATH);
categoryJSON = createJSON(CATEGORY_PATH);
}
private static JSONObject createJSON(String path) {
StringBuilder jsonString = new StringBuilder(StringUtils.EMPTY);
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(IOUtils.readResource(path)))) {
String s;
while ((s = bufferedReader.readLine()) != null) {
jsonString.append(s);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return new JSONObject(jsonString.toString());
}
public static void createJSAPITree(DefaultMutableTreeNode rootNode) {
createJSAPITree(categoryJSON, rootNode);
}
public static String getDirectCategory(String name) {
if (jsapiJSON != null) {
Iterator<String> it = jsapiJSON.keys();
while (it.hasNext()) {
String key = it.next();
JSONArray nameArray = jsapiJSON.optJSONArray(key);
for (int i = 0; i < nameArray.length(); i++) {
if (StringUtils.equals(nameArray.getString(i), name)) {
return key;
}
}
}
}
return null;
}
private static void createJSAPITree(JSONObject jsonObject, DefaultMutableTreeNode rootNode) {
if (jsonObject != null && rootNode != null) {
Iterator<String> it = jsonObject.keys();
while (it.hasNext()) {
String key = it.next();
JSONObject subNode = jsonObject.optJSONObject(key);
if (subNode.size() == 0) {
rootNode.add(new DefaultMutableTreeNode(new CategoryTreeNodesUserObject(key)));
} else {
DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(new CategoryTreeNodesUserObject(key));
rootNode.add(treeNode);
createJSAPITree(subNode, treeNode);
}
}
}
}
private static List<String> getAllSubNodes(String name) {
return getAllSubNodes(name, categoryJSON);
}
public static List<String> getAllNames() {
ArrayList<String> result = new ArrayList<>();
if (jsapiJSON != null) {
Iterator<String> it = jsapiJSON.keys();
while (it.hasNext()) {
String key = it.next();
JSONArray nameArray = jsapiJSON.optJSONArray(key);
for (int i = 0; i < nameArray.length(); i++) {
result.add(nameArray.getString(i));
}
}
}
return result;
}
public static List<String> getNames(String category) {
ArrayList<String> result = new ArrayList<>();
List<String> subCategories = getAllSubNodes(category);
if (jsapiJSON != null) {
for (String subCategory : subCategories) {
if (jsapiJSON.containsKey(subCategory)) {
JSONArray nameArray = jsapiJSON.optJSONArray(subCategory);
for (int i = 0; i < nameArray.length(); i++) {
result.add(nameArray.getString(i));
}
}
}
}
return result;
}
private static List<String> getAllSubNodes(String name, JSONObject jsonObject) {
ArrayList<String> result = new ArrayList<>();
if (jsonObject != null) {
Iterator<String> it = jsonObject.keys();
while (it.hasNext()) {
String key = it.next();
JSONObject subNode = jsonObject.optJSONObject(key);
if (subNode.size() == 0) {
if (StringUtils.equals(key, name)) {
result.add(key);
return result;
}
} else {
if (StringUtils.equals(key, name)) {
result.add(key);
result.addAll(getAllSubNodes(subNode));
return result;
} else {
result.addAll(getAllSubNodes(name, subNode));
}
}
}
}
return result;
}
private static List<String> getAllSubNodes(JSONObject jsonObject) {
ArrayList<String> result = new ArrayList<>();
if (jsonObject != null) {
Iterator<String> it = jsonObject.keys();
while (it.hasNext()) {
String key = it.next();
JSONObject subNode = jsonObject.optJSONObject(key);
if (subNode.size() == 0) {
result.add(key);
} else {
result.add(key);
result.addAll(getAllSubNodes(subNode));
}
}
}
return result;
}
}

9
designer-base/src/main/java/com/fr/design/javascript/jsapi/JSAPIUserObject.java

@ -0,0 +1,9 @@
package com.fr.design.javascript.jsapi;
public interface JSAPIUserObject {
String getValue();
String getDisplayText();
}

7
designer-base/src/main/java/com/fr/design/javascript/jsapi/JSImplPopulateAction.java

@ -0,0 +1,7 @@
package com.fr.design.javascript.jsapi;
import com.fr.js.JavaScriptImpl;
public interface JSImplPopulateAction {
void populate(JavaScriptImpl javaScript);
}

7
designer-base/src/main/java/com/fr/design/javascript/jsapi/JSImplUpdateAction.java

@ -0,0 +1,7 @@
package com.fr.design.javascript.jsapi;
import com.fr.js.JavaScriptImpl;
public interface JSImplUpdateAction {
void update(JavaScriptImpl javaScript);
}

7
designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java

@ -28,6 +28,8 @@ import com.fr.design.fun.impl.AbstractTemplateTreeShortCutProvider;
import com.fr.design.gui.iprogressbar.ProgressDialog;
import com.fr.design.gui.iscrollbar.UIScrollBar;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.share.mini.MiniShopDisposingChecker;
import com.fr.design.mainframe.share.mini.MiniShopNativeTaskManager;
import com.fr.design.mainframe.toolbar.ToolBarMenuDock;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import com.fr.design.mainframe.vcs.common.VcsHelper;
@ -157,6 +159,11 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
@Override
public void windowClosing(WindowEvent e) {
// 检查mini商城是否存在未结束的后台任务
if (!MiniShopDisposingChecker.check()) {
return;
}
// 关闭前check
if (!TemplateSavingChecker.check()) {
return;

16
designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

@ -2,6 +2,7 @@ package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.base.Parameter;
import com.fr.base.TRL;
import com.fr.base.extension.FileExtension;
import com.fr.base.io.BaseBook;
import com.fr.base.iofile.attr.DesignBanCopyAttrMark;
@ -105,9 +106,9 @@ import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.undo.UndoManager;
import java.awt.BorderLayout;
import java.io.ByteArrayOutputStream;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.io.ByteArrayOutputStream;
import java.util.Set;
import java.util.concurrent.Callable;
@ -1000,7 +1001,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
return true;
}
public boolean isNewCreateTpl(){
public boolean isNewCreateTpl() {
return isNewCreateTpl;
}
@ -1543,7 +1544,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
/**
* 设置新引擎后有不支持的功能时设计器中模板的标题需要加上兼容模式或者不支持分页引擎来提示用户
* */
*/
private String compatibilityTip() {
if (!CptAndCptxCompatibilityUtil.isEngineXEnable(this.getTarget(), getEditingFILE().getPath())) {
return StringUtils.EMPTY;
@ -1888,6 +1889,15 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
templateThemeButton.setToolTipText(name);
}
/**
* 定位
*
* @param trl
*/
public void navigate(TRL trl) {
}
public void generateForBiddenTemplate() {
}

12
designer-base/src/main/java/com/fr/design/mainframe/form/FormECDesignerProvider.java

@ -1,10 +1,6 @@
package com.fr.design.mainframe.form;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import com.fr.base.TRL;
import com.fr.design.designer.TargetComponent;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.menu.MenuDef;
@ -12,6 +8,10 @@ import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef;
import com.fr.form.FormElementCaseProvider;
import javax.swing.JComponent;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
public interface FormECDesignerProvider {
String XML_TAG = "FormElementCaseDesigner";
@ -92,4 +92,6 @@ public interface FormECDesignerProvider {
void refreshPropertyPane();
void removeSelection();
default void navigate(TRL trl) {}
}

186
designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogHandler.java

@ -1,31 +1,46 @@
package com.fr.design.mainframe.loghandler;
import com.finebi.cbb.base.tuple.Pair;
import com.fr.base.BaseUtils;
import com.fr.base.TRL;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.ui.util.UIUtil;
import com.fr.file.FILEFactory;
import com.fr.general.ComparatorUtils;
import com.fr.general.log.Log4jConfig;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.third.apache.logging.log4j.Level;
import com.fr.third.apache.logging.log4j.core.LogEvent;
import com.fr.third.guava.base.Splitter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTextPane;
import javax.swing.KeyStroke;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
@ -36,8 +51,14 @@ import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Date;
import java.util.Deque;
import java.util.List;
import java.util.regex.Pattern;
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
@ -61,6 +82,8 @@ public class DesignerLogHandler {
private static final String ACTION_MAP_KEY = "clear";
private static final Pattern pattern = Pattern.compile("\\([^(]*.(?>cpt|frm|cptx)[^)]*\\)");
public static DesignerLogHandler getInstance() {
return HOLDER.singleton;
@ -215,13 +238,61 @@ public class DesignerLogHandler {
popup.show(jTextArea, event.getX(), event.getY());
checkEnabled();
}
if (event.getButton() == MouseEvent.BUTTON1) {
String url = findTplLinkFromMouseEvent(event);
if (StringUtils.isNotEmpty(url)) {
navigate(url);
}
}
}
});
}
/**
* 将模板定位链接导航到指定的位置
*
* @param href 模板定位链接
*/
private void navigate(String href) {
if (!href.startsWith(TRL.PREFIX)) {
return;
}
TRL trl = new TRL(href);
DesignerContext.getDesignerFrame().openTemplate(FILEFactory.createFILE(ProjectConstants.REPORTLETS_NAME + FILEFactory.SEPARATOR + trl.getTemplatePath()));
JTemplate<?, ?> currentEditingTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (currentEditingTemplate != null) {
currentEditingTemplate.navigate(trl);
}
}
/**
* 鼠标事件中定位到模板链接
*
* @param event 鼠标事件
* @return 模板链接
*/
private String findTplLinkFromMouseEvent(MouseEvent event) {
JEditorPane editor = (JEditorPane) event.getSource();
int pos = editor.getUI().viewToModel(editor, event.getPoint());
if (pos >= 0 && editor.getDocument() instanceof HTMLDocument) {
HTMLDocument hdoc = (HTMLDocument) editor.getDocument();
Element elem = hdoc.getCharacterElement(pos);
Object a = elem.getAttributes().getAttribute(HTML.Tag.A);
if (a instanceof AttributeSet) {
AttributeSet set = (AttributeSet) a;
String url = (String) set.getAttribute(HTML.Attribute.HREF);
if (StringUtils.isNotEmpty(url)) {
return url;
}
}
}
return StringUtils.EMPTY;
}
private JTextPane initLogJTextArea() {
final JTextPane resultPane = new JTextPane();
resultPane.setContentType("text/html");
InputMap inputMap = resultPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), DefaultEditorKit.selectAllAction);
@ -294,6 +365,9 @@ public class DesignerLogHandler {
SimpleAttributeSet attrSet = new SimpleAttributeSet();
if (style == DesignerLogger.ERROR_INT) {
if (renderLink(str)) {
return;
}
StyleConstants.setForeground(attrSet, Color.RED);
StyleConstants.setBold(attrSet, true);
} else if (style == DesignerLogger.WARN_INT) {
@ -314,6 +388,86 @@ public class DesignerLogHandler {
}
}
/**
* 渲染模板链接
*
* @param str 可能包含模板链接字符串
* @return 是否处理成功
*/
private boolean renderLink(String str) {
Document doc = jTextArea.getStyledDocument();
if (doc instanceof HTMLDocument) {
String[] tplLink = findTplLink(str);
return tplLink != null
&& tplLink.length > 0
&& link2Html(str, tplLink);
}
return false;
}
/**
* 处理模板链接
*
* @param s 含有模板链接
* @param tplLink 模板链接
* @return 是否处理成功
*/
private boolean link2Html(String s, String[] tplLink) {
List<String> lineSeg = splitLineSeg(s, tplLink);
String html = buildHtml(lineSeg, tplLink);
try {
Document doc = jTextArea.getStyledDocument();
HTMLDocument htmlDocument = (HTMLDocument) doc;
htmlDocument.insertAfterEnd(htmlDocument.getCharacterElement(doc.getLength()), html);
} catch (BadLocationException | IOException ignored) {
// 这里出问题不记录日志否则会导致死循环
return false;
}
return true;
}
@NotNull
private String buildHtml(List<String> lineSeg, String[] tplLink) {
StringBuilder sb = new StringBuilder("<span style=\"font-weight: bold;font-size:" + jTextArea.getFont().getSize() + "\">");
for (int i = 0; i < tplLink.length; i++) {
sb.append("<span style=\"color:red;\">")
.append(lineSeg.get(i))
.append("</span><a href=\"tpl://")
.append(tplLink[i], 1, tplLink[i].length() - 1)
.append("\">")
.append(tplLink[i])
.append("</a>");
}
if (lineSeg.size() > tplLink.length) {
sb.append("<span style=\"color:red;\">").append(lineSeg.get(lineSeg.size() - 1)).append("</span>");
}
sb.append("</span>");
return sb.toString();
}
/**
* 将非公式部分切割为数组
*/
@NotNull
private List<String> splitLineSeg(String s, String[] tplLink) {
String seg = s.replaceAll("\\n", "<br/>");
List<String> lineSeg = new ArrayList<>(2);
List<String> lineSegTmp = new ArrayList<>();
String tmp = seg;
for (String link : tplLink) {
lineSegTmp = Splitter.on(link).omitEmptyStrings().splitToList(tmp);
lineSeg.add(lineSegTmp.get(0));
if (lineSegTmp.size() > 1) {
tmp = lineSegTmp.get(1);
}
}
if (lineSegTmp.size() > 1) {
lineSeg.add(lineSegTmp.get(1));
}
return lineSeg;
}
private String appendLocaleMark(String str, int style) {
if (style == DesignerLogger.ERROR_INT) {
@ -375,4 +529,34 @@ public class DesignerLogHandler {
};
}
/**
* 尝试找到模板链接
*
* @param s 可能含有模板链接的字符串
* @return 模板链接
*/
@Nullable
public static String[] findTplLink(String s) {
List<String> list = new ArrayList<>();
// 栈配对
Deque<Pair<Character, Integer>> stack = new ArrayDeque<>();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '(') {
stack.push(new Pair<>(c, i));
} else if (c == ')') {
Pair<Character, Integer> left = stack.peek();
if (left != null && left.getFirst() == '(') {
Pair<Character, Integer> pop = stack.pop();
String link = s.substring(pop.getSecond(), i + 1);
if (link.contains(ProjectConstants.CPT_SUFFIX)
|| link.contains(ProjectConstants.FRM_SUFFIX)) {
list.add(link);
}
}
}
}
return list.toArray(new String[0]);
}
}

40
designer-base/src/main/java/com/fr/design/mainframe/predefined/PatternStyle.java

@ -1,40 +0,0 @@
package com.fr.design.mainframe.predefined;
import com.fr.config.predefined.PredefinedStyle;
//import com.fr.predefined.PredefinedPatternStyleManager;
/**
* Created by kerry on 2020-08-31
*/
public enum PatternStyle {
DARK_STYLE(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Dark_Pattern")) {
@Override
public PredefinedStyle getPredefinedStyle() {
// return PredefinedPatternStyleManager.INSTANCE.getDarkMode();
return new PredefinedStyle();
}
},
LIGHT_STYLE(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Light_Pattern")) {
@Override
public PredefinedStyle getPredefinedStyle() {
// return PredefinedPatternStyleManager.INSTANCE.getLightMode();
return new PredefinedStyle();
}
};
private String name;
PatternStyle(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public abstract PredefinedStyle getPredefinedStyle();
}

143
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleBlock.java

@ -1,143 +0,0 @@
package com.fr.design.mainframe.predefined.ui;
import com.fr.base.BaseUtils;
import com.fr.base.GraphHelper;
import com.fr.config.predefined.PredefinedStyle;
import com.fr.design.mainframe.predefined.ui.dialog.PredefinedStyleEditDialog;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.predefined.ui.preview.PredefinedStylePreviewPane;
import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.stable.Constants;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* Created by kerry on 2020-08-25
*/
public class PredefinedStyleBlock extends JPanel {
private PredefinedStyle previewObject;
private PredefinedStyleSelectPane parentPane;
private Icon markedMode = IOUtils.readIcon("/com/fr/design/form/images/marker_selected.png");
private static final Color BORDER_COLOR = new Color(141, 194, 249);
private boolean mouseOver = false;
private MouseListener mouseListener = new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
setSelect();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
mouseOver = true;
PredefinedStyleBlock.this.repaint();
}
@Override
public void mouseExited(MouseEvent e) {
mouseOver = false;
PredefinedStyleBlock.this.repaint();
}
};
public PredefinedStyleBlock(PredefinedStyle previewObject, PredefinedStyleSelectPane selectPane, boolean supportEdit) {
this.previewObject = previewObject;
this.parentPane = selectPane;
initPane(supportEdit);
this.addMouseListener(mouseListener);
}
private void setSelect() {
this.parentPane.setSelectedPreviewPane(this);
}
@Override
public void paint(Graphics g) {
super.paint(g);
boolean isSelected = ComparatorUtils.equals(this, this.parentPane.getSelectedPreviewPane());
if (ComparatorUtils.equals(this.parentPane.getCurrentApplicateStyle(), this.previewObject.getStyleName())) {
markedMode.paintIcon(this, g, 176, 0);
}
if (isSelected || this.mouseOver) {
g.setColor(BORDER_COLOR);
Rectangle rectangle = new Rectangle(1, 1, this.getWidth() - 2, this.getHeight() - 2);
GraphHelper.draw(g, rectangle, Constants.LINE_MEDIUM);
}
}
private void initPane(boolean supportEdit) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
PredefinedStylePreviewPane content = new PredefinedStylePreviewPane(0.387, 0.384);
content.setParent(this);
content.setPreferredSize(new Dimension(200, 180));
UILabel label = new UILabel(previewObject.getStyleName());
label.setToolTipText(previewObject.getStyleName());
label.setPreferredSize(new Dimension(167, 25));
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane();
panel.setBorder(BorderFactory.createEmptyBorder(0,9,2,5));
panel.add(label, BorderLayout.WEST);
if (supportEdit) {
addEditButton(panel);
}
this.add(content, BorderLayout.CENTER);
this.add(panel, BorderLayout.SOUTH);
this.setPreferredSize(new Dimension(200, 210));
panel.setBackground(Color.WHITE);
this.setBackground(Color.WHITE);
content.refresh(this.previewObject);
}
private void addEditButton(JPanel panel) {
UIButton editButton = new UIButton(BaseUtils.readIcon("/com/fr/design/icon/icon_edit.png"));
editButton.setPreferredSize(new Dimension(24, 24));
editButton.setBorderPainted(false);
editButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PredefinedStyleEditPane editPane = PredefinedStyleEditPane.createEditPane(parentPane);
PredefinedStyleEditDialog editDialog = new PredefinedStyleEditDialog(
SwingUtilities.getWindowAncestor(PredefinedStyleBlock.this), editPane, previewObject.isBuiltIn());
editPane.populate(PredefinedStyleBlock.this.previewObject);
editDialog.setVisible(true);
}
});
panel.add(editButton, BorderLayout.EAST);
}
public PredefinedStyle update() {
return this.previewObject;
}
}

374
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleEditPane.java

@ -1,374 +0,0 @@
package com.fr.design.mainframe.predefined.ui;
import com.fr.base.ChartColorMatching;
import com.fr.base.ChartPreStyleConfig;
import com.fr.base.Style;
import com.fr.base.background.ColorBackground;
import com.fr.config.predefined.ColorFillStyle;
import com.fr.config.predefined.PredefinedCellStyle;
import com.fr.config.predefined.PredefinedCellStyleConfig;
import com.fr.config.predefined.PredefinedColorStyle;
import com.fr.config.predefined.PredefinedStyle;
import com.fr.config.predefined.PredefinedStyleConfig;
import com.fr.config.ServerPreferenceConfig;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.frpane.AbstractAttrNoScrollPane;
import com.fr.design.gui.frpane.AttributeChangeListener;
import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.predefined.ui.detail.ChartStyleSettingPane;
import com.fr.design.mainframe.predefined.ui.detail.ColorFillStylePane;
import com.fr.design.mainframe.predefined.ui.detail.PredefinedBackgroundSettingPane;
import com.fr.design.mainframe.predefined.ui.detail.ComponentStyleSettingPane;
import com.fr.design.mainframe.predefined.ui.detail.CellStyleListControlPane;
import com.fr.design.mainframe.predefined.ui.preview.PredefinedStylePreviewPane;
import com.fr.design.ui.util.UIUtil;
import com.fr.design.utils.DesignUtils;
import com.fr.general.FRFont;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import com.fr.transaction.Configurations;
import com.fr.transaction.WorkerFacade;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Created by kerry on 2020-08-26
*/
public class PredefinedStyleEditPane extends AbstractAttrNoScrollPane {
private static final Color TIP_COLOR = Color.decode("#8F8F92");
private PredefinedStylePreviewPane previewPane;
private UITextField styleNameField;
private PredefinedBackgroundSettingPane backgroundSettingPane;
private CellStyleListControlPane cellStyleSettingPane;
private ComponentStyleSettingPane componentStyleSettingPane;
private ChartStyleSettingPane chartStyleSettingPane;
private PredefinedStyleSelectPane selectPane;
private ColorFillStylePane colorFillStylePane;
private boolean isPopulating = false;
private UITabbedPane uiTabbedPane;
private boolean isLightMode = true;
@Override
protected JPanel createContentPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
jPanel.add(createLeftPane(), BorderLayout.WEST);
jPanel.add(createRightPane(), BorderLayout.CENTER);
this.addAttributeChangeListener(new AttributeChangeListener() {
@Override
public void attributeChange() {
if (!isPopulating) {
valueChangeAction();
}
}
});
return jPanel;
}
public void valueChangeAction() {
boolean displayFormBackground = backgroundSettingPane.currentFormBackground() || uiTabbedPane.getSelectedIndex() == 3;
previewPane.refresh(this.update(), displayFormBackground);
}
@Override
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Style_Edit");
}
private PredefinedStyleEditPane(PredefinedStyleSelectPane selectPane, boolean newEditPane) {
this.selectPane = selectPane;
this.styleNameField.setEnabled(newEditPane);
}
public static PredefinedStyleEditPane createEditPane(PredefinedStyleSelectPane selectPane) {
return new PredefinedStyleEditPane(selectPane, false);
}
public static PredefinedStyleEditPane createNewEditPane(PredefinedStyleSelectPane selectPane) {
return new PredefinedStyleEditPane(selectPane, true);
}
private JPanel createLeftPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel titlePane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Overall_Preview"));
previewPane = new PredefinedStylePreviewPane();
previewPane.setPreferredSize(new Dimension(517, 500));
titlePane.add(previewPane);
jPanel.add(titlePane, BorderLayout.CENTER);
return jPanel;
}
private JPanel createRightPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel styleNamePane = createStyleNamePane();
jPanel.add(styleNamePane, BorderLayout.NORTH);
JPanel basicSettingPane = createBasicSettingPane();
jPanel.add(basicSettingPane, BorderLayout.CENTER);
JPanel customDetailPane = createCustomDetailPane();
jPanel.add(customDetailPane, BorderLayout.SOUTH);
return jPanel;
}
private JPanel createStyleNamePane() {
JPanel jPanel = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(5, 26, 8);
jPanel.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Style_Name")));
this.styleNameField = new UITextField();
this.styleNameField.setPreferredSize(new Dimension(160, 20));
jPanel.add(this.styleNameField);
return jPanel;
}
private JPanel createBasicSettingPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel titlePane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Basic_Setting"));
JPanel contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
colorFillStylePane = new ColorFillStylePane();
contentPane.add(colorFillStylePane);
titlePane.add(contentPane);
jPanel.add(titlePane, BorderLayout.CENTER);
titlePane.setSize(new Dimension(348, 157));
return jPanel;
}
private JPanel createCustomDetailPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel titlePane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Custom_Detail"));
titlePane.setLayout(FRGUIPaneFactory.createLeftZeroLayout());
jPanel.add(titlePane, BorderLayout.CENTER);
uiTabbedPane = new UITabbedPane();
uiTabbedPane.addTab(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Template_Background"), createTemplateBackgroundSettingPane());
uiTabbedPane.addTab(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Cell_Style"), createCellStyleSettingPane());
uiTabbedPane.addTab(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Chart_Style"), createChartStyleSettingPane());
uiTabbedPane.addTab(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Component_Style"), createComponentStyleSettingPane());
uiTabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
valueChangeAction();
}
});
titlePane.add(uiTabbedPane);
uiTabbedPane.setPreferredSize(new Dimension(323, 298));
titlePane.setPreferredSize(new Dimension(333, 320));
return jPanel;
}
private JPanel createTemplateBackgroundSettingPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
jPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
this.backgroundSettingPane = new PredefinedBackgroundSettingPane();
jPanel.setPreferredSize(new Dimension(309, 248));
UIScrollPane scrollPane = new UIScrollPane(this.backgroundSettingPane);
scrollPane.setBorder(BorderFactory.createEmptyBorder());
jPanel.add(new UIScrollPane(this.backgroundSettingPane));
return jPanel;
}
private JPanel createCellStyleSettingPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
jPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
this.cellStyleSettingPane = new CellStyleListControlPane();
this.cellStyleSettingPane.registerAttrChangeListener(new AttributeChangeListener() {
@Override
public void attributeChange() {
valueChangeAction();
}
});
jPanel.add(this.cellStyleSettingPane);
return jPanel;
}
private JPanel createChartStyleSettingPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
jPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
this.chartStyleSettingPane = new ChartStyleSettingPane();
jPanel.add(this.chartStyleSettingPane);
return jPanel;
}
private JPanel createComponentStyleSettingPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
jPanel.setLayout(new BorderLayout(0, 5));
jPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
this.componentStyleSettingPane = new ComponentStyleSettingPane();
UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_ComponentStyle_Setting_Tip"));
label.setForeground(TIP_COLOR);
jPanel.add(label, BorderLayout.NORTH);
jPanel.add(this.componentStyleSettingPane, BorderLayout.CENTER);
return jPanel;
}
public void populate(PredefinedStyle previewObject) {
isPopulating = true;
isLightMode = previewObject.isLightMode();
styleNameField.setText(previewObject.getStyleName());
this.backgroundSettingPane.populateBean(previewObject.getPredefinedBackground());
this.cellStyleSettingPane.populateBean(previewObject.getCellStyleConfig());
this.componentStyleSettingPane.populateBean(previewObject.getComponentStyle());
this.colorFillStylePane.populateBean(previewObject.getPredefinedColorStyle());
this.chartStyleSettingPane.populateBean(previewObject.getPredefinedChartStyle());
previewPane.refresh(previewObject);
isPopulating = false;
}
public PredefinedStyle update() {
PredefinedStyle predefinedStyle = new PredefinedStyle();
predefinedStyle.setLightMode(isLightMode);
predefinedStyle.setStyleName(this.styleNameField.getText());
PredefinedCellStyleConfig cellStyleConfig = this.cellStyleSettingPane.updateBean();
predefinedStyle.setCellStyleConfig(cellStyleConfig);
predefinedStyle.setPredefinedBackground(this.backgroundSettingPane.updateBean());
predefinedStyle.setComponentStyle(this.componentStyleSettingPane.updateBean());
PredefinedColorStyle colorStyle = this.colorFillStylePane.update();
updateCellStyleByColorStyle(colorStyle, cellStyleConfig);
predefinedStyle.setPredefinedColorStyle(colorStyle);
predefinedStyle.setPredefinedChartStyle(this.chartStyleSettingPane.updateBean());
return predefinedStyle;
}
private void updateCellStyleByColorStyle(PredefinedColorStyle colorStyle, PredefinedCellStyleConfig cellStyleConfig) {
PredefinedCellStyle headerStyle = cellStyleConfig.getStyle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header"));
PredefinedCellStyle highlightStyle = cellStyleConfig.getStyle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Highlight_Text"));
ColorFillStyle colorFillStyle = colorStyle.getColorFillStyle();
List<Color> colorList = new ArrayList<>();
if (colorFillStyle == null || colorFillStyle.getColorList().size() == 0){
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance();
String defaultName = config.getCurrentStyle();
ChartColorMatching defaultStyle = (ChartColorMatching) config.getPreStyle(defaultName);
if (defaultStyle != null) {
colorList = defaultStyle.getColorList();
}
} else {
colorList = colorFillStyle.getColorList();
}
if (colorList.size() < 2) {
return;
}
if (headerStyle != null) {
Style style = headerStyle.getStyle();
Color color = colorList.get(0);
headerStyle.setStyle(style.deriveBackground(ColorBackground.getInstance(color)));
}
if (highlightStyle != null) {
Style style = highlightStyle.getStyle();
Color color = colorList.get(1);
FRFont font = style.getFRFont();
font.setForeground(color);
highlightStyle.setStyle(style.deriveFRFont(font));
}
}
public boolean saveStyle() {
PredefinedStyle previewObject;
try {
previewObject = update();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
}
if (this.styleNameField.isEnabled() && !validateRepeat(previewObject.getStyleName())) {
return false;
}
if (!saveStyle(previewObject)) {
return false;
}
HistoryTemplateListCache.getInstance().repaintCurrentEditingTemplate();
return true;
}
private boolean saveStyle(PredefinedStyle previewObject) {
PredefinedStyleConfig config = ServerPreferenceConfig.getInstance().getPreferenceStyleConfig();
if (StringUtils.isEmpty(previewObject.getStyleName())) {
FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(PredefinedStyleEditPane.this),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Name_Cannot_Empty"));
return false;
}
config.add(previewObject);
PredefinedStyleConfig sortedConfig = resortConfigStyles(previewObject, config);
// Configurations.modify(new WorkerFacade(ServerPreferenceConfig.class) {
// @Override
// public void run() {
// ServerPreferenceConfig.getInstance().setPreferenceStyleConfig(sortedConfig);
// }
// });
selectPane.refreshPane();
return true;
}
public void saveAsNewStyle(String styleName) {
PredefinedStyle previewObject;
try {
previewObject = update();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return;
}
previewObject.setStyleName(styleName);
if (validateRepeat(styleName)) {
saveStyle(previewObject);
}
}
private boolean validateRepeat(String styleName) {
PredefinedStyleConfig config = ServerPreferenceConfig.getInstance().getPreferenceStyleConfig();
if (config.getStyle(styleName) != null) {
FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(PredefinedStyleEditPane.this),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Name_Repeat"));
return false;
}
return true;
}
private PredefinedStyleConfig resortConfigStyles(PredefinedStyle priorityStyle, PredefinedStyleConfig config){
PredefinedStyleConfig sortedConfig = new PredefinedStyleConfig();
PredefinedStyle defaultStyle = config.getDefaultPredefinedStyle();
if (defaultStyle != null) {
sortedConfig.add(defaultStyle);
config.removeStyle(defaultStyle.getStyleName());
sortedConfig.setDefaultPredefinedStyle(defaultStyle.getStyleName());
}
if (priorityStyle != null && !priorityStyle.isDefaultStyle()) {
sortedConfig.add(priorityStyle);
config.removeStyle(priorityStyle.getStyleName());
}
Iterator<PredefinedStyle> iterator = config.getPredefinedStyleIterator();
while (iterator.hasNext()) {
PredefinedStyle entry = iterator.next();
sortedConfig.add(entry);
}
sortedConfig.setCompatibleStyleName(config.getCompatibleStyleName());
return sortedConfig;
}
}

102
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleSelectPane.java

@ -1,102 +0,0 @@
package com.fr.design.mainframe.predefined.ui;
import com.fr.config.ServerPreferenceConfig;
import com.fr.config.predefined.PredefinedStyle;
import com.fr.design.dialog.BasicPane;
import com.fr.design.event.ChangeListener;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.layout.FRGUIPaneFactory;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.util.Iterator;
import java.awt.BorderLayout;
import java.awt.Dimension;
/**
* Created by kerry on 2020-08-26
*/
public class PredefinedStyleSelectPane extends BasicPane {
private PredefinedStyleBlock selectedBlock;
private boolean editable;
private JPanel contentPane;
private String currentApplicateStyle;
private ChangeListener changeListener;
public PredefinedStyleSelectPane(String currentApplicateStyle, boolean editable) {
this.editable = editable;
this.currentApplicateStyle = currentApplicateStyle;
initPane();
}
public void registerChangeListener(ChangeListener changeListener) {
this.changeListener = changeListener;
}
private void initPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
contentPane = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(5, 8);
createContentPane();
UIScrollPane scrollPane = new UIScrollPane(contentPane);
scrollPane.setPreferredSize(new Dimension(630, 480));
scrollPane.setBorder(BorderFactory.createEmptyBorder());
this.add(scrollPane, BorderLayout.CENTER);
}
public void createContentPane() {
contentPane.removeAll();
Iterator<PredefinedStyle> iterator = ServerPreferenceConfig.getInstance().getPreferenceStyleConfig().getPredefinedStyleIterator();
int rowCount = (ServerPreferenceConfig.getInstance().getPreferenceStyleConfig().getPredefinedSize() +2)/ 3;
contentPane.setPreferredSize(new Dimension(618, 220 * rowCount));
while (iterator.hasNext()) {
PredefinedStyle tmpStyle = iterator.next();
if (tmpStyle != null) {
PredefinedStyleBlock tmpPanel =
new PredefinedStyleBlock(tmpStyle, this, this.editable);
contentPane.add(tmpPanel);
}
}
}
public String getCurrentApplicateStyle() {
return currentApplicateStyle;
}
public void refreshPane() {
createContentPane();
this.validate();
this.repaint();
}
@Override
protected String title4PopupWindow() {
return null;
}
public void setSelectedPreviewPane(PredefinedStyleBlock selectedPreviewPane) {
this.selectedBlock = selectedPreviewPane;
if (changeListener != null) {
changeListener.fireChanged(null);
}
this.repaint();
}
public PredefinedStyleBlock getSelectedPreviewPane() {
return selectedBlock;
}
public PredefinedStyle update() {
if (this.selectedBlock == null){
return null;
}
return this.selectedBlock.update();
}
}

159
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/PredefinedStyleSettingPane.java

@ -1,159 +0,0 @@
package com.fr.design.mainframe.predefined.ui;
import com.fr.config.predefined.PredefinedNameStyleProvider;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.frpane.AbstractAttrNoScrollPane;
import com.fr.design.gui.frpane.AttributeChangeListener;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.predefined.ui.preview.StyleSettingPreviewPane;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Created by kerry on 2020-09-02
*/
public abstract class PredefinedStyleSettingPane<T> extends AbstractAttrNoScrollPane {
protected StyleSettingPreviewPane previewPane;
protected UIRadioButton predefinedRadioBtn;
private UIRadioButton customRadioBtn;
private JPanel customDetailPane;
private JPanel predefinedSettingPane;
private CardLayout tabbedPane;
private JPanel center;
private boolean isPopulating = false;
public void setPopulating(boolean populating) {
isPopulating = populating;
}
protected void initContentPane() {
leftContentPane = createContentPane();
this.add(leftContentPane, BorderLayout.CENTER);
}
@Override
protected JPanel createContentPane() {
JPanel contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
previewPane = createPreviewPane();
JPanel previewTitlePane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview"));
if (previewPane != null) {
previewTitlePane.setPreferredSize(new Dimension(407, 527));
previewTitlePane.add(previewPane);
contentPane.add(previewTitlePane, BorderLayout.WEST);
}
customDetailPane = createCustomDetailPane();
predefinedSettingPane = createPredefinedSettingPane();
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel jPanel = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(10, 20, 10);
jPanel.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style")));
predefinedRadioBtn = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preference_Predefined"));
customRadioBtn = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom"));
tabbedPane = new CardLayout();
center = new JPanel(tabbedPane);
center.add(predefinedSettingPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preference_Predefined"));
center.add(customDetailPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom"));
predefinedRadioBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
populateCustomPane();
tabbedPane.show(center, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preference_Predefined"));
}
});
customRadioBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tabbedPane.show(center, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom"));
}
});
jPanel.add(predefinedRadioBtn);
jPanel.add(customRadioBtn);
ButtonGroup layoutBG = new ButtonGroup();
layoutBG.add(predefinedRadioBtn);
layoutBG.add(customRadioBtn);
centerPane.add(jPanel, BorderLayout.NORTH);
centerPane.add(center, BorderLayout.CENTER);
contentPane.add(centerPane, BorderLayout.CENTER);
this.addAttributeChangeListener(new AttributeChangeListener() {
@Override
public void attributeChange() {
if (isPopulating) {
return;
}
if (previewPane != null) {
previewPane.refresh();
}
}
});
return contentPane;
}
protected abstract StyleSettingPreviewPane createPreviewPane();
protected abstract JPanel createCustomDetailPane();
protected JPanel createPredefinedSettingPane() {
return new JPanel();
}
protected void populate(PredefinedNameStyleProvider nameStyle) {
this.predefinedRadioBtn.setSelected(nameStyle.usePredefinedStyle());
this.customRadioBtn.setSelected(!nameStyle.usePredefinedStyle());
if (nameStyle.usePredefinedStyle()) {
tabbedPane.show(center, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preference_Predefined"));
} else {
tabbedPane.show(center, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Custom"));
}
}
protected String getPredefinedStyleName() {
JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
return template.getTemplatePredefinedStyle();
}
/**
* 用于在切换到预定义样式后重置自定义样式的设置
*/
protected abstract void populateCustomPane();
/**
* 展示数据
*
* @param ob 待展示的对象
*/
public abstract void populateBean(T ob);
/**
* 保存数据
*
* @return 待保存的对象
*/
public abstract T updateBean();
/**
* 保存数据
*
* @param ob 待保存的对象
*/
public void updateBean(T ob) {
}
}

51
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/ReportPredefinedStylePane.java

@ -1,51 +0,0 @@
package com.fr.design.mainframe.predefined.ui;
import com.fr.config.predefined.PredefinedStyle;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.JTemplate;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
/**
* Created by kerry on 2020-08-28
*/
public class ReportPredefinedStylePane extends BasicPane {
private PredefinedStyleSelectPane selectPane;
private JTemplate currentTemplate;
public ReportPredefinedStylePane(JTemplate jTemplate) {
this.currentTemplate = jTemplate;
initPane();
}
private void initPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel jPanel = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Style_Select"));
jPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
JPanel subPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.selectPane = new PredefinedStyleSelectPane(currentTemplate.getTemplatePredefinedStyle(), false);
subPanel.add(this.selectPane, BorderLayout.CENTER);
jPanel.add(subPanel, BorderLayout.CENTER);
this.add(jPanel, BorderLayout.CENTER);
}
public void update() {
PredefinedStyle style = selectPane.update();
if (style != null) {
// currentTemplate.resetPredefinedStyle(style.getStyleName());
}
}
public void refresh() {
this.selectPane.refreshPane();
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Template_Style");
}
}

218
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/ServerPredefinedStylePane.java

@ -1,218 +0,0 @@
package com.fr.design.mainframe.predefined.ui;
import com.fr.base.BaseUtils;
import com.fr.config.predefined.PredefinedStyle;
import com.fr.config.predefined.PredefinedStyleConfig;
import com.fr.config.ServerPreferenceConfig;
import com.fr.design.actions.UpdateAction;
import com.fr.design.event.ChangeEvent;
import com.fr.design.event.ChangeListener;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.predefined.PatternStyle;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.i18n.Toolkit;
import com.fr.design.icon.IconPathConstants;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.predefined.ui.dialog.PredefinedStyleEditDialog;
import com.fr.design.menu.MenuDef;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.utils.DesignUtils;
import com.fr.stable.StringUtils;
import com.fr.transaction.Configurations;
import com.fr.transaction.WorkerFacade;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* Created by kerry on 2020-08-25
*/
public class ServerPredefinedStylePane extends BasicPane {
private static final Color TIP_COLOR = Color.decode("#8F8F92");
private RemoveAction removeAction;
private PredefinedStyleSelectPane selectPane;
public ServerPredefinedStylePane() {
initPane();
}
private void initPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel jPanel = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Style_Manager"));
jPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
jPanel.setLayout(FRGUIPaneFactory.createLeftZeroLayout());
JPanel subPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
subPanel.add(createControlPane(), BorderLayout.NORTH);
PredefinedStyle style = ServerPreferenceConfig.getInstance().getPreferenceStyleConfig().getDefaultPredefinedStyle();
this.selectPane = new PredefinedStyleSelectPane(style == null ? StringUtils.EMPTY : style.getStyleName(), true);
this.selectPane.registerChangeListener(new ChangeListener() {
@Override
public void fireChanged(ChangeEvent event) {
PredefinedStyle selectStyle = selectPane.getSelectedPreviewPane().update();
removeAction.setEnabled(!selectStyle.isBuiltIn());
}
});
this.selectPane.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
if (selectPane.getSelectedPreviewPane() != null) {
removeAction.setEnabled(true);
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
JSeparator jSeparator = new JSeparator();
subPanel.add(jSeparator, BorderLayout.CENTER);
subPanel.add(this.selectPane, BorderLayout.SOUTH);
jPanel.add(subPanel);
this.add(jPanel, BorderLayout.CENTER);
this.repaint();
}
private JPanel createControlPane() {
MenuDef addMenuDef = new MenuDef(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Action_Add"));
addMenuDef.setIconPath(IconPathConstants.ADD_POPMENU_ICON_PATH);
createAddMenuDef(addMenuDef);
ToolBarDef toolbarDef = new ToolBarDef();
removeAction = new RemoveAction();
removeAction.setEnabled(false);
toolbarDef.addShortCut(addMenuDef, removeAction);
UIToolbar toolBar = ToolBarDef.createJToolBar();
toolBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
toolbarDef.updateToolBar(toolBar);
JPanel toolbarPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
toolbarPane.add(toolBar, BorderLayout.CENTER);
UILabel tipLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Style_Manager_Tip"));
tipLabel.setForeground(TIP_COLOR);
tipLabel.setHorizontalTextPosition(UILabel.RIGHT);
toolbarPane.add(tipLabel, BorderLayout.EAST);
toolbarPane.setPreferredSize(new Dimension(620, 30));
return toolbarPane;
}
private void createAddMenuDef(MenuDef addMenuDef) {
addMenuDef.setRePaint(true);
addMenuDef.addShortCut(new CreateStyleAction(PatternStyle.DARK_STYLE));
addMenuDef.addShortCut(new CreateStyleAction(PatternStyle.LIGHT_STYLE));
}
public void update() {
PredefinedStyle style = selectPane.update();
if (style != null) {
PredefinedStyleConfig config = ServerPreferenceConfig.getInstance().getPreferenceStyleConfig();
config.setDefaultPredefinedStyle(style.getStyleName());
// Configurations.modify(new WorkerFacade(ServerPreferenceConfig.class) {
// @Override
// public void run() {
// ServerPreferenceConfig.getInstance().setPreferenceStyleConfig(config);
// }
// });
}
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Server_Style");
}
private class RemoveAction extends UpdateAction {
public RemoveAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Remove"));
this.setMnemonic('R');
this.setSmallIcon(BaseUtils.readIcon(IconPathConstants.TD_REMOVE_ICON_PATH));
}
@Override
public void actionPerformed(ActionEvent e) {
PredefinedStyle previewObject = ServerPredefinedStylePane.this.selectPane.update();
int selVal = FineJOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(ServerPredefinedStylePane.this),
Toolkit.i18nText("Fine-Design_Predefined_Remove_Style_Confirm", previewObject.getStyleName()),
Toolkit.i18nText("Fine-Design_Basic_Delete"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (selVal == JOptionPane.YES_OPTION) {
removeStyle(previewObject.getStyleName());
ServerPredefinedStylePane.this.selectPane.refreshPane();
}
}
}
private class CreateStyleAction extends UpdateAction {
private PatternStyle style;
public CreateStyleAction(PatternStyle style) {
this.style = style;
this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Create_Parttern_Style") + style.getName());
this.setMnemonic('R');
}
@Override
public void actionPerformed(ActionEvent e) {
createNewPatternStylePane();
}
private void createNewPatternStylePane() {
PredefinedStyleEditPane editPane = PredefinedStyleEditPane.createNewEditPane(selectPane);
PredefinedStyleEditDialog editDialog = new PredefinedStyleEditDialog(
SwingUtilities.getWindowAncestor(ServerPredefinedStylePane.this), editPane);
PredefinedStyle predefinedStyle = style.getPredefinedStyle();
predefinedStyle.setStyleName(StringUtils.EMPTY);
editPane.populate(predefinedStyle);
editDialog.setVisible(true);
}
}
private void removeStyle(String name) {
PredefinedStyleConfig config = ServerPreferenceConfig.getInstance().getPreferenceStyleConfig();
config.removeStyle(name);
// Configurations.modify(new WorkerFacade(ServerPreferenceConfig.class) {
// @Override
// public void run() {
// ServerPreferenceConfig.getInstance().setPreferenceStyleConfig(config);
// }
// });
}
}

308
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/CellStyleListControlPane.java

@ -1,308 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail;
import com.fr.base.BaseUtils;
import com.fr.base.Style;
import com.fr.config.predefined.PredefinedCellStyle;
import com.fr.config.predefined.PredefinedCellStyleConfig;
import com.fr.design.actions.UpdateAction;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.NameInspector;
import com.fr.design.gui.controlpane.JListControlPane;
import com.fr.design.gui.controlpane.NameObjectCreator;
import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.gui.controlpane.ShortCut4JControlPane;
import com.fr.design.gui.controlpane.UnrepeatedNameHelper;
import com.fr.design.gui.frpane.AttributeChangeListener;
import com.fr.design.gui.ilist.ListModelElement;
import com.fr.design.gui.ilist.ModNameActionListener;
import com.fr.design.gui.style.AlignmentPane;
import com.fr.design.gui.style.FormatPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.predefined.ui.detail.cell.CustomPredefinedStylePane;
import com.fr.design.menu.ShortCut;
import com.fr.general.ComparatorUtils;
import com.fr.general.NameObject;
import com.fr.invoke.Reflect;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.Nameable;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
/**
* Created by kerry on 2020-09-27
*/
public class CellStyleListControlPane extends JListControlPane {
private boolean namePermitted = true;
private AttributeChangeListener attributeChangeListener;
public CellStyleListControlPane() {
super();
this.addModNameActionListener(new ModNameActionListener() {
public void nameModed(int index, String oldName, String newName) {
if (ComparatorUtils.equals(oldName, newName) || ComparatorUtils.equals(newName, NameInspector.ILLEGAL_NAME_HOLDER)) {
return;
}
namePermitted = true;
String[] allNames = nameableList.getAllNames();
allNames[index] = StringUtils.EMPTY;
if (StringUtils.isEmpty(newName)) {
showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Empty_Name"), index);
return;
}
if (isNameRepeated(new List[]{Arrays.asList(allNames)}, newName)) {
showTipDialogAndReset(Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Duplicate_Name", newName), index);
return;
}
populateSelectedValue();
}
});
}
public void registerAttrChangeListener(AttributeChangeListener listener){
this.attributeChangeListener = listener;
}
private void showTipDialogAndReset(String content, int index) {
nameableList.stopEditing();
FineJOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(CellStyleListControlPane.this),
content,
Toolkit.i18nText("Fine-Design_Basic_Alert"),
JOptionPane.WARNING_MESSAGE);
setIllegalIndex(index);
namePermitted = false;
}
@Override
public NameableCreator[] createNameableCreators() {
return new NameableCreator[]{
new CellStyleNameObjectCreator(Toolkit.i18nText("Fine-Design_Predefined_Cell_New_Style"),
PredefinedCellStyle.class, CustomPredefinedStylePaneNoBorder.class) {
@Override
public boolean acceptDefaultNameObject(Object ob) {
return ((PredefinedCellStyle) ob).isDefaultStyle();
}
},
new CellStyleNameObjectCreator(Toolkit.i18nText("Fine-Design_Predefined_Cell_New_Style"),
PredefinedCellStyle.class, CustomPredefinedStylePane.class)};
}
@Override
public BasicBeanPane createPaneByCreators(NameableCreator creator) {
CustomPredefinedStylePane stylePane = (CustomPredefinedStylePane) super.createPaneByCreators(creator);
stylePane.registerAttrChangeListener(attributeChangeListener);
return stylePane;
}
@Override
protected String title4PopupWindow() {
return StringUtils.EMPTY;
}
protected void initComponentPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setCreators(this.createNameableCreators());
initCardPane();
JPanel leftPane = getLeftPane();
JSeparator jSeparator = new JSeparator(SwingConstants.VERTICAL);
leftPane.setPreferredSize(new Dimension(70, 0));
jSeparator.setPreferredSize(new Dimension(2, 0));
cardPane.setPreferredSize(new Dimension(238, 0));
cardPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
JPanel mainSplitPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
mainSplitPane.add(leftPane, BorderLayout.WEST);
mainSplitPane.add(jSeparator, BorderLayout.CENTER);
mainSplitPane.add(cardPane, BorderLayout.EAST);
this.add(mainSplitPane, BorderLayout.CENTER);
this.checkButtonEnabled();
}
protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{
createAddItemShortCut4JControlPane(),
new RemoveItemShortCut4JControlPane(new RemoveItemAction())
};
}
private static class CustomPredefinedStylePaneNoBorder extends CustomPredefinedStylePane {
@Override
protected List<BasicPane> initPaneList() {
paneList = new ArrayList<BasicPane>();
paneList.add(new FormatPane());
paneList.add(new AlignmentPane());
return paneList;
}
}
private ShortCut4JControlPane createAddItemShortCut4JControlPane (){
ShortCut shortCut = shortCutFactory.createAddItemUpdateAction(new NameableCreator[]{
new CellStyleNameObjectCreator(Toolkit.i18nText("Fine-Design_Predefined_Cell_New_Style"),
PredefinedCellStyle.class, CustomPredefinedStylePane.class)});
return new AddItemShortCut4JControlPane(shortCut);
}
private class AddItemShortCut4JControlPane extends ShortCut4JControlPane{
AddItemShortCut4JControlPane(ShortCut shortCut) {
this.shortCut = shortCut;
}
@Override
public void checkEnable() {
this.shortCut.setEnabled(true);
}
}
private class RemoveItemShortCut4JControlPane extends ShortCut4JControlPane {
RemoveItemShortCut4JControlPane(ShortCut shortCut) {
this.shortCut = shortCut;
}
@Override
public void checkEnable() {
ListModelElement selectModel = CellStyleListControlPane.this.getSelectedValue();
if (selectModel != null) {
NameObject selectNameObject = (NameObject) selectModel.wrapper;
PredefinedCellStyle cellStyle = (PredefinedCellStyle) (selectNameObject.getObject());
this.shortCut.setEnabled(!cellStyle.isBuiltIn() && !cellStyle.isDefaultStyle());
} else {
this.shortCut.setEnabled(false);
}
}
}
private class RemoveItemAction extends UpdateAction {
RemoveItemAction() {
this.setName(com.fr.design.i18n.Toolkit.i18nText(("Fine-Design_Basic_Action_Remove")));
this.setMnemonic('R');
this.setSmallIcon(BaseUtils
.readIcon("/com/fr/base/images/cell/control/remove.png"));
}
@Override
public void actionPerformed(ActionEvent evt) {
CellStyleListControlPane.this.onRemoveItem();
}
}
class CellStyleNameObjectCreator extends NameObjectCreator {
public CellStyleNameObjectCreator(String menuName, Class clazz, Class<? extends BasicBeanPane> updatePane) {
super(menuName, clazz, updatePane);
}
public Nameable createNameable(UnrepeatedNameHelper helper) {
Constructor<? extends PredefinedCellStyle> constructor = null;
try {
constructor = clazzOfInitCase.getConstructor();
PredefinedCellStyle cellStyle = constructor.newInstance();
cellStyle.setName(menuName);
cellStyle.setStyle(Style.getInstance());
return new NameObject(helper.createUnrepeatedName(this.menuName()), cellStyle);
} catch (NoSuchMethodException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (IllegalAccessException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (InstantiationException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} catch (InvocationTargetException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
/**
*
* @param ob
* @return
*/
public Object acceptObject2Populate(Object ob) {
if (ob instanceof NameObject) {
ob = ((NameObject) ob).getObject();
}
if (clazzOfObject != null && clazzOfObject.isInstance(ob) && acceptDefaultNameObject(ob)) {
doSthChanged4Icon(ob);
return ob;
}
return null;
}
public boolean acceptDefaultNameObject(Object ob) {
return !((PredefinedCellStyle) ob).isDefaultStyle();
}
}
/**
* Populate
*/
public void populateBean(PredefinedCellStyleConfig ob) {
if (ob == null) {
return;
}
List nameStyleList = new ArrayList();
Iterator styleNameIterator = ob.getStyleNameIterator();
while (styleNameIterator.hasNext()) {
String name = (String) styleNameIterator.next();
PredefinedCellStyle tmpStyle = ob.getStyle(name);
if (tmpStyle != null) {
nameStyleList.add(new NameObject(name, tmpStyle));
}
}
NameObject[] nameObjects = new NameObject[nameStyleList.size()];
nameStyleList.toArray(nameObjects);
populate(nameObjects);
}
public PredefinedCellStyleConfig updateBean() {
Nameable[] nameables = this.update();
PredefinedCellStyleConfig styleConfig = new PredefinedCellStyleConfig();
for (int i = 0; i < nameables.length; i++) {
PredefinedCellStyle tmpStyle = (PredefinedCellStyle) ((NameObject) nameables[i]).getObject();
tmpStyle.setName(nameables[i].getName());
styleConfig.addStyle(tmpStyle);
}
return styleConfig;
}
}

94
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/ChartStyleSettingPane.java

@ -1,94 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail;
import com.fr.config.predefined.PredefinedChartStyle;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.MultiTabPane;
import com.fr.design.mainframe.predefined.ui.detail.chart.ChartAxisStylePane;
import com.fr.design.mainframe.predefined.ui.detail.chart.ChartBackgroundStylePane;
import com.fr.design.mainframe.predefined.ui.detail.chart.ChartDataSheetStylePane;
import com.fr.design.mainframe.predefined.ui.detail.chart.ChartLabelStylePane;
import com.fr.design.mainframe.predefined.ui.detail.chart.ChartLegendStylePane;
import com.fr.design.mainframe.predefined.ui.detail.chart.ChartTitleStylePane;
import java.util.ArrayList;
import java.util.List;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-16
*/
public class ChartStyleSettingPane extends MultiTabPane<PredefinedChartStyle> {
private ChartTitleStylePane chartTitleStylePane;
private ChartLegendStylePane chartLegendStylePane;
private ChartLabelStylePane chartLabelPane;
private ChartAxisStylePane chartAxisStylePane;
private ChartDataSheetStylePane chartDataSheetStylePane;
private ChartBackgroundStylePane chartBackgroundStylePane;
public ChartStyleSettingPane() {
}
@Override
protected void initLayout() {
super.initLayout();
}
@Override
protected List<BasicPane> initPaneList() {
this.chartTitleStylePane = new ChartTitleStylePane();
this.chartLegendStylePane = new ChartLegendStylePane();
this.chartLabelPane = new ChartLabelStylePane();
this.chartAxisStylePane = new ChartAxisStylePane();
this.chartDataSheetStylePane = new ChartDataSheetStylePane();
this.chartBackgroundStylePane = new ChartBackgroundStylePane();
paneList = new ArrayList<>();
paneList.add(this.chartTitleStylePane);
paneList.add(this.chartLegendStylePane);
paneList.add(this.chartLabelPane);
paneList.add(this.chartAxisStylePane);
paneList.add(this.chartDataSheetStylePane);
paneList.add(this.chartBackgroundStylePane);
return paneList;
}
@Override
public void populateBean(PredefinedChartStyle ob) {
chartTitleStylePane.populate(ob);
chartLegendStylePane.populate(ob);
chartLabelPane.populate(ob);
chartAxisStylePane.populate(ob);
chartDataSheetStylePane.populate(ob);
chartBackgroundStylePane.populate(ob);
}
@Override
public void updateBean(PredefinedChartStyle ob) {
}
@Override
public PredefinedChartStyle updateBean() {
PredefinedChartStyle chartStyle = new PredefinedChartStyle();
chartTitleStylePane.update(chartStyle);
chartLegendStylePane.update(chartStyle);
chartLabelPane.update(chartStyle);
chartAxisStylePane.update(chartStyle);
chartDataSheetStylePane.update(chartStyle);
chartBackgroundStylePane.update(chartStyle);
return chartStyle;
}
@Override
public boolean accept(Object ob) {
return false;
}
@Override
public void reset() {
}
}

63
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/ComponentStyleSettingPane.java

@ -1,63 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail;
import com.fr.config.predefined.PredefinedComponentStyle;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.MultiTabPane;
import com.fr.design.mainframe.predefined.ui.detail.component.ComponentFrameStylePane;
import com.fr.design.mainframe.predefined.ui.detail.component.ComponentTitleStylePane;
import java.util.ArrayList;
import java.util.List;
/**
* Created by kerry on 2020-09-01
*/
public class ComponentStyleSettingPane extends MultiTabPane<PredefinedComponentStyle> {
private ComponentFrameStylePane frameStylePane;
private ComponentTitleStylePane titleStylePane;
public ComponentStyleSettingPane() {
}
@Override
protected List<BasicPane> initPaneList() {
this.frameStylePane = new ComponentFrameStylePane();
this.titleStylePane = ComponentTitleStylePane.createPredefinedSettingPane();
paneList = new ArrayList<BasicPane>();
paneList.add(this.frameStylePane);
paneList.add(this.titleStylePane);
return paneList;
}
@Override
public void populateBean(PredefinedComponentStyle ob) {
this.frameStylePane.populate(ob);
this.titleStylePane.populate(ob);
}
@Override
public void updateBean(PredefinedComponentStyle ob) {
}
@Override
public PredefinedComponentStyle updateBean() {
PredefinedComponentStyle componentStyle = new PredefinedComponentStyle();
this.frameStylePane.update(componentStyle);
this.titleStylePane.update(componentStyle);
return componentStyle;
}
@Override
public boolean accept(Object ob) {
return false;
}
@Override
public void reset() {
}
}

81
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/PredefinedBackgroundSettingPane.java

@ -1,81 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail;
import com.fr.config.predefined.PredefinedBackground;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ibutton.UIButtonGroup;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.predefined.ui.detail.background.BackgroundSettingPane;
import com.fr.design.mainframe.predefined.ui.detail.background.BackgroundWithAlphaSettingPane;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Created by kerry on 2020-08-31
*/
public class PredefinedBackgroundSettingPane extends BasicBeanPane<PredefinedBackground> {
private UIButtonGroup buttonGroup;
private BackgroundSettingPane reportBackgroundSettingPane;
private BackgroundWithAlphaSettingPane formBackgroundSettingPane;
public PredefinedBackgroundSettingPane() {
initPane();
}
private void initPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
reportBackgroundSettingPane = new BackgroundSettingPane();
formBackgroundSettingPane = new BackgroundWithAlphaSettingPane();
CardLayout tabbedPane = new CardLayout();
JPanel center = new JPanel(tabbedPane);
center.add(reportBackgroundSettingPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plain_Report"));
center.add(formBackgroundSettingPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Decision_Report"));
this.buttonGroup = new UIButtonGroup(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plain_Report"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Decision_Report")});
buttonGroup.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (buttonGroup.getSelectedIndex() == 0) {
tabbedPane.show(center, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plain_Report"));
} else {
tabbedPane.show(center, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Decision_Report"));
}
}
});
this.add(buttonGroup, BorderLayout.NORTH);
this.add(center, BorderLayout.CENTER);
this.buttonGroup.setSelectedIndex(0);
}
public boolean currentFormBackground() {
return buttonGroup.getSelectedIndex() == 1;
}
@Override
public void populateBean(PredefinedBackground predefinedBackground) {
reportBackgroundSettingPane.populateBean(predefinedBackground.getReportBackground());
formBackgroundSettingPane.populateBean(predefinedBackground.getFormBackground());
}
@Override
public PredefinedBackground updateBean() {
PredefinedBackground predefinedBackground = new PredefinedBackground();
predefinedBackground.setReportBackground(reportBackgroundSettingPane.updateBean());
predefinedBackground.setFormBackground(formBackgroundSettingPane.updateBean());
return predefinedBackground;
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Background_Setting");
}
}

51
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/AbstractBackgroundDetailPane.java

@ -1,51 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.design.event.UIObserverListener;
import com.fr.design.mainframe.backgroundpane.BackgroundQuickPane;
import com.fr.general.Background;
import javax.swing.event.ChangeListener;
/**
* Created by kerry on 2020-09-14
*/
public abstract class AbstractBackgroundDetailPane<T extends Background> extends BackgroundQuickPane {
@Override
public boolean accept(Background background) {
return false;
}
@Override
public void populateBean(Background background) {
this.populate((T) background);
}
@Override
public Background updateBean() {
return this.update();
}
@Override
public String title4PopupWindow() {
return null;
}
@Override
public void reset() {
}
@Override
public void registerChangeListener(UIObserverListener listener) {
}
public abstract void populate(T background);
public abstract T update();
public void addChangeListener(ChangeListener changeListener) {
}
}

135
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/BackgroundSettingPane.java

@ -1,135 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.backgroundpane.BackgroundQuickPane;
import com.fr.general.Background;
import com.fr.log.FineLoggerFactory;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
/**
* Created by kerry on 2020-09-02
*/
public class BackgroundSettingPane extends BasicBeanPane<Background> {
private ChangeListener changeListener = null;
private UIComboBox headCombobox;
private BackgroundQuickPane[] paneList;
public BackgroundSettingPane() {
init();
}
private void init() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.add(createComboHeadPane(), BorderLayout.NORTH);
CardLayout cardlayout = new CardLayout();
paneList = supportKindsOfBackgroundUI();
final JPanel centerPane = new JPanel(cardlayout) {
@Override
public Dimension getPreferredSize() {// AUGUST:使用当前面板的的高度
int index = headCombobox.getSelectedIndex();
return new Dimension(super.getPreferredSize().width, paneList[index].getPreferredSize().height);
}
};
centerPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
for (BackgroundQuickPane pane : paneList) {
headCombobox.addItem(pane.title4PopupWindow());
centerPane.add(pane, pane.title4PopupWindow());
}
headCombobox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
cardlayout.show(centerPane, (String) headCombobox.getSelectedItem());
}
});
this.add(centerPane, BorderLayout.CENTER);
}
public void addChangeListener(ChangeListener changeListener) {
this.changeListener = changeListener;
}
private JPanel createComboHeadPane() {
headCombobox = new UIComboBox();
JPanel jPanel = TableLayoutHelper.createGapTableLayoutPane(
new Component[][]{new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Fill")), headCombobox}},
TableLayoutHelper.FILL_NONE, 33, 5);
headCombobox.setPreferredSize(new Dimension(160, 20));
jPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
return jPanel;
}
protected BackgroundQuickPane[] supportKindsOfBackgroundUI() {
java.util.List<BackgroundQuickPane> kinds = new ArrayList<>();
kinds.add(new EmptyBackgroundPane());
kinds.add(new ColorDetailPane());
kinds.add(new TextureDetailObservePane());
kinds.add(new PatternDetailPane());
kinds.add(createImageSelectPane());
kinds.add(new GradientDetailPane());
return kinds.toArray(new BackgroundQuickPane[kinds.size()]);
}
protected ImageDetailPane createImageSelectPane() {
ImageDetailPane imageDetailPane = new ImageDetailPane();
imageDetailPane.registerChangeListener(new UIObserverListener() {
@Override
public void doChange() {
fireChangeListener();
}
});
return imageDetailPane;
}
protected void fireChangeListener() {
if (changeListener != null) {
changeListener.stateChanged(null);
}
}
@Override
public void populateBean(Background background) {
for (int i = 0; i < paneList.length; i++) {
BackgroundQuickPane pane = paneList[i];
if (pane.accept(background)) {
pane.populateBean(background);
headCombobox.setSelectedIndex(i);
return;
}
}
}
@Override
public Background updateBean() {
int selectIndex = this.headCombobox.getSelectedIndex();
try {
return paneList[selectIndex].updateBean();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
@Override
protected String title4PopupWindow() {
return null;
}
}

76
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/BackgroundWithAlphaSettingPane.java

@ -1,76 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.config.predefined.BackgroundWithAlpha;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.designer.IntervalConstants;
import com.fr.design.gui.frpane.UINumberDragPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
/**
* Created by kerry on 2020-09-04
*/
public class BackgroundWithAlphaSettingPane extends BasicBeanPane<BackgroundWithAlpha> {
private BackgroundSettingPane backgroundSettingPane;
//透明度
private UINumberDragPane numberDragPane;
private double maxNumber = 100;
public BackgroundWithAlphaSettingPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
backgroundSettingPane = new FormBackgroundSettingPane();
JPanel eastpane = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(2, 0);
this.numberDragPane = new UINumberDragPane(0, 100);
this.numberDragPane.setPreferredSize(new Dimension(148, 20));
eastpane.add(numberDragPane);
eastpane.add(new UILabel("%"));
JPanel transparencyPane = TableLayoutHelper.createGapTableLayoutPane(
new Component[][]{new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget-Style_Alpha")),
eastpane}}, TableLayoutHelper.FILL_LASTCOLUMN, 18, 5);
transparencyPane.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
Component[][] components = new Component[][]{
new Component[]{backgroundSettingPane},
new Component[]{transparencyPane}};
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, TableLayoutHelper.FILL_NONE, IntervalConstants.INTERVAL_W2, IntervalConstants.INTERVAL_L1);
this.add(panel, BorderLayout.CENTER);
}
public void addChangeListener(ChangeListener changeListener) {
this.backgroundSettingPane.addChangeListener(changeListener);
}
@Override
public void populateBean(BackgroundWithAlpha ob) {
backgroundSettingPane.populateBean(ob.getBackground());
numberDragPane.populateBean(ob.getAlpha() * maxNumber);
}
@Override
public BackgroundWithAlpha updateBean() {
BackgroundWithAlpha backgroundWithAlpha = new BackgroundWithAlpha();
backgroundWithAlpha.setBackground(backgroundSettingPane.updateBean());
backgroundWithAlpha.setAlpha((float) (numberDragPane.updateBean() / maxNumber));
return backgroundWithAlpha;
}
@Override
protected String title4PopupWindow() {
return null;
}
}

56
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/ColorDetailPane.java

@ -1,56 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.base.background.ColorBackground;
import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.style.color.NewColorSelectPane;
import com.fr.general.Background;
import java.awt.BorderLayout;
/**
* Created by kerry on 2020-08-31
*/
public class ColorDetailPane extends AbstractBackgroundDetailPane<ColorBackground> {
private ColorBackgroundSelectPane selectPane;
public ColorDetailPane() {
this.selectPane = new ColorBackgroundSelectPane();
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.add(this.selectPane, BorderLayout.CENTER);
}
@Override
public void populate(ColorBackground background) {
this.selectPane.setColor(background.getColor());
}
@Override
public ColorBackground update() {
return ColorBackground.getInstance(selectPane.getColor());
}
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Color");
}
@Override
public boolean accept(Background background) {
return background instanceof ColorBackground;
}
class ColorBackgroundSelectPane extends NewColorSelectPane implements UIObserver {
protected UIObserverListener uiObserverListener;
@Override
public void registerChangeListener(UIObserverListener listener) {
this.uiObserverListener = listener;
}
@Override
public boolean shouldResponseChangeListener() {
return true;
}
}
}

34
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/EmptyBackgroundPane.java

@ -1,34 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.general.Background;
/**
* Created by kerry on 2020-09-01
*/
public class EmptyBackgroundPane extends AbstractBackgroundDetailPane {
@Override
public void populate(Background background) {
}
@Override
public Background update() {
return null;
}
/**
* 名称
*
* @return 名称
*/
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Null");
}
public boolean accept(Background background) {
return background == null;
}
}

48
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/FormBackgroundSettingPane.java

@ -1,48 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.event.UIObserverListener;
import com.fr.design.fun.BackgroundQuickUIProvider;
import com.fr.design.mainframe.backgroundpane.BackgroundQuickPane;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Created by kerry on 2020-09-14
*/
public class FormBackgroundSettingPane extends BackgroundSettingPane {
public FormBackgroundSettingPane() {
super();
}
@Override
protected BackgroundQuickPane[] supportKindsOfBackgroundUI() {
ColorDetailPane colorDetailPane = new ColorDetailPane();
ImageDetailPane imageDetailPane = createImageSelectPane();
GradientDetailPane gradientPane = new GradientDetailPane();
//hugh:表单支持背景接口
List<BackgroundQuickPane> kinds = new ArrayList<BackgroundQuickPane>();
kinds.add(new EmptyBackgroundPane());
kinds.add(colorDetailPane);
kinds.add(imageDetailPane);
kinds.add(gradientPane);
Set<BackgroundQuickUIProvider> providers = ExtraDesignClassManager.getInstance().getArray(BackgroundQuickUIProvider.MARK_STRING);
for (BackgroundQuickUIProvider provider : providers) {
BackgroundQuickPane newTypePane = provider.appearanceForBackground();
newTypePane.registerChangeListener(new UIObserverListener() {
@Override
public void doChange() {
fireChangeListener();
}
});
kinds.add(newTypePane);
}
return kinds.toArray(new BackgroundQuickPane[kinds.size()]);
}
}

159
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/GradientDetailPane.java

@ -1,159 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.base.background.GradientBackground;
import com.fr.design.designer.IntervalConstants;
import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.style.background.gradient.GradientBar;
import com.fr.general.Background;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* 渐变色的面板不是很pp面板应用显得繁琐有写可以写成控件类型比如色彩选择的可以做得花哨点
*
* @author ben
*/
public class GradientDetailPane extends AbstractBackgroundDetailPane<GradientBackground> implements UIObserver {
private static final long serialVersionUID = -6854603990673031897L;
private UIObserverListener listener;
private UIRadioButton left2right, top2bottom;
private GradientBar gradientBar;
private ChangeListener changeListener = null;
public GradientDetailPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel gradientPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel blankJp = new JPanel();
gradientBar = new GradientBar(4, 140);
blankJp.add(gradientBar);
gradientPanel.add(gradientBar, BorderLayout.SOUTH);
JPanel jp = new JPanel(new GridLayout(2, 1, 15, 10));
left2right = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Page_Setup_Horizontal"));
jp.add(left2right);
left2right.setSelected(true);
left2right.addActionListener(reviewListener);
top2bottom = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Page_Setup_Vertical"));
jp.add(top2bottom);
top2bottom.addActionListener(reviewListener);
ButtonGroup toggle = new ButtonGroup();
toggle.add(left2right);
toggle.add(top2bottom);
Component[][] components = new Component[][]{
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Gradient_Setting")), gradientPanel},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Gradient_Color")), jp}
};
JPanel contentPane = TableLayoutHelper.createGapTableLayoutPane(components, TableLayoutHelper.FILL_LASTCOLUMN,
IntervalConstants.INTERVAL_W4, IntervalConstants.INTERVAL_L1);
this.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (listener != null) {
listener.doChange();
}
}
});
this.add(contentPane);
}
@Override
public boolean accept(Background background) {
return background instanceof GradientBackground;
}
public void populate(GradientBackground bg) {
this.gradientBar.getSelectColorPointBtnP1().setColorInner(bg.getStartColor());
this.gradientBar.getSelectColorPointBtnP2().setColorInner(bg.getEndColor());
if (bg.getDirection() == GradientBackground.LEFT2RIGHT) {
left2right.setSelected(true);
} else {
top2bottom.setSelected(true);
}
if (bg.isUseCell()) {
return;
}
double startValue = (double) bg.getBeginPlace();
double endValue = (double) bg.getFinishPlace();
gradientBar.setStartValue(startValue);
gradientBar.setEndValue(endValue);
this.gradientBar.repaint();
}
public GradientBackground update() {
GradientBackground gb = new GradientBackground(
gradientBar.getSelectColorPointBtnP1().getColorInner(),
gradientBar.getSelectColorPointBtnP2().getColorInner());
if (left2right.isSelected()) {
gb.setDirection(GradientBackground.LEFT2RIGHT);
} else {
gb.setDirection(GradientBackground.TOP2BOTTOM);
}
if (gradientBar.isOriginalPlace()) {
gb.setUseCell(true);
} else {
gb.setUseCell(false);
gb.setBeginPlace((float) gradientBar.getStartValue());
gb.setFinishPlace((float) gradientBar.getEndValue());
}
return gb;
}
ActionListener reviewListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
fireChagneListener();
}
};
public void addChangeListener(ChangeListener changeListener) {
this.changeListener = changeListener;
gradientBar.addChangeListener(changeListener);
}
public void fireChagneListener() {
if (this.changeListener != null) {
ChangeEvent evt = new ChangeEvent(this);
this.changeListener.stateChanged(evt);
}
}
@Override
public void registerChangeListener(UIObserverListener listener) {
this.listener = listener;
}
@Override
public boolean shouldResponseChangeListener() {
return true;
}
@Override
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Gradient_Color");
}
}

215
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/ImageDetailPane.java

@ -1,215 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.base.Style;
import com.fr.base.background.ImageBackground;
import com.fr.base.background.ImageFileBackground;
import com.fr.design.designer.IntervalConstants;
import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.frpane.ImgChooseWrapper;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.style.background.image.ImageFileChooser;
import com.fr.design.style.background.image.ImagePreviewPane;
import com.fr.general.Background;
import com.fr.stable.Constants;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Image background pane.
*/
public class ImageDetailPane extends AbstractBackgroundDetailPane<ImageBackground> implements UIObserver {
private UIObserverListener listener;
protected ImagePreviewPane previewPane = null;
private Style imageStyle = null;
private ChangeListener changeListener = null;
private ImageFileChooser imageFileChooser = null;
private UIRadioButton defaultRadioButton = null;
private UIRadioButton tiledRadioButton = null;
private UIRadioButton extendRadioButton = null;
private UIRadioButton adjustRadioButton = null;
public ImageDetailPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.add(initSelectFilePane(), BorderLayout.CENTER);
imageFileChooser = new ImageFileChooser();
imageFileChooser.setMultiSelectionEnabled(false);
previewPane = new ImagePreviewPane();
this.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (listener != null) {
listener.doChange();
}
}
});
}
public JPanel initSelectFilePane() {
JPanel selectFilePane = FRGUIPaneFactory.createBorderLayout_L_Pane();
selectFilePane.setBorder(BorderFactory.createEmptyBorder());
UIButton selectPictureButton = new UIButton(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Image_Select"));
selectPictureButton.setMnemonic('S');
selectPictureButton.addActionListener(selectPictureActionListener);
selectPictureButton.setPreferredSize(new Dimension(160, 20));
//布局
defaultRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Alignment_Layout_Default"));
tiledRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Alignment_Layout_Image_Titled"));
extendRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Alignment_Layout_Image_Extend"));
adjustRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Style_Alignment_Layout_Image_Adjust"));
defaultRadioButton.addActionListener(layoutActionListener);
tiledRadioButton.addActionListener(layoutActionListener);
extendRadioButton.addActionListener(layoutActionListener);
adjustRadioButton.addActionListener(layoutActionListener);
JPanel jp = new JPanel(new GridLayout(4, 1, 15, 10));
for (UIRadioButton button : imageLayoutButtons()) {
jp.add(button);
}
ButtonGroup layoutBG = new ButtonGroup();
layoutBG.add(defaultRadioButton);
layoutBG.add(tiledRadioButton);
layoutBG.add(extendRadioButton);
layoutBG.add(adjustRadioButton);
defaultRadioButton.setSelected(true);
Component[][] components = new Component[][]{
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Image")), selectPictureButton},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Fill_Mode")), jp}
};
JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, TableLayoutHelper.FILL_NONE,
IntervalConstants.INTERVAL_L4, IntervalConstants.INTERVAL_L1);
selectFilePane.add(centerPane, BorderLayout.CENTER);
return selectFilePane;
}
protected UIRadioButton[] imageLayoutButtons() {
return new UIRadioButton[]{
defaultRadioButton,
tiledRadioButton,
extendRadioButton,
adjustRadioButton
};
}
@Override
public boolean accept(Background background) {
return background instanceof ImageBackground;
}
/**
* Select picture.
*/
ActionListener selectPictureActionListener = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
int returnVal = imageFileChooser.showOpenDialog(ImageDetailPane.this);
setImageStyle();
ImgChooseWrapper.getInstance(previewPane, imageFileChooser, imageStyle, changeListener).dealWithImageFile(returnVal);
}
};
protected void setImageStyle() {
if (tiledRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED);
} else if (adjustRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_ADJUST);
} else if (extendRadioButton.isSelected()) {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_EXTEND);
} else {
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER);
}
}
ActionListener layoutActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
setImageStyle();
changeImageStyle();
}
private void changeImageStyle() {
previewPane.setImageStyle(ImageDetailPane.this.imageStyle);
previewPane.repaint();
}
};
@Override
public void populate(ImageBackground imageBackground) {
if (imageBackground.getLayout() == Constants.IMAGE_CENTER) {
defaultRadioButton.setSelected(true);
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER);
} else if (imageBackground.getLayout() == Constants.IMAGE_EXTEND) {
extendRadioButton.setSelected(true);
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_EXTEND);
} else if (imageBackground.getLayout() == Constants.IMAGE_ADJUST) {
adjustRadioButton.setSelected(true);
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_ADJUST);
} else {
tiledRadioButton.setSelected(true);
imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED);
}
previewPane.setImageStyle(ImageDetailPane.this.imageStyle);
if (imageBackground.getImage() != null) {
previewPane.setImageWithSuffix(imageBackground.getImageWithSuffix());
previewPane.setImage(imageBackground.getImage());
}
fireChagneListener();
}
@Override
public ImageBackground update() {
ImageBackground imageBackground = new ImageFileBackground(previewPane.getImageWithSuffix());
setImageStyle();
imageBackground.setLayout(imageStyle.getImageLayout());
return imageBackground;
}
@Override
public void addChangeListener(ChangeListener changeListener) {
this.changeListener = changeListener;
}
private void fireChagneListener() {
if (this.changeListener != null) {
ChangeEvent evt = new ChangeEvent(this);
this.changeListener.stateChanged(evt);
}
}
@Override
public void registerChangeListener(UIObserverListener listener) {
this.listener = listener;
}
@Override
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Image");
}
}

119
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/PatternDetailPane.java

@ -1,119 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.base.background.PatternBackground;
import com.fr.design.designer.IntervalConstants;
import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.style.background.impl.PatternBackgroundPane;
import com.fr.design.style.color.ColorSelectBox;
import com.fr.general.Background;
import com.fr.log.FineLoggerFactory;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.LayoutManager;
/**
* Created by kerry on 2020-08-31
*/
public class PatternDetailPane extends AbstractBackgroundDetailPane<PatternBackground> implements UIObserver {
private UIObserverListener listener;
private PatternNewBackgroundPane patternNewBackgroundPane;
public PatternDetailPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
patternNewBackgroundPane = new PatternNewBackgroundPane(6);
this.add(patternNewBackgroundPane, BorderLayout.CENTER);
}
@Override
public void registerChangeListener(UIObserverListener listener) {
this.listener = listener;
}
@Override
public void populate(PatternBackground background) {
this.patternNewBackgroundPane.populate(background);
}
@Override
public PatternBackground update() {
try {
return (PatternBackground) this.patternNewBackgroundPane.update();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
@Override
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Pattern");
}
@Override
public boolean accept(Background background) {
return background instanceof PatternBackground;
}
@Override
public boolean shouldResponseChangeListener() {
return true;
}
class PatternNewBackgroundPane extends PatternBackgroundPane {
private PatternNewBackgroundPane(int nColumn) {
super(nColumn);
}
protected LayoutManager layoutOfTypePane(int nColumn) {
return new GridLayout(0, nColumn, 2, 2);
}
protected void initComponents(int nColumn) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder());
JPanel jPanel = new JPanel();
jPanel.setLayout(layoutOfTypePane(nColumn));
setChildrenOfTypePane(jPanel);
foregroundColorPane = new ColorSelectBox(80);
backgroundColorPane = new ColorSelectBox(80);
foregroundColorPane.setSelectObject(Color.lightGray);
backgroundColorPane.setSelectObject(Color.black);
UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Pattern"));
label.setVerticalAlignment(SwingConstants.TOP);
Component[][] components = new Component[][]{
new Component[]{label, jPanel},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_ForeBackground_Color")), foregroundColorPane},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Pattern_Color")), backgroundColorPane}
};
JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, TableLayoutHelper.FILL_LASTCOLUMN,
IntervalConstants.INTERVAL_W4, IntervalConstants.INTERVAL_L1);
JPanel jPanel1 = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane();
jPanel1.add(centerPane);
jPanel1.setBorder(BorderFactory.createEmptyBorder());
this.add(jPanel1, BorderLayout.NORTH);
this.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (listener != null) {
listener.doChange();
}
}
});
}
}
}

97
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/background/TextureDetailObservePane.java

@ -1,97 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.background;
import com.fr.base.background.TextureBackground;
import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.style.background.texture.TextureDetailPane;
import com.fr.general.Background;
import com.fr.log.FineLoggerFactory;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
/**
* Created by kerry on 2020-09-02
*/
public class TextureDetailObservePane extends AbstractBackgroundDetailPane<TextureBackground> implements UIObserver {
private TextureDetailPane detailPane;
private UIObserverListener listener;
public TextureDetailObservePane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
detailPane = TextureDetailPane.createMiniTextureDetailPane(6);
detailPane.setPreferredSize(new Dimension(160, 108));
UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Texture"));
label.setPreferredSize(new Dimension(24, 108));
label.setVerticalAlignment(SwingConstants.TOP);
JPanel jPanel = TableLayoutHelper.createGapTableLayoutPane(
new Component[][]{new Component[]{label, detailPane}}, TableLayoutHelper.FILL_LASTCOLUMN, 33, 5);
jPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 10));
detailPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (listener != null) {
listener.doChange();
}
}
});
this.add(jPanel, BorderLayout.CENTER);
}
@Override
public void registerChangeListener(UIObserverListener listener) {
this.listener = listener;
}
@Override
public boolean shouldResponseChangeListener() {
return true;
}
@Override
public void populate(TextureBackground background) {
this.detailPane.populate(background);
}
@Override
public TextureBackground update() {
try {
return (TextureBackground) this.detailPane.update();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
@Override
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Background_Texture");
}
@Override
public boolean accept(Background background) {
return background instanceof TextureBackground;
}
@Override
public void addChangeListener(ChangeListener changeListener) {
}
}

223
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/cell/CustomPredefinedStylePane.java

@ -1,223 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.cell;
import com.fr.base.ScreenResolution;
import com.fr.base.Style;
import com.fr.config.predefined.PredefinedCellStyle;
import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.AttrScrollPane;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.BasicScrollPane;
import com.fr.design.dialog.MultiTabPane;
import com.fr.design.gui.frpane.AbstractAttrNoScrollPane;
import com.fr.design.gui.frpane.AttributeChangeListener;
import com.fr.design.gui.style.AbstractBasicStylePane;
import com.fr.design.gui.style.AlignmentPane;
import com.fr.design.gui.style.BorderPane;
import com.fr.design.gui.style.FormatPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;
/**
* 复杂的原型图导致复杂的画法非我所愿也
*
* @author zhou
* @since 2012-5-24上午10:36:10
*/
public class CustomPredefinedStylePane extends MultiTabPane<PredefinedCellStyle> {
private PredefinedCellStyle cellStyle;
private PreviewArea previewArea;
private boolean populating;
private AttributeChangeListener attributeChangeListener;
public CustomPredefinedStylePane() {
super();
tabPane.setOneLineTab(true);
tabPane.setDrawLine(false);
tabPane.setBorder(BorderFactory.createLineBorder(UIConstants.SHADOW_GREY));
tabPane.setLayout(new GridLayout(1, 3, 0, 0));
}
public void registerAttrChangeListener(AttributeChangeListener listener){
this.attributeChangeListener = listener;
}
private void fireAttrChangeListener() {
if (this.attributeChangeListener != null) {
this.attributeChangeListener.attributeChange();
}
}
/**
* @return
*/
public String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Custom_Style");
}
/**
*
*/
public void reset() {
populateBean(null);
}
@Override
/**
*
*/
public void populateBean(PredefinedCellStyle ob) {
this.populating = true;
this.cellStyle = ob;
for (int i = 0; i < paneList.size(); i++) {
((AbstractBasicStylePane) paneList.get(i)).populateBean(ob.getStyle());
previewArea.preview(ob.getStyle());
}
this.populating = false;
}
@Override
/**
*
*/
public PredefinedCellStyle updateBean() {
AbstractBasicStylePane basicStylePane = (AbstractBasicStylePane) paneList.get(tabPane.getSelectedIndex());
this.cellStyle.setStyle(basicStylePane.update(this.cellStyle.getStyle()));
return this.cellStyle;
}
/**
* @param ob
* @return
*/
public boolean accept(Object ob) {
return ob instanceof PredefinedCellStyle;
}
@Override
protected List<BasicPane> initPaneList() {
paneList = new ArrayList<BasicPane>();
paneList.add(new FormatPane());
paneList.add(new BorderPane());
paneList.add(new AlignmentPane());
return paneList;
}
protected void initLayout() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel jPanel = new JPanel();
jPanel.setLayout(new BorderLayout(0, 4));
JPanel previewPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
previewArea = new PreviewArea();
previewPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preview"), null));
previewPane.add(previewArea, BorderLayout.CENTER);
this.add(previewPane, BorderLayout.NORTH);
this.add(jPanel, BorderLayout.CENTER);
jPanel.add(tabPane, BorderLayout.NORTH);
JPanel attrListenerPane = new AbstractAttrNoScrollPane() {
@Override
protected void initContentPane() {
leftContentPane = createContentPane();
this.add(leftContentPane, BorderLayout.CENTER);
}
@Override
protected JPanel createContentPane() {
this.addAttributeChangeListener(new AttributeChangeListener() {
@Override
public void attributeChange() {
if (populating) {
return;
}
PredefinedCellStyle cellStyle = updateBean();
if (cellStyle != null) {
previewArea.preview(cellStyle.getStyle());
}
fireAttrChangeListener();
}
});
BasicScrollPane basicScrollPane = new AttrScrollPane() {
@Override
protected JPanel createContentPane() {
return centerPane;
}
};
return basicScrollPane;
}
};
jPanel.add(attrListenerPane, BorderLayout.CENTER);
}
@Override
/**
*
*/
public void updateBean(PredefinedCellStyle ob) {
return;
}
/**
* 预览Style的面板
*
* @author richer
*/
private static class PreviewArea extends JComponent {
private String paintText = "Report";
private Style style = Style.DEFAULT_STYLE;
public PreviewArea() {
setPreferredSize(new Dimension(40, 30));
}
public void preview(Style style) {
this.style = style;
repaint();
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
int resolution = ScreenResolution.getScreenResolution();
if (style == Style.DEFAULT_STYLE) {
// 如果是默认的style,就只写"Report"上去
Style.paintContent(g2d, paintText, style, getWidth() - 3, getHeight() - 3, resolution);
return;
}
Style.paintBackground(g2d, style, getWidth() - 3, getHeight() - 3);
Style.paintContent(g2d, paintText, style, getWidth() - 3, getHeight() - 3, resolution);
Style.paintBorder(g2d, style, getWidth() - 3, getHeight() - 3);
}
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}
}
}

49
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/AbstractChartStylePane.java

@ -1,49 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.chart;
import com.fr.config.predefined.PredefinedChartStyle;
import com.fr.design.constants.LayoutConstants;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-17
*/
public abstract class AbstractChartStylePane extends BasicPane {
public AbstractChartStylePane() {
initComponents();
initPane();
}
protected abstract void initComponents();
protected void initPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
double e = 155;
double p = TableLayout.PREFERRED;
double[] columnSize = {p, e};
JPanel gapTableLayoutPane = TableLayoutHelper.createGapTableLayoutPane(getComponent(), getRows(p), columnSize, 20, LayoutConstants.VGAP_LARGE);
gapTableLayoutPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
UIScrollPane rightTopPane = new UIScrollPane(gapTableLayoutPane);
rightTopPane.setBorder(BorderFactory.createEmptyBorder());
this.add(rightTopPane, BorderLayout.CENTER);
}
protected abstract Component[][] getComponent();
protected abstract double[] getRows(double p);
public abstract void populate(PredefinedChartStyle chartStyle);
public abstract void update(PredefinedChartStyle chartStyle);
}

69
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartAxisStylePane.java

@ -1,69 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.chart;
import com.fr.config.predefined.PredefinedChartStyle;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.style.color.ColorSelectBox;
import java.awt.Component;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-16
*/
public class ChartAxisStylePane extends AbstractChartStylePane {
//轴标题字体样式
private ChartFontPane titleFontPane;
//轴标签字体样式
private ChartFontPane labelFontPane;
//轴线颜色
private ColorSelectBox axisLineColor;
protected void initComponents() {
titleFontPane = new ChartFontPane() {
public String getUILabelText() {
return Toolkit.i18nText("Fine-Design_Chart_Axis_Title_Character");
}
};
labelFontPane = new ChartFontPane() {
public String getUILabelText() {
return Toolkit.i18nText("Fine-Design_Chart_Axis_Label_Character");
}
};
axisLineColor = new ColorSelectBox(100);
}
protected Component[][] getComponent() {
return new Component[][]{
new Component[]{titleFontPane, null},
new Component[]{labelFontPane, null},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Axis_Line_Color")), axisLineColor}
};
}
protected double[] getRows(double p) {
return new double[]{p, p, p};
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Axis");
}
public void populate(PredefinedChartStyle chartStyle) {
titleFontPane.populate(chartStyle.getAxisTitleFont());
labelFontPane.populate(chartStyle.getAxisLabelFont());
axisLineColor.setSelectObject(chartStyle.getAxisLineColor());
}
public void update(PredefinedChartStyle chartStyle) {
chartStyle.setAxisTitleFont(titleFontPane.update());
chartStyle.setAxisLabelFont(labelFontPane.update());
chartStyle.setAxisLineColor(axisLineColor.getSelectObject());
}
}

113
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartBackgroundStylePane.java

@ -1,113 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.chart;
import com.fr.base.background.ImageBackground;
import com.fr.config.predefined.PredefinedChartStyle;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.backgroundpane.BackgroundQuickPane;
import com.fr.design.mainframe.backgroundpane.ColorBackgroundQuickPane;
import com.fr.design.mainframe.backgroundpane.ImageBackgroundQuickPane;
import com.fr.design.mainframe.backgroundpane.NullBackgroundQuickPane;
import com.fr.design.mainframe.backgroundpane.VanChartGradientPane;
import com.fr.design.style.color.ColorSelectBox;
import com.fr.general.Background;
import com.fr.stable.Constants;
import javax.swing.JPanel;
import java.util.ArrayList;
import java.util.List;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-17
*/
public class ChartBackgroundStylePane extends AbstractChartStylePane {
private UIComboBox typeComboBox;
private List<BackgroundQuickPane> paneList;
private JPanel centerPane;
//网格线颜色
private ColorSelectBox mainGridColor;
protected void initComponents() {
mainGridColor = new ColorSelectBox(100);
typeComboBox = new UIComboBox();
final CardLayout cardlayout = new CardLayout();
initList();
centerPane = new JPanel(cardlayout) {
@Override
public Dimension getPreferredSize() {// AUGUST:使用当前面板的的高度
int index = typeComboBox.getSelectedIndex();
return new Dimension(super.getPreferredSize().width, paneList.get(index).getPreferredSize().height);
}
};
for (int i = 0; i < paneList.size(); i++) {
BackgroundQuickPane pane = paneList.get(i);
typeComboBox.addItem(pane.title4PopupWindow());
centerPane.add(pane, pane.title4PopupWindow());
}
typeComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
cardlayout.show(centerPane, (String) typeComboBox.getSelectedItem());
}
});
}
protected Component[][] getComponent() {
return new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Area_Background_Color")), typeComboBox},
new Component[]{null, centerPane},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Grid_Line_Color")), mainGridColor}
};
}
protected double[] getRows(double p) {
return new double[]{p, p, p, p};
}
private void initList() {
paneList = new ArrayList<>();
paneList.add(new NullBackgroundQuickPane());
paneList.add(new ColorBackgroundQuickPane());
paneList.add(new ImageBackgroundQuickPane(false));
paneList.add(new VanChartGradientPane());
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Background");
}
public void populate(PredefinedChartStyle chartStyle) {
Background background = chartStyle.getChartBackground();
for (int i = 0; i < paneList.size(); i++) {
BackgroundQuickPane pane = paneList.get(i);
if (pane.accept(background)) {
pane.populateBean(background);
typeComboBox.setSelectedIndex(i);
break;
}
}
mainGridColor.setSelectObject(chartStyle.getGridMainLineColor());
}
public void update(PredefinedChartStyle chartStyle) {
chartStyle.setChartBackground(paneList.get(typeComboBox.getSelectedIndex()).updateBean());
if (chartStyle.getChartBackground() instanceof ImageBackground) {
((ImageBackground) chartStyle.getChartBackground()).setLayout(Constants.IMAGE_EXTEND);
}
chartStyle.setGridMainLineColor(mainGridColor.getSelectObject());
}
}

58
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartDataSheetStylePane.java

@ -1,58 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.chart;
import com.fr.config.predefined.PredefinedChartStyle;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.style.color.ColorSelectBox;
import java.awt.Component;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-17
*/
public class ChartDataSheetStylePane extends AbstractChartStylePane {
//字体样式
private ChartFontPane fontPane;
//边框颜色
private ColorSelectBox borderColor;
protected void initComponents() {
fontPane = new ChartFontPane() {
public String getUILabelText() {
return Toolkit.i18nText("Fine-Design_Chart_DataSheet_Character");
}
};
borderColor = new ColorSelectBox(100);
}
protected Component[][] getComponent() {
return new Component[][]{
new Component[]{fontPane, null},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Border_Color")), borderColor}
};
}
protected double[] getRows(double p) {
return new double[]{p, p, p};
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Data_Sheet");
}
public void populate(PredefinedChartStyle chartStyle) {
fontPane.populate(chartStyle.getDataSheetFont());
borderColor.setSelectObject(chartStyle.getDataSheetBorderColor());
}
public void update(PredefinedChartStyle chartStyle) {
chartStyle.setDataSheetFont(fontPane.update());
chartStyle.setDataSheetBorderColor(borderColor.getSelectObject());
}
}

160
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartFontPane.java

@ -1,160 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.chart;
import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.base.Utils;
import com.fr.design.constants.LayoutConstants;
import com.fr.design.dialog.BasicPane;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ibutton.UIColorButton;
import com.fr.design.gui.ibutton.UIToggleButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.FRFont;
import com.fr.general.GeneralUtils;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-16
*/
public class ChartFontPane extends BasicPane {
public static final int FONT_START = 6;
public static final int FONT_END = 72;
private UIComboBox fontNameComboBox;
private UIComboBox fontSizeComboBox;
private UIToggleButton bold;
private UIToggleButton italic;
private UIColorButton fontColor;
private static Integer[] FONT_SIZES = new Integer[FONT_END - FONT_START + 1];
static {
for (int i = FONT_START; i <= FONT_END; i++) {
FONT_SIZES[i - FONT_START] = i;
}
}
public ChartFontPane() {
initState();
initComponents();
}
private void initState() {
fontNameComboBox = new UIComboBox(Utils.getAvailableFontFamilyNames4Report());
fontSizeComboBox = new UIComboBox(FONT_SIZES);
bold = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png"));
italic = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png"));
fontColor = new UIColorButton();
}
protected void initComponents() {
Component[] components = new Component[]{
fontColor, italic, bold
};
JPanel buttonPane = new JPanel(new BorderLayout());
buttonPane.add(fontSizeComboBox, BorderLayout.CENTER);
buttonPane.add(GUICoreUtils.createFlowPane(components, FlowLayout.LEFT, LayoutConstants.HGAP_LARGE), BorderLayout.EAST);
this.setLayout(new BorderLayout());
this.add(getContentPane(buttonPane), BorderLayout.CENTER);
populate(FRContext.getDefaultValues().getFRFont());
}
protected JPanel getContentPane(JPanel buttonPane) {
double e = 155;
double p = TableLayout.PREFERRED;
double[] rows = {p, p, p};
double[] columnSize = {p, e};
UILabel text = new UILabel(getUILabelText(), SwingConstants.LEFT);
Component[][] components = {
new Component[]{null, null},
new Component[]{text, fontNameComboBox},
new Component[]{null, buttonPane}
};
return TableLayoutHelper.createGapTableLayoutPane(components, rows, columnSize, 20, LayoutConstants.VGAP_LARGE);
}
public String getUILabelText() {
return Toolkit.i18nText("Fine-Design_Chart_Character");
}
public String title4PopupWindow() {
return null;
}
public void populate(FRFont frFont) {
UIObserverListener listener = fontNameComboBox == null ? null : fontNameComboBox.getUiObserverListener();
removeAllComboBoxListener();
if (frFont != null) {
fontNameComboBox.setSelectedItem(frFont.getFamily());
bold.setSelected(frFont.isBold());
italic.setSelected(frFont.isItalic());
populateFontSize(frFont);
if (fontColor != null) {
fontColor.setColor(frFont.getForeground());
}
}
//更新结束后,注册监听器
registerAllComboBoxListener(listener);
}
private void populateFontSize(FRFont frFont) {
if (fontSizeComboBox != null) {
fontSizeComboBox.setSelectedItem(frFont.getSize());
}
}
private void removeAllComboBoxListener() {
fontNameComboBox.removeChangeListener();
fontSizeComboBox.removeChangeListener();
}
private void registerAllComboBoxListener(UIObserverListener listener) {
fontNameComboBox.registerChangeListener(listener);
fontSizeComboBox.registerChangeListener(listener);
}
/**
* 更新字
*
* @return 更新字
*/
public FRFont update() {
String name = GeneralUtils.objectToString(fontNameComboBox.getSelectedItem());
return FRFont.getInstance(name, updateFontStyle(), updateFontSize(), fontColor.getColor());
}
private int updateFontStyle() {
int style = Font.PLAIN;
if (bold.isSelected() && !italic.isSelected()) {
style = Font.BOLD;
} else if (!bold.isSelected() && italic.isSelected()) {
style = Font.ITALIC;
} else if (bold.isSelected() && italic.isSelected()) {
style = 3;
}
return style;
}
private float updateFontSize() {
return Float.parseFloat(GeneralUtils.objectToString(fontSizeComboBox.getSelectedItem()));
}
}

78
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartLabelStylePane.java

@ -1,78 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.chart;
import com.fr.config.predefined.PredefinedChartStyle;
import com.fr.design.gui.ibutton.UIButtonGroup;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-16
*/
public class ChartLabelStylePane extends AbstractChartStylePane {
private UIButtonGroup<Integer> autoButton;
//字体样式
private ChartFontPane chartFontPane;
protected void initComponents() {
autoButton = new UIButtonGroup<>(new String[]{Toolkit.i18nText("Fine-Design_Chart_Auto"),
Toolkit.i18nText("Fine-Design_Chart_Custom")});
chartFontPane = new ChartFontPane() {
public String getUILabelText() {
return Toolkit.i18nText("Fine-Design_Chart_Label_Character");
}
};
initListener();
}
protected Component[][] getComponent() {
return new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Style_Setting")), autoButton},
new Component[]{chartFontPane, null}
};
}
protected double[] getRows(double p) {
return new double[]{p, p, p};
}
private void initListener() {
autoButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
checkPreButton();
}
});
}
private void checkPreButton() {
chartFontPane.setVisible(autoButton.getSelectedIndex() == 1);
chartFontPane.setPreferredSize(autoButton.getSelectedIndex() == 1 ? new Dimension(0, 60) : new Dimension(0, 0));
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Label");
}
public void populate(PredefinedChartStyle chartStyle) {
autoButton.setSelectedIndex(chartStyle.isAutoLabelFont() ? 0 : 1);
chartFontPane.populate(chartStyle.getLabelFont());
checkPreButton();
}
public void update(PredefinedChartStyle chartStyle) {
chartStyle.setAutoLabelFont(autoButton.getSelectedIndex() == 0);
chartStyle.setLabelFont(chartFontPane.update());
}
}

49
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartLegendStylePane.java

@ -1,49 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.chart;
import com.fr.config.predefined.PredefinedChartStyle;
import com.fr.design.i18n.Toolkit;
import java.awt.Component;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-16
*/
public class ChartLegendStylePane extends AbstractChartStylePane {
//字体样式
private ChartFontPane chartFontPane;
protected void initComponents() {
chartFontPane = new ChartFontPane() {
public String getUILabelText() {
return Toolkit.i18nText("Fine-Design_Chart_Legend_Character");
}
};
}
protected Component[][] getComponent() {
return new Component[][]{
new Component[]{chartFontPane, null}
};
}
protected double[] getRows(double p) {
return new double[]{p};
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Legend");
}
public void populate(PredefinedChartStyle chartStyle) {
chartFontPane.populate(chartStyle.getLegendFont());
}
public void update(PredefinedChartStyle chartStyle) {
chartStyle.setLegendFont(chartFontPane.update());
}
}

49
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/chart/ChartTitleStylePane.java

@ -1,49 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.chart;
import com.fr.config.predefined.PredefinedChartStyle;
import com.fr.design.i18n.Toolkit;
import java.awt.Component;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-16
*/
public class ChartTitleStylePane extends AbstractChartStylePane {
//字体样式
private ChartFontPane chartFontPane;
protected void initComponents() {
chartFontPane = new ChartFontPane() {
public String getUILabelText() {
return Toolkit.i18nText("Fine-Design_Chart_Title_Character");
}
};
}
protected Component[][] getComponent() {
return new Component[][]{
new Component[]{chartFontPane, null}
};
}
protected double[] getRows(double p) {
return new double[]{p};
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Report_Title");
}
public void populate(PredefinedChartStyle chartStyle) {
chartFontPane.populate(chartStyle.getTitleFont());
}
public void update(PredefinedChartStyle chartStyle) {
chartStyle.setTitleFont(chartFontPane.update());
}
}

148
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/component/ComponentFrameStylePane.java

@ -1,148 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.component;
import com.fr.base.GraphHelper;
import com.fr.base.Utils;
import com.fr.config.predefined.PredefinedComponentStyle;
import com.fr.design.gui.frpane.UINumberDragPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIButtonUI;
import com.fr.design.gui.ibutton.UIColorButton;
import com.fr.design.gui.icombobox.LineComboBox;
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.BackgroundSpecialPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.backgroundpane.GradientBackgroundQuickPane;
import com.fr.general.act.BorderPacker;
import com.fr.stable.Constants;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.geom.RoundRectangle2D;
/**
* Created by kerry on 2020-09-01
*/
public class ComponentFrameStylePane extends ComponentStylePane {
private final static String[] BORDER_STYLE = new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Common"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Shadow")};
private static final double ALPHA_MAX_NUMBER = 100;
private final static int[] BORDER_LINE_STYLE_ARRAY = new int[]{
Constants.LINE_NONE,
Constants.LINE_THIN, //1px
Constants.LINE_MEDIUM, //2px
Constants.LINE_THICK, //3px
};
//渲染风格
private UIComboBox borderStyleCombo;
//边框粗细
private LineComboBox currentLineCombo;
//边框圆角
private UISpinner borderCornerSpinner;
//边框颜色
private UIColorButton currentLineColorPane;
//主体背景
private BackgroundSpecialPane backgroundPane;
//透明度
private UINumberDragPane numberDragPane;
public ComponentFrameStylePane() {
initPane();
}
protected void initPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0));
this.borderStyleCombo = new UIComboBox(BORDER_STYLE);
this.currentLineCombo = new LineComboBox(BORDER_LINE_STYLE_ARRAY);
this.currentLineColorPane = new UIColorButton(null);
this.borderCornerSpinner = new UISpinner(0, 1000, 1, 0);
currentLineColorPane.setUI(getButtonUI(currentLineColorPane));
currentLineColorPane.set4ToolbarButton();
currentLineColorPane.setPreferredSize(new Dimension(20, 20));
JPanel buttonPane = new JPanel(new BorderLayout());
buttonPane.add(currentLineColorPane, BorderLayout.WEST);
backgroundPane = new BackgroundSpecialPane();
JPanel transparencyPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.numberDragPane = new UINumberDragPane(0, 100);
transparencyPane.add(numberDragPane, BorderLayout.CENTER);
transparencyPane.add(new UILabel(" %"), BorderLayout.EAST);
double p = TableLayout.PREFERRED;
double[] rowSize = {p, p, p, p, p, p, p, p};
double[] columnSize = {p, 157};
JPanel rightTopContentPane = TableLayoutHelper.createCommonTableLayoutPane(new JComponent[][]{
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Render_Style")), borderStyleCombo},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Border_Line")), currentLineCombo},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Border_Color")), buttonPane},
getBorderCornerSpinnerComp(),
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget-Style_Body_Background")), backgroundPane},
{new UILabel(""), new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget-Style_Alpha"))},
{new UILabel(""), transparencyPane},
}, rowSize, columnSize, 10);
UIScrollPane rightTopPane = new UIScrollPane(rightTopContentPane);
rightTopPane.setBorder(BorderFactory.createEmptyBorder());
this.add(rightTopPane, BorderLayout.CENTER);
}
private JComponent[] getBorderCornerSpinnerComp() {
return new JComponent[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Radius") + ":"), borderCornerSpinner};
}
protected UIButtonUI getButtonUI(final UIColorButton uiColorButton) {
return new UIButtonUI() {
public void paint(Graphics g, JComponent c) {
UIButton b = (UIButton) c;
g.setColor(Color.black);
GraphHelper.draw(g, new RoundRectangle2D.Double(1, 1, b.getWidth() - 2, b.getHeight() - 2, 0, 0), 1);
if (b.getModel().isEnabled()) {
g.setColor(uiColorButton.getColor());
} else {
g.setColor(new Color(Utils.filterRGB(uiColorButton.getColor().getRGB(), 50)));
}
g.fillRect(2, 2, b.getWidth() - 3, b.getHeight() - 3);
}
};
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Frame");
}
@Override
public void populate(PredefinedComponentStyle componentStyle) {
BorderPacker borderStyle = componentStyle.getBorderStyle();
this.borderStyleCombo.setSelectedIndex(borderStyle.getBorderStyle());
this.borderCornerSpinner.setValue(borderStyle.getBorderRadius());
this.currentLineCombo.setSelectedLineStyle(borderStyle.getBorder());
this.currentLineColorPane.setColor(borderStyle.getColor());
this.backgroundPane.populateBean(borderStyle.getBackground());
numberDragPane.populateBean(borderStyle.getAlpha() * ALPHA_MAX_NUMBER);
}
@Override
public void update(PredefinedComponentStyle componentStyle) {
BorderPacker style = componentStyle.getBorderStyle();
style.setBorderStyle(borderStyleCombo.getSelectedIndex());
style.setBorderRadius((int) borderCornerSpinner.getValue());
style.setBorder(currentLineCombo.getSelectedLineStyle());
style.setColor(currentLineColorPane.getColor());
style.setBackground(backgroundPane.update());
style.setAlpha((float) (numberDragPane.updateBean() / ALPHA_MAX_NUMBER));
}
}

93
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/component/ComponentMarginStylePane.java

@ -1,93 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.component;
import com.fr.config.predefined.PredefinedComponentStyle;
import com.fr.design.designer.IntervalConstants;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ispinner.UISpinner;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
/**
* Created by kerry on 2020-09-01
*/
public class ComponentMarginStylePane extends ComponentStylePane {
protected UISpinner top;
protected UISpinner bottom;
protected UISpinner left;
protected UISpinner right;
public ComponentMarginStylePane() {
initBoundPane(0, 0, 0, 0);
}
public void initBoundPane(int t, int b, int l, int r) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
top = new UISpinner(0, Integer.MAX_VALUE, 1, t);
bottom = new UISpinner(0, Integer.MAX_VALUE, 1, b);
left = new UISpinner(0, Integer.MAX_VALUE, 1, l);
right = new UISpinner(0, Integer.MAX_VALUE, 1, r);
top.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout_Padding_Duplicate"));
bottom.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout_Padding_Duplicate"));
left.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout_Padding_Duplicate"));
right.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout_Padding_Duplicate"));
UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout_Padding_Duplicate"));
label.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L1, 0, 0, 0));
label.setVerticalAlignment(SwingConstants.TOP);
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(new Component[][]{
new Component[]{label, createRightPane()}}, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W2, IntervalConstants.INTERVAL_L1);
this.add(panel);
}
public JPanel createRightPane() {
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
double[] rowSize = {p, p};
double[] columnSize = {f, f};
int[][] rowCount = {{1, 1}, {1, 1}};
Component[][] components1 = new Component[][]{
new Component[]{top, bottom},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Top"), SwingConstants.CENTER), new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bottom"), SwingConstants.CENTER)}
};
Component[][] components2 = new Component[][]{
new Component[]{left, right},
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Left"), SwingConstants.CENTER), new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Right"), SwingConstants.CENTER)}
};
JPanel northPanel = TableLayoutHelper.createGapTableLayoutPane(components1, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_L6, IntervalConstants.INTERVAL_L6);
northPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, IntervalConstants.INTERVAL_L1, 0));
JPanel centerPanel = TableLayoutHelper.createGapTableLayoutPane(components2, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_L6, IntervalConstants.INTERVAL_L6);
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane();
panel.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L1, 0, IntervalConstants.INTERVAL_L1, 0));
panel.add(northPanel, BorderLayout.NORTH);
panel.add(centerPanel, BorderLayout.CENTER);
return panel;
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Base_Margin");
}
@Override
public void populate(PredefinedComponentStyle componentStyle) {
this.top.setValue(componentStyle.getTop());
this.bottom.setValue(componentStyle.getBottom());
this.left.setValue(componentStyle.getLeft());
this.right.setValue(componentStyle.getRight());
}
@Override
public void update(PredefinedComponentStyle componentStyle) {
componentStyle.setTop((int) this.top.getValue());
componentStyle.setBottom((int) this.bottom.getValue());
componentStyle.setLeft((int) this.left.getValue());
componentStyle.setRight((int) this.right.getValue());
}
}

15
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/component/ComponentStylePane.java

@ -1,15 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.component;
import com.fr.config.predefined.PredefinedComponentStyle;
import com.fr.design.dialog.BasicPane;
/**
* Created by kerry on 2020-09-01
*/
public abstract class ComponentStylePane extends BasicPane {
public abstract void populate(PredefinedComponentStyle componentStyle);
public abstract void update(PredefinedComponentStyle componentStyle);
}

253
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/detail/component/ComponentTitleStylePane.java

@ -1,253 +0,0 @@
package com.fr.design.mainframe.predefined.ui.detail.component;
import com.fr.base.BaseUtils;
import com.fr.base.Utils;
import com.fr.config.predefined.PredefinedComponentStyle;
import com.fr.design.constants.LayoutConstants;
import com.fr.design.constants.UIConstants;
import com.fr.design.formula.TinyFormulaPane;
import com.fr.design.gui.ibutton.UIButtonGroup;
import com.fr.design.gui.ibutton.UIColorButton;
import com.fr.design.gui.ibutton.UIToggleButton;
import com.fr.design.gui.icombobox.LineComboBox;
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.style.BackgroundNoImagePane;
import com.fr.design.gui.style.FRFontPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.backgroundpane.GradientBackgroundQuickPane;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.WidgetTitle;
import com.fr.general.FRFont;
import com.fr.general.act.BorderPacker;
import com.fr.general.act.TitlePacker;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
/**
* Created by kerry on 2020-09-01
*/
public class ComponentTitleStylePane extends ComponentStylePane {
private final static Dimension BUTTON_SIZE = new Dimension(24, 20);
//标题内容
private TinyFormulaPane formulaPane;
//标题格式
private UIComboBox fontNameComboBox;
private UIComboBox fontSizeComboBox;
private UIColorButton colorSelectPane;
private UIToggleButton bold;
private UIToggleButton italic;
private UIToggleButton underline;
private LineComboBox underlineCombo;
//对齐方式
private UIButtonGroup hAlignmentPane;
//标题背景
private BackgroundNoImagePane titleBackgroundPane;
public static ComponentTitleStylePane createPredefinedSettingPane(){
return new ComponentTitleStylePane(true);
}
public static ComponentTitleStylePane createStyleSettingPane(){
return new ComponentTitleStylePane(false);
}
private ComponentTitleStylePane(boolean isPredefined) {
initPane(isPredefined);
}
protected void initPane(boolean isPredefined) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(6, 0,0,0));
formulaPane = new TinyFormulaPane();
fontSizeComboBox = new UIComboBox(FRFontPane.FONT_SIZES);
fontNameComboBox = new UIComboBox(Utils.getAvailableFontFamilyNames4Report());
fontNameComboBox.setPreferredSize(new Dimension(105 , 20));
JPanel fontSizeTypePane = new JPanel(new BorderLayout(3, 0));
fontSizeTypePane.add(fontSizeComboBox, BorderLayout.CENTER);
fontSizeTypePane.add(fontNameComboBox, BorderLayout.EAST);
Icon[] hAlignmentIconArray = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"),
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"),
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png"),};
Integer[] hAlignment = new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT};
hAlignmentPane = new UIButtonGroup<Integer>(hAlignmentIconArray, hAlignment);
hAlignmentPane.setAllToolTips(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_StyleAlignment_Left")
, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_StyleAlignment_Center"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_StyleAlignment_Right")});
JPanel hPaneContainer = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
hPaneContainer.add(hAlignmentPane);
titleBackgroundPane = new BackgroundNoImagePane();
double p = TableLayout.PREFERRED;
double[] rowSize = {p, p, p, p, p, p, p, p};
double[] columnSize = {p, 157};
JComponent[][] jComponents = new JComponent[][]{
{new UILabel(com.fr.design.i18n.Toolkit.i18nText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Char"))), fontSizeTypePane},
{new UILabel(""), initFontButtonPane()},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Alignment-Style")), hAlignmentPane},
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Title_Background")), titleBackgroundPane}};
JComponent[][] displayComponents = createDisplayComponentArray(isPredefined, jComponents);
JPanel rightBottomContentPane = TableLayoutHelper.createCommonTableLayoutPane(displayComponents, rowSize, columnSize, 10);
UIScrollPane jPanel = new UIScrollPane(rightBottomContentPane);
jPanel.setBorder(BorderFactory.createEmptyBorder());
this.add(jPanel, BorderLayout.CENTER);
}
private JComponent[][] createDisplayComponentArray(boolean isPredefined, JComponent[][] baseComponents) {
if (isPredefined) {
return baseComponents;
}
JComponent[][] titleComponent = new JComponent[][]{{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Title_Content")), formulaPane}};
return ArrayUtils.addAll(titleComponent, baseComponents);
}
protected JPanel initFontButtonPane() {
colorSelectPane = new UIColorButton();
bold = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png"));
italic = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png"));
underline = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/underline.png"));
bold.setPreferredSize(BUTTON_SIZE);
italic.setPreferredSize(BUTTON_SIZE);
underline.setPreferredSize(BUTTON_SIZE);
underline.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
underlineCombo.setVisible(underline.isSelected());
}
});
underlineCombo = new LineComboBox(UIConstants.BORDER_LINE_STYLE_ARRAY);
Component[] components_font = new Component[]{
colorSelectPane, italic, bold, underline
};
JPanel buttonPane = new JPanel(new BorderLayout());
buttonPane.add(GUICoreUtils.createFlowPane(components_font, FlowLayout.LEFT, LayoutConstants.HGAP_SMALL));
JPanel combinePane = FRGUIPaneFactory.createBorderLayout_S_Pane();
combinePane.add(buttonPane, BorderLayout.WEST);
combinePane.add(underlineCombo, BorderLayout.CENTER);
initAllNames();
setToolTips();
return combinePane;
}
protected void initAllNames() {
fontNameComboBox.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Family"));
fontSizeComboBox.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Size"));
colorSelectPane.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Foreground"));
italic.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Italic"));
bold.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Bold"));
underline.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Underline"));
underlineCombo.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Line_Style"));
}
protected void setToolTips() {
colorSelectPane.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Foreground"));
italic.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Italic"));
bold.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Bold"));
underline.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_FRFont_Underline"));
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Title");
}
@Override
public void populate(PredefinedComponentStyle componentStyle) {
BorderPacker borderStyle = componentStyle.getBorderStyle();
TitlePacker widgetTitle = borderStyle == null ? new WidgetTitle() : borderStyle.getTitle();
widgetTitle = widgetTitle == null ? new WidgetTitle() : widgetTitle;
populateFormula(widgetTitle);
populateFont(widgetTitle);
hAlignmentPane.setSelectedItem(widgetTitle.getPosition());
titleBackgroundPane.populateBean(widgetTitle.getBackground());
}
private void populateFormula(TitlePacker widgetTitle) {
this.formulaPane.populateBean(widgetTitle.getTextObject().toString());
}
protected void populateFont(TitlePacker widgetTitle) {
FRFont frFont = widgetTitle.getFrFont();
this.fontSizeComboBox.setSelectedItem(frFont.getSize());
this.fontNameComboBox.setSelectedItem(frFont.getFamily());
this.colorSelectPane.setColor(frFont.getForeground());
this.colorSelectPane.repaint();
bold.setSelected(frFont.isBold());
italic.setSelected(frFont.isItalic());
int line = frFont.getUnderline();
if (line == Constants.LINE_NONE) {
underline.setSelected(false);
underlineCombo.setVisible(false);
} else {
underline.setSelected(true);
underlineCombo.setVisible(true);
this.underlineCombo.setSelectedLineStyle(line);
}
}
@Override
public void update(PredefinedComponentStyle componentStyle) {
BorderPacker style = componentStyle.getBorderStyle();
TitlePacker title = style.getTitle() == null ? new WidgetTitle() : style.getTitle();
String titleText = formulaPane.updateBean();
title.setTextObject(titleText);
style.setType(StringUtils.isEmpty(titleText) ? LayoutBorderStyle.STANDARD : LayoutBorderStyle.TITLE);
FRFont frFont = title.getFrFont();
frFont = frFont.applySize((Integer) fontSizeComboBox.getSelectedItem());
frFont = frFont.applyName(fontNameComboBox.getSelectedItem().toString());
frFont = frFont.applyForeground(colorSelectPane.getColor());
frFont = updateItalicBold(frFont);
int line = underline.isSelected() ? this.underlineCombo.getSelectedLineStyle() : Constants.LINE_NONE;
frFont = frFont.applyUnderline(line);
title.setFrFont(frFont);
title.setPosition((Integer) hAlignmentPane.getSelectedItem());
title.setBackground(titleBackgroundPane.update());
style.setTitle(title);
}
private FRFont updateItalicBold(FRFont frFont) {
int italic_bold = frFont.getStyle();
boolean isItalic = italic_bold == Font.ITALIC || italic_bold == (Font.BOLD + Font.ITALIC);
boolean isBold = italic_bold == Font.BOLD || italic_bold == (Font.BOLD + Font.ITALIC);
if (italic.isSelected() && !isItalic) {
italic_bold += Font.ITALIC;
} else if (!italic.isSelected() && isItalic) {
italic_bold -= Font.ITALIC;
}
frFont = frFont.applyStyle(italic_bold);
if (bold.isSelected() && !isBold) {
italic_bold += Font.BOLD;
} else if (!bold.isSelected() && isBold) {
italic_bold -= Font.BOLD;
}
frFont = frFont.applyStyle(italic_bold);
return frFont;
}
}

193
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/dialog/PredefinedStyleEditDialog.java

@ -1,193 +0,0 @@
package com.fr.design.mainframe.predefined.ui.dialog;
import com.fr.config.ServerPreferenceConfig;
import com.fr.config.predefined.PredefinedStyleConfig;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.mainframe.predefined.ui.PredefinedStyleEditPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* Created by kerry on 2020-08-26
*/
public class PredefinedStyleEditDialog extends JDialog {
public PredefinedStyleEditDialog(Window parent, PredefinedStyleEditPane contentPane) {
this(parent, contentPane, false);
}
public PredefinedStyleEditDialog(Window parent, PredefinedStyleEditPane contentPane, boolean isBuiltIn) {
super(parent, ModalityType.APPLICATION_MODAL);
this.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Style_Edit"));
this.setResizable(false);
JPanel defaultPane = FRGUIPaneFactory.createBorderLayout_L_Pane();
this.setContentPane(defaultPane);
UIButton saveBtn = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Save"));
saveBtn.setEnabled(!isBuiltIn);
saveBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(contentPane.saveStyle()){
dialogExit();
}
}
});
UIButton saveAsBtn = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Save_As_New"));
saveAsBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SaveAsNewStyleDialog saveAsNewStyleDialog = new SaveAsNewStyleDialog(PredefinedStyleEditDialog.this, contentPane);
saveAsNewStyleDialog.setVisible(true);
}
});
UIButton cancelBtn = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel"));
cancelBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialogExit();
}
});
JPanel buttonPanel = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
buttonPanel.add(saveBtn);
buttonPanel.add(saveAsBtn);
buttonPanel.add(cancelBtn);
defaultPane.add(contentPane, BorderLayout.CENTER);
defaultPane.add(buttonPanel, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dialogExit();
}
});
this.setSize(new Dimension(900, 600));
GUICoreUtils.centerWindow(this);
}
public void dialogExit() {
this.dispose();
}
class SaveAsNewStyleDialog extends JDialog {
private UITextField textField;
private UILabel tipLabel;
public SaveAsNewStyleDialog(Window parent, PredefinedStyleEditPane editPane) {
super(parent, ModalityType.APPLICATION_MODAL);
this.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Save_As_New"));
this.setResizable(false);
UIButton confirm = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Confirm"));
confirm.setEnabled(false);
confirm.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String name = textField.getText();
if (valid(name)) {
editPane.saveAsNewStyle(name);
dialogExit();
PredefinedStyleEditDialog.this.dialogExit();
} else {
tipLabel.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Name_Repeat"));
}
}
});
UIButton cancle = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel"));
cancle.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialogExit();
}
});
JPanel defaultPane = FRGUIPaneFactory.createBorderLayout_L_Pane();
JPanel buttonPanel = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
buttonPanel.add(confirm);
buttonPanel.add(cancle);
JPanel panel = createSaveAsPane(confirm);
defaultPane.add(panel, BorderLayout.CENTER);
defaultPane.add(buttonPanel, BorderLayout.SOUTH);
this.setContentPane(defaultPane);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dialogExit();
}
});
this.setSize(new Dimension(300, 140));
GUICoreUtils.centerWindow(this);
}
private JPanel createSaveAsPane(UIButton confirm) {
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel centerPane = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(20, 5);
centerPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Style_Name")));
textField = new UITextField();
textField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
confirm.setEnabled(StringUtils.isNotEmpty(textField.getText()));
}
@Override
public void removeUpdate(DocumentEvent e) {
}
@Override
public void changedUpdate(DocumentEvent e) {
}
});
textField.setPreferredSize(new Dimension(180, 20));
centerPane.add(textField);
panel.add(centerPane, BorderLayout.CENTER);
tipLabel = new UILabel();
tipLabel.setBorder(BorderFactory.createEmptyBorder(10, 20, 0, 0));
tipLabel.setForeground(Color.RED);
panel.add(tipLabel, BorderLayout.SOUTH);
return panel;
}
public void dialogExit() {
this.dispose();
}
private boolean valid(String name) {
PredefinedStyleConfig config = ServerPreferenceConfig.getInstance().getPreferenceStyleConfig();
return !config.containStyle(name);
}
}
}

97
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/dialog/ReportPredefinedStyleDialog.java

@ -1,97 +0,0 @@
package com.fr.design.mainframe.predefined.ui.dialog;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.predefined.ui.ReportPredefinedStylePane;
import com.fr.design.mainframe.predefined.ui.ServerPredefinedStylePane;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.workspace.WorkContext;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* Created by kerry on 2020-08-26
*/
public class ReportPredefinedStyleDialog extends JDialog {
public ReportPredefinedStyleDialog(Window parent, ReportPredefinedStylePane contentPane) {
super(parent, ModalityType.APPLICATION_MODAL);
this.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Template_Style"));
this.setResizable(false);
JPanel defaultPane = FRGUIPaneFactory.createBorderLayout_L_Pane();
this.setContentPane(defaultPane);
UIButton managerBtn = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Style_Manager"));
managerBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ServerPredefinedStylePane predefinedStylePane = new ServerPredefinedStylePane();
ServerPredefinedStyleDialog dialog = new ServerPredefinedStyleDialog(ReportPredefinedStyleDialog.this, predefinedStylePane);
dialog.setVisible(true);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
contentPane.refresh();
}
});
}
});
UIButton settingBtn = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Applicate_Style"));
settingBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
contentPane.update();
dialogExit();
}
});
UIButton cancelBtn = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel"));
cancelBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialogExit();
}
});
JPanel southPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
if (WorkContext.getCurrent().isRoot()){
JPanel buttonPanel1 = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane();
buttonPanel1.add(managerBtn);
southPane.add(buttonPanel1, BorderLayout.CENTER);
}
JPanel buttonPanel2 = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
buttonPanel2.add(settingBtn);
buttonPanel2.add(cancelBtn);
southPane.add(buttonPanel2, BorderLayout.EAST);
defaultPane.add(contentPane, BorderLayout.CENTER);
defaultPane.add(southPane, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dialogExit();
}
});
this.setSize(new Dimension(660, 600));
GUICoreUtils.centerWindow(this);
}
public void dialogExit() {
this.dispose();
}
}

68
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/dialog/ServerPredefinedStyleDialog.java

@ -1,68 +0,0 @@
package com.fr.design.mainframe.predefined.ui.dialog;
import com.fr.design.mainframe.predefined.ui.ServerPredefinedStylePane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* Created by kerry on 2020-08-26
*/
public class ServerPredefinedStyleDialog extends JDialog {
public ServerPredefinedStyleDialog(Window parent, ServerPredefinedStylePane contentPane) {
super(parent, ModalityType.APPLICATION_MODAL);
this.setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Predefined_Server_Style"));
this.setResizable(false);
JPanel defaultPane = FRGUIPaneFactory.createBorderLayout_L_Pane();
this.setContentPane(defaultPane);
UIButton settingBtn = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Set_Default"));
settingBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
contentPane.update();
dialogExit();
}
});
UIButton cancelBtn = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel"));
cancelBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialogExit();
}
});
JPanel buttonPanel = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
buttonPanel.add(settingBtn);
buttonPanel.add(cancelBtn);
defaultPane.add(contentPane, BorderLayout.CENTER);
defaultPane.add(buttonPanel, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dialogExit();
}
});
this.setSize(new Dimension(660, 600));
GUICoreUtils.centerWindow(this);
}
public void dialogExit(){
this.dispose();
}
}

108
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/ChartPreStylePreView.java

@ -1,108 +0,0 @@
package com.fr.design.mainframe.predefined.ui.preview;
import com.fr.base.chart.BaseChartCollection;
import com.fr.base.chart.BaseChartPainter;
import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.base.chart.result.WebChartIDInfo;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.config.predefined.PredefinedStyle;
import com.fr.design.gui.chart.MiddleChartComponent;
import com.fr.general.Background;
import com.fr.script.Calculator;
import com.fr.stable.core.PropertyChangeListener;
import javax.swing.BorderFactory;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-09-28
*/
public class ChartPreStylePreView extends MiddleChartComponent {
private ChartCollection chartCollection;
private double scaleX = 1.0;
private double scaleY = 1.0;
private CallbackEvent callbackEvent;
private static final int BOUNDS = 10;
private Background componentBackground;
public ChartPreStylePreView() {
}
public ChartPreStylePreView(ChartCollection cc) {
this(cc, 1.0, 1.0);
}
public ChartPreStylePreView(ChartCollection cc, double scaleX, double scaleY) {
this.scaleX = scaleX;
this.scaleY = scaleY;
this.setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10));
populate(cc);
}
public void setCallbackEvent(CallbackEvent callbackEvent) {
this.callbackEvent = callbackEvent;
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.translate(BOUNDS, BOUNDS);
g2d.scale(scaleX, scaleY);
super.paintComponent(g);
drawChart(g2d);
g2d.scale(1 / scaleX, 1 / scaleY);
g2d.translate(-BOUNDS, -BOUNDS);
}
private void drawChart(Graphics2D g2d) {
Dimension d = getBounds().getSize();
int chartWidth = (int) (d.width / scaleX) - BOUNDS * 2;
int chartHeight = (int) (d.height / scaleX) - BOUNDS * 2;
if (componentBackground != null) {
Graphics clipg = g2d.create(0, 0, chartWidth, chartHeight);
componentBackground.paint(clipg, clipg.getClipBounds());
}
BaseChartPainter painter = chartCollection.createResultChartPainterWithOutDealFormula(Calculator.createCalculator(),
WebChartIDInfo.createEmptyDesignerInfo(), chartWidth, chartHeight);
painter.paint(g2d, chartWidth, chartHeight, 0, null, callbackEvent);
}
public void refresh(PredefinedStyle style) {
/*VanChart vanChart = chartCollection.getSelectedChartProvider(VanChart.class);
List<ChartThemeStyleProvider> chartThemeStyleProviders = vanChart.getChartPreStyleProvider();
for (ChartThemeStyleProvider chartThemeStyleProvider : chartThemeStyleProviders) {
chartThemeStyleProvider.updateThemeStyle(style);
}
componentBackground = style.getComponentStyle().getBorderStyle().getBackground();
vanChart.attrChange();*/
}
@Override
public void populate(BaseChartCollection cc) {
this.chartCollection = (ChartCollection) cc;
}
@Override
public BaseChartCollection update() {
return this.chartCollection;
}
@Override
public void addStopEditingListener(PropertyChangeListener l) {
}
@Override
public void reset() {
}
}

142
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/ComponentPreviewPane.java

@ -1,142 +0,0 @@
package com.fr.design.mainframe.predefined.ui.preview;
import com.fr.base.FRContext;
import com.fr.base.GraphHelper;
import com.fr.config.predefined.PredefinedStyle;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.Background;
import com.fr.general.FRFont;
import com.fr.general.act.BorderPacker;
import com.fr.general.act.TitlePacker;
import com.fr.stable.Constants;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
/**
* Created by kerry on 2020-09-04
*/
public abstract class ComponentPreviewPane extends StyleSettingPreviewPane {
private PredefinedStyle style = new PredefinedStyle();
private static final int SMALL_GAP = 10;
private static final int GAP = 10;
private JPanel contentPane;
private TitlePreviewPane titlePane;
public ComponentPreviewPane() {
this.setBackground(null);
this.setOpaque(false);
this.contentPane = createContentPane();
this.titlePane = new TitlePreviewPane();
this.titlePane.setPreferredSize(new Dimension(484, 35));
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10));
this.add(titlePane, BorderLayout.NORTH);
this.add(contentPane, BorderLayout.CENTER);
}
protected abstract JPanel createContentPane();
public void refresh() {
this.repaint();
}
public void refresh(PredefinedStyle style) {
this.style = style;
}
public void paintComponents(Graphics g) {
BorderPacker borderStyle = style.getComponentStyle().getBorderStyle();
updateBorders(g, borderStyle);
paintTitle(g, borderStyle.getTitle());
paintContentPane(g, borderStyle);
super.paintComponents(g);
}
private void paintContentPane(Graphics g, BorderPacker borderStyle) {
Graphics clipg;
clipg = g.create(10, 40, this.contentPane.getWidth(), this.contentPane.getHeight());
if (borderStyle.getBackground() != null) {
borderStyle.getBackground().paint(clipg, clipg.getClipBounds());
}
clipg.dispose();
}
private void paintTitle(Graphics g, TitlePacker titlePacker) {
Background background = titlePacker.getBackground();
if (background != null) {
background.paint(g, new Rectangle2D.Double(10, 5, this.titlePane.getWidth(), this.titlePane.getHeight()));
}
titlePane.setTitleObject(titlePacker);
titlePane.paintComponent(g);
}
private void updateBorders(Graphics g, BorderPacker borderStyle) {
if (borderStyle != null) {
borderStyle.paint(g, new Rectangle2D.Double(SMALL_GAP, SMALL_GAP, getWidth() - GAP, getHeight() - SMALL_GAP - GAP));
}
}
private class TitlePreviewPane extends JPanel {
private FRFont frFont = null;
private int titlePosition = Constants.LEFT;
public TitlePreviewPane() {
this.setBackground(null);
this.setOpaque(false);
frFont = FRContext.getDefaultValues().getFRFont();
}
@Override
public void paint(Graphics g) {
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Dimension d = getSize();
if (frFont == null) {
return;
}
FontMetrics fm = getFontMetrics(frFont);
if (this.isEnabled()) {
g2d.setColor(frFont.getForeground());
} else {
g2d.setColor(new Color(237, 237, 237));
}
g2d.setFont(frFont.applyResolutionNP(96));
String paintText = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Predefined_Preview_Title_Text");
int startY = 0, startX = 0;
startX = (d.width - fm.stringWidth(paintText)) / 2;
startY = (d.height - fm.getHeight()) / 2 + fm.getAscent();
if (this.titlePosition == Constants.LEFT) {
startX = GAP;
} else if (this.titlePosition == Constants.RIGHT) {
startX = d.width - fm.stringWidth(paintText) - GAP - fm.getMaxAdvance();
}
GraphHelper.drawString(g2d, paintText, startX, startY);
}
public void setTitleObject(TitlePacker titlePacker) {
this.frFont = titlePacker.getFrFont();
this.titlePosition = titlePacker.getPosition();
}
}
}

171
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/ElementCasePreview.java

@ -1,171 +0,0 @@
package com.fr.design.mainframe.predefined.ui.preview;
import com.fr.base.ScreenResolution;
import com.fr.base.Style;
import com.fr.config.predefined.PredefinedCellStyle;
import com.fr.config.predefined.PredefinedCellStyleConfig;
import com.fr.config.predefined.PredefinedStyle;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.log.FineLoggerFactory;
import com.fr.third.javax.annotation.Nonnull;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
/**
* Created by kerry on 2020-09-04
*/
public class ElementCasePreview extends ComponentPreviewPane {
private static final List<String[]> PREVIEW_DATA_LIST = new ArrayList<>();
private static final String BLANK_CHAR = " ";
private List<GridRowPane> gridRowPanes;
static {
readPreviewData();
}
private static void readPreviewData() {
try {
InputStream inputStream = ElementCasePreview.class.getResourceAsStream("/com/fr/design/mainframe/predefined/previewData");
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,
StandardCharsets.UTF_8));
String lineTxt = null;
while ((lineTxt = br.readLine()) != null) {
String[] data = lineTxt.split(BLANK_CHAR);
PREVIEW_DATA_LIST.add(data);
}
br.close();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
@Override
protected JPanel createContentPane() {
gridRowPanes = new ArrayList<>();
JPanel jPanel = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
jPanel.setOpaque(false);
jPanel.setBackground(null);
for (int i = 0; i < PREVIEW_DATA_LIST.size(); i++) {
GridRowPane gridRowPane = new GridRowPane(PREVIEW_DATA_LIST.get(i), Style.DEFAULT_STYLE);
gridRowPanes.add(gridRowPane);
jPanel.add(gridRowPane);
}
return jPanel;
}
public void refresh(PredefinedStyle style) {
super.refresh(style);
PredefinedCellStyleConfig cellStyleConfig = style.getCellStyleConfig();
for (int i = 0; i < gridRowPanes.size(); i++) {
Style renderStyle = getMainContentStyle(cellStyleConfig);
if (i == 0) {
renderStyle = getReportHeaderStyle(cellStyleConfig);
}
if (i == PREVIEW_DATA_LIST.size() - 1) {
renderStyle = getHighLightStyle(cellStyleConfig);
}
gridRowPanes.get(i).preview(renderStyle);
}
}
private Style getReportHeaderStyle(PredefinedCellStyleConfig config) {
return getCellStyle(config, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header"));
}
private Style getMainContentStyle(PredefinedCellStyleConfig config) {
return getCellStyle(config, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Main_Text"));
}
private Style getHighLightStyle(PredefinedCellStyleConfig config) {
return getCellStyle(config, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Highlight_Text"));
}
@Nonnull
private Style getCellStyle(PredefinedCellStyleConfig config, String styleName) {
PredefinedCellStyle cellStyle = config.getStyle(styleName);
if (cellStyle == null) {
return Style.DEFAULT_STYLE;
}
return cellStyle.getStyle();
}
class GridRowPane extends JPanel {
private List<GridPreview> gridPreviews = new ArrayList<>();
public GridRowPane(String[] data, Style style) {
this.setOpaque(false);
this.setBackground(null);
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel panel = FRGUIPaneFactory.createNColumnGridInnerContainer_Pane(4, 0, 0);
panel.setOpaque(false);
panel.setBackground(null);
for (String text : data) {
GridPreview gridPreview = new GridPreview(text);
gridPreviews.add(gridPreview);
panel.add(gridPreview);
}
this.add(panel, BorderLayout.CENTER);
preview(style);
}
public void preview(Style style) {
for (GridPreview grid : gridPreviews) {
grid.preview(style);
}
}
}
private static class GridPreview extends JComponent {
private Style style = Style.DEFAULT_STYLE;
private String value;
public GridPreview(String value) {
this.value = value;
setPreferredSize(new Dimension(125, 30));
}
public void preview(Style style) {
this.style = style;
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
int resolution = ScreenResolution.getScreenResolution();
if (style == Style.DEFAULT_STYLE) {
Style.paintContent(g2d, value, style, getWidth() - 3, getHeight() - 3, resolution);
return;
}
Style.paintBackground(g2d, style, getWidth(), getHeight());
Style.paintContent(g2d, value, style, getWidth() - 3, getHeight() - 3, resolution);
Style.paintBorder(g2d, style, getWidth() , getHeight() );
}
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}
}
}

157
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/PredefinedStylePreviewPane.java

@ -1,157 +0,0 @@
package com.fr.design.mainframe.predefined.ui.preview;
import com.fr.base.background.ColorBackground;
import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.chartattr.Title;
import com.fr.chart.charttypes.ChartTypeManager;
import com.fr.config.predefined.PredefinedStyle;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.utils.ComponentUtils;
import com.fr.general.Background;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.chart.attr.axis.VanChartAxis;
import com.fr.plugin.chart.base.AttrLabel;
import com.fr.plugin.chart.base.VanChartTools;
import com.fr.plugin.chart.column.VanChartColumnPlot;
import com.fr.plugin.chart.vanchart.VanChart;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.util.ArrayList;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
/**
* Created by kerry on 2020-09-06
*/
public class PredefinedStylePreviewPane extends StyleSettingPreviewPane implements CallbackEvent {
private ElementCasePreview elementCasePreview;
private Background background;
private double scaleX = 1.0;
private double scaleY = 1.0;
private ChartPreStylePreView columnChartPane;
private int COLUMN_CHART_WIDTH = 517;
private int COLUMN_CHART_HEIGHT = 290;
private JPanel parent;
public PredefinedStylePreviewPane() {
this(1.0, 1.0);
}
public PredefinedStylePreviewPane(double scaleX, double scaleY) {
this.scaleX = scaleX;
this.scaleY = scaleY;
this.setBackground(Color.WHITE);
this.elementCasePreview = new ElementCasePreview();
this.add(initChartPreViewPane());
this.elementCasePreview.setPreferredSize(new Dimension(517, 200));
this.add(this.elementCasePreview);
}
public void setParent(JPanel parent) {
this.parent = parent;
}
private JPanel initChartPreViewPane() {
columnChartPane = new ChartPreStylePreView(initVanColumnChart());
columnChartPane.setPreferredSize(new Dimension(COLUMN_CHART_WIDTH, COLUMN_CHART_HEIGHT));
columnChartPane.setCallbackEvent(this);
JPanel panel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
panel.add(columnChartPane);
return panel;
}
//柱形图
private ChartCollection initVanColumnChart() {
try {
VanChart chart = (VanChart) ChartTypeManager.getInstance().getCharts(VanChartColumnPlot.VAN_CHART_COLUMN_PLOT_ID)[0].clone();
VanChartTools vanChartTools = chart.getVanChartTools();
vanChartTools.setSort(false);
vanChartTools.setExport(false);
vanChartTools.setFullScreen(false);
VanChartColumnPlot plot = chart.getPlot();
AttrLabel defaultAttrLabel = plot.getDefaultAttrLabel();
defaultAttrLabel.setEnable(true);
defaultAttrLabel.getAttrLabelDetail().getBorder().setBorderStyle(0);
defaultAttrLabel.getAttrLabelDetail().getBackground().setBackground(null);
plot.getConditionCollection().getDefaultAttr().addDataSeriesCondition(defaultAttrLabel);
plot.getLegend().setLegendVisible(false);
plot.getDataSheet().setVisible(true);
VanChartAxis defaultYAxis = plot.getDefaultYAxis();
Title title = new Title();
title.setTextObject(Toolkit.i18nText("Fine-Design_Chart_Axis_Title"));
title.getTextAttr().setRotation(-90);
defaultYAxis.setTitle(title);
defaultYAxis.setShowAxisTitle(true);
ChartCollection chartCollection = new ChartCollection(chart);
return chartCollection;
} catch (Exception ex) {
FineLoggerFactory.getLogger().error(ex.getMessage(), ex);
}
return null;
}
@Override
public void refresh() {
}
@Override
public void paint(Graphics g) {
((Graphics2D) g).scale(scaleX, scaleY);
// 禁止双缓冲
ArrayList<JComponent> dbcomponents = new ArrayList<JComponent>();
ComponentUtils.disableBuffer(this.elementCasePreview, dbcomponents);
if (background == null) {
background = ColorBackground.getInstance(Color.WHITE);
}
background.paint(g, new Rectangle2D.Double(0, 0, 517, 500));
this.columnChartPane.paintComponent(g);
g.translate(0, COLUMN_CHART_HEIGHT);
this.elementCasePreview.paintComponents(g);
g.translate(0, -COLUMN_CHART_HEIGHT);
// 恢复双缓冲
ComponentUtils.resetBuffer(dbcomponents);
}
@Override
public void paintComponents(Graphics g) {
super.paintComponents(g);
if (background != null) {
background.paint(g, new Rectangle2D.Double(0, 0, this.getWidth(), this.getHeight()));
}
}
public void refresh(PredefinedStyle style) {
refresh(style, false);
}
public void refresh(PredefinedStyle style, boolean displayFormBackground) {
elementCasePreview.refresh(style);
columnChartPane.refresh(style);
background = displayFormBackground ? style.getFormBackground().getBackground() : style.getReportBackground();
this.repaint();
}
@Override
public void callback() {
if (parent != null) {
parent.repaint();
} else {
this.repaint();
}
}
}

17
designer-base/src/main/java/com/fr/design/mainframe/predefined/ui/preview/StyleSettingPreviewPane.java

@ -1,17 +0,0 @@
package com.fr.design.mainframe.predefined.ui.preview;
import javax.swing.JPanel;
/**
* Created by kerry on 2020-08-31
*/
public abstract class StyleSettingPreviewPane extends JPanel {
public StyleSettingPreviewPane() {
}
public abstract void refresh();
}

4
designer-base/src/main/java/com/fr/design/mainframe/share/ComponentShareUtil.java

@ -34,6 +34,10 @@ public class ComponentShareUtil {
return localeMark.getValue();
}
public static boolean isShowMiniShopWindow() {
return isShowOnlineWidgetRepoPane();
}
/**
* 判断是否可触达
*

37
designer-base/src/main/java/com/fr/design/mainframe/share/mini/MiniShopDisposingChecker.java

@ -0,0 +1,37 @@
package com.fr.design.mainframe.share.mini;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import javax.swing.JOptionPane;
import java.awt.Component;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2022/1/8
*/
public class MiniShopDisposingChecker {
public static boolean check() {
return check(DesignerContext.getDesignerFrame());
}
public static boolean check(Component optionParentComponent) {
if (MiniShopNativeTaskManager.getInstance().hasExecutingTasks()) {
int result = FineJOptionPane.showConfirmDialog(
optionParentComponent,
Toolkit.i18nText("Fine-Design_Share_Online_Mini_Shop_Close_Tip"),
"",
FineJOptionPane.YES_NO_OPTION
);
if (result == JOptionPane.YES_OPTION) {
MiniShopNativeTaskManager.getInstance().cancelAllExecutingTasks();
return true;
}
return false;
}
return true;
}
}

11
designer-base/src/main/java/com/fr/design/mainframe/share/mini/MiniShopNativeTask.java

@ -0,0 +1,11 @@
package com.fr.design.mainframe.share.mini;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2022/1/8
*/
public interface MiniShopNativeTask {
void execute();
void cancel();
}

42
designer-base/src/main/java/com/fr/design/mainframe/share/mini/MiniShopNativeTaskManager.java

@ -0,0 +1,42 @@
package com.fr.design.mainframe.share.mini;
import java.util.HashSet;
import java.util.Set;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2022/1/8
*/
public class MiniShopNativeTaskManager {
private MiniShopNativeTaskManager() {
}
private static class HOLDER {
private static final MiniShopNativeTaskManager singleton = new MiniShopNativeTaskManager();
}
public static MiniShopNativeTaskManager getInstance() {
return MiniShopNativeTaskManager.HOLDER.singleton;
}
private static final Set<MiniShopNativeTask> executingTasks = new HashSet<>();
public void addStartedTask(MiniShopNativeTask task) {
executingTasks.add(task);
}
public void removeCompletedTask(MiniShopNativeTask task) {
executingTasks.remove(task);
}
public boolean hasExecutingTasks() {
return !executingTasks.isEmpty();
}
public void cancelAllExecutingTasks() {
for (MiniShopNativeTask executingTask: executingTasks) {
executingTask.cancel();
}
executingTasks.clear();
}
}

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

@ -206,7 +206,7 @@ public abstract class TemplateThemeProfilePane<T extends TemplateTheme> extends
});
}
public UIButton createSaveButton() {
public UIButton createSaveButton(final TemplateThemeProfileDialog<T> profileDialog) {
saveButton = new UIButton();
saveButton.setText(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Profile_Pane_Save"));
saveButton.setEnabled(false);
@ -224,6 +224,7 @@ public abstract class TemplateThemeProfilePane<T extends TemplateTheme> extends
@Override
public void run() {
DesignerToastMsgUtil.toastPrompt(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Profile_Pane_Save_Successfully"));
profileDialog.exit();
}
});
}

9
designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeGridPagesDialog.java

@ -7,6 +7,7 @@ import com.fr.design.mainframe.theme.TemplateThemeGridPagesPane;
import com.fr.design.mainframe.theme.TemplateThemeGridPane;
import javax.swing.JPanel;
import java.awt.Window;
/**
* @author Starryi
@ -19,13 +20,17 @@ public class TemplateThemeGridPagesDialog extends TemplateThemeDialog implements
protected TemplateThemeGridPagesPane overallPane;
public TemplateThemeGridPagesDialog() {
super(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Using_Dialog_Title"), CONTENT_WIDTH, CONTENT_HEIGHT);
public TemplateThemeGridPagesDialog(Window parentWindow) {
super(parentWindow, Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Using_Dialog_Title"), CONTENT_WIDTH, CONTENT_HEIGHT);
setupContentPane();
setupActionButtons();
}
public TemplateThemeGridPagesDialog() {
this(DesignerContext.getDesignerFrame());
}
@Override
protected JPanel createContentPane() {
overallPane = new TemplateThemeGridPagesPane(this);

2
designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeProfileDialog.java

@ -90,7 +90,7 @@ public class TemplateThemeProfileDialog<T extends TemplateTheme> extends Templat
}));
}
uiButtonList.add(profilePane.createSaveButton());
uiButtonList.add(profilePane.createSaveButton(TemplateThemeProfileDialog.this));
uiButtonList.add(profilePane.createSaveAsButton(TemplateThemeProfileDialog.this));
uiButtonList.add(createCancelButton());

7
designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeUsingDialog.java

@ -1,11 +1,18 @@
package com.fr.design.mainframe.theme.dialog;
import java.awt.Window;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2021/8/13
*/
public class TemplateThemeUsingDialog extends TemplateThemeGridPagesDialog {
public TemplateThemeUsingDialog(Window parentWindow) {
super(parentWindow);
overallPane.showThemeUsingPane();
}
public TemplateThemeUsingDialog() {
super();
overallPane.showThemeUsingPane();

2
designer-base/src/main/java/com/fr/design/mainframe/theme/edit/ReportBodyStyleEditPane.java

@ -8,13 +8,11 @@ import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.predefined.ui.detail.background.BackgroundSettingPane;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;

6
designer-base/src/main/java/com/fr/design/report/fit/AdaptiveFrmFitAttrModel.java

@ -13,11 +13,7 @@ import com.fr.report.fit.ReportFitAttr;
public class AdaptiveFrmFitAttrModel extends AbstractFitAttrModelProvider {
public FitType[] getFitTypes() {
return new FitType[]{
FitType.DOUBLE_FIT,
FitType.HORIZONTAL_FIT,
FitType.NOT_FIT
};
return new FitType[0];
}
public String getFitName() {

130
designer-base/src/main/java/com/fr/design/report/fit/BaseFitAttrPane.java

@ -2,27 +2,17 @@ package com.fr.design.report.fit;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.DesignSizeI18nManager;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.report.fit.menupane.FitPreviewPane;
import com.fr.design.report.fit.menupane.FitRadioGroup;
import com.fr.design.report.fit.menupane.FontRadioGroup;
import com.fr.design.report.fit.provider.FitAttrModelProvider;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.report.fit.ReportFitAttr;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Set;
import java.util.stream.Collectors;
@ -35,11 +25,8 @@ public abstract class BaseFitAttrPane extends BasicBeanPane<ReportFitAttr> {
protected UILabel belowSetLabel;
protected UIComboBox itemChoose;
protected java.util.List<FitAttrModel> fitAttrModelList = new ArrayList<>();
private ReportFitConfigPane fitConfigPane;
public FontRadioGroup fontRadioGroup;
public FitRadioGroup adaptRadioGroup;
public JPanel attrJPanel;
public FitPreviewPane previewJPanel;
public FitAttrModel fitAttrModel;
private static final int BELOW_SET_COMPONENT_HSPACE = 8;
@ -64,128 +51,27 @@ public abstract class BaseFitAttrPane extends BasicBeanPane<ReportFitAttr> {
protected void populateModel(FitAttrModel fitAttrModel) {
this.fitAttrModel = fitAttrModel;
if (attrJPanel != null) {
contentJPanel.remove(attrJPanel);
if (fitConfigPane != null) {
contentJPanel.remove(fitConfigPane);
}
if (previewJPanel != null) {
contentJPanel.remove(previewJPanel);
}
fontRadioGroup = new FontRadioGroup();
adaptRadioGroup = new FitRadioGroup();
initAttrJPanel();
initPreviewJPanel();
this.fitConfigPane = fitAttrModel instanceof CptFitAttrModel ? new ReportFitConfigPane(fitAttrModel, true) : new FormFitConfigPane(fitAttrModel, true);
contentJPanel.add(fitConfigPane);
}
protected void initAttrJPanel() {
int colCount = fitAttrModel.getFitTypes().length + 1;
Component[][] components = new Component[2][colCount];
initFitRadioGroup(fontRadioGroup, i18nText("Fine-Designer_Fit-Font"), new String[]{i18nText("Fine-Designer_Fit"), i18nText("Fine-Designer_Fit-No")}, components[0]);
initFitRadioGroup(adaptRadioGroup, fitAttrModel.getFitName(), Arrays.stream(fitAttrModel.getFitTypes()).map(FitType::description).toArray(String[]::new), components[1]);
double[] rowSize = new double[2];
double[] columnSize = new double[colCount];
for (int i = 0; i < rowSize.length; i++) {
rowSize[i] = 20;
}
for (int i = 0; i < columnSize.length; i++) {
if (i == 0) {
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.firstColumn").getWidth();
} else {
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.column").getWidth();
}
}
attrJPanel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
attrJPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));
contentJPanel.add(attrJPanel);
}
private void initFitRadioGroup(FitRadioGroup fitRadioGroup, String name, String[] options, Component[] components) {
components[0] = new UILabel(name);
for (int i = 0; i < options.length; i++) {
if (options[i] != null) {
UIRadioButton fontFitRadio = new UIRadioButton(options[i]);
fitRadioGroup.add(fontFitRadio);
components[i + 1] = fontFitRadio;
} else {
components[i + 1] = null;
}
}
fitRadioGroup.addActionListener(getPreviewActionListener());
}
protected ActionListener getPreviewActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshPreviewJPanel();
}
};
}
protected void refreshPreviewJPanel() {
String previewIndex = getPreviewIndex();
previewJPanel.refreshPreview(previewIndex, fontRadioGroup.isEnabled());
}
protected String getPreviewIndex() {
return getStateInPC(adaptRadioGroup.getSelectRadioIndex()) + "" + fontRadioGroup.getSelectRadioIndex();
}
protected void initPreviewJPanel() {
previewJPanel = new FitPreviewPane();
previewJPanel.setBorder(BorderFactory.createEmptyBorder(0, getPreviewJPanelLeft(), 0, 0));
contentJPanel.add(previewJPanel);
}
private int getPreviewJPanelLeft() {
int left = 0;
if (belowSetLabel.getPreferredSize() != null) {
left = belowSetLabel.getPreferredSize().width + BELOW_SET_COMPONENT_HSPACE;
}
return left;
}
protected int getStateInPC(int index) {
FitType[] fitTypes = fitAttrModel.getFitTypes();
return fitTypes[index].getState();
}
protected int getOptionIndex(int state) {
FitType[] fitTypes = fitAttrModel.getFitTypes();
for (int i = 0; i < fitTypes.length; i++) {
if (ComparatorUtils.equals(state, fitTypes[i].getState())) {
return i;
}
}
return 0;
}
@Override
public void populateBean(ReportFitAttr ob) {
fontRadioGroup.selectIndexButton(ob.isFitFont() ? 0 : 1);
adaptRadioGroup.selectIndexButton(getOptionIndex(ob.fitStateInPC()));
refreshPreviewJPanel();
this.fitConfigPane.populateBean(ob);
}
@Override
public ReportFitAttr updateBean() {
ReportFitAttr reportFitAttr = new ReportFitAttr();
reportFitAttr.setFitFont(fontRadioGroup.isFontFit());
reportFitAttr.setFitStateInPC(getStateInPC(adaptRadioGroup.getSelectRadioIndex()));
return reportFitAttr;
return this.fitConfigPane.updateBean();
}
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
fontRadioGroup.setEnabled(enabled);
adaptRadioGroup.setEnabled(enabled);
refreshPreviewJPanel();
this.fitConfigPane.setEnabled(enabled);
}
@Override

9
designer-base/src/main/java/com/fr/design/report/fit/FitAttrModel.java

@ -3,6 +3,8 @@ package com.fr.design.report.fit;
import com.fr.design.mainframe.JTemplate;
import com.fr.report.fit.ReportFitAttr;
import java.util.Arrays;
public interface FitAttrModel {
/**
* @Description 名称比如普通报表决策报表等
@ -19,6 +21,12 @@ public interface FitAttrModel {
**/
FitType[] getFitTypes();
/**
* @Description 表格自适应选项名称集合
**/
default String[] getFitTypeNames(){
return Arrays.stream(getFitTypes()).map(FitType::description).toArray(String[]::new);
}
/**
* @Description 获取全局的自适应属性
@ -41,4 +49,5 @@ public interface FitAttrModel {
* @param: jTemplate
**/
boolean isAvailable(JTemplate jTemplate);
}

11
designer-base/src/main/java/com/fr/design/report/fit/FitType.java

@ -60,6 +60,17 @@ public enum FitType {
return DEFAULT;
}
public static FitType parseByFitState(int state) {
for (FitType attrState : values()) {
if (attrState.state == state) {
return attrState;
}
}
return DEFAULT;
}
public int getState() {
return this.state;
}

128
designer-base/src/main/java/com/fr/design/report/fit/FormFitAttrModelType.java

@ -0,0 +1,128 @@
package com.fr.design.report.fit;
import com.fr.design.designer.properties.items.Item;
import com.fr.form.fit.common.LightTool;
import com.fr.form.main.BodyScaleAttrTransformer;
import com.fr.form.main.Form;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WBodyLayoutType;
import com.fr.form.ui.container.WFitLayout;
public enum FormFitAttrModelType {
PLAIN_FORM_FIT_ATTR_MODEL {
@Override
public FitAttrModel getFitAttrModel() {
return new FrmFitAttrModel();
}
@Override
public Item[] getFitLayoutScaleAttr() {
return new Item[]{
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Bidirectional_Adaptive"), WFitLayout.STATE_FULL),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Horizontal_Adaptive"), WFitLayout.STATE_ORIGIN)};
}
@Override
public Item[] getAbsoluteLayoutSaleAttr() {
return new Item[]{
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Bidirectional_Adaptive"), WAbsoluteLayout.STATE_FIT),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit-No"), WAbsoluteLayout.STATE_FIXED)
};
}
@Override
public int getScaleAttrShowIndex(WFitLayout wFitLayout) {
int scale = wFitLayout.getScaleAttr();
if (wFitLayout.getBodyLayoutType() == WBodyLayoutType.FIT) {
return BodyScaleAttrTransformer.getFitBodyCompStateFromScaleAttr(scale);
} else {
return BodyScaleAttrTransformer.getAbsoluteBodyCompStateFromScaleAttr(scale);
}
}
@Override
public int parseScaleAttrFromShowIndex(int showIndex, WBodyLayoutType wBodyLayoutType) {
if (wBodyLayoutType == WBodyLayoutType.FIT) {
if (showIndex == 0) {
return WFitLayout.SCALE_FULL;
} else {
return WFitLayout.SCALE_HOR;
}
} else {
if (showIndex == 0) {
return WFitLayout.SCALE_FULL;
} else {
return WFitLayout.SCALE_NO;
}
}
}
},
NEW_FORM_FIT_ATTR_MODEL {
@Override
public FitAttrModel getFitAttrModel() {
return new AdaptiveFrmFitAttrModel();
}
@Override
public Item[] getFitLayoutScaleAttr() {
return new Item[]{
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Bidirectional_Adaptive"), WFitLayout.STATE_FULL),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Horizontal_Adaptive"), WFitLayout.STATE_ORIGIN),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit-No"), 2)};
}
@Override
public Item[] getAbsoluteLayoutSaleAttr() {
return new Item[]{
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Bidirectional_Adaptive"), WFitLayout.STATE_FULL),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Horizontal_Adaptive"), WFitLayout.STATE_ORIGIN),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit-No"), 2)};
}
@Override
public int getScaleAttrShowIndex(WFitLayout wFitLayout) {
int scale = wFitLayout.getScaleAttr();
if (scale == WFitLayout.SCALE_NO) {
return 2;
} else if (scale == WFitLayout.SCALE_HOR) {
return 1;
} else {
return 0;
}
}
@Override
public int parseScaleAttrFromShowIndex(int showIndex, WBodyLayoutType wBodyLayoutType) {
if (showIndex == 0) {
return WFitLayout.SCALE_FULL;
} else if (showIndex == 1) {
return WFitLayout.SCALE_HOR;
} else {
return WFitLayout.SCALE_NO;
}
}
};
public abstract FitAttrModel getFitAttrModel();
public abstract Item[] getFitLayoutScaleAttr();
public abstract Item[] getAbsoluteLayoutSaleAttr();
public abstract int getScaleAttrShowIndex(WFitLayout wFitLayout);
public abstract int parseScaleAttrFromShowIndex(int showIndex, WBodyLayoutType wBodyLayoutType);
public static FormFitAttrModelType parse(Form form) {
return LightTool.containNewFormFlag(form) ? NEW_FORM_FIT_ATTR_MODEL : PLAIN_FORM_FIT_ATTR_MODEL;
}
}

163
designer-base/src/main/java/com/fr/design/report/fit/FormFitConfigPane.java

@ -0,0 +1,163 @@
package com.fr.design.report.fit;
import com.fr.base.svg.SVGLoader;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.imenu.UIPopupMenu;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.report.fit.menupane.FitRadioGroup;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.report.fit.ReportFitAttr;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class FormFitConfigPane extends ReportFitConfigPane {
private static final int ICON_OFFSET_X = 25;
private static final int ICON_OFFSET_Y = 3;
private static final int ICON_SIZE = 16;
private static final Image HOVER_IMAGE = SVGLoader.load("/com/fr/design/icon/icon_ec_default_fit.svg");
private static final int DEFAULT_ITEM = 0;
private static final int CUSTOM_ITEM = 1;
public FormFitConfigPane(FitAttrModel fitAttrModel) {
this(fitAttrModel, false);
}
public FormFitConfigPane(FitAttrModel fitAttrModel, boolean globalConfig) {
super(fitAttrModel, globalConfig);
}
protected JPanel initECConfigPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
if (fitAttrModel.getFitTypeNames().length != 0) {
Component[] ecComponents = new Component[fitAttrModel.getFitTypeNames().length + 1];
initRadioGroup(ecConfigRadioGroup, fitAttrModel.getFitName(), fitAttrModel.getFitTypeNames(), ecComponents);
jPanel.add(createSubAttrPane(ecComponents), BorderLayout.CENTER);
jPanel.add(createTipPane(), BorderLayout.SOUTH);
}
return jPanel;
}
protected void initRadioGroup(FitRadioGroup fitRadioGroup, String name, String[] options, Component[] components) {
components[0] = new UILabel(name);
for (int i = 0; i < options.length; i++) {
if (options[i] != null) {
UIRadioButton fontFitRadio = ComparatorUtils.equals(options[i], Toolkit.i18nText("Fine-Designer_Fit-Default")) ? new UIRadioButtonWithIcon(options[i]) : new UIRadioButton(options[i]);
fitRadioGroup.add(fontFitRadio);
components[i + 1] = fontFitRadio;
} else {
components[i + 1] = null;
}
}
fitRadioGroup.addActionListener(getPreviewActionListener());
}
private class UIRadioButtonWithIcon extends UIRadioButton {
private final JPopupMenu popupMenu;
private NewFitPreviewPane ecFitPreviewPane;
public UIRadioButtonWithIcon(String text) {
super(text);
popupMenu = this.createPopupMenu();
initMouseListener();
}
private JPopupMenu createPopupMenu() {
UIPopupMenu uiPopupMenu = new UIPopupMenu() {
@Override
protected void paintBorder(Graphics g) {
}
};
uiPopupMenu.setLayout(new BorderLayout(0, 0));
uiPopupMenu.setOpaque(false);
uiPopupMenu.add(ecFitPreviewPane = new NewFitPreviewPane(FitType.HORIZONTAL_FIT), BorderLayout.CENTER);
ecFitPreviewPane.setPreferredSize(new Dimension(300, 204));
return uiPopupMenu;
}
private void initMouseListener() {
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
hidePreviewPane();
}
});
int defaultTextWidth = calculateStartX();
this.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
if (new Rectangle(ICON_OFFSET_X + defaultTextWidth, ICON_OFFSET_Y, ICON_SIZE, ICON_SIZE).contains(e.getPoint())) {
showPreviewPane(e);
} else {
hidePreviewPane();
}
}
});
}
public void showPreviewPane(MouseEvent e) {
popupMenu.setVisible(true);
ecFitPreviewPane.refreshPreview(fontRadioGroup.isFontFit());
GUICoreUtils.showPopupMenu(popupMenu, this, e.getX() + 10, e.getY() + 10);
}
public void hidePreviewPane() {
if (popupMenu != null && popupMenu.isVisible()) {
popupMenu.setVisible(false);
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(HOVER_IMAGE, calculateStartX() + ICON_OFFSET_X, ICON_OFFSET_Y, null);
}
private int calculateStartX() {
FontMetrics metrics = this.getFontMetrics(this.getFont());
return metrics.stringWidth(this.getText());
}
}
private JPanel createTipPane() {
JPanel jPanel = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true);
UILabel label1 = new UILabel(Toolkit.i18nText("Fine-Design_Form_PC_FIT_Config_Tip1"));
jPanel.add(label1);
label1.setForeground(Color.lightGray);
UILabel label2 = new UILabel(Toolkit.i18nText("Fine-Design_Form_PC_FIT_Config_Tip2"));
jPanel.add(label2);
label2.setForeground(Color.lightGray);
return jPanel;
}
protected void refreshPreviewJPanel() {
previewJPanel.refreshPreview(fontRadioGroup.isFontFit());
}
protected void populateECConfigRadioGroup(int fitStateInPC) {
ecConfigRadioGroup.selectIndexButton(fitStateInPC == 0 ? DEFAULT_ITEM : CUSTOM_ITEM);
}
protected void updateECConfigRadioGroup(ReportFitAttr reportFitAttr) {
reportFitAttr.setFitStateInPC(ecConfigRadioGroup.getSelectRadioIndex());
}
}

9
designer-base/src/main/java/com/fr/design/report/fit/FrmFitAttrModel.java

@ -17,7 +17,7 @@ public class FrmFitAttrModel implements FitAttrModel {
@Override
public String getFitName() {
return Toolkit.i18nText("Fine-Designer_Fit-Element");
return Toolkit.i18nText("Fine-Design_Form_PC_FIT_Config_EC_Label");
}
public FitType[] getFitTypes() {
@ -29,6 +29,13 @@ public class FrmFitAttrModel implements FitAttrModel {
};
}
@Override
public String[] getFitTypeNames() {
return new String[]{
Toolkit.i18nText("Fine-Designer_Fit-Default"), Toolkit.i18nText("Fine-Design_Basic_Custom")
};
}
@Override
public ReportFitAttr getGlobalReportFitAttr() {
return ReportFitConfig.getInstance().getFrmFitAttr();

79
designer-base/src/main/java/com/fr/design/report/fit/NewFitPreviewPane.java

@ -0,0 +1,79 @@
package com.fr.design.report.fit;
import com.fr.base.GraphHelper;
import com.fr.general.FRFont;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
public class NewFitPreviewPane extends JPanel {
private boolean fitFont = false;
private FitType fitType = FitType.DOUBLE_FIT;
private static final Color DEFAULT_PAINT_COLOR = Color.decode("#419BF9");
private static final int FIT_FONT_SIZE = 15;
private static final int NO_FIT_FONT_SIZE = 10;
private static final Dimension NO_FIT_CONTAINER_DIMENSION = new Dimension(230, 80);
public NewFitPreviewPane(){
}
public NewFitPreviewPane(FitType fitType){
this.fitType = fitType;
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.GRAY);
GraphHelper.drawRect(g, 1, 1, this.getWidth() - 2, this.getHeight() - 2);
g.setColor(DEFAULT_PAINT_COLOR);
FRFont textFont = FRFont.getInstance(FRFont.DEFAULT_FONTNAME, Font.PLAIN, fitFont ? FIT_FONT_SIZE : NO_FIT_FONT_SIZE);
g.setFont(textFont);
Dimension dimension = calculateCellDimension();
GraphHelper.drawLine(g, 1, dimension.height, dimension.width * 2 - 1, dimension.height);
GraphHelper.drawLine(g, dimension.width, 1, dimension.width, dimension.height * 2 - 1);
GraphHelper.drawRect(g, 1, 1, dimension.width * 2 - 2, dimension.height * 2 - 2);
double startX = calculateTextDrawStartX(dimension.width, this.getFontMetrics(textFont), "text1");
double startY = calculateTextDrawStartY(dimension.height);
GraphHelper.drawString(g, "text1", startX, startY);
GraphHelper.drawString(g, "text2", dimension.width + startX, startY);
GraphHelper.drawString(g, "text3", startX, dimension.height + startY);
GraphHelper.drawString(g, "text4", dimension.width + startX, dimension.height + startY);
}
private Dimension calculateCellDimension() {
if (fitType == FitType.DOUBLE_FIT) {
return new Dimension(this.getWidth() / 2, this.getHeight() / 2);
} else if (fitType == FitType.NOT_FIT) {
return new Dimension(NO_FIT_CONTAINER_DIMENSION.width / 2, NO_FIT_CONTAINER_DIMENSION.height / 2);
} else {
return new Dimension(this.getWidth() / 2, NO_FIT_CONTAINER_DIMENSION.height / 2);
}
}
private double calculateTextDrawStartX(int containerWidth, FontMetrics fontMetrics, String text) {
return (containerWidth - fontMetrics.stringWidth(text)) / 2.0D;
}
private double calculateTextDrawStartY(int containerHeight) {
return containerHeight / 2.0D;
}
public void refreshPreview(boolean fitFont, FitType fitType) {
this.fitFont = fitFont;
this.fitType = fitType;
repaint();
}
public void refreshPreview(boolean fitFont) {
this.fitFont = fitFont;
repaint();
}
}

172
designer-base/src/main/java/com/fr/design/report/fit/ReportFitConfigPane.java

@ -0,0 +1,172 @@
package com.fr.design.report.fit;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.DesignSizeI18nManager;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.report.fit.menupane.FitRadioGroup;
import com.fr.design.report.fit.menupane.FontRadioGroup;
import com.fr.general.ComparatorUtils;
import com.fr.report.fit.ReportFitAttr;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import static com.fr.design.i18n.Toolkit.i18nText;
public class ReportFitConfigPane extends JPanel {
public FontRadioGroup fontRadioGroup;
public FitRadioGroup ecConfigRadioGroup;
protected NewFitPreviewPane previewJPanel;
protected FitAttrModel fitAttrModel;
protected boolean globalConfig;
public ReportFitConfigPane(FitAttrModel fitAttrModel, boolean globalConfig) {
this.fitAttrModel = fitAttrModel;
this.globalConfig = globalConfig;
initComponent();
}
private void initComponent() {
JPanel contentJPanel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(false, FlowLayout.LEFT, 0, 0);
this.add(contentJPanel);
fontRadioGroup = new FontRadioGroup();
ecConfigRadioGroup = new FitRadioGroup();
contentJPanel.add(initAttrJPanel());
contentJPanel.add(initPreviewJPanel());
}
private JPanel initAttrJPanel() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
Component[] fontComponents = new Component[3];
initRadioGroup(fontRadioGroup, i18nText("Fine-Designer_Fit-Font"), new String[]{i18nText("Fine-Designer_Fit"), i18nText("Fine-Designer_Fit-No")}, fontComponents);
jPanel.add(createSubAttrPane(fontComponents), BorderLayout.NORTH);
jPanel.add(initECConfigPane(), BorderLayout.CENTER);
return jPanel;
}
protected JPanel initECConfigPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
Component[] ecComponents = new Component[fitAttrModel.getFitTypeNames().length + 1];
initRadioGroup(ecConfigRadioGroup, fitAttrModel.getFitName(), fitAttrModel.getFitTypeNames(), ecComponents);
jPanel.add(createSubAttrPane(ecComponents), BorderLayout.CENTER);
return jPanel;
}
protected JPanel createSubAttrPane(Component[] components) {
double[] rowSize = new double[]{20};
double[] columnSize = new double[components.length];
for (int i = 0; i < columnSize.length; i++) {
if (i == 0) {
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.firstColumn").getWidth();
} else {
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.column").getWidth();
}
}
JPanel attrJPanel = TableLayoutHelper.createTableLayoutPane(new Component[][]{components}, rowSize, columnSize);
attrJPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));
return attrJPanel;
}
protected void initRadioGroup(FitRadioGroup fitRadioGroup, String name, String[] options, Component[] components) {
components[0] = new UILabel(name);
for (int i = 0; i < options.length; i++) {
if (options[i] != null) {
UIRadioButton fontFitRadio = new UIRadioButton(options[i]);
fitRadioGroup.add(fontFitRadio);
components[i + 1] = fontFitRadio;
} else {
components[i + 1] = null;
}
}
fitRadioGroup.addActionListener(getPreviewActionListener());
}
protected ActionListener getPreviewActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshPreviewJPanel();
}
};
}
public void refreshPreviewJPanel(FitType fitType) {
previewJPanel.refreshPreview(fontRadioGroup.isFontFit(), fitType);
}
protected void refreshPreviewJPanel() {
previewJPanel.refreshPreview(fontRadioGroup.isFontFit(), FitType.parse(updateBean()));
}
private JPanel initPreviewJPanel() {
JPanel wrapperPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
previewJPanel = new NewFitPreviewPane();
wrapperPane.add(previewJPanel, BorderLayout.CENTER);
int leftIndent = globalConfig ? (int) DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.firstColumn").getWidth() : 0;
wrapperPane.setBorder(BorderFactory.createEmptyBorder(0, leftIndent, 0, 0));
wrapperPane.setPreferredSize(new Dimension(300 + leftIndent, 204));
return wrapperPane;
}
public void populateBean(ReportFitAttr ob) {
fontRadioGroup.selectIndexButton(ob.isFitFont() ? 0 : 1);
populateECConfigRadioGroup(ob.fitStateInPC());
refreshPreviewJPanel();
}
protected void populateECConfigRadioGroup(int fitStateInPC){
ecConfigRadioGroup.selectIndexButton(getOptionIndex(fitStateInPC));
}
protected void updateECConfigRadioGroup(ReportFitAttr reportFitAttr){
reportFitAttr.setFitStateInPC(getStateInPC(ecConfigRadioGroup.getSelectRadioIndex()));
}
public ReportFitAttr updateBean() {
ReportFitAttr reportFitAttr = new ReportFitAttr();
reportFitAttr.setFitFont(fontRadioGroup.isFontFit());
updateECConfigRadioGroup(reportFitAttr);
return reportFitAttr;
}
protected int getStateInPC(int index) {
FitType[] fitTypes = fitAttrModel.getFitTypes();
if (index > fitTypes.length - 1) {
return index;
}
return fitTypes[index].getState();
}
protected int getOptionIndex(int state) {
FitType[] fitTypes = fitAttrModel.getFitTypes();
for (int i = 0; i < fitTypes.length; i++) {
if (ComparatorUtils.equals(state, fitTypes[i].getState())) {
return i;
}
}
return 0;
}
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
fontRadioGroup.setEnabled(enabled);
ecConfigRadioGroup.setEnabled(enabled);
}
}

28
designer-base/src/main/java/com/fr/design/selection/Selectedable.java

@ -1,25 +1,29 @@
package com.fr.design.selection;
import com.fr.base.TRL;
/**
*
* @author zhou
* @since 2012-7-26上午10:20:32
*/
public interface Selectedable<S extends SelectableElement> {
public S getSelection();
S getSelection();
void setSelection(S selectElement);
public void setSelection(S selectElement);
/**
* Adds a <code>ChangeListener</code> to the listener list.
*/
void addSelectionChangeListener(SelectionListener selectionListener);
/**
* Adds a <code>ChangeListener</code> to the listener list.
*/
public void addSelectionChangeListener(SelectionListener selectionListener);
/**
* removes a <code>ChangeListener</code> from the listener list.
*/
void removeSelectionChangeListener(SelectionListener selectionListener);
/**
* removes a <code>ChangeListener</code> from the listener list.
*/
public void removeSelectionChangeListener(SelectionListener selectionListener);
// august:这儿就不要加fireSelectionChangeListener方法了。因为这个方法一般要定义成私有的,不然外部随即的调用!
default void navigate(TRL trl) {
// august:这儿就不要加fireSelectionChangeListener方法了。因为这个方法一般要定义成私有的,不然外部随即的调用!
}
}

33
designer-base/src/main/java/com/fr/design/startup/FineStartupNotificationFactory.java

@ -0,0 +1,33 @@
package com.fr.design.startup;
import org.jetbrains.annotations.NotNull;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2022/1/11
*/
public class FineStartupNotificationFactory {
private static final FineStartupNotificationProvider DEFAULT = Install4jStartupNotificationProvider.getInstance();
private static FineStartupNotificationProvider provider;
public FineStartupNotificationFactory() {
}
public static FineStartupNotificationProvider getNotification() {
return provider;
}
public static void setLogger(@NotNull FineStartupNotificationProvider provider) {
FineStartupNotificationFactory.provider = provider;
}
public static void reset() {
provider = DEFAULT;
}
static {
provider = DEFAULT;
}
}

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

Loading…
Cancel
Save