You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.5 KiB
86 lines
2.5 KiB
package com.fr.startup.ui; |
|
|
|
import com.fr.base.svg.SVGIcon; |
|
import com.fr.design.env.DesignerWorkspaceType; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.stable.StringUtils; |
|
|
|
import javax.swing.Icon; |
|
import javax.swing.JComponent; |
|
import javax.swing.JRootPane; |
|
import java.net.URL; |
|
|
|
/** |
|
* created by Harrison on 2022/07/11 |
|
**/ |
|
public class StartupPageUtil { |
|
|
|
public static final int INVALID_PORT = -1; |
|
public static final String COLON = ":"; |
|
|
|
/** |
|
* 获取最近区域的 ICON |
|
* |
|
* @param workspaceBean 工作目录 |
|
* @return 图标 |
|
*/ |
|
public static Icon getIcon4RecentAreaByWorkspace(StartupWorkspaceBean workspaceBean) { |
|
|
|
if (workspaceBean.getType() == DesignerWorkspaceType.Local) { |
|
return SVGIcon.readSVGIcon("/com/fr/design/startup/local_server_background_36.svg", 36, 36); |
|
} |
|
return SVGIcon.readSVGIcon("/com/fr/design/startup/remote_server_background_36.svg", 36, 36); |
|
} |
|
|
|
/** |
|
* 获取工作目录描述区域的 ICON |
|
* |
|
* @param workspaceBean 工作目录 |
|
* @return 图标 |
|
*/ |
|
public static Icon getIcon4DescAreaByWorkspace(StartupWorkspaceBean workspaceBean) { |
|
|
|
if (workspaceBean.getType() == DesignerWorkspaceType.Local) { |
|
return SVGIcon.readSVGIcon("/com/fr/design/startup/local_server_background_28.svg", 28, 28); |
|
} |
|
return SVGIcon.readSVGIcon("/com/fr/design/startup/remote_server_background_28.svg", 28, 28); |
|
} |
|
|
|
/** |
|
* 返回 ip : port |
|
* |
|
* @param urlStr 完整的 url 值,例如 https://localhost:3090/xxx |
|
* @return localhost:3090 |
|
*/ |
|
public static String getRemoteAddress(String urlStr) { |
|
|
|
try { |
|
if (StringUtils.isEmpty(urlStr)) { |
|
return StringUtils.EMPTY; |
|
} |
|
URL url = new URL(urlStr); |
|
String host = url.getHost(); |
|
int port = url.getPort(); |
|
if (port == INVALID_PORT) { |
|
return host; |
|
} |
|
return host + COLON + port; |
|
} catch (Exception e) { |
|
FineLoggerFactory.getLogger().debug(e.getMessage(), e); |
|
return urlStr; |
|
} |
|
} |
|
|
|
/** |
|
* 透明的背景,需要从根节点重绘 |
|
* |
|
* @param component 组件 |
|
*/ |
|
public static void repaintAll(JComponent component) { |
|
|
|
JRootPane rootPane = component.getRootPane(); |
|
if (rootPane != null) { |
|
rootPane.repaint(); |
|
} |
|
} |
|
}
|
|
|