1 19 20 package org.netbeans.modules.form.palette; 21 22 import java.io.File ; 23 import javax.swing.JFileChooser ; 24 import javax.swing.BorderFactory ; 25 import javax.swing.event.*; 26 import java.awt.event.*; 27 import java.beans.*; 28 29 import org.openide.WizardDescriptor; 30 31 39 40 class ChooseJARWizardPanel implements WizardDescriptor.Panel { 41 42 private JFileChooser fileChooser; 43 private static String lastDirectoryUsed; 44 45 private AddToPaletteWizard wizard; 46 47 private EventListenerList listenerList; 48 49 52 public java.awt.Component getComponent() { 53 if (fileChooser == null) { fileChooser = new JFileChooser (lastDirectoryUsed); 55 fileChooser.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 56 57 fileChooser.setName(PaletteUtils.getBundleString("CTL_SelectJAR_Caption")); fileChooser.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (0)); 61 62 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 63 fileChooser.setAcceptAllFileFilterUsed(true); 64 fileChooser.setControlButtonsAreShown(false); 65 fileChooser.setMultiSelectionEnabled(true); 66 67 fileChooser.setFileFilter(new javax.swing.filechooser.FileFilter () { 68 public boolean accept(File f) { 69 return f.isDirectory() 70 || f.getName().toLowerCase().endsWith(".jar"); } 72 public String getDescription() { 73 return PaletteUtils.getBundleString("CTL_JarArchivesMask"); } 75 }); 76 77 fileChooser.addActionListener(new ActionListener() { 78 public void actionPerformed(ActionEvent ev) { 79 wizard.stepToNext(); 80 } 81 }); 82 83 fileChooser.addPropertyChangeListener(new PropertyChangeListener() { 84 public void propertyChange(PropertyChangeEvent ev) { 85 if (JFileChooser.SELECTED_FILES_CHANGED_PROPERTY 86 .equals(ev.getPropertyName())) 87 fireStateChanged(); 88 } 89 }); 90 } 91 92 return fileChooser; 93 } 94 95 public org.openide.util.HelpCtx getHelp() { 96 return new org.openide.util.HelpCtx("beans.adding"); } 99 100 public boolean isValid() { 101 if (fileChooser != null && fileChooser.getSelectedFiles().length > 0) { 102 lastDirectoryUsed = fileChooser.getCurrentDirectory().getAbsolutePath(); 103 return true; 104 } 105 return false; 106 } 107 108 public void readSettings(Object settings) { 109 wizard = (AddToPaletteWizard) settings; 110 } 111 112 public void storeSettings(Object settings) { 113 if (fileChooser != null) 114 ((AddToPaletteWizard)settings).setJARFiles(fileChooser.getSelectedFiles()); 115 } 116 117 public void addChangeListener(ChangeListener listener) { 118 if (listenerList == null) 119 listenerList = new EventListenerList(); 120 listenerList.add(ChangeListener.class, listener); 121 } 122 123 public void removeChangeListener(ChangeListener listener) { 124 if (listenerList != null) 125 listenerList.remove(ChangeListener.class, listener); 126 } 127 128 130 void fireStateChanged() { 131 if (listenerList == null) 132 return; 133 134 ChangeEvent e = null; 135 Object [] listeners = listenerList.getListenerList(); 136 for (int i=listeners.length-2; i >= 0; i-=2) { 137 if (listeners[i] == ChangeListener.class) { 138 if (e == null) 139 e = new ChangeEvent(this); 140 ((ChangeListener)listeners[i+1]).stateChanged(e); 141 } 142 } 143 } 144 } 145 | Popular Tags |