Example usage for com.intellij.openapi.ui FixedSizeButton FixedSizeButton

List of usage examples for com.intellij.openapi.ui FixedSizeButton FixedSizeButton

Introduction

In this page you can find the example usage for com.intellij.openapi.ui FixedSizeButton FixedSizeButton.

Prototype

public FixedSizeButton() 

Source Link

Usage

From source file:com.intellij.execution.junit2.configuration.JUnitConfigurable.java

License:Apache License

public JUnitConfigurable(final Project project) {
    myProject = project;/* www.ja va 2  s  .  c o  m*/
    myModel = new JUnitConfigurationModel(project);
    myModuleSelector = new ConfigurationModuleSelector(project, getModulesComponent());
    myCommonJavaParameters.setModuleContext(myModuleSelector.getModule());
    myModule.getComponent().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            myCommonJavaParameters.setModuleContext(myModuleSelector.getModule());
        }
    });
    myBrowsers = new BrowseModuleValueActionListener[] { new PackageChooserActionListener(project),
            new TestClassBrowser(project), new MethodBrowser(project), new TestsChooserActionListener(project),
            new BrowseModuleValueActionListener(project) {
                @Override
                protected String showDialog() {
                    final VirtualFile virtualFile = FileChooser.chooseFile(
                            FileChooserDescriptorFactory.createSingleFolderDescriptor(), project, null);
                    if (virtualFile != null) {
                        return FileUtil.toSystemDependentName(virtualFile.getPath());
                    }
                    return null;
                }
            } };
    // Garbage support
    final DefaultComboBoxModel aModel = new DefaultComboBoxModel();
    aModel.addElement(JUnitConfigurationModel.ALL_IN_PACKAGE);
    aModel.addElement(JUnitConfigurationModel.DIR);
    aModel.addElement(JUnitConfigurationModel.PATTERN);
    aModel.addElement(JUnitConfigurationModel.CLASS);
    aModel.addElement(JUnitConfigurationModel.METHOD);
    myTypeChooser.setModel(aModel);
    myTypeChooser.setRenderer(new ListCellRendererWrapper<Integer>() {
        @Override
        public void customize(JList list, Integer value, int index, boolean selected, boolean hasFocus) {
            switch (value) {
            case JUnitConfigurationModel.ALL_IN_PACKAGE:
                setText("All in package");
                break;
            case JUnitConfigurationModel.DIR:
                setText("All in directory");
                break;
            case JUnitConfigurationModel.PATTERN:
                setText("Pattern");
                break;
            case JUnitConfigurationModel.CLASS:
                setText("Class");
                break;
            case JUnitConfigurationModel.METHOD:
                setText("Method");
                break;
            }
        }
    });

    myTestLocations[JUnitConfigurationModel.ALL_IN_PACKAGE] = myPackage;
    myTestLocations[JUnitConfigurationModel.CLASS] = myClass;
    myTestLocations[JUnitConfigurationModel.METHOD] = myMethod;
    myTestLocations[JUnitConfigurationModel.DIR] = myDir;

    final JPanel panel = myPattern.getComponent();
    panel.setLayout(new BorderLayout());
    myPatternTextField = new TextFieldWithBrowseButton();
    myPatternTextField.setButtonIcon(IconUtil.getAddIcon());
    panel.add(myPatternTextField, BorderLayout.CENTER);
    final FixedSizeButton editBtn = new FixedSizeButton();
    editBtn.setIcon(AllIcons.Actions.ShowViewer);
    editBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Messages.showTextAreaDialog(myPatternTextField.getTextField(), "Configure suite tests",
                    "EditParametersPopupWindow");
        }
    });
    panel.add(editBtn, BorderLayout.EAST);
    myTestLocations[JUnitConfigurationModel.PATTERN] = myPattern;

    final FileChooserDescriptor dirFileChooser = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    dirFileChooser.setHideIgnored(false);
    final JTextField textField = myDir.getComponent().getTextField();
    InsertPathAction.addTo(textField, dirFileChooser);
    FileChooserFactory.getInstance().installFileCompletion(textField, dirFileChooser, true, null);
    // Done

    myModel.setListener(this);

    myTypeChooser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final Object selectedItem = myTypeChooser.getSelectedItem();
            myModel.setType((Integer) selectedItem);
            changePanel();
        }
    });
    myModel.setType(JUnitConfigurationModel.CLASS);
    installDocuments();
    addRadioButtonsListeners(new JRadioButton[] { myWholeProjectScope, mySingleModuleScope, myModuleWDScope },
            null);
    myWholeProjectScope.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(final ChangeEvent e) {
            onScopeChanged();
        }
    });

    myCommonJavaParameters.getProgramParametersComponent().setVisible(false);

    setAnchor(mySearchForTestsLabel);
    myModule.setAnchor(myAlternativeJREPanel.getCbEnabled());
    myCommonJavaParameters.setAnchor(myAlternativeJREPanel.getCbEnabled());
}

From source file:com.theoryinpractice.testng.configuration.TestNGConfigurationEditor.java

License:Apache License

public TestNGConfigurationEditor(Project project) {
    this.project = project;
    BrowseModuleValueActionListener[] browseListeners = new BrowseModuleValueActionListener[] {
            new PackageBrowser(project), new TestClassBrowser(project, this), new MethodBrowser(project, this),
            new GroupBrowser(project, this), new SuiteBrowser(project), new TestClassBrowser(project, this) {
                @Override//w  ww  .  j  a  va2  s.  c  om
                protected void onClassChoosen(PsiClass psiClass) {
                    final JTextField textField = myPatternTextField.getTextField();
                    final String text = textField.getText();
                    textField.setText(text + (text.length() > 0 ? "||" : "") + psiClass.getQualifiedName());
                }

                @Override
                public void actionPerformed(ActionEvent e) {
                    showDialog();
                }
            } };
    model = new TestNGConfigurationModel(project);
    model.setListener(this);
    createView();
    moduleSelector = new ConfigurationModuleSelector(project, getModulesComponent());
    commonJavaParameters.setModuleContext(moduleSelector.getModule());
    moduleClasspath.getComponent().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            commonJavaParameters.setModuleContext(moduleSelector.getModule());
        }
    });

    final JPanel panel = myPattern.getComponent();
    panel.setLayout(new BorderLayout());
    myPatternTextField = new TextFieldWithBrowseButton();
    myPatternTextField.setButtonIcon(IconUtil.getAddIcon());
    panel.add(myPatternTextField, BorderLayout.CENTER);
    final FixedSizeButton editBtn = new FixedSizeButton();
    editBtn.setIcon(AllIcons.Actions.ShowViewer);
    editBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Messages.showTextAreaDialog(myPatternTextField.getTextField(), "Configure suite tests",
                    "EditParametersPopupWindow");
        }
    });
    panel.add(editBtn, BorderLayout.EAST);

    registerListener(
            new JRadioButton[] { packageTest, classTest, methodTest, groupTest, suiteTest, patternTest },
            new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    ButtonModel buttonModel = (ButtonModel) e.getSource();
                    if (buttonModel.isSelected()) {
                        if (buttonModel == packageTest.getModel()) {
                            model.setType(TestType.PACKAGE);
                        } else if (buttonModel == classTest.getModel()) {
                            model.setType(TestType.CLASS);
                        } else if (buttonModel == methodTest.getModel()) {
                            model.setType(TestType.METHOD);
                        } else if (buttonModel == groupTest.getModel()) {
                            model.setType(TestType.GROUP);
                        } else if (buttonModel == suiteTest.getModel()) {
                            model.setType(TestType.SUITE);
                        } else if (buttonModel == patternTest.getModel()) {
                            model.setType(TestType.PATTERN);
                        }
                        redisplay();
                    }
                }
            });
    registerListener(new JRadioButton[] { packagesInProject, packagesInModule, packagesAcrossModules }, null);
    packagesInProject.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            evaluateModuleClassPath();
        }
    });

    LabeledComponent[] components = new LabeledComponent[] { packageField, classField, methodField, groupField,
            suiteField, myPattern };
    for (int i = 0; i < components.length; i++) {
        JComponent field = components[i].getComponent();
        Object document = model.getDocument(i);
        if (field instanceof TextFieldWithBrowseButton) {
            ((TextFieldWithBrowseButton) field).getTextField().setDocument((PlainDocument) document);
        } else if (field instanceof EditorTextFieldWithBrowseButton) {
            final com.intellij.openapi.editor.Document componentDocument = ((EditorTextFieldWithBrowseButton) field)
                    .getChildComponent().getDocument();
            model.setDocument(i, componentDocument);
        } else {
            field = myPatternTextField;
            document = new PlainDocument();
            ((TextFieldWithBrowseButton) field).getTextField().setDocument((Document) document);
            model.setDocument(i, document);
        }

        browseListeners[i].setField((ComponentWithBrowseButton) field);
    }
    model.setType(TestType.CLASS);
    propertiesFile.getComponent().getTextField().setDocument(model.getPropertiesFileDocument());
    outputDirectory.getComponent().getTextField().setDocument(model.getOutputDirectoryDocument());

    commonJavaParameters.setProgramParametersLabel(
            ExecutionBundle.message("junit.configuration.test.runner.parameters.label"));

    setAnchor(outputDirectory.getLabel());
    alternateJDK.setAnchor(moduleClasspath.getLabel());
    commonJavaParameters.setAnchor(moduleClasspath.getLabel());
}