[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view ViewToolbarFactory.java, NONE, 1.1 Vi
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2007-06-28 00:04:59
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21825/src/net/sourceforge/bprocessor/gl/view Modified Files: View.java Added Files: ViewToolbarFactory.java Log Message: Extracted code generating the view part of the toolbar into a new class. Added a new drawmode similar to the shading mode but where surfaces that would otherwise be rasterized-seethrough now are invisible and unselectable. --- NEW FILE: ViewToolbarFactory.java --- package net.sourceforge.bprocessor.gl.view; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.net.URL; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JToggleButton; import org.apache.log4j.Logger; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gui.Toolbar; public class ViewToolbarFactory { /** The logger */ private static Logger log = Logger.getLogger(ViewToolbarFactory.class); public void registerToolbar(GLView glv) { Toolbar tb = Toolbar.getInstance(); tb.addSeparator(3); ButtonGroup bg = new ButtonGroup(); JToggleButton but = tb.registerAction(new ViewLighting(glv)); bg.add(but); but.setToolTipText("Shading"); but.setMnemonic(KeyEvent.VK_F5); but.setSelected(true); but = tb.registerAction(new ViewNoRaster(glv)); bg.add(but); but.setToolTipText("Shading no raster"); but.setMnemonic(KeyEvent.VK_F6); but = tb.registerAction(new ViewSolid(glv)); bg.add(but); but.setToolTipText("Solid"); but.setMnemonic(KeyEvent.VK_F7); but = tb.registerAction(new ViewWireframe(glv)); bg.add(but); but.setToolTipText("Wireframe"); but.setMnemonic(KeyEvent.VK_F8); } /** * The viewwireframe inner class */ class ViewWireframe extends AbstractAction { /** */ private static final long serialVersionUID = 1L; /** The GLView */ private GLView glv = null; /** * Constructor * @param glv TheGLView */ ViewWireframe(GLView glv) { this.glv = glv; ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("Biconwire.gif"); ImageIcon im = new ImageIcon(url); putValue(Action.SMALL_ICON, im); } /** * Called when the button is pressed * @param e The ActionEvent */ public void actionPerformed(ActionEvent e) { glv.getView().changeDrawMode(View.WIREFRAME_MODE); glv.repaint(true); } } /** * The "no raster" inner class */ class ViewNoRaster extends AbstractAction { /** */ private static final long serialVersionUID = 1L; /** The GLView */ private GLView glv = null; /** * Constructor * @param glv TheGLView */ ViewNoRaster(GLView glv) { this.glv = glv; ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("Biconlight.gif"); ImageIcon im = new ImageIcon(url); putValue(Action.SMALL_ICON, im); } /** * Called when the button is pressed * @param e The ActionEvent */ public void actionPerformed(ActionEvent e) { glv.getView().changeDrawMode(View.SPACE_ASSGN_MODE); glv.repaint(true); } } /** * The viewSolid inner class */ class ViewSolid extends AbstractAction { /** */ private static final long serialVersionUID = 1L; /** The GLView */ private GLView glv = null; /** * Constructor * @param glv TheGLView */ ViewSolid(GLView glv) { this.glv = glv; ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("Biconsolid.gif"); ImageIcon im = new ImageIcon(url); putValue(Action.SMALL_ICON, im); } /** * Called when the button is pressed * @param e The ActionEvent */ public void actionPerformed(ActionEvent e) { glv.getView().changeDrawMode(View.SOLID_MODE); glv.repaint(true); } } /** * The viewlighting inner class */ class ViewLighting extends AbstractAction { /** */ private static final long serialVersionUID = 1L; /** The GLView */ private GLView glv = null; /** * Constructor * @param glv TheGLView */ ViewLighting(GLView glv) { this.glv = glv; ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("Biconlight.gif"); ImageIcon im = new ImageIcon(url); putValue(Action.SMALL_ICON, im); } /** * Called when the button is pressed * @param e The ActionEvent */ public void actionPerformed(ActionEvent e) { glv.getView().changeDrawMode(View.LIGHTING_MODE); glv.repaint(true); } } } Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.220 retrieving revision 1.221 diff -C2 -d -r1.220 -r1.221 *** View.java 27 Jun 2007 22:08:13 -0000 1.220 --- View.java 28 Jun 2007 00:04:59 -0000 1.221 *************** *** 15,19 **** import net.sourceforge.bprocessor.gl.model.SpaceBox; import net.sourceforge.bprocessor.gl.model.Widget; - import net.sourceforge.bprocessor.gui.Toolbar; import net.sourceforge.bprocessor.model.ClippingPlane; --- 15,18 ---- *************** *** 53,59 **** import java.awt.Toolkit; - import java.awt.event.ActionEvent; - import java.awt.event.KeyEvent; - import java.net.URL; import java.nio.IntBuffer; --- 52,55 ---- *************** *** 67,75 **** import javax.media.opengl.glu.GLUtessellatorCallback; import javax.media.opengl.glu.GLUtessellatorCallbackAdapter; - import javax.swing.AbstractAction; - import javax.swing.Action; - import javax.swing.ImageIcon; - import javax.swing.JToggleButton; - import javax.swing.ButtonGroup; import org.apache.log4j.Logger; --- 63,66 ---- *************** *** 209,218 **** /** The last touched surface */ protected static Surface lastSurface; ! /** */ public static final int WIREFRAME_MODE = 2; ! /** */ public static final int SOLID_MODE = 1; ! /** */ public static final int LIGHTING_MODE = 0; --- 200,215 ---- /** The last touched surface */ protected static Surface lastSurface; + + /** Flag for the "space assignmened only" style of view. + * This style of view will only show those surfaces that + * have some space assignment*/ + public static final int SPACE_ASSGN_MODE = 3; ! /** Flag for the wireframe style of view */ public static final int WIREFRAME_MODE = 2; ! ! /** Flag for the solid style of view (no lighting) */ public static final int SOLID_MODE = 1; ! /** Flag for the lighted style of view (this is the default) */ public static final int LIGHTING_MODE = 0; *************** *** 493,516 **** tempVertices = new HashSet<Vertex>(); colorMap = new HashMap(); ! edgeStyleMap = new HashMap(); glObjects3D = new HashSet<GlObject>(); ! widgets = new LinkedList<Widget>(); ! ! Toolbar tb = Toolbar.getInstance(); ! tb.addSeparator(3); ! ButtonGroup bg = new ButtonGroup(); ! JToggleButton but = tb.registerAction(new ViewLighting(glv)); ! bg.add(but); ! but.setToolTipText("Shading"); ! but.setMnemonic(KeyEvent.VK_F5); ! but.setSelected(true); ! but = tb.registerAction(new ViewSolid(glv)); ! bg.add(but); ! but.setToolTipText("Solid"); ! but.setMnemonic(KeyEvent.VK_F6); ! but = tb.registerAction(new ViewWireframe(glv)); ! bg.add(but); ! but.setToolTipText("Wireframe"); ! but.setMnemonic(KeyEvent.VK_F7); } --- 490,496 ---- tempVertices = new HashSet<Vertex>(); colorMap = new HashMap(); ! edgeStyleMap = new HashMap<Edge, EdgeAttributes>(); glObjects3D = new HashSet<GlObject>(); ! widgets = new LinkedList<Widget>(); } *************** *** 1121,1126 **** transform(space.getTransformations()); if (active) { ! Collection surfaces = space.getSurfaces(); switch (drawMode) { case LIGHTING_MODE: { gl.glEnable(GL.GL_LIGHTING); --- 1101,1115 ---- transform(space.getTransformations()); if (active) { ! Collection<Surface> surfaces = space.getSurfaces(); switch (drawMode) { + case SPACE_ASSGN_MODE: { + Collection<Surface> temp = new HashSet<Surface>(); + for (Surface s : surfaces) { + if (isVisible(s)) { + temp.add(s); + } + } + surfaces = temp; + } case LIGHTING_MODE: { gl.glEnable(GL.GL_LIGHTING); *************** *** 1988,1996 **** if (selectMode == VERTICES || selectMode == ALL) { - Iterator iter = vertices.iterator(); gl.glPushMatrix(); Space owner = null; ! while (iter.hasNext()) { ! Vertex v = (Vertex)iter.next(); pushName(gl, v); if (v.getOwner() != owner) { --- 1977,1983 ---- if (selectMode == VERTICES || selectMode == ALL) { gl.glPushMatrix(); Space owner = null; ! for (Vertex v : vertices) { pushName(gl, v); if (v.getOwner() != owner) { *************** *** 2006,2014 **** } if (selectMode == EDGES || selectMode == ALL) { - Iterator iter = edges.iterator(); gl.glPushMatrix(); Space owner = null; ! while (iter.hasNext()) { ! Edge e = (Edge)iter.next(); pushName(gl, e); if (e.getOwner() != owner) { --- 1993,1999 ---- } if (selectMode == EDGES || selectMode == ALL) { gl.glPushMatrix(); Space owner = null; ! for (Edge e : edges) { pushName(gl, e); if (e.getOwner() != owner) { *************** *** 2023,2033 **** gl.glPopMatrix(); } ! if ((selectMode == SURFACES || selectMode == ALL) && ! drawMode != WIREFRAME_MODE) { ! Iterator it = surfaces.iterator(); gl.glPushMatrix(); Space owner = null; ! while (it.hasNext()) { ! Surface s = (Surface)it.next(); pushName(gl, s); if (s.getOwner() != owner) { --- 2008,2028 ---- gl.glPopMatrix(); } ! ! if (drawMode == WIREFRAME_MODE) { ! surfaces = new HashSet<Surface>(); ! } else if (drawMode == SPACE_ASSGN_MODE) { ! Collection<Surface> temp = new LinkedList<Surface>(); ! for (Surface s : surfaces) { ! if (isVisible(s)) { ! temp.add(s); ! } ! } ! surfaces = temp; ! } ! ! if (selectMode == SURFACES || selectMode == ALL) { gl.glPushMatrix(); Space owner = null; ! for (Surface s : surfaces) { pushName(gl, s); if (s.getOwner() != owner) { *************** *** 2802,2807 **** */ public void changeDrawMode(int mode) { ! if (mode <= 2 && mode >= 0) { drawMode = mode; } } --- 2797,2803 ---- */ public void changeDrawMode(int mode) { ! if (mode <= 3 && mode >= 0) { drawMode = mode; + log.info("drawmode:" + mode); } } *************** *** 3117,3216 **** /** - * The viewwireframe inner class - */ - class ViewWireframe extends AbstractAction { - /** */ - private static final long serialVersionUID = 1L; - - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - ViewWireframe(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconwire.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.getView().changeDrawMode(View.WIREFRAME_MODE); - glv.repaint(true); - } - } - - /** - * The viewSolid inner class - */ - class ViewSolid extends AbstractAction { - /** */ - private static final long serialVersionUID = 1L; - - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - ViewSolid(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconsolid.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.getView().changeDrawMode(View.SOLID_MODE); - glv.repaint(true); - } - } - - /** - * The viewlighting inner class - */ - class ViewLighting extends AbstractAction { - /** */ - private static final long serialVersionUID = 1L; - - /** The GLView */ - private GLView glv = null; - - /** - * Constructor - * @param glv TheGLView - */ - ViewLighting(GLView glv) { - this.glv = glv; - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource("Biconlight.gif"); - ImageIcon im = new ImageIcon(url); - putValue(Action.SMALL_ICON, im); - } - - /** - * Called when the button is pressed - * @param e The ActionEvent - */ - public void actionPerformed(ActionEvent e) { - glv.getView().changeDrawMode(View.LIGHTING_MODE); - glv.repaint(true); - } - } - - /** * @return Returns the bgColor. */ --- 3113,3116 ---- |