[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl GLView.java,1.14,1.15
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-09-14 14:02:21
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24941 Modified Files: GLView.java Log Message: added length field Index: GLView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/GLView.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GLView.java 12 Sep 2005 18:04:33 -0000 1.14 --- GLView.java 14 Sep 2005 14:02:13 -0000 1.15 *************** *** 11,14 **** --- 11,19 ---- import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.gl.view.ViewFactory; + import net.sourceforge.bprocessor.model.EdgeFacade; + import net.sourceforge.bprocessor.model.Edge; + import net.sourceforge.bprocessor.kernel.notification.NotificationListener; + import net.sourceforge.bprocessor.kernel.notification.Notification; + import net.sourceforge.bprocessor.kernel.notification.Notifier; import net.sourceforge.bprocessor.gui.GUI; *************** *** 17,21 **** import net.java.games.jogl.GLDrawableFactory; import net.java.games.jogl.GLCanvas; ! //import java.awt.Dimension; import org.apache.log4j.Logger; --- 22,30 ---- import net.java.games.jogl.GLDrawableFactory; import net.java.games.jogl.GLCanvas; ! import java.awt.Dimension; ! import java.awt.BorderLayout; ! import javax.swing.JTextField; ! import javax.swing.JPanel; ! import javax.swing.JLabel; import org.apache.log4j.Logger; *************** *** 37,40 **** --- 46,52 ---- private Tool tool; + /** the length parameter */ + private LengthField lengthField; + /** * Constuctor *************** *** 47,51 **** glc = GLDrawableFactory.getFactory().createGLCanvas(glCap); ! //glc.setPreferredSize(new Dimension(0, 0)); view = ViewFactory.getFactory(this).getDefault(); glc.addGLEventListener(view); --- 59,74 ---- glc = GLDrawableFactory.getFactory().createGLCanvas(glCap); ! JPanel jp = new JPanel(); ! jp.setPreferredSize(new Dimension(450, 450)); ! jp.setLayout(new BorderLayout()); ! jp.add(glc, BorderLayout.CENTER); ! ! JPanel lengthPanel = new JPanel(); ! lengthPanel.setLayout(new BorderLayout()); ! lengthPanel.add(new JLabel("LENGTH: "), BorderLayout.WEST); ! lengthField = new LengthField(); ! lengthPanel.add(lengthField, BorderLayout.CENTER); ! jp.add(lengthPanel, BorderLayout.SOUTH); ! view = ViewFactory.getFactory(this).getDefault(); glc.addGLEventListener(view); *************** *** 56,60 **** glc.addKeyListener(tool); ! GUI.getInstance().registerPanel(glc, GUI.SPLIT_MIDDLE); log.info("Done Creating GlView"); glc.setAutoSwapBufferMode(false); --- 79,83 ---- glc.addKeyListener(tool); ! GUI.getInstance().registerPanel(jp, GUI.SPLIT_MIDDLE); log.info("Done Creating GlView"); glc.setAutoSwapBufferMode(false); *************** *** 107,112 **** } } ! ! /** --- 130,149 ---- } } ! ! /** ! * Set the length in the lengthField display ! * @param length The new length ! */ ! public void setLength(double length) { ! lengthField.setText(length); ! } ! ! /** ! * Get the length ! * @return The length ! */ ! public double getLength() { ! return lengthField.getDouble(); ! } /** *************** *** 133,135 **** --- 170,239 ---- return glc; } + + /** + * The length field class + */ + class LengthField extends JTextField implements NotificationListener { + /** The logger */ + private Logger log = Logger.getLogger(LengthField.class); + + /** + * The constructor + */ + public LengthField() { + super(15); + + Notifier.getInstance().addListener(this); + } + + /** + * set the text in the length field + * do only take integer + * @param d The integer + */ + public void setText(double d) { + super.setText(Double.toString(d)); + } + + /** + * Return the double in the textfield + * @return The double in the field + */ + public double getDouble() { + try { + double d = Double.parseDouble(super.getText()); + return d; + } catch (NumberFormatException e) { + log.warn(e); + } + return 0; + } + + /** + * Handle a notification + * @param n The notification + */ + public void handleNotification(Notification n) { + if (n.getType().equals(Notification.EDGE_SELECTED)) { + Edge e = (Edge)(EdgeFacade.getInstance().findById(n.getObject())); + setText(e.getLength()); + } else if (n.getType().equals(Notification.EDGE_DESELECTED)) { + setText(0); + } + } + + + /** + * Should the listener handle this notification + * @param type The notification type + * @return Returns true on SELECTED events; otherwise false + */ + public boolean isNotificationEnabled(String type) { + if (type.equals(Notification.EDGE_SELECTED) || + type.equals(Notification.EDGE_DESELECTED)) { + return true; + } + return false; + } + } } |