private void initializeAnnotations()

in uimaj-ep-cev/src/main/java/org/apache/uima/cev/data/CEVData.java [123:195]


  private void initializeAnnotations(Map<String, StyleMapEntry> style) {
    IPreferenceStore store = CEVPlugin.getDefault().getPreferenceStore();
    String filter = store.getString(CEVPreferenceConstants.P_ANNOTATION_FILTER);

    int i = 0;

    TypeSystem typeSystem = cas.getTypeSystem();
    Iterator<Type> tIter = typeSystem.getTypeIterator();
    while (tIter.hasNext()) {
      Type t = tIter.next();

      if (!t.getName().matches(filter) && typeSystem.subsumes(cas.getAnnotationType(), t)) {
        indexedTypes.add(t);

        if (style != null && style.containsKey(t.getName())) {
          StyleMapEntry se = style.get(t.getName());
          bgColors.put(t, new Color(Display.getCurrent(), se.getBackground().getRed(), se
                  .getBackground().getGreen(), se.getBackground().getBlue()));
          fgColors.put(t, new Color(Display.getCurrent(), se.getForeground().getRed(), se
                  .getForeground().getGreen(), se.getForeground().getBlue()));
        } else {
          RGB rgb = Display.getCurrent().getSystemColor(COLOR_NR[i++ % COLOR_NR.length]).getRGB();
          int sum = rgb.blue + rgb.green + rgb.red;
          int max = Math.max(Math.max(rgb.blue, rgb.green), rgb.red);
          bgColors.put(t, new Color(Display.getCurrent(), rgb));
          if (sum < 255 || max < 129) {
            fgColors.put(
                    t,
                    new Color(Display.getCurrent(), Display.getCurrent()
                            .getSystemColor(SWT.COLOR_WHITE).getRGB()));
          } else {
            fgColors.put(
                    t,
                    new Color(Display.getCurrent(), Display.getCurrent()
                            .getSystemColor(SWT.COLOR_BLACK).getRGB()));
          }
        }

        annotationState.put(t, new HashMap<AnnotationFS, Boolean>());
        annotationStateCount.put(t, 0);
      }
    }

    Collections.sort(indexedTypes, new Comparator<Type>() {
      public int compare(Type o1, Type o2) {
        return o1.getName().compareTo(o2.getName());
      }
    });

    FSIndex anIndex = cas.getAnnotationIndex();
    FSIterator anIter = anIndex.iterator();

    while (anIter.isValid()) {
      AnnotationFS annot = (AnnotationFS) anIter.get();
      if (annotationState.containsKey(annot.getType())) {
        boolean show = false;
        if (style != null) {
          StyleMapEntry se = style.get(annot.getType().getName());
          if (se != null) {
            show = se.getChecked();
          }
        }
        annotations.add(annot);
        annotationState.get(annot.getType()).put(annot, show);
        if (show) {
          annotationStateCount.put(annot.getType(), annotationStateCount.get(annot.getType()) + 1);
        }

      }

      anIter.moveToNext();
    }
  }