javadoc update for CompletionPanel

This commit is contained in:
Manindra Moharana
2014-01-31 14:06:46 +05:30
parent 83a542bf36
commit 5f54d4fe72

View File

@@ -1,3 +1,21 @@
/*
* Copyright (C) 2012-14 Manindra Moharana <me@mkmoharana.com>
*
* 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 <me@mkmoharana.com>
*
*/
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 <me@mkmoharana.com>
*
*/
private class CustomListRenderer extends
javax.swing.DefaultListCellRenderer {
//protected final ImageIcon classIcon, fieldIcon, methodIcon;