Browse Source

Neues PopUpWindow Work in Progress

tolatesry 7 years ago
parent
commit
e977db0777
3 changed files with 179 additions and 3 deletions
  1. 39 3
      src/ui/view/GUI.java
  2. 2 0
      src/ui/view/MyCanvas.java
  3. 138 0
      src/ui/view/NewPopUp.java

+ 39 - 3
src/ui/view/GUI.java

@@ -89,6 +89,8 @@ public class GUI implements CategoryListener {
 	/** checked if supplyBars should be shown */
 	private final JCheckBox showSupplyBarsCheckBox = new JCheckBox(
 			"Show supply bars.");
+	private final JCheckBox showTooltipsCheckBox = new JCheckBox(
+			"Show tooltips.");
 	/** menu for the different fairness Models */
 	private final JMenu mnFairnessModel = new JMenu("Fairness Model");
 	/** press to supply minimum demand first */
@@ -109,6 +111,9 @@ public class GUI implements CategoryListener {
 			JSplitPane.VERTICAL_SPLIT);
 	// the tabbed canvas containing the different sub-net tabs of the grid (Main
 	// Grid + Nodes of Nodes)
+	
+	private final JLabel lblHint = new JLabel("To connect two Objects use SHIFT + Left Mouse Button");
+	private final JPanel myPanel = new JPanel(new BorderLayout());
 	private final JTabbedPane tabbedPaneInnerOriginal = new JTabbedPane(
 			JTabbedPane.TOP);
 	// the main canvas where we can see the grid currently displayed
@@ -900,6 +905,13 @@ public class GUI implements CategoryListener {
 					((UpperNodeCanvas) canvasOrUpperNodeCanvas).repaint();
 				}
 			});
+		
+		mnNewMenuView.add(showTooltipsCheckBox);
+		showTooltipsCheckBox.setSelected(true);
+		showTooltipsCheckBox.addActionListener(arg0 -> {
+			showHint(showTooltipsCheckBox.isSelected());
+			});
+		
 
 		// Split View
 		mntmSplitView
@@ -1957,18 +1969,22 @@ public class GUI implements CategoryListener {
 		//toolBar.add(comboBox);
 		//comboBox.setModel(new DefaultComboBoxModel(comboBoxCat));
 		// Add Buttonnew DefaultComboBoxModel(comboBoxCat)
+		//TODO: Add functionalyty
 		btnAddPopUp.add(mItemNew);
 		mItemNew.addActionListener(actionEvent -> {
 			System.out.println("New..");
+			showHint(true);
 		});
 		btnAddPopUp.addSeparator();
 		btnAddPopUp.add(mItemCategory);
 		mItemCategory.addActionListener(actionEvent -> {
 			System.out.println("Category");
+			lblHint.setText("Category");
 		});
 		btnAddPopUp.add(mItemObject);
 		mItemObject.addActionListener(actionEvent -> {
 			System.out.println("Object");
+			showHint(false);
 		});
 		btnAddPopUp.add(mItemSwitch);
 		mItemSwitch.addActionListener(actionEvent -> {
@@ -1980,6 +1996,7 @@ public class GUI implements CategoryListener {
 		});
 		btnAdd.addActionListener(actionEvent -> {
 			btnAddPopUp.show(btnAdd, 0, 0);
+			
 			//btnAddPopUp.
 			//JOptionPane.showMessageDialog(contentPane, "Work in Progress" , "Message" , JOptionPane.WARNING_MESSAGE);
 			/*
@@ -2397,7 +2414,15 @@ public class GUI implements CategoryListener {
 		splitPane.setLeftComponent(scrollPane1);
 		splitPaneCanvasConsole.setLeftComponent(tabbedPaneOriginal);
 		tabbedPaneOriginal.addTab("View", tabbedPaneInnerOriginal);
-		tabbedPaneInnerOriginal.addTab("Main Grid", canvasSP);
+		
+		
+		myPanel.add(canvasSP, BorderLayout.CENTER);
+		myPanel.add(lblHint, BorderLayout.PAGE_END);
+		lblHint.setBackground(new Color(53, 178, 76, 100));
+		lblHint.setOpaque(true);
+		
+		
+		tabbedPaneInnerOriginal.addTab("Main Grid", myPanel);
 		tabbedPaneOriginal.addTab("Statistics", statScrollPane);
 		tabbedPaneOriginal.addTab("Holon", holonCanvas);
 		FlexiblePane flexPane = new FlexiblePane(controller);
@@ -2958,8 +2983,12 @@ public class GUI implements CategoryListener {
 		}
 
 		if (upperLevelSelectedComponent instanceof JTabbedPane) {
-			return (JScrollPane) ((JTabbedPane) upperLevelSelectedComponent)
-					.getSelectedComponent();
+			Component nextLevel = ((JTabbedPane) upperLevelSelectedComponent).getSelectedComponent();
+			if(nextLevel instanceof JPanel)
+				return (JScrollPane) ((JPanel)nextLevel).getComponent(0);
+			else
+				return (JScrollPane) nextLevel;
+			
 		} else if (upperLevelSelectedComponent instanceof JScrollPane) {
 			return (JScrollPane) upperLevelSelectedComponent;
 		} else {
@@ -3043,4 +3072,11 @@ public class GUI implements CategoryListener {
 			e1.printStackTrace();
 		}
 	}
+	/**
+	 * Function to set the visibility for Hints
+	 * @param enable true = show false = hide
+	 */
+	public void showHint(boolean enable){
+		lblHint.setVisible(enable);
+	}
 }

+ 2 - 0
src/ui/view/MyCanvas.java

@@ -380,7 +380,9 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 		String maxCap = null;
 		super.paintComponent(g);
 		// Rendering
+		
 		g2 = (Graphics2D) g;
+		
 		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
 				RenderingHints.VALUE_ANTIALIAS_ON);
 		g2.setRenderingHints(rh);

+ 138 - 0
src/ui/view/NewPopUp.java

@@ -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;
+	}
+}