Commit d3a91a4b authored by Philipp Spohr's avatar Philipp Spohr
Browse files

More elegant Listener implementation for Column changes

parent 4fe665ec
<!--
Copyright (C) 2017 Philipp Spohr
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
......@@ -21,7 +21,7 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<bundle.symbolicName>de.hhu.ba.yoshikoWrapper</bundle.symbolicName>
<bundle.namespace>de.hhu.ba.yoshikoWrapper</bundle.namespace>
......@@ -34,7 +34,7 @@
<groupId>de.hhu.ba</groupId>
<artifactId>yoshikoWrapper</artifactId>
<version>0.1.0</version>
<name>YoshikoWrapper</name>
<build>
......
......@@ -24,19 +24,13 @@ package de.hhu.ba.yoshikoWrapper;
import java.util.Properties;
import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.application.events.SetCurrentNetworkListener;
import org.cytoscape.application.swing.CySwingApplication;
import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.model.events.AddedEdgesListener;
import org.cytoscape.model.events.ColumnCreatedListener;
import org.cytoscape.model.events.ColumnDeletedListener;
import org.cytoscape.model.events.RemovedEdgesListener;
import org.cytoscape.model.subnetwork.CyRootNetworkManager;
import org.cytoscape.service.util.AbstractCyActivator;
import org.cytoscape.service.util.CyServiceRegistrar;
import org.cytoscape.session.events.SessionLoadedListener;
import org.cytoscape.task.create.CloneNetworkTaskFactory;
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
......@@ -53,7 +47,6 @@ import de.hhu.ba.yoshikoWrapper.core.CyCore;
import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
import de.hhu.ba.yoshikoWrapper.core.YoshUtil;
import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader;
import de.hhu.ba.yoshikoWrapper.cytoUtil.NetChangeListener;
import de.hhu.ba.yoshikoWrapper.swing.components.MainPanel;
/**
......@@ -113,15 +106,6 @@ public class CyActivator extends AbstractCyActivator {
MainPanel mainPanel = new MainPanel();
registerService(context,mainPanel,CytoPanelComponent.class, new Properties());
//Listener for Network-Changes -> Updating possible columns for mapping
NetChangeListener netChangeListener = new NetChangeListener(mainPanel.getColumnMapper());
registerService(context,netChangeListener, AddedEdgesListener.class, new Properties());
registerService(context,netChangeListener, RemovedEdgesListener.class, new Properties());
registerService(context,netChangeListener, ColumnCreatedListener.class, new Properties());
registerService(context,netChangeListener, ColumnDeletedListener.class, new Properties());
registerService(context,netChangeListener, SessionLoadedListener.class, new Properties());
registerService(context,netChangeListener, SetCurrentNetworkListener.class, new Properties());
}
......
......@@ -49,15 +49,17 @@ public class YoshikoLoader {
}
try {
System.out.println("Attempting to load library @: "+libPath);
logger.info("Attempting to load library @: "+libPath);
if (!libPath.substring(0,libPath.lastIndexOf(".")).endsWith(REQUIRED_VERSION)) {
throw new Exception(LocalizationManager.get("libFail")+" "+REQUIRED_VERSION);
//TODO: Error output!
}
System.load(libPath);
//update cfg
CyCore.cm.getProperties().setProperty("pathToYoshiko", libPath);
}
catch(Exception e) {
logger.error(e.getMessage());
JOptionPane.showMessageDialog(null, LocalizationManager.get("libFail")+" "+REQUIRED_VERSION);
return;
}
......
/*******************************************************************************
* Copyright (C) 2017 Philipp Spohr
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
package de.hhu.ba.yoshikoWrapper.cytoUtil;
import org.cytoscape.application.events.SetCurrentNetworkEvent;
import org.cytoscape.application.events.SetCurrentNetworkListener;
import org.cytoscape.model.events.AddedEdgesEvent;
import org.cytoscape.model.events.AddedEdgesListener;
import org.cytoscape.model.events.ColumnCreatedEvent;
import org.cytoscape.model.events.ColumnCreatedListener;
import org.cytoscape.model.events.ColumnDeletedEvent;
import org.cytoscape.model.events.ColumnDeletedListener;
import org.cytoscape.model.events.RemovedEdgesEvent;
import org.cytoscape.model.events.RemovedEdgesListener;
import org.cytoscape.session.events.SessionLoadedEvent;
import org.cytoscape.session.events.SessionLoadedListener;
import de.hhu.ba.yoshikoWrapper.core.CyCore;
import de.hhu.ba.yoshikoWrapper.swing.components.ColumnMapper;
public class NetChangeListener
implements //everything
AddedEdgesListener,
RemovedEdgesListener,
ColumnCreatedListener,
ColumnDeletedListener,
SessionLoadedListener,
SetCurrentNetworkListener
{
private ColumnMapper columnMapper;
public NetChangeListener(ColumnMapper columnMapper) {
this.columnMapper = columnMapper;
}
@Override
public void handleEvent(ColumnDeletedEvent e) {
if (
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultEdgeTable() ||
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNetworkTable() ||
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNodeTable()
)
{
columnMapper.updateValues();
}
}
@Override
public void handleEvent(ColumnCreatedEvent e) {
if (
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultEdgeTable() ||
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNetworkTable() ||
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNodeTable()
)
{
columnMapper.updateValues();
}
}
@Override
public void handleEvent(RemovedEdgesEvent e) {
if (
e.getSource() == CyCore.cy.getCurrentNetwork()
)
{
columnMapper.updateValues();
}
}
@Override
public void handleEvent(AddedEdgesEvent e) {
if (
e.getSource() == CyCore.cy.getCurrentNetwork()
)
{
columnMapper.updateValues();
}
}
@Override
public void handleEvent(SessionLoadedEvent e) {
columnMapper.updateValues();
}
@Override
public void handleEvent(SetCurrentNetworkEvent e) {
columnMapper.updateValues();
}
}
/*******************************************************************************
* Copyright (C) 2017 Philipp Spohr
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
......@@ -21,40 +21,63 @@
******************************************************************************/
package de.hhu.ba.yoshikoWrapper.swing.components;
import java.util.Properties;
import javax.swing.GroupLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.GroupLayout.Alignment;
import org.cytoscape.application.events.SetCurrentNetworkEvent;
import org.cytoscape.application.events.SetCurrentNetworkListener;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.events.ColumnCreatedEvent;
import org.cytoscape.model.events.ColumnCreatedListener;
import org.cytoscape.model.events.ColumnDeletedEvent;
import org.cytoscape.model.events.ColumnDeletedListener;
import org.cytoscape.session.events.SessionLoadedEvent;
import org.cytoscape.session.events.SessionLoadedListener;
import de.hhu.ba.yoshikoWrapper.core.CyCore;
import de.hhu.ba.yoshikoWrapper.swing.EnableWhenSelectedListener;
import de.hhu.ba.yoshikoWrapper.swing.SwingUtil;
@SuppressWarnings("serial") //will never be serialized
public class ColumnMapper extends JPanel{
public class ColumnMapper extends JPanel
implements //everything
ColumnCreatedListener,
ColumnDeletedListener,
SessionLoadedListener,
SetCurrentNetworkListener
{
//Swing components
private final JComboBox<CyColumn> editingCostMapper;
private final JComboBox<CyColumn> permanentMapper;
private final JComboBox<CyColumn> forbiddenMapper;
private final JCheckBox useMappingCost;
private final JCheckBox useMappingPerm;
private final JCheckBox useMappingForb;
public ColumnMapper() {
//Listener for Network-Changes -> Updating possible columns for mapping
CyCore.registrar.registerService(this,ColumnCreatedListener.class,new Properties());
CyCore.registrar.registerService(this,ColumnDeletedListener.class,new Properties());
CyCore.registrar.registerService(this,SessionLoadedListener.class,new Properties());
CyCore.registrar.registerService(this,SetCurrentNetworkListener.class,new Properties());
//SWING COMPONENTS
//Combo-Boxes that map to the CyColumns
editingCostMapper = new JComboBox<CyColumn>();
permanentMapper = new JComboBox<CyColumn>();
forbiddenMapper = new JComboBox<CyColumn>();
//Should only be enabled if the option is checked
editingCostMapper.setEnabled(false);
permanentMapper.setEnabled(false);
......@@ -63,7 +86,7 @@ public class ColumnMapper extends JPanel{
useMappingCost = new JCheckBox("Map modification costs");
useMappingPerm = new JCheckBox("Map edges as permanent");
useMappingForb = new JCheckBox("Map edges as forbidden");
useMappingCost.addActionListener(
new EnableWhenSelectedListener(useMappingCost, editingCostMapper)
);
......@@ -73,15 +96,15 @@ public class ColumnMapper extends JPanel{
useMappingForb.addActionListener(
new EnableWhenSelectedListener(useMappingForb, forbiddenMapper)
);
SwingUtil.addAll(this,useMappingCost,editingCostMapper);
SwingUtil.addAll(this,useMappingPerm,permanentMapper);
SwingUtil.addAll(this,useMappingForb,forbiddenMapper);
//Layout
GroupLayout layout = new GroupLayout(this);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(useMappingCost)
......@@ -95,8 +118,8 @@ public class ColumnMapper extends JPanel{
)
);
layout.setVerticalGroup(layout.createSequentialGroup()
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup()
.addComponent(useMappingCost)
.addComponent(editingCostMapper)
......@@ -110,20 +133,20 @@ public class ColumnMapper extends JPanel{
.addComponent(forbiddenMapper)
)
);
this.setLayout(layout);
//Initial call to get table values
updateValues();
}
public void updateValues() {
private void updateValues() {
CyNetwork net = CyCore.cy.getCurrentNetwork();
if (net != null) { //Check if a network is loaded
//Clear entries
editingCostMapper.removeAllItems();
for (CyColumn c : net.getDefaultEdgeTable().getColumns()){
......@@ -138,7 +161,7 @@ public class ColumnMapper extends JPanel{
useMappingCost.setSelected(false);
editingCostMapper.setEnabled(false);
}
forbiddenMapper.removeAllItems();
for (CyColumn c : net.getDefaultEdgeTable().getColumns()){
//Only add columns with boolean values
......@@ -152,7 +175,7 @@ public class ColumnMapper extends JPanel{
useMappingForb.setSelected(false);
forbiddenMapper.setEnabled(false);
}
permanentMapper.removeAllItems();
for (CyColumn c : net.getDefaultEdgeTable().getColumns()){
//Only add columns with boolean values
......@@ -166,24 +189,59 @@ public class ColumnMapper extends JPanel{
useMappingPerm.setSelected(false);
permanentMapper.setEnabled(false);
}
}
}
//LISTENER__IMPL//
@Override
public void handleEvent(SetCurrentNetworkEvent e) {
updateValues();
}
@Override
public void handleEvent(SessionLoadedEvent e) {
updateValues();
}
@Override
public void handleEvent(ColumnDeletedEvent e) {
if (
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultEdgeTable() ||
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNetworkTable()
)
{
updateValues();
}
}
@Override
public void handleEvent(ColumnCreatedEvent e) {
if (
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultEdgeTable() ||
e.getSource() == CyCore.cy.getCurrentNetwork().getDefaultNetworkTable()
)
{
updateValues();
}
}
public CyColumn getEditingCostColumn() {
if (useMappingCost.isSelected()) {
return editingCostMapper.getItemAt(editingCostMapper.getSelectedIndex());
}
return null;
}
public CyColumn getForbiddenColumn() {
if (useMappingForb.isSelected()) {
return forbiddenMapper.getItemAt(forbiddenMapper.getSelectedIndex());
}
return null;
}
public CyColumn getPermanentColumn() {
if (useMappingPerm.isSelected()) {
return permanentMapper.getItemAt(permanentMapper.getSelectedIndex());
......@@ -191,4 +249,6 @@ public class ColumnMapper extends JPanel{
return null;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment