1 19 20 package org.netbeans.modules.web.project.ui.customizer; 21 22 import java.awt.Component ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import javax.swing.DefaultListCellRenderer ; 26 import javax.swing.DefaultListModel ; 27 import javax.swing.JList ; 28 import javax.swing.ListSelectionModel ; 29 30 import org.netbeans.modules.web.api.webmodule.WebFrameworkSupport; 31 import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider; 32 33 37 public class AddFrameworkPanel extends javax.swing.JPanel { 38 39 40 public AddFrameworkPanel(List usedFrameworks) { 41 initComponents(); 42 jListFrameworks.setCellRenderer(new FrameworksListCellRenderer()); 43 createFrameworksList(usedFrameworks); 44 jListFrameworks.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 45 } 46 47 private void createFrameworksList(List usedFrameworks) { 48 List frameworks = WebFrameworkSupport.getFrameworkProviders(); 49 DefaultListModel model = new DefaultListModel (); 50 jListFrameworks.setModel(model); 51 52 for (int i = 0; i < frameworks.size(); i++) { 53 WebFrameworkProvider framework = (WebFrameworkProvider) frameworks.get(i); 54 if (usedFrameworks.size() == 0) 55 model.addElement(framework); 56 else 57 for (int j = 0; j < usedFrameworks.size(); j++) 58 if (!((WebFrameworkProvider) usedFrameworks.get(j)).getName().equals(framework.getName())) { 59 model.addElement(framework); 60 break; 61 } 62 } 63 64 65 } 66 67 68 73 private void initComponents() { 75 jScrollPane1 = new javax.swing.JScrollPane (); 76 jListFrameworks = new javax.swing.JList (); 77 jLabel1 = new javax.swing.JLabel (); 78 79 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/project/ui/customizer/Bundle").getString("ACSD_AddFramework")); 80 jScrollPane1.setViewportView(jListFrameworks); 81 jListFrameworks.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/project/ui/customizer/Bundle").getString("ACSN_ListFrameworks")); 82 jListFrameworks.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/project/ui/customizer/Bundle").getString("ACSD_ListFrameworks")); 83 84 jLabel1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/project/ui/customizer/Bundle").getString("LBL_Select_Framework")); 85 86 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 87 this.setLayout(layout); 88 layout.setHorizontalGroup( 89 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 90 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) 91 .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) 92 ); 93 layout.setVerticalGroup( 94 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 95 .add(layout.createSequentialGroup() 96 .add(jLabel1) 97 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 98 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)) 99 ); 100 } 102 103 public javax.swing.JLabel jLabel1; 105 public javax.swing.JList jListFrameworks; 106 public javax.swing.JScrollPane jScrollPane1; 107 109 public List getSelectedFrameworks() { 110 List selectedFrameworks = new LinkedList (); 111 DefaultListModel model = (DefaultListModel ) jListFrameworks.getModel(); 112 int[] indexes = jListFrameworks.getSelectedIndices(); 113 for (int i = 0; i < indexes.length; i++) 114 selectedFrameworks.add(model.get(indexes[i])); 115 116 return selectedFrameworks; 117 } 118 119 public static class FrameworksListCellRenderer extends DefaultListCellRenderer { 120 121 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 122 if (value instanceof WebFrameworkProvider) { 123 WebFrameworkProvider item = (WebFrameworkProvider) value; 124 return super.getListCellRendererComponent(list, item.getName(), index, isSelected, cellHasFocus); 125 } else 126 return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 127 } 128 } 129 130 } 131 | Popular Tags |