package de.hhu.ba.yoshikoWrapper.gui; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import javax.swing.JCheckBox; import javax.swing.JComboBox; import org.cytoscape.application.CyApplicationManager; import org.cytoscape.model.CyColumn; import org.cytoscape.model.CyNetwork; import de.hhu.ba.yoshikoWrapper.core.Core; @SuppressWarnings("serial") //will never be serialized public class ModificationCostMapper extends ComfortPanel { //Symbolic links private CyApplicationManager cy; //Swing components private JComboBox<CyColumn> tableFields; private JCheckBox useMapping; public ModificationCostMapper() { tableFields = new JComboBox<CyColumn>(); useMapping = new JCheckBox("Map modification costs"); useMapping.setToolTipText( "When you use this value you can assign a column in the edge table to represent the modification costs that are to be paid for deleting an edge." +"You can also assign negative values if you have a complete graph to represent insertion costs." +"Note: Any missing values are assumed to be the default values" ); cy = Core.getApplicationManager(); this.addAll(useMapping,tableFields); //Initial call to get table values updateValues(); //Add a focus listener to update values //TODO: This might be a bit inelegant but there is no way to get a callback from CS when a table changes values tableFields.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { updateValues(); } @Override public void focusLost(FocusEvent e) {} }); } public void updateValues() { //Clear entries tableFields.removeAllItems(); CyNetwork net = cy.getCurrentNetwork(); if (net != null) { //Check if a network is loaded for (CyColumn c : net.getDefaultEdgeTable().getColumns()){ tableFields.addItem(c); } } } public CyColumn getValue() { if (useMapping.isSelected()) { return tableFields.getItemAt(tableFields.getSelectedIndex()); } return null; } }