This project has retired. For details please refer to its
Attic page.
CollectionRenderer xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.workbench.swing;
2021import java.awt.Component;
22import java.util.Collection;
23import java.util.GregorianCalendar;
2425import javax.swing.JTable;
26import javax.swing.table.DefaultTableCellRenderer;
2728import org.apache.chemistry.opencmis.commons.definitions.Choice;
29import org.apache.chemistry.opencmis.workbench.ClientHelper;
3031publicclassCollectionRendererextends DefaultTableCellRenderer {
32privatestaticfinallong serialVersionUID = 1L;
3334publicCollectionRenderer() {
35super();
36 }
3738 @Override
39public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
40int row, int column) {
41 Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
4243int height = (int) getPreferredSize().getHeight();
44if (height > (getFontMetrics(getFont()).getHeight() + getInsets().bottom + getInsets().top)) {
45if (table.getRowHeight(row) != height) {
46 table.setRowHeight(row, height);
47 }
48 }
4950return comp;
51 }
5253 @Override
54protectedvoid setValue(Object value) {
55 Collection<?> col = (Collection<?>) value;
5657if ((col == null) || (col.isEmpty())) {
58super.setValue("");
59return;
60 }
6162// build string63 StringBuilder sb = new StringBuilder("<html>");
64for (Object o : col) {
65 sb.append("<span>"); // workaround for a bug in Swing66if (o == null) {
67 sb.append("<i>null</i>");
68 } elseif (o instanceof GregorianCalendar) {
69 sb.append(ClientHelper.getDateString((GregorianCalendar) o));
70 } elseif (o instanceof Choice<?>) {
71 sb.append(((Choice<?>) o).getValue());
72 } else {
73 sb.append(o.toString());
74 }
75 sb.append("</span><br/>");
76 }
77// sb.append("</html>");7879super.setValue(sb.toString());
80 }
81 }