<commit_before>// PathVisio,
// a tool for data visualization and analysis using Biological Pathways
// Copyright 2006-2007 BiGCaT Bioinformatics
//
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0 
//  
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
//
package org.pathvisio.cytoscape;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

import org.pathvisio.Engine;
import org.pathvisio.gui.swing.propertypanel.TypedProperty;
import org.pathvisio.model.ObjectType;
import org.pathvisio.model.PathwayElement;
import org.pathvisio.model.PropertyType;
import org.pathvisio.view.VPathwayWrapperBase;

/**
 * Panel to configure attribute to GPML property mappings
 * @author thomas
 */
public class AttributeDefaultsPanel extends JPanel {
	String[] columnNames = new String[] { "Property", "Default value" };
	AttributeMapper mapper;
	
	JTable table;
	AttributeMapperTableModel tableModel;
	
	List<TypedProperty> properties = new ArrayList<TypedProperty>();
	
	public AttributeDefaultsPanel(AttributeMapper mapper) {
		setLayout(new BorderLayout());
		
		//Hack to make TypedProperty work
		Engine.init();
		Engine.getCurrent().setWrapper(new VPathwayWrapperBase());
		Engine.getCurrent().newPathway();
		
		this.mapper = mapper;
		tableModel = new AttributeMapperTableModel();
		
		//Get the property list
		PathwayElement dummyElement = PathwayElement.createPathwayElement(ObjectType.DATANODE);
		for(PropertyType p : dummyElement.getAttributes(false)) {
			if(!mapper.isProtected(p)) {
				TypedProperty tp = new TypedProperty(p);
				Object value = mapper.getDefaultValue(p);
				if(value == null) {
					value = dummyElement.getProperty(p);
				}
				tp.setValue(value);
				properties.add(tp);
			}
		}
		
		table = new JTable(tableModel) {
			public TableCellRenderer getCellRenderer(int row, int column) {
				TableCellRenderer r = tableModel.getCellRenderer(row, column);
				return r == null ? super.getCellRenderer(row, column) : r;
			}

			public TableCellEditor getCellEditor(int row, int column) {
				TableCellEditor e = tableModel.getCellEditor(row, column);
				return e == null ? super.getCellEditor(row, column) : e;
			}
		};
		
		JEditorPane help = new JEditorPane("text/html", <commit_msg>Added SwingEngine dependency to cytoscape plugin<commit_after>// PathVisio,
// a tool for data visualization and analysis using Biological Pathways
// Copyright 2006-2007 BiGCaT Bioinformatics
//
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0 
//  
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
//
package org.pathvisio.cytoscape;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

import org.pathvisio.Engine;
import org.pathvisio.gui.swing.SwingEngine;
import org.pathvisio.gui.swing.propertypanel.TypedProperty;
import org.pathvisio.model.ObjectType;
import org.pathvisio.model.PathwayElement;
import org.pathvisio.model.PropertyType;
import org.pathvisio.view.VPathwayWrapperBase;

/**
 * Panel to configure attribute to GPML property mappings
 * @author thomas
 */
public class AttributeDefaultsPanel extends JPanel {
	String[] columnNames = new String[] { "Property", "Default value" };
	AttributeMapper mapper;
	
	JTable table;
	AttributeMapperTableModel tableModel;
	
	List<TypedProperty> properties = new ArrayList<TypedProperty>();
	
	public AttributeDefaultsPanel(AttributeMapper mapper) {
		setLayout(new BorderLayout());
		
		//Hack to make TypedProperty work
		Engine engine = Engine.init();
		engine.setWrapper(new VPathwayWrapperBase());
		engine.newPathway();
		SwingEngine swingEngine = SwingEngine.init(engine);
		
		this.mapper = mapper;
		tableModel = new AttributeMapperTableModel();
		
		//Get the property list
		PathwayElement dummyElement = PathwayElement.createPathwayElement(ObjectType.DATANODE);
		for(PropertyType p : dummyElement.getAttributes(false)) {
			if(!mapper.isProtected(p)) {
				TypedProperty tp = new TypedProperty(swingEngine, p);
				Object value = mapper.getDefaultValue(p);
				if(value == null) {
					value = dummyElement.getProperty(p);
				}
				tp.setValue(value);
				properties.add(tp);
			}
		}
		
		table = new JTable(tableModel) {
			public TableCellRenderer getCellRenderer(int row, int column) {
				TableCellRenderer r = tableModel.getCellRenderer(row, column);
				return r == null ? super.getCellRenderer(row, column) : r;
			}

			public TableCellEditor getCellEditor(int row, int column) {
				TableCellEditor e = tableModel.getCellEditor(row, column);
				return e == null ? super.getCellEditor(row, column) : e;
			}
		};
		
		JEditorPane help = new JEditorPane("text/html", 
{'fraction_non_alphanumeric': 0.09907223326706428, 'fraction_numerical': 0.003976143141153081, 'mean_word_length': 4.404655326768129, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7062123', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1728, 'n_words': 497}