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

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

Introduction

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

Prototype

TextComponentAccessor

Source Link

Usage

From source file:bazaar4idea.ui.BzrConfigurationIdePanel.java

License:Apache License

public BzrConfigurationIdePanel(final BzrGlobalSettings globalSettings) {

    myQueue = new MergingUpdateQueue("idepanelqueue", 500, true, basePanel, null, basePanel, true);

    m_globalSettings = globalSettings;/*  w w w  . j  a va  2 s  .co  m*/
    loadSettings();

    String title = BzrBundle.message("bzr4intellij.configuration.title");
    String description = BzrBundle.message("bzr4intellij.configuration.description");

    pathSelector.addBrowseFolderListener(title, description, null,
            new FileChooserDescriptor(true, false, false, false, false, false),
            new TextComponentAccessor<JTextField>() {
                public String getText(JTextField component) {
                    return component.getText();
                }

                public void setText(JTextField component, String text) {
                    component.setText(text);
                }
            });

    final ActionListener defaultPathListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            pathSelector.setText(BzrGlobalSettings.DEFAULT_EXECUTABLE);
        }
    };

    pathDefaultButton.addActionListener(defaultPathListener);

    pathSelector.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            queueValidationHintsUpdate();
        }
    });
}

From source file:com.android.tools.idea.avdmanager.SkinChooser.java

License:Apache License

public SkinChooser(@Nullable Project project, boolean resolveSystemImageSkins) {
    myResolveSystemImageSkins = resolveSystemImageSkins;
    setItems(getSkins());//ww w.  j  a  v a2  s. c  om
    //noinspection unchecked
    getComboBox().setRenderer(new ColoredListCellRenderer() {
        @Override
        protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected,
                boolean hasFocus) {
            File skinFile = ((value) == null) ? NO_SKIN : (File) value;
            String skinPath = skinFile.getPath();
            if (FileUtil.filesEqual(skinFile, NO_SKIN)) {
                append("No Skin");
            } else if (skinPath.contains("/sdk/platforms/")) {
                append(skinPath.replaceAll(".*/sdk/platforms/(.*)/skins/(.*)", "$2 ($1)"));
            } else if (skinPath.contains("/sdk/system-images/")) {
                append(skinPath.replaceAll(".*/sdk/system-images/(.*)/(.*)/(.*)/skins/(.*)", "$4 ($1 $3)"));
            } else {
                append(skinFile.getName());
            }
        }
    });
    FileChooserDescriptor skinChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false,
            false);
    addBrowseFolderListener("Select Custom Skin", "Select the directory containing your custom skin definition",
            project, skinChooserDescriptor, new TextComponentAccessor<JComboBox>() {
                @Override
                public String getText(JComboBox component) {
                    return ((File) component.getSelectedItem()).getPath();
                }

                @Override
                public void setText(JComboBox component, @NotNull String text) {
                    List<File> items = getSkins();
                    File f = new File(text);
                    items.add(f);
                    setItems(items);
                    getComboBox().setSelectedItem(f);
                }
            });
    getComboBox().addItemListener(this);
    setTextFieldPreferredWidth(20);

}

From source file:com.intellij.application.options.pathMacros.PathMacroEditor.java

License:Apache License

public PathMacroEditor(String title, String macroName, String value, Validator validator) {
    super(true);/*w  ww.j a  v a  2  s .co  m*/
    setTitle(title);
    myValidator = validator;
    myNameField.setText(macroName);
    DocumentListener documentListener = new DocumentAdapter() {
        public void textChanged(DocumentEvent event) {
            updateControls();
        }
    };
    myNameField.getDocument().addDocumentListener(documentListener);
    myValueField.setText(value);
    myValueField.addBrowseFolderListener(null, null, null,
            new FileChooserDescriptor(false, true, true, false, true, false),
            new TextComponentAccessor<JTextField>() {
                public String getText(JTextField component) {
                    return component.getText();
                }

                public void setText(JTextField component, String text) {
                    final int len = text.length();
                    if (len > 0 && text.charAt(len - 1) == File.separatorChar) {
                        text = text.substring(0, len - 1);
                    }
                    component.setText(text);
                }
            });
    myValueField.getTextField().getDocument().addDocumentListener(documentListener);

    init();
    updateControls();
}

From source file:consulo.nuget.module.extension.NuGetConfigPanel.java

License:Apache License

public NuGetConfigPanel(final NuGetMutableModuleExtension moduleExtension) {
    super(new VerticalFlowLayout(VerticalFlowLayout.TOP));

    final JBTextField textField = new JBTextField();

    textField.getEmptyText().setText(VfsUtil.urlToPath(
            moduleExtension.getModule().getModuleDirUrl() + "/" + NuGetModuleExtension.PACKAGES_CONFIG));

    String configFileUrl = moduleExtension.getConfigFileUrl();
    if (!StringUtil.isEmpty(configFileUrl)) {
        textField.setText(FileUtil.toSystemDependentName(VfsUtil.urlToPath(configFileUrl)));
    }/*w w  w .  ja  va2s. c om*/

    TextFieldWithBrowseButton browseButton = new TextFieldWithBrowseButton(textField);
    browseButton.addBrowseFolderListener("Select File", "Select NuGet package config file",
            moduleExtension.getProject(),
            FileChooserDescriptorFactory.createSingleFileDescriptor(XmlFileType.INSTANCE),
            new TextComponentAccessor<JTextField>() {
                @Override
                public String getText(JTextField component) {
                    return FileUtil.toSystemDependentName(component.getText());
                }

                @Override
                public void setText(JTextField component, String text) {
                    component.setText(FileUtil.toSystemDependentName(text));
                }
            });
    textField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            moduleExtension.setConfigFilePath(FileUtil.toSystemIndependentName(textField.getText()));
        }
    });
    add(LabeledComponent.create(browseButton, "Config file:"));
}

From source file:jz.hwd.envvars.table.HWDEnvVarEditor.java

License:Apache License

public HWDEnvVarEditor(String title, String macroName, String value, Validator validator) {
    super(true);/*from   ww  w .j a v a 2  s  . com*/
    setTitle(title);
    myValidator = validator;
    myNameField.setText(macroName);
    DocumentListener documentListener = new DocumentAdapter() {
        public void textChanged(DocumentEvent event) {
            updateControls();
        }
    };
    myNameField.getDocument().addDocumentListener(documentListener);
    myValueField.setText(value);
    myValueField.addBrowseFolderListener(null, null, null,
            new FileChooserDescriptor(false, true, true, false, true, false),
            new TextComponentAccessor<JTextField>() {
                public String getText(JTextField component) {
                    return component.getText();
                }

                public void setText(JTextField component, @NotNull String text) {
                    final int len = text.length();
                    if (len > 0 && text.charAt(len - 1) == File.separatorChar) {
                        text = text.substring(0, len - 1);
                    }
                    component.setText(text);
                }
            });
    myValueField.getTextField().getDocument().addDocumentListener(documentListener);

    init();
    updateControls();
}

From source file:org.intellij.xquery.runner.ui.run.main.module.ModuleSelector.java

License:Apache License

private static TextComponentAccessor<EditorTextField> getTextComponentAccessor() {
    return new TextComponentAccessor<EditorTextField>() {
        @Override/*from   w ww.ja va  2 s . c om*/
        public String getText(EditorTextField component) {
            String text = component.getText();
            final VirtualFile file = VirtualFileManager.getInstance()
                    .findFileByUrl(VfsUtil.pathToUrl(text.replace(File.separatorChar, '/')));
            if (file != null && !file.isDirectory()) {
                final VirtualFile parent = file.getParent();
                assert parent != null;
                return parent.getPresentableUrl();
            }
            return text;
        }

        @Override
        public void setText(EditorTextField component, String text) {
            component.setText(text);
        }
    };
}

From source file:org.mustbe.consulo.nodejs.run.NodeJSConfigurationEditor.java

License:Apache License

public NodeJSConfigurationEditor(Project project, NodeJSConfiguration nodeJSConfiguration) {
    myNodeJSConfiguration = nodeJSConfiguration;

    myScriptTextField.addBrowseFolderListener("Select Script", "Select Script File For Execution", project,
            new FileChooserDescriptor(true, false, false, false, false, false),
            new TextComponentAccessor<JTextField>() {
                @Override/*from   ww w .j  av a  2  s .  c om*/
                public String getText(JTextField jTextField) {
                    return jTextField.getText();
                }

                @Override
                public void setText(JTextField jTextField, String text) {
                    Module selectedItem = (Module) myModuleBox.getSelectedItem();
                    if (selectedItem == null) {
                        jTextField.setText(text);
                    } else {
                        String moduleDirPath = selectedItem.getModuleDirPath();
                        String relativePath = FileUtil.getRelativePath(moduleDirPath,
                                FileUtil.toSystemIndependentName(text), '/');
                        jTextField.setText(relativePath);
                    }
                }
            });
}