Search in sources :

Example 1 with PlaneView

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();
        }
    });
}
Also used : Enumeration(java.util.Enumeration) MouseEvent(java.awt.event.MouseEvent) Plane(mage.game.command.Plane) HTMLDocument(javax.swing.text.html.HTMLDocument) CardView(mage.view.CardView) MouseAdapter(java.awt.event.MouseAdapter) VirtualCardInfo(mage.client.cards.VirtualCardInfo) CardInfo(mage.cards.repository.CardInfo) PlaneView(mage.view.PlaneView) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)1 HTMLDocument (javax.swing.text.html.HTMLDocument)1 CardInfo (mage.cards.repository.CardInfo)1 VirtualCardInfo (mage.client.cards.VirtualCardInfo)1 Plane (mage.game.command.Plane)1 CardView (mage.view.CardView)1 PlaneView (mage.view.PlaneView)1