Browse Source

REPORT-134498 修复启动页的环境卡片边框问题

fbp/release
vito 2 months ago
parent
commit
f9b348b851
  1. 47
      designer-base/src/main/java/com/fine/theme/utils/FineUIUtils.java
  2. 117
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  3. 20
      designer-base/src/main/java/com/fr/startup/ui/StartupPageWorkspacePanel.java
  4. 8
      designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonStoryBoard.java
  5. 3
      designer-realize/src/main/java/com/fr/start/CarinaDesigner.java

47
designer-base/src/main/java/com/fine/theme/utils/FineUIUtils.java

@ -44,6 +44,9 @@ import static com.formdev.flatlaf.util.UIScale.scale;
*/
public class FineUIUtils {
public static final String LEFT = "LEFT";
public static final String RIGHT = "RIGHT";
public static final int RETINA_SCALE_FACTOR = 2;
/**
@ -212,17 +215,48 @@ public class FineUIUtils {
*/
public static void paintPartRoundButtonBorder(Component c, Graphics2D g2, int x, int y, int width, int height,
float borderWidth, float arc) {
if (isLeftRoundButton(c)) {
paintPartRoundButtonBorder(g2, x, y, width, height, borderWidth, arc, LEFT, false);
} else {
paintPartRoundButtonBorder(g2, x, y, width, height, borderWidth, arc, RIGHT, false);
}
}
/**
* 绘制部分圆角矩形边框
*
* @param g2 Graphics2D
* @param x x坐标
* @param y y坐标
* @param width 宽度
* @param height 高度
* @param borderWidth 边框宽度
* @param arc 圆角
* @param roundPart 圆角的方位当前只能设置一侧
* @param closedPath 是否封闭非圆角那一侧是否有边框是为有边框
*/
public static void paintPartRoundButtonBorder(Graphics2D g2, int x, int y, int width, int height,
float borderWidth, float arc, String roundPart, boolean closedPath) {
FlatUIUtils.setRenderingHints(g2);
arc = scale(arc);
float t = scale(borderWidth);
float t2x = t * 2;
Path2D path2D = new Path2D.Float(Path2D.WIND_EVEN_ODD);
if (isLeftRoundButton(c)) {
path2D.append(createLeftRoundRectangle(x, y, width, height, arc), false);
path2D.append(createLeftRoundRectangle(x + t, y + t, width - t, height - t2x, arc - t), false);
} else {
path2D.append(createRightRoundRectangle(x, y, width, height, arc), false);
path2D.append(createRightRoundRectangle(x, y + t, width - t, height - t2x, arc - t), false);
switch (roundPart) {
case LEFT: {
path2D.append(createLeftRoundRectangle(x, y, width, height, arc), false);
path2D.append(createLeftRoundRectangle(x + t, y + t,
width - (closedPath ? t2x : t), height - t2x, arc - t), false);
break;
}
case RIGHT:
default: {
path2D.append(createRightRoundRectangle(x, y, width, height, arc), false);
path2D.append(createRightRoundRectangle(x + (closedPath ? t : 0), y + t,
width - (closedPath ? t2x : t), height - t2x, arc - t), false);
break;
}
}
g2.fill(path2D);
}
@ -452,6 +486,7 @@ public class FineUIUtils {
/**
* 创建一个支持自动换行的提示文本
*
* @param text 显示的文本内容
* @return 自动换行提示文本
*/

117
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -104,12 +104,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
* The manager of Designer GUI.
* 下面的作者日期都是随手写的具体作者已经无法考究
*
* @author anonymous
* @version 11.0
* @author anonymous
* @version 11.0
* created by anonymous on 2002/11/08
*/
public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReadable {
private static final int MAX_SHOW_NUM = 10;
private static final String VERSION_80 = "80";
private static final String VERSION_90 = "90";
@ -122,26 +122,26 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
* 指定默认工作空间
*/
public static final String DEFAULT_WORKSPACE_PATH = "fr.designer.workspace.default";
public static final String LAST_EAST_REGION_LAYOUT = "LastEastRegionLayout";
public static final String LAST_WEST_REGION_LAYOUT = "LastWestRegionLayout";
private static DesignerEnvManager designerEnvManager; // gui.
private String activationKey = null;
private String logLocation = null;
private Rectangle windowBounds = null; // window bounds.
private String DialogCurrentDirectory = null;
private String CurrentDirectoryPrefix = null;
private Map<String, List<String>> recentOpenedFileListMap = new HashMap<>();
private List<String> tempRecentOpenedFilePathList = new ArrayList<String>();
private XmlElement<Map<String, List<String>>> recentOpenedMapping = SimpleXmlElement.of(recentOpenedFileListMap);
private boolean showPaintToolBar = true;
private int maxNumberOrPreviewRow = 200;
private XmlElement<EnvConfiguration> envConfig = SimpleXmlElement.of(new EnvConfiguration());
private boolean showProjectPane = true;
private boolean showDataPane = true;
//p:这是当前选择的数据库连接的名字,这个在新建数据源的时候用到.
@ -195,12 +195,12 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
private boolean embedServerLazyStartup = false;
//最近使用的颜色
private ColorSelectConfigManager configManager = new ColorSelectConfigManager();
/**
* 环境检测配置
*/
private EnvDetectorConfig envDetectorConfig = EnvDetectorConfig.getInstance();
/**
* alphafine
*/
@ -214,11 +214,11 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
private DesignerPushUpdateConfigManager designerPushUpdateConfigManager = DesignerPushUpdateConfigManager.getInstance();
private VcsConfigManager vcsConfigManager = VcsConfigManager.getInstance();
private DesignerStartupConfig designerStartupConfig = DesignerStartupConfig.getInstance();
private SwitchForSwingChecker switchForSwingChecker = SwitchForSwingChecker.getInstance();
public static final String CAS_CERTIFICATE_PATH = "certificatePath";
public static final String CAS_CERTIFICATE_PASSWORD = "certificatePass";
@ -267,7 +267,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
designerEnvManager = new DesignerEnvManager();
//REPORT-15332有一个国际化调用比较早,需要在这边就设置好locale,由于后台GeneralContext默认是China
GeneralContext.setLocale(designerEnvManager.getLanguage());
if (!asyncInitEnvManager()) {
// 如果异步读取失败, 则恢复原来的逻辑
compatibleInitEnvManager();
@ -287,9 +287,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
return designerEnvManager;
}
private static void compatibleInitEnvManager() {
try {
XMLTools.readFileXML(designerEnvManager, designerEnvManager.getDesignerEnvFile());
} catch (FileNotFoundException e) {
@ -299,7 +299,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
* 异步初始化环境管理, 提供配置, 帮助处理预期外的问题
* 1-当优化开启时才走异步逻辑
@ -308,7 +308,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
* @return /
*/
private static boolean asyncInitEnvManager() {
AtomicBoolean noEx = new AtomicBoolean(false);
OptimizeUtil.initiateOpen(DesignerEnvManager.class.getSimpleName().toLowerCase(), () -> {
try {
@ -326,7 +326,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
}
public static void checkNameEnvMap() {
if (designerEnvManager == null || designerEnvManager.getNameEnvMap().size() > 0) {
return;
}
@ -1060,11 +1060,11 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
public void setLanguage(Locale locale) {
this.language = locale;
}
public boolean isStartupPageEnabled() {
return this.designerStartupConfig.isEnabled();
}
public void setStartupPageEnabled(boolean enabled) {
this.designerStartupConfig.setEnabled(enabled);
}
@ -1191,9 +1191,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
public void setCurrentDirectoryPrefix(String prefix) {
this.CurrentDirectoryPrefix = prefix;
}
public List<String> getRecentOpenedFilePathList4Env(String envName) {
if (StringUtils.isEmpty(envName)) {
return tempRecentOpenedFilePathList;
} else {
@ -1201,7 +1201,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
recentOpenedMapping.getValue().put(envName, tempRecentOpenedFilePathList);
}
}
return recentOpenedMapping.getValue().get(envName);
}
@ -1209,7 +1209,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
* 返回最近打开的文件路径列表
*/
public List<String> getRecentOpenedFilePathList() {
return this.getRecentOpenedFilePathList4Env(getCurEnvName());
}
@ -1713,7 +1713,16 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
}
}
}
Carina.config(LanguageConfigProvider.class).setLocale(CommonUtils.localeToString(designerEnvManager.getLanguage()));
setLocale();
}
private static void setLocale() {
try {
Carina.config(LanguageConfigProvider.class)
.setLocale(CommonUtils.localeToString(designerEnvManager.getLanguage()));
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
@ -1853,10 +1862,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
public void setLayoutTemplateStyle(int layoutTemplateStyle) {
this.layoutTemplateStyle = layoutTemplateStyle;
}
@Override
public void initElements(File xmlFile) throws XmlException {
try {
backupOldXmlFile();
XmlInitialFactory xmlInitialFactory = XmlInitialFactory.create(xmlFile);
@ -1876,7 +1885,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
});
})
.init("EnvConfigMap", (e) -> {
final EnvConfiguration previousConfig = this.envConfig.getValue();
this.envConfig = AsyncXmlElement.of(DesignerStartupPool.common(), () -> {
DesignerEnvManager.this.readEnvConfigMap(e, previousConfig);
@ -1928,13 +1937,13 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
throw new XmlException(e);
}
}
/**
* 备份老的 xml 文件, 防止第一次修改存在问题
* 但是只备份一次其他都走老逻辑
*/
private void backupOldXmlFile() {
try {
File oldFile = getEnvFile();
String newFilePath = ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "Env_backup.xml";
@ -1948,7 +1957,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
} catch (Exception ignored) {
}
}
/**
* Read XML.<br>
* The method will be invoked when read data from XML file.<br>
@ -2040,16 +2049,16 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
}
private void readAlphaFineAttr(XMLableReader reader) {
AlphaFineConfigManager config = AlphaFineConfigManager.getInstance();
reader.readXMLObject(config);
this.alphaFineConfigManager = SimpleXmlElement.of(config);
}
private void readEnvDetectorConfig(XMLableReader reader) {
reader.readXMLObject(this.envDetectorConfig);
}
private void readStartupConfig(XMLableReader reader) {
reader.readXMLObject(this.designerStartupConfig);
}
@ -2165,9 +2174,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
this.setPaginationLineColor(new Color(Integer.parseInt(tmpVal)));
}
}
private void readEnvConfigMap(XMLableReader reader, EnvConfiguration envConfigs) {
String currentEnv = reader.getAttrAsString("currentEnv", StringUtils.EMPTY);
envConfigs.setCurEnvName(currentEnv);
reader.readXMLObject(new XMLReadable() {
@ -2232,15 +2241,15 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
}
});
}
private void readRecentOpenFileList(XMLableReader reader) {
readRecentOpenFileList0(reader);
checkRecentOpenedFileNum();
}
private void readRecentOpenFileList0(XMLableReader reader) {
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) {
@ -2358,13 +2367,13 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
writer.end();
}
}
private void writeEnvDetectorConfig(XMLPrintWriter writer) {
if (this.envDetectorConfig != null) {
this.envDetectorConfig.writeXML(writer);
}
}
private void writeStartupConfig(XMLPrintWriter writer) {
if (this.designerStartupConfig != null) {
this.designerStartupConfig.writeXML(writer);
@ -2630,7 +2639,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
}
private void readFvsDesignerConfig(XMLableReader reader) {
SimpleDesignerConfig config = fvsDesignerConfig.getValue();
reader.readXMLObject(config);
fvsDesignerConfig = SimpleXmlElement.of(config);
@ -2672,39 +2681,39 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter, AsyncXmlReada
public SnapChatConfig getSnapChatConfig() {
return snapChatConfig;
}
private EnvConfiguration getEnvConfig() {
return envConfig.getValue();
}
private Map<String, DesignerWorkspaceInfo> getNameEnvMap() {
return getEnvConfig().getNameEnvMap();
}
private static class EnvConfiguration {
// name和Env的键值对
private Map<String, DesignerWorkspaceInfo> nameEnvMap = new ListMap<>();
// marks: 当前报表服务器名字
private String curEnvName = null;
public Map<String, DesignerWorkspaceInfo> getNameEnvMap() {
return nameEnvMap;
}
public void setNameEnvMap(Map<String, DesignerWorkspaceInfo> nameEnvMap) {
this.nameEnvMap = nameEnvMap;
}
public String getCurEnvName() {
return curEnvName;
}
public void setCurEnvName(String curEnvName) {
this.curEnvName = curEnvName;
}
}
}

20
designer-base/src/main/java/com/fr/startup/ui/StartupPageWorkspacePanel.java

@ -23,7 +23,6 @@ import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JViewport;
import javax.swing.ScrollPaneConstants;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
@ -311,11 +310,10 @@ public class StartupPageWorkspacePanel extends JPanel {
if (borderColor != null) {
g2d.setColor(borderColor);
g2d.setStroke(new BasicStroke(BORDER_THIN));
FlatUIUtils.setRenderingHints(g2d);
Path2D path2D = FineUIUtils.createLeftRoundRectangle(0, 0,
getWidth() - BORDER_THIN, getHeight() - BORDER_THIN, ARC_DIAMETER);
g2d.draw(path2D);
FineUIUtils.paintPartRoundButtonBorder(g2d, 0, 0,
this.getWidth(), this.getHeight(),
BORDER_THIN, ARC_DIAMETER,
FineUIUtils.LEFT, true);
}
}
};
@ -437,11 +435,11 @@ public class StartupPageWorkspacePanel extends JPanel {
Color borderColor = borderColorRef.get();
if (borderColor != null) {
g2d.setColor(borderColor);
g2d.setStroke(new BasicStroke(BORDER_THIN));
FlatUIUtils.setRenderingHints(g2d);
Path2D path2D = FineUIUtils.createRightRoundRectangle(0, 0,
getWidth() - BORDER_THIN, getHeight() - BORDER_THIN, ARC_DIAMETER);
g2d.draw(path2D);
FineUIUtils.paintPartRoundButtonBorder(g2d, 0, 0,
this.getWidth(), this.getHeight(),
BORDER_THIN, ARC_DIAMETER,
FineUIUtils.RIGHT, true
);
}
}

8
designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonStoryBoard.java

@ -3,9 +3,11 @@ package com.fr.design.gui.storybook.components;
import com.fine.theme.icon.LazyIcon;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UICombinationButton;
import com.fr.design.gui.ibutton.UISaveForbiddenButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.storybook.Story;
import com.fr.design.gui.storybook.StoryBoard;
import com.fr.design.i18n.Toolkit;
import com.fr.design.style.color.UIToolbarColorButton;
import javax.swing.JButton;
@ -177,7 +179,9 @@ public class ButtonStoryBoard extends StoryBoard {
.with(it -> setStyle(it, STYLE_PRIMARY)),
cell(new UICombinationButton("按钮2", new LazyIcon("triangle_down"))),
cell(new JButton("按钮", new LazyIcon("add"))),
cell(new JButton(new LazyIcon("multi")))
cell(new UICombinationButton(
new UISaveForbiddenButton(Toolkit.i18nText("Fine-Design_Basic_Preview"), new LazyIcon("run").white()),
new UISaveForbiddenButton(new LazyIcon("triangle_down").white()))).with(UICombinationButton::setPrimary)
),
row(20,
cell(new UIToolbarColorButton(new LazyIcon("foreground"))),
@ -189,7 +193,7 @@ public class ButtonStoryBoard extends StoryBoard {
);
}
public JComponent toolbar(){
public JComponent toolbar() {
JToolBar bar = new JToolBar();
UIToolbarColorButton foreground = new UIToolbarColorButton(new LazyIcon("foreground"));
bar.add(foreground);

3
designer-realize/src/main/java/com/fr/start/CarinaDesigner.java

@ -41,6 +41,7 @@ public class CarinaDesigner extends MainDesigner{
* main
*/
public static void main(String[] args) {
installUIDevModeTools();
DesignerStartupContext.getRecorder().start();
PartitionManager manager = new PartitionManagerImpl();
StateHubContext.setReady(false);
@ -66,8 +67,6 @@ public class CarinaDesigner extends MainDesigner{
DesignerStartupContext.getRecorder().stop();
SwitchForSwingChecker.initThreadMonitoring();
DesignerLatencyMetric.getInstance().start();
installUIDevModeTools();
}
/**

Loading…
Cancel
Save