/platform/platform-api/src/com/intellij/openapi/roots/ui/util/BaseTextCommentCellAppearance.java

https://bitbucket.org/nbargnesi/idea · Java · 71 lines · 45 code · 11 blank · 15 comment · 5 complexity · d39d7643330de589381816e286aba6e5 MD5 · raw file

  1. /*
  2. * Copyright 2000-2012 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.intellij.openapi.roots.ui.util;
  17. import com.intellij.openapi.roots.ui.CellAppearanceEx;
  18. import com.intellij.openapi.util.text.StringUtil;
  19. import com.intellij.ui.HtmlListCellRenderer;
  20. import com.intellij.ui.SimpleColoredComponent;
  21. import com.intellij.ui.SimpleTextAttributes;
  22. import org.jetbrains.annotations.NotNull;
  23. import javax.swing.*;
  24. public abstract class BaseTextCommentCellAppearance implements CellAppearanceEx {
  25. private SimpleTextAttributes myCommentAttributes = SimpleTextAttributes.GRAY_ATTRIBUTES;
  26. private SimpleTextAttributes myTextAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
  27. protected abstract Icon getIcon();
  28. protected abstract String getSecondaryText();
  29. protected abstract String getPrimaryText();
  30. public void customize(@NotNull final SimpleColoredComponent component) {
  31. component.setIcon(getIcon());
  32. component.append(getPrimaryText(), myTextAttributes);
  33. final String secondaryText = getSecondaryText();
  34. if (!StringUtil.isEmptyOrSpaces(secondaryText)) {
  35. component.append(" (" + secondaryText + ")", myCommentAttributes);
  36. }
  37. }
  38. public void customize(@NotNull final HtmlListCellRenderer renderer) {
  39. renderer.setIcon(getIcon());
  40. renderer.append(getPrimaryText(), myTextAttributes);
  41. final String secondaryText = getSecondaryText();
  42. if (!StringUtil.isEmptyOrSpaces(secondaryText)) {
  43. renderer.append(" (" + secondaryText + ")", myCommentAttributes);
  44. }
  45. }
  46. @NotNull
  47. public String getText() {
  48. String secondaryText = getSecondaryText();
  49. if (secondaryText != null && secondaryText.length() > 0) {
  50. return getPrimaryText() + " (" + secondaryText + ")";
  51. }
  52. return getPrimaryText();
  53. }
  54. public void setCommentAttributes(SimpleTextAttributes commentAttributes) {
  55. myCommentAttributes = commentAttributes;
  56. }
  57. public void setTextAttributes(SimpleTextAttributes textAttributes) {
  58. myTextAttributes = textAttributes;
  59. }
  60. }