mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
more debugging
This commit is contained in:
@@ -2,12 +2,16 @@ package processing.app.syntax;
|
|||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.WindowConstants;
|
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.Platform;
|
||||||
import processing.app.Preferences;
|
import processing.app.Preferences;
|
||||||
import processing.app.ui.Editor;
|
import processing.app.ui.Editor;
|
||||||
import processing.app.ui.Theme;
|
import processing.app.ui.Theme;
|
||||||
|
import processing.app.ui.Toolkit;
|
||||||
|
|
||||||
|
|
||||||
public class SyntaxDebug extends JFrame {
|
public class SyntaxDebug extends JFrame {
|
||||||
@@ -19,20 +23,55 @@ public class SyntaxDebug extends JFrame {
|
|||||||
Theme.init();
|
Theme.init();
|
||||||
|
|
||||||
area = new JEditTextArea(new PdeTextAreaDefaults(),
|
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);
|
add(area);
|
||||||
//setMinimumSize(new Dimension(500, 400));
|
|
||||||
pack();
|
pack();
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
Toolkit.registerWindowCloseKeys(getRootPane(), e -> System.exit(0));
|
||||||
setMinimumSize(new Dimension(500, 400));
|
setMinimumSize(new Dimension(500, 400));
|
||||||
setVisible(true);
|
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() {
|
void drawError() {
|
||||||
PdeTextAreaPainter painter = (PdeTextAreaPainter) area.getPainter();
|
PdeTextAreaPainter painter = (PdeTextAreaPainter) area.getPainter();
|
||||||
|
|||||||
Reference in New Issue
Block a user