<commit_before>package gui.models;

import gui.PasswordPane;

import java.awt.Color;
import java.awt.Component;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

import org.bouncycastle.crypto.InvalidCipherTextException;

import qora.account.Account;
import qora.account.PrivateKeyAccount;
import qora.block.Block;
import qora.crypto.AEScrypto;
import qora.transaction.MessageTransaction;
import qora.transaction.Transaction;
import qora.wallet.Wallet;
import utils.Converter;
import utils.DateTimeFormat;
import utils.NumberAsString;
import utils.ObserverMessage;
import utils.Pair;
import utils.TableMenuPopupUtil;
import controller.Controller;
import database.DBSet;

@SuppressWarnings("serial")
public class MessagesTableModel extends JTable implements Observer{
	private ArrayList<MessageBuf> messageBufs;
	Comparator<MessageBuf> comparator = new Comparator<MessageBuf>() {
	    public int compare(MessageBuf c1, MessageBuf c2) {
	        return (int) (c2.getTimestamp() - c1.getTimestamp());
	    }
	};

	JMenuItem menuDecrypt;
	private DefaultTableModel messagesModel;
	int width;
	int fontHeight;
	
	public MessagesTableModel()
	{
		this.setShowGrid(false);

		fontHeight = this.getFontMetrics(this.getFont()).getHeight();

		messageBufs = new ArrayList<MessageBuf>();
		messagesModel = new DefaultTableModel();
		this.setModel(messagesModel);
		messagesModel.addColumn("");
		
		DefaultTableCellRenderer topRenderer = new DefaultTableCellRenderer();
		topRenderer.setVerticalAlignment(DefaultTableCellRenderer.TOP);
		this.getColumn("").setCellRenderer( topRenderer );
		
		List<Pair<Account, Transaction>> transaction = Controller.getInstance().getLastTransactions(30000);
		
		for (Pair<Account, Transaction> pair : transaction) 
		{
			if(pair.getB().getType() == Transaction.MESSAGE_TRANSACTION)
			{
				boolean is = false;
				for (MessageBuf message : messageBufs) {
					if(Arrays.equals(pair.getB().getSignature(), message.getSignature()))
					{
						is = true;
						break;
					}
				}
				if(!is)
				{
					addMessage(messageBufs.size(),(MessageTransaction)pair.getB());
				}
			}
		}
		
		Collections.sort(messageBufs, comparator);
		
		messagesModel.setRowCount(messageBufs.size());
		for ( int j = messageBufs.size()-1; j >= 0; j-- )
		{
			setHeight(j);	
		}
		
		
		//MENU
		JPopupMenu menu = new JPopupMenu();	

		JMenuItem copyMessage = new JMenuItem("Copy Message");
		copyMessage.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e) 
			{<commit_msg>Now loads all Messages history<commit_after>package gui.models;

import gui.PasswordPane;

import java.awt.Color;
import java.awt.Component;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

import org.bouncycastle.crypto.InvalidCipherTextException;

import qora.account.Account;
import qora.account.PrivateKeyAccount;
import qora.block.Block;
import qora.crypto.AEScrypto;
import qora.transaction.MessageTransaction;
import qora.transaction.Transaction;
import qora.wallet.Wallet;
import utils.Converter;
import utils.DateTimeFormat;
import utils.NumberAsString;
import utils.ObserverMessage;
import utils.Pair;
import utils.TableMenuPopupUtil;
import controller.Controller;
import database.DBSet;

@SuppressWarnings("serial")
public class MessagesTableModel extends JTable implements Observer{
	private ArrayList<MessageBuf> messageBufs;
	Comparator<MessageBuf> comparator = new Comparator<MessageBuf>() {
	    public int compare(MessageBuf c1, MessageBuf c2) {
	        return (int) (c2.getTimestamp() - c1.getTimestamp());
	    }
	};

	JMenuItem menuDecrypt;
	private DefaultTableModel messagesModel;
	int width;
	int fontHeight;
	
	public MessagesTableModel()
	{
		this.setShowGrid(false);

		fontHeight = this.getFontMetrics(this.getFont()).getHeight();

		messageBufs = new ArrayList<MessageBuf>();
		messagesModel = new DefaultTableModel();
		this.setModel(messagesModel);
		messagesModel.addColumn("");
		
		DefaultTableCellRenderer topRenderer = new DefaultTableCellRenderer();
		topRenderer.setVerticalAlignment(DefaultTableCellRenderer.TOP);
		this.getColumn("").setCellRenderer( topRenderer );
		
		List<Transaction> transactions = new ArrayList<Transaction>();;

		for (Transaction transaction : Controller.getInstance().getUnconfirmedTransactions()) {
			if(transaction.getType() == Transaction.MESSAGE_TRANSACTION)
			{
				transactions.add(transaction);
			}
		}
		
		for (Account account : Controller.getInstance().getAccounts()) {
			transactions.addAll(DBSet.getInstance().getTransactionFinalMap().getTransactionsByTypeAndAddress(account.getAddress(), Transaction.MESSAGE_TRANSACTION, 0));	
		}
		
		for (Transaction messagetx : transactions) {
			boolean is = false;
			for (MessageBuf message : messageBufs) {
				if(Arrays.equals(messagetx.getSignature(), message.getSignature()))
				{
					is = true;
					break;
				}
			}
			if(!is)
			{
				addMessage(messageBufs.size(),(MessageTransaction)messagetx);
			}
		}
				
		Collections.sort(messageBufs, comparator);
		
		messagesModel.setRowCount(messageBufs.size());
		for ( int j = messageBufs.size()-1; j >= 0; j-- )
		{
			setHeight(j);	
		}
		
		
		//MENU
		JPopupMenu menu = new JPopupMenu();	

		JMenuItem copyMessage = new JMenuItem("Copy Message");
		copyMessage.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e) 
			{
{'fraction_non_alphanumeric': 0.10820895522388059, 'fraction_numerical': 0.0024875621890547263, 'mean_word_length': 5.254969749351772, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, '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': '358745', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2151, 'n_words': 423}