Commit 0a1f88a2 authored by Nico Mack's avatar Nico Mack

Minor code cleanup

parent a644e451
...@@ -93,8 +93,8 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager { ...@@ -93,8 +93,8 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
} }
/** /**
* Method called to initialize bootstrapping from a previously provided XML file. The method * Method called to initialize bootstrapping from a previously provided XML file. The method will
* will create all objects, cursors, and blobs. * create all objects, cursors, and blobs.
* *
* @throws BuildException * @throws BuildException
* Thrown when one or more of the tangibles failed to build. * Thrown when one or more of the tangibles failed to build.
...@@ -109,10 +109,10 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager { ...@@ -109,10 +109,10 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
} }
/** /**
* Method called to create a new instance of a cursor object. New cursor object will be created * Method called to create a new instance of a cursor object. New cursor object will be created from
* from template specified in bootstrap file. In case multiple cursor templates are encountered, * template specified in bootstrap file. In case multiple cursor templates are encountered, only the
* only the first one will taken into account. This may change in future release, allowing to * first one will taken into account. This may change in future release, allowing to assign
* assign different cursor templates depending on the cursor ID. * different cursor templates depending on the cursor ID.
* *
* @param cursorId * @param cursorId
* specifies the ID of the cursor object to create. * specifies the ID of the cursor object to create.
...@@ -154,15 +154,14 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager { ...@@ -154,15 +154,14 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
Element rootNode = bootstrap.getRootElement(); Element rootNode = bootstrap.getRootElement();
List<Element> connectionsRootNodes = rootNode.getChildren(Externalization.CONNECTIONS_NODE); // $NON-NLS-1$ List<Element> connectionsRootNodes = rootNode.getChildren(Externalization.CONNECTIONS_NODE); // $NON-NLS-1$
if (connectionsRootNodes != null) { if (connectionsRootNodes != null) {
for (Element connectionsNode : connectionsRootNodes) for (Element connectionsNode : connectionsRootNodes) {
if (connectionsNode != null) { if (connectionsNode != null) {
for (Element connectionNode : connectionsNode.getChildren()) { for (Element connectionNode : connectionsNode.getChildren()) {
switch (connectionNode.getName()) { if (Externalization.TETHERS_NODE.equals(connectionNode.getName())) {
case "tethers": //$NON-NLS-1$
this.loadTethers(connectionNode); this.loadTethers(connectionNode);
break; } else {
default: throw new BuildException(StringUtils.build("Unrecognized connection type {} !", connectionsNode.getName())); //$NON-NLS-1$
throw new BuildException(StringUtils.build("Unrecognized connection type {} !", connectionsNode.getName())); //$NON-NLS-1$ //$NON-NLS-2$ }
} }
} }
} }
...@@ -170,13 +169,12 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager { ...@@ -170,13 +169,12 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
} }
/** /**
* Note: When this method encounters an exception, it clears all previously loaded objects from * Note: When this method encounters an exception, it clears all previously loaded objects from the
* the list. * list.
* *
* @param objectRootNode * @param objectRootNode
* The root node holding the <code>object</code> node(s). * The root node holding the <code>object</code> node(s).
* @throws BuildException * @throws BuildException
* TODO
*/ */
private void loadTethers(Element tetherRootNode) throws BuildException { private void loadTethers(Element tetherRootNode) throws BuildException {
List<Element> tetherNodes = tetherRootNode.getChildren(Externalization.TETHER_NODE); List<Element> tetherNodes = tetherRootNode.getChildren(Externalization.TETHER_NODE);
...@@ -192,14 +190,14 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager { ...@@ -192,14 +190,14 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
LOGGER.error("One of the desired tethers could not be build!", e); //$NON-NLS-1$ LOGGER.error("One of the desired tethers could not be build!", e); //$NON-NLS-1$
tetherMap.clear(); tetherMap.clear();
throw new BuildException("One of the desired tethers could not be build! " + e.getMessage(), e); //$NON-NLS-1$ throw new BuildException("One of the desired tethers could not be build!", e); //$NON-NLS-1$
} }
} }
/** /**
* builds a cursor from the specified template node. A second parameter allows specifying the * builds a cursor from the specified template node. A second parameter allows specifying the
* bootstrapping context, a map holding the names and the values of variables for interpolation * bootstrapping context, a map holding the names and the values of variables for interpolation of
* of variable properties in template definition. * variable properties in template definition.
* *
* @param templateNode * @param templateNode
* specifies the template node to build the cursor from * specifies the template node to build the cursor from
...@@ -231,8 +229,8 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager { ...@@ -231,8 +229,8 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
/** /**
* builds a widget from the specified template node. A second parameter allows specifying the * builds a widget from the specified template node. A second parameter allows specifying the
* bootstrapping context, a map holding the names and the values of variables for interpolation * bootstrapping context, a map holding the names and the values of variables for interpolation of
* of variable properties in template definition. * variable properties in template definition.
* *
* @param templateNode * @param templateNode
* specifies the template node to build the widget from * specifies the template node to build the widget from
...@@ -263,8 +261,8 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager { ...@@ -263,8 +261,8 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
/** /**
* Note: When this method encounters an exception, it clears all previously loaded objects from * Note: When this method encounters an exception, it clears all previously loaded objects from the
* the list. * list.
* *
* @param objectRootNode * @param objectRootNode
* The root node holding the <code>object</code> node(s). * The root node holding the <code>object</code> node(s).
...@@ -290,12 +288,11 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager { ...@@ -290,12 +288,11 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
} }
/** /**
* Method used to determine the appropriate builder for a given object and then issue a build * Method used to determine the appropriate builder for a given object and then issue a build call.
* call.
* *
* @param objectNode * @param objectNode
* The node from a larger document that contains, as children, all the necessary * The node from a larger document that contains, as children, all the necessary information
* information to resolve the correct builder and build the final widget. * to resolve the correct builder and build the final widget.
* @param context * @param context
* @param callback * @param callback
* @return The final widget as defined by the children of the element node. * @return The final widget as defined by the children of the element node.
......
...@@ -56,8 +56,8 @@ public class AnimatedShapeCorona extends AnimatedCorona { ...@@ -56,8 +56,8 @@ public class AnimatedShapeCorona extends AnimatedCorona {
// * Constants * // * Constants *
// *************************************************************************** // ***************************************************************************
private static final String OPACITY = "opacity"; //$NON-NLS-1$ private static final String PROPERTY_OPACITY = "opacity"; //$NON-NLS-1$
private static final String SCALE = "scale"; //$NON-NLS-1$ private static final String PROPERTY_SCALE = "scale"; //$NON-NLS-1$
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
...@@ -117,9 +117,9 @@ public class AnimatedShapeCorona extends AnimatedCorona { ...@@ -117,9 +117,9 @@ public class AnimatedShapeCorona extends AnimatedCorona {
List<AnimationProperty<?>> properties = this.getAnimationProperties(); List<AnimationProperty<?>> properties = this.getAnimationProperties();
for (AnimationProperty<?> property : properties) { for (AnimationProperty<?> property : properties) {
if (OPACITY.equals(property.getProperty())) { if (PROPERTY_OPACITY.equals(property.getProperty())) {
this.setOpacity((double) property.getStart()); this.setOpacity((double) property.getStart());
} else if (SCALE.equals(property.getProperty())) { } else if (PROPERTY_SCALE.equals(property.getProperty())) {
this.setScale((double) property.getStart()); this.setScale((double) property.getStart());
} }
} }
......
...@@ -33,6 +33,7 @@ import java.awt.Color; ...@@ -33,6 +33,7 @@ import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke; import java.awt.Stroke;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
...@@ -159,6 +160,36 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str ...@@ -159,6 +160,36 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
this.setInformation(htmlContent); this.setInformation(htmlContent);
} }
// ---------------------------------------------------------------------------
protected BufferedImage renderHtml(String html, Shape canvas) {
BufferedImage renderedHtml;
Rectangle2D bounds;
HTMLDocument document = (HTMLDocument) htmlEditor.createDefaultDocument();
if (baseUrl != null) {
document.setBase(baseUrl);
}
bounds = canvas.getBounds2D();
editor.setDocument(document);
editor.setText(html);
renderedHtml = new BufferedImage((int) bounds.getWidth() - (2 * insetBorder), (int) bounds.getHeight() - (2 * insetBorder), BufferedImage.TYPE_INT_ARGB);
Graphics2D offscreen = renderedHtml.createGraphics();
offscreen.setRenderingHints(renderingHints);
AffineTransform translate = AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY());
offscreen.setClip(translate.createTransformedShape(canvas));
editor.paint(offscreen);
offscreen.dispose();
return renderedHtml;
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
// * Class Body * // * Class Body *
...@@ -179,13 +210,9 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str ...@@ -179,13 +210,9 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
if (this.opacity < 1.0f) if (this.opacity < 1.0f)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity)); localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
AffineTransform transform = this.getTransform(null); AffineTransform transform = this.getTransform(null);
localCanvas.setTransform(transform); localCanvas.setTransform(transform);
// Shape transformedShape = transform.createTransformedShape(shape);
localCanvas.setPaint(fillColour); localCanvas.setPaint(fillColour);
localCanvas.fill(shape); localCanvas.fill(shape);
...@@ -210,26 +237,9 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str ...@@ -210,26 +237,9 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setInformation(String information) { public void setInformation(String information) {
HTMLDocument html = (HTMLDocument) htmlEditor.createDefaultDocument();
if (baseUrl != null) {
html.setBase(baseUrl);
}
editor.setDocument(html);
editor.setText(information);
rendered = new BufferedImage((int) shapeBounds.getWidth() - (2 * insetBorder), (int) shapeBounds.getHeight() - (2 * insetBorder), BufferedImage.TYPE_INT_ARGB);
Graphics2D offscreen = rendered.createGraphics();
offscreen.setRenderingHints(renderingHints);
AffineTransform translate = AffineTransform.getTranslateInstance(-shapeBounds.getX(), -shapeBounds.getY());
offscreen.setClip(translate.createTransformedShape(shape));
editor.paint(offscreen);
offscreen.dispose();
rendered = this.renderHtml(information, shape);
renderedCentre = new Point(((float) rendered.getWidth() / 2), ((float) rendered.getHeight() / 2), 0f, ScreenCoordinates.class); renderedCentre = new Point(((float) rendered.getWidth() / 2), ((float) rendered.getHeight() / 2), 0f, ScreenCoordinates.class);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
...@@ -99,24 +99,6 @@ public class TextBox extends Corona implements ContextEventListener, Information ...@@ -99,24 +99,6 @@ public class TextBox extends Corona implements ContextEventListener, Information
return; return;
} }
// centre.toScreenCoordinates();
// if (initialTranslation != null) {
// initialTranslation.toScreenCoordinates();
// }
//
// Point drawAt = centre.add(initialTranslation);
//
// AffineTransform rotation = new AffineTransform();
// rotation.rotate(rotateWithHandle ? drawAt.getAngle() : initialTranslation != null ?
// initialTranslation.getAngle() : 0, centre.getX(), centre.getY());
// rotation.transform(drawAt, drawAt);
//
// if (Double.compare(initialRotation, 0d) != 0) {
// AffineTransform transformation = new AffineTransform();
// transformation.rotate(initialRotation, drawAt.getX(), drawAt.getY());
// canvas.setTransform(transformation);
// }
AffineTransform restore = canvas.getTransform(); AffineTransform restore = canvas.getTransform();
AffineTransform transform = this.getTransform(null); AffineTransform transform = this.getTransform(null);
canvas.setTransform(transform); canvas.setTransform(transform);
...@@ -127,7 +109,6 @@ public class TextBox extends Corona implements ContextEventListener, Information ...@@ -127,7 +109,6 @@ public class TextBox extends Corona implements ContextEventListener, Information
TextHelper.configure(font, fontSize, colour, centred); TextHelper.configure(font, fontSize, colour, centred);
TextHelper.drawText(canvas, new Point(0f, 0f, 0f, ScreenCoordinates.class), lineWidth, textToShow); TextHelper.drawText(canvas, new Point(0f, 0f, 0f, ScreenCoordinates.class), lineWidth, textToShow);
canvas.setTransform(restore); canvas.setTransform(restore);
} }
......
...@@ -60,15 +60,7 @@ public class Line extends InformationFeed { ...@@ -60,15 +60,7 @@ public class Line extends InformationFeed {
if ((origin == null) || (ending == null)) if ((origin == null) || (ending == null))
return; return;
// Shape previousLine = null;
// if ((previousOrigin != null) && (previousEnding != null))
// {
// previousLine = new Line2D.Double(new Point2D.Double(previousOrigin.x, previousOrigin.y),
// new Point2D.Double(previousEnding.x, previousEnding.y));
// }
//
Stroke pen = new BasicStroke(strokeWidth); Stroke pen = new BasicStroke(strokeWidth);
// canvas.clip(pen.createStrokedShape(previousLine));
Shape line = new Line2D.Double(new Point2D.Double(origin.x, origin.y), new Point2D.Double(ending.x, ending.y)); Shape line = new Line2D.Double(new Point2D.Double(origin.x, origin.y), new Point2D.Double(ending.x, ending.y));
canvas.setStroke(pen); canvas.setStroke(pen);
......
...@@ -21,6 +21,9 @@ import lu.list.itis.dkd.tui.utility.ScreenCoordinates; ...@@ -21,6 +21,9 @@ import lu.list.itis.dkd.tui.utility.ScreenCoordinates;
import lu.list.itis.dkd.tui.widget.corona.Corona; import lu.list.itis.dkd.tui.widget.corona.Corona;
import lu.list.itis.dkd.tui.widget.corona.ShapeFactory; import lu.list.itis.dkd.tui.widget.corona.ShapeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Shape; import java.awt.Shape;
...@@ -75,8 +78,7 @@ public class TouchManager { ...@@ -75,8 +78,7 @@ public class TouchManager {
/* LATCHED_STATE */ {LATCHED_STATE, DRAGGED_STATE, RELEASED_STATE} /* LATCHED_STATE */ {LATCHED_STATE, DRAGGED_STATE, RELEASED_STATE}
}; };
// private static final Logger LOGGER = private static final Logger LOGGER = LoggerFactory.getLogger(TouchManager.class.getSimpleName());
// LoggerFactory.getLogger(TouchManager.class.getSimpleName());
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// *************************************************************************** // ***************************************************************************
...@@ -113,8 +115,9 @@ public class TouchManager { ...@@ -113,8 +115,9 @@ public class TouchManager {
newState = (isLatching) ? LATCHING_TRANSITIONS[oldState][event] newState = (isLatching) ? LATCHING_TRANSITIONS[oldState][event]
: NON_LATCHING_TRANSITIONS[oldState][event]; : NON_LATCHING_TRANSITIONS[oldState][event];
// LOGGER.info("State Change [{}] =[{}]=> [{}]", oldState, event, newState); //$NON-NLS-1$ if (LOGGER.isDebugEnabled()) {
LOGGER.debug("State Change [{}] =[{}]=> [{}]", oldState, event, newState); //$NON-NLS-1$
}
return newState; return newState;
} }
...@@ -215,6 +218,9 @@ public class TouchManager { ...@@ -215,6 +218,9 @@ public class TouchManager {
this.touchStates.put(touchId, newState); this.touchStates.put(touchId, newState);
if (touched) { if (touched) {
this.touchPositions.put(touchId, event.getPosition()); this.touchPositions.put(touchId, event.getPosition());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Cursor {} touched @ Position [{}]", touchId, event.getPosition()); //$NON-NLS-1$
}
} }
return touched; return touched;
...@@ -280,6 +286,10 @@ public class TouchManager { ...@@ -280,6 +286,10 @@ public class TouchManager {
if (released) { if (released) {
this.touchStates.remove(touchId); this.touchStates.remove(touchId);
this.touchPositions.remove(touchId); this.touchPositions.remove(touchId);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Cursor {} released @ Position [{}]", touchId, event.getPosition()); //$NON-NLS-1$
}
} else { } else {
this.touchStates.put(touchId, newState); this.touchStates.put(touchId, newState);
this.touchPositions.put(touchId, event.getPosition()); this.touchPositions.put(touchId, event.getPosition());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment