001package systems.dmx.core.impl;
002
003import systems.dmx.core.model.TopicModel;
004import systems.dmx.core.model.topicmaps.TopicViewModel;
005import systems.dmx.core.model.topicmaps.ViewProperties;
006
007import org.codehaus.jettison.json.JSONObject;
008
009
010
011// TODO: rethink inheritance. Can we have a common "ObjectViewModel" for both, topics and assocs?
012// Is this a case for Java 8 interfaces, which can have a default implementation?
013class TopicViewModelImpl extends TopicModelImpl implements TopicViewModel {
014
015    // --- Instance Variables ---
016
017    private ViewProperties viewProps;
018
019    // --- Constructors ---
020
021    TopicViewModelImpl(TopicModelImpl topic, ViewProperties viewProps) {
022        super(topic);
023        this.viewProps = viewProps;
024    }
025
026    // --- Public Methods ---
027
028    public ViewProperties getViewProperties() {
029        return viewProps;
030    }
031
032    // ---
033
034    public int getX() {
035        return viewProps.getInt("dmx.topicmaps.x");
036    }
037
038    public int getY() {
039        return viewProps.getInt("dmx.topicmaps.y");
040    }
041
042    public boolean getVisibility() {
043        return viewProps.getBoolean("dmx.topicmaps.visibility");
044    }
045
046    // ---
047
048    @Override
049    public JSONObject toJSON() {
050        try {
051            return super.toJSON().put("viewProps", viewProps.toJSON());
052        } catch (Exception e) {
053            throw new RuntimeException("Serialization failed", e);
054        }
055    }
056}