Enable hyperlinks handling only in the game log window.

This commit is contained in:
rkfg 2016-03-07 03:33:04 +03:00
parent 23e93f008a
commit f95921cc73
3 changed files with 27 additions and 10 deletions

View file

@ -352,6 +352,10 @@ public class ChatPanelBasic extends javax.swing.JPanel {
}
}
public void enableHyperlinks() {
txtConversation.enableHyperlinks();
}
private void txtMessageKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMessageKeyTyped
handleKeyTyped(evt);
}//GEN-LAST:event_txtMessageKeyTyped

View file

@ -39,10 +39,14 @@ public class ColorPane extends JEditorPane {
HTMLDocument doc = new HTMLDocument();
private int tooltipDelay;
private int tooltipCounter;
private boolean hyperlinkEnabled = false;
public ColorPane() {
this.setEditorKit(kit);
this.setDocument(doc);
}
private void addHyperlinkHandlers() {
addHyperlinkListener(new HyperlinkListener() {
@Override
@ -62,7 +66,7 @@ public class ColorPane extends JEditorPane {
if (e.getEventType() == EventType.EXITED) {
setPopupVisibility(container, false);
}
if (e.getEventType() == EventType.ENTERED) {
if (e.getEventType() == EventType.ENTERED && card != null) {
CardInfoPane cardInfoPane = (CardInfoPane) MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
cardInfoPane.setCard(new CardView(card.getMockCard()), container);
setPopupVisibility(container, true);
@ -90,20 +94,21 @@ public class ColorPane extends JEditorPane {
});
}
private void setPopupVisibility(final Component container, final boolean show)
throws InterruptedException {
private void setPopupVisibility(final Component container, final boolean show) throws InterruptedException {
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Point location = new Point(getLocationOnScreen().x - container.getWidth(), MouseInfo.getPointerInfo().getLocation().y);
Component parentComponent = MageFrame.getInstance();
location = GuiDisplayUtil.keepComponentInsideParent(location, parentComponent.getLocationOnScreen(), container, parentComponent);
container.setLocation(location);
tooltipCounter += show ? 1 : -1;
if (tooltipCounter < 0) {
tooltipCounter = 0;
}
if (tooltipCounter > 0) {
Point location = new Point(getLocationOnScreen().x - container.getWidth(), MouseInfo.getPointerInfo().getLocation().y);
Component parentComponent = MageFrame.getInstance();
location = GuiDisplayUtil.keepComponentInsideParent(location, parentComponent.getLocationOnScreen(), container, parentComponent);
container.setLocation(location);
}
container.setVisible(tooltipCounter > 0);
c.repaint();
}
@ -131,7 +136,9 @@ public class ColorPane extends JEditorPane {
public void append(String text) {
try {
text = text.replaceAll("(<font color=[^>]*>([^<]*)) (\\[[0-9a-fA-F]*\\])</font>", "<a href=\"#$2\">$1</a> $3");
if (hyperlinkEnabled) {
text = text.replaceAll("(<font color=[^>]*>([^<]*)) (\\[[0-9a-fA-F]*\\])</font>", "<a href=\"#$2\">$1</a> $3");
}
setEditable(true);
kit.insertHTML(doc, doc.getLength(), text, 0, 0, null);
setEditable(false);
@ -163,4 +170,9 @@ public class ColorPane extends JEditorPane {
super.paintChildren(g);
}
public void enableHyperlinks(){
hyperlinkEnabled = true;
addHyperlinkHandlers();
}
}

View file

@ -1296,6 +1296,7 @@ public final class GamePanel extends javax.swing.JPanel {
gameChatPanel.setConnectedChat(userChatPanel);
gameChatPanel.disableInput();
gameChatPanel.setMinimumSize(new java.awt.Dimension(100, 48));
gameChatPanel.enableHyperlinks();
jSplitPane2 = new javax.swing.JSplitPane();
handContainer = new HandPanel();
handCards = new HashMap<>();