package net.teamlixo.eggcrack.ui; import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.Spacer; import com.jgoodies.forms.factories.FormFactory; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; import com.sun.org.apache.xpath.internal.operations.Bool; import net.teamlixo.eggcrack.authentication.configuration.ServiceConfiguration; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class ConfigurationInterface extends JDialog { private JPanel contentPane; private JButton buttonOK; private JPanel formSpace; private FormLayout formLayout; private int y = 1; public ConfigurationInterface() { $$$setupUI$$$(); setContentPane(contentPane); setModal(true); setMinimumSize(new Dimension(400, 400)); getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { onOK(); } }); } private void onOK() { dispose(); } public void addOptions(ServiceConfiguration.Option... options) { for (ServiceConfiguration.Option option : options) addOption(option); } public void addOption(final ServiceConfiguration.Option option) { if (option.getValue().getClass().equals(Boolean.class)) { final JPanel panel3 = new JPanel(); panel3.setLayout(new GridLayoutManager(1, 2, new Insets(10, 10, 10, 10), -1, -1)); panel3.setBackground(new Color(238, 238, 238)); formLayout.appendRow(FormFactory.DEFAULT_ROWSPEC); CellConstraints cc = new CellConstraints(); formSpace.add(panel3, cc.xy(1, y++)); final JLabel label3 = new JLabel(); label3.setText(option.getName()); label3.setMinimumSize(new Dimension(100, -1)); panel3.add(label3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final JCheckBox checkBox1 = new JCheckBox(); checkBox1.setText("Enabled"); checkBox1.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { option.setValue((Boolean) checkBox1.isSelected()); } }); checkBox1.setSelected((Boolean) option.getValue()); panel3.add(checkBox1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); } } private void createUIComponents() { formSpace = new JPanel(); formSpace.setLayout(formLayout = new FormLayout("fill:d:grow", "center:d:noGrow")); } /** * Method generated by IntelliJ IDEA GUI Designer * >>> IMPORTANT!! <<< * DO NOT edit this method OR call it in your code! * * @noinspection ALL */ private void $$$setupUI$$$() { createUIComponents(); contentPane = new JPanel(); contentPane.setLayout(new BorderLayout(0, 0)); final JPanel panel1 = new JPanel(); panel1.setLayout(new BorderLayout(0, 0)); contentPane.add(panel1, BorderLayout.NORTH); final JPanel panel2 = new JPanel(); panel2.setLayout(new GridLayoutManager(2, 2, new Insets(10, 10, 10, 10), -1, -1)); panel2.setBackground(new Color(-1)); panel1.add(panel2, BorderLayout.CENTER); final JLabel label1 = new JLabel(); label1.setFont(new Font(label1.getFont().getName(), Font.BOLD, 18)); label1.setText("Configure Plugin"); panel2.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 Spacer spacer1 = new Spacer(); panel2.add(spacer1, new GridConstraints(0, 1, 2, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); final JLabel label2 = new JLabel(); label2.setText("You can change some plugin-specific settings."); panel2.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)); formSpace.setBackground(new Color(-1118482)); contentPane.add(formSpace, BorderLayout.CENTER); final JPanel panel3 = new JPanel(); panel3.setLayout(new GridLayoutManager(1, 2, new Insets(10, 10, 10, 10), -1, -1)); panel3.setBackground(new Color(-1)); contentPane.add(panel3, BorderLayout.SOUTH); final Spacer spacer2 = new Spacer(); panel3.add(spacer2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); final JPanel panel4 = new JPanel(); panel4.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); panel4.setBackground(new Color(-1)); panel3.add(panel4, new GridConstraints(0, 1, 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, 0, false)); buttonOK = new JButton(); buttonOK.setText("OK"); panel4.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); } /** * @noinspection ALL */ public JComponent $$$getRootComponent$$$() { return contentPane; } }