package org.jetbrains.sbt.settings;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.ui.JBColor;
import com.intellij.ui.RawCommandLineEditor;
import com.intellij.ui.TitledSeparator;
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.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/**
* @author Pavel Fatin
*/
public class SbtSettingsPane {
private JRadioButton myBundledButton;
private JRadioButton myCustomButton;
private JTextField myMaximumHeapSize;
private TextFieldWithBrowseButton myLauncherPath;
private RawCommandLineEditor myVmParameters;
private JLabel myLauncherPathLabel;
private JPanel myContentPanel;
private JLabel myLauncherNote;
public SbtSettingsPane() {
myBundledButton.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent itemEvent) {
setLauncherPathEnabled(itemEvent.getStateChange() == ItemEvent.DESELECTED);
}
});
myCustomButton.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent itemEvent) {
setLauncherPathEnabled(itemEvent.getStateChange() == ItemEvent.SELECTED);
}
});
myBundledButton.setSelected(true);
myLauncherPath.addBrowseFolderListener("Choose a custom launcher", "Choose sbt-launch.jar", null,
FileChooserDescriptorFactory.createSingleLocalFileDescriptor());
myLauncherNote.setForeground(JBColor.GRAY);
}
public JPanel getContentPanel() {
return myContentPanel;
}
public void setLauncherPathEnabled(boolean enabled) {
myLauncherPathLabel.setEnabled(enabled);
myLauncherPath.setEnabled(enabled);
}
public boolean isCustomLauncher() {
return myCustomButton.isSelected();
}
public void setCustomLauncherEnabled(boolean enabled) {
myBundledButton.setSelected(!enabled);
myCustomButton.setSelected(enabled);
}
public String getLauncherPath() {
return myLauncherPath.getText();
}
public void setLauncherPath(String path) {
myLauncherPath.setText(path);
}
public String getMaximumHeapSize() {
return myMaximumHeapSize.getText();
}
public void setMaximumHeapSize(String value) {
myMaximumHeapSize.setText(value);
}
public String getVmParameters() {
return myVmParameters.getText();
}
public void setMyVmParameters(String value) {
myVmParameters.setText(value);
}
{
// 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$$$() {
myContentPanel = new JPanel();
myContentPanel.setLayout(new GridLayoutManager(8, 1, new Insets(0, 0, 0, 0), -1, -1));
final Spacer spacer1 = new Spacer();
myContentPanel.add(spacer1, new GridConstraints(7, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
final TitledSeparator titledSeparator1 = new TitledSeparator();
titledSeparator1.setText("Launcher (sbt-launch.jar)");
myContentPanel.add(titledSeparator1, new GridConstraints(0, 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, null, null, 0, false));
final TitledSeparator titledSeparator2 = new TitledSeparator();
titledSeparator2.setText("JVM options");
myContentPanel.add(titledSeparator2, new GridConstraints(4, 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, null, null, 0, false));
final JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
myContentPanel.add(panel1, new GridConstraints(5, 0, 2, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 1, false));
final JLabel label1 = new JLabel();
label1.setText("Maximum heap size, MB");
label1.setDisplayedMnemonic('H');
label1.setDisplayedMnemonicIndex(8);
panel1.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label2 = new JLabel();
label2.setText("VM parameters:");
label2.setDisplayedMnemonic('P');
label2.setDisplayedMnemonicIndex(3);
panel1.add(label2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
myMaximumHeapSize = new JTextField();
myMaximumHeapSize.setColumns(5);
panel1.add(myMaximumHeapSize, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
myVmParameters = new RawCommandLineEditor();
panel1.add(myVmParameters, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, new Dimension(250, -1), null, null, 0, false));
final JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
myContentPanel.add(panel2, new GridConstraints(1, 0, 3, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 1, false));
myBundledButton = new JRadioButton();
myBundledButton.setText("Bundled");
myBundledButton.setMnemonic('B');
myBundledButton.setDisplayedMnemonicIndex(0);
panel2.add(myBundledButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
myCustomButton = new JRadioButton();
myCustomButton.setText("Custom");
myCustomButton.setMnemonic('C');
myCustomButton.setDisplayedMnemonicIndex(0);
panel2.add(myCustomButton, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JPanel panel3 = new JPanel();
panel3.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
panel2.add(panel3, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 1, false));
myLauncherPath = new TextFieldWithBrowseButton();
panel3.add(myLauncherPath, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, new Dimension(250, -1), null, null, 0, false));
myLauncherPathLabel = new JLabel();
myLauncherPathLabel.setText("Path:");
panel3.add(myLauncherPathLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
myLauncherNote = new JLabel();
myLauncherNote.setText("SBT 0.13.* launchers are not supported yet");
panel3.add(myLauncherNote, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
label1.setLabelFor(myMaximumHeapSize);
ButtonGroup buttonGroup;
buttonGroup = new ButtonGroup();
buttonGroup.add(myBundledButton);
buttonGroup.add(myCustomButton);
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$() {
return myContentPanel;
}
}