aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes opening a window on mouse over Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "opening a window on mouse over" Watch "opening a window on mouse over" New topic
Author

opening a window on mouse over

Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
i have developed a tree through swing.Now i want to open a window in the same frame which details that node.(it doesnot matter if its a pop-up or a
new Jframe.(please explain in details kindly.)


here is the code :-



package edu.berkeley.guir.prefuse.demos;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Image;
import java.awt.Paint;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.net.URL;
import java.util.Iterator;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

//import org.apache.bcel.generic.NEW;



import myExtension.MyFocusListener;
import myExtension.MyNodeShape;
import myExtension.MyTreeApplet;

import edu.berkeley.guir.prefuse.AggregateItem;
import edu.berkeley.guir.prefuse.Display;
import edu.berkeley.guir.prefuse.EdgeItem;
import edu.berkeley.guir.prefuse.FocusManager;
import edu.berkeley.guir.prefuse.ItemRegistry;
import edu.berkeley.guir.prefuse.NodeItem;
import edu.berkeley.guir.prefuse.VisualItem;
import edu.berkeley.guir.prefuse.action.ActionSwitch;
import edu.berkeley.guir.prefuse.action.RepaintAction;
import edu.berkeley.guir.prefuse.action.animate.ColorAnimator;
import edu.berkeley.guir.prefuse.action.animate.FontAnimator;
import edu.berkeley.guir.prefuse.action.animate.LocationAnimator;
import edu.berkeley.guir.prefuse.action.animate.PolarLocationAnimator;
import edu.berkeley.guir.prefuse.action.animate.SizeAnimator;
import edu.berkeley.guir.prefuse.action.assignment.ColorFunction;
import edu.berkeley.guir.prefuse.action.filter.TreeEdgeFilter;
import edu.berkeley.guir.prefuse.action.filter.TreeFilter;
import edu.berkeley.guir.prefuse.action.filter.WindowedTreeFilter;
import edu.berkeley.guir.prefuse.activity.ActionList;
import edu.berkeley.guir.prefuse.activity.SlowInSlowOutPacer;
import edu.berkeley.guir.prefuse.activity.ThereAndBackPacer;
import edu.berkeley.guir.prefuse.event.FocusEvent;
import edu.berkeley.guir.prefuse.event.FocusListener;
import edu.berkeley.guir.prefuse.focus.DefaultFocusSet;
import edu.berkeley.guir.prefuse.graph.DefaultTreeNode;
import edu.berkeley.guir.prefuse.graph.Graph;
import edu.berkeley.guir.prefuse.graph.Tree;
import edu.berkeley.guir.prefuse.graph.TreeNode;
import edu.berkeley.guir.prefuse.graph.external.DatabaseLoader;
import edu.berkeley.guir.prefuse.graph.io.TabDelimitedTreeReader;
import edu.berkeley.guir.prefuse.graph.io.XMLGraphReader;
import edu.berkeley.guir.prefuse.render.DefaultEdgeRenderer;
import edu.berkeley.guir.prefuse.render.DefaultNodeRenderer;
import edu.berkeley.guir.prefuse.render.DefaultRendererFactory;
import edu.berkeley.guir.prefuse.render.ImageFactory;
import edu.berkeley.guir.prefuse.render.PolygonRenderer;
import edu.berkeley.guir.prefuse.render.Renderer;
import edu.berkeley.guir.prefuse.render.ShapeRenderer;
import edu.berkeley.guir.prefuse.render.TextImageItemRenderer;
import edu.berkeley.guir.prefuse.render.TextItemRenderer;
import edu.berkeley.guir.prefuse.util.ColorMap;
import edu.berkeley.guir.prefuse.util.StringAbbreviator;
import edu.berkeley.guir.prefusex.controls.DragControl;
import edu.berkeley.guir.prefusex.controls.FocusControl;
import edu.berkeley.guir.prefusex.controls.NeighborHighlightControl;
import edu.berkeley.guir.prefusex.controls.PanControl;
import edu.berkeley.guir.prefusex.controls.RotationControl;
import edu.berkeley.guir.prefusex.controls.SubtreeDragControl;
import edu.berkeley.guir.prefusex.controls.ToolTipControl;
import edu.berkeley.guir.prefusex.controls.ZoomControl;
import edu.berkeley.guir.prefusex.controls.ZoomingPanControl;
import edu.berkeley.guir.prefusex.layout.IndentedTreeLayout;
import edu.berkeley.guir.prefusex.layout.RadialTreeLayout;
import edu.berkeley.guir.prefusex.layout.TopDownTreeLayout;
import edu.berkeley.guir.prefusex.layout.VerticalTreeLayout;

/**
* Demo application showcasing the use of an animated radial tree layout to
* visualize a graph. This is a re-implementation of <a
* href="http://zesty.ca/pubs/yee-gtv-infovis2001.pdf">Ping Yee et al.'s
* Animated Exploration of Dynamic Graphs with Radial Layout</a>.
*
* @version 1.0
* @author <a href="http://jheer.org">Jeffrey Heer</a> prefuse(AT)jheer.org
*/
public class MyTreeTest extends JFrame implements HyperlinkListener , FocusListener{

public static final String GRAPH_GUIR = "C:/eclipse/workspace/PREFUSE/Demos/etc/myData.xml";
public static final String GRAPH_FRIENDSTER = "C:/eclipse/workspace/PREFUSE/Demos/etc/friendster.xml";
public static final String GRAPH_TERROR = "C:/eclipse/workspace/PREFUSE/Demos/etc/terror.xml";
public static final String nameField = "label";




public static void main(String[] argv) {
new RadialGraphDemo();
} //

public MyTreeTest() {
super("RadialLayout Demo");
try {

String str ="LABEL\tPARENTLABEL\tSCORE" +
"\nTSA\tParent"+
"\nHealth and Insurance\tOrganization And Maintenance\t-999.0"+
"\nITMS\tOrganization And Maintenance\t-999.0"+
"\nProjects\tTSA\t-999.0"+
"\nFixed Infrastructure\tOrganization And Maintenance\t87.94"+
"\nLife Insurance\tOrganization And Maintenance\t-999.0"+
"\nSecurity Investigation\tSecurity\t-999.0"+
"\nSecurity\tTSA\t-999.0"+
"\nOrganization And Maintenance\tTSA\t87.94"+
"\nOM-AVL-11\tFixed Infrastructure\t89.04"+
"\nOM-AVL-13\tFixed Infrastructure\t-999.0";

InputStream is = new StringBufferInputStream(str);

TabDelimitedTreeReader treeReader = new TabDelimitedTreeReader();

String inputFile = GRAPH_GUIR;
XMLGraphReader gr = new XMLGraphReader();
gr.setNodeType(DefaultTreeNode.class);
//Graph graph = gr.loadGraph(inputFile);
Tree graph = treeReader.loadTree(is);

//AggregateItem aggItem = new AggregateItem();

Iterator nodeIterator = graph.getNodes();

while(nodeIterator.hasNext()){
TreeNode node = (DefaultTreeNode)nodeIterator.next();
//System.out.println("NODE ATTIBUTES : "+node.getAttributes());
node.setAttribute("image","C:/eclipse/workspace/PREFUSE/src/myExtension/RedEventBig.jpg");

if(node.getAttribute("LABE").equalsIgnoreCase("Security")){
// aggItem.setAsChild(node);
}

}



// create display and filter
ItemRegistry registry = new ItemRegistry(graph);
System.out.println("REGISTRY OBJECT IS "+registry);
Display display = new Display();



Iterator iterator = registry.getItems();
while(iterator.hasNext()){
VisualItem item = (VisualItem)iterator.next();
//nodeRenderer.getShape(item);

}

// initialize renderers
TextItemRenderer nodeRenderer = new TextItemRenderer();
nodeRenderer.setTextAttributeName("LABE");
nodeRenderer.setMaxTextWidth(175);
//System.out.println("SHAPE IS "+nodeRenderer.getShape());
//nodeRenderer.setAbbrevType(StringAbbreviator.NAME);
//nodeRenderer.setRoundedCorner(2,2);

Renderer edgeRenderer = new DefaultEdgeRenderer();

registry.setRendererFactory(new DefaultRendererFactory(nodeRenderer, edgeRenderer));

// initialize action pipelines
ActionList layout = new ActionList(registry);
//layout.add(new TreeFilter(true));
layout.add(new TreeFilter(true));
layout.add(new VerticalTreeLayout());
layout.add(new DemoColorFunction(3));

ActionList update = new ActionList(registry);
update.add(new DemoColorFunction(3));
update.add(new RepaintAction());
//update.add(new ActionSwitch());

ActionList animate = new ActionList(registry, 1000, 10);
animate.setPacingFunction(new SlowInSlowOutPacer());
//animate.add(new PolarLocationAnimator());
//animate.add(new ColorAnimator());
animate.add(new RepaintAction());
animate.add(new LocationAnimator());
animate.add(new FontAnimator());
animate.alwaysRunAfter(layout);

// initialize display
display.setItemRegistry(registry);
display.setSize(1100,700);
display.setBackground(Color.WHITE);
//display.addControlListener(new MyTreeApplet());
//display.addFocusListener(new MyFocusListener());
display.addControlListener(new FocusControl(layout));
display.addControlListener(new FocusControl(1,FocusManager.DEFAULT_KEY));
display.addControlListener(new DragControl());
display.addControlListener(new PanControl());
display.addControlListener(new ZoomControl());
//display.addControlListener(new ToolTipControl());
//display.addControlListener(new NeighborHighlightControl(update));
display.setUseCustomTooltips(true);
display.addControlListener(new ToolTipControl("ObjectName"));
//display.addControlListener(new ZoomingPanControl());
//display.addControlListener(new SubtreeDragControl());
//display.addControlListener(new RotationControl());

Display overview = new Display(registry);

overview.setBorder(BorderFactory.createLineBorder(Color.RED, 1));
overview.setSize(250,250);
overview.zoom(new Point2D.Float(0,0),0.1);
//display.add(overview);

registry.getFocusManager().putFocusSet(
FocusManager.HOVER_KEY, new DefaultFocusSet());

// create and display application window
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add(display, BorderLayout.CENTER);
pack();
setVisible(true);

// run filter+layout, and perform initial animation
layout.runNow();
} catch ( Exception e ) {
e.printStackTrace();
}
} //

/*public class MouseOverEvents extends MouseAdapter {

public void mouseEntered(MouseEvent e) {
(TreeNode)e.get("TreeNode");
repaint();
}

}*/

public class DemoColorFunction extends ColorFunction {
private Color graphEdgeColor = Color.LIGHT_GRAY;
private Color highlightColor = new Color(50,50,255);
private Color focusColor = new Color(255,50,50);
private Color lightGray = new Color(220,220,255);
private ColorMap colorMap;

public DemoColorFunction(int thresh) {
colorMap = new ColorMap(
ColorMap.getInterpolatedMap(thresh+1, Color.RED, Color.BLACK),
0, thresh);
} //



public Paint getFillColor(VisualItem item) {
if ( item instanceof NodeItem ) {
Color pastelRed = new Color(255,125,125);
return lightGray;
} else if ( item instanceof AggregateItem ) {
return Color.LIGHT_GRAY;
} else if ( item instanceof EdgeItem ) {
return getColor(item);
} else {
return Color.BLACK;
}
} //

public Paint getColor(VisualItem item) {
if ( item.isFocus() ) {
return focusColor;
} else if ( item.isHighlighted() ) {
return highlightColor;
} else if (item instanceof NodeItem) {
int d = ((NodeItem)item).getDepth();
return colorMap.getColor(d);
} else if (item instanceof EdgeItem) {
EdgeItem e = (EdgeItem) item;
if ( e.isTreeEdge() ) {
int d, d1, d2;
d1 = ((NodeItem)e.getFirstNode()).getDepth();
d2 = ((NodeItem)e.getSecondNode()).getDepth();
d = Math.max(d1, d2);
return colorMap.getColor(d);
} else {
return graphEdgeColor;
}
} else {
return Color.BLACK;
}
} //
} // end of inner class DemoColorFunction

/* (non-Javadoc)
* @see javax.swing.event.HyperlinkListener#hyperlinkUpdate(javax.swing.event.HyperlinkEvent)
*/
public void hyperlinkUpdate(HyperlinkEvent event) {
System.out.println("THIS IS IN HYPERLINK UPDATE ");

}

/* (non-Javadoc)
* @see edu.berkeley.guir.prefuse.event.FocusListener#focusChanged(edu.berkeley.guir.prefuse.event.FocusEvent)
*/
public void focusChanged(FocusEvent e) {
System.out.println("INSIDE FOCUS LISTENER");
}

} // end of classs RadialGraphDemo
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: opening a window on mouse over
 
Similar Threads
ClassCastException while casting to XMLTreeNode(JTree from XML)
Getting a couple errors on scribble applet
filtering N number of leaf nodes per parent node
How to navigate between multiple GUI classes
converting a string color to an object color