package com.googlecode.gchart.gcharttestapp.client; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.RadioButton; import com.google.gwt.user.client.ui.VerticalPanel; import com.googlecode.gchart.client.GChart; import com.googlecode.gchart.client.HoverUpdateable; /** * This example uses a HoverUpdateable widget (a * "hover widget") to create a radio-button-based form that * pops up whenever the user hovers over a point on any * curve, and that allows the user to change that curve's * color and symbol type.
* * As this example illustrates, a hoverWidget can do many of * the same kinds of things you might consider doing with a * modal dialog launched when the user clicks on a point. * But be aware of these important differences/limitations: * *
* *
* *
* *
* *
* *
* * In general, although hover widgets were originally * intended for the static display of additional info about * the hovered-over point, as long as you recognize and work * within their limitations, they also provide an excellent * way of quickly accepting point/curve related user inputs, * too. Kind of like a right click menu without the click. * * */ public class GChartExample19 extends GChart { // various choices, and their labels, in the "hover-form" final String[] color = {"red", "green", "blue"}; final String[] colorLabel = {"Red", "Green", "Blue"}; final SymbolType[] symbol = { SymbolType.VBAR_SOUTH, SymbolType.BOX_CENTER, SymbolType.PIE_SLICE_HATCHED_SHADING}; final String[] symbolLabel = {"Bar", "Box", "Pie"}; // integer offset of the given value in given array private int indexOf(String[] array, String value) { for (int i = 0; i < array.length; i++) if (array[i].equals(value)) return i; throw new IllegalArgumentException( "Value (" + value + ") not found."); } class CurveEditingForm extends VerticalPanel implements HoverUpdateable { CurveEditingForm() { /* For reference, here's the CSS style-name definition in gcharttestapp.css: .gchartestapp-GChartExample19-CurveEditingForm { background-color: #DDF; border-width: 10px; border-color: black; border-style: solid; border-width: 1px; padding: 10px; } */ setStyleName("gchartestapp-GChartExample19-CurveEditingForm"); add(new HTML()); // to hold label for color radio-group for (int i = 0; i < colorLabel.length; i++) { RadioButton radioButton = new RadioButton("color", colorLabel[i]); radioButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String label = ((RadioButton) event.getSource()).getText(); getTouchedCurve().getSymbol().setBorderColor( color[indexOf(colorLabel, label)]); update(); } }); add(radioButton); } add(new HTML()); // to hold label for symbol radio-group for (int i = 0; i < symbolLabel.length; i++) { RadioButton radioButton = new RadioButton("symbol", symbolLabel[i]); radioButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String label = ((RadioButton) event.getSource()).getText(); getTouchedCurve().getSymbol().setSymbolType( symbol[indexOf(symbolLabel, label)]); // symbol changes can change point "touching" // mouse: lock touched point to prevent this update(TouchedPointUpdateOption.TOUCHED_POINT_LOCKED); } }); add(radioButton); } } private void loadCurveProperties(Curve c) { int iWidget = 0; ((HTML) getWidget(iWidget)).setHTML( "