3 Replies Latest reply: Feb 23, 2012 5:02 PM by ArtashesGamarian RSS

    New Markup using JVue applet with default colors that override .ini setting

    897480
      Goal: To load the JVue applet initially populated with a given document(drawing) and if there are no markups at all:
      •     Give the user a markup with a custom filename
      •     Configure the applet so that all markups:
      o     Have a specific custom outline color that overrides setting in allusers.ini
      o     Have a specific custom fill color that overrides setting in allusers.ini

      Problem: The following code achieves everything except setting the custom colors via the method configureMarkups().
      •     If configureMarkups() is called, the applet will not save a valid Markup file (it is zero bytes).
      •     If configureMarkups() is simply not called, the applet will save a valid Markup file (but the markups are not the desired color)
      •     See the text following this code for a more detailed process flow:

      package com.kpe.esd.applets;

      import java.awt.Color;

      import com.cimmetry.core.Property;
      import com.cimmetry.markupbean.Markup;
      import com.cimmetry.markupbean.MarkupBean;
      import com.cimmetry.markupbean.MarkupEntitySpec;
      import com.cimmetry.vuebean.event.VueEvent;
      import com.cimmetry.vuebean.event.VueFileListener;
      import com.cimmetry.vuebean.event.VueMarkupListener;
      import com.cimmetry.vuebean.event.VueModelEvent;
      import com.cimmetry.vuebean.event.VueModelListener;

      public class JVueKPE extends com.cimmetry.jvue.JVue
      implements VueMarkupListener, VueModelListener, VueFileListener {

      /** serialVersionUID */
      private static final long serialVersionUID = 1L;

      public void onInitDone() {
      super.onInitDone();

      System.out.println("***KPE*** JVue extension (Build 20120219-i) has been initialized.");
      }


      /**
      *
      * @param markupBean
      * @param filename
      * @param author
      */
      public void createUserMarkup(MarkupBean markupBean, String filename, String author) {
      System.out.println("***KPE*** createUserMarkup()");
      System.out.println(" filename: " + filename);
      System.out.println(" author: " + author);

      final boolean first = markupBean.getActiveMarkup().getName().contains("ntitled");

      final Markup newmarkup = first
      ? markupBean.getActiveMarkup() : markupBean.createMarkup(true);
      newmarkup.setName(filename);

      // Create a Properties class and instantiate the object
      final Property root = new Property("Markup", "KPE User Markup");
      root.addChildProperty("CSI_DocID", "<<dms:newmarkup>>"+filename);
      root.addChildProperty("CSI_DocName", filename);
      root.addChildProperty("CSI_DocReadOnly", "false");
      root.addChildProperty("CSI_DocAuthor", author != null ? author : "mickeymouse");
      root.addChildProperty("author", author != null ? author : "minniemouse");
      root.addChildProperty("Read-Only", "false");
      root.addChildProperty("CSI_MarkupType", "normal");
      newmarkup.setProperty(root);

      this.getActiveVueBean().getVueEventBroadcaster().addMarkupListener(this);
      this.getActiveVueBean().getVueEventBroadcaster().addModelListener(this);
      this.getActiveVueBean().getVueEventBroadcaster().addFileListener(this);

      // Make sure this is the last line of the method!!!
      if (!first) markupBean.setActiveMarkup(newmarkup); // This has no effect on enabling markup entity buttons

      }

      public void createUserMarkup_tested_works(MarkupBean markupBean, String filename, String author) {
      System.out.println("***KPE*** createUserMarkup()");
      System.out.println(" filename: " + filename);
      System.out.println(" author: " + author);

      final Markup newmarkup = markupBean.createMarkup(true);
      newmarkup.setName(filename);

      // Create a Properties class and instantiate the object
      final Property root = new Property("Markup", "KPE User Markup");
      root.addChildProperty("CSI_DocID", "<<dms:newmarkup>>"+filename);
      root.addChildProperty("CSI_DocName", filename);
      root.addChildProperty("CSI_DocReadOnly", "false");
      root.addChildProperty("CSI_DocAuthor", author != null ? author : "mickeymouse");
      root.addChildProperty("author", author != null ? author : "minniemouse");
      root.addChildProperty("Read-Only", "false");
      root.addChildProperty("CSI_MarkupType", "normal");
      newmarkup.setProperty(root);

      this.getActiveVueBean().getVueEventBroadcaster().addMarkupListener(this);
      this.getActiveVueBean().getVueEventBroadcaster().addModelListener(this);
      this.getActiveVueBean().getVueEventBroadcaster().addFileListener(this);

      // Always search for, and delete, "untitled" markups
      final Markup[] allmarkups = markupBean.getMarkups();
      for (Markup thismarkup : allmarkups) {
      System.out.print("***KPE*** Markup Name: " + thismarkup.getName());
      if (thismarkup.getName().contains("ntitled")) {
      markupBean.deleteMarkup(thismarkup);
      System.out.println(" <<< removed.");
      } else {
      System.out.println(" <<< kept.");
      }
      }

      // Make sure this is the last line of the method!!!
      markupBean.setActiveMarkup(newmarkup); // This has no effect on enabling markup entity buttons

      }

      public void configureMarkups(boolean isGreenMarks) {
      System.out.println("***KPE*** configureMarkups()");
      System.out.println(" isGreenMarks: " + isGreenMarks);

      final MarkupBean mbean = this.getActiveVueBean().getMarkupBean();
      final Markup active = mbean.getActiveMarkup();

      MarkupEntitySpec spec = active.getMarkupSettings();
      if (spec == null) {
      System.out.println("***KPE*** Why is spec null?");
      spec = new MarkupEntitySpec(mbean);
      }

      spec.setColor(isGreenMarks ? Color.GREEN : Color.RED);
      spec.setFillColor(Color.YELLOW);
      mbean.selectionSetSpec(spec);

      }

      @Override
      public void onMarkupEvent(VueEvent evt) {
      System.out.println("***KPE*** markup event = " + evt.getEventName());
      switch (evt.getType()) {
      case VueEvent.ONENTERMARKUPMODE:
      break;
      }
      }

      @Override
      public void onModelEvent(VueModelEvent evt) {
      System.out.println("***KPE*** model event = " + evt.getType());
      }


      @Override
      public void onFileEvent(VueEvent evt) {
      System.out.println("***KPE*** markup event = " + evt.getEventName());
      }

      }


      Process Flow
      APPLET IN HTML
      <object id = "JVue" name = "JVue by Oracle"
      classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
      codebase = "${viewer.codebase}"
      width = "100%" height = "50%" >
      <param name="code" value="com.kpe.esd.applets.JVueKPE" />
      <param name="codebase" value="${viewer.codebase}" />
      <param name="cache_archive" value="jvue.jar,jogl.jar,gluegen-rt.jar" />
      <param name="cache_version" value="cache_version" />
      <param name="type" value="application/x-java-applet;version=1.6" />
      <param name="mayscript" value="true" />
      <param name="scriptable" value="true" />
      <param name="EMBEDDED" value="TRUE">
      <param name="HEAVYWEIGHT" value="FALSE">
      <param name="VERBOSE" value="DEBUG">
      <param name="JVUESERVER" value="${viewer.autoVueServlet}">
      <param name="DMS" value="${viewer.autoVueDMS}">
      <param name="DMSARGS" value="USERNAME;DMS_PRESERVE_COOKIES;">
      <param name="USERNAME" value="anonymous">
      <param name="DMS_PRESERVE_COOKIES" value="TRUE">
      <param name="ONINIT" value="onJVueInit();">
      <param name="GUIFILE" value="${viewer.autoVueGUI}">
      </object>
      JAVASCRIPT: ONJVUEINIT()
      function onJVueInit() {

      var applet = getJVue();
      if (applet) {
      applet.setFile('${viewer.autoVueFilename}'); // [B1]
      applet.waitForLastMethod();

      AVOpenMarkupFile();
      AVConfigureMarkups();

      } else {
      alarm('!! Cannot find AutoVue applet !!!');
      }

      }; // end onJVueInit()

      JAVASCRIPT: AVOPENMARKUPFILE()
      function AVOpenMarkupFile() {
      var applet = getJVue();
      if (true) {                   
      applet.openMarkup('*'); // [2]
      } else {
      // ...
      }
      waitForMarkupsToBeLoaded(applet); // This statement is VERY important.

      var vuebean = applet.getActiveVueBean();
      applet.waitForLastMethod();
      alarm("VueBean: " + vuebean);
      var mbean = vuebean.getMarkupBean();
      applet.waitForLastMethod();
      alarm("MarkupBean: " + mbean);
      alarm("Markups Count: " + mbean.getMarkupsCount());

      var found = -1;
      var untitled = false;
      var allmarkups = mbean.getMarkups();
      if ( false ) { // mbean.getMarkupsCount() == 1
      if (allmarkups[0].getName().slice(0,8) == 'Untitled') {
      allmarkups[0].setName(pg_userMarkupFilename);
      } else {
      alarm(allmarkups[0].getName().slice(0,8));
      }
      } else {
      for (var index = 0, len = allmarkups.length; index < len; ++index) {
      var item = allmarkups[index];
      // Your code working on item here...
      alarm("Markup Name: " + item.getName());
      alarm("Markup Property: " + displayProperty(item.getProperty(), 0, 0, 1));

      if (pm_isHistory) { item.setReadOnly(true); }
      if (item.getName().slice(0,8) == 'Untitled') {
      found = index;
      untitled = true;
      // Untitled Markups get removed later by custom applet
      } else {
      if (item.getName().indexOf(pg_userMarkupFilename) > -1) {
      found = index;
      } else {
      if (!pm_isHistory && pm_isLead) { item.setReadOnly(false); }
      }
      }

      var information = item.getMarkupInformation();
      if (information != null) {
      for (var j = 0, len2 = information.length; j < len2; ++j) {
      var info = information[j];
      // Your code working on item here...
      alarm("Markup Information: " + info );
      }
      }
      }
      }

      if (untitled || (found == -1)) createMarkup(mbean, 'mickey mouse');

      }


      JAVASCRIPT: CREATEMARKUP()
      function createMarkup(mbean, author) {
      getJVue().createUserMarkup(mbean, pg_userMarkupFilename, author);
      };

      Note: Both versions of createUserMarkup() seem to work and allow successful saving of the markup file if configureMarkups() is not subsequently called.
      JAVASCRIPT: AVCONFIGUREMARKUPS()
      function AVConfigureMarkups() {
      var applet = getJVue();
      applet.configureMarkups(pm_isGreen);
      };