Commit b6c2841b authored by Nico Mack's avatar Nico Mack

Changes required for upcoming update of COPSE project

parent aec8d03f
......@@ -55,7 +55,7 @@ cleanup.use_this_for_non_static_field_access_only_if_necessary=true
cleanup.use_this_for_non_static_method_access=true
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
cleanup.use_type_arguments=false
cleanup_profile=_LIST
cleanup_profile=_LIST Code Profile
cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
......
......@@ -17,7 +17,6 @@
package lu.list.itis.dkd.tui;
import lu.list.itis.dkd.tui.bootstrapping.StageSetBootstrapper;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.content.Stage;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.widget.BaseWidget;
......@@ -43,8 +42,14 @@ import java.util.concurrent.ConcurrentHashMap;
public class StageManager {
protected TangibleContentManager contentManager;
protected static volatile ConcurrentHashMap<Integer, Stage> stageMap = new ConcurrentHashMap<>();
// ***************************************************************************
// * Constants
// ***************************************************************************
private static final int TANGIBLE_INTERFACE_STAGE_ID = 0;
protected static final Logger LOGGER = LoggerFactory.getLogger(StageManager.class.getSimpleName());
......@@ -86,10 +91,25 @@ public class StageManager {
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param contentManager
*/
// ---------------------------------------------------------------------------
public void setContentManager(TangibleContentManager contentManager) {
this.contentManager = contentManager;
for (Entry<Integer, Stage> entry : stageMap.entrySet()) {
Stage stage = entry.getValue();
stage.setContentManager(contentManager);
}
}
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public void doneLoading() {
for (Entry<Integer, Stage> entry : stageMap.entrySet()) {
Stage stage = entry.getValue();
......@@ -130,16 +150,16 @@ public class StageManager {
*/
// ---------------------------------------------------------------------------
public void setContent(Collection<Entry<String, Content>> contents) {
if (contents != null) {
for (Entry<String, Content> entry : contents) {
Content content = entry.getValue();
if (stageMap.containsKey(content.getStageId())) {
stageMap.get(content.getStageId()).addToStage(entry.getKey(), content);
}
}
}
}
// public void setContent(Collection<Entry<String, Content>> contents) {
// if (contents != null) {
// for (Entry<String, Content> entry : contents) {
// Content content = entry.getValue();
// if (stageMap.containsKey(content.getStageId())) {
// stageMap.get(content.getStageId()).addToStage(entry.getKey(), content);
// }
// }
// }
// }
// ---------------------------------------------------------------------------
/**
......
......@@ -252,7 +252,8 @@ public abstract class TangibleApplication {
*/
public void setContentManager(TangibleContentManager contentManager) {
this.contentManager = contentManager;
stageManager.setContent(contentManager.getContents());
stageManager.setContentManager(contentManager);
// stageManager.setContent(contentManager.getContents());
}
/**
......
......@@ -23,6 +23,7 @@ package lu.list.itis.dkd.tui;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.content.Drawable;
import lu.list.itis.dkd.tui.event.ContentEventListener;
import com.google.common.collect.HashMultimap;
......@@ -31,9 +32,8 @@ import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -70,65 +70,66 @@ public abstract class TangibleContentManager implements ContentEventListener {
}
/**
* Method to sort all content by the functionality it offers as given by a parent class or
* interface.
*
* TODO DESIGN This method is not scalable. It needs to be redesigned.
*
* @param desiredParent
* The class that all content we filter by should implement or extend.
* @return A {@link ConcurrentHashMap} of content that implements the desired interface or
* extends the desired class.
* @param clazz
* @param stageId
* @return
*/
@SuppressWarnings("unchecked")
public synchronized <I> Map<String, I> getContent(Class<I> desiredParent) {
ConcurrentHashMap<String, I> implementingContent = new ConcurrentHashMap<>();
// if (desiredParent.equals(Zoomable.class)) {
// for (Content content : contentMapping.values()) {
// if (content instanceof Zoomable) {
// implementingContent.put(content.getIdentifier(), (I) content);
// }
// }
// }
//
// if (desiredParent.equals(InformationProvider.class)) {
// for (Content content : contentMapping.values()) {
// if (content instanceof InformationProvider) {
// implementingContent.put(content.getIdentifier(), (I) content);
// }
// }
// }
public <T> List<T> getContent(Class<T> clazz, Integer stageId) {
List<T> results = new ArrayList<>();
for (Content content : contentMapping.values()) {
if (desiredParent.isAssignableFrom(content.getClass())) {
implementingContent.put(content.getIdentifier(), (I) content);
if (clazz.isAssignableFrom(content.getClass())) {
if ((stageId == null) || (stageId.equals(content.getStageId()))) {
results.add((T) content);
}
}
}
return results;
}
return implementingContent;
}
/**
* Method used to reorder the collection of content instances by using their comparator.
*
* @return A sorted collection of content.
*/
public synchronized Collection<Content> reorder() {
ArrayList<Content> orderedContent = new ArrayList<>(contentMapping.values());
Collections.sort(orderedContent);
return orderedContent;
// public synchronized Collection<Content> reorder() {
// ArrayList<Content> orderedContent = new ArrayList<>(contentMapping.values());
// Collections.sort(orderedContent);
// return orderedContent;
// }
/**
* Method used to return a sublist of {@link Content} instances that by the business logic,
* should be drawn.
*
* @return A collection of {@link Content} instances that are to be drawn.
*/
public Collection<Drawable> getDrawableContents() {
List<Drawable> drawableContents = this.getContent(Drawable.class, null);
Collections.sort(drawableContents);
return drawableContents;
}
/**
* Method used to return a sublist of {@link Content} instances that by the business logic,
* should be drawn.
*
* @param stageId
* specifies the Id of the stage to filter drawable content for.s
*
* @return A collection of {@link Content} instances that are to be drawn.
*/
public abstract Collection<Content> getDrawableContents();
public Collection<Drawable> getDrawableContents(int stageId) {
List<Drawable> drawableContents = this.getContent(Drawable.class, stageId);
Collections.sort(drawableContents);
return drawableContents;
}
/**
* Method used to map a handle ID to a {@link Content} instance.
......
......@@ -71,12 +71,6 @@ public class TangibleInterfaceManager extends Stage {
/** The URI of the calibration file as qualified from this file. */
protected String calibrationFileURI = "calibration.xml"; //$NON-NLS-1$
/** Width of the frame to display the visualisation in. */
// private int windowWidth;
/** Height of the frame to display the visualisation in. */
// private int windowHeight;
/** Field indicating whether the application should be shown full screen or not. */
protected boolean fullscreen;
......@@ -91,9 +85,6 @@ public class TangibleInterfaceManager extends Stage {
/** Index pointer used to switch between different configuration points. */
protected int configurationPoint = 0;
/** A reference to the hosting application to access different managers if needed. */
// private volatile TangibleApplication tangibleApplication;
private Area clippingRegion;
private Area fullScreenArea;
......
......@@ -36,8 +36,8 @@ import java.util.Objects;
* @version 2.3.0
*/
@NonNullByDefault
public abstract class Content implements Comparable<Content> {
protected int drawPriority = 50;
public abstract class Content { // implements Comparable<Content> {
// protected int drawPriority = 50;
protected int stageId = 0;
protected String identifier;
protected Area clippingRegion;
......@@ -64,12 +64,11 @@ public abstract class Content implements Comparable<Content> {
*/
// ---------------------------------------------------------------------------
@Override
public int compareTo(@Nullable Content content) {
if (content == null)
throw new NullPointerException();
return Integer.compare(getDrawPriority(), content.getDrawPriority());
}
// public int compareTo(@Nullable Content content) {
// if (content == null)
// throw new NullPointerException();
// return Integer.compare(getDrawPriority(), content.getDrawPriority());
// }
// ---------------------------------------------------------------------------
......@@ -82,7 +81,7 @@ public abstract class Content implements Comparable<Content> {
if (object instanceof Content) {
Content other = (Content) object;
equals &= (getDrawPriority() == other.getDrawPriority());
// equals &= (getDrawPriority() == other.getDrawPriority());
equals &= (getStageId() == other.getStageId());
if (identifier != null) {
......@@ -101,7 +100,8 @@ public abstract class Content implements Comparable<Content> {
@Override
public int hashCode() {
return Objects.hash(drawPriority, stageId, identifier);
// return Objects.hash(drawPriority, stageId, identifier);
return Objects.hash(stageId, identifier);
}
/**
......@@ -112,9 +112,9 @@ public abstract class Content implements Comparable<Content> {
* @return The draw priority of this content instance.
*/
protected int getDrawPriority() {
return drawPriority;
}
// protected int getDrawPriority() {
// return drawPriority;
// }
/**
* Simple getter method for identifier.
......@@ -156,9 +156,9 @@ public abstract class Content implements Comparable<Content> {
* The variable determining order depending on the implementation.
*/
public void updateDrawPriority(int order) {
this.drawPriority = order;
}
// public void updateDrawPriority(int order) {
// this.drawPriority = order;
// }
/**
* Method used for initialising all fields necessary for the content to function.
......
......@@ -16,6 +16,8 @@
*/
package lu.list.itis.dkd.tui.content;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import java.awt.Graphics2D;
/**
......@@ -23,9 +25,19 @@ import java.awt.Graphics2D;
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public interface Drawable {
public interface Drawable extends Comparable<Drawable> {
/**
* @param canvas
*/
public void paint(Graphics2D canvas);
@Override
public int compareTo(@Nullable Drawable drawable);
/**
* @return
*/
public int getDrawPriority();
}
......@@ -17,6 +17,7 @@
package lu.list.itis.dkd.tui.content;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.TangibleContentManager;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
......@@ -27,8 +28,6 @@ import lu.list.itis.dkd.tui.utility.StringUtils;
import lu.list.itis.dkd.tui.widget.BaseWidget;
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.jdom2.Element;
import org.pushingpixels.trident.Timeline.RepeatBehavior;
......@@ -76,8 +75,12 @@ public class Stage extends JComponent {
protected transient GraphicsDevice device;
protected JFrame window;
protected TangibleContentManager contentManager;
protected volatile ConcurrentHashMap<Integer, BaseWidget> objects = new ConcurrentHashMap<>();
protected transient volatile Multimap<String, Content> contents = HashMultimap.create();
// protected transient volatile Multimap<String, Content> contents = HashMultimap.create();
// ***************************************************************************
// * Constants *
......@@ -219,15 +222,13 @@ public class Stage extends JComponent {
// ---------------------------------------------------------------------------
@SuppressWarnings("unchecked")
protected <T> List<T> getContent(Class<T> clazz) {
List<T> results = new ArrayList<>();
for (Content content : contents.values()) {
if (clazz.isAssignableFrom(content.getClass())) {
results.add((T) content);
}
if (contentManager != null) {
results = contentManager.getContent(clazz, this.stageId);
}
return results;
}
......@@ -239,10 +240,18 @@ public class Stage extends JComponent {
timeline.playLoop(RepeatBehavior.LOOP);
}
/**
* @param contentManager
*/
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
public void setContentManager(TangibleContentManager contentManager) {
this.contentManager = contentManager;
}
// ---------------------------------------------------------------------------
/**
* Method used to set up a {@link JFrame} and all corresponding components to be displayed.
......@@ -303,7 +312,10 @@ public class Stage extends JComponent {
/** Method used to initialise the content. */
public void initAll() {
contents.values().forEach(item -> item.initialise());
if (contentManager != null) {
Collection<Content> contents = contentManager.getContent(Content.class, this.stageId);
contents.forEach(item -> item.initialise());
}
}
// ---------------------------------------------------------------------------
......@@ -340,12 +352,14 @@ public class Stage extends JComponent {
*/
// ---------------------------------------------------------------------------
public void addToStage(String identifier, Content content) {
Preconditions.checkArgument(content != null, "The passed object cannot be null!"); //$NON-NLS-1$
Preconditions.checkArgument(content.getStageId() == this.stageId, "The passed content {} is not intended to be added to stage with ID {}!", identifier, stageId); //$NON-NLS-1$
this.contents.put(identifier, content);
}
// public void addToStage(String identifier, Content content) {
// Preconditions.checkArgument(content != null, "The passed object cannot be null!");
// //$NON-NLS-1$
// Preconditions.checkArgument(content.getStageId() == this.stageId, "The passed content {} is
// not intended to be added to stage with ID {}!", identifier, stageId); //$NON-NLS-1$
//
// this.contents.put(identifier, content);
// }
// ---------------------------------------------------------------------------
/**
......
......@@ -16,6 +16,9 @@
*/
package lu.list.itis.dkd.tui.utility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -30,7 +33,11 @@ import java.util.regex.Pattern;
public class StringUtils {
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("(\\{\\})", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("((?<!\\\\)\\{(?<!\\\\)\\})", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Pattern ESCAPED_PATTERN = Pattern.compile("\\\\([{}])", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
private static final Logger LOGGER = LoggerFactory.getLogger(StringUtils.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -38,6 +45,30 @@ public class StringUtils {
// ***************************************************************************
// ---------------------------------------------------------------------------
public static Integer getIntegerValue(String valueAsString) {
Integer value = null;
try {
value = Integer.parseInt(valueAsString);
} catch (NumberFormatException exception) {
LOGGER.error("Failed to convert {} to an integer value!", valueAsString); //$NON-NLS-1$
}
return value;
}
// ---------------------------------------------------------------------------
public static Double getDoubleValue(String valueAsString) {
Double value = null;
try {
value = Double.parseDouble(valueAsString);
} catch (NumberFormatException exception) {
LOGGER.error("Failed to convert {} to an double value!", valueAsString); //$NON-NLS-1$
}
return value;
}
// ---------------------------------------------------------------------------
public static String build(String template, Object... parameters) {
if (template == null)
......@@ -61,6 +92,18 @@ public class StringUtils {
}
builder.append(template.substring(position));
String build = builder.toString();
builder = new StringBuilder();
Matcher escapeMatcher = ESCAPED_PATTERN.matcher(build);
position = 0;
while (escapeMatcher.find()) {
builder.append(build.substring(position, escapeMatcher.start()));
builder.append(escapeMatcher.group(1));
position = escapeMatcher.end();
}
builder.append(build.substring(position));
return builder.toString();
}
......
......@@ -30,7 +30,7 @@ import static org.junit.Assert.fail;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.adapter.TuiAdapter;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.content.Drawable;
import lu.list.itis.dkd.tui.event.ContentEvent;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.IdMapper;
......@@ -226,7 +226,7 @@ public class TangibleApplicationTest {
* {@inheritDoc}
*/
@Override
public Collection<Content> getDrawableContents() {
public Collection<Drawable> getDrawableContents() {
fail("Method not implemented in mock!"); //$NON-NLS-1$
return new HashSet<>();
}
......
......@@ -25,7 +25,7 @@ import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.content.Drawable;
import lu.list.itis.dkd.tui.event.ContentEvent;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.widget.BaseWidget;
......@@ -210,7 +210,7 @@ public class TangibleInterfaceManagerTest {
* {@inheritDoc}
*/
@Override
public Collection<Content> getDrawableContents() {
public Collection<Drawable> getDrawableContents() {
// fail("Method not implemented in mock!");
return new HashSet<>();
}
......
......@@ -58,6 +58,11 @@ public class StringUtilsTest {
completed = StringUtils.build(template, param2);
assertEquals("Mary had a lamb", completed);
template = "The answer is \\{{}\\}";
String[] param3 = {"42"};
completed = StringUtils.build(template, param3);
assertEquals("The answer is {42}", completed);
completed = StringUtils.build("Careful with that axe eugene!", null);
assertEquals("Careful with that axe eugene!", completed);
......
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