Java 类com.intellij.ui.SimpleColoredRenderer 实例源码

项目:intellij-ce-playground    文件:LayoutEditorFixture.java   
private void describe(@NotNull SimpleColoredRenderer renderer,
                      @NotNull AttributeWrapper wrapper,
                      @NotNull RadComponent component,
                      boolean showSelected,
                      int depth) {
  SimpleTextAttributes style = wrapper.getAttribute(SimpleTextAttributes.REGULAR_ATTRIBUTES);
  for (int i = 0; i < depth; i++) {
    renderer.append("    ", style);
  }

  if (showSelected && myPanel.getSurfaceArea().isSelected(component)) {
    renderer.append("*");
  }
  myPanel.getTreeDecorator().decorate(component, renderer, wrapper, true);
  renderer.append("\n", style);

  for (RadComponent child : component.getChildren()) {
    describe(renderer, wrapper, child, showSelected, depth + 1);
  }
}
项目:intellij-ce-playground    文件:LayoutEditorTestBase.java   
private static void decorate(StringBuilder sb, RadViewComponent component, int depth) {
  for (int i = 0; i < depth; i++) {
    sb.append("    ");
  }

  SimpleColoredRenderer renderer = new SimpleColoredRenderer();
  AndroidTreeDecorator decorator = new AndroidTreeDecorator(RadModelBuilder.getProject(component));
  decorator.decorate(component, renderer, AttributeWrapper.DEFAULT, true);
  sb.append(renderer);
  sb.append('\n');
  for (RadViewComponent child : RadViewComponent.getViewComponents(component.getChildren())) {
    decorate(sb, child, depth + 1);
  }
}
项目:intellij-ce-playground    文件:LayoutEditorFixture.java   
/**
 * Describes the current state of the components. This is similar to
 * {@link #describeComponentTree(boolean)}, but this will unconditionally
 * show all components, whereas {@link #describeComponentTree(boolean)} will
 * not show nodes that have not been expanded/loaded.
 *
 * @param showSelected if true, mark selected items in the description
 * @return a description of the components hierarchy
 */
public String describeComponents(final boolean showSelected) {
  final StringBuilder sb = new StringBuilder(100);
  final RadComponent root = myPanel.getRootComponent();
  if (root != null) {
    ApplicationManager.getApplication().runReadAction(new Runnable() {
      @Override
      public void run() {
        SimpleColoredRenderer renderer = new SimpleColoredRenderer();
        AttributeWrapper wrapper = new AttributeWrapper() {
          @Override
          public SimpleTextAttributes getAttribute(SimpleTextAttributes attributes) {
            return SimpleTextAttributes.REGULAR_ATTRIBUTES;
          }
        };
        describe(renderer, wrapper, root, showSelected, 0);
        SimpleColoredComponent.ColoredIterator iterator = renderer.iterator();
        while (iterator.hasNext()) {
          iterator.next();
          sb.append(iterator.getFragment());
        }
      }
    });
  }

  return sb.toString();
}
项目:intellij-ce-playground    文件:LayoutEditorFixture.java   
/**
 * Describes the current state of the component tree. Like {@link #describeComponents(boolean)}, but queries the actual UI tree widget
 * rather than the internal component hierarchy. This means it won't include UI nodes that have not been created yet, such as nodes in
 * unexpanded part of the tree.
 *
 * @param showSelected if true, mark selected items in the description
 * @return a description of the component tree
 */
public String describeComponentTree(final boolean showSelected) {
  final StringBuilder sb = new StringBuilder(100);
  DesignerToolWindow toolWindow = myPanel.getToolWindow();
  if (toolWindow != null) {
    final ComponentTree componentTree = toolWindow.getComponentTree();
    final TreeModel model = componentTree.getModel();
    final Object root = model.getRoot();
    if (root != null) {
      execute(new GuiTask() {
        @Override
        protected void executeInEDT() throws Throwable {
          SimpleColoredRenderer renderer = new SimpleColoredRenderer();
          AttributeWrapper wrapper = new AttributeWrapper() {
            @Override
            public SimpleTextAttributes getAttribute(SimpleTextAttributes attributes) {
              return SimpleTextAttributes.REGULAR_ATTRIBUTES;
            }
          };
          if (componentTree.isRootVisible()) {
            describe(renderer, wrapper, componentTree, model, root, showSelected, 0);
          }
          else {
            for (int i = 0, n = model.getChildCount(root); i < n; i++) {
              Object child = model.getChild(root, i);
              describe(renderer, wrapper, componentTree, model, child, showSelected, 0);
            }
          }
          SimpleColoredComponent.ColoredIterator iterator = renderer.iterator();
          while (iterator.hasNext()) {
            iterator.next();
            sb.append(iterator.getFragment());
          }
        }
      });
    }
  }
  return sb.toString();
}
项目:intellij-ce-playground    文件:LayoutEditorFixture.java   
private void describe(@NotNull SimpleColoredRenderer renderer,
                      @NotNull AttributeWrapper wrapper,
                      @NotNull ComponentTree componentTree,
                      @NotNull TreeModel model,
                      @NotNull Object node,
                      boolean showSelected,
                      int depth) {
  SimpleTextAttributes style = wrapper.getAttribute(SimpleTextAttributes.REGULAR_ATTRIBUTES);
  for (int i = 0; i < depth; i++) {
    renderer.append("    ", style);
  }

  if (!model.isLeaf(node) && model.getChildCount(node) > 0 &&
    model.getChild(node, 0) instanceof LoadingNode) {
    renderer.append("> ", style);
  }

  RadComponent component = componentTree.extractComponent(node);
  if (component != null) {
    if (showSelected && myPanel.getSurfaceArea().isSelected(component)) {
      renderer.append("*");
    }
    myPanel.getTreeDecorator().decorate(component, renderer, wrapper, true);
  }
  else {
    renderer.append("<missing component>", style);
  }
  renderer.append("\n", style);

  if (!model.isLeaf(node)) {
    for (int i = 0, n = model.getChildCount(node); i < n; i++) {
      Object child = model.getChild(node, i);
      if (child instanceof LoadingNode) {
        continue;
      }
      describe(renderer, wrapper, componentTree, model, child, showSelected, depth + 1);
    }
  }
}