public int getColor(VisualItem item) {
      if (item.getInt("searchDepth") == 1) return ColorScheme.searchColor;

      if (item.canGetInt("senseIndex"))
        return ColorScheme.sensesPalette[
            item.getInt("senseIndex") % ColorScheme.sensesPalette.length];
      else return ColorScheme.resultsColor;
    }
    public int getColor(VisualItem item) {
      if (ENTROPY_COLOR) return entropyColor(item);
      // test
      //			if (item.getBoolean("cut")){
      //				return new Color(222,13,107).getRGB();
      //			}
      // color is fixed, what changes as a function of the value is the transparency (alpha)
      int color = sca.getColor(item);

      // lemmas and senses in the pathToRoot
      if (item.isInGroup("pathToRoot")
          && ((item.getInt("type") == 1) || (item.getInt("type") == 4)))
        color = ColorScheme.pathToRootColor;

      // count off -- just return color
      if (NodeColorAction.this.docuBurstActionList.countType.equals(DocuBurstActionList.NOCOUNT))
        return color;

      float total =
          (float)
              (item.getFloat(
                  DocuBurstActionList.CACHECOUNT
                      + NodeColorAction.this.docuBurstActionList.countType));
      float maxTotal =
          NodeColorAction.this.docuBurstActionList.getMaxTotal(
              NodeColorAction.this.docuBurstActionList.countType);

      if (total < 0) color = ColorScheme.negativeColor;

      if (total == 0) {
        if (color != ColorScheme.pathToRootColor)
          // zero senses get grey, zero lemmas and words get clear
          return ColorLib.setAlpha(ColorScheme.zeroOccurrenceSenseColor, ColorScheme.zeroAlpha);
        else
          // modulate path to root color
          return ColorLib.setAlpha(color, ColorScheme.zeroAlpha);
      }

      // initial alpha for zero and one count
      int alpha = ColorScheme.zeroAlpha;

      alpha += (int) (((float) total / (float) maxTotal) * (float) (255 - alpha));

      if (total < 0)
        System.err.println(
            "total: " + total + " node: " + item.getString("label") + " alpha: " + alpha);

      // this should not occur except for rounding errors
      if (alpha > 255) alpha = 255;

      return ColorLib.setAlpha(color, alpha);
    }
    public int entropyColor(VisualItem item) {
      // color is fixed, what changes as a function of the value is the transparency (alpha)
      int color = sca.getColor(item);

      // lemmas and senses in the pathToRoot
      if (item.isInGroup("pathToRoot")
          && ((item.getInt("type") == 1) || (item.getInt("type") == 4)))
        color = ColorScheme.pathToRootColor;

      // count off -- just return color
      if (NodeColorAction.this.docuBurstActionList.countType.equals(DocuBurstActionList.NOCOUNT))
        return color;

      // float total = item.getFloat(DocuBurstActionList.CONDENTROPY);
      float total = item.getFloat(DocuBurstActionList.CONDENTROPY);
      float maxTotal =
          NodeColorAction.this.docuBurstActionList.getMaxTotal(DocuBurstActionList.CONDENTROPY);

      if (total < 0) color = ColorScheme.negativeColor;

      if (total == 0) {
        if (color != ColorScheme.pathToRootColor)
          // zero senses get grey, zero lemmas and words get clear
          return ColorLib.setAlpha(color, 255);
        else
          // modulate path to root color
          return ColorLib.setAlpha(color, ColorScheme.zeroAlpha);
      }

      // initial alpha for zero and one count
      int alpha = 10;

      float condEntropyMin = NodeColorAction.this.docuBurstActionList.getCondEntropyMinTotal();

      // alpha += (int) ( (1 - Math.log(total/maxTotal)/Math.log(condEntropyMin)) * (float) (255 -
      // alpha));
      alpha +=
          (int) ((Math.log(total / maxTotal) / Math.log(condEntropyMin)) * (float) (255 - alpha));

      if (total < 0)
        System.err.println(
            "total: " + total + " node: " + item.getString("label") + " alpha: " + alpha);

      // this should not occur except for rounding errors
      if (alpha > 255) alpha = 255;

      return ColorLib.setAlpha(color, alpha);
    }
Esempio n. 4
0
  /**
   * expands one level at a time when step node is clicked
   *
   * @param item
   */
  public void expandOneLevel(VisualItem item) {

    Visualization vis = item.getVisualization();
    TableNodeItem stepItem = (TableNodeItem) item;
    TableNodeItem stepParent = getStepParent(stepItem);
    TableNodeItem stepChild = getStepChild(stepItem);

    int finishNodeId = 0;
    Iterator visualItems = vis.visibleItems();
    VisualItem node;

    while (visualItems.hasNext()) {
      node = (VisualItem) visualItems.next();
      if (node instanceof TableNodeItem
          && node.getInt(ID) > (stepParent.getInt(ID) + 1)
          && node.getInt(ID) < stepChild.getInt(ID)
          && node.getString(TYPE).equals(START)
          && node.getInt(ID) > finishNodeId) {
        collapseExpand(node);
        finishNodeId = finishNode((TableNodeItem) node).getInt(ID);
      }
    }
  }
Esempio n. 5
0
  /**
   * updates the focus group to the step if a sequence is being collapsed or to the start node of
   * the sequence if the sequence is being expanded
   *
   * @param id
   */
  public void updateFocusGroup(int nodeId, Visualization vis) {
    Iterator visualItems = vis.items();
    VisualItem item = null;
    final String group = Visualization.FOCUS_ITEMS;

    while (visualItems.hasNext()) {
      item = (VisualItem) visualItems.next();
      if (item instanceof TableNodeItem && item.getInt(ID) == nodeId) {
        TupleSet ts = vis.getFocusGroup(group);
        ts.setTuple(item);
        break;
      }
    }

    vis.run("animate");
  }
Esempio n. 6
0
    public void itemPressed(VisualItem item, java.awt.event.MouseEvent e) {
      if (e.getClickCount() == 2) {
        Node v = null;
        String pindex = "/";
        String parent = "/";
        int ind;
        String itemname = item.getString(LABEL);
        for (int i = 0; ; i++) {
          v = (getNode(i));
          String current = getName(v);
          if (current.compareTo(itemname) == 0) {
            ind = (int) v.get(Index);
            if (ind <= 9) itemname = itemname.substring(0, itemname.length() - 1);
            else itemname = itemname.substring(0, itemname.length() - 2);
            while (pindex != "Start") {
              Node h = v.getParent();
              pindex = getName(h);
              ind = (int) h.get(Index);

              if (pindex == "Start") break;

              if (ind <= 9) parent = "/" + pindex.substring(0, pindex.length() - 1) + parent;
              else parent = "/" + pindex.substring(0, pindex.length() - 2) + parent;

              v = h;
            }
            break;
          }
        }

        System.out.println(parent.substring(1) + itemname);

        // trial2 hello2 = new
        // trial2(item.getInt(Index),(item.getString(LABEL)),parent.substring(1)+itemname,100);
        urllink mainPanel =
            new urllink(
                item.getInt(Index), (item.getString(LABEL)), parent.substring(1) + itemname, 100);

        JFrame frame = new JFrame("Click any option");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(mainPanel);
        frame.pack();
        frame.setLocationByPlatform(true);
        frame.setVisible(true);
      }
    }
    public Font getFont(VisualItem item) {
      int nc = item.getInt(NODECOUNT);
      // if (nc==1)
      //  return defaultTreeFont;

      // int cc = item.getInt(ROWCOUNT);

      // float smin = 1f/cc;

      float s = (float) nc / rowCount;
      float fs = defaultTreeFont.getSize();
      if (s > 1) fs = fs * 2f;
      if (s > minFreqRatio * 60) fs = fs * 3f;
      else if (s > minFreqRatio * 40) fs = fs * 3f;
      else if (s > minFreqRatio * 20) fs = fs * 2.8f;
      else if (s > minFreqRatio * 15) fs = fs * 2.5f;
      else if (s > minFreqRatio * 10) fs = fs * 2f;
      else if (s > minFreqRatio * 6) fs = fs * 1.8f;
      else if (s > minFreqRatio * 3) fs = fs * 1.6f;
      else if (s > minFreqRatio * 2) fs = fs * 1.4f;
      else if (s > minFreqRatio * 1.4) fs = fs * 1.2f;
      else if (s <= minFreqRatio) fs = fs * 0.5f;

      Font font = defaultTreeFont.deriveFont(fs);
      System.err.println(
          "w="
              + item.getString(NAME)
              + " fs="
              + fs
              + " rc="
              + rowCount
              + " s="
              + s
              + " minFreqRatio="
              + minFreqRatio
              + " fn="
              + font);
      return font;
      // }
      // return defaultFont;
    }
Esempio n. 8
0
    @Override
    public void itemReleased(VisualItem item, MouseEvent e) {
      // when right-mouse released, release the dragged document glyph
      if (!SwingUtilities.isRightMouseButton(e)) {
        return;
      }
      // debug
      System.out.println("debug: " + this.getClass().getName() + ": item released");
      if (dragged) {
        activeItem = null;
        item.setFixed(wasFixed);
        dragged = false;
      }
      // clear the focus
      Visualization vis = item.getVisualization();
      vis.getFocusGroup(Visualization.FOCUS_ITEMS).clear();

      // determine whether item is in same region or new region;
      //  if new region, call controller to update attr vals
      double x = item.getX();
      double y = item.getY();
      double w = item.getDouble(WIDTH);
      double h = item.getDouble(HEIGHT);
      int newRegionX = -1;
      int newRegionY = -1;
      String xAttrName = docGridLayout.getXAttr();
      String yAttrName = docGridLayout.getYAttr();
      List<String> xCats = docGridLayout.getXCats();
      List<String> yCats = docGridLayout.getYCats();
      List<Integer> xCatRegionSizes = docGridLayout.getXCatRegionSizes();
      List<Integer> yCatRegionSizes = docGridLayout.getYCatRegionSizes();
      List<Integer> xCatPositions = docGridLayout.getXCatPositions();
      List<Integer> yCatPositions = docGridLayout.getYCatPositions();
      // for each region, get start and range;
      for (int i = 0; i < xCats.size(); i++) {
        int xRegionStart = xCatPositions.get(i);
        int xRegionEnd = xRegionStart + xCatRegionSizes.get(i);
        if (xRegionStart < x + (w / 2.) && x + (w / 2.) < xRegionEnd) {
          newRegionX = i;
        }
      }
      for (int i = 0; i < yCats.size(); i++) {
        int yRegionStart = yCatPositions.get(i);
        int yRegionEnd = yRegionStart + yCatRegionSizes.get(i);
        if (yRegionStart < y + (h / 2.) && y + (h / 2.) < yRegionEnd) {
          newRegionY = i;
        }
      }

      int docID = item.getInt(DocumentGridTable.NODE_ID);

      // debug
      //            System.out.println("debug: item moved:
      // docID="+docID+"xOrig="+xCats.get(origRegionX)+", xNew="+xCats.get(newRegionX)+",
      // yOrig="+yCats.get(origRegionY)+", yNew="+yCats.get(newRegionY));

      // update for x and y separately
      //            if (origRegionX != newRegionX && newRegionX != -1) {
      String newCatX = xCats.get(newRegionX);
      controller.updateDocumentAttr(docID, xAttrName, newCatX);
      controller.documentAttributesUpdated(docID);
      //            }
      //            if (origRegionY != newRegionY && newRegionY != -1) {
      String newCatY = yCats.get(newRegionY);
      controller.updateDocumentAttr(docID, yAttrName, newCatY);
      controller.documentAttributesUpdated(docID);
      //            }

    }
Esempio n. 9
0
    @Override
    //        public void itemPressed(VisualItem item, MouseEvent e) {
    public void itemClicked(VisualItem item, MouseEvent e) {
      // load (or unload) marked-up text into glasspane on rightclick
      // glasspane text is now loaded on mouseover instead

      // temp: zoom on selection
      if (SwingUtilities.isLeftMouseButton(e)) {
        if (item.canGetInt(DocumentGridTable.NODE_ID)) {
          int nodeId = item.getInt(DocumentGridTable.NODE_ID);
          boolean hasSelectFocus = item.getBoolean(SELECT_FOCUS);
          boolean hasWidthFocus = item.getBoolean(WIDTH_FOCUS);
          boolean hasHeightFocus = item.getBoolean(HEIGHT_FOCUS);
          if (hasSelectFocus) {
            // simply deselect the node
            resetGlyphFocus();
          } else {
            // clear all other node selections
            resetGlyphFocus();
            // select this node
            item.setBoolean(SELECT_FOCUS, true);
            item.setBoolean(WIDTH_FOCUS, true);
            item.setBoolean(HEIGHT_FOCUS, true);
          }

          // ensure that the layout has been reprocessed before loading glasspane
          documentGridLayout.categoricalLayout();

          m_vis.run(
              "init"); // init is needed to run here, since sizing is tightly-bound with our
                       // faux-fisheye zooming
          //                    m_vis.run("repaint");

          // appear the glasspane at appropriate size & location
          // get relative location of Visualization
          int xOffset = 0;
          int yOffset = 0;
          JComponent component = display;
          // recursively go through this Component's ancestors, summing offset information in order
          // to get the absolute position relative to window
          do {
            Point visLocation = component.getLocation();
            xOffset += visLocation.x;
            yOffset += visLocation.y;
          } while ((!component.getParent().getClass().equals(JRootPane.class))
              && (component = (JComponent) component.getParent()) != null);
          // debug
          //                    System.out.println("debug: " + this.getClass().getName() + ":
          // offsets: " + xOffset + ", " + yOffset);

          String attrIdStr =
              colorAttrName; // TODO make highlighting more general, not just based on color!

          // make sure that the clicked item is not temporarily ``disabled'' (ie, zoom state was not
          // immediately toggled by a glasspane-oriented class)
          if (disableNextZoomItem == null || disableNextZoomItem != item) {
            disableNextZoomItem = null;
            int x = (int) item.getEndX() + bufferPx + xOffset;
            int y = (int) item.getEndY() + bufferPx + yOffset;
            int w = (int) item.getDouble(WIDTH_END) - 2 * bufferPx;
            int h = (int) item.getDouble(HEIGHT_END) - 2 * bufferPx;
            // debug
            System.out.println(
                "debug: "
                    + this.getClass().getName()
                    + ": displaying sized glasspane at x="
                    + x
                    + ", y="
                    + y
                    + ", w="
                    + w
                    + ", h="
                    + h);
            glassPane.displaySizedPane((int) x, (int) y, (int) w, (int) h, item);

            AbstractDocument doc = glassPane.getAbstDoc();
            controller.writeDocTextWithHighlights(doc, nodeId, attrIdStr);

            glassPane.setBackgroundColor(new Color(docColorAction.getColor(item)));
          } else {
            disableNextZoomItem = null;
          }
        }
      }
    }
Esempio n. 10
0
    @Override
    public void render(Graphics2D g, VisualItem item) {

      if (item.isVisible()) {
        item.setShape(Constants.SHAPE_RECTANGLE);
        RectangularShape shape = (RectangularShape) getShape(item);
        if (shape != null) {

          shape
              .getBounds2D()
              .setRect(
                  (double) item.get(VisualItem.X),
                  (double) item.get(VisualItem.Y),
                  item.getSize(),
                  item.getSize());

          // draw basic glyph
          Color strokeColor = ColorLib.getColor(item.getStrokeColor());
          Color fillColor = ColorLib.getColor(item.getFillColor());

          //                    int size = (int)item.getSize();
          int x = (int) item.getX() + bufferPx;
          int y = (int) item.getY() + bufferPx;
          int w = (int) item.getDouble(WIDTH) - 2 * bufferPx;
          int h = (int) item.getDouble(HEIGHT) - 2 * bufferPx;
          g.setPaint(fillColor);
          g.fillRect(x, y, w, h);

          // draw string on-top of glyph, filling the glyph's area

          //                    String s = "doc=" + item.getString(NODE_NAME) + "\n";
          String s = "";

          // set text: full document if no search term, else excerpts containing the search term
          String queryStr = searchQ.getSearchSet().getQuery();
          String focusText = item.getString(DocumentGridTable.NODE_FOCUS_TEXT);
          if (queryStr != null
              && !queryStr.isEmpty()
              && focusText != null
              && !focusText.equals("null")
              && !focusText.equals("")) {
            // if search query and terms present in document, use term-containing spans
            s += focusText;
          } else if (queryStr != null
              && !queryStr.isEmpty()
              && focusText.equals(FOCUS_SENT_SPLITTER)) {
            // if search query but no terms present in document, use blank
            s += "";
          } else if ((queryStr == null || queryStr.isEmpty()) && item.canGetInt(NODE_ID)) {
            // if no search query, build feature-oriented summary based on color attribute
            s = controller.getDocumentSummary(item.getInt(NODE_ID), colorAttrName);
          }

          // TODO : idea: set font size dynamically based on number of active nodes? based on size
          // of rect?
          int fontSize = 10;

          item.setFont(FontLib.getFont("Tahoma", Font.PLAIN, fontSize));

          Font f = item.getFont();

          // compute width, height for the given text
          // NOTE: this logic has been moved into drawStringMultiline
          //                    int[] textDims = getTextDims(g, f, s);

          // debug
          //                    System.out.println("debug: "+this.getClass().getName()+":
          // drawStringMultiline at x="+x1+", y="+y1+", w="+w+", h="+h);
          drawStringMultiline(g, f, s, x, y, w, h);
        }
      }
    }