|
1 | 1 | package webapp.client; |
2 | 2 |
|
3 | 3 | import com.google.gwt.core.client.EntryPoint; |
| 4 | +import com.google.gwt.core.client.GWT; |
4 | 5 | import com.google.gwt.dom.client.Style; |
5 | 6 | import com.google.gwt.event.dom.client.ClickEvent; |
6 | 7 | import com.google.gwt.event.dom.client.ClickHandler; |
| 8 | +import com.google.gwt.safehtml.shared.SafeHtml; |
| 9 | +import com.google.gwt.safehtml.shared.SafeHtmlUtils; |
7 | 10 | import com.google.gwt.user.client.Command; |
8 | 11 | import com.google.gwt.user.client.Window; |
9 | 12 | import com.google.gwt.user.client.ui.*; |
10 | 13 | import core.ui.GExpertUI; |
11 | 14 | import webapp.client.GExpertCore; |
12 | 15 | import webapp.client.tools.ToolManager; |
| 16 | +import webapp.client.tools.Tool; |
13 | 17 |
|
14 | 18 | import java.util.ArrayList; |
15 | 19 | import java.util.List; |
@@ -39,6 +43,37 @@ private void updateToolButtonStyles(Button activeButton, Button... otherButtons) |
39 | 43 | } |
40 | 44 | } |
41 | 45 |
|
| 46 | + /** |
| 47 | + * Creates a button with an icon for a tool. |
| 48 | + * @param toolId The tool ID |
| 49 | + * @param label The button label |
| 50 | + * @return The created button |
| 51 | + */ |
| 52 | + private Button createToolButton(String toolId, String label) { |
| 53 | + Button button = new Button(); |
| 54 | + Tool tool = toolManager.getTool(toolId); |
| 55 | + |
| 56 | + if (tool != null && tool.getIconPath() != null && !tool.getIconPath().isEmpty()) { |
| 57 | + // Build an <img> + label safely: |
| 58 | + String iconUrl = GWT.getModuleBaseURL() + tool.getIconPath(); |
| 59 | + String safeLabel = SafeHtmlUtils.htmlEscape(label); |
| 60 | + String imgTag = |
| 61 | + "<img src=\"" + iconUrl + "\"" |
| 62 | + + " width=\"16\" height=\"16\"" |
| 63 | + + " style=\"vertical-align:middle; margin-right:4px;\"/>"; |
| 64 | + SafeHtml html = SafeHtmlUtils.fromTrustedString(imgTag + safeLabel); |
| 65 | + button.setHTML(html); |
| 66 | + } else { |
| 67 | + button.setText(label); |
| 68 | + } |
| 69 | + // Tooltip (if available) |
| 70 | + if (tool != null && tool.getDescription() != null) { |
| 71 | + button.setTitle(tool.getDescription()); |
| 72 | + } |
| 73 | + |
| 74 | + return button; |
| 75 | + } |
| 76 | + |
42 | 77 | @Override |
43 | 78 | public void onModuleLoad() { |
44 | 79 | // Initialize UI and core components |
@@ -113,24 +148,24 @@ public void onModuleLoad() { |
113 | 148 | toolbar.getElement().getStyle().setProperty("borderBottomColor", "#CCCCCC"); |
114 | 149 |
|
115 | 150 | // Add tool buttons |
116 | | - Button selectButton = new Button("Select"); |
117 | | - Button pointButton = new Button("Point"); |
118 | | - Button lineButton = new Button("Line"); |
119 | | - Button parallelButton = new Button("Parallel"); |
120 | | - Button perpButton = new Button("Perpendicular"); |
121 | | - Button footButton = new Button("Foot"); |
122 | | - Button circleButton = new Button("Circle"); |
123 | | - Button circle3pButton = new Button("Circle 3P"); |
124 | | - Button compassButton = new Button("Compass"); |
125 | | - Button angleButton = new Button("Angle"); |
126 | | - Button polygonButton = new Button("Polygon"); |
127 | | - Button textButton = new Button("Text"); |
128 | | - Button midpointButton = new Button("Midpoint"); |
129 | | - Button intersectButton = new Button("Intersect"); |
130 | | - Button mirrorButton = new Button("Mirror"); |
131 | | - Button isoscelesButton = new Button("Isosceles"); |
132 | | - Button squareButton = new Button("Square"); |
133 | | - Button triangleButton = new Button("Triangle"); |
| 151 | + Button selectButton = createToolButton("select", "Select"); |
| 152 | + Button pointButton = createToolButton("point", "Point"); |
| 153 | + Button lineButton = createToolButton("line", "Line"); |
| 154 | + Button parallelButton = createToolButton("parallel", "Parallel"); |
| 155 | + Button perpButton = createToolButton("perp", "Perpendicular"); |
| 156 | + Button footButton = createToolButton("foot", "Foot"); |
| 157 | + Button circleButton = createToolButton("circle", "Circle"); |
| 158 | + Button circle3pButton = createToolButton("circle3p", "Circle 3P"); |
| 159 | + Button compassButton = createToolButton("circler", "Compass"); |
| 160 | + Button angleButton = createToolButton("angle", "Angle"); |
| 161 | + Button polygonButton = createToolButton("polygon", "Polygon"); |
| 162 | + Button textButton = createToolButton("text", "Text"); |
| 163 | + Button midpointButton = createToolButton("midpoint", "Midpoint"); |
| 164 | + Button intersectButton = createToolButton("intersect", "Intersect"); |
| 165 | + Button mirrorButton = createToolButton("mirror", "Mirror"); |
| 166 | + Button isoscelesButton = createToolButton("iso", "Isosceles"); |
| 167 | + Button squareButton = createToolButton("square", "Square"); |
| 168 | + Button triangleButton = createToolButton("triangle", "Triangle"); |
134 | 169 |
|
135 | 170 | // Set button styles |
136 | 171 | Style selectStyle = selectButton.getElement().getStyle(); |
|
0 commit comments