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 private void txtMessageKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMessageKeyTyped
handleKeyTyped(evt); handleKeyTyped(evt);
}//GEN-LAST:event_txtMessageKeyTyped }//GEN-LAST:event_txtMessageKeyTyped

View file

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