<commit_before>package com.remuladgryta.cardgame.ui;

import javax.swing.JEditorPane;
import javax.swing.JList;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.html.HTMLEditorKit;

import com.remuladgryta.cardgame.Card;
import com.remuladgryta.cardgame.GameEngine;

public class CardView extends JEditorPane implements ListSelectionListener,
		HyperlinkListener {

	private Card currentCard;
	private GameEngine engine;
	private boolean interactive = false;

	public boolean isInteractive() {
		return interactive;
	}

	public void setInteractive(boolean interactive) {
		this.interactive = interactive;
	}

	public GameEngine getEngine() {
		return engine;
	}

	public void setEngine(GameEngine engine) {
		this.engine = engine;
	}

	private JList<Card> cardList;

	public CardView() {
		super("text/html", "");
		((HTMLEditorKit) getEditorKit()).setAutoFormSubmission(false);
		addHyperlinkListener(this);
		setEditable(false);
	}

	public JList<Card> getCardList() {
		return cardList;
	}

	public void setCardList(JList<Card> cardList) {
		cardList.removeListSelectionListener(this);
		this.cardList = cardList;
		cardList.addListSelectionListener(this);
	}

	@Override
	public void valueChanged(ListSelectionEvent evt) {
		StringBuilder sb = new StringBuilder();
		currentCard = cardList.getSelectedValue();
		if (currentCard != null) {
			// Add card texts
			sb.append("<b>");
			sb.append(currentCard.getTitle());
			sb.append("</b> <br/>");
			sb.append(currentCard.getText());
			sb.append("<br/>");
			if (interactive) {
				// Add links to play/discard
				sb.append("<a href=\"http://play\"> Play </a> &nbsp &nbsp &nbsp");
				sb.append("<a href=\"http://discard\"> Discard </a>");
			}
		}
		setText(sb.toString());
	}

	@Override
	public void hyperlinkUpdate(HyperlinkEvent event) {
		if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
			if (event.getURL().getHost().equals("play")) {
				currentCard.selectForPlay(engine.getCurrentPlayer());
			} else if (event.getURL().getHost().equals("discard")) {
				engine.getCurrentPlayer().getHand().removeCard(currentCard);
			}
		}
	}
}<commit_msg>Fixed CardView displaying wrong card data, hopefully for good this time.<commit_after>package com.remuladgryta.cardgame.ui;

import javax.swing.JEditorPane;
import javax.swing.JList;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.html.HTMLEditorKit;

import com.remuladgryta.cardgame.Card;
import com.remuladgryta.cardgame.GameEngine;

public class CardView extends JEditorPane implements ListSelectionListener,
		HyperlinkListener, ListDataListener {

	private Card currentCard;
	private GameEngine engine;
	private boolean interactive = false;

	public boolean isInteractive() {
		return interactive;
	}

	public void setInteractive(boolean interactive) {
		this.interactive = interactive;
	}

	public GameEngine getEngine() {
		return engine;
	}

	public void setEngine(GameEngine engine) {
		this.engine = engine;
	}

	private JList<Card> cardList;

	public CardView() {
		super("text/html", "");
		((HTMLEditorKit) getEditorKit()).setAutoFormSubmission(false);
		addHyperlinkListener(this);
		setEditable(false);
	}

	public JList<Card> getCardList() {
		return cardList;
	}

	public void setCardList(JList<Card> cardList) {
		if(this.cardList != null){
			this.cardList.removeListSelectionListener(this);
			this.cardList.getModel().removeListDataListener(this);
		}
		this.cardList = cardList;
		cardList.addListSelectionListener(this);
		cardList.getModel().addListDataListener(this);
	}

	@Override
	public void valueChanged(ListSelectionEvent evt) {
		updateView();
	}
	
	private void updateView(){
		StringBuilder sb = new StringBuilder();
		currentCard = cardList.getSelectedValue();
		if (currentCard != null) {
			// Add card texts
			sb.append("<b>");
			sb.append(currentCard.getTitle());
			sb.append("</b> <br/>");
			sb.append(currentCard.getText());
			sb.append("<br/>");
			if (interactive) {
				// Add links to play/discard
				sb.append("<a href=\"http://play\"> Play </a> &nbsp &nbsp &nbsp");
				sb.append("<a href=\"http://discard\"> Discard </a>");
			}
		}
		setText(sb.toString());
	}

	@Override
	public void hyperlinkUpdate(HyperlinkEvent event) {
		if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
			if (event.getURL().getHost().equals("play")) {
				currentCard.selectForPlay(engine.getCurrentPlayer());
			} else if (event.getURL().getHost().equals("discard")) {
				engine.getCurrentPlayer().getHand().removeCard(currentCard);
			}
		}
	}

	@Override
	public void contentsChanged(ListDataEvent arg0) {
		updateView();
	}

	@Override
	public void intervalAdded(ListDataEvent arg0) {
		updateView();
	}

	@Override
	public void intervalRemoved(ListDataEvent arg0) {
		updateView();
	}
}
{'fraction_non_alphanumeric': 0.1332686711930165, 'fraction_numerical': 0.0005819592628516004, 'mean_word_length': 4.879133409350057, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6605538', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1627, 'n_words': 319}