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.
80 lines
3.0 KiB
80 lines
3.0 KiB
package com.fr.design.utils; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.stable.StringUtils; |
|
|
|
import javax.swing.JComponent; |
|
import java.awt.Color; |
|
import java.awt.Font; |
|
|
|
/** |
|
* created by Harrison on 2022/05/24 |
|
**/ |
|
public class LinkStrUtils { |
|
|
|
public static final UILabel LABEL = new UILabel(); |
|
|
|
public static UILabel generateLabel(String html, JComponent templateLabel) { |
|
|
|
String style = generateStyle(templateLabel.getBackground(), templateLabel.getFont(), templateLabel.getForeground()); |
|
String fullHtml = generateHtmlTag(style, html); |
|
return new UILabel(fullHtml); |
|
} |
|
|
|
public static String generateHtmlTag(String html) { |
|
|
|
String defaultStyle = generateDefaultStyle(); |
|
return generateHtmlTag(defaultStyle, html); |
|
} |
|
|
|
public static String generateHtmlTag(String style, String html) { |
|
|
|
if (StringUtils.isEmpty(style)) { |
|
throw new NullPointerException("style"); |
|
} |
|
if (StringUtils.isEmpty(html)) { |
|
throw new NullPointerException("html"); |
|
} |
|
return "<html><body style=\"" + style + "\">" + html + "</body></html>"; |
|
} |
|
|
|
public static String generateLinkTag(String link, String text) { |
|
|
|
return "<a href=\"" + link + "\">" + text + "</a>"; |
|
} |
|
|
|
public static String generateLinkTagWithoutUnderLine(String link, String text) { |
|
return "<a style=\"text-decoration:none;\" href=\"" + link + "\">" + text + "</a>"; |
|
} |
|
|
|
public static String generateStyle(Color backgroundColor, Font font, Color fontColor) { |
|
|
|
// 构建相同风格样式 |
|
StringBuilder style = new StringBuilder("font-family:" + font.getFamily() + ";"); |
|
|
|
style.append("font-weight:").append(font.isBold() ? "bold" : "normal").append(";"); |
|
style.append("font-size:").append(font.getSize()).append("pt;"); |
|
style.append("color:rgb(").append(fontColor.getRed()).append(",").append(fontColor.getGreen()).append(",").append(fontColor.getBlue()).append(");"); |
|
style.append("background-color: rgb(").append(backgroundColor.getRed()).append(",").append(backgroundColor.getGreen()).append(",").append(backgroundColor.getBlue()).append(");"); |
|
|
|
return style.toString(); |
|
} |
|
|
|
public static String generateStyle(Font font, Color fontColor) { |
|
|
|
// 构建相同风格样式 |
|
StringBuilder style = new StringBuilder("font-family:" + font.getFamily() + ";"); |
|
|
|
style.append("font-weight:").append(font.isBold() ? "bold" : "normal").append(";"); |
|
style.append("font-size:").append(font.getSize()).append("pt;"); |
|
style.append("color:rgb(").append(fontColor.getRed()).append(",").append(fontColor.getGreen()).append(",").append(fontColor.getBlue()).append(");"); |
|
return style.toString(); |
|
} |
|
|
|
|
|
|
|
public static String generateDefaultStyle() { |
|
|
|
return generateStyle(LABEL.getBackground(), LABEL.getFont(), LABEL.getForeground()); |
|
} |
|
}
|
|
|