MCPcopy Index your code
hub / github.com/benfry/processing4 / ModeSelector

Class ModeSelector

app/src/processing/app/ui/ModeSelector.java:39–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37
38
39public class ModeSelector extends JPanel {
40 // corner radius for the dropdown
41 static final int RADIUS = Toolkit.zoom(3);
42
43 String title;
44 Font titleFont;
45 Color titleColor;
46 int titleAscent;
47 int titleWidth;
48
49 final int MODE_GAP_WIDTH = Toolkit.zoom(10);
50 final int ARROW_GAP_WIDTH = Toolkit.zoom(6);
51 final int ARROW_WIDTH = Toolkit.zoom(6);
52 final int ARROW_TOP = Toolkit.zoom(16);
53 final int ARROW_BOTTOM = Toolkit.zoom(22);
54
55 int[] triangleX = new int[3];
56 int[] triangleY = new int[] { ARROW_TOP, ARROW_TOP, ARROW_BOTTOM };
57
58 Color backgroundColor;
59 Color outlineColor;
60
61 public ModeSelector(Editor editor) {
62 title = editor.getMode().getTitle(); //.toUpperCase();
63
64 addMouseListener(new MouseAdapter() {
65 public void mousePressed(MouseEvent event) {
66 JPopupMenu popup = editor.getModePopup();
67 popup.show(ModeSelector.this, event.getX(), event.getY());
68 }
69 });
70
71 updateTheme();
72 }
73
74 public void updateTheme() {
75 titleFont = Theme.getFont("mode.title.font");
76 titleColor = Theme.getColor("mode.title.color");
77
78 // getGraphics() is null (even for editor) and no offscreen yet
79 //titleWidth = getToolkit().getFontMetrics(titleFont).stringWidth(title);
80 //titleWidth = editor.getGraphics().getFontMetrics(titleFont).stringWidth(title);
81
82 // Theme for mode popup is handled inside Editor.handleTheme()
83 // because Editor owns the parent object.
84
85 backgroundColor = Theme.getColor("mode.background.color");
86 outlineColor = Theme.getColor("mode.outline.color");
87 }
88
89 @Override
90 public void paintComponent(Graphics g) {
91 Graphics2D g2 = Toolkit.prepareGraphics(g);
92
93 g.setFont(titleFont);
94 if (titleAscent == 0) {
95 titleAscent = (int) processing.app.ui.Toolkit.getAscent(g); //metrics.getAscent();
96 }

Callers

nothing calls this directly

Calls 1

zoomMethod · 0.95

Tested by

no test coverage detected