2x icons and rid of the ugly border in the completion panel (#3906)

This commit is contained in:
Ben Fry
2015-09-29 23:00:19 -04:00
parent 07b1cbe558
commit 4c9b882a50
4 changed files with 85 additions and 58 deletions

View File

@@ -21,37 +21,27 @@ along with this program; if not, write to the Free Software Foundation, Inc.
package processing.mode.java.pdex;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.Painter;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.InsetsUIResource;
import javax.swing.plaf.basic.BasicScrollBarUI;
import javax.swing.text.BadLocationException;
import processing.app.Base;
import processing.app.Messages;
import processing.app.Mode;
import processing.app.syntax.JEditTextArea;
import processing.app.ui.Toolkit;
import processing.mode.java.JavaEditor;
@@ -117,15 +107,43 @@ public class CompletionPanel {
this.subWord = subWord;
}
loadIcons();
if (classIcon == null) {
File dir = new File(editor.getMode().getFolder(), "theme/completion");
classIcon = Toolkit.getIconX(dir, "class_obj");
methodIcon = Toolkit.getIconX(dir, "methpub_obj");
fieldIcon = Toolkit.getIconX(dir, "field_protected_obj");
localVarIcon = Toolkit.getIconX(dir, "field_default_obj");
}
popupMenu = new JPopupMenu();
popupMenu.removeAll();
popupMenu.setOpaque(false);
popupMenu.setBorder(null);
scrollPane = new JScrollPane();
styleScrollPane();
scrollPane.setViewportView(completionList = createSuggestionList(position, items));
// styleScrollPane();
//scrollPane.setViewportView(completionList = createSuggestionList(position, items));
completionList = new JList<CompletionCandidate>(items) {
{
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setSelectedIndex(0);
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
insertSelection(MOUSE_COMPLETION);
setInvisible();
}
}
});
setCellRenderer(new CustomListRenderer());
setFocusable(false);
}
};
scrollPane.setViewportView(completionList);
// remove an ugly multi-line border around it
scrollPane.setBorder(null);
popupMenu.add(scrollPane, BorderLayout.CENTER);
popupMenu.setPopupSize(calcWidth(), calcHeight(items.getSize())); //TODO: Eradicate this evil
popupMenu.setFocusable(false);
@@ -138,17 +156,7 @@ public class CompletionPanel {
}
private void loadIcons() {
if (classIcon == null) {
Mode mode = editor.getMode();
classIcon = mode.loadIcon("theme/completion/class_obj.png");
methodIcon = mode.loadIcon("theme/completion/methpub_obj.png");
fieldIcon = mode.loadIcon("theme/completion/field_protected_obj.png");
localVarIcon = mode.loadIcon("theme/completion/field_default_obj.png");
}
}
/*
private void styleScrollPane() {
String laf = UIManager.getLookAndFeel().getID();
if (!laf.equals("Nimbus") && !laf.equals("Windows")) return;
@@ -205,6 +213,7 @@ public class CompletionPanel {
return jbutton;
}
}
*/
public boolean isVisible() {
@@ -270,7 +279,6 @@ public class CompletionPanel {
* @param position
* @param items
* @return
*/
private JList<CompletionCandidate> createSuggestionList(final int position,
final DefaultListModel<CompletionCandidate> items) {
@@ -291,6 +299,7 @@ public class CompletionPanel {
list.setFocusable(false);
return list;
}
*/
/*
@@ -333,8 +342,8 @@ public class CompletionPanel {
try {
// If user types 'abc.', subword becomes '.' and null is returned
String currentSubword = fetchCurrentSubword();
int currentSubwordLen = currentSubword == null ? 0 : currentSubword
.length();
int currentSubwordLen =
(currentSubword == null) ? 0 : currentSubword.length();
//logE(currentSubword + " <= subword,len => " + currentSubword.length());
String selectedSuggestion =
completionList.getSelectedValue().getCompletionString();
@@ -346,13 +355,12 @@ public class CompletionPanel {
}
String completionString =
completionList.getSelectedValue().getCompletionString();
completionList.getSelectedValue().getCompletionString();
if (selectedSuggestion.endsWith(" )")) { // the case of single param methods
// selectedSuggestion = ")";
if (completionString.endsWith(" )")) {
completionString = completionString.substring(0, completionString
.length() - 2)
+ ")";
completionString =
completionString.substring(0, completionString.length() - 2) + ")";
}
}
@@ -365,20 +373,19 @@ public class CompletionPanel {
}
}
Messages.loge(subWord + " <= subword, Inserting suggestion=> "
+ selectedSuggestion + " Current sub: " + currentSubword);
Messages.loge(subWord + " <= subword, Inserting suggestion=> " +
selectedSuggestion + " Current sub: " + currentSubword);
if (currentSubword.length() > 0) {
textarea.getDocument().remove(insertionPosition - currentSubwordLen,
currentSubwordLen);
}
textarea.getDocument()
.insertString(insertionPosition - currentSubwordLen,
completionString, null);
textarea.getDocument().insertString(insertionPosition - currentSubwordLen,
completionString, null);
if (selectedSuggestion.endsWith(")") && !selectedSuggestion.endsWith("()")) {
// place the caret between '( and first ','
int x = selectedSuggestion.indexOf(',');
if(x == -1) {
if (x == -1) {
// the case of single param methods, containing no ','
textarea.setCaretPosition(textarea.getCaretPosition() - 1); // just before ')'
} else {
@@ -395,12 +402,12 @@ public class CompletionPanel {
setInvisible();
}
if(mouseClickOnOverloadedMethods) {
if (mouseClickOnOverloadedMethods) {
// See #2755
((JavaTextArea) editor.getTextArea()).fetchPhrase();
}
return true;
} catch (BadLocationException e1) {
e1.printStackTrace();
} catch (Exception e) {