diff --git a/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java b/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java index 8b669fc..dea550b 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/event/PSelectionEventHandler.java @@ -629,10 +629,8 @@ if (node instanceof PLayer) { for (Iterator i = selectableParents.iterator(); i.hasNext();) { PNode parent = (PNode) i.next(); - if (parent instanceof PCamera) { - if (((PCamera) parent).indexOfLayer((PLayer) node) != -1) { - return true; - } + if (parent instanceof PCamera && ((PCamera) parent).indexOfLayer((PLayer) node) != -1) { + return true; } } } diff --git a/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java b/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java index fc30dd0..14845ae 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/event/PStyledTextEventHandler.java @@ -150,23 +150,24 @@ PStyledText newText = new PStyledText(); Document doc = editor.getUI().getEditorKit(editor).createDefaultDocument(); - if (doc instanceof StyledDocument) { - if (!doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontFamily) - || !doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontSize)) { + if (doc instanceof StyledDocument && missingFontFamilyOrSize(doc)) { + Font eFont = editor.getFont(); + SimpleAttributeSet sas = new SimpleAttributeSet(); + sas.addAttribute(StyleConstants.FontFamily, eFont.getFamily()); + sas.addAttribute(StyleConstants.FontSize, new Integer(eFont.getSize())); - Font eFont = editor.getFont(); - SimpleAttributeSet sas = new SimpleAttributeSet(); - sas.addAttribute(StyleConstants.FontFamily, eFont.getFamily()); - sas.addAttribute(StyleConstants.FontSize, new Integer(eFont.getSize())); - - ((StyledDocument) doc).setParagraphAttributes(0, doc.getLength(), sas, false); - } + ((StyledDocument) doc).setParagraphAttributes(0, doc.getLength(), sas, false); } newText.setDocument(doc); return newText; } + private boolean missingFontFamilyOrSize(Document doc) { + return !doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontFamily) + || !doc.getDefaultRootElement().getAttributes().isDefined(StyleConstants.FontSize); + } + public void mousePressed(PInputEvent inputEvent) { PNode pickedNode = inputEvent.getPickedNode(); diff --git a/extras/src/main/java/edu/umd/cs/piccolox/handles/PBoundsHandle.java b/extras/src/main/java/edu/umd/cs/piccolox/handles/PBoundsHandle.java index cac0489..9092408 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/handles/PBoundsHandle.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/handles/PBoundsHandle.java @@ -110,8 +110,9 @@ } public void mouseExited(PInputEvent aEvent) { - PPickPath focus = aEvent.getInputManager().getMouseFocus(); if (cursorPushed) { + PPickPath focus = aEvent.getInputManager().getMouseFocus(); + if (focus == null || focus.getPickedNode() != PBoundsHandle.this) { aEvent.popCursor(); cursorPushed = false; diff --git a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java index 611f312..e2307f2 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PStyledText.java @@ -342,6 +342,7 @@ font = style.getFont(rootElement.getAttributes()); } } + if (font != null) { ((AttributedString) stringContents.get(i)).addAttribute(TextAttribute.FONT, font, (int) Math.max(0, curElement.getStartOffset() - pEnd.runStart), (int) Math.min(pEnd.runLimit - pEnd.runStart, diff --git a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java index 73dbf6c..7c47725 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/pswing/PSwingEventHandler.java @@ -103,11 +103,9 @@ listenNode.removeInputEventListener(this); } } - else if (!this.active && active) { - if (listenNode != null) { - this.active = true; - listenNode.addInputEventListener(this); - } + else if (!this.active && active && listenNode != null) { + this.active = true; + listenNode.addInputEventListener(this); } } diff --git a/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java b/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java index d6122bb..6281209 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/swing/PDefaultScrollDirector.java @@ -206,46 +206,44 @@ * @param y The new y position */ public void setViewPosition(double x, double y) { - if (camera != null) { - // If a scroll is in progress - we ignore new scrolls - - // if we didn't, since the scrollbars depend on the camera location - // we can end up with an infinite loop - if (!scrollInProgress) { - scrollInProgress = true; + // Bail out if scrollInProgress because we can end up with an infinite + // loop since the scrollbars depend on the camera location + if (camera == null || scrollInProgress) + return; - // Get the union of all the layers' bounds - PBounds layerBounds = new PBounds(); - List layers = camera.getLayersReference(); - for (Iterator i = layers.iterator(); i.hasNext();) { - PLayer layer = (PLayer) i.next(); - layerBounds.add(layer.getFullBoundsReference()); - } + scrollInProgress = true; - PAffineTransform at = camera.getViewTransform(); - at.transform(layerBounds, layerBounds); - - // Union the camera bounds - PBounds viewBounds = camera.getBoundsReference(); - layerBounds.add(viewBounds); - - // Now find the new view position in view coordinates - Point2D newPoint = new Point2D.Double(layerBounds.getX() + x, layerBounds.getY() + y); - - // Now transform the new view position into global coords - camera.localToView(newPoint); - - // Compute the new matrix values to put the camera at the - // correct location - double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY()); - double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY()); - - at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY); - - // Now actually set the camera's transform - camera.setViewTransform(at); - scrollInProgress = false; - } + // Get the union of all the layers' bounds + PBounds layerBounds = new PBounds(); + List layers = camera.getLayersReference(); + for (Iterator i = layers.iterator(); i.hasNext();) { + PLayer layer = (PLayer) i.next(); + layerBounds.add(layer.getFullBoundsReference()); } + + PAffineTransform at = camera.getViewTransform(); + at.transform(layerBounds, layerBounds); + + // Union the camera bounds + PBounds viewBounds = camera.getBoundsReference(); + layerBounds.add(viewBounds); + + // Now find the new view position in view coordinates + Point2D newPoint = new Point2D.Double(layerBounds.getX() + x, layerBounds.getY() + y); + + // Now transform the new view position into global coords + camera.localToView(newPoint); + + // Compute the new matrix values to put the camera at the + // correct location + double newX = -(at.getScaleX() * newPoint.getX() + at.getShearX() * newPoint.getY()); + double newY = -(at.getShearY() * newPoint.getX() + at.getScaleY() * newPoint.getY()); + + at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), newX, newY); + + // Now actually set the camera's transform + camera.setViewTransform(at); + scrollInProgress = false; } /** @@ -254,9 +252,9 @@ */ public void propertyChange(PropertyChangeEvent pce) { boolean isRelevantViewEvent = (PCamera.PROPERTY_VIEW_TRANSFORM == pce.getPropertyName()); - boolean isRelevantBoundsEvent = (PNode.PROPERTY_BOUNDS == pce.getPropertyName() || PNode.PROPERTY_FULL_BOUNDS == pce - .getPropertyName()) + boolean isRelevantBoundsEvent = isBoundsChangedEvent(pce) && (pce.getSource() == camera || pce.getSource() == view.getRoot()); + if (isRelevantViewEvent || isRelevantBoundsEvent) { if (shouldRevalidateScrollPane()) { scrollPane.revalidate(); @@ -267,6 +265,10 @@ } } + private boolean isBoundsChangedEvent(PropertyChangeEvent pce) { + return (PNode.PROPERTY_BOUNDS == pce.getPropertyName() || PNode.PROPERTY_FULL_BOUNDS == pce.getPropertyName()); + } + /** * Should the ScrollPane be revalidated. This occurs when either the * scrollbars are showing and should be remove or are not showing and should