mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
moving packages around
This commit is contained in:
@@ -1588,12 +1588,12 @@ public class JEditTextArea extends JComponent
|
||||
* This is slightly faster than using a KeyListener
|
||||
* because some Swing overhead is avoided.
|
||||
*/
|
||||
public PdeEditorListener editorListener;
|
||||
public EditorListener editorListener;
|
||||
|
||||
/**
|
||||
* The component that tracks the current line number.
|
||||
*/
|
||||
public PdeEditorLineStatus editorLineStatus;
|
||||
public EditorLineStatus editorLineStatus;
|
||||
|
||||
|
||||
public void processKeyEvent(KeyEvent evt) {
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
PdeEditorListener - filter key events for tab expansion/indent/etc
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Except where noted, code is written by Ben Fry and
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
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.app.syntax;
|
||||
|
||||
import processing.app.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
|
||||
public class PdeEditorListener {
|
||||
PdeEditor editor;
|
||||
JEditTextArea textarea;
|
||||
|
||||
boolean externalEditor;
|
||||
boolean expandTabs;
|
||||
String tabString;
|
||||
boolean autoIndent;
|
||||
|
||||
int selectionStart, selectionEnd;
|
||||
int position;
|
||||
|
||||
|
||||
public PdeEditorListener(PdeEditor editor, JEditTextArea textarea) {
|
||||
this.editor = editor;
|
||||
this.textarea = textarea;
|
||||
|
||||
// let him know that i'm leechin'
|
||||
textarea.editorListener = this;
|
||||
|
||||
applyPreferences();
|
||||
}
|
||||
|
||||
|
||||
public void applyPreferences() {
|
||||
expandTabs = PdePreferences.getBoolean("editor.tabs.expand");
|
||||
int tabSize = PdePreferences.getInteger("editor.tabs.size");
|
||||
tabString = PdeEditor.EMPTY.substring(0, tabSize);
|
||||
autoIndent = PdePreferences.getBoolean("editor.indent");
|
||||
externalEditor = PdePreferences.getBoolean("editor.external");
|
||||
}
|
||||
|
||||
|
||||
//public void setExternalEditor(boolean externalEditor) {
|
||||
//this.externalEditor = externalEditor;
|
||||
//}
|
||||
|
||||
|
||||
// called by JEditTextArea inside processKeyEvent
|
||||
public boolean keyPressed(KeyEvent event) {
|
||||
// don't do things if the textarea isn't editable
|
||||
if (externalEditor) return false;
|
||||
|
||||
//deselect(); // this is for paren balancing
|
||||
char c = event.getKeyChar();
|
||||
int code = event.getKeyCode();
|
||||
|
||||
//System.out.println(c + " " + code + " " + event);
|
||||
//System.out.println();
|
||||
|
||||
if ((event.getModifiers() & KeyEvent.META_MASK) != 0) {
|
||||
//event.consume(); // does nothing
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO i don't like these accessors. clean em up later.
|
||||
if (!editor.sketch.current.modified) {
|
||||
if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_TAB) ||
|
||||
(code == KeyEvent.VK_ENTER) || ((c >= 32) && (c < 128))) {
|
||||
editor.sketch.setModified();
|
||||
}
|
||||
}
|
||||
|
||||
switch ((int) c) {
|
||||
|
||||
case 9: // expand tabs
|
||||
if (expandTabs) {
|
||||
//tc.replaceSelection(tabString);
|
||||
textarea.setSelectedText(tabString);
|
||||
event.consume();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case 10: // auto-indent
|
||||
case 13:
|
||||
if (autoIndent) {
|
||||
char contents[] = textarea.getText().toCharArray();
|
||||
|
||||
// this is the position of the caret, if the textarea
|
||||
// only used a single kind of line ending
|
||||
int origIndex = textarea.getCaretPosition() - 1;
|
||||
|
||||
// walk through the array to the current caret position,
|
||||
// and count how many weirdo windows line endings there are,
|
||||
// which would be throwing off the caret position number
|
||||
int offset = 0;
|
||||
int realIndex = origIndex;
|
||||
for (int i = 0; i < realIndex-1; i++) {
|
||||
if ((contents[i] == 13) && (contents[i+1] == 10)) {
|
||||
offset++;
|
||||
realIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// back up until \r \r\n or \n.. @#($* cross platform
|
||||
|
||||
//System.out.println(origIndex + " offset = " + offset);
|
||||
origIndex += offset; // ARGH!#(* WINDOWS#@($*
|
||||
|
||||
int index = origIndex;
|
||||
int spaceCount = 0;
|
||||
boolean finished = false;
|
||||
while ((index != -1) && (!finished)) {
|
||||
if ((contents[index] == 10) ||
|
||||
(contents[index] == 13)) {
|
||||
finished = true;
|
||||
index++; // maybe ?
|
||||
} else {
|
||||
index--; // new
|
||||
}
|
||||
}
|
||||
while ((index < contents.length) && (index >= 0) &&
|
||||
(contents[index++] == ' ')) {
|
||||
spaceCount++;
|
||||
}
|
||||
|
||||
// seems that \r is being inserted anyway
|
||||
// so no need to insert the platform's line separator
|
||||
String insertion = "\n" + PdeEditor.EMPTY.substring(0, spaceCount);
|
||||
//tc.replaceSelection(insertion);
|
||||
textarea.setSelectedText(insertion);
|
||||
// microsoft vm version:
|
||||
//tc.setCaretPosition(oldCarrot + insertion.length() - 1);
|
||||
// sun vm version:
|
||||
// tc.setCaretPosition(oldCarrot + insertion.length());
|
||||
event.consume();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class PdeKeywords extends CTokenMarker {
|
||||
keywordColoring = new KeywordMap(false);
|
||||
keywordToReference = new Hashtable();
|
||||
|
||||
InputStream input = PdeBase.getStream("keywords.txt");
|
||||
InputStream input = Base.getStream("keywords.txt");
|
||||
InputStreamReader isr = new InputStreamReader(input);
|
||||
BufferedReader reader = new BufferedReader(isr);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class PdeKeywords extends CTokenMarker {
|
||||
reader.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
PdeBase.showError("Problem loading keywords",
|
||||
Base.showError("Problem loading keywords",
|
||||
"Could not load keywords.txt,\n" +
|
||||
"please re-install Processing.", e);
|
||||
System.exit(1);
|
||||
|
||||
@@ -47,60 +47,60 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
|
||||
styles = new SyntaxStyle[Token.ID_COUNT];
|
||||
|
||||
// comments
|
||||
styles[Token.COMMENT1] = PdePreferences.getStyle("comment1");
|
||||
styles[Token.COMMENT2] = PdePreferences.getStyle("comment2");
|
||||
styles[Token.COMMENT1] = Preferences.getStyle("comment1");
|
||||
styles[Token.COMMENT2] = Preferences.getStyle("comment2");
|
||||
|
||||
// abstract, final, private
|
||||
styles[Token.KEYWORD1] = PdePreferences.getStyle("keyword1");
|
||||
styles[Token.KEYWORD1] = Preferences.getStyle("keyword1");
|
||||
|
||||
// beginShape, point, line
|
||||
styles[Token.KEYWORD2] = PdePreferences.getStyle("keyword2");
|
||||
styles[Token.KEYWORD2] = Preferences.getStyle("keyword2");
|
||||
|
||||
// byte, char, short, color
|
||||
styles[Token.KEYWORD3] = PdePreferences.getStyle("keyword3");
|
||||
styles[Token.KEYWORD3] = Preferences.getStyle("keyword3");
|
||||
|
||||
// constants: null, true, this, RGB, TWO_PI
|
||||
styles[Token.LITERAL1] = PdePreferences.getStyle("literal1");
|
||||
styles[Token.LITERAL1] = Preferences.getStyle("literal1");
|
||||
|
||||
// p5 built in variables: mouseX, width, pixels
|
||||
styles[Token.LITERAL2] = PdePreferences.getStyle("literal2");
|
||||
styles[Token.LITERAL2] = Preferences.getStyle("literal2");
|
||||
|
||||
// ??
|
||||
styles[Token.LABEL] = PdePreferences.getStyle("label");
|
||||
styles[Token.LABEL] = Preferences.getStyle("label");
|
||||
|
||||
// + - = /
|
||||
styles[Token.OPERATOR] = PdePreferences.getStyle("operator");
|
||||
styles[Token.OPERATOR] = Preferences.getStyle("operator");
|
||||
|
||||
// area that's not in use by the text (replaced with tildes)
|
||||
styles[Token.INVALID] = PdePreferences.getStyle("invalid");
|
||||
styles[Token.INVALID] = Preferences.getStyle("invalid");
|
||||
|
||||
|
||||
// moved from TextAreaPainter
|
||||
|
||||
font = PdePreferences.getFont("editor.font");
|
||||
font = Preferences.getFont("editor.font");
|
||||
|
||||
fgcolor = PdePreferences.getColor("editor.fgcolor");
|
||||
bgcolor = PdePreferences.getColor("editor.bgcolor");
|
||||
fgcolor = Preferences.getColor("editor.fgcolor");
|
||||
bgcolor = Preferences.getColor("editor.bgcolor");
|
||||
|
||||
caretVisible = true;
|
||||
caretBlinks = PdePreferences.getBoolean("editor.caret.blink");
|
||||
caretColor = PdePreferences.getColor("editor.caret.color");
|
||||
caretBlinks = Preferences.getBoolean("editor.caret.blink");
|
||||
caretColor = Preferences.getColor("editor.caret.color");
|
||||
|
||||
selectionColor = PdePreferences.getColor("editor.selection.color");
|
||||
selectionColor = Preferences.getColor("editor.selection.color");
|
||||
|
||||
lineHighlight =
|
||||
PdePreferences.getBoolean("editor.linehighlight");
|
||||
Preferences.getBoolean("editor.linehighlight");
|
||||
lineHighlightColor =
|
||||
PdePreferences.getColor("editor.linehighlight.color");
|
||||
Preferences.getColor("editor.linehighlight.color");
|
||||
|
||||
bracketHighlight =
|
||||
PdePreferences.getBoolean("editor.brackethighlight");
|
||||
Preferences.getBoolean("editor.brackethighlight");
|
||||
bracketHighlightColor =
|
||||
PdePreferences.getColor("editor.brackethighlight.color");
|
||||
Preferences.getColor("editor.brackethighlight.color");
|
||||
|
||||
eolMarkers = PdePreferences.getBoolean("editor.eolmarkers");
|
||||
eolMarkerColor = PdePreferences.getColor("editor.eolmarkers.color");
|
||||
eolMarkers = Preferences.getBoolean("editor.eolmarkers");
|
||||
eolMarkerColor = Preferences.getColor("editor.eolmarkers.color");
|
||||
|
||||
paintInvalid = PdePreferences.getBoolean("editor.invalid");
|
||||
paintInvalid = Preferences.getBoolean("editor.invalid");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ public class TextAreaPainter extends JComponent implements TabExpander
|
||||
*/
|
||||
public void paint(Graphics gfx)
|
||||
{
|
||||
if (PdeBase.isMacOS()) {
|
||||
if (Base.isMacOS()) {
|
||||
Graphics2D g2 = (Graphics2D) gfx;
|
||||
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
|
||||
Reference in New Issue
Block a user