use of mage.view.PlaneView in project mage by magefree.
the class ColorPane method addHyperlinkHandlers.
private void addHyperlinkHandlers() {
addHyperlinkListener(e -> ThreadUtils.threadPool2.submit(() -> {
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300) == 0) {
// if disabled
return;
}
// finds extra data in html element like object_id, alternative_name, etc
Map<String, String> extraData = new HashMap<>();
if (e.getSourceElement() instanceof HTMLDocument.RunElement) {
HTMLDocument.RunElement el = (HTMLDocument.RunElement) e.getSourceElement();
Enumeration attNames = el.getAttributeNames();
while (attNames.hasMoreElements()) {
Object attName = attNames.nextElement();
Object attValue = el.getAttribute(attName);
// custom attributes in SimpleAttributeSet element
if (attValue instanceof SimpleAttributeSet) {
SimpleAttributeSet attReal = (SimpleAttributeSet) attValue;
Enumeration attRealNames = attReal.getAttributeNames();
while (attRealNames.hasMoreElements()) {
Object attRealName = attRealNames.nextElement();
Object attRealValue = attReal.getAttribute(attRealName);
String name = attRealName.toString();
String value = attRealValue.toString();
extraData.put(name, value);
}
}
}
}
String cardName = e.getDescription().substring(1);
String alternativeName = CardUtil.urlDecode(extraData.getOrDefault("alternative_name", ""));
if (!alternativeName.isEmpty()) {
cardName = alternativeName;
}
if (e.getEventType() == EventType.ENTERED) {
CardView cardView = null;
// card
CardInfo card = CardRepository.instance.findCards(cardName).stream().findFirst().orElse(null);
if (card != null) {
cardView = new CardView(card.getMockCard());
}
// plane
if (cardView == null) {
Plane plane = Plane.createPlaneByFullName(cardName);
if (plane != null) {
cardView = new CardView(new PlaneView(plane));
}
}
if (cardView != null) {
cardInfo.init(cardView, this.bigCard, this.gameId);
cardInfo.setTooltipDelay(CHAT_TOOLTIP_DELAY_MS);
cardInfo.onMouseEntered(MouseInfo.getPointerInfo().getLocation());
cardInfo.onMouseMoved(MouseInfo.getPointerInfo().getLocation());
}
}
if (e.getEventType() == EventType.EXITED) {
cardInfo.onMouseExited();
}
}));
addMouseListener(new MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
cardInfo.onMouseExited();
}
});
}
Aggregations