Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

IndicatorsRenderer.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.isFrozen) {
  85. JLabel icon = new JLabel(frozenIcon);
  86. tooltip.append(Translation.get("gb.isFrozen")).append("<br/>");
  87. add(icon);
  88. }
  89. if (model.isFederated) {
  90. JLabel icon = new JLabel(federatedIcon);
  91. tooltip.append(Translation.get("gb.isFederated")).append("<br/>");
  92. add(icon);
  93. }
  94. switch (model.accessRestriction) {
  95. case NONE: {
  96. add(new JLabel(blankIcon));
  97. break;
  98. }
  99. case PUSH: {
  100. JLabel icon = new JLabel(pushIcon);
  101. tooltip.append(Translation.get("gb.pushRestricted")).append("<br/>");
  102. add(icon);
  103. break;
  104. }
  105. case CLONE: {
  106. JLabel icon = new JLabel(pullIcon);
  107. tooltip.append(Translation.get("gb.cloneRestricted")).append("<br/>");
  108. add(icon);
  109. break;
  110. }
  111. case VIEW: {
  112. JLabel icon = new JLabel(viewIcon);
  113. tooltip.append(Translation.get("gb.viewRestricted")).append("<br/>");
  114. add(icon);
  115. break;
  116. }
  117. default:
  118. add(new JLabel(blankIcon));
  119. }
  120. if (tooltip.length() > 0) {
  121. tooltip.insert(0, "<html><body>");
  122. setToolTipText(tooltip.toString().trim());
  123. }
  124. }
  125. return this;
  126. }
  127. }