adding custom scroll bar implementation to go with theme

This commit is contained in:
Ben Fry
2022-01-12 17:30:23 -05:00
parent d506b4c2a0
commit 90cffecdf9
3 changed files with 39 additions and 29 deletions

View File

@@ -128,20 +128,6 @@ public class JEditTextArea extends JComponent
add(RIGHT, vertical = new JScrollBar(Adjustable.VERTICAL));
add(BOTTOM, horizontal = new JScrollBar(Adjustable.HORIZONTAL));
/*
vertical.setBackground(Color.YELLOW);
horizontal.setBackground(Color.YELLOW);
System.out.println(vertical.getUI());
//vertical.setUI(new javax.swing.plaf.basic.BasicScrollBarUI() {
vertical.setUI(new com.apple.laf.AquaScrollBarUI() {
@Override
protected void configureScrollBarColors() {
this.thumbColor = Color.GREEN;
}
});
*/
// Add some event listeners
vertical.addAdjustmentListener(new AdjustHandler());
horizontal.addAdjustmentListener(new AdjustHandler());

View File

@@ -37,6 +37,19 @@ import java.awt.*;
public class PdeScrollBarUI extends BasicScrollBarUI {
private final Dimension none = new Dimension();
private Color backgroundColor;
private Color pressedColor;
private Color rolloverColor;
private Color enabledColor;
public void updateTheme() {
backgroundColor = Theme.getColor("editor.scrollbar.color");
pressedColor = Theme.getColor("editor.scrollbar.thumb.pressed.color");
rolloverColor = Theme.getColor("editor.scrollbar.thumb.rollover.color");
enabledColor = Theme.getColor("editor.scrollbar.thumb.enabled.color");
}
@Override
protected JButton createDecreaseButton(int orientation) {
@@ -62,9 +75,21 @@ public class PdeScrollBarUI extends BasicScrollBarUI {
}
/*
@Override
public void paint(Graphics g, JComponent c) {
// this takes care of the track as well as the corner notch
// where the horizontal and vertical scrollbars meet (edit: nope)
g.setColor(Theme.getColor("editor.scrollbar.color"));
g.fillRect(0, 0, c.getWidth(), c.getHeight());
super.paint(g, c);
}
*/
@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle r) {
g.setColor(Theme.getColor("editor.scrollbar.color"));
g.setColor(backgroundColor);
g.fillRect(0, 0, c.getWidth(), c.getHeight());
}
@@ -79,11 +104,11 @@ public class PdeScrollBarUI extends BasicScrollBarUI {
JScrollBar sb = (JScrollBar) c;
if (sb.isEnabled()) {
if (isDragging) {
color = Theme.getColor("editor.scrollbar.thumb.pressed.color");
color = pressedColor;
} else if (isThumbRollover()) {
color = Theme.getColor("editor.scrollbar.thumb.rollover.color");
color = rolloverColor;
} else {
color = Theme.getColor("editor.scrollbar.thumb.enabled.color");
color = enabledColor;
}
g2.setPaint(color);
int inset = 3;

View File

@@ -20,8 +20,7 @@ along with this program; if not, write to the Free Software Foundation, Inc.
package processing.app.syntax;
import java.awt.Cursor;
import java.awt.Image;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.HashMap;
@@ -55,10 +54,14 @@ public class PdeTextArea extends JEditTextArea {
super(defaults, inputHandler);
this.editor = editor;
vertical.setUI(new PdeScrollBarUI());
horizontal.setUI(new PdeScrollBarUI());
// change cursor to pointer in the gutter area
painter.addMouseMotionListener(gutterCursorMouseAdapter);
add(CENTER, painter);
// already added by call to super(), removing [fry 220112]
//add(CENTER, painter);
// load settings from theme.txt
gutterGradient = Theme.makeGradient("editor", Editor.LEFT_GUTTER, 500);
@@ -76,15 +79,11 @@ public class PdeTextArea extends JEditTextArea {
}
/*
public void setMode(Mode mode) {
((PdeTextAreaPainter) painter).setMode(mode);
}
*/
@Override
public void updateTheme() {
((PdeTextAreaPainter) painter).updateTheme();
painter.updateTheme();
((PdeScrollBarUI) vertical.getUI()).updateTheme();
((PdeScrollBarUI) horizontal.getUI()).updateTheme();
repaint();
}
@@ -154,7 +153,7 @@ public class PdeTextArea extends JEditTextArea {
* take gutter width into account.
* @param line the 0-based line number
* @param x the horizontal pixel position
* @return he character offset (0 is the first character on a line)
* @return the character offset (0 is the first character on a line)
*/
@Override
public int xToOffset(int line, int x) {