1 19 20 25 26 package org.netbeans.modules.css.visual.ui; 27 28 import java.awt.Color ; 29 import java.awt.Component ; 30 import java.awt.Dimension ; 31 import java.util.ArrayList ; 32 import java.util.List ; 33 import javax.swing.AbstractListModel ; 34 import javax.swing.DefaultListCellRenderer ; 35 import javax.swing.JList ; 36 import javax.swing.JPanel ; 37 import javax.swing.border.LineBorder ; 38 39 44 public class StyleEditorListPanel extends javax.swing.JPanel { 45 StyleBuilderPanel styleBuilderPanel = null; 46 47 List editorList = new ArrayList (); 48 49 50 public StyleEditorListPanel(StyleBuilderPanel mainPanel) { 51 styleBuilderPanel = mainPanel; 52 initComponents(); 53 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 getPreferredSize(){ 72 Dimension dim = super.getPreferredSize(); 73 dim.setSize(dim.getWidth()+20,dim.getHeight()); 74 return dim; 75 } 76 77 private void initComponents() { 79 styleEditorList = new javax.swing.JList (); 80 81 setLayout(new java.awt.BorderLayout ()); 82 83 setMinimumSize(new java.awt.Dimension (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 () { 88 public void valueChanged(javax.swing.event.ListSelectionEvent 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 } 99 private void styleEditorListValueChanged(javax.swing.event.ListSelectionEvent evt) { if (evt.getValueIsAdjusting()) return; 101 JList list = (JList ) evt.getSource(); 102 StyleEditor styleEditor = (StyleEditor) list.getSelectedValue(); 103 styleBuilderPanel.setEditorPanel((JPanel )styleEditor); 104 } 106 class StyleEditorListModel extends AbstractListModel { 107 108 public int getSize() { 109 return editorList.size(); 110 } 111 112 public Object getElementAt(int i) { 113 return editorList.get(i); 114 } 115 } 116 117 private static class StyleEditorListRenderer extends DefaultListCellRenderer { 118 119 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 120 if (isSelected) { 121 setBackground(list.getSelectionBackground()); 122 setForeground(list.getSelectionForeground()); 123 Color lineColor = list.getSelectionBackground().darker(); 124 setBorder(new LineBorder (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 private javax.swing.JList styleEditorList; 138 140 } 141 | Popular Tags |