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

Minor code cleanup

parent a644e451
......@@ -93,8 +93,8 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
}
/**
* Method called to initialize bootstrapping from a previously provided XML file. The method
* will create all objects, cursors, and blobs.
* Method called to initialize bootstrapping from a previously provided XML file. The method will
* create all objects, cursors, and blobs.
*
* @throws BuildException
* Thrown when one or more of the tangibles failed to build.
......@@ -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
* from template specified in bootstrap file. In case multiple cursor templates are encountered,
* only the first one will taken into account. This may change in future release, allowing to
* assign different cursor templates depending on the cursor ID.
* Method called to create a new instance of a cursor object. New cursor object will be created from
* template specified in bootstrap file. In case multiple cursor templates are encountered, only the
* first one will taken into account. This may change in future release, allowing to assign
* different cursor templates depending on the cursor ID.
*
* @param cursorId
* specifies the ID of the cursor object to create.
......@@ -154,29 +154,27 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
Element rootNode = bootstrap.getRootElement();
List<Element> connectionsRootNodes = rootNode.getChildren(Externalization.CONNECTIONS_NODE); // $NON-NLS-1$
if (connectionsRootNodes != null) {
for (Element connectionsNode : connectionsRootNodes)
for (Element connectionsNode : connectionsRootNodes) {
if (connectionsNode != null) {
for (Element connectionNode : connectionsNode.getChildren()) {
switch (connectionNode.getName()) {
case "tethers": //$NON-NLS-1$
this.loadTethers(connectionNode);
break;
default:
throw new BuildException(StringUtils.build("Unrecognized connection type {} !", connectionsNode.getName())); //$NON-NLS-1$ //$NON-NLS-2$
if (Externalization.TETHERS_NODE.equals(connectionNode.getName())) {
this.loadTethers(connectionNode);
} else {
throw new BuildException(StringUtils.build("Unrecognized connection type {} !", connectionsNode.getName())); //$NON-NLS-1$
}
}
}
}
}
}
/**
* Note: When this method encounters an exception, it clears all previously loaded objects from
* the list.
* Note: When this method encounters an exception, it clears all previously loaded objects from the
* list.
*
* @param objectRootNode
* The root node holding the <code>object</code> node(s).
* @throws BuildException
* TODO
*/
private void loadTethers(Element tetherRootNode) throws BuildException {
List<Element> tetherNodes = tetherRootNode.getChildren(Externalization.TETHER_NODE);
......@@ -192,14 +190,14 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
LOGGER.error("One of the desired tethers could not be build!", e); //$NON-NLS-1$
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
* bootstrapping context, a map holding the names and the values of variables for interpolation
* of variable properties in template definition.
* bootstrapping context, a map holding the names and the values of variables for interpolation of
* variable properties in template definition.
*
* @param templateNode
* specifies the template node to build the cursor from
......@@ -231,8 +229,8 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
/**
* 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
* of variable properties in template definition.
* bootstrapping context, a map holding the names and the values of variables for interpolation of
* variable properties in template definition.
*
* @param templateNode
* specifies the template node to build the widget from
......@@ -263,8 +261,8 @@ public class TangibleObjectBootstrapper extends TangibleObjectManager {
/**
* Note: When this method encounters an exception, it clears all previously loaded objects from
* the list.
* Note: When this method encounters an exception, it clears all previously loaded objects from the
* list.
*
* @param objectRootNode
* The root node holding the <code>object</code> node(s).
......@@ -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
* call.
* Method used to determine the appropriate builder for a given object and then issue a build call.
*
* @param objectNode
* The node from a larger document that contains, as children, all the necessary
* information to resolve the correct builder and build the final widget.
* The node from a larger document that contains, as children, all the necessary information
* to resolve the correct builder and build the final widget.
* @param context
* @param callback
* @return The final widget as defined by the children of the element node.
......
......@@ -56,8 +56,8 @@ public class AnimatedShapeCorona extends AnimatedCorona {
// * Constants *
// ***************************************************************************
private static final String OPACITY = "opacity"; //$NON-NLS-1$
private static final String SCALE = "scale"; //$NON-NLS-1$
private static final String PROPERTY_OPACITY = "opacity"; //$NON-NLS-1$
private static final String PROPERTY_SCALE = "scale"; //$NON-NLS-1$
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -117,9 +117,9 @@ public class AnimatedShapeCorona extends AnimatedCorona {
List<AnimationProperty<?>> properties = this.getAnimationProperties();
for (AnimationProperty<?> property : properties) {
if (OPACITY.equals(property.getProperty())) {
if (PROPERTY_OPACITY.equals(property.getProperty())) {
this.setOpacity((double) property.getStart());
} else if (SCALE.equals(property.getProperty())) {
} else if (PROPERTY_SCALE.equals(property.getProperty())) {
this.setScale((double) property.getStart());
}
}
......
......@@ -33,6 +33,7 @@ import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
......@@ -159,6 +160,36 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
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 *
......@@ -179,13 +210,9 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
if (this.opacity < 1.0f)
localCanvas.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
AffineTransform transform = this.getTransform(null);
localCanvas.setTransform(transform);
// Shape transformedShape = transform.createTransformedShape(shape);
localCanvas.setPaint(fillColour);
localCanvas.fill(shape);
......@@ -210,26 +237,9 @@ public class HtmlBox extends SelectableCorona implements InformationReceiver<Str
/** {@inheritDoc} */
@Override
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);
}
// ---------------------------------------------------------------------------
......
......@@ -99,24 +99,6 @@ public class TextBox extends Corona implements ContextEventListener, Information
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 transform = this.getTransform(null);
canvas.setTransform(transform);
......@@ -127,7 +109,6 @@ public class TextBox extends Corona implements ContextEventListener, Information
TextHelper.configure(font, fontSize, colour, centred);
TextHelper.drawText(canvas, new Point(0f, 0f, 0f, ScreenCoordinates.class), lineWidth, textToShow);
canvas.setTransform(restore);
}
......
......@@ -60,15 +60,7 @@ public class Line extends InformationFeed {
if ((origin == null) || (ending == null))
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);
// canvas.clip(pen.createStrokedShape(previousLine));
Shape line = new Line2D.Double(new Point2D.Double(origin.x, origin.y), new Point2D.Double(ending.x, ending.y));
canvas.setStroke(pen);
......
......@@ -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.ShapeFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
......@@ -75,8 +78,7 @@ public class TouchManager {
/* LATCHED_STATE */ {LATCHED_STATE, DRAGGED_STATE, RELEASED_STATE}
};
// private static final Logger LOGGER =
// LoggerFactory.getLogger(TouchManager.class.getSimpleName());
private static final Logger LOGGER = LoggerFactory.getLogger(TouchManager.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -113,8 +115,9 @@ public class TouchManager {
newState = (isLatching) ? 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;
}
......@@ -215,6 +218,9 @@ public class TouchManager {
this.touchStates.put(touchId, newState);
if (touched) {
this.touchPositions.put(touchId, event.getPosition());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Cursor {} touched @ Position [{}]", touchId, event.getPosition()); //$NON-NLS-1$
}
}
return touched;
......@@ -280,6 +286,10 @@ public class TouchManager {
if (released) {
this.touchStates.remove(touchId);
this.touchPositions.remove(touchId);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Cursor {} released @ Position [{}]", touchId, event.getPosition()); //$NON-NLS-1$
}
} else {
this.touchStates.put(touchId, newState);
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