1 19 20 package org.netbeans.bluej.options; 21 22 import java.io.File ; 23 import java.io.File ; 24 import javax.swing.JFileChooser ; 25 import javax.swing.SwingUtilities ; 26 import javax.swing.filechooser.FileFilter ; 27 import org.netbeans.bluej.BluejProject; 28 import org.openide.DialogDisplayer; 29 import org.openide.NotifyDescriptor; 30 import org.openide.util.NbBundle; 31 import org.openide.util.Utilities; 32 33 37 public class BlueJPanel extends javax.swing.JPanel { 38 39 private boolean changed = false; 40 41 public BlueJPanel() { 42 initComponents(); 43 } 44 45 50 private void initComponents() { 52 lblHome = new javax.swing.JLabel (); 53 txtHome = new javax.swing.JTextField (); 54 btnHome = new javax.swing.JButton (); 55 lblHint = new javax.swing.JLabel (); 56 57 lblHome.setLabelFor(txtHome); 58 lblHome.setText(org.openide.util.NbBundle.getBundle(BlueJPanel.class).getString("LBL_Home")); 59 60 btnHome.setText(org.openide.util.NbBundle.getBundle(BlueJPanel.class).getString("BTN_Home")); 61 btnHome.addActionListener(new java.awt.event.ActionListener () { 62 public void actionPerformed(java.awt.event.ActionEvent evt) { 63 btnHomeActionPerformed(evt); 64 } 65 }); 66 67 lblHint.setText(org.openide.util.NbBundle.getBundle(BlueJPanel.class).getString("LBL_Hint")); 68 lblHint.setVerticalAlignment(javax.swing.SwingConstants.TOP); 69 70 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 71 this.setLayout(layout); 72 layout.setHorizontalGroup( 73 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 74 .add(layout.createSequentialGroup() 75 .addContainerGap() 76 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 77 .add(lblHint, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE) 78 .add(layout.createSequentialGroup() 79 .add(lblHome) 80 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 81 .add(txtHome, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE) 82 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 83 .add(btnHome))) 84 .addContainerGap()) 85 ); 86 layout.setVerticalGroup( 87 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 88 .add(layout.createSequentialGroup() 89 .addContainerGap() 90 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 91 .add(lblHome) 92 .add(txtHome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 93 .add(btnHome)) 94 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 95 .add(lblHint, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 96 .add(136, 136, 136)) 97 ); 98 } 100 private void btnHomeActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (txtHome.getText()); 102 if (Utilities.getOperatingSystem() == Utilities.OS_MAC) { 103 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 104 chooser.setFileFilter(new FileFilter () { 105 public boolean accept(File f) { 106 return f.isDirectory(); } 108 public String getDescription() { 109 return NbBundle.getMessage(BlueJPanel.class, "Macosx_filter"); 110 } 111 }); 112 } else { 113 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 114 } 115 int r = chooser.showDialog( 116 SwingUtilities.getWindowAncestor(this), 117 NbBundle.getMessage(BlueJPanel.class, "Select_Directory")); 118 if (r == JFileChooser.APPROVE_OPTION) { 119 File file = chooser.getSelectedFile(); 120 File bjLib = BluejProject.getUserLibPath(file); 121 System.out.println("bjhome=" + bjLib.getAbsolutePath()); 122 if (!bjLib.exists()) { 123 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( 124 NbBundle.getMessage(BlueJPanel.class, "Not_a_bluej_home", file), 125 NotifyDescriptor.Message.WARNING_MESSAGE)); 126 return; 127 } 128 txtHome.setText(file.getAbsolutePath()); 129 changed = true; 130 } 131 132 } 134 boolean isChangedData() { 135 return changed; 136 } 137 138 boolean isValidData() { 139 return true; 140 } 141 142 String getBlueJHome() { 143 return txtHome.getText().trim(); 144 } 145 146 void setBlueJHome(String home) { 147 txtHome.setText(home); 148 } 149 150 151 private javax.swing.JButton btnHome; 153 private javax.swing.JLabel lblHint; 154 private javax.swing.JLabel lblHome; 155 private javax.swing.JTextField txtHome; 156 158 } 159 | Popular Tags |