more debugging

This commit is contained in:
Ben Fry
2022-01-29 11:26:26 -05:00
parent 6ec1887eba
commit 4bbf290dca

View File

@@ -2,12 +2,16 @@ package processing.app.syntax;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import java.awt.Dimension;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;
import processing.app.Platform;
import processing.app.Preferences;
import processing.app.ui.Editor;
import processing.app.ui.Theme;
import processing.app.ui.Toolkit;
public class SyntaxDebug extends JFrame {
@@ -19,20 +23,55 @@ public class SyntaxDebug extends JFrame {
Theme.init();
area = new JEditTextArea(new PdeTextAreaDefaults(),
new PdeInputHandler(null));
new PdeInputHandler(null)) {
area.setText("abcdefghijklmnopqrstuvwxyz0123456789");
protected TextAreaPainter createPainter(final TextAreaDefaults defaults) {
return new TextAreaPainter(this, defaults) {
public void paint(Graphics g) {
// System.out.println("painting");
super.paint(g);
showLatest();
}
};
}
};
// System.out.println(area.getPainter()); // not a PdeTextAreaPainter
String what = "Not Lucida Grande abcdefghijklmnopqrstuvwxyz0123456789";
area.setText(what);
area.select(12, 25);
System.out.println("should be selecting " + what.substring(area.getSelectionStart(), area.getSelectionStop()));
add(area);
//setMinimumSize(new Dimension(500, 400));
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Toolkit.registerWindowCloseKeys(getRootPane(), e -> System.exit(0));
setMinimumSize(new Dimension(500, 400));
setVisible(true);
}
void showLatest() {
System.out.println("getting font is " + getFont());
FontMetrics metrics = getFontMetrics(area.getPainter().getFont());
System.out.println(metrics);
String what = area.getText();
System.out.println(what.length());
System.out.println(floatWidth(" "));
System.out.println(floatWidth(what));
}
float floatWidth(String what) {
FontMetrics metrics = getFontMetrics(area.getPainter().getFont());
// data, offset, offset + len, fm.getFontRenderContext());
Rectangle2D bounds = metrics.getStringBounds(what, getGraphics());
return (float) bounds.getWidth();
}
/*
void drawError() {
PdeTextAreaPainter painter = (PdeTextAreaPainter) area.getPainter();