001: /*
002: * PropertyHintRendererPanel.java
003: *
004: * Created on December 19, 2007, 3:58 PM
005: */
006:
007: package it.businesslogic.ireport.gui;
008:
009: import java.awt.Component;
010: import java.awt.Insets;
011: import javax.swing.JList;
012: import javax.swing.ListCellRenderer;
013: import javax.swing.UIManager;
014: import javax.swing.border.EmptyBorder;
015:
016: /**
017: *
018: * @author gtoffoli
019: */
020: public class PropertyHintListCellRenderer extends javax.swing.JPanel
021: implements ListCellRenderer {
022:
023: public void setSelected(boolean b) {
024: setBackground(b ? UIManager
025: .getColor("List.selectionBackground") : UIManager
026: .getColor("ToolTip.background"));
027: jLabelDescription.setForeground(b ? UIManager
028: .getColor("List.selectionForeground") : UIManager
029: .getColor("ToolTip.foreground"));
030: jLabelProperty.setForeground(b ? UIManager
031: .getColor("List.selectionForeground") : UIManager
032: .getColor("ToolTip.foreground"));
033: }
034:
035: public void setPropertyName(String s) {
036: if (s == null)
037: s = "";
038: if (!s.startsWith("<html><b>"))
039: s = "<html><b>" + s;
040: jLabelProperty.setText(s);
041: }
042:
043: public void setPropertyDescription(String s) {
044: if (s == null)
045: s = "";
046: if (!s.startsWith("<html>"))
047: s = "<html>" + s;
048: jLabelDescription.setText(s);
049: }
050:
051: /** Creates new form PropertyHintRendererPanel */
052: public PropertyHintListCellRenderer() {
053: initComponents();
054: }
055:
056: /** This method is called from within the constructor to
057: * initialize the form.
058: * WARNING: Do NOT modify this code. The content of this method is
059: * always regenerated by the Form Editor.
060: */
061: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
062: private void initComponents() {
063: java.awt.GridBagConstraints gridBagConstraints;
064:
065: jLabelProperty = new javax.swing.JLabel();
066: jLabelDescription = new javax.swing.JLabel();
067: jSeparator1 = new javax.swing.JSeparator();
068:
069: setLayout(new java.awt.GridBagLayout());
070:
071: jLabelProperty.setText("<html><b>Property");
072: gridBagConstraints = new java.awt.GridBagConstraints();
073: gridBagConstraints.gridx = 0;
074: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
075: gridBagConstraints.weightx = 1.0;
076: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
077: add(jLabelProperty, gridBagConstraints);
078:
079: jLabelDescription.setText("jLabel1");
080: jLabelDescription
081: .setVerticalAlignment(javax.swing.SwingConstants.TOP);
082: jLabelDescription
083: .setVerticalTextPosition(javax.swing.SwingConstants.TOP);
084: gridBagConstraints = new java.awt.GridBagConstraints();
085: gridBagConstraints.gridx = 0;
086: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
087: gridBagConstraints.weightx = 1.0;
088: gridBagConstraints.weighty = 1.0;
089: gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 4);
090: add(jLabelDescription, gridBagConstraints);
091:
092: jSeparator1.setMinimumSize(new java.awt.Dimension(1, 1));
093: jSeparator1.setPreferredSize(new java.awt.Dimension(1, 1));
094: gridBagConstraints = new java.awt.GridBagConstraints();
095: gridBagConstraints.gridx = 0;
096: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
097: add(jSeparator1, gridBagConstraints);
098: }// </editor-fold>//GEN-END:initComponents
099:
100: // Variables declaration - do not modify//GEN-BEGIN:variables
101: private javax.swing.JLabel jLabelDescription;
102: private javax.swing.JLabel jLabelProperty;
103: private javax.swing.JSeparator jSeparator1;
104:
105: // End of variables declaration//GEN-END:variables
106:
107: public Component getListCellRendererComponent(JList list,
108: Object value, int index, boolean isSelected,
109: boolean cellHasFocus) {
110:
111: setSelected(isSelected);
112: if (value instanceof PropertyHint) {
113: PropertyHint ph = (PropertyHint) value;
114: this .setPropertyName(ph.getPropertyName());
115: this .setPropertyDescription(ph.getPropertyDescription());
116: } else {
117: this .setPropertyName("" + value);
118: this .setPropertyDescription("");
119: }
120:
121: if (cellHasFocus) {
122: setBorder(UIManager
123: .getBorder("List.focusCellHighlightBorder"));
124: } else {
125: setBorder(new EmptyBorder(new Insets(1, 1, 1, 1)));
126: }
127:
128: return this;
129: }
130:
131: }
|