Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attributesview
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20921/src/net/sourceforge/bprocessor/gui/attributesview
Added Files:
AttributeExample.java
Log Message:
Example of using AttributesPanel
--- NEW FILE: AttributeExample.java ---
//---------------------------------------------------------------------------------
// $Id: AttributeExample.java,v 1.1 2006/01/05 13:35:32 henryml Exp $
//
// Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net)
// Released under the Lesser GNU Public License v2.1
//---------------------------------------------------------------------------------
package net.sourceforge.bprocessor.gui.attributesview;
import java.awt.BorderLayout;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* An example of using AttributesPanel
*/
public class AttributeExample extends JFrame {
/**
* Constructor
*/
public AttributeExample() {
super();
this.setTitle("Attribute Panel");
HashMap map = new HashMap();
List keys = new LinkedList();
keys.add("x");
keys.add("y");
keys.add("z");
keys.add("rotation");
keys.add("label");
map.put("x", "1.0000");
map.put("y", "2.0000");
map.put("z", "0.7500");
map.put("rotation", "90");
map.put("label", "Vertex 1");
AttributesPanel attributeView = new AttributesPanel();
attributeView.setAttributes(build(keys, map));
this.getContentPane().add(attributeView, BorderLayout.NORTH);
this.getContentPane().add(new JPanel(), BorderLayout.CENTER);
this.pack();
this.setVisible(true);
}
/**
* Build a list of AttributeView using the values in the map
* @param keys Specifies the order of the keys
* @param map Specifies the values
* @return A list of AttributeView
*/
List build(List keys, HashMap map) {
List attributes = new LinkedList();
Iterator iter = keys.iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
String value = (String) map.get(key);
StringAttributeView current = new StringAttributeView(key, value);
current.addStringAttributeListener(
new StringAttributeListener() {
public void valueChanged(String name, String value) {
System.out.println(name + " = " + value);
}
}
);
attributes.add(current);
}
return attributes;
}
/**
* Main
* @param args Arguments
*/
public static void main(String[] args) {
new AttributeExample();
}
}
|