001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.soa.mappercore;
021:
022: import java.awt.Color;
023: import java.awt.Component;
024: import java.awt.Font;
025: import javax.swing.JLabel;
026: import javax.swing.tree.TreePath;
027: import org.netbeans.modules.soa.mappercore.model.VertexItem;
028: import org.netbeans.modules.soa.mappercore.utils.Utils;
029:
030: /**
031: *
032: * @author anjeleevich
033: */
034: public class DefaultVertexItemRenderer extends JLabel implements
035: VertexItemRenderer {
036: public DefaultVertexItemRenderer() {
037: setBorder(null);
038: }
039:
040: public Component getVertexItemRendererComponent(Mapper mapper,
041: TreePath treePath, VertexItem vertexItem) {
042: setFont(getFont().deriveFont(Font.PLAIN));
043:
044: Object value = vertexItem.getValue();
045: String text = null;
046: //
047: // Indicates if the VertexItem's value is going to be shown
048: boolean valuePrepared = false;
049: //
050: if (value != null) {
051: text = value.toString();
052: if (text != null) {
053: Class type = vertexItem.getValueType();
054: if (Utils.equal(type, Number.class)) {
055: prepareNumberRenderer();
056: } else {
057: if (Utils.equal(type, String.class)) {
058: text = "\'" + text + "\'"; // NOI18N
059: }
060: prepareTextRenderer();
061: }
062: valuePrepared = true;
063: }
064: }
065: //
066: if (!valuePrepared) {
067: // value == null here
068: prepareCommentRenderer();
069: //
070: String shortDescr = vertexItem.getShortDescription();
071: if (shortDescr != null && shortDescr.length() != 0) {
072: text = shortDescr;
073: } else {
074: Class type = vertexItem.getValueType();
075: if (type != null) {
076: if (Utils.equal(type, Number.class)) {
077: text = "Number";
078: } else if (Utils.equal(type, String.class)) {
079: text = "String";
080: } else if (type != null) {
081: text = type.getCanonicalName();
082: }
083: }
084: }
085: }
086:
087: setText((text == null) ? "" : text);
088:
089: return this ;
090: }
091:
092: protected void prepareCommentRenderer() {
093: setHorizontalAlignment(LEFT);
094: setForeground(Color.GRAY);
095: }
096:
097: protected void prepareTextRenderer() {
098: setHorizontalAlignment(LEFT);
099: setForeground(Color.BLACK);
100: }
101:
102: protected void prepareNumberRenderer() {
103: setHorizontalAlignment(RIGHT);
104: setForeground(Color.BLACK);
105: }
106:
107: protected void prepareBooleanRenderer() {
108: setHorizontalAlignment(LEFT);
109: }
110: }
|