001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.propertyeditors.css;
042:
043: import org.netbeans.modules.visualweb.propertyeditors.css.model.CssStyleData;
044: import java.awt.Color;
045: import java.awt.Component;
046: import java.awt.Dimension;
047: import java.util.ArrayList;
048: import java.util.List;
049: import javax.swing.AbstractListModel;
050: import javax.swing.DefaultListCellRenderer;
051: import javax.swing.JList;
052: import javax.swing.JPanel;
053: import javax.swing.ListModel;
054: import javax.swing.border.LineBorder;
055:
056: /**
057: * This is the left hand side Editor list panel
058: * @author Winston Prakash
059: */
060: public class StyleEditorListPanel extends javax.swing.JPanel {
061: StyleBuilderPanel styleBuilderPanel = null;
062: CssStyleData cssStyleData = null;
063:
064: List editorList = new ArrayList();
065:
066: /** Creates new form EditorListPanel */
067: public StyleEditorListPanel(StyleBuilderPanel mainPanel,
068: CssStyleData styleData) {
069: cssStyleData = styleData;
070: styleBuilderPanel = mainPanel;
071: initComponents();
072: // Set the background of the List to panel background
073: // (light grey) instead of white.
074: styleEditorList.setBackground(getBackground());
075: styleEditorList.setModel(new StyleEditorListModel());
076: styleEditorList.setCellRenderer(new StyleEditorListRenderer());
077: }
078:
079: public void addEditor(StyleEditor editor) {
080: editorList.add(editor);
081: }
082:
083: public void setSelectedEditor(StyleEditor editor) {
084: int index = editorList.indexOf(editor);
085: if (index >= 0) {
086: styleEditorList.setSelectedIndex(index);
087: }
088: }
089:
090: public Dimension getPreferredSize() {
091: Dimension dim = super .getPreferredSize();
092: dim.setSize(dim.getWidth() + 20, dim.getHeight());
093: return dim;
094: }
095:
096: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
097: private void initComponents() {
098: styleEditorList = new javax.swing.JList();
099:
100: setLayout(new java.awt.BorderLayout());
101:
102: setMinimumSize(new java.awt.Dimension(80, 200));
103: setOpaque(false);
104: styleEditorList.setBorder(javax.swing.BorderFactory
105: .createEmptyBorder(2, 2, 2, 2));
106: styleEditorList
107: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
108: styleEditorList
109: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
110: public void valueChanged(
111: javax.swing.event.ListSelectionEvent evt) {
112: styleEditorListValueChanged(evt);
113: }
114: });
115:
116: add(styleEditorList, java.awt.BorderLayout.NORTH);
117: styleEditorList.getAccessibleContext().setAccessibleName(
118: org.openide.util.NbBundle.getMessage(
119: StyleEditorListPanel.class,
120: "STYLE_EDITOR_LIST_ACCESSIBLE_NAME"));
121: styleEditorList.getAccessibleContext()
122: .setAccessibleDescription(
123: org.openide.util.NbBundle.getMessage(
124: StyleEditorListPanel.class,
125: "STYLE_EDITOR_LIST_ACCESSIBLE_DESC"));
126:
127: }// </editor-fold>//GEN-END:initComponents
128:
129: private void styleEditorListValueChanged(
130: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_styleEditorListValueChanged
131: if (evt.getValueIsAdjusting())
132: return;
133: JList list = (JList) evt.getSource();
134: StyleEditor styleEditor = (StyleEditor) list.getSelectedValue();
135: styleBuilderPanel.setEditorPanel((JPanel) styleEditor);
136: }//GEN-LAST:event_styleEditorListValueChanged
137:
138: class StyleEditorListModel extends AbstractListModel {
139:
140: public int getSize() {
141: return editorList.size();
142: }
143:
144: public Object getElementAt(int i) {
145: return editorList.get(i);
146: }
147: }
148:
149: class StyleEditorListRenderer extends DefaultListCellRenderer {
150:
151: public Component getListCellRendererComponent(JList list,
152: Object value, int index, boolean isSelected,
153: boolean cellHasFocus) {
154: if (isSelected) {
155: setBackground(list.getSelectionBackground());
156: setForeground(list.getSelectionForeground());
157: Color lineColor = list.getSelectionBackground()
158: .darker();
159: setBorder(new LineBorder(lineColor, 1, true));
160: } else {
161: setBackground(list.getBackground());
162: setForeground(list.getForeground());
163: setBorder(null);
164: }
165: StyleEditor styleEditor = (StyleEditor) value;
166: setText(styleEditor.getDisplayName());
167: return this ;
168: }
169: }
170:
171: // Variables declaration - do not modify//GEN-BEGIN:variables
172: private javax.swing.JList styleEditorList;
173: // End of variables declaration//GEN-END:variables
174:
175: }
|