[piccolo2d-dev] Issue 110 in piccolo2d: Syntactical code clean
Comment #2 on issue 110 by mr0...@mro.name: Syntactical code clean http://code.google.com/p/piccolo2d/issues/detail?id=110 Let me refer to http://books.google.de/books?id=n4jmGp2EO1YCpg=PA43lpg=PA43dq=finalsource=blots=j73YVpCe7isig=vIkMEfh0kW6XMlh7ubwtXxr-dK4hl=deei=kOpuSvH_M8eOsAaX9aSXBQsa=Xoi=book_resultct=resultresnum=4 - can't say it any better. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 110 in piccolo2d: Syntactical code clean
Comment #3 on issue 110 by samrreid: Syntactical code clean http://code.google.com/p/piccolo2d/issues/detail?id=110 I presume that (3) doesn't entail making any classes or non-private methods final (none should be). What reasons has allain.lalonde given for not using 'final' where possible? They don't appear in this thread. I agree that final parameters and variables (and fields where possible) are safer than the mutable form, and that it is worth the increase in verbosity. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Re: Issue 110 in piccolo2d: Syntactical code clean
err replace good development process with strict development process On Jul 28, 9:45 am, allain allain.lalo...@gmail.com wrote: final on parameters protects us from writing to them from within methods. FindBugs and PMD (I think) both flag this behaviour as problematic and catch many others in the process. If, and it's a big one, we target reducing the # of warnings being flagged by these tools, bugs introduced by not having final get caught anyway (along with countless others). I think adding final in a context where FindBugs failures breaks the build is unnecessary. That said, adding final to parameters doesn't hinder anything, it just adds verbosity for something that FindBugs and PMD would both disallow anyway. Not dead set against it, and the code will end up higher quality in the end no matter, I'm just stating my dislike for blanket covering a codebase with final when it's not necessary with a good development process. Just my 2 cents. On Jul 28, 8:42 am, codesite-nore...@google.com wrote: Comment #3 on issue 110 by samrreid: Syntactical code cleanhttp://code.google.com/p/piccolo2d/issues/detail?id=110 I presume that (3) doesn't entail making any classes or non-private methods final (none should be). What reasons has allain.lalonde given for not using 'final' where possible? They don't appear in this thread. I agree that final parameters and variables (and fields where possible) are safer than the mutable form, and that it is worth the increase in verbosity. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at:http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 110 in piccolo2d: Syntactical code clean
Comment #5 on issue 110 by allain.lalonde: Syntactical code clean http://code.google.com/p/piccolo2d/issues/detail?id=110 (copied form mailing list) final on parameters protects us from writing to them from within methods. FindBugs and PMD (I think) both flag this behaviour as problematic and catch many others in the process. If, and it's a big one, we target reducing the # of warnings being flagged by these tools, bugs introduced by not having final get caught anyway (along with countless others). I think adding final in a context where FindBugs failures breaks the build is unnecessary. That said, adding final to parameters doesn't hinder anything, it just adds verbosity for something that FindBugs and PMD would both disallow anyway. Not dead set against it, and the code will end up higher quality in the end no matter, I'm just stating my dislike for blanket covering a codebase with final when it's not necessary with a strict development process. Just my 2 cents. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 111 in piccolo2d: Piccolo is missing HTML support
Comment #1 on issue 111 by mr0...@mro.name: Piccolo is missing HTML support http://code.google.com/p/piccolo2d/issues/detail?id=111 great! -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 111 in piccolo2d: Piccolo is missing HTML support
Comment #2 on issue 111 by samrreid: Piccolo is missing HTML support http://code.google.com/p/piccolo2d/issues/detail?id=111 In some runs, I experimented with making the internal JLabel static (so all PHTML shared a copy), and didn't see any problems with the rendering. We should discuss whether a static JLabel would be better or worse. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 63 in piccolo2d: JSlider fails to render knob icon under Intel Macs in Java 1.5
Comment #3 on issue 63 by samrreid: JSlider fails to render knob icon under Intel Macs in Java 1.5 http://code.google.com/p/piccolo2d/issues/detail?id=63 My coworker, the reporter of this bug, indicated that this bug is fixed with newer versions Mac's Java implementation. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 110 in piccolo2d: Syntactical code clean
Comment #6 on issue 110 by samrreid: Syntactical code clean http://code.google.com/p/piccolo2d/issues/detail?id=110 If we already have a process in place that flags reassignment to variables and arguments (as allain suggested above), then I think inserting 'final' is unnecessary. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 110 in piccolo2d: Syntactical code clean
Comment #7 on issue 110 by heuermh: Syntactical code clean http://code.google.com/p/piccolo2d/issues/detail?id=110 I thought I did apply the Eclipse formatter at one point in the past? Checkstyle doesn't show many whitespace errors. I would advise to be careful with the final parameter stuff, as many methods in Piccolo2D modifiy the input parameters. I don't typically use an IDE, so the automatic format-on-cleanup is going to be lost on me. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 110 in piccolo2d: Syntactical code clean
Comment #8 on issue 110 by mr0...@mro.name: Syntactical code clean http://code.google.com/p/piccolo2d/issues/detail?id=110 @Michael: you did? the better! So there won't be many ws diffs. @All: A process in place is a good thing to have. But if that leads to not using the compiler to detect flaws I think it's misused. Again: I talk about making implicit final private stuff explicitly final so the compiler can check. Who else wants to check this may well do so. I just don't see the point why we shouldn't use the compiler to check this. Please show me the code metric that tells me that I changed a before final field accidently into a mutated one. And even if there were such a mindreading tool - I'd prefer the compiler shouting at me. Requires no plugin into whatever editor one may use. The code becomes more explicit, to both, man and machine. I'll do it in ~2h from now. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] [piccolo2d] r595 commited - Added PHtml and HTMLExample...
Revision: 595 Author: allain.lalonde Date: Tue Jul 28 10:22:29 2009 Log: Added PHtml and HTMLExample I've made it support link clicks by having a getClickedAddress(Point2D point) method. http://code.google.com/p/piccolo2d/source/detail?r=595 Added: /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java Modified: /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/ExampleRunner.java === --- /dev/null +++ /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java Tue Jul 28 10:22:29 2009 @@ -0,0 +1,242 @@ +package edu.umd.cs.piccolo.nodes; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.plaf.basic.BasicHTML; +import javax.swing.text.Position; +import javax.swing.text.View; + +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolo.util.PPaintContext; + +/** + * PHtml is a Piccolo node for rendering HTML text. It uses a JLabel under the + * hood so you have the same restrictions regarding html as you have when using + * standard Swing components (HTML 3.2 + subset of CSS 1.0). + * + * @author Chris Malley (cmal...@pixelzoom.com) + * @author Sam Reid + */ +public class PHtml extends PNode { + +/** + * Allows for future serialization code to understand versioned binary + * formats. + */ +private static final long serialVersionUID = 1L; + +private static final Pattern tagPattern = Pattern.compile(/?[^]+); +private static final Pattern linkPattern = Pattern.compile(a .*href=(\\\([^\\\]*)\\\|\\\'([^\\\]*)\\\')); + +private static final Font DEFAULT_FONT = new JTextField().getFont(); +private static final Color DEFAULT_HTML_COLOR = Color.BLACK; + +/** + * The property name that identifies a change of this node's font (see + * {...@link #getFont getFont}). Both old and new value will be set in any + * property change event. + */ +public static final String PROPERTY_FONT = font; +public static final int PROPERTY_CODE_FONT = 1 20; + +/** + * The property name that identifies a change of this node's html (see + * {...@link #getHTML getHTML}). Both old and new value will be set in any + * property change event. + */ +public static final String PROPERTY_HTML = html; +public static final int PROPERTY_CODE_HTML = 1 21; + +/** + * The property name that identifies a change of this node's html color (see + * {...@link #getHtml getHTMLColor}). Both old and new value will be set in any + * property change event. + */ +public static final String PROPERTY_HTML_COLOR = html color; +public static final int PROPERTY_CODE_HTML_COLOR = 1 22; + +private JLabel htmlLabel; +private View htmlView; +private final Rectangle htmlBounds; + +public PHtml() { +this(null, DEFAULT_FONT, DEFAULT_HTML_COLOR); +} + +public PHtml(String html) { +this(html, DEFAULT_FONT, DEFAULT_HTML_COLOR); +} + +public PHtml(String html, Color htmlColor) { +this(html, DEFAULT_FONT, htmlColor); +} + +public PHtml(String html, Font font, Color htmlColor) { +htmlLabel = new JLabel(html); +htmlLabel.setFont(font); +htmlLabel.setForeground(htmlColor); +htmlBounds = new Rectangle(); +update(); +} + +/** + * @return HTML being rendered by this node + */ +public String getHTML() { +return htmlLabel.getText(); +} + +/** + * Changes the HTML being rendered by this node + * + * @param newHtml + */ +public void setHTML(String newHtml) { +if (isNewHtml(newHtml)) { +String oldHtml = htmlLabel.getText(); +htmlLabel.setText(newHtml); +update(); +firePropertyChange(PROPERTY_CODE_HTML, PROPERTY_HTML, oldHtml, newHtml); +} +} + +private boolean isNewHtml(String html) { +return (htmlLabel.getText() != null html == null) || (htmlLabel.getText() == null html != null) +|| (!htmlLabel.getText().equals(html)); +} + +/** + * Gets the font. + * + * @return the font + */ +public Font getFont() { +return htmlLabel.getFont(); +} + +/** + * Set the font of this PHtml. + */ +public void setFont(Font newFont) { +Font oldFont = htmlLabel.getFont(); +htmlLabel.setFont(newFont); +update(); + +firePropertyChange(PROPERTY_CODE_FONT, PROPERTY_FONT, oldFont, newFont); +} + +/** + * Gets the color used
[piccolo2d-dev] Issue 101 in piccolo2d: Eliminate printStackTrace
Updates: Status: Started Comment #11 on issue 101 by mr0...@mro.name: Eliminate printStackTrace http://code.google.com/p/piccolo2d/issues/detail?id=101 undone in r596. will commit the agreed on changes soon. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 22 in piccolo2d: Name property for PNodes
Comment #21 on issue 22 by mr0...@mro.name: Name property for PNodes http://code.google.com/p/piccolo2d/issues/detail?id=22 undone in r597. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 110 in piccolo2d: Syntactical code clean
Comment #9 on issue 110 by mr0...@mro.name: Syntactical code clean http://code.google.com/p/piccolo2d/issues/detail?id=110 done it, see r599 local mvn build ok, hudson struggles with the checkout. @Michael: can you clirr this version against 1.2.1? -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 110 in piccolo2d: Syntactical code clean
Updates: Status: Fixed Comment #10 on issue 110 by mr0...@mro.name: Syntactical code clean http://code.google.com/p/piccolo2d/issues/detail?id=110 BTW, r599 also added the Eclipse Code Clean Profile http://code.google.com/p/piccolo2d/source/browse/piccolo2d.java/trunk/core/src/build/conf/eclipse-code-clean.xml or for those who like it a bit more visual: http://www.getdropbox.com/gallery/965005/2/piccolo2d/code-clean?h=334773 -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] [piccolo2d] r600 commited - issue#22 again without syntax check.
Revision: 600 Author: mr0...@mro.name Date: Tue Jul 28 13:25:13 2009 Log: issue#22 again without syntax check. http://code.google.com/p/piccolo2d/source/detail?r=600 Modified: /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java === --- /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java Tue Jul 28 12:46:54 2009 +++ /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PNode.java Tue Jul 28 13:25:13 2009 @@ -240,6 +240,24 @@ private boolean fullBoundsInvalid; private boolean childBoundsInvalid; private boolean occluded; + +private String name; + +public void setName(final String name) { +this.name = name; +} + +public String getName() { +return name; +} + +/** + * Calls {...@link PNode} followed by {...@link PNode#setName(String)}. + */ +public PNode(final String name) { +this(); +setName(name); +} /** * Constructs a new PNode. --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 22 in piccolo2d: Name property for PNodes
Comment #22 on issue 22 by mr0...@mro.name: Name property for PNodes http://code.google.com/p/piccolo2d/issues/detail?id=22 redone in r600. Please verify and vote. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 101 in piccolo2d: Eliminate printStackTrace
Updates: Status: Fixed Comment #12 on issue 101 by mr0...@mro.name: Eliminate printStackTrace http://code.google.com/p/piccolo2d/issues/detail?id=101 redone in r601. Please verify vote. -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] Issue 22 in piccolo2d: Name property for PNodes
Updates: Status: Fixed Comment #23 on issue 22 by mr0...@mro.name: Name property for PNodes http://code.google.com/p/piccolo2d/issues/detail?id=22 (No comment was entered for this change.) -- You received this message because you are listed in the owner or CC fields of this issue, or because you starred this issue. You may adjust your issue notification preferences at: http://code.google.com/hosting/settings --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] [piccolo2d] r605 commited - a rude review: the example looks nice, the matching needs some tests.
Revision: 605 Author: mr0...@mro.name Date: Tue Jul 28 14:32:21 2009 Log: a rude review: the example looks nice, the matching needs some tests. http://code.google.com/p/piccolo2d/source/detail?r=605 Modified: /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java === --- /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java Tue Jul 28 14:14:32 2009 +++ /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java Tue Jul 28 14:32:21 2009 @@ -56,13 +56,12 @@ */ public class PHtml extends PNode { -/** - * Allows for future serialization code to understand versioned binary - * formats. - */ private static final long serialVersionUID = 1L; +// FIXME: imagine img alt=21 src=here comes the meat / private static final Pattern tagPattern = Pattern.compile(/?[^]+); +// FIXME: imagine a href=where to go +// title=this is not the href='gotcha!' / private static final Pattern linkPattern = Pattern.compile(a .*href=(\\\([^\\\]*)\\\|\\\'([^\\\]*)\\\')); private static final Font DEFAULT_FONT = new JTextField().getFont(); @@ -72,24 +71,29 @@ * The property name that identifies a change of this node's font (see * {...@link #getFont getFont}). Both old and new value will be set in any * property change event. + * + * FIXME what's that? */ public static final String PROPERTY_FONT = font; +// FIXME what's that? public static final int PROPERTY_CODE_FONT = 1 20; /** * The property name that identifies a change of this node's html (see * {...@link #getHTML getHTML}). Both old and new value will be set in any - * property change event. + * property change event. FIXME what's that? */ public static final String PROPERTY_HTML = html; +// FIXME what's that? public static final int PROPERTY_CODE_HTML = 1 21; /** * The property name that identifies a change of this node's html color (see * {...@link #getHtml getHTMLColor}). Both old and new value will be set in any - * property change event. + * property change event. FIXME what's that? */ public static final String PROPERTY_HTML_COLOR = html color; +// FIXME what's that? public static final int PROPERTY_CODE_HTML_COLOR = 1 22; private final JLabel htmlLabel; @@ -117,6 +121,8 @@ } /** + * FIXME better name innerHtml as w3c does? + * * @return HTML being rendered by this node */ public String getHTML() { @@ -126,6 +132,8 @@ /** * Changes the HTML being rendered by this node * + * FIXME better name innerHtml as w3c does? + * * @param newHtml */ public void setHTML(final String newHtml) { @@ -138,6 +146,7 @@ } private boolean isNewHtml(final String html) { +// FIXME NPE if both are null - can this happen? return htmlLabel.getText() != null html == null || htmlLabel.getText() == null html != null || !htmlLabel.getText().equals(html); } @@ -166,6 +175,8 @@ * Gets the color used to render the HTML. If you want to get the paint used * for the node, use getPaint. * + * FIXME be more consistent - either always HTML or Html but don't mix. + * * @return the color used to render the HTML. */ public Color getHTMLColor() { @@ -210,7 +221,7 @@ return boundsChanged; } -/* +/** * Paints the node. The HTML string is painted last, so it appears on top of * any child nodes. * @@ -229,6 +240,9 @@ /** * Returns the address specified in the link under the given point. * + * FIXME this method looks shaky - can you refactor to get it into a test + * harness? + * * @param clickedPoint * @return String containing value of href for clicked link, or null if no * link clicked --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] [piccolo2d] r606 commited - forgot to clean
Revision: 606 Author: mr0...@mro.name Date: Tue Jul 28 14:34:37 2009 Log: forgot to clean http://code.google.com/p/piccolo2d/source/detail?r=606 Modified: /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java === --- /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java Tue Jul 28 10:22:29 2009 +++ /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java Tue Jul 28 14:34:37 2009 @@ -12,13 +12,14 @@ import edu.umd.cs.piccolox.PFrame; public class HTMLExample extends PFrame { +private static final long serialVersionUID = 1L; private StringBuffer html; public HTMLExample() { this(null); } -public HTMLExample(PCanvas aCanvas) { +public HTMLExample(final PCanvas aCanvas) { super(HTMLExample, false, aCanvas); } @@ -33,17 +34,18 @@ final PHtml htmlNode = new PHtml(html.toString()); htmlNode.setBounds(0, 0, 400, 400); getCanvas().getLayer().addChild(htmlNode); - + getCanvas().addInputEventListener(new PBasicInputEventHandler() { -public void mouseClicked(PInputEvent event) { -PNode clickedNode = event.getPickedNode(); -if (!(clickedNode instanceof PHtml)) +public void mouseClicked(final PInputEvent event) { +final PNode clickedNode = event.getPickedNode(); +if (!(clickedNode instanceof PHtml)) { return; - -Point2D clickPoint = event.getPositionRelativeTo(clickedNode); -PHtml htmlNode = (PHtml)clickedNode; - -String url = htmlNode.getClickedAddress(clickPoint); +} + +final Point2D clickPoint = event.getPositionRelativeTo(clickedNode); +final PHtml htmlNode = (PHtml) clickedNode; + +final String url = htmlNode.getClickedAddress(clickPoint); JOptionPane.showMessageDialog(null, url); } }); @@ -55,7 +57,7 @@ html.append(lifont style='color:red; font-style: italic;'Limited CSS 1.0/font/li); html.append(liTables:); appendTable(); -html.append(/li); +html.append(/li); html.append(/ul); } @@ -66,7 +68,7 @@ html.append(/table); } -public static void main(String[] args) { +public static void main(final String[] args) { new HTMLExample(); } } --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] [piccolo2d] r607 commited - uh - non-wellformed HTML allowed - honestly?
Revision: 607 Author: mr0...@mro.name Date: Tue Jul 28 14:37:17 2009 Log: uh - non-wellformed HTML allowed - honestly? http://code.google.com/p/piccolo2d/source/detail?r=607 Modified: /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java === --- /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java Tue Jul 28 14:32:21 2009 +++ /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java Tue Jul 28 14:37:17 2009 @@ -50,6 +50,9 @@ * hood so you have the same restrictions regarding html as you have when using * standard Swing components (HTML 3.2 + subset of CSS 1.0). * + * FIXME: so it's not necessary well-formed? Atts like a href=unquoted / are + * ok? + * * @author Chris Malley (cmal...@pixelzoom.com) * @author Sam Reid * @author Allain Lalonde --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] [piccolo2d] r608 commited - Bug Example. Maybe esoteric but allowed and no warning in the docs.
Revision: 608 Author: mr0...@mro.name Date: Tue Jul 28 14:41:02 2009 Log: Bug Example. Maybe esoteric but allowed and no warning in the docs. http://code.google.com/p/piccolo2d/source/detail?r=608 Modified: /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java === --- /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java Tue Jul 28 14:34:37 2009 +++ /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java Tue Jul 28 14:41:02 2009 @@ -26,7 +26,7 @@ public void initialize() { html = new StringBuffer(); html.append(p style='margin-bottom: 10px;'); -html.append(This is an example a href='#testing'of what can/a be done with PHtml.); +html.append(This is an example a href='#testing' title=\a href='FIXME!'\of what can/a be done with PHtml.); html.append(/p); html.append(pIt supports:/p); appendFeatures(); --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---
[piccolo2d-dev] [piccolo2d] r609 commited - Made PHtml not use regular expressions for parsing HTML3.2 since it re...
Revision: 609 Author: allain.lalonde Date: Tue Jul 28 21:35:50 2009 Log: Made PHtml not use regular expressions for parsing HTML3.2 since it really couldn't handle malformed HTML at all. At least now there's a passing attempt. http://code.google.com/p/piccolo2d/source/detail?r=609 Added: /piccolo2d.java/branches/phtml/core/src/test/java/edu/umd/cs/piccolo/nodes/PHtmlTest.java Modified: /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java === --- /dev/null +++ /piccolo2d.java/branches/phtml/core/src/test/java/edu/umd/cs/piccolo/nodes/PHtmlTest.java Tue Jul 28 21:35:50 2009 @@ -0,0 +1,52 @@ +package edu.umd.cs.piccolo.nodes; + +import java.awt.geom.Point2D; + +import junit.framework.TestCase; +import edu.umd.cs.piccolo.util.PBounds; + +public class PHtmlTest extends TestCase { + +public void testGetClickedAddressReturnsSingleQuotedAddress() { +PHtml html = new PHtml(a href='http://www.testing.com'testing/a); +html.setBounds(new PBounds(0, 0, 100, 100)); +assertEquals(http://www.testing.com;, html.getClickedAddress(new Point2D.Double(5,5))); +} + +public void testGetClickedAddressReturnsDoubleQuotedAddress() { +PHtml html = new PHtml(a href=\http://www.testing.com\;testing/a); +html.setBounds(new PBounds(0, 0, 100, 100)); +assertEquals(http://www.testing.com;, html.getClickedAddress(new Point2D.Double(5,5))); +} + +public void testBracketsAreValidInHrefs() { +PHtml html = new PHtml(a href='ab'testing/a); +html.setBounds(new PBounds(0, 0, 100, 100)); +assertEquals(ab, html.getClickedAddress(new Point2D.Double(5,5))); +} + +public void testGetClickedAddressReturnsNullWhenInvalid() { +PHtml html = new PHtml(a ='ab'testing/a); +html.setBounds(new PBounds(0, 0, 100, 100)); +assertNull(html.getClickedAddress(new Point2D.Double(5,5))); +} + +public void testGetClickedAddressReturnsHrefWhenMissingEndAnchorTag() { +PHtml html = new PHtml(a href='testing.com'testing); +html.setBounds(new PBounds(0, 0, 100, 100)); +assertEquals(testing.com, html.getClickedAddress(new Point2D.Double(5,5))); +} + +public void testHandlesTricksyTitles() { +PHtml html = new PHtml(a href=\where to go\ title=\this is not the href='gotcha!' \testing/a); +html.setBounds(new PBounds(0, 0, 100, 100)); +assertEquals(where to go, html.getClickedAddress(new Point2D.Double(5,5))); +} + +public void testHandlesHrefWithoutQuotes() { +PHtml html = new PHtml(a href=testing.comtesting/a); +html.setBounds(new PBounds(0, 0, 100, 100)); +assertEquals(testing.com, html.getClickedAddress(new Point2D.Double(5,5))); +} + +} === --- /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java Tue Jul 28 14:37:17 2009 +++ /piccolo2d.java/branches/phtml/core/src/main/java/edu/umd/cs/piccolo/nodes/PHtml.java Tue Jul 28 21:35:50 2009 @@ -61,12 +61,6 @@ private static final long serialVersionUID = 1L; -// FIXME: imagine img alt=21 src=here comes the meat / -private static final Pattern tagPattern = Pattern.compile(/?[^]+); -// FIXME: imagine a href=where to go -// title=this is not the href='gotcha!' / -private static final Pattern linkPattern = Pattern.compile(a .*href=(\\\([^\\\]*)\\\|\\\'([^\\\]*)\\\')); - private static final Font DEFAULT_FONT = new JTextField().getFont(); private static final Color DEFAULT_HTML_COLOR = Color.BLACK; @@ -253,32 +247,103 @@ public String getClickedAddress(final Point2D clickedPoint) { int position = pointToModelIndex(clickedPoint); -final Matcher tagMatcher = tagPattern.matcher(htmlLabel.getText()); +String html = htmlLabel.getText(); String address = null; -while (tagMatcher.find()) { -if (position = tagMatcher.start()) { +int currentPos = 0; +while (currentPos html.length()) { +if (html.charAt(currentPos) != '') { +currentPos++; +} +else if (position currentPos) { break; } -position += tagMatcher.end() - tagMatcher.start(); - -final String tag = tagMatcher.group().toLowerCase(); -if (/a.equals(tag)) { -address = null; -} -else { -final Matcher linkMatcher = linkPattern.matcher(tag); -if (linkMatcher.find()) { -address = linkMatcher.group(2); -if (address == null) { -address = linkMatcher.group(3); -} +else { +int tagStart = currentPos; +int tagEnd = findTagEnd(html, currentPos); + +
[piccolo2d-dev] [piccolo2d] r610 commited - Removed example of 'invalid' html markup, since it's been fixed
Revision: 610 Author: allain.lalonde Date: Tue Jul 28 21:39:14 2009 Log: Removed example of 'invalid' html markup, since it's been fixed http://code.google.com/p/piccolo2d/source/detail?r=610 Modified: /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java === --- /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java Tue Jul 28 14:41:02 2009 +++ /piccolo2d.java/branches/phtml/examples/src/main/java/edu/umd/cs/piccolo/examples/HTMLExample.java Tue Jul 28 21:39:14 2009 @@ -26,7 +26,7 @@ public void initialize() { html = new StringBuffer(); html.append(p style='margin-bottom: 10px;'); -html.append(This is an example a href='#testing' title=\a href='FIXME!'\of what can/a be done with PHtml.); +html.append(This is an example a href='#testing'of what can/a be done with PHtml.); html.append(/p); html.append(pIt supports:/p); appendFeatures(); --~--~-~--~~~---~--~~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~--~~~~--~~--~--~---