|
What this is
This file is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Java by Example" TM.
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 2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.junit.wizards;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ResourceBundle;
import javax.accessibility.AccessibleContext;
import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import org.netbeans.modules.junit.GuiUtils;
import org.netbeans.modules.junit.NamedObject;
import org.netbeans.modules.junit.SizeRestrictedPanel;
import org.openide.awt.Mnemonics;
import org.openide.filesystems.FileObject;
import org.openide.util.NbBundle;
/**
* Panel which serves as a visual component for step "Settings"
* of the wizards.
*
* @author Marian Petras
*/
public class SettingsPanel extends JPanel {
/** label displaying the project name */
private JLabel lblProjectName;
/** label displaying the (target) folder name */
private JLabel lblTestFileName;
/** combo-box for choice of template */
private JComboBox cboTemplate;
/**
* Creates a new instance of SettingsPanel .
*
* @param projectName project name to be displayed in the panel
* @param folderName folder name to be displayed in the panel
* @param defaultTemplate resource path of the default template
* @param optionsPanel panel containing checkboxes and other GUI
* elements, to be displayed in the lower part
* of the panel
*/
public SettingsPanel(String projectName,
String testFileName,
String defaultTemplate,
JComponent optionsPanel) {
/* Create the components: */
ResourceBundle bundle = NbBundle.getBundle(SettingsPanel.class);
JLabel lblProject = new JLabel();
JLabel lblFileName = new JLabel();
JLabel lblTemplate = new JLabel();
Mnemonics.setLocalizedText(lblProject,
bundle.getString("LBL_Project")); //NOI18N
Mnemonics.setLocalizedText(lblFileName,
bundle.getString("LBL_Filename")); //NOI18N
Mnemonics.setLocalizedText(lblTemplate,
bundle.getString("LBL_Template")); //NOI18N
lblProjectName = new JLabel(projectName);
lblTestFileName = new JLabel(testFileName);
cboTemplate = GuiUtils.createTemplateChooser(defaultTemplate);
lblProject.setLabelFor(lblProjectName);
lblFileName.setLabelFor(lblTestFileName);
lblTemplate.setLabelFor(cboTemplate);
AccessibleContext accessCtx;
accessCtx = lblProjectName.getAccessibleContext();
accessCtx.setAccessibleName(
bundle.getString("AD_Name_Project_name")); //NOI18N
accessCtx.setAccessibleDescription(
bundle.getString("AD_Descr_Project_name")); //NOI18N
accessCtx = lblTestFileName.getAccessibleContext();
accessCtx.setAccessibleName(
bundle.getString("AD_Name_Test_class_file_name")); //NOI18N
accessCtx.setAccessibleDescription(
bundle.getString("AD_Descr_Test_class_file_name")); //NOI18N
accessCtx = cboTemplate.getAccessibleContext();
accessCtx.setAccessibleName(
bundle.getString("AD_Name_Test_class_template")); //NOI18N
accessCtx.setAccessibleDescription(
bundle.getString("AD_Descr_Test_class_template")); //NOI18N
bundle = null;
/* set layout of the components: */
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.weightx = 0.0f;
gbc.insets = new Insets(0, 0, 6, 12);
add(lblProject, gbc);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1.0f;
gbc.insets = new Insets(0, 0, 6, 0);
add(lblProjectName, gbc);
gbc.gridy++;
gbc.gridwidth = 1;
gbc.weightx = 0.0f;
gbc.insets = new Insets(0, 0, 0, 12);
add(lblFileName, gbc);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1.0f;
gbc.insets = new Insets(0, 0, 0, 0);
add(lblTestFileName, gbc);
gbc.gridy++;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(12, 0, 18, 0);
add(createSeparator(), gbc);
gbc.fill = GridBagConstraints.NONE;
gbc.gridy++;
gbc.gridwidth = 1;
gbc.weightx = 0.0f;
gbc.insets = new Insets(0, 0, 11, 12);
add(lblTemplate, gbc);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.weightx = 1.0f;
gbc.insets = new Insets(0, 0, 11, 0);
add(cboTemplate, gbc);
gbc.gridy++;
gbc.insets = new Insets(0, 0, 0, 0);
add(optionsPanel, gbc);
/* Create a vertical filler at the bottom part of this panel: */
gbc.gridy++;
gbc.weighty = 1.0f;
add(new JPanel(), gbc);
}
/**
*/
void setProjectName(String projectName) {
lblProjectName.setText(projectName);
}
/**
*/
void setTestFileName(String testFileName) {
lblTestFileName.setText(testFileName);
}
/**
* Returns a chosen template.
*
* @return FileObject representing the template chosen
* in the combo-box; or null if no template is chosen
* (because of the combo-box being empty)
*/
FileObject getTemplate() {
Object selectedObject = cboTemplate.getSelectedItem();
if (selectedObject == null) {
return null;
}
return (FileObject) ((NamedObject) selectedObject).object;
}
/**
* Selects a given template.
*
* @param templatePath path of the template which should be selected;
* may be null - then no item is selected
*/
void selectTemplate(String templatePath) {
if (templatePath == null) {
return;
}
ComboBoxModel model = cboTemplate.getModel();
int itemsCount = model.getSize();
if (itemsCount == 0) {
return;
}
for (int i = 0; i < itemsCount; i++) {
NamedObject namedObj = (NamedObject) model.getElementAt(i);
FileObject template = (FileObject) namedObj.object;
if (template.getPath().equals(templatePath)) {
cboTemplate.setSelectedIndex(i);
return;
}
}
}
/**
* Creates a separator - horizontal line.
*
* @return created separator
*/
private JComponent createSeparator() {
JPanel panel = new SizeRestrictedPanel(false, true);
panel.setPreferredSize(new java.awt.Dimension(1, 1));
panel.setBorder(BorderFactory.createMatteBorder(
1, 0, 0, 0,
UIManager.getDefaults().getColor("Label.foreground"))); //NOI18N
return panel;
}
}
|