Esempio n. 1
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;
          }
        }
      }
    }