<commit_before>package org.cytoscape.browser.internal;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableRowSorter;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.application.swing.CytoPanelName;
import org.cytoscape.browser.internal.util.ColumnResizer;
import org.cytoscape.equations.EquationCompiler;
import org.cytoscape.event.CyEventHelper;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.model.CyNetworkTableManager;
import org.cytoscape.model.CyTable;
import org.cytoscape.model.CyTableManager;
import org.cytoscape.service.util.CyServiceRegistrar;
import org.cytoscape.task.TableTaskFactory;
import org.cytoscape.util.swing.OpenBrowser;
import org.cytoscape.work.swing.DialogTaskManager;
import javax.swing.table.DefaultTableModel;


/**
 * Base class for all Table Browsers.
 *
 */
public abstract class AbstractTableBrowser extends JPanel implements CytoPanelComponent, ActionListener {

	private static final long serialVersionUID = 1968196123280466989L;
	
	static final Dimension SELECTOR_SIZE = new Dimension(400, 32);
	
	// Color theme for table browser.
	static final Color NETWORK_COLOR = new Color(0xA5, 0x2A, 0x2A);
	static final Color SELECTED_ITEM_BACKGROUND_COLOR = new Color(0xA0, 0xA0, 0xA0, 80);
	
	private static final Dimension PANEL_SIZE = new Dimension(550, 400);
	
	protected final CyTableManager tableManager;
	protected final CyServiceRegistrar serviceRegistrar;
	private final EquationCompiler compiler;
	
	protected AttributeBrowserToolBar attributeBrowserToolBar;
		
	protected CyTable currentTable;
	protected final CyApplicationManager applicationManager;
	protected final CyNetworkManager networkManager;
	private final OpenBrowser openBrowser;
	private final PopupMenuHelper popupMenuHelper; 
	private final CyEventHelper eventHelper;
	

	// Tab title for the CytoPanel
	private final String tabTitle;
	private final Map<BrowserTableModel,JScrollPane> scrollPanes;
	private final Map<CyTable,BrowserTableModel> browserTableModels;
	private JScrollPane currentScrollPane;
	
	AbstractTableBrowser(final String tabTitle,
						 final CyTableManager tableManager,
						 final CyNetworkTableManager networkTableManager,
						 final CyServiceRegistrar serviceRegistrar,
						 final EquationCompiler compiler,
						 final OpenBrowser openBrowser,
						 final CyNetworkManager networkManager,
						 final TableTaskFactory deleteTableTaskFactory,
						 final DialogTaskManager guiTaskManager,
						 final PopupMenuHelper popupMenuHelper,
						 final CyApplicationManager applicationManager,
						 final CyEventHelper eventHelper) {
		this.tableManager = tableManager;
		this.serviceRegistrar = serviceRegistrar;
		this.compiler = compiler;
		this.tabTitle = tabTitle;
		this.networkManager = networkManager;
		this.applicationManager = applicationManager;
		this.openBrowser = openBrowser;
		this.popupMenuHelper = popupMenuHelper;
		this.eventHelper = eventHelper;

		this.scrollPanes = new HashMap<BrowserTableModel,JScrollPane>();
		this.browserTableModels = new HashMap<CyTable,BrowserTableModel>();
		
		this.setLayout(new BorderLayout());
		this.setPreferredSize(PANEL_SIZE);
		this.setSize(PANEL_SIZE);
	}

	/**
	 * Returns the Component to be added to the CytoPanel.
	 * @return The Component to be added to the CytoPanel.
	 */
	@Override
	public Component getComponent() { return this; }

	/**
	 * Returns the name of the CytoPanel that this component should be added to.
	 * @return the name of the CytoPanel that this component should be added to.
	 */
	@Override
	public CytoPanelName getCytoPanelName() {
		return CytoPanelName.SOUTH;
	}

	/**
	 * Returns the title of the tab within the CytoPanel for this component.
	 * @return the title of the tab within the CytoPanel for this component.
	 */
	@Override
	public String getTitle() { return tabTitle; }

	/**
	 * @return null
	 */
	@Override
	public Icon getIcon() { return null; }
	
	// Delete the given table from the JTable
	public void deleteTable(CyTable cyTable){
		BrowserTableModel model = browserTableModels.remove(cyTable);
		if (model == null) {
			return;
		}
		scrollPanes.remove(model);
		serviceRegistrar.unregisterAllServices(model);
		
		model.getBrowserTable().setModel(new DefaultTableModel());
		
		if (currentTable == cyTable) {
			currentTable = null;
		}
	}
	
	synchronized void showSelectedTable() {
		if (currentScrollPane != null)
			remove(currentScrollPane);

		final BrowserTableModel currentBrowserTableModel = getCurrentBrowserTableModel();
		final JScrollPane newScrollPane = getScrollPane(currentBrowserTableModel);
		
		if (newScrollPane != null)
			add(newScrollPane, BorderLayout.CENTER);
		else
			repaint();

		currentScrollPane = newScrollPane;
		applicationManager.setCurrentTable(currentTable);
		attributeBrowserToolBar.setBrowserTableModel(currentBrowserTableModel);
		
		// Resize column
		if (currentBrowserTableModel != null)
			ColumnResizer.adjustColumnPreferredWidths(currentBrowserTableModel.getTable());
	}<commit_msg>fixes #1234 removed the code that resized the columns on each setcurrentview event.<commit_after>package org.cytoscape.browser.internal;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableRowSorter;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.application.swing.CytoPanelName;
import org.cytoscape.browser.internal.util.ColumnResizer;
import org.cytoscape.equations.EquationCompiler;
import org.cytoscape.event.CyEventHelper;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.model.CyNetworkTableManager;
import org.cytoscape.model.CyTable;
import org.cytoscape.model.CyTableManager;
import org.cytoscape.service.util.CyServiceRegistrar;
import org.cytoscape.task.TableTaskFactory;
import org.cytoscape.util.swing.OpenBrowser;
import org.cytoscape.work.swing.DialogTaskManager;
import javax.swing.table.DefaultTableModel;


/**
 * Base class for all Table Browsers.
 *
 */
public abstract class AbstractTableBrowser extends JPanel implements CytoPanelComponent, ActionListener {

	private static final long serialVersionUID = 1968196123280466989L;
	
	static final Dimension SELECTOR_SIZE = new Dimension(400, 32);
	
	// Color theme for table browser.
	static final Color NETWORK_COLOR = new Color(0xA5, 0x2A, 0x2A);
	static final Color SELECTED_ITEM_BACKGROUND_COLOR = new Color(0xA0, 0xA0, 0xA0, 80);
	
	private static final Dimension PANEL_SIZE = new Dimension(550, 400);
	
	protected final CyTableManager tableManager;
	protected final CyServiceRegistrar serviceRegistrar;
	private final EquationCompiler compiler;
	
	protected AttributeBrowserToolBar attributeBrowserToolBar;
		
	protected CyTable currentTable;
	protected final CyApplicationManager applicationManager;
	protected final CyNetworkManager networkManager;
	private final OpenBrowser openBrowser;
	private final PopupMenuHelper popupMenuHelper; 
	private final CyEventHelper eventHelper;
	

	// Tab title for the CytoPanel
	private final String tabTitle;
	private final Map<BrowserTableModel,JScrollPane> scrollPanes;
	private final Map<CyTable,BrowserTableModel> browserTableModels;
	private JScrollPane currentScrollPane;
	
	AbstractTableBrowser(final String tabTitle,
						 final CyTableManager tableManager,
						 final CyNetworkTableManager networkTableManager,
						 final CyServiceRegistrar serviceRegistrar,
						 final EquationCompiler compiler,
						 final OpenBrowser openBrowser,
						 final CyNetworkManager networkManager,
						 final TableTaskFactory deleteTableTaskFactory,
						 final DialogTaskManager guiTaskManager,
						 final PopupMenuHelper popupMenuHelper,
						 final CyApplicationManager applicationManager,
						 final CyEventHelper eventHelper) {
		this.tableManager = tableManager;
		this.serviceRegistrar = serviceRegistrar;
		this.compiler = compiler;
		this.tabTitle = tabTitle;
		this.networkManager = networkManager;
		this.applicationManager = applicationManager;
		this.openBrowser = openBrowser;
		this.popupMenuHelper = popupMenuHelper;
		this.eventHelper = eventHelper;

		this.scrollPanes = new HashMap<BrowserTableModel,JScrollPane>();
		this.browserTableModels = new HashMap<CyTable,BrowserTableModel>();
		
		this.setLayout(new BorderLayout());
		this.setPreferredSize(PANEL_SIZE);
		this.setSize(PANEL_SIZE);
	}

	/**
	 * Returns the Component to be added to the CytoPanel.
	 * @return The Component to be added to the CytoPanel.
	 */
	@Override
	public Component getComponent() { return this; }

	/**
	 * Returns the name of the CytoPanel that this component should be added to.
	 * @return the name of the CytoPanel that this component should be added to.
	 */
	@Override
	public CytoPanelName getCytoPanelName() {
		return CytoPanelName.SOUTH;
	}

	/**
	 * Returns the title of the tab within the CytoPanel for this component.
	 * @return the title of the tab within the CytoPanel for this component.
	 */
	@Override
	public String getTitle() { return tabTitle; }

	/**
	 * @return null
	 */
	@Override
	public Icon getIcon() { return null; }
	
	// Delete the given table from the JTable
	public void deleteTable(CyTable cyTable){
		BrowserTableModel model = browserTableModels.remove(cyTable);
		if (model == null) {
			return;
		}
		scrollPanes.remove(model);
		serviceRegistrar.unregisterAllServices(model);
		
		model.getBrowserTable().setModel(new DefaultTableModel());
		
		if (currentTable == cyTable) {
			currentTable = null;
		}
	}
	
	synchronized void showSelectedTable() {
		if (currentScrollPane != null)
			remove(currentScrollPane);

		final BrowserTableModel currentBrowserTableModel = getCurrentBrowserTableModel();
		final JScrollPane newScrollPane = getScrollPane(currentBrowserTableModel);
		
		if (newScrollPane != null)
			add(newScrollPane, BorderLayout.CENTER);
		else
			repaint();

		currentScrollPane = newScrollPane;
		applicationManager.setCurrentTable(currentTable);
		attributeBrowserToolBar.setBrowserTableModel(currentBrowserTableModel);
	
		
		/* 
		// Never resize columns as they would reset the columns each time the view is changed
		if (currentBrowserTableModel != null)
			ColumnResizer.adjustColumnPreferredWidths(currentBrowserTableModel.getTable());
		 */
	}
{'fraction_non_alphanumeric': 0.07475098236315453, 'fraction_numerical': 0.008407200950379237, 'mean_word_length': 5.1517706576728495, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '834913', 'n_tokens_mistral': 3479, 'n_tokens_neox': 3002, 'n_words': 807}