Browse Source

search Popup

Teh-Hai Julian Zheng 8 years ago
parent
commit
e671a46632
3 changed files with 68 additions and 7 deletions
  1. 4 4
      src/ui/controller/Control.java
  2. 16 0
      src/ui/view/GUI.java
  3. 48 3
      src/ui/view/searchPopUp.java

+ 4 - 4
src/ui/controller/Control.java

@@ -65,6 +65,10 @@ public class Control {
 	public CpsObject searchCategoryObject(String category, String object) {
 		return multiPurposeController.searchCatObj(multiPurposeController.searchCat(category), object);
 	}
+	
+	public Category searchCategory(String cat) {
+		return multiPurposeController.searchCat(cat);
+	}
 
 	/* Operations for Categories and Objects */
 	public void addCategory(String cat) {
@@ -83,10 +87,6 @@ public class Control {
 		categoryController.addNewHolonSwitch(cat, obj, "/Images/switch-off.png");
 	}
 
-	public Category searchCategory(String cat) {
-		return multiPurposeController.searchCat(cat);
-	}
-
 	public void deleteCategory(String cat) {
 		categoryController.deleteCategory(cat);
 	}

+ 16 - 0
src/ui/view/GUI.java

@@ -34,6 +34,7 @@ import javax.swing.JButton;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
+import javax.swing.JDialog;
 import javax.swing.JEditorPane;
 import javax.swing.JFileChooser;
 import javax.swing.JFrame;
@@ -195,6 +196,7 @@ public class GUI<E> implements CategoryListener {
 	private final JMenuItem mntmUndo = new JMenuItem("Undo");
 	private final JMenuItem mntmRedo = new JMenuItem("Redo");
 	private final JMenuItem mntmEditEdges = new JMenuItem("Edit Edges");
+	private final JMenuItem mntmFindReplace = new JMenuItem("Find/ Replace");
 
 	/**
 	 * Create the application.
@@ -397,6 +399,20 @@ public class GUI<E> implements CategoryListener {
 		mnNewMenu_1.add(mntmUndo);
 
 		mnNewMenu_1.add(mntmRedo);
+		mntmFindReplace.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				try {
+
+					searchPopUp dialog = new searchPopUp(controller, canvas);
+					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+					dialog.setVisible(true);
+				} catch (Exception e1) {
+					e1.printStackTrace();
+				}
+			}
+		});
+		
+		mnNewMenu_1.add(mntmFindReplace);
 
 		menuBar.add(mnNewMenu_2);
 		mntmEditEdges.addActionListener(new ActionListener() {

+ 48 - 3
src/ui/view/searchPopUp.java

@@ -5,6 +5,9 @@ import java.awt.BorderLayout;
 import javax.swing.JDialog;
 import javax.swing.JPanel;
 import javax.swing.border.EmptyBorder;
+
+import classes.CpsObject;
+
 import javax.swing.JLabel;
 
 import java.awt.Font;
@@ -14,6 +17,7 @@ import javax.swing.JTextField;
 import javax.swing.JRadioButton;
 import javax.swing.JButton;
 
+import ui.controller.Control;
 import ui.controller.MultiPurposeController;
 
 import java.awt.event.ActionListener;
@@ -23,9 +27,10 @@ public class searchPopUp extends JDialog {
 	private final JPanel contentPanel = new JPanel();
 	private JTextField replaceTextField;
 	private JTextField findTextField;
-	private MultiPurposeController multiController;
+	private Control controller;
+	private MyCanvas canvas;
 	
-	searchPopUp(MultiPurposeController multiCont){
+	searchPopUp(Control controller, MyCanvas canvas){
 		super((java.awt.Frame) null, true);
 		setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
 		this.setTitle("Search for Objects");
@@ -35,7 +40,8 @@ public class searchPopUp extends JDialog {
 		getContentPane().add(contentPanel, BorderLayout.CENTER);
 		contentPanel.setLayout(null);
 		
-		multiController = multiCont;
+		this.controller = controller;
+		this.canvas = canvas;
 		
 		JLabel lblFind = new JLabel("Find:");
 		lblFind.setFont(new Font("Tahoma", Font.PLAIN, 13));
@@ -47,11 +53,13 @@ public class searchPopUp extends JDialog {
 		lblReplace.setBounds(10, 41, 56, 14);
 		contentPanel.add(lblReplace);
 		
+		//ReplaceTest
 		replaceTextField = new JTextField();
 		replaceTextField.setBounds(76, 39, 101, 20);
 		contentPanel.add(replaceTextField);
 		replaceTextField.setColumns(10);
 		
+		//FindText
 		findTextField = new JTextField();
 		findTextField.setBounds(76, 11, 101, 20);
 		contentPanel.add(findTextField);
@@ -66,6 +74,7 @@ public class searchPopUp extends JDialog {
 		rdbtnForward.setFont(new Font("Tahoma", Font.PLAIN, 13));
 		rdbtnForward.setBounds(10, 111, 109, 23);
 		contentPanel.add(rdbtnForward);
+		rdbtnForward.setSelected(true);
 		
 		JRadioButton rdbtnBackward = new JRadioButton("Backward");
 		rdbtnBackward.setFont(new Font("Tahoma", Font.PLAIN, 13));
@@ -81,27 +90,63 @@ public class searchPopUp extends JDialog {
 		rdbtnAll.setFont(new Font("Tahoma", Font.PLAIN, 13));
 		rdbtnAll.setBounds(121, 112, 109, 23);
 		contentPanel.add(rdbtnAll);
+		rdbtnAll.setSelected(true);
 		
 		JRadioButton rdbtnSingle = new JRadioButton("Single");
 		rdbtnSingle.setFont(new Font("Tahoma", Font.PLAIN, 13));
 		rdbtnSingle.setBounds(121, 138, 109, 23);
 		contentPanel.add(rdbtnSingle);
 		
+		//FindButton
 		JButton btnFind = new JButton("Find");
+		btnFind.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				CpsObject cps = null;
+				if(rdbtnAll.isSelected()) {
+					
+				}
+				if(rdbtnSingle.isSelected()) {
+					
+					if(rdbtnForward.isSelected()) {
+						
+					}
+					if(rdbtnBackward.isSelected()) {
+						
+					}
+				}
+			}
+		});
 		btnFind.setFont(new Font("Tahoma", Font.PLAIN, 13));
 		btnFind.setBounds(10, 186, 89, 23);
 		contentPanel.add(btnFind);
 		
+		//ReplaceButton
 		JButton btnReplace = new JButton("Replace");
+		btnReplace.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+			}
+		});
 		btnReplace.setFont(new Font("Tahoma", Font.PLAIN, 13));
 		btnReplace.setBounds(110, 187, 89, 23);
 		contentPanel.add(btnReplace);
 		
+		//ReplaceAllButton
 		JButton btnReplaceAll = new JButton("Replace All");
+		btnReplaceAll.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent e) {
+				for (CpsObject cps : controller.getModel().getObjectsOnCanvas()) {
+
+					if(cps.getName().equals(findTextField.getText())) 
+						cps.setName(replaceTextField.getText());
+				}
+				canvas.repaint();
+			}
+		});
 		btnReplaceAll.setFont(new Font("Tahoma", Font.PLAIN, 11));
 		btnReplaceAll.setBounds(110, 218, 89, 23);
 		contentPanel.add(btnReplaceAll);
 		
+		//CloseButton
 		JButton btnClose = new JButton("Close");
 		btnClose.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent arg0) {