/** @description Method to do a search and populate the results panel with the search result */ public void search() { /* Search for the specified user */ Collection<StorageEntry> results = null; try { results = cUserProfile .getNode() .get(Profile.generateKey(keywordTF.getText()), Profile.type, null, true, 5) .get(); } catch (InterruptedException | ExecutionException ie) { System.err.println("Searcher Interrupted"); } /* Now we display the result onto the result panel */ StorageEntry profileSE = null; long recency = 0; for (StorageEntry e : results) { /* Select the most recent result */ if (e.getSubmissionTime() > recency) { recency = e.getSubmissionTime(); profileSE = e; } } /* Add this friend's profile to the frame */ resultsPanel.add(new UserDisplay(profileSE)); /* Refresh the frame */ frame.repaint(); frame.revalidate(); }
/** * @description Here we create the search frame GUI Our Frame GUI will basically contain a search * box and a panel area to display results */ private void createGUI() { /* Setting up the main panel */ mainPanel = new JPanel(new BorderLayout()); /* Adding the search keyword TF to the main panel */ keywordTF = new JTextField(); keywordTF.addKeyListener( new KeyListener() { /* Adding a key listener to the search keyword text field*/ @Override public void keyTyped(KeyEvent e) {} @Override public void keyPressed(KeyEvent e) {} @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { /* Call the search method */ frame.search(); } } }); mainPanel.add(keywordTF, BorderLayout.NORTH); /* Adding the Results Panel to the main panel */ resultsPanel = new JPanel(); mainPanel.add(resultsPanel, BorderLayout.CENTER); /* Add the Main panel to the frame */ scrollPane = new JScrollPane(mainPanel); frame.getContentPane().add(scrollPane); }
/** @description Call the necessary methods to display */ public void showGUI() { frame.pack(); frame.setMinimumSize(new Dimension(500, 500)); frame.setVisible(true); }