You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IndicatorsRenderer.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright 2011 gitblit.com.
  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.gitblit.client;
  17. import java.awt.Component;
  18. import java.awt.FlowLayout;
  19. import java.io.Serializable;
  20. import javax.swing.ImageIcon;
  21. import javax.swing.JLabel;
  22. import javax.swing.JPanel;
  23. import javax.swing.JTable;
  24. import javax.swing.table.TableCellRenderer;
  25. import com.gitblit.models.RepositoryModel;
  26. /**
  27. * Renders the type indicators (tickets, frozen, access restriction, etc) in a
  28. * single cell.
  29. *
  30. * @author James Moger
  31. *
  32. */
  33. public class IndicatorsRenderer extends JPanel implements TableCellRenderer, Serializable {
  34. private static final long serialVersionUID = 1L;
  35. private final ImageIcon blankIcon;
  36. private final ImageIcon pushIcon;
  37. private final ImageIcon pullIcon;
  38. private final ImageIcon viewIcon;
  39. private final ImageIcon doxIcon;
  40. private final ImageIcon frozenIcon;
  41. private final ImageIcon federatedIcon;
  42. private final ImageIcon forkIcon;
  43. private final ImageIcon sparkleshareIcon;
  44. private final ImageIcon mirrorIcon;
  45. public IndicatorsRenderer() {
  46. super(new FlowLayout(FlowLayout.RIGHT, 1, 0));
  47. blankIcon = new ImageIcon(getClass().getResource("/blank.png"));
  48. pushIcon = new ImageIcon(getClass().getResource("/lock_go_16x16.png"));
  49. pullIcon = new ImageIcon(getClass().getResource("/lock_pull_16x16.png"));
  50. viewIcon = new ImageIcon(getClass().getResource("/shield_16x16.png"));
  51. doxIcon = new ImageIcon(getClass().getResource("/book_16x16.png"));
  52. frozenIcon = new ImageIcon(getClass().getResource("/cold_16x16.png"));
  53. federatedIcon = new ImageIcon(getClass().getResource("/federated_16x16.png"));
  54. forkIcon = new ImageIcon(getClass().getResource("/commit_divide_16x16.png"));
  55. sparkleshareIcon = new ImageIcon(getClass().getResource("/star_16x16.png"));
  56. mirrorIcon = new ImageIcon(getClass().getResource("/mirror_16x16.png"));
  57. }
  58. @Override
  59. public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
  60. boolean hasFocus, int row, int column) {
  61. if (isSelected)
  62. setBackground(table.getSelectionBackground());
  63. else
  64. setBackground(table.getBackground());
  65. removeAll();
  66. if (value instanceof RepositoryModel) {
  67. StringBuilder tooltip = new StringBuilder();
  68. RepositoryModel model = (RepositoryModel) value;
  69. if (model.isSparkleshared()) {
  70. JLabel icon = new JLabel(sparkleshareIcon);
  71. tooltip.append(Translation.get("gb.isSparkleshared")).append("<br/>");
  72. add(icon);
  73. }
  74. if (model.isMirror) {
  75. JLabel icon = new JLabel(mirrorIcon);
  76. tooltip.append(Translation.get("gb.isMirror")).append("<br/>");
  77. add(icon);
  78. }
  79. if (model.isFork()) {
  80. JLabel icon = new JLabel(forkIcon);
  81. tooltip.append(Translation.get("gb.isFork")).append("<br/>");
  82. add(icon);
  83. }
  84. if (model.useDocs) {
  85. JLabel icon = new JLabel(doxIcon);
  86. tooltip.append(Translation.get("gb.docs")).append("<br/>");
  87. add(icon);
  88. }
  89. if (model.isFrozen) {
  90. JLabel icon = new JLabel(frozenIcon);
  91. tooltip.append(Translation.get("gb.isFrozen")).append("<br/>");
  92. add(icon);
  93. }
  94. if (model.isFederated) {
  95. JLabel icon = new JLabel(federatedIcon);
  96. tooltip.append(Translation.get("gb.isFederated")).append("<br/>");
  97. add(icon);
  98. }
  99. switch (model.accessRestriction) {
  100. case NONE: {
  101. add(new JLabel(blankIcon));
  102. break;
  103. }
  104. case PUSH: {
  105. JLabel icon = new JLabel(pushIcon);
  106. tooltip.append(Translation.get("gb.pushRestricted")).append("<br/>");
  107. add(icon);
  108. break;
  109. }
  110. case CLONE: {
  111. JLabel icon = new JLabel(pullIcon);
  112. tooltip.append(Translation.get("gb.cloneRestricted")).append("<br/>");
  113. add(icon);
  114. break;
  115. }
  116. case VIEW: {
  117. JLabel icon = new JLabel(viewIcon);
  118. tooltip.append(Translation.get("gb.viewRestricted")).append("<br/>");
  119. add(icon);
  120. break;
  121. }
  122. default:
  123. add(new JLabel(blankIcon));
  124. }
  125. if (tooltip.length() > 0) {
  126. tooltip.insert(0, "<html><body>");
  127. setToolTipText(tooltip.toString().trim());
  128. }
  129. }
  130. return this;
  131. }
  132. }