1 19 20 package org.netbeans.modules.j2ee.persistence.wizard.unit; 21 22 import java.awt.Component ; 23 import javax.swing.JLabel ; 24 import javax.swing.JList ; 25 import javax.swing.ListCellRenderer ; 26 import org.netbeans.api.db.explorer.DatabaseConnection; 27 import org.openide.util.NbBundle; 28 29 33 public class JdbcListCellRenderer extends JLabel implements ListCellRenderer { 34 35 public JdbcListCellRenderer() { 36 setOpaque(true); 37 setHorizontalAlignment(LEFT); 38 setVerticalAlignment(CENTER); 39 } 40 41 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 42 String text = value == null ? NbBundle.getMessage(JdbcListCellRenderer.class, "LBL_NoAvailableConnection") : String.valueOf(value); 44 45 if (value instanceof DatabaseConnection) { 46 DatabaseConnection connection = (DatabaseConnection) value; 47 text = connection.getName(); 48 } 49 50 if (isSelected) { 51 setBackground(list.getSelectionBackground()); 52 setForeground(list.getSelectionForeground()); 53 } else { 54 setBackground(list.getBackground()); 55 setForeground(list.getForeground()); 56 } 57 58 setFont(list.getFont()); 59 setText(text); 60 61 return this; 62 } 63 64 } 65 | Popular Tags |