bazaar4idea.ui.BzrSetExecutableDialog.java Source code

Java tutorial

Introduction

Here is the source code for bazaar4idea.ui.BzrSetExecutableDialog.java

Source

// Copyright 2009 Victor Iacoban
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions and
// limitations under the License.
package bazaar4idea.ui;

import bazaar4idea.i18n.BzrBundle;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;

import javax.swing.*;
import java.awt.*;
import java.util.ResourceBundle;

public class BzrSetExecutableDialog extends DialogWrapper {

    private JPanel centerPanel;

    private TextFieldWithBrowseButton hgExecutablePath;

    private JLabel infoLabel;

    private JLabel errorLabel;

    public BzrSetExecutableDialog(Project project) {
        super(project, false);
        Object[] params1 = new Object[] {};
        String title = BzrBundle.message("bzr4intellij.configuration.title", params1);
        Object[] params = new Object[] {};
        String description = BzrBundle.message("bzr4intellij.configuration.description", params);

        hgExecutablePath.addBrowseFolderListener(title, description, null,
                new FileChooserDescriptor(true, false, false, false, false, false));
        init();
    }

    @Override
    protected JComponent createCenterPanel() {
        return centerPanel;
    }

    public void setBadHgPath(String hgPath) {
        hgExecutablePath.setText(hgPath);
        Object[] params = new Object[] { hgPath };
        errorLabel.setText(BzrBundle.message("bzr4intellij.error.invalidExecutable", params));
    }

    public String getNewHgPath() {
        return hgExecutablePath.getText();
    }

    {
        // GUI initializer generated by IntelliJ IDEA GUI Designer
        // >>> IMPORTANT!! <<<
        // DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /** Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        centerPanel = new JPanel();
        centerPanel.setLayout(new GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1));
        hgExecutablePath = new TextFieldWithBrowseButton();
        centerPanel.add(hgExecutablePath,
                new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE,
                        GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW,
                        GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null,
                        new Dimension(400, -1), null, 0, false));
        infoLabel = new JLabel();
        this.$$$loadLabelText$$$(infoLabel, ResourceBundle.getBundle("org/emergent/bzr4j/intellij/BzrVcsMessages")
                .getString("bzr4intellij.executable.full_path"));
        centerPanel.add(infoLabel,
                new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                        GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
                        false));
        errorLabel = new JLabel();
        errorLabel.setFont(new Font(errorLabel.getFont().getName(), Font.ITALIC, errorLabel.getFont().getSize()));
        errorLabel.setForeground(Color.red);
        this.$$$loadLabelText$$$(errorLabel, ResourceBundle.getBundle("org/emergent/bzr4j/intellij/BzrVcsMessages")
                .getString("bzr4intellij.error.invalidExecutable"));
        centerPanel.add(errorLabel,
                new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                        GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
                        false));
        final Spacer spacer1 = new Spacer();
        centerPanel.add(spacer1,
                new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
                        GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
    }

    /** @noinspection ALL */
    private void $$$loadLabelText$$$(JLabel component, String text) {
        StringBuffer result = new StringBuffer();
        boolean haveMnemonic = false;
        char mnemonic = '\0';
        int mnemonicIndex = -1;
        for (int i = 0; i < text.length(); i++) {
            if (text.charAt(i) == '&') {
                i++;
                if (i == text.length())
                    break;
                if (!haveMnemonic && text.charAt(i) != '&') {
                    haveMnemonic = true;
                    mnemonic = text.charAt(i);
                    mnemonicIndex = result.length();
                }
            }
            result.append(text.charAt(i));
        }
        component.setText(result.toString());
        if (haveMnemonic) {
            component.setDisplayedMnemonic(mnemonic);
            component.setDisplayedMnemonicIndex(mnemonicIndex);
        }
    }

    /** @noinspection ALL */
    public JComponent $$$getRootComponent$$$() {
        return centerPanel;
    }
}