Select Git revision
ClusterView.java
-
Philipp Spohr authored
Various small fixes / stuff
Philipp Spohr authoredVarious small fixes / stuff
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ClusterView.java 3.67 KiB
/*******************************************************************************
* 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.gui;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import org.cytoscape.model.CyNode;
import org.cytoscape.util.swing.BasicCollapsiblePanel;
import de.hhu.ba.yoshikoWrapper.core.GraphicsLoader;
import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster;
@SuppressWarnings("serial")
public class ClusterView extends JPanel {
private final JLabel title;
private final JLabel clusterSize;
private final JLabel icon;
private final BasicCollapsiblePanel nodeList;
private final Border regularBorder = BorderFactory.createLineBorder(Color.GRAY,3);
private final Border highlightBorder = BorderFactory.createLineBorder(GraphicsLoader.yoshikoGreen,3);
//SYMBOLIC LINKS
/**Simple array list containing references to the nodes that are represented by this cluster view
*
*/
private YoshikoCluster cluster;
public ClusterView(YoshikoCluster c) {
this.cluster = c;
//Swing init
this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
title = new JLabel(LocalizationManager.get("cluster")+" "+(c.getID()+1));
clusterSize = new JLabel(LocalizationManager.get("clusterSize")+" "+c.getSize());
icon = new JLabel();
icon.setBorder(BorderFactory.createLineBorder(Color.BLACK));
cluster.generateImage(icon,128, 128);
SwingUtil.addAll(this,title,clusterSize,icon);
this.add(Box.createVerticalStrut(4));
nodeList = new BasicCollapsiblePanel(LocalizationManager.get("nodes"));
//Loop over nodes in the cluster and add them to the view
for (CyNode n : c.getSubNetwork().getNodeList()) {
nodeList.add(
new JLabel(
c.getNodeName(n)
)
);
}
this.add(nodeList);
this.addMouseListener(mouseListener);
this.setBorder(regularBorder);
}
private MouseListener mouseListener = new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {}
@Override
public void mousePressed(MouseEvent e) {
cluster.select();
}
@Override
public void mouseReleased(MouseEvent e) {}
@Override
public void mouseEntered(MouseEvent e) {
setBorder(highlightBorder);
}
@Override
public void mouseExited(MouseEvent e) {
setBorder(regularBorder);
}
};
}