remove redundant use of "if (DEBUG)"

This commit is contained in:
Ben Fry
2016-12-21 23:56:40 -05:00
parent fb1b0c4d02
commit 71a6c643fa
4 changed files with 29 additions and 38 deletions

View File

@@ -74,7 +74,7 @@ public class Util {
*/
static public StringDict readSettings(File inputFile) {
if (!inputFile.exists()) {
if (Base.DEBUG) System.err.println(inputFile + " does not exist.");
Messages.loge(inputFile + " does not exist inside readSettings()");
return null;
}
String lines[] = PApplet.loadStrings(inputFile);

View File

@@ -15,12 +15,12 @@ import java.text.CharacterIterator;
import javax.swing.text.BadLocationException;
import processing.app.Base;
import processing.app.Messages;
import processing.app.Preferences;
import processing.app.syntax.JEditTextArea;
import processing.app.syntax.TextAreaPainter;
/**
* This class Manage texts from input method
* by begin-process-end steps.
@@ -156,16 +156,16 @@ public class CompositionTextManager {
e.printStackTrace();
}
}
private TextLayout getTextLayout(AttributedCharacterIterator text, int committedCount) {
boolean antialias = Preferences.getBoolean("editor.smooth");
TextAreaPainter painter = textArea.getPainter();
// create attributed string with font info.
AttributedString composed = new AttributedString(text, committedCount, text.getEndIndex());
Font font = painter.getFontMetrics().getFont();
composed.addAttribute(TextAttribute.FONT, font);
// set hint of antialiasing to render target.
Graphics2D g2d = (Graphics2D)painter.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
@@ -173,9 +173,7 @@ public class CompositionTextManager {
RenderingHints.VALUE_TEXT_ANTIALIAS_ON :
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
FontRenderContext frc = g2d.getFontRenderContext();
if (Base.DEBUG) {
Messages.log("debug: FontRenderContext is Antialiased = " + frc.getAntiAliasingHint());
}
Messages.log("debug: FontRenderContext is Antialiased = " + frc.getAntiAliasingHint());
return new TextLayout(composed.getIterator(), frc);
}

View File

@@ -8,19 +8,18 @@ import java.awt.Rectangle;
import java.awt.font.TextHitInfo;
import java.awt.font.TextLayout;
import processing.app.Base;
import processing.app.Messages;
import processing.app.syntax.JEditTextArea;
/**
* Paint texts from input method. Text via input method are transmitted by
* AttributedCaharacterIterator. This class helps the PDE's TextAreaPainter
* Paint texts from input method. Text via input method are transmitted by
* AttributedCaharacterIterator. This class helps the PDE's TextAreaPainter
* to handle AttributedCaharacterIterator.
*
*
* For practical purposes, paint to textarea is done by TextLayout class.
* Because TextLayout class is easy to draw composing texts. (For example,
* Because TextLayout class is easy to draw composing texts. (For example,
* draw underline composing texts, focus when select from candidates text.)
*
*
* @author Takashi Maekawa (takachin@generative.info)
*/
public class CompositionTextPainter {
@@ -39,7 +38,7 @@ public class CompositionTextPainter {
composedTextLayout = null;
}
/**
* Check the painter has TextLayout.
* If a user input via InputMethod, this result will return true.
@@ -47,19 +46,19 @@ public class CompositionTextPainter {
public boolean hasComposedTextLayout() {
return (composedTextLayout != null);
}
/**
* Set TextLayout to the painter.
* TextLayout will be created and set by CompositionTextManager.
*
*
* @see CompositionTextManager
*/
public void setComposedTextLayout(TextLayout composedTextLayout, int composedStartCaretPosition) {
this.composedTextLayout = composedTextLayout;
this.composedBeginCaretPosition = composedStartCaretPosition;
}
/**
* Invalidate this TextLayout to set null.
@@ -70,23 +69,23 @@ public class CompositionTextPainter {
this.composedBeginCaretPosition = composedEndCaretPosition;
//this.composedBeginCaretPosition = textArea.getCaretPosition();
}
/**
* Draw text via input method with composed text information.
* This method can draw texts with some underlines to illustrate converting characters.
*
* This method can draw texts with some underlines to illustrate converting characters.
*
* This method is workaround for TextAreaPainter.
* Because, TextAreaPainter can't treat AttributedCharacterIterator directly.
* AttributedCharacterIterator has very important information when composing text.
* It has a map where are converted characters and committed characters.
* Ideally, changing TextAreaPainter method can treat AttributedCharacterIterator is better. But it's very tough!!
* So I choose to write some code as a workaround.
*
*
* This draw method is proceeded with the following steps.
* 1. Original TextAreaPainter draws characters.
* 1. Original TextAreaPainter draws characters.
* 2. CompositionTextPainter.draw method paints composed text. It was actually drawn by TextLayout.
*
*
* @param gfx set TextAreaPainter's Graphics object.
* @param fillBackGroundColor set textarea's background.
*/
@@ -102,7 +101,7 @@ public class CompositionTextPainter {
Point composedLoc = getCaretLocation();
//refillComposedArea(fillBackGroundColor, composedLoc.x, composedLoc.y);
composedTextLayout.draw((Graphics2D) gfx, composedLoc.x, composedLoc.y);
// draw caret.
if (this.caret != null) {
int caretLocation = Math.round(composedTextLayout.getCaretInfo(caret)[0]);
@@ -110,10 +109,6 @@ public class CompositionTextPainter {
composedLoc.y - (int)composedTextLayout.getAscent(),
1,
(int)composedTextLayout.getAscent() + (int)composedTextLayout.getDescent());
// blink caret.
if (Base.DEBUG) {
Messages.log(rect.toString());
}
Color c = gfx.getColor(); // save
if (caretColorFlag) {
caretColorFlag = false;
@@ -129,8 +124,8 @@ public class CompositionTextPainter {
}
// /**
// * Fill color to erase characters drawn by original TextAreaPainter.
// *
// * Fill color to erase characters drawn by original TextAreaPainter.
// *
// * @param fillColor fill color to erase characters drawn by original TextAreaPainter method.
// * @param x x-coordinate where to fill.
// * @param y y-coordinate where to fill.
@@ -144,7 +139,7 @@ public class CompositionTextPainter {
// int paintWidth = (int) composedTextLayout.getBounds().getWidth();
// gfx.fillRect(x, newY, paintWidth, paintHeight);
// }
private Point getCaretLocation() {
int line = textArea.getCaretLine();

View File

@@ -195,9 +195,7 @@ public class InputMethodSupport implements InputMethodRequests, InputMethodListe
}
CompositionTextPainter compositionPainter = textArea.getPainter().getCompositionTextpainter();
if (Base.DEBUG) {
Messages.log(" textArea.getCaretPosition() + committed_count: " + (textArea.getCaretPosition() + committedCount));
}
Messages.log("textArea.getCaretPosition() + committed_count: " + (textArea.getCaretPosition() + committedCount));
compositionPainter.setComposedTextLayout(getTextLayout(text, committedCount), textArea.getCaretPosition() + committedCount);
compositionPainter.setCaret(event.getCaret());