1 19 20 21 package org.netbeans.modules.openfile; 22 23 24 import java.io.File ; 25 import java.awt.BorderLayout ; 26 import java.awt.Component ; 27 import java.awt.Dimension ; 28 import java.util.List ; 29 import javax.swing.event.ListSelectionEvent ; 30 import javax.swing.event.ListSelectionListener ; 31 import javax.swing.Icon ; 32 import javax.swing.ImageIcon ; 33 import javax.swing.JButton ; 34 import javax.swing.JLabel ; 35 import javax.swing.JList ; 36 import javax.swing.JTextField ; 37 import javax.swing.JPanel ; 38 import javax.swing.JScrollPane ; 39 import javax.swing.JTextArea ; 40 import javax.swing.ListCellRenderer ; 41 import javax.swing.ListSelectionModel ; 42 import java.awt.event.*; 43 import org.openide.util.NbBundle; 44 45 46 50 public class PackagePanel extends JPanel { 51 52 private File f; 53 54 private int pkgLevel; 55 56 private List dirs; 57 58 private List pkgs; 59 60 61 62 public PackagePanel(File f, int pkgLevel, List dirs, List pkgs) { 63 this.f = f; 64 this.pkgLevel = pkgLevel; 65 this.dirs = dirs; 66 this.pkgs = pkgs; 67 68 initComponents2(); 69 70 initAccessibility(); 71 } 72 73 74 JButton getOKButton() { 75 return okButton; 76 } 77 78 JButton getCancelButton() { 79 return cancelButton; 80 } 81 82 JList getList() { 83 return list; 84 } 85 86 87 private void initComponents2() { 88 okButton = new JButton (NbBundle.getMessage(PackagePanel.class, "LBL_okButton")); 89 cancelButton = new JButton (NbBundle.getMessage(PackagePanel.class, "LBL_cancelButton")); 90 list = new JList (pkgs.toArray()); 91 92 setLayout (new BorderLayout (0, 5)); 93 setBorder (new javax.swing.border.EmptyBorder (8, 8, 8, 8)); 94 95 textArea = new JTextArea (); 96 textArea.setDisabledTextColor (javax.swing.UIManager.getColor ("Label.foreground")); 98 textArea.setFont (javax.swing.UIManager.getFont ("Label.font")); 100 textArea.setText (NbBundle.getMessage(PackagePanel.class, pkgLevel == -1 ? "TXT_whereMountNoSuggest" : "TXT_whereMountSuggest", f.getName ())); 101 textArea.setEditable (false); 102 textArea.setEnabled (false); 103 textArea.setOpaque (false); 104 textArea.setLineWrap (true); 105 textArea.setWrapStyleWord (true); 106 add (textArea, BorderLayout.NORTH); 107 108 list.setVisibleRowCount (5); 109 list.setSelectionMode (ListSelectionModel.SINGLE_SELECTION); 110 if (pkgLevel != -1) list.setSelectedIndex (pkgLevel); 111 list.setCellRenderer (new ListCellRenderer () { 112 private Icon folderIcon = new ImageIcon (OpenFile.class.getResource ("folder.gif")); private Icon rootFolderIcon = new ImageIcon (OpenFile.class.getResource ("rootFolder.gif")); private final JLabel lab = new JLabel (); 115 116 public Component getListCellRendererComponent (JList lst, Object value, int index, boolean isSelected, boolean cellHasFocus) { 117 String pkg2 = (String ) value; 118 if (pkg2.equals ("")) { lab.setText (NbBundle.getMessage(PackagePanel.class, "LBL_packageWillBeDefault")); 120 lab.setIcon (rootFolderIcon); 121 } else { 122 lab.setText (NbBundle.getMessage(PackagePanel.class, "LBL_packageWillBe", pkg2)); 123 lab.setIcon (folderIcon); 124 } 125 if (isSelected) { 126 lab.setBackground (lst.getSelectionBackground ()); 127 lab.setForeground (lst.getSelectionForeground ()); 128 } else { 129 lab.setBackground (lst.getBackground ()); 130 lab.setForeground (lst.getForeground ()); 131 } 132 lab.setEnabled (lst.isEnabled ()); 133 lab.setFont (lst.getFont ()); 134 lab.setOpaque (true); 135 return lab; 136 } 137 }); 138 add (new JScrollPane (list), BorderLayout.CENTER); 139 140 final JTextField field = new JTextField (); 143 field.setEditable(false); 146 field.setEnabled(true); 147 field.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(PackagePanel.class, "ACS_Field")); 149 field.selectAll(); 150 field.addFocusListener(new FocusListener() { 151 public void focusGained(FocusEvent e) { 152 field.selectAll(); 153 } 154 155 public void focusLost(java.awt.event.FocusEvent e){ 156 } 157 }); 158 add (field, BorderLayout.SOUTH); 159 160 setPreferredSize (new Dimension (450, 300)); 161 162 list.addListSelectionListener (new ListSelectionListener () { 163 public void valueChanged (ListSelectionEvent ev) { 164 updateLabelEtcFromList (field, list, dirs, okButton); 165 } 166 }); 167 updateLabelEtcFromList (field, list, dirs, okButton); 168 } 169 170 private void initAccessibility() { 171 this.getAccessibleContext ().setAccessibleDescription (textArea.getText ()); 172 okButton.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(PackagePanel.class, "ACS_LBL_okButton")); 173 cancelButton.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(PackagePanel.class, "ACS_LBL_cancelButton")); 174 list.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PackagePanel.class, "ACSN_List")); 175 list.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(PackagePanel.class, "ACSD_List")); 176 } 177 178 179 private static void updateLabelEtcFromList (JTextField field, JList list, List dirs, JButton okButton) { 180 int idx = list.getSelectedIndex (); 181 if (idx == -1) { 182 field.setText (" "); field.getAccessibleContext().setAccessibleName(" "); 184 okButton.setEnabled (false); 185 } else { 186 File dir = (File ) dirs.get(idx); 187 field.setText (NbBundle.getMessage(PackagePanel.class, "LBL_dirWillBe", dir.getAbsolutePath ())); 188 field.getAccessibleContext().setAccessibleName(NbBundle.getMessage(PackagePanel.class, "LBL_dirWillBe", dir.getAbsolutePath ())); 189 okButton.setEnabled (true); 190 } 191 } 192 193 194 199 private void initComponents() { 201 setLayout(new java.awt.BorderLayout ()); 202 203 } 205 206 private JButton okButton; 207 private JButton cancelButton; 208 private JList list; 209 private JTextArea textArea; 210 213 } 214 | Popular Tags |