Commit 3fecb764 authored by Nico Mack's avatar Nico Mack

Added Scene Content class

parent 7d666092
package lu.list.itis.dkd.tui.content;
import lu.list.itis.dkd.tui.content.builder.BaseSceneBuilder;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class Scene extends Content implements Drawable {
private int drawPriority;
private BufferedImage backdrop;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s)
// ***************************************************************************
// ---------------------------------------------------------------------------
public Scene(BaseSceneBuilder<?> builder) {
super(builder.identifier);
this.backdrop = builder.backdrop;
this.drawPriority = builder.drawPriority;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s)
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public void initialise() {}
// ---------------------------------------------------------------------------
@Override
public void paint(Graphics2D canvas) {
if (backdrop != null) {
canvas.drawImage(backdrop, 0, 0, null);
}
}
// ---------------------------------------------------------------------------
@Override
public int compareTo(Drawable drawable) {
int comparison = -1;
if (drawable != null) {
comparison = Integer.compare(drawPriority, drawable.getDrawPriority());
}
return comparison;
}
// ---------------------------------------------------------------------------
@Override
public int getDrawPriority() {
return drawPriority;
}
}
package lu.list.itis.dkd.tui.content.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.content.Scene;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.utility.StringUtils;
import com.google.common.base.Strings;
import org.jdom2.Element;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
* @param <B>
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class BaseSceneBuilder<B extends BaseSceneBuilder<B>> extends ContentBuilder<B> {
public int drawPriority;
public BufferedImage backdrop;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public BaseSceneBuilder() {
drawPriority = 0;
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize. This constructor will add all associated handles as keys in
* the position map.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public BaseSceneBuilder(Element rootElement) throws BuildException {
super(rootElement);
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* Constructor initializing all fields from an {@link Element} containing as child elements all the
* information on fields to initialize. This constructor will add all associated handles as keys in
* the position map.
*
* @param rootElement
* The element harbouring, on child nodes, the necessary information to initialize all fields
* of the builder.
* @param context
* @param callback
* @throws BuildException
* Thrown when any of the fields fail to populate due to an error in reading information
* from the XML file.
*/
// ---------------------------------------------------------------------------
public BaseSceneBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
drawPriority = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.DRAW_PRIORITY_NODE, BootstrappingUtils.OPTIONAL, 0, context);
String imagePath = BootstrappingUtils.getContentAsString(rootElement, Externalization.IMAGE_ELEMENT, BootstrappingUtils.OPTIONAL, null, context);
if (!Strings.isNullOrEmpty(imagePath)) {
try {
backdrop = ImageIO.read(new File(imagePath));
} catch (IOException exception) {
throw new BuildException(StringUtils.build("The image {} could not be read!", imagePath), exception); //$NON-NLS-1$
}
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public abstract Scene build() throws BuildException;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
package lu.list.itis.dkd.tui.content.builder;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.content.Scene;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.Element;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public class SceneBuilder extends BaseSceneBuilder<SceneBuilder> {
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public SceneBuilder() {
super();
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public SceneBuilder(Element rootElement) throws BuildException {
super(rootElement);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public SceneBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
super(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public Scene build() throws BuildException {
return new Scene(this);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
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