Thread: [Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview AttributeView.java,1.32,1.33 Att
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-02-09 13:55:21
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20192/src/net/sourceforge/bprocessor/gui/attrview Modified Files: AttributeView.java AttributePanel.java StringAttribute.java GenericPanel.java Log Message: Changes to the attribute view so that it now are able to show attributes more general Index: StringAttribute.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/StringAttribute.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StringAttribute.java 3 Feb 2006 20:11:45 -0000 1.2 --- StringAttribute.java 9 Feb 2006 13:55:12 -0000 1.3 *************** *** 19,22 **** --- 19,23 ---- import javax.swing.Box; import javax.swing.BoxLayout; + import javax.swing.DebugGraphics; import javax.swing.JComponent; import javax.swing.JLabel; *************** *** 70,75 **** this.add(component); this.add(Box.createHorizontalGlue()); ! label.addMouseListener(this); ! component.addMouseListener(this); } --- 71,78 ---- this.add(component); this.add(Box.createHorizontalGlue()); ! if (attribute.isEditable()) { ! label.addMouseListener(this); ! component.addMouseListener(this); ! } } *************** *** 81,85 **** private JLabel createLabel(String key) { JLabel keyLabel = new JLabel(key + " :"); ! keyLabel.setFont(AttributePanel.FONT_BOLD); return keyLabel; } --- 84,88 ---- private JLabel createLabel(String key) { JLabel keyLabel = new JLabel(key + " :"); ! keyLabel.setFont(AttributeView.FONT_BOLD); return keyLabel; } *************** *** 140,147 **** s = (String)value; } else if (value instanceof Double) { ! s = ((Double) value).toString(); } JLabel valueLabel = new JLabel(s); ! valueLabel.setFont(AttributePanel.FONT_PLAIN); return valueLabel; } --- 143,158 ---- s = (String)value; } else if (value instanceof Double) { ! s = ((Double)value).toString(); ! int index = s.indexOf('.'); ! if (index > 0) { ! s = s.substring(0, index + 4 > s.length() ? s.length() - 1 : index + 4); ! } } JLabel valueLabel = new JLabel(s); ! if (attribute.isEditable()) { ! valueLabel.setFont(AttributeView.FONT_PLAIN); ! } else { ! valueLabel.setFont(AttributeView.FONT_ITALIC); ! } return valueLabel; } *************** *** 160,164 **** } JTextField valueEditor = new JTextField(s); ! valueEditor.setFont(AttributePanel.FONT_PLAIN); return valueEditor; } --- 171,175 ---- } JTextField valueEditor = new JTextField(s); ! valueEditor.setFont(AttributeView.FONT_PLAIN); return valueEditor; } *************** *** 176,188 **** */ public void startEditing() { ! if (editor == null) { ! component.remove(0); ! editor = (JTextField) createValueEditor(attribute.getValue()); ! editor.addKeyListener(this); ! component.add(editor); ! component.revalidate(); } - editor.requestFocus(); - editor.selectAll(); } --- 187,205 ---- */ public void startEditing() { ! if (attribute.isEditable()) { ! if (editor == null) { ! Dimension d = component.getSize(); ! component.remove(0); ! editor = (JTextField) createValueEditor(attribute.getValue()); ! editor.setMaximumSize(new Dimension((int)(d.getWidth()), ! (int)d.getHeight())); ! editor.setDebugGraphicsOptions(DebugGraphics.LOG_OPTION); ! editor.addKeyListener(this); ! component.add(editor); ! component.revalidate(); ! } ! editor.requestFocus(); ! editor.selectAll(); } } *************** *** 192,196 **** */ public void stopEditing() { ! if (editor != null) { Object val = attribute.getValue(); if (val instanceof String) { --- 209,213 ---- */ public void stopEditing() { ! if (editor != null && attribute.isEditable()) { Object val = attribute.getValue(); if (val instanceof String) { Index: GenericPanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/GenericPanel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GenericPanel.java 3 Feb 2006 20:11:45 -0000 1.2 --- GenericPanel.java 9 Feb 2006 13:55:12 -0000 1.3 *************** *** 7,10 **** --- 7,11 ---- package net.sourceforge.bprocessor.gui.attrview; + import java.awt.BorderLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; *************** *** 12,19 **** --- 13,24 ---- import java.util.List; + import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; + import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; + import javax.swing.border.EtchedBorder; + import javax.swing.border.TitledBorder; import net.sourceforge.bprocessor.model.Attribute; *************** *** 41,50 **** */ public GenericPanel(Parametric param) { ! super(); this.content = Box.createVerticalBox(); obj = param; attributes = param.getAttributes(); ! generateContent(attributes); ! add(this.content); addMouseListener(this); } --- 46,63 ---- */ public GenericPanel(Parametric param) { ! super(new BorderLayout()); this.content = Box.createVerticalBox(); obj = param; attributes = param.getAttributes(); ! generateContent(attributes, content); ! Box b = Box.createHorizontalBox(); ! JLabel label = new JLabel(" - " + ! param.getClass().getName().replaceFirst("net.sourceforge.bprocessor.model.", "") + " - "); ! label.setFont(AttributeView.FONT_HEADER); ! b.add(Box.createHorizontalGlue()); ! b.add(label); ! b.add(Box.createHorizontalGlue()); ! add(BorderLayout.NORTH, b); ! add(BorderLayout.CENTER, this.content); addMouseListener(this); } *************** *** 53,74 **** * local method for generating the content * @param what The list of attrinutes */ ! private void generateContent(List what) { Iterator iter = what.iterator(); while (iter.hasNext()) { Attribute a = (Attribute)iter.next(); if (a.getValue() instanceof String || a.getValue() instanceof Double) { StringAttribute sa = new StringAttribute(a); sa.addStringAttributeListener(new AttributeListener() { public void valueChanged(Attribute a) { - System.out.println("WOW"); obj.setAttributes(attributes); } }); sa.addMouseListener(this); ! content.add(new AttributeRow(sa)); ! } else if (a.getValue() == null) { ! // Just a label ! content.add(new JLabel(a.getName())); } } --- 66,101 ---- * local method for generating the content * @param what The list of attrinutes + * @param where The place to put all the generated content; */ ! private void generateContent(List what, JComponent where) { Iterator iter = what.iterator(); while (iter.hasNext()) { Attribute a = (Attribute)iter.next(); if (a.getValue() instanceof String || a.getValue() instanceof Double) { + // All the simple types in a field just for editing StringAttribute sa = new StringAttribute(a); sa.addStringAttributeListener(new AttributeListener() { public void valueChanged(Attribute a) { obj.setAttributes(attributes); } }); sa.addMouseListener(this); ! where.add(new AttributeRow(sa)); ! } else if (a.getValue() instanceof List) { ! // Take care of all list attributes ! List elems = (List)a.getValue(); ! Iterator iterElems = elems.iterator(); ! Box more = Box.createVerticalBox(); ! TitledBorder b = BorderFactory.createTitledBorder( ! BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), ! a.getName()); ! b.setTitleJustification(TitledBorder.CENTER); ! more.setBorder(b); ! if (iterElems.next() instanceof Attribute) { ! generateContent(elems, more); ! } ! where.add(more); ! } else { ! System.out.println("[GenericPanel] Something were not implemented"); } } Index: AttributePanel.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/AttributePanel.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AttributePanel.java 9 Feb 2006 13:12:18 -0000 1.4 --- AttributePanel.java 9 Feb 2006 13:55:12 -0000 1.5 *************** *** 9,13 **** import java.awt.Color; import java.awt.Dimension; - import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; --- 9,12 ---- *************** *** 40,49 **** private Object current; - /** The font used in plain */ - public static final Font FONT_PLAIN = new Font("Sans-serif", Font.PLAIN, 12); - - /** The font used in bold */ - public static final Font FONT_BOLD = new Font("Sans-serif", Font.BOLD, 12); - /** If its a textfield */ public static final int TFIELD = 1; --- 39,42 ---- *************** *** 91,95 **** con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(FONT_BOLD); add(name); --- 84,88 ---- con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(AttributeView.FONT_BOLD); add(name); *************** *** 100,104 **** con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(nameEdit, con); ! nameEdit.setFont(FONT_PLAIN); add(nameEdit); nameEdit.addKeyListener(new MyKeyListener(o, TFIELD)); --- 93,97 ---- con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(nameEdit, con); ! nameEdit.setFont(AttributeView.FONT_PLAIN); add(nameEdit); nameEdit.addKeyListener(new MyKeyListener(o, TFIELD)); *************** *** 194,203 **** con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(FONT_BOLD); add(name); JLabel vertexName = new JLabel(o.getName()); layout.setConstraints(vertexName, con); ! vertexName.setFont(FONT_PLAIN); add(vertexName); --- 187,196 ---- con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(AttributeView.FONT_BOLD); add(name); JLabel vertexName = new JLabel(o.getName()); layout.setConstraints(vertexName, con); ! vertexName.setFont(AttributeView.FONT_PLAIN); add(vertexName); *************** *** 214,218 **** con.weightx = 0; layout.setConstraints(x, con); ! x.setFont(FONT_BOLD); add(x); --- 207,211 ---- con.weightx = 0; layout.setConstraints(x, con); ! x.setFont(AttributeView.FONT_BOLD); add(x); *************** *** 223,227 **** con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(xEdit, con); ! xEdit.setFont(FONT_PLAIN); add(xEdit); xEdit.addKeyListener(new MyKeyListener(o, XCOOR)); --- 216,220 ---- con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(xEdit, con); ! xEdit.setFont(AttributeView.FONT_PLAIN); add(xEdit); xEdit.addKeyListener(new MyKeyListener(o, XCOOR)); *************** *** 232,236 **** con.fill = GridBagConstraints.NONE; layout.setConstraints(y, con); ! y.setFont(FONT_BOLD); add(y); --- 225,229 ---- con.fill = GridBagConstraints.NONE; layout.setConstraints(y, con); ! y.setFont(AttributeView.FONT_BOLD); add(y); *************** *** 241,245 **** con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(yEdit, con); ! yEdit.setFont(FONT_PLAIN); add(yEdit); yEdit.addKeyListener(new MyKeyListener(o, YCOOR)); --- 234,238 ---- con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(yEdit, con); ! yEdit.setFont(AttributeView.FONT_PLAIN); add(yEdit); yEdit.addKeyListener(new MyKeyListener(o, YCOOR)); *************** *** 250,254 **** con.fill = GridBagConstraints.NONE; layout.setConstraints(z, con); ! z.setFont(FONT_BOLD); add(z); --- 243,247 ---- con.fill = GridBagConstraints.NONE; layout.setConstraints(z, con); ! z.setFont(AttributeView.FONT_BOLD); add(z); *************** *** 259,263 **** con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(zEdit, con); ! zEdit.setFont(FONT_PLAIN); add(zEdit); zEdit.addKeyListener(new MyKeyListener(o, ZCOOR)); --- 252,256 ---- con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(zEdit, con); ! zEdit.setFont(AttributeView.FONT_PLAIN); add(zEdit); zEdit.addKeyListener(new MyKeyListener(o, ZCOOR)); *************** *** 287,296 **** con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(FONT_BOLD); add(name); JLabel edgeName = new JLabel(o.getName()); layout.setConstraints(edgeName, con); ! edgeName.setFont(FONT_PLAIN); add(edgeName); --- 280,289 ---- con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(AttributeView.FONT_BOLD); add(name); JLabel edgeName = new JLabel(o.getName()); layout.setConstraints(edgeName, con); ! edgeName.setFont(AttributeView.FONT_PLAIN); add(edgeName); *************** *** 307,311 **** con.gridwidth = 1; layout.setConstraints(length, con); ! length.setFont(FONT_BOLD); add(length); --- 300,304 ---- con.gridwidth = 1; layout.setConstraints(length, con); ! length.setFont(AttributeView.FONT_BOLD); add(length); *************** *** 316,320 **** con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(lengthEdit, con); ! lengthEdit.setFont(FONT_PLAIN); add(lengthEdit); lengthEdit.addKeyListener(new MyKeyListener(o, LENGTH)); --- 309,313 ---- con.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(lengthEdit, con); ! lengthEdit.setFont(AttributeView.FONT_PLAIN); add(lengthEdit); lengthEdit.addKeyListener(new MyKeyListener(o, LENGTH)); *************** *** 345,354 **** con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(FONT_BOLD); add(name); JLabel surfaceName = new JLabel(o.getName()); layout.setConstraints(surfaceName, con); ! surfaceName.setFont(FONT_PLAIN); add(surfaceName); --- 338,347 ---- con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(AttributeView.FONT_BOLD); add(name); JLabel surfaceName = new JLabel(o.getName()); layout.setConstraints(surfaceName, con); ! surfaceName.setFont(AttributeView.FONT_PLAIN); add(surfaceName); *************** *** 364,368 **** con.gridwidth = 1; layout.setConstraints(fspace, con); ! fspace.setFont(FONT_BOLD); add(fspace); --- 357,361 ---- con.gridwidth = 1; layout.setConstraints(fspace, con); ! fspace.setFont(AttributeView.FONT_BOLD); add(fspace); *************** *** 380,384 **** con.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints(frontSpaceName, con); ! frontSpaceName.setFont(FONT_PLAIN); add(frontSpaceName); --- 373,377 ---- con.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints(frontSpaceName, con); ! frontSpaceName.setFont(AttributeView.FONT_PLAIN); add(frontSpaceName); *************** *** 402,406 **** con.gridwidth = 1; layout.setConstraints(bspace, con); ! bspace.setFont(FONT_BOLD); add(bspace); --- 395,399 ---- con.gridwidth = 1; layout.setConstraints(bspace, con); ! bspace.setFont(AttributeView.FONT_BOLD); add(bspace); *************** *** 417,421 **** con.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints(backSpaceName, con); ! backSpaceName.setFont(FONT_PLAIN); add(backSpaceName); --- 410,414 ---- con.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints(backSpaceName, con); ! backSpaceName.setFont(AttributeView.FONT_PLAIN); add(backSpaceName); *************** *** 456,465 **** con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(FONT_BOLD); add(name); JLabel cameraName = new JLabel(c.getName()); layout.setConstraints(cameraName, con); ! cameraName.setFont(FONT_PLAIN); add(cameraName); --- 449,458 ---- con.weightx = 0; layout.setConstraints(name, con); ! name.setFont(AttributeView.FONT_BOLD); add(name); JLabel cameraName = new JLabel(c.getName()); layout.setConstraints(cameraName, con); ! cameraName.setFont(AttributeView.FONT_PLAIN); add(cameraName); *************** *** 491,495 **** typeCon.gridy = 0; JLabel cam = new JLabel("Camera:"); ! cam.setFont(FONT_BOLD); type.add(cam, typeCon); --- 484,488 ---- typeCon.gridy = 0; JLabel cam = new JLabel("Camera:"); ! cam.setFont(AttributeView.FONT_BOLD); type.add(cam, typeCon); *************** *** 529,533 **** typeCon.gridy = 4; JLabel eyel = new JLabel("Eye-point:"); ! cam.setFont(FONT_BOLD); type.add(eyel, typeCon); typeCon.gridwidth = 1; --- 522,526 ---- typeCon.gridy = 4; JLabel eyel = new JLabel("Eye-point:"); ! cam.setFont(AttributeView.FONT_BOLD); type.add(eyel, typeCon); typeCon.gridwidth = 1; *************** *** 564,568 **** typeCon.gridy = 8; JLabel rolll = new JLabel("Roll:"); ! cam.setFont(FONT_BOLD); type.add(rolll, typeCon); typeCon.gridwidth = 1; --- 557,561 ---- typeCon.gridy = 8; JLabel rolll = new JLabel("Roll:"); ! cam.setFont(AttributeView.FONT_BOLD); type.add(rolll, typeCon); typeCon.gridwidth = 1; Index: AttributeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/AttributeView.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** AttributeView.java 3 Feb 2006 15:23:00 -0000 1.32 --- AttributeView.java 9 Feb 2006 13:55:12 -0000 1.33 *************** *** 12,16 **** --- 12,18 ---- import net.sourceforge.bprocessor.model.Selection; + import java.awt.BorderLayout; import java.awt.Dimension; + import java.awt.Font; import javax.swing.JPanel; *************** *** 25,28 **** --- 27,43 ---- private static Logger log = Logger.getLogger(AttributeView.class); + /** The font used in plain */ + public static final Font FONT_PLAIN = new Font("Sans-serif", Font.PLAIN, 12); + + /** The font used in bold */ + public static final Font FONT_BOLD = new Font("Sans-serif", Font.BOLD, 12); + + /** The font used in bold */ + public static final Font FONT_ITALIC = new Font("Sans-serif", Font.ITALIC, 12); + + /** The font used in bold */ + public static final Font FONT_HEADER = new Font("Sans-serif", Font.BOLD, 13); + + /** * Constructor *************** *** 42,50 **** Selection selection = Selection.primary(); if (object == selection) { ! if (selection.size() > 0) { Object o = selection.iterator().next(); this.removeAll(); if (o instanceof Parametric) { ! this.add(new GenericPanel((Parametric)o)); } else { AttributePanel ap = new AttributePanel(); --- 57,65 ---- Selection selection = Selection.primary(); if (object == selection) { ! if (selection.size() == 1) { Object o = selection.iterator().next(); this.removeAll(); if (o instanceof Parametric) { ! this.add(BorderLayout.NORTH, new GenericPanel((Parametric)o)); } else { AttributePanel ap = new AttributePanel(); *************** *** 52,55 **** --- 67,72 ---- this.add(ap); } + } else { + this.removeAll(); } } |