forked from fanruan/design
Browse Source
Merge in DESIGN/design from ~HADES/design:release/10.0 to release/10.0 * commit '358d972dee8097028365832a103cd98d85d94abd': REPORT-40646 去掉无用的代码 REPORT-40646 远程设计对接平台密码策略feature/big-screen
ju.ju
4 years ago
5 changed files with 250 additions and 17 deletions
@ -0,0 +1,55 @@ |
|||||||
|
package com.fr.design.dialog.link; |
||||||
|
|
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Desktop; |
||||||
|
import java.awt.Font; |
||||||
|
import java.net.URI; |
||||||
|
import javax.swing.JEditorPane; |
||||||
|
import javax.swing.event.HyperlinkEvent; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用来构建JOptionPane带超链的消息提示 |
||||||
|
* |
||||||
|
* @author hades |
||||||
|
* @version 10.0 |
||||||
|
* Created by hades on 2020/10/23 |
||||||
|
*/ |
||||||
|
public class MessageWithLink extends JEditorPane { |
||||||
|
|
||||||
|
public MessageWithLink(String message, String linkName, String link) { |
||||||
|
super("text/html", "<html><body style=\"" + getStyle() + "\">" + message + "<a href=\"" + link + "\">" + linkName + "</a>" + "</body></html>"); |
||||||
|
addHyperlinkListener(e -> { |
||||||
|
if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { |
||||||
|
try { |
||||||
|
Desktop.getDesktop().browse(URI.create(link)); |
||||||
|
} catch (Exception exception) { |
||||||
|
FineLoggerFactory.getLogger().error(exception.getMessage(), exception); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
setEditable(false); |
||||||
|
setBorder(null); |
||||||
|
} |
||||||
|
|
||||||
|
public MessageWithLink(String linkName, String link ) { |
||||||
|
this(StringUtils.EMPTY, linkName, link); |
||||||
|
} |
||||||
|
|
||||||
|
private static StringBuilder getStyle() { |
||||||
|
// 构建和相同风格样式
|
||||||
|
UILabel label = new UILabel(); |
||||||
|
Font font = label.getFont(); |
||||||
|
Color color = label.getBackground(); |
||||||
|
|
||||||
|
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("background-color: rgb(").append(color.getRed()).append(",").append(color.getGreen()).append(",").append(color.getBlue()).append(");"); |
||||||
|
|
||||||
|
return style; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue