|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.project.libraries.ui; import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; import org.openide.util.NbBundle; import org.netbeans.modules.project.libraries.LibraryTypeRegistry; import org.netbeans.spi.project.libraries.LibraryTypeProvider; /** * * @author tom */ public class NewLibraryPanel extends javax.swing.JPanel { private LibrariesModel model; private Map typeMap; private javax.swing.JButton okOption; /** Creates new form NewLibraryPanel */ public NewLibraryPanel (LibrariesModel model, javax.swing.JButton okOptions ) { this.model = model; this.okOption = okOptions; initComponents(); this.name.setColumns(25); this.name.getDocument().addDocumentListener(new javax.swing.event.DocumentListener () { public void insertUpdate(javax.swing.event.DocumentEvent e) { nameChanged(); } public void removeUpdate(javax.swing.event.DocumentEvent e) { nameChanged(); } public void changedUpdate(javax.swing.event.DocumentEvent e) { nameChanged(); } }); this.initModel (); } public String getLibraryType () { Integer index = new Integer (this.libraryType.getSelectedIndex()); return (String) this.typeMap.get(index); } public String getLibraryName () { return this.name.getText(); } public void addNotify() { super.addNotify(); this.name.selectAll(); } private void initModel () { this.typeMap = new HashMap (); this.name.setText (NbBundle.getMessage (NewLibraryPanel.class,"TXT_NewLibrary")); LibraryTypeRegistry regs = LibraryTypeRegistry.getDefault(); LibraryTypeProvider[] providers = regs.getLibraryTypeProviders(); for (int i=0; i< providers.length; i++) { typeMap.put (new Integer(i),providers[i].getLibraryType()); String displayName = providers[i].getDisplayName(); if (displayName == null) { displayName = providers[i].getLibraryType(); } this.libraryType.addItem (displayName); } if (this.libraryType.getItemCount() > 0) { this.libraryType.setSelectedIndex(0); } } private void nameChanged () { String name = this.name.getText(); boolean valid = false; String message; if (name.length() == 0) { message = NbBundle.getMessage(NewLibraryPanel.class,"ERR_InvalidName"); } else { valid = LibrariesCustomizer.isValidName (model, name); if (valid) { if (isReasonableAntProperty(name)) { message = " "; //NOI18N } else { valid = false; message = NbBundle.getMessage(NewLibraryPanel.class,"ERR_InvalidCharacters"); } } else { message = MessageFormat.format(NbBundle.getMessage(NewLibraryPanel.class, "ERR_ExistingName"), new Object[] {name}); } } this.okOption.setEnabled (valid); this.status.setText(message); } private boolean isReasonableAntProperty(String name) { // XXX: there is method in PropertyUtils.isUsablePropertyName() // which should be used here but that would create dependency // on ant/project modules which is not desirable. // Anyway, the restriction on display name is just for promoD. return name.indexOf(' ') == -1; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; jLabel2 = new javax.swing.JLabel(); name = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); libraryType = new javax.swing.JComboBox(); status = new javax.swing.JLabel(); setLayout(new java.awt.GridBagLayout()); getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/project/libraries/ui/Bundle").getString("AD_NewLibraryPanel")); jLabel2.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/project/libraries/ui/Bundle").getString("MNE_AddLibraryLibraryName").charAt(0)); jLabel2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/project/libraries/ui/Bundle").getString("CTL_LibraryName")); jLabel2.setLabelFor(name); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(12, 12, 6, 6); add(jLabel2, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(12, 6, 6, 12); add(name, gridBagConstraints); name.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/project/libraries/ui/Bundle").getString("AD_LibraryName")); jLabel1.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/project/libraries/ui/Bundle").getString("MNE_AddLibraryLibraryType").charAt(0)); jLabel1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/project/libraries/ui/Bundle").getString("CTL_LibraryType")); jLabel1.setLabelFor(libraryType); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(6, 12, 6, 6); add(jLabel1, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 12); add(libraryType, gridBagConstraints); libraryType.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/project/libraries/ui/Bundle").getString("AD_LibraryType")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(6, 12, 12, 12); add(status, gridBagConstraints); }//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JComboBox libraryType; private javax.swing.JTextField name; private javax.swing.JLabel status; // End of variables declaration//GEN-END:variables } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.