mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
cleaning up and auto-fixing
This commit is contained in:
@@ -80,9 +80,9 @@ public class JEditTextArea extends JComponent
|
||||
|
||||
private InputMethodSupport inputMethodSupport;
|
||||
|
||||
private TextAreaDefaults defaults;
|
||||
private final TextAreaDefaults defaults;
|
||||
|
||||
private Brackets bracketHelper = new Brackets();
|
||||
private final Brackets bracketHelper = new Brackets();
|
||||
|
||||
private FontMetrics cachedPartialPixelWidthFont;
|
||||
private float partialPixelWidth;
|
||||
@@ -102,11 +102,9 @@ public class JEditTextArea extends JComponent
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK);
|
||||
|
||||
if (!DISABLE_CARET) {
|
||||
caretTimer = new Timer(500, new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (hasFocus()) {
|
||||
blinkCaret();
|
||||
}
|
||||
caretTimer = new Timer(500, e -> {
|
||||
if (hasFocus()) {
|
||||
blinkCaret();
|
||||
}
|
||||
});
|
||||
caretTimer.setInitialDelay(500);
|
||||
@@ -152,13 +150,10 @@ public class JEditTextArea extends JComponent
|
||||
// We don't seem to get the initial focus event?
|
||||
// focusedComponent = this;
|
||||
|
||||
addMouseWheelListener(new MouseWheelListener() {
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||
if (scrollBarsInitialized) {
|
||||
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
|
||||
int scrollAmount = e.getUnitsToScroll();
|
||||
addMouseWheelListener(e -> {
|
||||
if (scrollBarsInitialized) {
|
||||
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
|
||||
int scrollAmount = e.getUnitsToScroll();
|
||||
// System.out.println("rot/amt = " + e.getWheelRotation() + " " + amt);
|
||||
// int max = vertical.getMaximum();
|
||||
// System.out.println("UNIT SCROLL of " + amt + " at value " + vertical.getValue() + " and max " + max);
|
||||
@@ -174,14 +169,13 @@ public class JEditTextArea extends JComponent
|
||||
// }
|
||||
// System.out.println(" " + e);
|
||||
|
||||
// inertia scrolling on OS X will fire several shift-wheel events
|
||||
// that are negative values.. this makes the scrolling area jump.
|
||||
boolean isHorizontal = Platform.isMacOS() && e.isShiftDown();
|
||||
if (isHorizontal) {
|
||||
horizontal.setValue(horizontal.getValue() + scrollAmount);
|
||||
}else{
|
||||
vertical.setValue(vertical.getValue() + scrollAmount);
|
||||
}
|
||||
// inertia scrolling on OS X will fire several shift-wheel events
|
||||
// that are negative values.. this makes the scrolling area jump.
|
||||
boolean isHorizontal = Platform.isMacOS() && e.isShiftDown();
|
||||
if (isHorizontal) {
|
||||
horizontal.setValue(horizontal.getValue() + scrollAmount);
|
||||
}else{
|
||||
vertical.setValue(vertical.getValue() + scrollAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,7 +185,6 @@ public class JEditTextArea extends JComponent
|
||||
|
||||
/**
|
||||
* Override this to provide your own painter for this {@link JEditTextArea}.
|
||||
* @param defaults
|
||||
* @return a newly constructed {@link TextAreaPainter}.
|
||||
*/
|
||||
protected TextAreaPainter createPainter(final TextAreaDefaults defaults) {
|
||||
@@ -922,9 +915,11 @@ public class JEditTextArea extends JComponent
|
||||
int length = getLineLength(line);
|
||||
String str = getText(offset, length);
|
||||
|
||||
for(int i = 0; i < str.length(); i++) {
|
||||
if(!Character.isWhitespace(str.charAt(i))) {
|
||||
return offset + i;
|
||||
if (str != null) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (!Character.isWhitespace(str.charAt(i))) {
|
||||
return offset + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return offset + length;
|
||||
@@ -948,9 +943,11 @@ public class JEditTextArea extends JComponent
|
||||
int length = getLineLength(line);
|
||||
String str = getText(offset - length - 1, length);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if(!Character.isWhitespace(str.charAt(length - i - 1))) {
|
||||
return offset - i;
|
||||
if (str != null) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (!Character.isWhitespace(str.charAt(length - i - 1))) {
|
||||
return offset - i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return offset - length;
|
||||
@@ -1654,11 +1651,7 @@ public class JEditTextArea extends JComponent
|
||||
String selection = getSelectedText();
|
||||
if (selection != null) {
|
||||
int repeatCount = inputHandler.getRepeatCount();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i = 0; i < repeatCount; i++)
|
||||
sb.append(selection);
|
||||
|
||||
clipboard.setContents(new StringSelection(sb.toString()), null);
|
||||
clipboard.setContents(new StringSelection(selection.repeat(Math.max(0, repeatCount))), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1689,10 +1682,8 @@ public class JEditTextArea extends JComponent
|
||||
+ getTextAsHtml(null) + "\n</pre></body></html>");
|
||||
|
||||
Clipboard clipboard = processing.app.ui.Toolkit.getSystemClipboard();
|
||||
clipboard.setContents(formatted, new ClipboardOwner() {
|
||||
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
||||
// I don't care about ownership
|
||||
}
|
||||
clipboard.setContents(formatted, (clipboard1, contents) -> {
|
||||
// I don't care about ownership
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1824,7 +1815,9 @@ public class JEditTextArea extends JComponent
|
||||
} else if (c == '"') {
|
||||
buffer.append(""");
|
||||
} else if (c > 127) {
|
||||
buffer.append("&#" + ((int) c) + ";"); // use unicode entity
|
||||
buffer.append("&#"); // use unicode entity
|
||||
buffer.append((int) c); // use unicode entity
|
||||
buffer.append(';'); // use unicode entity
|
||||
} else {
|
||||
buffer.append(c); // normal character
|
||||
}
|
||||
@@ -1876,11 +1869,7 @@ public class JEditTextArea extends JComponent
|
||||
}
|
||||
|
||||
int repeatCount = inputHandler.getRepeatCount();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < repeatCount; i++) {
|
||||
sb.append(selection);
|
||||
}
|
||||
selection = sb.toString();
|
||||
selection = selection.repeat(Math.max(0, repeatCount));
|
||||
setSelectedText(selection);
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -2189,9 +2178,9 @@ public class JEditTextArea extends JComponent
|
||||
centerHeight);
|
||||
|
||||
// Lay out all status components, in order
|
||||
Enumeration status = leftOfScrollBar.elements();
|
||||
Enumeration<Component> status = leftOfScrollBar.elements();
|
||||
while (status.hasMoreElements()) {
|
||||
Component comp = (Component)status.nextElement();
|
||||
Component comp = status.nextElement();
|
||||
Dimension dim = comp.getPreferredSize();
|
||||
comp.setBounds(ileft,
|
||||
itop + centerHeight,
|
||||
@@ -2210,19 +2199,9 @@ public class JEditTextArea extends JComponent
|
||||
private Component center;
|
||||
private Component right;
|
||||
private Component bottom;
|
||||
private Vector leftOfScrollBar = new Vector();
|
||||
private final Vector<Component> leftOfScrollBar = new Vector<>();
|
||||
}
|
||||
|
||||
// static class CaretBlinker implements ActionListener
|
||||
// {
|
||||
// public void actionPerformed(ActionEvent evt)
|
||||
// {
|
||||
// if(focusedComponent != null
|
||||
// && focusedComponent.hasFocus())
|
||||
// focusedComponent.blinkCaret();
|
||||
// }
|
||||
// }
|
||||
|
||||
class MutableCaretEvent extends CaretEvent
|
||||
{
|
||||
MutableCaretEvent()
|
||||
@@ -2251,14 +2230,11 @@ public class JEditTextArea extends JComponent
|
||||
// If this is not done, mousePressed events accumulate
|
||||
// and the result is that scrolling doesn't stop after
|
||||
// the mouse is released
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
if (evt.getAdjustable() == vertical) {
|
||||
setFirstLine(vertical.getValue());
|
||||
} else {
|
||||
setHorizontalOffset(-horizontal.getValue());
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
if (evt.getAdjustable() == vertical) {
|
||||
setFirstLine(vertical.getValue());
|
||||
} else {
|
||||
setHorizontalOffset(-horizontal.getValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user