<commit_before>package table;

import javax.swing.*; 
import javax.swing.event.*; 
import javax.swing.border.*;
import javax.swing.table.*;

import java.awt.*; 
import java.awt.event.*;
import java.awt.image.*;

import java.util.*;
import ui.ATable;

import graph.Route;
import graph.GraphPopup;

public class NetworkTable extends JComponent implements ActionListener {
	protected JScrollPane scroller = null;

	public void actionPerformed(ActionEvent ev) {
		isAlive = false;
	}

	public boolean isAlive() {
		return isAlive;
	}

	public Image getScreenshot() {
		BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
		Graphics g = image.getGraphics();
		paint(g);
		g.dispose();
		return image;
	}

	protected boolean isAlive = true;

	protected GraphPopup popup = null;

	public void setGraphPopup(GraphPopup popup) {
		this.popup = popup;
	}

	public NetworkTable() {
		this(new Properties());
	}

	protected GenericTableModel model;
	protected JTable table;

	public NetworkTable(Properties display) {
		this.display = display;

		model = new GenericTableModel(new String[] { " ", "Address", "Label", "Description", "Pivot" }, "Address", 256);
		table = new ATable(model);
		TableRowSorter sorter = new TableRowSorter(model);
		sorter.toggleSortOrder(1);

		Comparator hostCompare = new Comparator() {
			public int compare(Object a, Object b) {
				long aa = Route.ipToLong(a + "");
				long bb = Route.ipToLong(b + "");

				if (aa > bb) {
					return 1;
				}
				else if (aa < bb) {
					return -1;
				}
				else {
					return 0;
				}
			}

			public boolean equals(Object a, Object b) {
				return (a + "").equals(b + "");
			}
		};

		sorter.setComparator(1, hostCompare);
		sorter.setComparator(4, hostCompare);

		table.setRowSorter(sorter);
		table.setColumnSelectionAllowed(false);

		table.getColumn("Address").setPreferredWidth(125);
		table.getColumn("Label").setPreferredWidth(125);
		table.getColumn("Pivot").setPreferredWidth(125);
		table.getColumn(" ").setPreferredWidth(32);
		table.getColumn(" ").setMaxWidth(32);
		table.getColumn("Description").setPreferredWidth(500);

		final TableCellRenderer parent = table.getDefaultRenderer(Object.class);
		table.setDefaultRenderer(Object.class, new TableCellRenderer() {
			public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
				JLabel component = (JLabel)parent.getTableCellRendererComponent(table, value, isSelected, false, row, col);

				if (col == 4 && Boolean.TRUE.equals(model.getValueAt(table, row, "Active"))) {
					component.setFont(component.getFont().deriveFont(Font.BOLD));
				}
				else if (col == 1 && !"".equals(model.getValueAt(table, row, "Description"))) {
					component.setFont(component.getFont().deriveFont(Font.BOLD));
				}
				else {
					component.setFont(component.getFont().deriveFont(Font.PLAIN));
				}

				String tip = model.getValueAt(table, row, "Tooltip") + "";

				if (tip.length() > 0) {
					component.setToolTipText(tip);
				}
				return component;
			}
		});

		table.getColumn(" ").setCellRenderer(new TableCellRenderer() {
			public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
				JLabel component = (JLabel)parent.getTableCellRendererComponent(table, value, isSelected, false, row, col);
				component.setIcon(new ImageIcon((Image)model.getValueAt(table, row, "Image")));
				component.setText("");

				String tip = model.getValueAt(table, row, "Tooltip") + "";

				if (tip.length() > 0) {
					component.setToolTipText(tip);
				}

				return component;
			}
		});

		table.addMouseListener(new MouseAdapter() {
			public void all(MouseEvent ev) {
				if (ev.isPopupTrigger()) {
					popup.showGraphPopup(getSelectedHosts(), ev);<commit_msg>make sure table always uses desired renderer<commit_after>package table;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.table.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

import java.util.*;
import ui.ATable;

import graph.Route;
import graph.GraphPopup;

public class NetworkTable extends JComponent implements ActionListener {
	protected JScrollPane scroller = null;

	public void actionPerformed(ActionEvent ev) {
		isAlive = false;
	}

	public boolean isAlive() {
		return isAlive;
	}

	public Image getScreenshot() {
		BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
		Graphics g = image.getGraphics();
		paint(g);
		g.dispose();
		return image;
	}

	protected boolean isAlive = true;

	protected GraphPopup popup = null;

	public void setGraphPopup(GraphPopup popup) {
		this.popup = popup;
	}

	public NetworkTable() {
		this(new Properties());
	}

	protected GenericTableModel model;
	protected JTable table;

	public NetworkTable(Properties display) {
		this.display = display;

		model = new GenericTableModel(new String[] { " ", "Address", "Label", "Description", "Pivot" }, "Address", 256);
		table = new ATable(model);
		TableRowSorter sorter = new TableRowSorter(model);
		sorter.toggleSortOrder(1);

		Comparator hostCompare = new Comparator() {
			public int compare(Object a, Object b) {
				long aa = Route.ipToLong(a + "");
				long bb = Route.ipToLong(b + "");

				if (aa > bb) {
					return 1;
				}
				else if (aa < bb) {
					return -1;
				}
				else {
					return 0;
				}
			}

			public boolean equals(Object a, Object b) {
				return (a + "").equals(b + "");
			}
		};

		sorter.setComparator(1, hostCompare);
		sorter.setComparator(4, hostCompare);

		table.setRowSorter(sorter);
		table.setColumnSelectionAllowed(false);

		table.getColumn("Address").setPreferredWidth(125);
		table.getColumn("Label").setPreferredWidth(125);
		table.getColumn("Pivot").setPreferredWidth(125);
		table.getColumn(" ").setPreferredWidth(32);
		table.getColumn(" ").setMaxWidth(32);
		table.getColumn("Description").setPreferredWidth(500);

		final TableCellRenderer parent = table.getDefaultRenderer(Object.class);
		final TableCellRenderer phear  = new TableCellRenderer() {
			public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
				JLabel component = (JLabel)parent.getTableCellRendererComponent(table, value, isSelected, false, row, col);

				if (col == 4 && Boolean.TRUE.equals(model.getValueAt(table, row, "Active"))) {
					component.setFont(component.getFont().deriveFont(Font.BOLD));
				}
				else if (col == 1 && !"".equals(model.getValueAt(table, row, "Description"))) {
					component.setFont(component.getFont().deriveFont(Font.BOLD));
				}
				else {
					component.setFont(component.getFont().deriveFont(Font.PLAIN));
				}

				String tip = model.getValueAt(table, row, "Tooltip") + "";

				if (tip.length() > 0) {
					component.setToolTipText(tip);
				}

				return component;
			}
		};

		table.getColumn("Address").setCellRenderer(phear);
		table.getColumn("Label").setCellRenderer(phear);
		table.getColumn("Description").setCellRenderer(phear);
		table.getColumn("Pivot").setCellRenderer(phear);

		table.getColumn(" ").setCellRenderer(new TableCellRenderer() {
			public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
				JLabel component = (JLabel)parent.getTableCellRendererComponent(table, value, isSelected, false, row, col);
				component.setIcon(new ImageIcon((Image)model.getValueAt(table, row, "Image")));
				component.setText("");

				String tip = model.getValueAt(table, row, "Tooltip") + "";

				if (tip.length() > 0) {
					component.setToolTipText(tip);
				}

				return component;
			}
		});

		table.addMouseListener(new MouseAdapter() {
			public void all(MouseEvent ev) {
				if (ev.isPopupTrigger()) {
					popup.showGraphPopup(getSelectedHosts(), ev);
{'fraction_non_alphanumeric': 0.13567398119122256, 'fraction_numerical': 0.007523510971786834, 'mean_word_length': 4.289124668435013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6246048', 'n_tokens_mistral': 2887, 'n_tokens_neox': 2471, 'n_words': 551}