mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
these don't make sense in Mode
This commit is contained in:
@@ -29,8 +29,6 @@ import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.app.ui.Editor;
|
||||
import processing.app.ui.EditorException;
|
||||
@@ -52,18 +50,6 @@ public class JavaMode extends Mode {
|
||||
|
||||
initLogger();
|
||||
loadPreferences();
|
||||
loadIcons();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Needed by code completion panel. See {@link processing.mode.java.pdex.CompletionPanel}
|
||||
*/
|
||||
private void loadIcons(){
|
||||
classIcon = loadIcon("theme/icon_class_obj.png");
|
||||
methodIcon = loadIcon("theme/icon_methpub_obj.png");
|
||||
fieldIcon = loadIcon("theme/icon_field_protected_obj.png");
|
||||
localVarIcon = loadIcon("theme/icon_field_default_obj.png");
|
||||
}
|
||||
|
||||
|
||||
@@ -339,11 +325,6 @@ public class JavaMode extends Mode {
|
||||
|
||||
static volatile public boolean enableTweak = false;
|
||||
|
||||
static public ImageIcon classIcon;
|
||||
static public ImageIcon fieldIcon;
|
||||
static public ImageIcon methodIcon;
|
||||
static public ImageIcon localVarIcon;
|
||||
|
||||
|
||||
public void loadPreferences() {
|
||||
Base.log("Load PDEX prefs");
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
@@ -49,17 +50,12 @@ import javax.swing.plaf.basic.BasicScrollBarUI;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Mode;
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
import processing.mode.java.JavaEditor;
|
||||
import processing.mode.java.JavaMode;
|
||||
|
||||
|
||||
/**
|
||||
* Manages the actual suggestion popup that gets displayed
|
||||
* @author Manindra Moharana <me@mkmoharana.com>
|
||||
*/
|
||||
public class CompletionPanel {
|
||||
|
||||
/**
|
||||
* The completion list generated by ASTGenerator
|
||||
*/
|
||||
@@ -93,6 +89,11 @@ public class CompletionPanel {
|
||||
|
||||
private boolean horizontalScrollBarVisible = false;
|
||||
|
||||
static public ImageIcon classIcon;
|
||||
static public ImageIcon fieldIcon;
|
||||
static public ImageIcon methodIcon;
|
||||
static public ImageIcon localVarIcon;
|
||||
|
||||
|
||||
/**
|
||||
* Triggers the completion popup
|
||||
@@ -103,19 +104,23 @@ public class CompletionPanel {
|
||||
* @param location - Point location where popup list is to be displayed
|
||||
* @param dedit
|
||||
*/
|
||||
public CompletionPanel(final JEditTextArea textarea, int position, String subWord,
|
||||
DefaultListModel<CompletionCandidate> items, final Point location, JavaEditor editor) {
|
||||
public CompletionPanel(final JEditTextArea textarea,
|
||||
int position, String subWord,
|
||||
DefaultListModel<CompletionCandidate> items,
|
||||
final Point location, JavaEditor editor) {
|
||||
this.textarea = (JavaTextArea) textarea;
|
||||
this.editor = editor;
|
||||
this.insertionPosition = position;
|
||||
if (subWord.indexOf('.') != -1)
|
||||
if (subWord.indexOf('.') != -1) {
|
||||
this.subWord = subWord.substring(subWord.lastIndexOf('.') + 1);
|
||||
else
|
||||
} else {
|
||||
this.subWord = subWord;
|
||||
}
|
||||
popupMenu = new JPopupMenu();
|
||||
popupMenu.removeAll();
|
||||
popupMenu.setOpaque(false);
|
||||
popupMenu.setBorder(null);
|
||||
|
||||
scrollPane = new JScrollPane();
|
||||
styleScrollPane();
|
||||
scrollPane.setViewportView(completionList = createSuggestionList(position, items));
|
||||
@@ -125,6 +130,18 @@ public class CompletionPanel {
|
||||
textarea.requestFocusInWindow();
|
||||
popupMenu.show(textarea, location.x, textarea.getBaseline(0, 0) + location.y);
|
||||
//log("Suggestion shown: " + System.currentTimeMillis());
|
||||
loadIcons();
|
||||
}
|
||||
|
||||
|
||||
private void loadIcons() {
|
||||
if (classIcon == null) {
|
||||
Mode mode = editor.getMode();
|
||||
classIcon = mode.loadIcon("theme/completion/icon_class_obj.png");
|
||||
methodIcon = mode.loadIcon("theme/completion/icon_methpub_obj.png");
|
||||
fieldIcon = mode.loadIcon("theme/completion/icon_field_protected_obj.png");
|
||||
localVarIcon = mode.loadIcon("theme/completion/icon_field_default_obj.png");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +220,7 @@ public class CompletionPanel {
|
||||
int maxHeight = 250;
|
||||
FontMetrics fm = textarea.getGraphics().getFontMetrics();
|
||||
float itemHeight = Math.max((fm.getHeight() + (fm.getDescent()) * 0.5f),
|
||||
JavaMode.classIcon.getIconHeight() * 1.2f);
|
||||
classIcon.getIconHeight() * 1.2f);
|
||||
|
||||
if (horizontalScrollBarVisible) {
|
||||
itemCount++;
|
||||
@@ -237,7 +254,7 @@ public class CompletionPanel {
|
||||
}
|
||||
int w = Math.min((int) min, maxWidth);
|
||||
horizontalScrollBarVisible = (w == maxWidth);
|
||||
w += JavaMode.classIcon.getIconWidth(); // add icon width too!
|
||||
w += classIcon.getIconWidth(); // add icon width too!
|
||||
w += fm.stringWidth(" "); // a bit of offset
|
||||
//log("popup width " + w);
|
||||
return w; // popup menu width
|
||||
@@ -535,19 +552,19 @@ public class CompletionPanel {
|
||||
CompletionCandidate cc = (CompletionCandidate) value;
|
||||
switch (cc.getType()) {
|
||||
case CompletionCandidate.LOCAL_VAR:
|
||||
label.setIcon(JavaMode.localVarIcon);
|
||||
label.setIcon(localVarIcon);
|
||||
break;
|
||||
case CompletionCandidate.LOCAL_FIELD:
|
||||
case CompletionCandidate.PREDEF_FIELD:
|
||||
label.setIcon(JavaMode.fieldIcon);
|
||||
label.setIcon(fieldIcon);
|
||||
break;
|
||||
case CompletionCandidate.LOCAL_METHOD:
|
||||
case CompletionCandidate.PREDEF_METHOD:
|
||||
label.setIcon(JavaMode.methodIcon);
|
||||
label.setIcon(methodIcon);
|
||||
break;
|
||||
case CompletionCandidate.LOCAL_CLASS:
|
||||
case CompletionCandidate.PREDEF_CLASS:
|
||||
label.setIcon(JavaMode.classIcon);
|
||||
label.setIcon(classIcon);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user