[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview ClassificationAttribute.java, 1
Status: Pre-Alpha
Brought to you by:
henryml
From: Nikolaj B. <nbr...@us...> - 2006-10-24 20:38:36
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8344/src/net/sourceforge/bprocessor/gui/attrview Modified Files: ClassificationAttribute.java GenericPanel.java Log Message: Changed the classification,to use the new classification model Index: GenericPanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** GenericPanel.java 11 Oct 2006 06:23:07 -0000 1.21 --- GenericPanel.java 24 Oct 2006 20:38:28 -0000 1.22 *************** *** 27,30 **** --- 27,31 ---- import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Camera; + import net.sourceforge.bprocessor.model.Classification; import net.sourceforge.bprocessor.model.Description; import net.sourceforge.bprocessor.model.Entity; *************** *** 182,186 **** }); where.add(new AttributeRow(ba)); ! } else if (a.getValue() instanceof String[]) { // Handles the classification ClassificationAttribute ca = new ClassificationAttribute(a); --- 183,187 ---- }); where.add(new AttributeRow(ba)); ! } else if (a.getValue() instanceof Classification) { // Handles the classification ClassificationAttribute ca = new ClassificationAttribute(a); *************** *** 270,274 **** this.ga = ga; this.add(ga); ! if (ga.attribute().isEditable() || ga instanceof LinkAttribute) { ga.addMouseListener(this); } --- 271,276 ---- this.ga = ga; this.add(ga); ! if (ga.attribute().isEditable() || ga instanceof LinkAttribute ! || ga instanceof ClassificationAttribute) { ga.addMouseListener(this); } *************** *** 317,327 **** */ public void update() { ! if (simpleUpdate) { simpleUpdate(); simpleUpdate = false; } else { complexUpdate(); ! } } /** * --- 319,331 ---- */ public void update() { ! complexUpdate(); ! /*if (simpleUpdate) { simpleUpdate(); simpleUpdate = false; } else { complexUpdate(); ! }*/ } + /** * Index: ClassificationAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/ClassificationAttribute.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ClassificationAttribute.java 26 Jun 2006 11:37:52 -0000 1.1 --- ClassificationAttribute.java 24 Oct 2006 20:38:28 -0000 1.2 *************** *** 9,25 **** import java.awt.Dimension; ! import java.awt.event.FocusEvent; ! import java.awt.event.FocusListener; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import javax.swing.Box; import javax.swing.BoxLayout; - import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import net.sourceforge.bprocessor.model.Attribute; /** --- 9,35 ---- import java.awt.Dimension; ! import java.awt.event.ActionEvent; ! import java.awt.event.ActionListener; ! import java.awt.event.KeyEvent; ! import java.awt.event.KeyListener; ! import java.awt.event.MouseEvent; ! import java.awt.event.MouseListener; import java.util.Iterator; import java.util.LinkedList; import java.util.List; + import java.util.StringTokenizer; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JComponent; import javax.swing.JLabel; + import javax.swing.JMenu; + import javax.swing.JMenuBar; + import javax.swing.JMenuItem; + import javax.swing.JTextField; import net.sourceforge.bprocessor.model.Attribute; + import net.sourceforge.bprocessor.model.Classification; + import net.sourceforge.bprocessor.model.Project; /** *************** *** 27,31 **** */ public class ClassificationAttribute extends GenericAttribute ! implements FocusListener { /** The listeners */ --- 37,41 ---- */ public class ClassificationAttribute extends GenericAttribute ! implements KeyListener, MouseListener, ActionListener { /** The listeners */ *************** *** 36,45 **** /** The component */ ! private JComponent component; /** The Label */ private JLabel label; ! --- 46,60 ---- /** The component */ ! private JComponent component1; ! ! /** The component */ ! private JComponent component2; /** The Label */ private JLabel label; ! /** The editor, when this EditableAttribute is being edited */ ! private JTextField editor; ! *************** *** 53,73 **** this.attribute = attribute; this.listeners = new LinkedList(); - - label = createLabel(attribute.getName()); - - Box header = Box.createHorizontalBox(); Box column = Box.createVerticalBox(); header.add(Box.createHorizontalStrut(7)); header.add(label); header.add(Box.createHorizontalGlue()); column.add(Box.createRigidArea(new Dimension(70, 3))); column.add(header); column.add(Box.createRigidArea(new Dimension(70, 3))); ! column.setMaximumSize(new Dimension(60, Short.MAX_VALUE)); this.add(column); - component = Box.createHorizontalBox(); - component.add(createValueLabel(attribute.getValue())); - this.add(component); - this.add(Box.createHorizontalGlue()); } --- 68,92 ---- this.attribute = attribute; this.listeners = new LinkedList(); Box column = Box.createVerticalBox(); + label = createLabel("Classification"); + component1 = Box.createHorizontalBox(); + component2 = Box.createHorizontalBox(); + if (attribute.getClassification() != null) { + component2.add(createValueLabel(attribute.getClassification().getFullId())); + } else { + component2.add(createValueLabel("None")); + } + Box header = Box.createHorizontalBox(); header.add(Box.createHorizontalStrut(7)); header.add(label); + header.add(component2); header.add(Box.createHorizontalGlue()); column.add(Box.createRigidArea(new Dimension(70, 3))); column.add(header); column.add(Box.createRigidArea(new Dimension(70, 3))); ! ! component1.add(createMenu(attribute.getValue())); ! column.add(component1); this.add(column); } *************** *** 85,88 **** --- 104,125 ---- /** + * Add a mouselisterner to the active elements in the ClassificationAttribute + * @param mouseListener the mouselistener + */ + public void addMouseListener(MouseListener mouseListener) { + label.addMouseListener(mouseListener); + component2.addMouseListener(mouseListener); + } + + /** + * Remove a mouselisterner to the active elements in the ClassificationAttribute + * @param mouseListener the mouselistener + */ + public void removeMouseListener(MouseListener mouseListener) { + label.removeMouseListener(mouseListener); + component2.removeMouseListener(mouseListener); + } + + /** * Add a listener that are notified when the value is changed * @param listener The listener *************** *** 116,127 **** * @return The label */ ! private JComponent createValueLabel(Object value) { ! JComboBox valueLabel; ! valueLabel = new JComboBox((String[]) value); if (attribute.getClassification() != null) { ! valueLabel.setSelectedItem(attribute.getClassification()); } valueLabel.addFocusListener(this); return valueLabel; } --- 153,209 ---- * @return The label */ ! private JComponent createMenu(Object value) { ! JMenuBar valueLabel = new JMenuBar(); ! JMenu menu, subMenu; ! MyMenuItem mi, submi; ! boolean hasChildren = false; if (attribute.getClassification() != null) { ! menu = new JMenu(attribute.getClassification().getName()); ! } else { ! menu = new JMenu("Classification"); ! } ! Iterator it = ((Classification) value).getChildren().iterator(); ! while (it.hasNext()) { ! Classification current = (Classification) it.next(); ! if (current.getChildren() != null) { ! hasChildren = true; ! } ! if (hasChildren) { ! Iterator subit = current.getChildren().iterator(); ! subMenu = new JMenu(current.getName()); ! submi = new MyMenuItem(current); ! submi.addActionListener(this); ! subMenu.add(submi); ! while (subit.hasNext()) { ! Classification subcur = (Classification) subit.next(); ! submi = new MyMenuItem(subcur); ! submi.addActionListener(this); ! subMenu.add(submi); ! } ! menu.add(subMenu); ! } else { ! mi = new MyMenuItem(current); ! mi.addActionListener(this); ! menu.add(mi); ! } } + valueLabel.add(menu); + return valueLabel; + + /* + JComboBox valueLabel; + valueLabel = new JComboBox(((Classification) value).getChildren()); + JMenu childs = new JMenu("Children"); + JMenuItem child = new JMenuItem("hat"); + childs.add(child); + child = new JMenuItem("hus"); + childs.add(child); + valueLabel.add(childs); + if (attribute.getClassification() != null) { + valueLabel.setSelectedItem(attribute.getClassification()); + } valueLabel.addFocusListener(this); return valueLabel; + */ } *************** *** 136,182 **** } - /** ! * Not in use ! * @param event The FocusEvent */ ! public void focusGained(FocusEvent event) { ! // TODO Auto-generated method stub ! } ! /** ! * Stop editing on the combobox ! * @param event The event */ ! public void focusLost(FocusEvent event) { ! attribute.setValue(((JComboBox) event.getSource()).getSelectedItem()); ! valueChanged(); } ! /** ! * Not in use */ public void startEditing() { ! // TODO Auto-generated method stub } ! /** ! * Not in use */ public void stopEditing() { ! // TODO Auto-generated method stub ! } ! /** ! * Not in use */ public void cancelEditing() { ! // TODO Auto-generated method stub } } --- 218,420 ---- } /** ! * Create a value label ! * @param value The value ! * @return The label */ ! private JComponent createValueLabel(Object value) { ! String s = ""; ! JLabel valueLabel; ! if (value instanceof String) { ! s = (String)value; ! } ! valueLabel = new JLabel(s); ! if (attribute.isEditable()) { ! valueLabel.setFont(AttributeView.FONT_PLAIN); ! } else { ! valueLabel.setFont(AttributeView.FONT_ITALIC); ! } ! return valueLabel; } ! /** ! * Create a value editor ! * @param value The value ! * @return The editor */ ! private JComponent createValueEditor(Object value) { ! String s = ""; ! if (value instanceof String) { ! s = (String)value; ! } ! JTextField valueEditor = new JTextField(s); ! valueEditor.setFont(AttributeView.FONT_PLAIN); + return valueEditor; } ! ! /** ! * Start editing the value by replacing the label with an editor */ public void startEditing() { ! if (editor == null) { ! component2.remove(0); ! if (attribute.getClassification() != null) { ! editor = (JTextField) createValueEditor(attribute.getClassification().getFullId()); ! } else { ! editor = (JTextField) createValueEditor(""); ! } ! editor.addKeyListener(this); ! component2.add(editor); ! component2.revalidate(); ! } ! editor.requestFocus(); ! editor.selectAll(); } ! /** ! * Stop editing the value by replacing the editor with an label, ! * and sending valueChanged to all listeners. */ public void stopEditing() { ! if (editor != null) { ! Object val = attribute.getValue(); ! String id = editor.getText(); ! StringTokenizer st = new StringTokenizer(id, "."); ! Classification clas = Project.getInstance().getClassification(); ! String curid; ! while (st.hasMoreTokens()) { ! curid = st.nextToken(); ! Iterator it = clas.getChildren().iterator(); ! while (it.hasNext()) { ! Classification current = (Classification) it.next(); ! if (curid.equalsIgnoreCase(current.getId().toString())) { ! clas = current; ! } ! } ! } ! attribute.setValue(clas); ! ! component2.remove(editor); ! editor.removeKeyListener(this); ! editor = null; ! component2.add(createValueLabel(clas.getFullId())); ! component2.revalidate(); ! valueChanged(); ! } } ! /** ! * Cancels editing the value by replacing the editor with an label, ! * without sending any events to listeners. */ public void cancelEditing() { ! if (editor != null) { ! component2.remove(editor); ! editor.removeKeyListener(this); ! editor = null; ! component2.add(createValueLabel(attribute.getValue())); ! component2.revalidate(); ! } ! } ! ! /** ! * Respond to the enter key by stopping editing. ! * @param event The KeyEvent ! */ ! public void keyPressed(KeyEvent event) { ! if (event.getKeyCode() == KeyEvent.VK_ENTER) { ! stopEditing(); ! } else if (event.getKeyCode() == KeyEvent.VK_ESCAPE) { ! cancelEditing(); ! } ! } ! ! /** ! * Not in use ! * @param event The KeyEvent ! */ ! public void keyTyped(KeyEvent event) { } ! /** ! * Not in use ! * @param event The KeyEvent ! */ ! public void keyReleased(KeyEvent event) { } ! ! /** ! * Start editing on the view ! * @param event The event ! */ ! public void mouseClicked(MouseEvent event) { ! startEditing(); ! } ! ! /** ! * Not in use ! * @param event The MouseEvent ! */ ! public void mousePressed(MouseEvent event) { } ! /** ! * Not in use ! * @param event The MouseEvent ! */ ! public void mouseReleased(MouseEvent event) { } ! /** ! * Not in use ! * @param event The MouseEvent ! */ ! public void mouseEntered(MouseEvent event) { } ! /** ! * Not in use ! * @param event The MouseEvent ! */ ! public void mouseExited(MouseEvent event) { } ! ! /** ! * Handles the event from the classification menu ! * @param e is the action event ! */ ! public void actionPerformed(ActionEvent e) { ! MyMenuItem source = (MyMenuItem)(e.getSource()); ! attribute.setValue(source.getClassification()); ! valueChanged(); ! } ! ! /** ! * extended version of JMenuItem that also contains a classification ! */ ! class MyMenuItem extends JMenuItem { ! ! /** the classification */ ! private Classification cla; ! ! /** ! * Constructor for a new MyMenuItem ! * @param classification the classification ! */ ! MyMenuItem(Classification classification) { ! super(classification.getName()); ! setClassification(classification); ! } ! ! /** ! * return the classification for the current menu item ! * @return the classification ! */ ! public Classification getClassification() { ! return cla; ! } + /** + * Sets the classification for a menu item + * @param cla the classification + */ + public void setClassification(Classification cla) { + this.cla = cla; + } } + } |