1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-07 00:04:36 +03:00

Merging r327:r331 of the branches/processing-sync into the trunk. This adds the Processing core, and some new features including printing, copy for discourse, better auto-format, improved keyboard shortcuts, etc.

This commit is contained in:
David A. Mellis
2007-09-25 14:04:01 +00:00
parent 413b439974
commit 616d65d32a
40 changed files with 31946 additions and 779 deletions

View File

@@ -136,9 +136,10 @@ public abstract class InputHandler extends KeyAdapter
{
String name = (String)en.nextElement();
ActionListener _listener = getAction(name);
if(_listener == listener)
if(_listener == listener) {
return name;
}
}
return null;
}
@@ -180,7 +181,6 @@ public abstract class InputHandler extends KeyAdapter
/**
* Grabs the next key typed event and invokes the specified
* action with the key as a the action command.
* @param action The action
*/
public void grabNextKeyStroke(ActionListener listener)
{
@@ -743,19 +743,32 @@ public abstract class InputHandler extends KeyAdapter
{
JEditTextArea textArea = getTextArea(evt);
int caret = textArea.getCaretPosition();
if(caret == textArea.getDocumentLength())
{
if (textArea.getSelectionStart() !=
textArea.getSelectionEnd()) {
// just move to the end of the selection
textArea.select(caret, caret);
} else {
// beep at the user for being annoying
textArea.getToolkit().beep();
return;
}
if(select)
textArea.select(textArea.getMarkPosition(),
caret + 1);
else
} else if (select) {
textArea.select(textArea.getMarkPosition(), caret+1);
} else {
int start = textArea.getSelectionStart();
int end = textArea.getSelectionEnd();
if (start != end) {
textArea.select(end, end);
} else {
textArea.setCaretPosition(caret + 1);
}
}
}
}
public static class next_line implements ActionListener
{
@@ -774,7 +787,13 @@ public abstract class InputHandler extends KeyAdapter
if(line == textArea.getLineCount() - 1)
{
textArea.getToolkit().beep();
//textArea.getToolkit().beep();
int doc = textArea.getDocumentLength();
if (select) {
textArea.select(textArea.getMarkPosition(), doc);
} else {
textArea.setCaretPosition(doc);
}
return;
}
@@ -901,13 +920,19 @@ public abstract class InputHandler extends KeyAdapter
return;
}
if(select)
textArea.select(textArea.getMarkPosition(),
caret - 1);
else
if (select) {
textArea.select(textArea.getMarkPosition(), caret-1);
} else {
int start = textArea.getSelectionStart();
int end = textArea.getSelectionEnd();
if (start != end) {
textArea.select(start, start);
} else {
textArea.setCaretPosition(caret - 1);
}
}
}
}
public static class prev_line implements ActionListener
{
@@ -926,7 +951,14 @@ public abstract class InputHandler extends KeyAdapter
if(line == 0)
{
textArea.getToolkit().beep();
if (select) {
if (textArea.getSelectionStart() != 0) {
textArea.select(textArea.getMarkPosition(), 0);
}
} else {
textArea.setCaretPosition(0);
}
//textArea.getToolkit().beep();
return;
}

View File

@@ -888,22 +888,20 @@ public class JEditTextArea extends JComponent
*/
public void setText(String text)
{
try
{
try {
document.beginCompoundEdit();
document.remove(0,document.getLength());
document.insertString(0,text,null);
}
catch(BadLocationException bl)
{
} catch (BadLocationException bl) {
bl.printStackTrace();
}
finally
{
} finally {
document.endCompoundEdit();
}
}
/**
* Returns the specified substring of the document.
* @param start The start offset
@@ -1502,7 +1500,7 @@ public class JEditTextArea extends JComponent
/**
* Sets if the selection should be rectangular.
* @param overwrite True if the selection should be rectangular,
* @param rectSelect True if the selection should be rectangular,
* false otherwise.
*/
public final void setSelectionRectangular(boolean rectSelect)
@@ -1644,6 +1642,7 @@ public class JEditTextArea extends JComponent
switch(evt.getID()) {
case KeyEvent.KEY_TYPED:
//if ((editorListener != null) && !editorListener.keyTyped(evt)) {
inputHandler.keyTyped(evt);
break;
case KeyEvent.KEY_PRESSED:
@@ -2145,21 +2144,52 @@ public class JEditTextArea extends JComponent
bl.printStackTrace();
}
// Ok, it's not a bracket... select the word
String lineText = getLineText(line);
char ch = lineText.charAt(Math.max(0,offset - 1));
String noWordSep = (String)document.getProperty("noWordSep");
if(noWordSep == null)
noWordSep = "";
// If the user clicked on a non-letter char,
// we select the surrounding non-letters
boolean selectNoLetter = (!Character
.isLetterOrDigit(ch)
&& noWordSep.indexOf(ch) == -1);
// Ok, it's not a bracket... select the word
String lineText = getLineText(line);
int wordStart = 0;
int wordEnd = lineText.length();
char ch = lineText.charAt(Math.max(0,offset - 1));
// special case for whitespace (fry 0122, bug #348)
// this is really nasty.. turns out that double-clicking any non-letter
// or digit char gets lumped together.. sooo, this quickly gets messy,
// because really it needs to check whether the chars are of the same
// type.. so a double space or double - might be grouped together,
// but what about a +=1? do + and - get grouped but not the 1? blech,
// coming back to this later. it's not a difficult fix, just a
// time-consuming one to track down all the proper cases.
/*
if (ch == ' ') {
//System.out.println("yeehaa");
for(int i = offset - 1; i >= 0; i--) {
if (lineText.charAt(i) == ' ') {
wordStart = i;
} else {
break;
}
}
for(int i = offset; i < lineText.length(); i++) {
if (lineText.charAt(i) == ' ') {
wordEnd = i + 1;
} else {
break;
}
}
} else {
*/
// If the user clicked on a non-letter char,
// we select the surrounding non-letters
boolean selectNoLetter = (!Character.isLetterOrDigit(ch)
&& noWordSep.indexOf(ch) == -1);
for(int i = offset - 1; i >= 0; i--) {
ch = lineText.charAt(i);
@@ -2170,18 +2200,15 @@ public class JEditTextArea extends JComponent
}
}
int wordEnd = lineText.length();
for(int i = offset; i < lineText.length(); i++)
{
for(int i = offset; i < lineText.length(); i++) {
ch = lineText.charAt(i);
if(selectNoLetter ^ (!Character
.isLetterOrDigit(ch) &&
noWordSep.indexOf(ch) == -1))
{
if(selectNoLetter ^ (!Character.isLetterOrDigit(ch) &&
noWordSep.indexOf(ch) == -1)) {
wordEnd = i;
break;
}
}
//}
int lineStart = getLineStartOffset(line);
select(lineStart + wordStart,lineStart + wordEnd);

View File

@@ -76,7 +76,7 @@ public class KeywordMap
/**
* Adds a key-value mapping.
* @param keyword The key
* @Param id The value
* @param id The value
*/
public void add(String keyword, byte id)
{

View File

@@ -76,7 +76,7 @@ public class PdeKeywords extends CTokenMarker {
}
}
String pieces[] = Base.split(line, '\t');
String pieces[] = processing.core.PApplet.split(line, '\t');
if (pieces.length >= 2) {
//int tab = line.indexOf('\t');
// any line with no tab is ignored

View File

@@ -2,9 +2,9 @@
/*
PdeTextAreaDefaults - grabs font/color settings for the editor
Part of the Processing project - http://Proce55ing.net
Part of the Processing project - http://processing.org
Except where noted, code is written by Ben Fry
Copyright (c) 2004-06 Ben Fry and Casey Reas
Copyright (c) 2001-03 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
@@ -32,41 +32,65 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
public PdeTextAreaDefaults() {
inputHandler = new DefaultInputHandler();
inputHandler.addDefaultKeyBindings();
//inputHandler.addDefaultKeyBindings(); // 0122
// use option on mac for things that are ctrl on windows/linux
String mod = Base.isMacOS() ? "A" : "C";
inputHandler.addKeyBinding("S+BACK_SPACE", InputHandler.BACKSPACE);
inputHandler.addKeyBinding("S+DELETE", InputHandler.DELETE);
// right now, ctrl-up/down is select up/down, but mod should be
// used instead, because the mac expects it to be option(alt)
inputHandler.addKeyBinding("BACK_SPACE", InputHandler.BACKSPACE);
inputHandler.addKeyBinding("C+BACK_SPACE", InputHandler.BACKSPACE_WORD);
inputHandler.addKeyBinding("DELETE", InputHandler.DELETE);
inputHandler.addKeyBinding("C+DELETE", InputHandler.DELETE_WORD);
inputHandler.addKeyBinding("ENTER", InputHandler.INSERT_BREAK);
inputHandler.addKeyBinding("TAB", InputHandler.INSERT_TAB);
//inputHandler.addKeyBinding("S+BACK_SPACE", InputHandler.BACKSPACE);
// for 0122, shift-backspace is delete
inputHandler.addKeyBinding("S+BACK_SPACE", InputHandler.DELETE);
inputHandler.addKeyBinding("S+DELETE", InputHandler.DELETE);
// the following two were changing for 0122 for better mac/pc compatability
inputHandler.addKeyBinding(mod+"+BACK_SPACE", InputHandler.BACKSPACE_WORD);
inputHandler.addKeyBinding(mod+"+DELETE", InputHandler.DELETE_WORD);
// handled by listener, don't bother here
//inputHandler.addKeyBinding("ENTER", InputHandler.INSERT_BREAK);
//inputHandler.addKeyBinding("TAB", InputHandler.INSERT_TAB);
inputHandler.addKeyBinding("INSERT", InputHandler.OVERWRITE);
inputHandler.addKeyBinding("C+\\", InputHandler.TOGGLE_RECT);
// disabling for 0122, not sure what this does
//inputHandler.addKeyBinding("C+\\", InputHandler.TOGGLE_RECT);
// beginning and ending of the current line
// for 0122, these have been changed for better compatability
// HOME and END now mean the beginning/end of the document
if (Base.isMacOS()) {
inputHandler.addKeyBinding("HOME", InputHandler.DOCUMENT_HOME);
inputHandler.addKeyBinding("END", InputHandler.DOCUMENT_END);
inputHandler.addKeyBinding("S+HOME", InputHandler.SELECT_DOC_HOME);
inputHandler.addKeyBinding("S+END", InputHandler.SELECT_DOC_END);
} else {
// for 0123 added the proper windows defaults
inputHandler.addKeyBinding("HOME", InputHandler.HOME);
inputHandler.addKeyBinding("END", InputHandler.END);
inputHandler.addKeyBinding("S+HOME", InputHandler.SELECT_HOME);
inputHandler.addKeyBinding("S+END", InputHandler.SELECT_END);
inputHandler.addKeyBinding("C+HOME", InputHandler.DOCUMENT_HOME);
inputHandler.addKeyBinding("C+END", InputHandler.DOCUMENT_END);
inputHandler.addKeyBinding("CS+HOME", InputHandler.SELECT_DOC_HOME);
inputHandler.addKeyBinding("CS+END", InputHandler.SELECT_DOC_END);
}
if (Base.isMacOS()) {
inputHandler.addKeyBinding("M+LEFT", InputHandler.HOME);
inputHandler.addKeyBinding("M+RIGHT", InputHandler.END);
inputHandler.addKeyBinding("MS+LEFT", InputHandler.SELECT_HOME); // 0122
inputHandler.addKeyBinding("MS+RIGHT", InputHandler.SELECT_END); // 0122
} else {
inputHandler.addKeyBinding("C+LEFT", InputHandler.HOME); // 0122
inputHandler.addKeyBinding("C+RIGHT", InputHandler.END); // 0122
inputHandler.addKeyBinding("CS+HOME", InputHandler.SELECT_HOME); // 0122
inputHandler.addKeyBinding("CS+END", InputHandler.SELECT_END); // 0122
}
inputHandler.addKeyBinding("S+HOME", InputHandler.SELECT_HOME);
inputHandler.addKeyBinding("S+END", InputHandler.SELECT_END);
inputHandler.addKeyBinding(mod + "+HOME", InputHandler.DOCUMENT_HOME);
inputHandler.addKeyBinding(mod + "+END", InputHandler.DOCUMENT_END);
inputHandler.addKeyBinding(mod + "S+HOME", InputHandler.SELECT_DOC_HOME);
inputHandler.addKeyBinding(mod + "S+END", InputHandler.SELECT_DOC_END);
inputHandler.addKeyBinding("PAGE_UP", InputHandler.PREV_PAGE);
inputHandler.addKeyBinding("PAGE_DOWN", InputHandler.NEXT_PAGE);
inputHandler.addKeyBinding("S+PAGE_UP", InputHandler.SELECT_PREV_PAGE);
@@ -80,6 +104,7 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
inputHandler.addKeyBinding("S+RIGHT", InputHandler.SELECT_NEXT_CHAR);
inputHandler.addKeyBinding(mod + "+RIGHT", InputHandler.NEXT_WORD);
inputHandler.addKeyBinding(mod + "S+RIGHT", InputHandler.SELECT_NEXT_WORD);
inputHandler.addKeyBinding("UP", InputHandler.PREV_LINE);
inputHandler.addKeyBinding(mod + "+UP", InputHandler.PREV_LINE); // p5
inputHandler.addKeyBinding("S+UP", InputHandler.SELECT_PREV_LINE);
@@ -87,6 +112,11 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
inputHandler.addKeyBinding(mod + "+DOWN", InputHandler.NEXT_LINE); // p5
inputHandler.addKeyBinding("S+DOWN", InputHandler.SELECT_NEXT_LINE);
inputHandler.addKeyBinding("MS+UP", InputHandler.SELECT_DOC_HOME);
inputHandler.addKeyBinding("CS+UP", InputHandler.SELECT_DOC_HOME);
inputHandler.addKeyBinding("MS+DOWN", InputHandler.SELECT_DOC_END);
inputHandler.addKeyBinding("CS+DOWN", InputHandler.SELECT_DOC_END);
inputHandler.addKeyBinding(mod + "+ENTER", InputHandler.REPEAT);
document = new SyntaxDocument();

View File

@@ -18,6 +18,7 @@ import javax.swing.text.*;
import javax.swing.JComponent;
import java.awt.event.MouseEvent;
import java.awt.*;
import java.awt.print.*;
/**
* The text area repaint manager. It performs double buffering and paints
@@ -25,8 +26,12 @@ import java.awt.*;
* @author Slava Pestov
* @version $Id$
*/
public class TextAreaPainter extends JComponent implements TabExpander
public class TextAreaPainter extends JComponent
implements TabExpander, Printable
{
/** True if inside printing, will handle disabling the highlight */
boolean printing;
/**
* Creates a new repaint manager. This should be not be called
* directly.
@@ -405,6 +410,32 @@ public class TextAreaPainter extends JComponent implements TabExpander
}
}
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
int lineHeight = fm.getHeight();
int linesPerPage = (int) (pageFormat.getImageableHeight() / lineHeight);
int lineCount = textArea.getLineCount();
int lastPage = lineCount / linesPerPage;
if (pageIndex > lastPage) {
return NO_SUCH_PAGE;
} else {
Graphics2D g2d = (Graphics2D)g;
TokenMarker tokenMarker = textArea.getDocument().getTokenMarker();
int firstLine = pageIndex*linesPerPage;
g2d.translate(Math.max(54, pageFormat.getImageableX()),
pageFormat.getImageableY() - firstLine*lineHeight);
printing = true;
for (int line = firstLine; line < firstLine + linesPerPage; line++) {
paintLine(g2d, tokenMarker, line, 0);
}
printing = false;
return PAGE_EXISTS;
}
}
/**
* Marks a line as needing a repaint.
* @param line The line to invalidate
@@ -600,6 +631,7 @@ public class TextAreaPainter extends JComponent implements TabExpander
protected void paintHighlight(Graphics gfx, int line, int y)
{
if (!printing) {
if (line >= textArea.getSelectionStartLine()
&& line <= textArea.getSelectionEndLine())
paintLineHighlight(gfx,line,y);
@@ -613,6 +645,7 @@ public class TextAreaPainter extends JComponent implements TabExpander
if (line == textArea.getCaretLine())
paintCaret(gfx,line,y);
}
}
protected void paintLineHighlight(Graphics gfx, int line, int y)
{