--- /dev/null
+package org.splat.simer;
+
+import org.splat.som.KnowledgeElement;
+import org.splat.wapp.PopupMenu;
+
+
+public class KnowledgeElementFacade {
+
+ private KnowledgeElement my;
+ private State state;
+ private String value;
+ private PopupMenu popup;
+
+ private enum State { closed, open }
+
+// ==============================================================================================================================
+// Constructor
+// ==============================================================================================================================
+
+ public KnowledgeElementFacade (KnowledgeElement represented) {
+// ------------------------------------------------------------
+ my = represented;
+ state = State.closed;
+
+ this.refresh(); // Initializes the presentation of my knowledge
+ }
+
+// ==============================================================================================================================
+// Public member functions
+// ==============================================================================================================================
+
+ public void develop () {
+// ----------------------
+ state = State.open;
+ }
+
+ public void reduce () {
+// ---------------------
+ state = State.closed;
+ }
+
+// ==============================================================================================================================
+// Getters
+// ==============================================================================================================================
+
+ public String getFullValue () {
+// -----------------------------
+ return my.getValue().replaceAll("'", "‘").replaceAll("\"", """);
+ }
+ public String getIndex () {
+// -------------------------
+ return String.valueOf(my.getIndex());
+ }
+ public PopupMenu getPopup () {
+// ----------------------------
+ popup.setContext("feedbex", my); // Cannot be done at construction because pop-ups are shared
+ return popup;
+ }
+ public String getPresentationState () {
+// -------------------------------------
+ return state.toString();
+ }
+ public String getProgressState () {
+// ---------------------------------
+ return my.getProgressState().toString();
+ }
+ public String getTitle () {
+// -------------------------
+ return my.getTitle();
+ }
+ public String getValue () {
+// -------------------------
+ if (state == State.closed) return value;
+ else return my.getValue();
+ }
+ public boolean isFacadeOf (KnowledgeElement represented) {
+// --------------------------------------------------------
+ return my.equals(represented);
+ }
+
+// ==============================================================================================================================
+// Protected services
+// ==============================================================================================================================
+
+ protected void refresh () {
+// -------------------------
+ String[] tags = {"<b>", "<i>", "<u>", "<sup>", "<sub>" };
+
+ popup = ApplicationSettings.getPopupMenu("feedbex");
+ value = my.getValue();
+
+// One line extract of the knowledge value
+ int size = 70 + 3; // Maximum length displayable on 1 line, including the starting <p> tag
+ int i;
+ for (i=0; i<tags.length; i++) {
+ int pos = value.indexOf(tags[i]);
+ if (pos > -1 && pos < size) size = size + 2*tags[i].length() + 1; // Inclusion of the open and close tags
+ }
+ if (value.startsWith("<p>")) {
+ int endex = value.indexOf("</p>");
+ if ((i=value.indexOf("<br")) > 0) if (i < endex) endex = i;
+ if ((i=value.indexOf("<ul>")) > 0) if (i < endex) endex = i;
+ if ((i=value.indexOf("<ol>")) > 0) if (i < endex) endex = i;
+ int next = endex + 4; // Index of the next paragraph, if exist
+ if (endex > size) {
+ endex = size;
+ char endchar = value.charAt(endex);
+ if (endchar == '-' || endchar == ',' || endchar == ';' || endchar == '.') endex += 1;
+ else if (endchar != ' ') while (--endex > 0) {
+ endchar = value.charAt(endex);
+ if (endchar == ' ') break;
+ if (endchar == '-' || endchar == ',' || endchar == ';' || endchar == '.') {
+ endex += 1;
+ break;
+ }
+ }
+ }
+ else size = 0;
+
+ value = value.substring(3, endex).trim();
+ if ((i=value.lastIndexOf("b>")) > 0) if (value.charAt(i-1) == '<') value = value + "</b>";
+ if ((i=value.lastIndexOf("i>")) > 0) if (value.charAt(i-1) == '<') value = value + "</i>";
+ if ((i=value.lastIndexOf("u>")) > 0) if (value.charAt(i-1) == '<') value = value + "</u>";
+ if (my.getValue().length() > next || size > 0) value = value + " ...";
+ }
+ else {
+ if (value.length() > size-3) value = value.substring(0, size-3) + " ...";
+ }
+ }
+}
\ No newline at end of file