mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 11:21:06 +01:00
implement the editor gradient, excising sketch outline, other visual tweaks
This commit is contained in:
@@ -2324,7 +2324,6 @@ public class JavaEditor extends Editor {
|
||||
*/
|
||||
@Override
|
||||
public void setCode(SketchCode code) {
|
||||
|
||||
//System.out.println("tab switch: " + code.getFileName());
|
||||
// set the new document in the textarea, etc. need to do this first
|
||||
super.setCode(code);
|
||||
|
||||
@@ -60,7 +60,8 @@ public class MarkerColumn extends JPanel {
|
||||
|
||||
private Color errorColor;
|
||||
private Color warningColor;
|
||||
private Color backgroundColor;
|
||||
// private Color backgroundColor;
|
||||
// private Image gutterGradient;
|
||||
|
||||
// Stores error markers displayed PER TAB along the error bar.
|
||||
private List<LineMarker> errorPoints =
|
||||
@@ -73,7 +74,8 @@ public class MarkerColumn extends JPanel {
|
||||
Mode mode = editor.getMode();
|
||||
errorColor = mode.getColor("editor.column.error.color");
|
||||
warningColor = mode.getColor("editor.column.warning.color");
|
||||
backgroundColor = mode.getColor("editor.gutter.bgcolor");
|
||||
// backgroundColor = mode.getColor("editor.gutter.bgcolor");
|
||||
// gutterGradient = mode.makeGradient("editor", Editor.RIGHT_GUTTER, height);
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
@@ -96,8 +98,8 @@ public class MarkerColumn extends JPanel {
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
g.setColor(backgroundColor);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.drawImage(editor.getJavaTextArea().getGutterGradient(),
|
||||
0, 0, getWidth(), getHeight(), this);
|
||||
|
||||
for (LineMarker m : errorPoints) {
|
||||
if (m.getType() == LineMarker.ERROR) {
|
||||
|
||||
@@ -2403,6 +2403,7 @@ public class ASTGenerator {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
protected SketchOutline sketchOutline;
|
||||
|
||||
public void showSketchOutline() {
|
||||
@@ -2411,6 +2412,7 @@ public class ASTGenerator {
|
||||
sketchOutline = new SketchOutline(codeTree, errorCheckerService);
|
||||
sketchOutline.show();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public void showTabOutline() {
|
||||
|
||||
@@ -68,7 +68,8 @@ public class JavaTextArea extends JEditTextArea {
|
||||
|
||||
// [px] space added to the left and right of gutter chars
|
||||
protected int gutterPadding; // = 3;
|
||||
protected Color gutterBgColor; // = new Color(252, 252, 252); // gutter background color
|
||||
protected Image gutterGradient;
|
||||
// protected Color gutterBgColor; // = new Color(252, 252, 252); // gutter background color
|
||||
protected Color gutterLineColor; // = new Color(233, 233, 233); // color of vertical separation line
|
||||
|
||||
/// the text marker for highlighting breakpoints in the gutter
|
||||
@@ -126,12 +127,10 @@ public class JavaTextArea extends JEditTextArea {
|
||||
|
||||
// load settings from theme.txt
|
||||
Mode mode = editor.getMode();
|
||||
gutterBgColor = mode.getColor("editor.gutter.bgcolor"); //, gutterBgColor);
|
||||
gutterLineColor = mode.getColor("editor.gutter.linecolor"); //, gutterLineColor);
|
||||
gutterGradient = mode.makeGradient("editor", Editor.LEFT_GUTTER, 500);
|
||||
//gutterBgColor = mode.getColor("editor.gutter.bgcolor");
|
||||
gutterLineColor = mode.getColor("editor.gutter.linecolor");
|
||||
gutterPadding = mode.getInteger("editor.gutter.padding");
|
||||
// breakpointMarker = mode.getString("editor.gutter.breakpoint.marker"); //, breakpointMarker);
|
||||
// breakpointMarker = "\u2666";
|
||||
// currentLineMarker = mode.getString("editor.gutter.currentline.marker"); //, currentLineMarker);
|
||||
|
||||
// TweakMode code
|
||||
prevCompListeners = painter.getComponentListeners();
|
||||
@@ -459,12 +458,12 @@ public class JavaTextArea extends JEditTextArea {
|
||||
|
||||
if (suggestionRequested) return null;
|
||||
|
||||
// don't show completions when the outline is visible
|
||||
boolean showSuggestions = astGenerator.sketchOutline == null ||
|
||||
!astGenerator.sketchOutline.isVisible();
|
||||
// // don't show completions when the outline is visible
|
||||
// boolean showSuggestions =
|
||||
// astGenerator.sketchOutline == null || !astGenerator.sketchOutline.isVisible();
|
||||
|
||||
if (showSuggestions && phrase != null &&
|
||||
candidates != null && !candidates.isEmpty()) {
|
||||
// if (showSuggestions && phrase != null &&
|
||||
if (phrase != null && candidates != null && !candidates.isEmpty()) {
|
||||
Collections.sort(candidates);
|
||||
defListModel = ASTGenerator.filterPredictions(candidates);
|
||||
Messages.log("Got: " + candidates.size() + " candidates, " + defListModel.size() + " filtered");
|
||||
@@ -669,6 +668,11 @@ public class JavaTextArea extends JEditTextArea {
|
||||
}
|
||||
|
||||
|
||||
public Image getGutterGradient() {
|
||||
return gutterGradient;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the gutter text of a specific line.
|
||||
*
|
||||
|
||||
@@ -102,9 +102,9 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
long thisTime = event.getWhen();
|
||||
if (thisTime - lastTime > 100) {
|
||||
if (event.getX() < Editor.LEFT_GUTTER) {
|
||||
int offset = getTextArea().xyToOffset(event.getX(), event.getY());
|
||||
int offset = getJavaTextArea().xyToOffset(event.getX(), event.getY());
|
||||
if (offset >= 0) {
|
||||
int lineIndex = getTextArea().getLineOfOffset(offset);
|
||||
int lineIndex = getJavaTextArea().getLineOfOffset(offset);
|
||||
javaEditor.toggleBreakpoint(lineIndex);
|
||||
}
|
||||
}
|
||||
@@ -135,8 +135,8 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
int startOffset = Math.max(errorStart, lineStart) - lineStart;
|
||||
int stopOffset = Math.min(errorEnd, lineEnd) - lineStart;
|
||||
|
||||
if (x >= getTextArea().offsetToX(line, startOffset) &&
|
||||
x <= getTextArea().offsetToX(line, stopOffset)) {
|
||||
if (x >= getJavaTextArea().offsetToX(line, startOffset) &&
|
||||
x <= getJavaTextArea().offsetToX(line, stopOffset)) {
|
||||
setToolTipText(problem.getMessage());
|
||||
evt.consume();
|
||||
}
|
||||
@@ -256,18 +256,20 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
* @param x horizontal position
|
||||
*/
|
||||
protected void paintLeftGutter(Graphics gfx, int line, int x) {
|
||||
// gfx.setColor(Color.ORANGE);
|
||||
int y = textArea.lineToY(line) + fm.getLeading() + fm.getMaxDescent();
|
||||
if (line == textArea.getSelectionStopLine()) {
|
||||
gfx.setColor(gutterLineHighlightColor);
|
||||
gfx.fillRect(0, y, Editor.LEFT_GUTTER, fm.getHeight());
|
||||
} else {
|
||||
gfx.setColor(getTextArea().gutterBgColor);
|
||||
//gfx.setColor(getJavaTextArea().gutterBgColor);
|
||||
gfx.setClip(0, y, Editor.LEFT_GUTTER, fm.getHeight());
|
||||
gfx.drawImage(getJavaTextArea().getGutterGradient(), 0, 0, getWidth(), getHeight(), this);
|
||||
gfx.setClip(null); // reset
|
||||
}
|
||||
gfx.fillRect(0, y, Editor.LEFT_GUTTER, fm.getHeight());
|
||||
|
||||
String text = null;
|
||||
if (getJavaEditor().isDebuggerEnabled()) {
|
||||
text = getTextArea().getGutterText(line);
|
||||
text = getJavaTextArea().getGutterText(line);
|
||||
}
|
||||
|
||||
gfx.setColor(gutterTextColor);
|
||||
@@ -342,19 +344,19 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
* @param line
|
||||
* 0-based line number
|
||||
* @param x
|
||||
*/
|
||||
protected void paintLineBgColor(Graphics gfx, int line, int x) {
|
||||
private void paintLineBgColor(Graphics gfx, int line, int x) {
|
||||
int y = textArea.lineToY(line);
|
||||
y += fm.getLeading() + fm.getMaxDescent();
|
||||
int height = fm.getHeight();
|
||||
|
||||
Color col = getTextArea().getLineBgColor(line);
|
||||
Color col = getJavaTextArea().getLineBgColor(line);
|
||||
if (col != null) {
|
||||
// paint line background
|
||||
gfx.setColor(col);
|
||||
gfx.fillRect(0, y, getWidth(), height);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
@@ -888,7 +890,7 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
}
|
||||
|
||||
|
||||
private JavaTextArea getTextArea() {
|
||||
private JavaTextArea getJavaTextArea() {
|
||||
return (JavaTextArea) textArea;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class SketchOutline {
|
||||
|
||||
ImageIcon classIcon, fieldIcon, methodIcon;
|
||||
|
||||
|
||||
|
||||
public SketchOutline(DefaultMutableTreeNode codeTree, ErrorCheckerService ecs) {
|
||||
errorCheckerService = ecs;
|
||||
editor = ecs.getEditor();
|
||||
@@ -81,7 +81,7 @@ public class SketchOutline {
|
||||
soNode = (DefaultMutableTreeNode) soNode.getChildAt(0);
|
||||
tempNode = soNode;
|
||||
soTree = new JTree(soNode);
|
||||
|
||||
|
||||
Mode mode = editor.getMode();
|
||||
classIcon = mode.loadIcon("theme/icon_class_obj.png");
|
||||
methodIcon = mode.loadIcon("theme/icon_methpub_obj.png");
|
||||
@@ -89,15 +89,15 @@ public class SketchOutline {
|
||||
|
||||
createGUI();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void createGUI(){
|
||||
frmOutlineView = new JFrame();
|
||||
frmOutlineView.setAlwaysOnTop(true);
|
||||
frmOutlineView.setUndecorated(true);
|
||||
Point tp = errorCheckerService.getEditor().getTextArea().getLocationOnScreen();
|
||||
|
||||
int minWidth = (int) (editor.getMinimumSize().width * 0.7f);
|
||||
int minWidth = (int) (editor.getMinimumSize().width * 0.7f);
|
||||
int maxWidth = (int) (editor.getMinimumSize().width * 0.9f);
|
||||
frmOutlineView.setLayout(new BoxLayout(frmOutlineView.getContentPane(),
|
||||
BoxLayout.Y_AXIS));
|
||||
@@ -109,7 +109,7 @@ public class SketchOutline {
|
||||
panelTop.add(searchField);
|
||||
|
||||
jsp = new JScrollPane();
|
||||
|
||||
|
||||
soTree.getSelectionModel()
|
||||
.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
soTree.setRootVisible(false);
|
||||
@@ -118,13 +118,13 @@ public class SketchOutline {
|
||||
soTree.expandRow(i);
|
||||
}
|
||||
soTree.setSelectionRow(0);
|
||||
|
||||
|
||||
jsp.setViewportView(soTree);
|
||||
jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
jsp.setMinimumSize(new Dimension(minWidth, editor.getTextArea().getHeight() - 10));
|
||||
jsp.setMaximumSize(new Dimension(maxWidth, editor.getTextArea().getHeight() - 10));
|
||||
|
||||
jsp.setMaximumSize(new Dimension(maxWidth, editor.getTextArea().getHeight() - 10));
|
||||
|
||||
panelBottom.add(jsp);
|
||||
frmOutlineView.add(panelTop);
|
||||
frmOutlineView.add(panelBottom);
|
||||
@@ -132,13 +132,13 @@ public class SketchOutline {
|
||||
frmOutlineView.pack();
|
||||
frmOutlineView.setBounds(tp.x + errorCheckerService.getEditor().getTextArea().getWidth() - minWidth, tp.y, minWidth,
|
||||
Math.min(editor.getTextArea().getHeight(), frmOutlineView.getHeight()));
|
||||
frmOutlineView.setMinimumSize(new Dimension(minWidth, Math.min(errorCheckerService.getEditor().getTextArea().getHeight(), frmOutlineView.getHeight())));
|
||||
frmOutlineView.setMinimumSize(new Dimension(minWidth, Math.min(errorCheckerService.getEditor().getTextArea().getHeight(), frmOutlineView.getHeight())));
|
||||
frmOutlineView.setLocation(tp.x + errorCheckerService.getEditor().getTextArea().getWidth()/2 - frmOutlineView.getWidth()/2,
|
||||
frmOutlineView.getY() + (editor.getTextArea().getHeight() - frmOutlineView.getHeight()) / 2);
|
||||
addListeners();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void addListeners() {
|
||||
|
||||
searchField.addKeyListener(new KeyAdapter() {
|
||||
@@ -147,10 +147,10 @@ public class SketchOutline {
|
||||
return;
|
||||
|
||||
internalSelection = true;
|
||||
|
||||
|
||||
if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
close();
|
||||
|
||||
|
||||
} else if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
if (soTree.getLastSelectedPathComponent() != null) {
|
||||
DefaultMutableTreeNode tnode = (DefaultMutableTreeNode) soTree
|
||||
@@ -162,13 +162,13 @@ public class SketchOutline {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else if (evt.getKeyCode() == KeyEvent.VK_UP) {
|
||||
if (soTree.getLastSelectedPathComponent() == null) {
|
||||
soTree.setSelectionRow(0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int x = soTree.getLeadSelectionRow() - 1;
|
||||
int step = jsp.getVerticalScrollBar().getMaximum()
|
||||
/ soTree.getRowCount();
|
||||
@@ -180,7 +180,7 @@ public class SketchOutline {
|
||||
.getValue() - step));
|
||||
}
|
||||
soTree.setSelectionRow(x);
|
||||
|
||||
|
||||
} else if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
if (soTree.getLastSelectedPathComponent() == null) {
|
||||
soTree.setSelectionRow(0);
|
||||
@@ -201,7 +201,7 @@ public class SketchOutline {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
searchField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
@@ -215,7 +215,7 @@ public class SketchOutline {
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
updateSelection();
|
||||
}
|
||||
|
||||
|
||||
private void updateSelection(){
|
||||
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
|
||||
protected Object doInBackground() throws Exception {
|
||||
@@ -225,7 +225,7 @@ public class SketchOutline {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void done() {
|
||||
protected void done() {
|
||||
soTree.setModel(new DefaultTreeModel(tempNode));
|
||||
((DefaultTreeModel) soTree.getModel()).reload();
|
||||
for (int i = 0; i < soTree.getRowCount(); i++) {
|
||||
@@ -260,15 +260,15 @@ public class SketchOutline {
|
||||
scrollToNode();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
soTree.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent me) {
|
||||
scrollToNode();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void scrollToNode() {
|
||||
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
|
||||
|
||||
@@ -294,7 +294,7 @@ public class SketchOutline {
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected boolean filterTree(String prefix, DefaultMutableTreeNode tree,
|
||||
DefaultMutableTreeNode mainTree) {
|
||||
if (mainTree.isLeaf()) {
|
||||
@@ -315,7 +315,7 @@ public class SketchOutline {
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void generateSketchOutlineTree(DefaultMutableTreeNode node,
|
||||
@@ -342,7 +342,7 @@ public class SketchOutline {
|
||||
FieldDeclaration fd = (FieldDeclaration) awnode.getNode();
|
||||
for (VariableDeclarationFragment vdf : (List<VariableDeclarationFragment>) fd.fragments()) {
|
||||
final String text = new CompletionCandidate(vdf).toString();
|
||||
DefaultMutableTreeNode newNode =
|
||||
DefaultMutableTreeNode newNode =
|
||||
new DefaultMutableTreeNode(new ASTNodeWrapper(vdf.getName(), text));
|
||||
node.add(newNode);
|
||||
}
|
||||
@@ -358,27 +358,27 @@ public class SketchOutline {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void show() {
|
||||
frmOutlineView.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void close(){
|
||||
frmOutlineView.setVisible(false);
|
||||
frmOutlineView.dispose();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isVisible(){
|
||||
return frmOutlineView.isVisible();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected class CustomCellRenderer extends DefaultTreeCellRenderer {
|
||||
|
||||
public Component getTreeCellRendererComponent(JTree tree, Object value,
|
||||
boolean sel, boolean expanded,
|
||||
boolean sel, boolean expanded,
|
||||
boolean leaf, int row,
|
||||
boolean hasFocus) {
|
||||
super.getTreeCellRendererComponent(tree, value, sel, expanded,
|
||||
@@ -391,9 +391,9 @@ public class SketchOutline {
|
||||
|
||||
public Icon getTreeIcon(Object o) {
|
||||
if (((DefaultMutableTreeNode) o).getUserObject() instanceof ASTNodeWrapper) {
|
||||
ASTNodeWrapper awrap = (ASTNodeWrapper)
|
||||
ASTNodeWrapper awrap = (ASTNodeWrapper)
|
||||
((DefaultMutableTreeNode) o).getUserObject();
|
||||
|
||||
|
||||
int type = awrap.getNode().getParent().getNodeType();
|
||||
if (type == ASTNode.METHOD_DECLARATION) {
|
||||
return methodIcon;
|
||||
|
||||
Reference in New Issue
Block a user