public void handleEvent()

in uimaj-ep-cev/src/main/java/org/apache/uima/cev/artifactViewer/TextArtifactViewer.java [67:166]


    public void handleEvent(Event event) {
      switch (event.type) {
        case SWT.Dispose:
        case SWT.KeyDown:
        case SWT.MouseMove: {
          if (tip == null)
            break;
          tip.dispose();
          tip = null;
          label = null;
          break;
        }
        case SWT.MouseHover: {
          Point point = new Point(event.x, event.y);
          int offsetAtLocation = -1;
          try {
            offsetAtLocation = text.getOffsetAtLocation(point);
          } catch (Exception e) {
            break;
          }

          List<AnnotationFS> annotationsToShow = new ArrayList<AnnotationFS>();
          List<AnnotationFS> annotationsAt = casData.getAnnotationsAt(offsetAtLocation);
          HashMap<Type, HashMap<AnnotationFS, Boolean>> annotationState = casData
                  .getAnnotationState();
          for (AnnotationFS annotationFS : annotationsAt) {
            Type type = annotationFS.getType();
            HashMap<AnnotationFS, Boolean> hashMap = annotationState.get(type);
            Boolean visible = hashMap.get(annotationFS);
            if (visible) {
              annotationsToShow.add(annotationFS);
            }
          }
          TypeSystem typeSystem = casData.getCAS().getTypeSystem();
          Type stringType = typeSystem.getType("uima.cas.String");
          StringBuilder infoText = new StringBuilder();

          List<StyleRange> styles = new ArrayList<StyleRange>();

          int start = 0;
          int end = 0;
          for (AnnotationFS each : annotationsToShow) {
            Type type = each.getType();
            String coveredText = each.getCoveredText();
            coveredText = shrink(coveredText);
            start = infoText.length();
            infoText.append(type.getShortName() + ": ");
            end = infoText.length();
            StyleRange style1 = new StyleRange();
            style1.start = start;
            style1.length = end - start;
            style1.fontStyle = SWT.BOLD;
            styles.add(style1);
            infoText.append(coveredText + "\n");
            List<Feature> features = type.getFeatures();
            for (Feature feature : features) {
              if (typeSystem.subsumes(stringType, feature.getRange())) {
                String shortName = feature.getShortName();
                String stringValue = each.getStringValue(feature);
                start = infoText.length();
                infoText.append("- " + shortName + ": ");
                end = infoText.length();
                StyleRange style2 = new StyleRange();
                style2.start = start;
                style2.length = end - start;
                style2.fontStyle = SWT.BOLD;
                styles.add(style2);
                infoText.append(shrink(stringValue) + "\n");
              }
            }
            infoText.append("\n");
          }

          if (tip != null && !tip.isDisposed())
            tip.dispose();

          if (!infoText.toString().equals("")) {
            tip = new Shell(Display.getCurrent().getActiveShell(), SWT.BALLOON
                    | SWT.ICON_INFORMATION | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
            tip.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            FillLayout layout = new FillLayout();
            layout.marginWidth = 2;
            tip.setLayout(layout);

            tipText = new StyledText(tip, SWT.NONE);
            tipText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
            tipText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            tipText.setText(infoText.toString());

            tipText.setStyleRanges(styles.toArray(new StyleRange[0]));
            tipText.layout(true);

            Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            Point pt = text.toDisplay(new Point(point.x + 20, point.y + 10));
            tip.setBounds(pt.x, pt.y, size.x, size.y);
            tip.setVisible(true);
          }
        }
      }
    }