[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview MyKeyListener.java,NONE,1.1 Attr
Status: Pre-Alpha
Brought to you by:
henryml
From: Nikolaj B. <nbr...@us...> - 2005-11-21 09:52:28
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32657/src/net/sourceforge/bprocessor/gui/attrview Modified Files: AttributeView.java Added Files: MyKeyListener.java Log Message: Added functionality, and editing option of spacenames --- NEW FILE: MyKeyListener.java --- //--------------------------------------------------------------------------------- // $Id: MyKeyListener.java,v 1.1 2005/11/21 09:52:17 nbramsen 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 java.awt.event.KeyListener; import java.awt.event.KeyEvent; import javax.swing.text.JTextComponent; import net.sourceforge.bprocessor.model.FunctionalSpace; import net.sourceforge.bprocessor.model.ConstructionSpace; import net.sourceforge.bprocessor.model.Project; /** * The focus handler */ public class MyKeyListener implements KeyListener { /** The current ConstructionSpace */ private ConstructionSpace cons; /** The current FunctionalSpace */ private FunctionalSpace funs; /** The current Object */ private Object current; /** * The constructor * @param o the event */ public MyKeyListener (Object o) { current = o; } /** * Handles keyTyped keyevent * @param e the event */ public void keyTyped(KeyEvent e) { } /** * Handles the keyReleased keyevent * @param e the keyevent */ public void keyReleased(KeyEvent e) { } /** * Handles focus event * @param e the event */ public void keyPressed(KeyEvent e) { int keyPressed = e.getKeyCode(); if (keyPressed == KeyEvent.VK_ENTER) { JTextComponent tf = (JTextComponent)e.getSource(); String newName = tf.getText(); if (current instanceof FunctionalSpace) { funs = (FunctionalSpace)current; funs.setName(newName); Project.getInstance().update(funs); } if (current instanceof ConstructionSpace) { cons = (ConstructionSpace)current; cons.setName(newName); Project.getInstance().update(cons); } } } } Index: AttributeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/AttributeView.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** AttributeView.java 20 Nov 2005 19:32:37 -0000 1.8 --- AttributeView.java 21 Nov 2005 09:52:17 -0000 1.9 *************** *** 22,29 **** --- 22,33 ---- import java.util.ArrayList; import java.util.List; + import java.awt.GridBagLayout; + import java.awt.GridBagConstraints; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; + import javax.swing.JTextField; + import javax.swing.JComboBox; import org.apache.log4j.Logger; *************** *** 64,71 **** if (type.equals(Notification.FUNCTIONAL_SPACE_SELECTED)) { FunctionalSpace current = Project.getInstance().findFunctionalSpaceById(n.getObject()); ! ap.display(current); } else if (type.equals(Notification.CONSTRUCTION_SPACE_SELECTED)) { ConstructionSpace current = Project.getInstance().findConstructionSpaceById(n.getObject()); ! ap.display(current); } else if (type.equals(Notification.ELEMENT_SELECTED)) { Element current = Project.getInstance().findElementById(n.getObject()); --- 68,75 ---- if (type.equals(Notification.FUNCTIONAL_SPACE_SELECTED)) { FunctionalSpace current = Project.getInstance().findFunctionalSpaceById(n.getObject()); ! ap.displayFuncSpace(current); } else if (type.equals(Notification.CONSTRUCTION_SPACE_SELECTED)) { ConstructionSpace current = Project.getInstance().findConstructionSpaceById(n.getObject()); ! ap.displayConsSpace(current); } else if (type.equals(Notification.ELEMENT_SELECTED)) { Element current = Project.getInstance().findElementById(n.getObject()); *************** *** 76,80 **** } else if (type.equals(Notification.SURFACE_SELECTED)) { Surface current = Project.getInstance().findSurfaceById(n.getObject()); ! ap.display(current); } else if (type.equals(Notification.FUNCTIONAL_SPACE_DESELECTED) || type.equals(Notification.CONSTRUCTION_SPACE_DESELECTED) || --- 80,84 ---- } else if (type.equals(Notification.SURFACE_SELECTED)) { Surface current = Project.getInstance().findSurfaceById(n.getObject()); ! ap.displaySurface(current); } else if (type.equals(Notification.FUNCTIONAL_SPACE_DESELECTED) || type.equals(Notification.CONSTRUCTION_SPACE_DESELECTED) || *************** *** 125,128 **** --- 129,208 ---- /** + * Display the functional space + * @param o The object + */ + void displayFuncSpace(FunctionalSpace o) { + removeAll(); + + GridBagLayout layout = new GridBagLayout(); + GridBagConstraints con = new GridBagConstraints(); + setLayout(layout); + + JLabel name = new JLabel("Name:"); + con.anchor = GridBagConstraints.PAGE_START; + con.weightx = 1.0; + layout.setConstraints(name, con); + add(name); + + JTextField nameEdit = new JTextField(o.getName(), 10); + con.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(nameEdit, con); + add(nameEdit); + nameEdit.addKeyListener(new MyKeyListener(o)); + + Object[] options = {"Arbejdsværelse", "Badeværelse", "Gang", "Køkken", "Stue", "Værelse"}; + JComboBox klassifikation = new JComboBox(options); + con.weightx = 0.0; + layout.setConstraints(klassifikation, con); + add(klassifikation); + } + + /** + * Display the construction space + * @param o The object + */ + void displayConsSpace(ConstructionSpace o) { + removeAll(); + + GridBagLayout layout = new GridBagLayout(); + GridBagConstraints con = new GridBagConstraints(); + setLayout(layout); + + JLabel name = new JLabel("Name:"); + con.anchor = GridBagConstraints.NORTH; + con.weightx = 1.0; + layout.setConstraints(name, con); + add(name); + JTextField nameEdit = new JTextField(o.getName(), 10); + nameEdit.addKeyListener(new MyKeyListener(o)); + con.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(nameEdit, con); + add(nameEdit); + } + + /** + * Display the surface + * @param o The object + */ + void displaySurface(Surface o) { + removeAll(); + + GridBagLayout layout = new GridBagLayout(); + GridBagConstraints con = new GridBagConstraints(); + setLayout(layout); + + JLabel name = new JLabel("Name:"); + con.anchor = GridBagConstraints.NORTH; + con.weightx = 1.0; + layout.setConstraints(name, con); + add(name); + + JLabel surfaceName = new JLabel(o.getName()); + con.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(surfaceName, con); + add(surfaceName); + } + + /** * Display the object * @param o The object |