|
@@ -0,0 +1,138 @@
|
|
|
+package ui.view;
|
|
|
+
|
|
|
+import java.awt.BorderLayout;
|
|
|
+import java.awt.CardLayout;
|
|
|
+import java.awt.Dimension;
|
|
|
+import java.awt.FlowLayout;
|
|
|
+import java.awt.GridBagLayout;
|
|
|
+import java.awt.GridLayout;
|
|
|
+
|
|
|
+import javax.swing.JButton;
|
|
|
+import javax.swing.JComboBox;
|
|
|
+import javax.swing.JDialog;
|
|
|
+import javax.swing.JLabel;
|
|
|
+import javax.swing.JPanel;
|
|
|
+import javax.swing.JTextField;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+public class NewPopUp extends JDialog{
|
|
|
+ //DefaultConstructor
|
|
|
+
|
|
|
+ String[] optionStrings = { "","Category", "Object", "Battery", "Switch"};
|
|
|
+ public static enum NewItem {
|
|
|
+ None, Category, Object, Battery, Switch;
|
|
|
+ public static NewItem getEnumAtIndex(int desired){
|
|
|
+ if(desired>=0 && desired<=4)
|
|
|
+ return values()[desired];
|
|
|
+ else
|
|
|
+ return None;
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+ NewItem choosenOption = NewItem.None;
|
|
|
+
|
|
|
+
|
|
|
+ //important JPanelItems
|
|
|
+ JComboBox optionList = new JComboBox(optionStrings);
|
|
|
+ JTextField inputName = new JTextField();
|
|
|
+ JButton saveButton = new JButton("Save");
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ NewPopUp dialog = new NewPopUp();
|
|
|
+ dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ NewPopUp(){
|
|
|
+ super((JDialog)null, "Create a..");
|
|
|
+ setVisible(true);
|
|
|
+ JPanel contentPanel = new JPanel();
|
|
|
+
|
|
|
+ contentPanel.setLayout(new BorderLayout());
|
|
|
+ contentPanel.add(makeTopPanel(), BorderLayout.PAGE_START);
|
|
|
+ JPanel cards = new JPanel(new CardLayout());
|
|
|
+ cards.add(makeNothingPanel(), NewItem.None.name());
|
|
|
+ cards.add(makeCategoryPanel(), NewItem.Category.name());
|
|
|
+ cards.add(makeObjectPanel(), NewItem.Object.name());
|
|
|
+ cards.add(makeBatteryPanel(), NewItem.Battery.name());
|
|
|
+ cards.add(makeSwitchPanel(), NewItem.Switch.name());
|
|
|
+ contentPanel.add(cards, BorderLayout.CENTER);
|
|
|
+
|
|
|
+ optionList.addActionListener(actionEvent -> {
|
|
|
+ CardLayout cl = (CardLayout)(cards.getLayout());
|
|
|
+ choosenOption = NewItem.getEnumAtIndex(optionList.getSelectedIndex());
|
|
|
+ cl.show(cards, choosenOption.name());
|
|
|
+ saveButton.setEnabled(choosenOption != NewItem.None);
|
|
|
+ });
|
|
|
+ saveButton.addActionListener(actionEvent -> {
|
|
|
+ System.out.println(choosenOption);
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ contentPanel.add(makeBottemPanel(), BorderLayout.PAGE_END);
|
|
|
+
|
|
|
+ add(contentPanel);
|
|
|
+ setMinimumSize(new Dimension(200,200));
|
|
|
+ }
|
|
|
+
|
|
|
+ private JPanel makeTopPanel() {
|
|
|
+ JPanel topPanel = new JPanel(new GridLayout(1,2));
|
|
|
+ JLabel text = new JLabel("Choose..");
|
|
|
+ topPanel.add(text);
|
|
|
+ topPanel.add(optionList);
|
|
|
+ return topPanel;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JPanel makeBottemPanel() {
|
|
|
+ JPanel bottomPanel = new JPanel();
|
|
|
+ bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
|
+ saveButton.setEnabled(false);
|
|
|
+ bottomPanel.add(saveButton);
|
|
|
+ JButton cancelButton = new JButton("Cancel");
|
|
|
+ bottomPanel.add(cancelButton);
|
|
|
+ return bottomPanel;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JPanel makeObjectPanel() {
|
|
|
+ return new JPanel();
|
|
|
+ }
|
|
|
+
|
|
|
+ private JPanel makeBatteryPanel() {
|
|
|
+ System.out.println("ssds222");
|
|
|
+ return new JPanel();
|
|
|
+ }
|
|
|
+
|
|
|
+ private JPanel makeNothingPanel() {
|
|
|
+ System.out.println("ssds");
|
|
|
+ return new JPanel();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private JPanel makeCategoryPanel()
|
|
|
+ {
|
|
|
+ JPanel newCategory = new JPanel(new FlowLayout());
|
|
|
+ JLabel categoryName = new JLabel("Name:");
|
|
|
+ String initialText = "The name of the new Category";
|
|
|
+ inputName.setText(initialText);
|
|
|
+ inputName.addFocusListener(new java.awt.event.FocusAdapter() {
|
|
|
+ public void focusGained(java.awt.event.FocusEvent evt) {
|
|
|
+ if (inputName.getText().equals(initialText)) {
|
|
|
+ inputName.selectAll();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ inputName.setColumns(20);
|
|
|
+ newCategory.add(categoryName);
|
|
|
+ newCategory.add(inputName);
|
|
|
+ return newCategory;
|
|
|
+ }
|
|
|
+ private JPanel makeSwitchPanel()
|
|
|
+ {
|
|
|
+ JPanel newCategory = new JPanel();
|
|
|
+ JLabel categoryName = new JLabel("Name:Switch");
|
|
|
+ newCategory.add(categoryName);
|
|
|
+ return newCategory;
|
|
|
+ }
|
|
|
+}
|