Java tutorial
// Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See License.txt in the project root. package com.microsoft.alm.plugin.idea.git.ui.simplecheckout; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.microsoft.alm.plugin.idea.common.resources.TfPluginBundle; import com.microsoft.alm.plugin.idea.common.ui.common.forms.BasicForm; import org.apache.commons.lang.StringUtils; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import java.awt.Dimension; import java.awt.Insets; import java.awt.event.ActionListener; /** * This form is for a simple checkout where the repo url is given */ public class SimpleCheckoutForm implements BasicForm { private JTextField directoryName; private JPanel contentPanel; private TextFieldWithBrowseButton parentDirectory; private JTextField repoUrl; private boolean initialized = false; public SimpleCheckoutForm() { $$$setupUI$$$(); } public JPanel getContentPanel() { ensureInitialized(); return contentPanel; } /** * If there is no directory name or parent dir then put the focus on that text box otherwise it will default to the clone button */ @Override public JComponent getPreferredFocusedComponent() { if (StringUtils.isEmpty(getParentDirectory())) { return parentDirectory; } else if (StringUtils.isEmpty(getDirectoryName())) { return directoryName; } else { return null; } } @Override public void addActionListener(ActionListener listener) { } private void ensureInitialized() { if (!initialized) { // Setup folder browser parentDirectory.getInsets().right = 0; parentDirectory.addBrowseFolderListener( TfPluginBundle.message(TfPluginBundle.KEY_CHECKOUT_DIALOG_PARENT_FOLDER_DIALOG_TITLE), null, null, new FileChooserDescriptor(false, true, false, false, false, false)); initialized = true; } } public void setParentDirectory(final String path) { parentDirectory.setText(path); } public String getParentDirectory() { return StringUtils.trim(parentDirectory.getText()); } private JComponent getParentDirectoryComponent() { return parentDirectory.getTextField(); } public void setDirectoryName(final String name) { directoryName.setText(name); } public String getDirectoryName() { return StringUtils.trim(directoryName.getText()); } private JComponent getDirectoryNameComponent() { return directoryName; } public void setRepoUrl(final String url) { repoUrl.setText(url); } public JComponent getComponent(final String name) { if (SimpleCheckoutModel.PROP_PARENT_DIR.equals(name)) { return getParentDirectoryComponent(); } if (SimpleCheckoutModel.PROP_DIRECTORY_NAME.equals(name)) { return getDirectoryNameComponent(); } return null; } /** * Method generated by IntelliJ IDEA GUI Designer * >>> IMPORTANT!! <<< * DO NOT edit this method OR call it in your code! * * @noinspection ALL */ private void $$$setupUI$$$() { contentPanel = new JPanel(); contentPanel.setLayout(new GridLayoutManager(6, 1, new Insets(0, 0, 0, 0), -1, -1)); contentPanel.setMinimumSize(new Dimension(500, 180)); final JLabel label1 = new JLabel(); label1.setText("Directory Name:"); contentPanel.add(label1, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); directoryName = new JTextField(); contentPanel.add(directoryName, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); final JLabel label2 = new JLabel(); label2.setText("Repository Url:"); contentPanel.add(label2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); repoUrl = new JTextField(); repoUrl.setEditable(false); contentPanel.add(repoUrl, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); parentDirectory = new TextFieldWithBrowseButton(); contentPanel.add(parentDirectory, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(150, -1), null, 0, false)); final JLabel label3 = new JLabel(); label3.setText("Parent Directory:"); contentPanel.add(label3, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); } /** * @noinspection ALL */ public JComponent $$$getRootComponent$$$() { return contentPanel; } }