MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / draw

Method draw

src/org/opensourcephysics/display/TextBox.java:78–153  ·  view source on GitHub ↗
(DrawingPanel panel, Graphics g)

Source from the content-addressed store, hash-verified

76 }
77
78 @Override
79public void draw(DrawingPanel panel, Graphics g) {
80 String tempText = text; // local reference for thread safety
81 if(tempText==null) {
82 return;
83 }
84 FontMetrics fm = g.getFontMetrics();
85 int sh = fm.getAscent()+2; // current string height
86 int sw = fm.stringWidth(tempText)+6; // current string width
87 boxHeight = Math.max(boxHeight, sh);
88 boxWidth = Math.max(boxWidth, sw);
89 switch(placement_mode) {
90 case PIXEL_PLACEMENT :
91 xpix = (int) x;
92 ypix = (int) y;
93 break;
94 case RELATIVE_PLACEMENT :
95 xpix = (int) (x*panel.getWidth());
96 ypix = (int) ((1-y)*panel.getHeight());
97 break;
98 case TOP_LEFT_PLACEMENT :
99 xpix = 0;
100 ypix = 0;
101 break;
102 case TOP_LEFT_GUTTER_PLACEMENT :
103 xpix = panel.getLeftGutter();
104 ypix = panel.getTopGutter();
105 break;
106 case BOTTOM_LEFT_PLACEMENT :
107 xpix = 0;
108 ypix = panel.getHeight()-boxHeight-yoffset-1;
109 break;
110 case BOTTOM_LEFT_GUTTER_PLACEMENT :
111 xpix = panel.getLeftGutter();
112 ypix = panel.getHeight()-boxHeight-yoffset-1-panel.getBottomGutter();
113 break;
114 case TOP_RIGHT_PLACEMENT :
115 xpix = panel.getWidth()-boxWidth-1;
116 ypix = 0;
117 break;
118 case TOP_RIGHT_GUTTER_PLACEMENT :
119 xpix = panel.getWidth()-boxWidth-1-panel.getRightGutter();
120 ypix = panel.getTopGutter();
121 break;
122 case BOTTOM_RIGHT_PLACEMENT :
123 xpix = panel.getWidth()-boxWidth-1;
124 ypix = panel.getHeight()-boxHeight-yoffset-1;
125 break;
126 case BOTTOM_RIGHT_GUTTER_PLACEMENT :
127 xpix = panel.getWidth()-boxWidth-1-panel.getRightGutter();
128 ypix = panel.getHeight()-boxHeight-yoffset-1-panel.getBottomGutter();
129 break;
130 default :
131 xpix = panel.xToPix(x);
132 ypix = panel.yToPix(y);
133 break;
134 }
135 int xoffset = this.xoffset, yoffset = this.yoffset;

Callers

nothing calls this directly

Calls 15

maxMethod · 0.80
getRightGutterMethod · 0.80
setClipMethod · 0.80
drawRectMethod · 0.80
drawStringMethod · 0.80
getWidthMethod · 0.65
getHeightMethod · 0.65
setFontMethod · 0.65
disposeMethod · 0.65
getFontMetricsMethod · 0.45
getAscentMethod · 0.45
getLeftGutterMethod · 0.45

Tested by

no test coverage detected