[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview AttributeView.java,NONE,1.1 pack
Status: Pre-Alpha
Brought to you by:
henryml
From: Jesper P. <je...@us...> - 2005-07-01 06:43:47
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26505 Added Files: AttributeView.java package.html Log Message: Initial import --- NEW FILE: package.html --- <body> This package defines functionality to show attributes for an object </body> --- NEW FILE: AttributeView.java --- //--------------------------------------------------------------------------------- // $Id: AttributeView.java,v 1.1 2005/07/01 06:43:38 jews 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.attrview; import net.sourceforge.bprocessor.kernel.notification.Notification; import net.sourceforge.bprocessor.kernel.notification.NotificationListener; import net.sourceforge.bprocessor.kernel.notification.Notifier; import net.sourceforge.bprocessor.model.ConstructionSpaceFacade; import net.sourceforge.bprocessor.model.Domain; import net.sourceforge.bprocessor.model.FunctionalSpaceFacade; import java.awt.GridLayout; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import org.apache.log4j.Logger; /** * The attribute view */ public class AttributeView extends JTabbedPane implements NotificationListener { /** The logger */ private static Logger log = Logger.getLogger(AttributeView.class); /** The attributes panel */ private AttributesPanel ap; /** Current object */ private Domain current; /** * Constructor */ public AttributeView() { super(); ap = new AttributesPanel(); addTab("Attributes", ap); current = null; Notifier.getInstance().addListener(this); } /** * Handle a notification * @param n The notification */ public void handleNotification(Notification n) { if (log.isDebugEnabled()) { log.debug(n); } String type = n.getType(); if (type.equals(Notification.FUNCTIONAL_SPACE_SELECTED)) { FunctionalSpaceFacade fsf = FunctionalSpaceFacade.getInstance(); current = fsf.findById(n.getObject()); ap.display(current); repaint(); } else if (type.equals(Notification.CONSTRUCTION_SPACE_SELECTED)) { ConstructionSpaceFacade csf = ConstructionSpaceFacade.getInstance(); current = csf.findById(n.getObject()); ap.display(current); repaint(); } } /** * Should the listener handle this notification * @param type The notification type * @return True if it should handle it; otherwise false */ public boolean isNotificationEnabled(String type) { if (type.equals(Notification.FUNCTIONAL_SPACE_SELECTED) || type.equals(Notification.CONSTRUCTION_SPACE_SELECTED)) { return true; } return false; } /** * Attributes panel */ class AttributesPanel extends JPanel { /** Current domain */ private Domain current; /** * Constructor */ AttributesPanel() { current = null; } /** * Display the domain * @param d The domain */ void display(Domain d) { current = d; List names = new ArrayList(); List components = new ArrayList(); Method[] methods = d.getClass().getMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; String name = m.getName(); if (name.startsWith("get")) { if (!name.endsWith("Id") && !name.endsWith("Class")) { if (returnTypeSupported(m.getReturnType())) { try { components.add(new JLabel(m.invoke(d, (Object[])null).toString())); if (name.length() > 4) { names.add(new JLabel(name.substring(3, 4).toUpperCase() + name.substring(4))); } else { names.add(new JLabel(name.substring(3, 4).toUpperCase())); } } catch (Exception e) { // Cant be accessed } } } } } removeAll(); setLayout(new GridLayout(names.size(), 2)); for (int i = 0; i < names.size(); i++) { add((JLabel)names.get(i)); add((JLabel)components.get(i)); } } /** * Return type supported * @param c The class for the return type * @return True if supported; otherwise false */ private boolean returnTypeSupported(Class c) { String n = c.getName(); if (n.equals("java.lang.String") || n.equals("java.lang.Integer") || n.equals("java.lang.Double") || n.equals("java.lang.Float") || n.equals("java.lang.Short") || n.equals("java.lang.Boolean") || n.equals("java.lang.Byte") || n.equals("java.lang.Long") || n.equals(Integer.TYPE.getName()) || n.equals(Double.TYPE.getName()) || n.equals(Float.TYPE.getName()) || n.equals(Short.TYPE.getName()) || n.equals(Boolean.TYPE.getName()) || n.equals(Byte.TYPE.getName()) || n.equals(Long.TYPE.getName())) { return true; } return false; } } } |