/* | |
* Copyright (c) 2010 Mia-Software. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* Gabriel Barbier (Mia-Software) - initial API and implementation | |
*/ | |
package org.eclipse.gmt.modisco.infra.prefuse.examples.radialgraphview; | |
import java.awt.BorderLayout; | |
import java.awt.Color; | |
import java.awt.Dimension; | |
import java.awt.Font; | |
import java.awt.event.MouseEvent; | |
import javax.swing.BorderFactory; | |
import javax.swing.Box; | |
import javax.swing.BoxLayout; | |
import javax.swing.JPanel; | |
import javax.swing.SwingConstants; | |
import prefuse.Visualization; | |
import prefuse.controls.ControlAdapter; | |
import prefuse.data.Graph; | |
import prefuse.data.Table; | |
import prefuse.data.io.GraphMLReader; | |
import prefuse.data.query.SearchQueryBinding; | |
import prefuse.data.search.SearchTupleSet; | |
import prefuse.util.FontLib; | |
import prefuse.util.ui.JFastLabel; | |
import prefuse.util.ui.JSearchPanel; | |
import prefuse.util.ui.UILib; | |
import prefuse.visual.VisualItem; | |
public class RadialGraphViewUtils { | |
public static JPanel demo(String datafile, final String label) { | |
Graph g = null; | |
try { | |
g = new GraphMLReader().readGraph(datafile); | |
} catch ( Exception e ) { | |
e.printStackTrace(); | |
System.exit(1); | |
} | |
return demo(g, label); | |
} | |
public static JPanel demo(Graph g, final String label) { | |
// create a new radial tree view | |
final RadialGraphView gview = new RadialGraphView(g, label); | |
Visualization vis = gview.getVisualization(); | |
// create a search panel for the tree map | |
SearchQueryBinding sq = new SearchQueryBinding( | |
(Table)vis.getGroup(RadialGraphViewConstants.treeNodes), label, | |
(SearchTupleSet)vis.getGroup(Visualization.SEARCH_ITEMS)); | |
JSearchPanel search = sq.createSearchPanel(); | |
search.setShowResultCount(true); | |
search.setBorder(BorderFactory.createEmptyBorder(5,5,4,0)); | |
search.setFont(FontLib.getFont("Tahoma", Font.PLAIN, 11)); //$NON-NLS-1$ | |
final JFastLabel title = new JFastLabel(" "); //$NON-NLS-1$ | |
title.setPreferredSize(new Dimension(350, 20)); | |
title.setVerticalAlignment(SwingConstants.BOTTOM); | |
title.setBorder(BorderFactory.createEmptyBorder(3,0,0,0)); | |
title.setFont(FontLib.getFont("Tahoma", Font.PLAIN, 16)); //$NON-NLS-1$ | |
gview.addControlListener(new ControlAdapter() { | |
public void itemEntered(VisualItem item, MouseEvent e) { | |
if ( item.canGetString(label) ) | |
title.setText(item.getString(label)); | |
} | |
public void itemExited(VisualItem item, MouseEvent e) { | |
title.setText(null); | |
} | |
}); | |
Box box = new Box(BoxLayout.X_AXIS); | |
box.add(Box.createHorizontalStrut(10)); | |
box.add(title); | |
box.add(Box.createHorizontalGlue()); | |
box.add(search); | |
box.add(Box.createHorizontalStrut(3)); | |
JPanel panel = new JPanel(new BorderLayout()); | |
panel.add(gview, BorderLayout.CENTER); | |
panel.add(box, BorderLayout.SOUTH); | |
Color BACKGROUND = Color.WHITE; | |
Color FOREGROUND = Color.DARK_GRAY; | |
UILib.setColor(panel, BACKGROUND, FOREGROUND); | |
return panel; | |
} | |
} |