From 5f54d4fe72ab7fac34d3a41c8be0d9b919311a31 Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Fri, 31 Jan 2014 14:06:46 +0530 Subject: [PATCH] javadoc update for CompletionPanel --- .../mode/experimental/CompletionPanel.java | 77 ++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/pdex/src/processing/mode/experimental/CompletionPanel.java b/pdex/src/processing/mode/experimental/CompletionPanel.java index 7973b7610..ab32e4b7d 100644 --- a/pdex/src/processing/mode/experimental/CompletionPanel.java +++ b/pdex/src/processing/mode/experimental/CompletionPanel.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2012-14 Manindra Moharana + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. + */ + package processing.mode.experimental; import static processing.mode.experimental.ExperimentalMode.log; import static processing.mode.experimental.ExperimentalMode.logE; @@ -23,21 +41,51 @@ import javax.swing.text.BadLocationException; import processing.app.syntax.JEditTextArea; +/** + * Manages the actual suggestion popup that gets displayed + * @author Manindra Moharana + * + */ public class CompletionPanel { + + /** + * The completion list generated by ASTGenerator + */ private JList completionList; + /** + * The popup menu in which the suggestion list is shown + */ private JPopupMenu popupMenu; + /** + * Partial word which triggered the code completion and which needs to be completed + */ private String subWord; + /** + * Postion where the completion has to be inserted + */ private int insertionPosition; private TextArea textarea; + /** + * Scroll pane in which the completion list is displayed + */ private JScrollPane scrollPane; protected DebugEditor editor; + /** + * Triggers the completion popup + * @param textarea + * @param position - insertion position(caret pos) + * @param subWord - Partial word which triggered the code completion and which needs to be completed + * @param items - completion candidates + * @param location - Point location where popup list is to be displayed + * @param dedit + */ public CompletionPanel(final JEditTextArea textarea, int position, String subWord, DefaultListModel items, final Point location, DebugEditor dedit) { this.textarea = (TextArea) textarea; @@ -72,7 +120,7 @@ public class CompletionPanel { popupMenu.setVisible(v); } - protected int setHeight(int itemCount){ + private int setHeight(int itemCount){ if(scrollPane.getHorizontalScrollBar().isVisible()) itemCount++; FontMetrics fm = textarea.getFontMetrics(textarea.getFont()); float h = (fm.getHeight() + fm.getDescent()*0.5f) * (itemCount + 1); @@ -94,6 +142,12 @@ public class CompletionPanel { return Math.min(280,(int)min); // popup menu height }*/ + /** + * Created the popup list to be displayed + * @param position + * @param items + * @return + */ private JList createSuggestionList(final int position, final DefaultListModel items) { @@ -142,6 +196,10 @@ public class CompletionPanel { return true; } + /** + * Inserts the CompletionCandidate chosen from the suggestion list + * @return + */ public boolean insertSelection() { if (completionList.getSelectedValue() != null) { try { @@ -174,12 +232,18 @@ public class CompletionPanel { return false; } + /** + * Hide the suggestion list + */ public void hide() { popupMenu.setVisible(false); //log("Suggestion hidden" + System.nanoTime()); //textarea.errorCheckerService.getASTGenerator().jdocWindowVisible(false); } + /** + * When up arrow key is pressed, moves the highlighted selection up in the list + */ public void moveUp() { if (completionList.getSelectedIndex() == 0) { scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getMaximum()); @@ -200,6 +264,9 @@ public class CompletionPanel { } + /** + * When down arrow key is pressed, moves the highlighted selection down in the list + */ public void moveDown() { if (completionList.getSelectedIndex() == completionList.getModel().getSize() - 1) { scrollPane.getVerticalScrollBar().setValue(0); @@ -231,7 +298,13 @@ public class CompletionPanel { // }); } - protected class CustomListRenderer extends + + /** + * Custom cell renderer to display icons along with the completion candidates + * @author Manindra Moharana + * + */ + private class CustomListRenderer extends javax.swing.DefaultListCellRenderer { //protected final ImageIcon classIcon, fieldIcon, methodIcon;