further work on cc

This commit is contained in:
Manindra Moharana
2013-04-20 19:06:28 +05:30
parent cdbcee6b68
commit e519f1711a
4 changed files with 227 additions and 194 deletions

View File

@@ -9,9 +9,7 @@ import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JList;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import processing.app.syntax.JEditTextArea;
@@ -25,11 +23,11 @@ public class CompletionPanel {
private final int insertionPosition;
private JEditTextArea textarea;
private TextArea textarea;
public CompletionPanel(JEditTextArea textarea, int position, String subWord,
String[] items, Point location) {
this.textarea = textarea;
CompletionCandidate[] items, Point location) {
this.textarea = (TextArea) textarea;
this.insertionPosition = position;
if (subWord.indexOf('.') != -1)
this.subWord = subWord.substring(subWord.lastIndexOf('.') + 1);
@@ -43,6 +41,8 @@ public class CompletionPanel {
BorderLayout.CENTER);
popupMenu.show(textarea, location.x, textarea.getBaseline(0, 0)
+ location.y);
this.textarea.errorCheckerService.astGenerator.updateJavaDoc((CompletionCandidate) list
.getSelectedValue());
}
public void hide() {
@@ -53,27 +53,7 @@ public class CompletionPanel {
return popupMenu.isVisible();
}
// private JList createSuggestionList(final int position, final String subWord) {
// Object[] data = new Object[10];
// for (int i = 0; i < data.length; i++) {
// data[i] = subWord + i * 10;
// }
// JList list = new JList(data);
// list.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));
// list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// list.setSelectedIndex(0);
// list.addMouseListener(new MouseAdapter() {
// @Override
// public void mouseClicked(MouseEvent e) {
// if (e.getClickCount() == 2) {
// insertSelection();
// }
// }
// });
// return list;
// }
public JList createSuggestionList(final int position, final String[] items) {
public JList createSuggestionList(final int position, final CompletionCandidate[] items) {
JList list = new JList(items);
list.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));
@@ -84,6 +64,7 @@ public class CompletionPanel {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
insertSelection();
hideSuggestion();
}
}
});
@@ -93,7 +74,7 @@ public class CompletionPanel {
public boolean insertSelection() {
if (list.getSelectedValue() != null) {
try {
final String selectedSuggestion = ((String) list.getSelectedValue())
final String selectedSuggestion = ((CompletionCandidate) list.getSelectedValue()).toString()
.substring(subWord.length());
textarea.getDocument().insertString(insertionPosition,
selectedSuggestion, null);
@@ -119,6 +100,9 @@ public class CompletionPanel {
int index = Math.max(list.getSelectedIndex() - 1, 0);
selectIndex(index);
}
textarea.errorCheckerService.astGenerator.updateJavaDoc((CompletionCandidate) list
.getSelectedValue());
}
public void moveDown() {
@@ -129,6 +113,8 @@ public class CompletionPanel {
.getSize() - 1);
selectIndex(index);
}
textarea.errorCheckerService.astGenerator.updateJavaDoc((CompletionCandidate) list
.getSelectedValue());
}
private void selectIndex(int index) {