[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/attrview AttributeView.java,1.27,1.28 MyK
Status: Pre-Alpha
Brought to you by:
henryml
From: Nikolaj B. <nbr...@us...> - 2006-01-23 02:47:09
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18550/src/net/sourceforge/bprocessor/gui/attrview Modified Files: AttributeView.java MyKeyListener.java Log Message: Updated the attributeview, so it can now show info for Vertex, and Edge too. Index: MyKeyListener.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/MyKeyListener.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MyKeyListener.java 18 Jan 2006 10:12:39 -0000 1.5 --- MyKeyListener.java 23 Jan 2006 02:47:00 -0000 1.6 *************** *** 9,15 **** --- 9,19 ---- import java.awt.event.KeyListener; import java.awt.event.KeyEvent; + + import javax.swing.JOptionPane; import javax.swing.text.JTextComponent; + import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Space; + import net.sourceforge.bprocessor.model.Vertex; /** *************** *** 24,27 **** --- 28,43 ---- public static final int TAREA = 2; + /** If its the length field */ + public static final int LENGTH = 3; + + /** The X coordinate */ + public static final int XCOOR = 4; + + /** The Y coordinate */ + public static final int YCOOR = 5; + + /** The Z coordinate */ + public static final int ZCOOR = 6; + /** The current ConstructionSpace */ private Space cons; *************** *** 38,42 **** /** * The constructor ! * @param o the event * @param type shows the type of the component the listeners listens too. */ --- 54,58 ---- /** * The constructor ! * @param o the object that has the listener attached. * @param type shows the type of the component the listeners listens too. */ *************** *** 85,88 **** --- 101,204 ---- } } + + if (type == LENGTH) { + JTextComponent tf = (JTextComponent)e.getSource(); + double newLength = 0; + boolean validInput = true; + try { + newLength = new Double(tf.getText()).doubleValue(); + } catch (Exception wrongInput) { + validInput = false; + } + + if (validInput) { + if (current instanceof Edge) { + Edge edge = (Edge) current; + edge.setLength(newLength); + edge.changed(); + } + } else { + JOptionPane.showMessageDialog(null, + "Please enter a number", + "Error - Invalid input", + JOptionPane.ERROR_MESSAGE); + } + + } + + if (type == XCOOR) { + JTextComponent tf = (JTextComponent)e.getSource(); + double newX = 0; + boolean validInput = true; + try { + newX = new Double(tf.getText()).doubleValue(); + } catch (Exception wrongInput) { + validInput = false; + } + + if (validInput) { + if (current instanceof Vertex) { + Vertex vertex = (Vertex) current; + vertex.setX(newX); + vertex.changed(); + } + } else { + JOptionPane.showMessageDialog(null, + "Please enter a number", + "Error - Invalid input", + JOptionPane.ERROR_MESSAGE); + } + + } + + if (type == YCOOR) { + JTextComponent tf = (JTextComponent)e.getSource(); + double newY = 0; + boolean validInput = true; + try { + newY = new Double(tf.getText()).doubleValue(); + } catch (Exception wrongInput) { + validInput = false; + } + + if (validInput) { + if (current instanceof Vertex) { + Vertex vertex = (Vertex) current; + vertex.setY(newY); + vertex.changed(); + } + } else { + JOptionPane.showMessageDialog(null, + "Please enter a number", + "Error - Invalid input", + JOptionPane.ERROR_MESSAGE); + } + + } + + if (type == ZCOOR) { + JTextComponent tf = (JTextComponent)e.getSource(); + double newZ = 0; + boolean validInput = true; + try { + newZ = new Double(tf.getText()).doubleValue(); + } catch (Exception wrongInput) { + validInput = false; + } + + if (validInput) { + if (current instanceof Vertex) { + Vertex vertex = (Vertex) current; + vertex.setZ(newZ); + vertex.changed(); + } + } else { + JOptionPane.showMessageDialog(null, + "Please enter a number", + "Error - Invalid input", + JOptionPane.ERROR_MESSAGE); + } + + } } } Index: AttributeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/attrview/AttributeView.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** AttributeView.java 19 Jan 2006 17:25:02 -0000 1.27 --- AttributeView.java 23 Jan 2006 02:46:59 -0000 1.28 *************** *** 15,18 **** --- 15,20 ---- import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; + import net.sourceforge.bprocessor.model.Edge; + import net.sourceforge.bprocessor.model.Vertex; import java.awt.Color; *************** *** 95,98 **** --- 97,112 ---- public static final int TAREA = 2; + /** The length field */ + public static final int LENGTH = 3; + + /** The X coordinate */ + public static final int XCOOR = 4; + + /** The Y coordinate */ + public static final int YCOOR = 5; + + /** The Z coordinate */ + public static final int ZCOOR = 6; + /** * Constructor *************** *** 212,215 **** --- 226,379 ---- } + /** + * Display the edge + * @param o The object + */ + void displayVertex(Vertex o) { + GridBagLayout layout = new GridBagLayout(); + GridBagConstraints con = new GridBagConstraints(); + setLayout(layout); + + JLabel name = new JLabel("Name: "); + con.anchor = GridBagConstraints.NORTH; + con.weightx = 0; + layout.setConstraints(name, con); + name.setFont(fontBold); + add(name); + + JLabel vertexName = new JLabel(o.getName()); + layout.setConstraints(vertexName, con); + vertexName.setFont(fontPlain); + add(vertexName); + + JPanel hfiller = new JPanel(); + hfiller.setOpaque(true); + con.weightx = 1.0; + con.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(hfiller, con); + add(hfiller); + + JLabel x = new JLabel("X: "); + con.anchor = GridBagConstraints.NORTH; + con.gridwidth = 1; + con.weightx = 0; + layout.setConstraints(x, con); + x.setFont(fontBold); + add(x); + + int xval = (int) (o.getX() * 100); + JTextField xEdit = new JTextField((Double.toString(((double) xval) / 100))); + con.gridwidth = GridBagConstraints.REMAINDER; + con.weightx = 1.0; + con.fill = GridBagConstraints.HORIZONTAL; + layout.setConstraints(xEdit, con); + xEdit.setFont(fontPlain); + add(xEdit); + xEdit.addKeyListener(new MyKeyListener(o, XCOOR)); + + JLabel y = new JLabel("Y: "); + con.gridwidth = 1; + con.weightx = 0; + con.fill = GridBagConstraints.NONE; + layout.setConstraints(y, con); + y.setFont(fontBold); + add(y); + + int yval = (int) (o.getY() * 100); + JTextField yEdit = new JTextField((Double.toString(((double) yval) / 100))); + con.gridwidth = GridBagConstraints.REMAINDER; + con.weightx = 1.0; + con.fill = GridBagConstraints.HORIZONTAL; + layout.setConstraints(yEdit, con); + yEdit.setFont(fontPlain); + add(yEdit); + yEdit.addKeyListener(new MyKeyListener(o, YCOOR)); + + JLabel z = new JLabel("Z: "); + con.gridwidth = 1; + con.weightx = 0; + con.fill = GridBagConstraints.NONE; + layout.setConstraints(z, con); + z.setFont(fontBold); + add(z); + + int zval = (int) (o.getZ() * 100); + JTextField zEdit = new JTextField((Double.toString(((double) zval) / 100))); + con.gridwidth = GridBagConstraints.REMAINDER; + con.weightx = 1.0; + con.fill = GridBagConstraints.HORIZONTAL; + layout.setConstraints(zEdit, con); + zEdit.setFont(fontPlain); + add(zEdit); + zEdit.addKeyListener(new MyKeyListener(o, ZCOOR)); + + JPanel vfiller = new JPanel(); + vfiller.setOpaque(true); + con.weighty = 1.0; + con.fill = GridBagConstraints.BOTH; + layout.setConstraints(vfiller, con); + add(vfiller); + + + + } + + /** + * Display the edge + * @param o The object + */ + void displayEdge(Edge o) { + GridBagLayout layout = new GridBagLayout(); + GridBagConstraints con = new GridBagConstraints(); + setLayout(layout); + + JLabel name = new JLabel("Name: "); + con.anchor = GridBagConstraints.NORTH; + con.weightx = 0; + layout.setConstraints(name, con); + name.setFont(fontBold); + add(name); + + JLabel edgeName = new JLabel(o.getName()); + layout.setConstraints(edgeName, con); + edgeName.setFont(fontPlain); + add(edgeName); + + JPanel hfiller = new JPanel(); + hfiller.setOpaque(true); + con.weightx = 1.0; + con.gridwidth = GridBagConstraints.REMAINDER; + layout.setConstraints(hfiller, con); + add(hfiller); + + JLabel length = new JLabel("Length: "); + con.anchor = GridBagConstraints.NORTH; + con.weightx = 0; + con.gridwidth = 1; + layout.setConstraints(length, con); + length.setFont(fontBold); + add(length); + + int l = (int) (o.getLength() * 100); + JTextField lengthEdit = new JTextField((Double.toString(((double) l) / 100))); + con.gridwidth = GridBagConstraints.REMAINDER; + con.weightx = 1.0; + con.fill = GridBagConstraints.HORIZONTAL; + layout.setConstraints(lengthEdit, con); + lengthEdit.setFont(fontPlain); + add(lengthEdit); + lengthEdit.addKeyListener(new MyKeyListener(o, LENGTH)); + + + JPanel vfiller = new JPanel(); + vfiller.setOpaque(true); + con.weighty = 1.0; + con.fill = GridBagConstraints.BOTH; + layout.setConstraints(vfiller, con); + add(vfiller); + + + } + /** *************** *** 516,519 **** --- 680,687 ---- } else if (current instanceof Camera) { displayCamera((Camera) current); + } else if (current instanceof Edge) { + displayEdge((Edge) current); + } else if (current instanceof Vertex) { + displayVertex((Vertex) current); } else { if (current != null) { *************** *** 525,526 **** --- 693,695 ---- } } + |