KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > visual > ui > StyleEditorListPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * StyleEditorListPanel.java
22  *
23  * Created on October 12, 2004, 9:29 AM
24  */

25
26 package org.netbeans.modules.css.visual.ui;
27
28 import java.awt.Color JavaDoc;
29 import java.awt.Component JavaDoc;
30 import java.awt.Dimension JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.List JavaDoc;
33 import javax.swing.AbstractListModel JavaDoc;
34 import javax.swing.DefaultListCellRenderer JavaDoc;
35 import javax.swing.JList JavaDoc;
36 import javax.swing.JPanel JavaDoc;
37 import javax.swing.border.LineBorder JavaDoc;
38
39 /**
40  * This is the left hand side Editor list panel
41  * @author Winston Prakash
42  * @version 1.0
43  */

44 public class StyleEditorListPanel extends javax.swing.JPanel JavaDoc {
45     StyleBuilderPanel styleBuilderPanel = null;
46
47     List JavaDoc editorList = new ArrayList JavaDoc();
48
49     /** Creates new form EditorListPanel */
50     public StyleEditorListPanel(StyleBuilderPanel mainPanel) {
51         styleBuilderPanel = mainPanel;
52         initComponents();
53         // Set the background of the List to panel background
54
// (light grey) instead of white.
55
styleEditorList.setBackground(getBackground());
56         styleEditorList.setModel(new StyleEditorListModel());
57         styleEditorList.setCellRenderer(new StyleEditorListRenderer());
58     }
59
60     public void addEditor(StyleEditor editor){
61         editorList.add(editor);
62     }
63
64     public void setSelectedEditor(StyleEditor editor){
65         int index = editorList.indexOf(editor);
66         if( index >= 0){
67             styleEditorList.setSelectedIndex(index);
68         }
69     }
70
71     public Dimension JavaDoc getPreferredSize(){
72          Dimension JavaDoc dim = super.getPreferredSize();
73          dim.setSize(dim.getWidth()+20,dim.getHeight());
74          return dim;
75     }
76
77     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
78
private void initComponents() {
79         styleEditorList = new javax.swing.JList JavaDoc();
80
81         setLayout(new java.awt.BorderLayout JavaDoc());
82
83         setMinimumSize(new java.awt.Dimension JavaDoc(80, 200));
84         setOpaque(false);
85         styleEditorList.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 2, 2, 2));
86         styleEditorList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
87         styleEditorList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
88             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
89                 styleEditorListValueChanged(evt);
90             }
91         });
92
93         add(styleEditorList, java.awt.BorderLayout.NORTH);
94         styleEditorList.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("STYLE_EDITOR_LIST_ACCESSIBLE_NAME"));
95         styleEditorList.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/css/visual/ui/Bundle").getString("STYLE_EDITOR_LIST_ACCESSIBLE_DESC"));
96
97     }// </editor-fold>//GEN-END:initComponents
98

99     private void styleEditorListValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_styleEditorListValueChanged
100
if (evt.getValueIsAdjusting()) return;
101         JList JavaDoc list = (JList JavaDoc) evt.getSource();
102         StyleEditor styleEditor = (StyleEditor) list.getSelectedValue();
103         styleBuilderPanel.setEditorPanel((JPanel JavaDoc)styleEditor);
104     }//GEN-LAST:event_styleEditorListValueChanged
105

106     class StyleEditorListModel extends AbstractListModel JavaDoc{
107
108         public int getSize() {
109             return editorList.size();
110         }
111
112         public Object JavaDoc getElementAt(int i) {
113             return editorList.get(i);
114         }
115     }
116
117     private static class StyleEditorListRenderer extends DefaultListCellRenderer JavaDoc{
118
119         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
120             if (isSelected) {
121                 setBackground(list.getSelectionBackground());
122                 setForeground(list.getSelectionForeground());
123                 Color JavaDoc lineColor = list.getSelectionBackground().darker();
124                 setBorder(new LineBorder JavaDoc(lineColor, 1, true));
125             } else {
126                 setBackground(list.getBackground());
127                 setForeground(list.getForeground());
128                 setBorder(null);
129             }
130             StyleEditor styleEditor = (StyleEditor) value;
131             setText(styleEditor.getDisplayName());
132             return this;
133         }
134     }
135     
136     // Variables declaration - do not modify//GEN-BEGIN:variables
137
private javax.swing.JList JavaDoc styleEditorList;
138     // End of variables declaration//GEN-END:variables
139

140 }
141
Popular Tags