001: /*
002: * JellyComponentGenerator.java
003: *
004: * Created on November 4, 2002, 3:01 PM
005: */
006:
007: package org.netbeans.modules.testtools.generator;
008:
009: import java.awt.Component;
010: import java.awt.Container;
011: import java.util.HashSet;
012: import java.util.Properties;
013: import javax.swing.JComponent;
014: import javax.swing.JDialog;
015: import javax.swing.JLabel;
016: import javax.swing.JList;
017: import javax.swing.JTable; // TODO - import org.netbeans.core.windows.services.NbPresenter;
018: import org.netbeans.jellytools.*;
019: import org.netbeans.jellytools.properties.PropertySheetOperator;
020: import org.netbeans.jemmy.operators.*;
021: import org.netbeans.modules.jemmysupport.generator.ComponentGenerator;
022: import org.netbeans.modules.jemmysupport.generator.ComponentGeneratorPanel;
023: import org.openide.explorer.propertysheet.PropertySheet;
024: import org.openide.util.NbBundle;
025: import org.openide.windows.TopComponent;
026:
027: /** Jelly Tools Component Generator class is extension of Jemmy Component Generator.
028: * @author <a href="mailto:adam.sotona@sun.com">Adam Sotona</a>
029: * @version 1.0
030: */
031: public class JellyComponentGenerator extends ComponentGenerator {
032:
033: static Properties jellyOperators;
034: static {
035: jellyOperators = new java.util.Properties();
036: try {
037: jellyOperators
038: .load(JellyComponentGenerator.class
039: .getClassLoader()
040: .getResourceAsStream(
041: "org/netbeans/modules/testtools/generator/JellyComponentGenerator.properties")); // NOI18N
042: } catch (Exception e) {
043: e.printStackTrace();
044: throw new java.lang.reflect.UndeclaredThrowableException(e,
045: NbBundle.getMessage(ComponentGeneratorPanel.class,
046: "MSG_PropertiesNotLoaded")); // NOI18N
047: }
048: }
049:
050: /** Creates a new instance of JellyComponentGenerator */
051: public JellyComponentGenerator(Properties props) {
052: super (props);
053: addOperatorRecords(jellyOperators);
054: }
055:
056: protected ComponentOperator createOperator(Component comp) {
057: if (comp instanceof PropertySheet)
058: return new PropertySheetOperator((JComponent) comp);
059: if (comp instanceof TopComponent)
060: return new TopComponentOperator((JComponent) comp);
061: // TODO if (comp instanceof NbPresenter) {
062: if (comp instanceof JDialog) {
063: NbDialogOperator dlg = new NbDialogOperator((JDialog) comp);
064: JLabel l;
065: if (((l = JLabelOperator.findJLabel((Container) comp,
066: "Steps", true, true)) != null)
067: && (l.getLabelFor() instanceof JList)) {
068: if (dlg.getTitle().startsWith("New Wizard")) {
069: return new NewWizardOperator((JDialog) comp);
070: }
071: return new WizardOperator((JDialog) comp);
072: }
073: return dlg;
074: }
075: if (comp.getClass().getName().equals(
076: "org.openide.explorer.view.TreeTable"))
077: return new TreeTableOperator((JTable) comp);
078: return super .createOperator(comp);
079: }
080:
081: static final HashSet NbDialogCaptions = new HashSet();
082: static {
083: NbDialogCaptions.add("Yes");
084: NbDialogCaptions.add("No");
085: NbDialogCaptions.add("OK");
086: NbDialogCaptions.add("Cancel");
087: NbDialogCaptions.add("Close");
088: NbDialogCaptions.add("Help");
089: };
090: static final HashSet WizardCaptions = new HashSet();
091: static {
092: NbDialogCaptions.add("Next >");
093: NbDialogCaptions.add("Back >");
094: NbDialogCaptions.add("Finish");
095: };
096:
097: protected ComponentRecord addComponent(
098: ComponentOperator componentOperator,
099: ContainerOperator containerOperator,
100: ComponentRecord parentComponent) {
101: if (containerOperator instanceof NbDialogOperator
102: && componentOperator instanceof JButtonOperator
103: && NbDialogCaptions
104: .contains(((JButtonOperator) componentOperator)
105: .getText()))
106: return null;
107: if (containerOperator instanceof WizardOperator) {
108: if (componentOperator instanceof JButtonOperator
109: && WizardCaptions
110: .contains(((JButtonOperator) componentOperator)
111: .getText()))
112: return null;
113: if (componentOperator instanceof JListOperator
114: && ((WizardOperator) containerOperator).lstSteps()
115: .getSource() == componentOperator
116: .getSource())
117: return null;
118: }
119: return super .addComponent(componentOperator, containerOperator,
120: parentComponent);
121: }
122:
123: protected boolean isTopComponent(Component comp) {
124: return (comp instanceof TopComponent)
125: || super.isTopComponent(comp);
126: }
127: }
|