teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.client.ui; ingo@41: ingo@41: import com.google.gwt.core.client.GWT; ingo@562: import com.google.gwt.i18n.client.NumberFormat; ingo@41: christian@4131: import com.smartgwt.client.data.AdvancedCriteria; raimund@863: import com.smartgwt.client.data.Criteria; raimund@1536: import com.smartgwt.client.data.Criterion; christian@4131: import com.smartgwt.client.data.Record; christian@4131: import com.smartgwt.client.types.Alignment; christian@4131: import com.smartgwt.client.types.ListGridFieldType; raimund@1536: import com.smartgwt.client.types.OperatorId; ingo@41: import com.smartgwt.client.widgets.Canvas; ingo@41: import com.smartgwt.client.widgets.Label; ingo@41: import com.smartgwt.client.widgets.form.DynamicForm; christian@4131: import com.smartgwt.client.widgets.form.fields.FormItem; christian@4131: import com.smartgwt.client.widgets.form.fields.RadioGroupItem; christian@4131: import com.smartgwt.client.widgets.form.fields.SelectItem; christian@4131: import com.smartgwt.client.widgets.form.fields.StaticTextItem; ingo@41: import com.smartgwt.client.widgets.form.fields.events.BlurEvent; christian@4131: import com.smartgwt.client.widgets.form.fields.events.BlurHandler; christian@4131: import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; ingo@41: import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; raimund@1534: import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; christian@4131: import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; christian@4131: import com.smartgwt.client.widgets.grid.CellFormatter; raimund@235: import com.smartgwt.client.widgets.grid.ListGrid; raimund@235: import com.smartgwt.client.widgets.grid.ListGridField; raimund@906: import com.smartgwt.client.widgets.grid.ListGridRecord; raimund@235: import com.smartgwt.client.widgets.grid.events.RecordClickEvent; christian@4131: import com.smartgwt.client.widgets.grid.events.RecordClickHandler; christian@4131: import com.smartgwt.client.widgets.layout.HLayout; christian@4131: import com.smartgwt.client.widgets.layout.VLayout; christian@4131: import com.smartgwt.client.widgets.tab.Tab; christian@4131: import com.smartgwt.client.widgets.tab.TabSet; raimund@893: import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; christian@4131: import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; raimund@235: teichmann@5835: import org.dive4elements.river.client.client.Config; teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; teichmann@5835: import org.dive4elements.river.client.client.event.FilterHandler; teichmann@5835: import org.dive4elements.river.client.client.event.RangeFilterEvent; teichmann@5835: import org.dive4elements.river.client.client.event.StringFilterEvent; teichmann@5835: import org.dive4elements.river.client.client.services.DistanceInfoService; teichmann@5835: import org.dive4elements.river.client.client.services.DistanceInfoServiceAsync; teichmann@5835: import org.dive4elements.river.client.client.ui.range.DistanceInfoDataSource; teichmann@5835: import org.dive4elements.river.client.shared.model.ArtifactDescription; teichmann@5835: import org.dive4elements.river.client.shared.model.Data; teichmann@5835: import org.dive4elements.river.client.shared.model.DataItem; teichmann@5835: import org.dive4elements.river.client.shared.model.DataList; teichmann@5835: import org.dive4elements.river.client.shared.model.DefaultData; teichmann@5835: import org.dive4elements.river.client.shared.model.DefaultDataItem; teichmann@5835: import org.dive4elements.river.client.shared.model.DistanceInfoObject; raimund@235: christian@4131: import java.util.ArrayList; christian@4131: import java.util.LinkedHashMap; christian@4131: import java.util.List; ingo@41: ingo@41: ingo@41: /** ingo@41: * This UIProvider creates a widget to enter locations or a distance. ingo@41: * ingo@41: * @author Ingo Weinzierl ingo@41: */ ingo@41: public class LocationDistancePanel ingo@41: extends AbstractUIProvider raimund@863: implements ChangeHandler, BlurHandler, FilterHandler ingo@41: { christian@4131: private static final long serialVersionUID = -10820092176039372L; christian@4131: felix@838: /** The message class that provides i18n strings. */ ingo@211: protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); ingo@41: felix@838: /** The DistanceInfoService used to retrieve locations about rivers. */ raimund@235: protected DistanceInfoServiceAsync distanceInfoService = raimund@235: GWT.create(DistanceInfoService.class); ingo@41: ingo@516: public static final String FIELD_MODE = "mode"; ingo@43: ingo@41: /** The constant name of the input field to enter the start of a distance.*/ ingo@41: public static final String FIELD_FROM = "from"; ingo@41: ingo@41: /** The constant name of the input field to enter the end of a distance.*/ ingo@41: public static final String FIELD_TO = "to"; ingo@41: ingo@516: /** The constant name of the input field to enter locations.*/ ingo@516: public static final String FIELD_VALUE_LOCATION = "location"; ingo@516: ingo@516: /** The constant name of the input field to enter distance.*/ ingo@516: public static final String FIELD_VALUE_DISTANCE = "distance"; ingo@516: ingo@41: /** The constant name of the input field to enter the step width of a ingo@41: * distance.*/ ingo@41: public static final String FIELD_WIDTH = "width"; ingo@41: ingo@53: public static final int WIDTH = 250; ingo@53: ingo@41: ingo@41: /** The radio group for input mode selection.*/ ingo@43: protected DynamicForm mode; ingo@41: ingo@41: /** A container that will contain the location or the distance panel.*/ ingo@41: protected HLayout container; ingo@41: ingo@55: /** The min value for a distance.*/ ingo@55: protected double min; ingo@55: ingo@55: /** The max value for a distance.*/ ingo@55: protected double max; ingo@55: ingo@43: /** The 'from' value entered in the distance mode.*/ ingo@43: protected double from; ingo@43: ingo@43: /** The 'to' value entered in the distance mode.*/ ingo@43: protected double to; ingo@43: ingo@43: /** The 'step' value entered in the distance mode.*/ ingo@43: protected double step; ingo@43: ingo@43: /** The values entered in the location mode.*/ ingo@43: protected double[] values; ingo@43: felix@838: /** The input panel for locations. */ raimund@235: protected DoubleArrayPanel locationPanel; raimund@235: felix@838: /** The input panel for distances. */ raimund@235: protected DoubleRangePanel distancePanel; raimund@235: felix@838: /** The tab set containing the location and distance table. */ raimund@235: protected TabSet inputTables; raimund@235: raimund@235: /** The distance table. */ raimund@235: protected ListGrid distanceTable; raimund@235: felix@838: /** The locations table. */ raimund@235: protected ListGrid locationsTable; raimund@235: raimund@237: /** The table data. */ raimund@237: protected DistanceInfoObject[] tableData; raimund@237: raimund@893: /** The table filter.*/ raimund@1534: protected TableFilter filterDescription; raimund@1534: protected RangeTableFilter filterRange; raimund@1534: raimund@1534: /** The Combobox for table filter criteria. */ raimund@1534: protected SelectItem filterCriteria; raimund@1567: protected StaticTextItem filterResultCount; raimund@1567: protected ListGrid currentFiltered; raimund@893: ingo@41: /** ingo@41: * Creates a new LocationDistancePanel instance. ingo@41: */ ingo@41: public LocationDistancePanel() { raimund@235: distanceTable = new ListGrid(); raimund@863: distanceTable.setAutoFetchData(true); raimund@863: raimund@235: locationsTable = new ListGrid(); raimund@863: locationsTable.setAutoFetchData(true); raimund@863: raimund@284: distanceTable.setShowHeaderContextMenu(false); raimund@284: locationsTable.setShowHeaderContextMenu(false); ingo@41: } ingo@41: ingo@41: ingo@41: /** ingo@41: * This method creates a widget that contains a label, a panel with ingo@41: * checkboxes to switch the input mode between location and distance input, ingo@41: * and a the mode specific panel. ingo@41: * ingo@41: * @param data The data that might be inserted. ingo@41: * ingo@41: * @return a panel. ingo@41: */ christian@4131: @Override ingo@51: public Canvas create(DataList data) { ingo@41: VLayout layout = new VLayout(); ingo@83: layout.setMembersMargin(10); ingo@41: ingo@57: Label label = new Label(MESSAGES.location_distance_state()); ingo@57: Canvas widget = createWidget(data); ingo@57: Canvas submit = getNextButton(); raimund@235: createDistanceInputPanel(); raimund@235: ingo@516: initDefaults(data); ingo@516: ingo@83: widget.setHeight(50); ingo@41: label.setHeight(25); ingo@41: ingo@41: layout.addMember(label); ingo@45: layout.addMember(widget); ingo@45: layout.addMember(submit); ingo@45: ingo@45: return layout; ingo@45: } ingo@45: ingo@45: raimund@235: /** andre@8449: * Setup a table for a DistanceInfoDataSource. andre@8449: * andre@8449: * Sets up a table to for input completion. The table andre@8449: * can be used either for single locations or distances. andre@8449: * Depending on the value of isDistance the table will andre@8449: * have a to and a from column or a single location column. andre@8449: * andre@8449: * @param table the ListGrid to set up. andre@8449: * @param doublePins wether or not to have. andre@8449: * @param isDistance wether or not to and from should be included. raimund@235: */ andre@8449: protected void setupDistanceInfoTable(ListGrid table, andre@8449: boolean doublePins, andre@8449: boolean isDistance) { raimund@863: raimund@1399: String baseUrl = GWT.getHostPageBaseURL(); raimund@1399: andre@8449: table.setWidth100(); andre@8449: table.setShowRecordComponents(true); andre@8449: table.setShowRecordComponentsByCell(true); andre@8449: table.setHeight100(); andre@8449: table.setEmptyMessage(MESSAGES.empty_filter()); andre@8449: table.setCanReorderFields(false); raimund@235: raimund@1390: CellFormatter cf = new CellFormatter() { christian@4131: @Override raimund@1390: public String format( raimund@1390: Object value, raimund@1390: ListGridRecord record, raimund@1390: int rowNum, int colNum) { raimund@1390: if (value == null) return null; raimund@1390: try { raimund@1390: NumberFormat nf; raimund@1390: double v = Double.parseDouble((String)value); raimund@1390: nf = NumberFormat.getFormat("###0.00##"); raimund@1390: return nf.format(v); raimund@1390: } raimund@1390: catch (Exception e) { raimund@1390: return value.toString(); raimund@1390: } raimund@1390: } raimund@1390: }; andre@8449: ListGridField pin1 = null; andre@8449: ListGridField pin2 = null; raimund@1390: andre@8449: if (doublePins) { andre@8449: pin1 = new ListGridField ("fromIcon", MESSAGES.from()); andre@8449: pin1.setWidth (30); andre@8449: } else { andre@8449: pin1 = new ListGridField ("fromIcon", MESSAGES.selection()); andre@8449: pin1.setWidth (60); andre@8449: } andre@8449: pin1.setType (ListGridFieldType.ICON); andre@8449: pin1.setCellIcon(baseUrl + MESSAGES.markerGreen()); andre@8449: andre@8449: if (doublePins) { andre@8449: pin2 = new ListGridField ("toIcon", MESSAGES.to()); andre@8449: pin2.setType (ListGridFieldType.ICON); andre@8449: pin2.setWidth (30); andre@8449: pin2.setCellIcon(baseUrl + MESSAGES.markerRed()); andre@8449: } andre@8449: andre@8449: if (isDistance) { andre@8449: /* We have from / to fields */ andre@8449: pin1.addRecordClickHandler (new RecordClickHandler () { andre@8449: @Override andre@8449: public void onRecordClick (RecordClickEvent e) { raimund@235: Record r = e.getRecord(); andre@8449: if (!isLocationMode ()) { andre@8449: /* distance panel and distance mode */ andre@8449: setFrom(r.getAttribute("from")); andre@8449: setTo(r.getAttribute("to")); andre@8449: } else { andre@8449: /* distance panel and location mode */ andre@8449: /* Pin 1 is the "from" pin */ andre@8449: appendLocation(r.getAttribute("from")); raimund@863: } raimund@235: } andre@8449: }); andre@8449: if (doublePins) { andre@8449: pin2.addRecordClickHandler (new RecordClickHandler () { andre@8449: @Override andre@8449: public void onRecordClick (RecordClickEvent e) { andre@8449: Record r = e.getRecord(); andre@8449: if (isLocationMode ()) { andre@8449: appendLocation(r.getAttribute("to")); andre@8449: } else { tom@8856: /* Distance and double pin behavior is only tom@8856: * defined for location mode. */ andre@8449: GWT.log("Unhandled input state."); andre@8449: } raimund@863: } andre@8449: }); andre@8449: } andre@8449: } else { andre@8449: /* We only have the from field */ andre@8449: pin1.addRecordClickHandler (new RecordClickHandler () { andre@8449: @Override andre@8449: public void onRecordClick (RecordClickEvent e) { andre@8449: Record r = e.getRecord(); andre@8449: if (!isLocationMode ()) { andre@8449: /* Location panel and distance mode */ andre@8449: setFrom(r.getAttribute("from")); andre@8449: } else { andre@8449: /* Location panel and location mode */ andre@8449: appendLocation(r.getAttribute("from")); raimund@235: } andre@8449: } andre@8449: }); andre@8449: if (doublePins) { andre@8449: pin2.addRecordClickHandler (new RecordClickHandler () { andre@8449: @Override andre@8449: public void onRecordClick (RecordClickEvent e) { andre@8449: Record r = e.getRecord(); andre@8449: if (!isLocationMode ()) { andre@8449: setTo(r.getAttribute("from")); andre@8449: } else { tom@8856: /* Distance and double pin behavior is only tom@8856: * defined for location mode. */ andre@8449: GWT.log("Unhandled input state."); andre@8449: } raimund@235: } andre@8449: }); raimund@235: } andre@8449: } raimund@235: raimund@235: ListGridField ddescr = new ListGridField("description", raimund@235: MESSAGES.description()); raimund@235: ddescr.setType(ListGridFieldType.TEXT); raimund@235: ddescr.setWidth("*"); andre@8449: andre@8449: ListGridField from; andre@8449: ListGridField to = null; andre@8449: andre@8449: if (isDistance) { andre@8449: from = new ListGridField("from", MESSAGES.from()); andre@8449: to = new ListGridField("to", MESSAGES.to()); andre@8449: to.setType(ListGridFieldType.FLOAT); andre@8449: to.setCellFormatter(cf); andre@8449: andre@8449: to.setWidth("12%"); andre@8449: to.setAlign(Alignment.LEFT); andre@8449: } else { andre@8449: from = new ListGridField("from", MESSAGES.locations()); andre@8449: } raimund@1390: from.setCellFormatter(cf); raimund@886: from.setWidth("12%"); raimund@906: raimund@235: ListGridField dside = new ListGridField("riverside", raimund@235: MESSAGES.riverside()); raimund@235: dside.setType(ListGridFieldType.TEXT); raimund@886: dside.setWidth("12%"); raimund@235: sascha@568: ListGridField bottom = sascha@568: new ListGridField("bottom", MESSAGES.bottom_edge()); sascha@568: bottom.setType(ListGridFieldType.TEXT); raimund@886: bottom.setWidth("10%"); raimund@1390: bottom.setCellFormatter(cf); sascha@568: sascha@568: ListGridField top = sascha@568: new ListGridField("top", MESSAGES.top_edge()); sascha@568: top.setType(ListGridFieldType.TEXT); raimund@886: top.setWidth("10%"); raimund@1390: top.setCellFormatter(cf); sascha@568: andre@8449: if (doublePins && isDistance) { andre@8449: table.setFields(pin1, pin2, ddescr, from, to, dside, bottom, top); andre@8449: } else if (doublePins) { andre@8449: table.setFields(pin1, pin2, ddescr, from, dside, bottom, top); andre@8449: } else if (isDistance) { andre@8449: table.setFields(pin1, ddescr, from, to, dside, bottom, top); andre@8449: } else { andre@8449: table.setFields(pin1, ddescr, from, dside, bottom, top); andre@8449: } raimund@235: } raimund@235: christian@4131: @Override ingo@53: public Canvas createOld(DataList dataList) { ingo@53: List items = dataList.getAll(); ingo@53: ingo@516: Data dMode = getData(items, "ld_mode"); ingo@516: DataItem[] dItems = dMode.getItems(); ingo@516: ingo@516: boolean rangeMode = true; ingo@516: if (dItems != null && dItems[0] != null) { ingo@516: rangeMode = FIELD_VALUE_DISTANCE.equals(dItems[0].getStringValue()); ingo@516: } ingo@516: ingo@516: HLayout layout = new HLayout(); ingo@516: layout.setWidth("400px"); ingo@516: ingo@516: Label label = new Label(dataList.getLabel()); ingo@516: label.setWidth("200px"); ingo@516: ingo@516: Canvas back = getBackButton(dataList.getState()); ingo@516: ingo@516: layout.addMember(label); ingo@516: ingo@516: if (rangeMode) { ingo@516: layout.addMember(getOldRangeSelection(dataList)); ingo@516: } ingo@516: else { ingo@516: layout.addMember(getOldLocationSelection(dataList)); ingo@516: } ingo@516: ingo@516: layout.addMember(back); ingo@516: ingo@516: return layout; ingo@516: } ingo@516: ingo@516: ingo@516: /** ingo@516: * Creates a label for the selected range. ingo@516: * ingo@516: * @param dataList The DataList containing all values for this state. ingo@516: * ingo@516: * @return A label displaying the selected values. ingo@516: */ ingo@516: protected Label getOldRangeSelection(DataList dataList) { ingo@516: List items = dataList.getAll(); ingo@516: ingo@53: Data dFrom = getData(items, "ld_from"); ingo@53: Data dTo = getData(items, "ld_to"); ingo@53: Data dStep = getData(items, "ld_step"); ingo@53: ingo@53: DataItem[] from = dFrom.getItems(); ingo@53: DataItem[] to = dTo.getItems(); ingo@53: DataItem[] step = dStep.getItems(); ingo@53: ingo@53: StringBuilder sb = new StringBuilder(); ingo@53: sb.append(from[0].getLabel()); ingo@53: sb.append(" " + MESSAGES.unitFrom() + " "); ingo@53: sb.append(to[0].getLabel()); ingo@53: sb.append(" " + MESSAGES.unitTo() + " "); ingo@53: sb.append(step[0].getLabel()); ingo@53: sb.append(" " + MESSAGES.unitWidth()); ingo@53: raimund@91: Label selected = new Label(sb.toString()); raimund@91: selected.setWidth("130px"); raimund@91: ingo@516: return selected; ingo@516: } ingo@53: ingo@516: ingo@516: /** ingo@516: * Creates a label for the selected locations. ingo@516: * ingo@516: * @param dataList The DataList containing all values for this state. ingo@516: * ingo@516: * @return A label displaying the selected values. ingo@516: */ ingo@516: protected Label getOldLocationSelection(DataList dataList) { ingo@516: List items = dataList.getAll(); ingo@516: ingo@516: Data dLocations = getData(items, "ld_locations"); ingo@516: DataItem[] lItems = dLocations.getItems(); ingo@516: raimund@3542: String[] splitted = lItems[0].getStringValue().split(" "); raimund@3542: String value = ""; raimund@3542: for (int i = 0; i < splitted.length; i++) { raimund@3542: try { raimund@3542: NumberFormat nf = NumberFormat.getDecimalFormat(); raimund@3542: double dv = Double.parseDouble(splitted[i]); raimund@3542: value += nf.format(dv) + " "; raimund@3542: } raimund@3542: catch(NumberFormatException nfe) { raimund@3542: value += splitted[i] + " "; raimund@3542: } raimund@3542: } ingo@516: ingo@516: Label selected = new Label(value); ingo@516: selected.setWidth(130); ingo@516: ingo@516: return selected; ingo@53: } ingo@53: ingo@53: ingo@53: /** ingo@55: * This method reads the default values defined in the DataItems of the Data ingo@55: * objects in list. ingo@55: * ingo@55: * @param list The DataList container that stores the Data objects. ingo@55: */ ingo@55: protected void initDefaults(DataList list) { ingo@516: Data m = getData(list.getAll(), "ld_mode"); ingo@516: Data l = getData(list.getAll(), "ld_locations"); ingo@55: Data f = getData(list.getAll(), "ld_from"); ingo@55: Data t = getData(list.getAll(), "ld_to"); ingo@55: Data s = getData(list.getAll(), "ld_step"); ingo@55: ingo@55: DataItem[] fItems = f.getItems(); ingo@55: DataItem[] tItems = t.getItems(); ingo@55: DataItem[] sItems = s.getItems(); ingo@55: ingo@55: min = Double.valueOf(fItems[0].getStringValue()); ingo@55: max = Double.valueOf(tItems[0].getStringValue()); ingo@55: step = Double.valueOf(sItems[0].getStringValue()); ingo@55: ingo@516: DataItem mDef = m.getDefault(); ingo@516: DataItem lDef = l.getDefault(); ingo@516: DataItem fDef = f.getDefault(); ingo@516: DataItem tDef = t.getDefault(); ingo@516: DataItem sDef = s.getDefault(); ingo@55: ingo@517: String mDefValue = mDef != null ? mDef.getStringValue() : null; ingo@517: String theMode = mDefValue != null && mDefValue.length() > 0 ingo@516: ? mDef.getStringValue() ingo@588: : FIELD_VALUE_DISTANCE; ingo@516: ingo@516: mode.setValue(FIELD_MODE, theMode); ingo@516: ingo@517: String fDefValue = fDef != null ? fDef.getStringValue() : null; ingo@517: setFrom(fDefValue != null && fDefValue.length() > 0 ingo@516: ? Double.valueOf(fDef.getStringValue()) ingo@516: : min); ingo@516: ingo@517: String tDefValue = tDef != null ? tDef.getStringValue() : null; ingo@517: setTo(tDefValue != null && tDefValue.length() > 0 ingo@516: ? Double.valueOf(tDef.getStringValue()) ingo@516: : max); ingo@516: ingo@517: String sDefValue = sDef != null ? sDef.getStringValue() : null; ingo@517: setStep(sDefValue != null && sDefValue.length() > 0 ingo@516: ? Double.valueOf(sDef.getStringValue()) ingo@516: : step); ingo@516: ingo@516: if (lDef != null) { ingo@517: String lDefValue = lDef != null ? lDef.getStringValue() : null; ingo@517: ingo@517: if (lDefValue != null && lDefValue.length() > 0) { ingo@517: setLocationValues(lDef.getStringValue()); ingo@517: } ingo@53: } ingo@53: ingo@516: if (theMode.equals(FIELD_VALUE_DISTANCE)) { andre@8448: enableDistanceMode(); ingo@588: inputTables.selectTab(1); andre@8449: } else { andre@8449: enableLocationMode(); ingo@516: } raimund@1567: currentFiltered = (ListGrid)inputTables.getSelectedTab().getPane(); andre@8446: andre@8446: distancePanel.setValues(getFrom(), getTo(), getStep()); ingo@53: } ingo@53: ingo@53: ingo@51: protected Canvas createWidget(DataList data) { ingo@45: VLayout layout = new VLayout(); ingo@45: container = new HLayout(); ingo@45: Canvas checkboxPanel = createRadioButtonPanel(); ingo@45: raimund@235: locationPanel = new DoubleArrayPanel( ingo@45: MESSAGES.unitLocation(), ingo@45: getLocationValues(), ingo@45: this); andre@8446: rrenkert@8262: distancePanel = new DoubleRangePanel( andre@8446: MESSAGES.unitFrom(), MESSAGES.unitTo(), MESSAGES.unitWidth(), andre@8446: 0, 0, 0, /* initDefaults set the default values for this. */ andre@8446: 400, andre@8446: this); rrenkert@8262: ingo@45: container.addMember(locationPanel); rrenkert@8262: container.addMember(distancePanel); rrenkert@8262: container.hideMember(locationPanel); ingo@45: ingo@41: layout.addMember(checkboxPanel); ingo@41: layout.addMember(container); ingo@41: raimund@235: container.setMembersMargin(30); raimund@235: raimund@235: inputTables = new TabSet(); raimund@893: inputTables.addTabSelectedHandler(new TabSelectedHandler() { christian@4131: @Override raimund@893: public void onTabSelected(TabSelectedEvent evt) { raimund@1534: filterDescription.clear(); raimund@1537: filterRange.clear(); raimund@1567: filterResultCount.setValue(""); raimund@1567: andre@8448: // The assumption is that location is tab 0 and distance tab 1 andre@8448: raimund@1567: Canvas c = evt.getTabPane(); raimund@1567: if(c instanceof ListGrid) { raimund@1567: currentFiltered = (ListGrid)c; raimund@1567: } raimund@893: } raimund@893: }); raimund@893: ingo@570: Tab locations = new Tab(MESSAGES.locations()); raimund@235: Tab distances = new Tab(MESSAGES.distance()); raimund@235: raimund@272: inputTables.setWidth100(); raimund@272: inputTables.setHeight100(); raimund@235: andre@8449: locations.setPane(locationsTable); raimund@235: distances.setPane(distanceTable); raimund@235: raimund@235: inputTables.addTab(locations); raimund@235: inputTables.addTab(distances); raimund@235: raimund@1567: filterResultCount = new StaticTextItem(MESSAGES.resultCount()); raimund@1567: filterResultCount.setTitleAlign(Alignment.LEFT); raimund@1567: filterResultCount.setTitleStyle("color: #000"); raimund@1567: raimund@1534: filterDescription = new TableFilter(); raimund@1534: filterDescription.setHeight("30px"); raimund@1534: filterDescription.addFilterHandler(this); raimund@1534: raimund@1534: filterRange = new RangeTableFilter(); raimund@1534: filterRange.setHeight("30px"); raimund@1534: filterRange.addFilterHandler(this); raimund@1534: filterRange.setVisible(false); raimund@1534: raimund@1534: filterCriteria = new SelectItem(); raimund@1534: filterCriteria.setShowTitle(false); raimund@1534: filterCriteria.setWidth(100); raimund@1534: filterCriteria.addChangedHandler(new ChangedHandler() { christian@4131: @Override raimund@1534: public void onChanged(ChangedEvent e) { raimund@1534: if(e.getValue().toString().equals("range")) { raimund@1534: filterRange.setVisible(true); raimund@1534: filterDescription.setVisible(false); raimund@1534: filterDescription.clear(); raimund@1567: filterResultCount.setValue(""); raimund@1534: } raimund@1534: else { raimund@1534: filterRange.setVisible(false); raimund@1534: filterRange.clear(); raimund@1534: filterDescription.setVisible(true); raimund@1567: filterResultCount.setValue(""); raimund@1534: } raimund@1534: } raimund@1534: }); raimund@1534: raimund@1534: LinkedHashMap filterMap = raimund@1534: new LinkedHashMap(); raimund@1534: filterMap.put("description", MESSAGES.description()); raimund@1534: filterMap.put("range", MESSAGES.range()); raimund@1534: filterCriteria.setValueMap(filterMap); raimund@1534: filterCriteria.setValue("description"); raimund@1534: raimund@1534: DynamicForm form = new DynamicForm(); raimund@1534: form.setFields(filterCriteria); raimund@863: inputTables.setHeight("*"); raimund@1567: DynamicForm form2 = new DynamicForm(); raimund@1567: form2.setFields(filterResultCount); raimund@863: raimund@863: VLayout helper = new VLayout(); raimund@1534: HLayout filterLayout = new HLayout(); raimund@1534: raimund@1534: filterLayout.addMember(form); raimund@1534: filterLayout.addMember(filterDescription); raimund@1534: filterLayout.addMember(filterRange); raimund@1567: filterLayout.setHeight("30px"); raimund@863: helper.addMember(inputTables); raimund@1534: helper.addMember(filterLayout); raimund@1567: helper.addMember(form2); raimund@863: helper.setHeight100(); raimund@863: helper.setWidth100(); raimund@863: raimund@869: helperContainer.addMember(helper); raimund@1534: filterLayout.setWidth("200"); ingo@41: ingo@41: return layout; ingo@41: } ingo@41: ingo@41: christian@4131: @Override raimund@863: public void onFilterCriteriaChanged(StringFilterEvent event) { raimund@863: String search = event.getFilter(); raimund@863: raimund@863: if (search != null && search.length() > 0) { raimund@863: Criteria c = new Criteria("description", search); raimund@863: raimund@863: locationsTable.filterData(c); raimund@863: distanceTable.filterData(c); raimund@1567: filterResultCount.setValue(currentFiltered.getRecords().length); raimund@863: } raimund@863: else { raimund@893: locationsTable.clearCriteria(); raimund@893: distanceTable.clearCriteria(); raimund@1567: filterResultCount.setValue(""); raimund@863: } raimund@863: } raimund@863: raimund@863: christian@4131: @Override raimund@1534: public void onFilterCriteriaChanged(RangeFilterEvent event) { raimund@1536: Float from = event.getFrom() - 0.001f; raimund@1536: Float to = event.getTo() + 0.001f; raimund@1536: GWT.log("filtering range: " + from + " to " + to); raimund@1536: raimund@1536: raimund@1536: Criterion combinedFilter = null; raimund@1536: Criterion locationFilter = null; raimund@1536: if (from.equals(Float.NaN) && to.equals(Float.NaN)) { raimund@1536: locationsTable.clearCriteria(); raimund@1536: distanceTable.clearCriteria(); raimund@1567: filterResultCount.setValue(""); raimund@1567: return; raimund@1536: } raimund@1536: else if (from.equals(Float.NaN)) { raimund@1536: combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); raimund@1536: locationFilter = raimund@1536: new Criterion("from", OperatorId.LESS_OR_EQUAL, to); raimund@1536: locationsTable.filterData(locationFilter); raimund@1536: distanceTable.filterData(combinedFilter); raimund@1567: filterResultCount.setValue(currentFiltered.getRecords().length); raimund@1536: return; raimund@1536: } raimund@1536: else if (to.equals(Float.NaN)) { raimund@1536: combinedFilter = raimund@1536: new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); raimund@1536: locationsTable.filterData(combinedFilter); raimund@1536: distanceTable.filterData(combinedFilter); raimund@1536: } raimund@1536: else { raimund@1536: AdvancedCriteria c1 = raimund@1536: new AdvancedCriteria(OperatorId.AND, new Criterion[] { raimund@1536: new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), raimund@1536: new Criterion("from", OperatorId.LESS_OR_EQUAL, to) raimund@1536: }); raimund@1536: raimund@1536: AdvancedCriteria c2 = raimund@1536: new AdvancedCriteria(OperatorId.AND, new Criterion[] { raimund@1536: new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), raimund@1536: new Criterion("to", OperatorId.LESS_OR_EQUAL, to) raimund@1536: }); raimund@1536: raimund@1537: AdvancedCriteria c3 = raimund@1537: new AdvancedCriteria(OperatorId.AND, new Criterion[] { raimund@1537: new Criterion("from", OperatorId.LESS_OR_EQUAL, to), raimund@1537: new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) raimund@1537: }); raimund@1537: raimund@1536: combinedFilter = raimund@1536: new AdvancedCriteria(OperatorId.OR, new Criterion[] { raimund@1537: c1, c2, c3 raimund@1536: }); raimund@1536: } raimund@1536: locationsTable.filterData(combinedFilter); raimund@1536: distanceTable.filterData(combinedFilter); raimund@1567: filterResultCount.setValue(currentFiltered.getRecords().length); raimund@1534: } raimund@863: raimund@863: ingo@562: @Override ingo@562: public List validate() { ingo@562: if (isLocationMode()) { ingo@562: return validateLocations(); ingo@562: } ingo@562: else { ingo@562: return validateRange(); ingo@562: } ingo@562: } ingo@562: ingo@562: ingo@562: protected List validateLocations() { ingo@562: List errors = new ArrayList(); ingo@562: NumberFormat nf = NumberFormat.getDecimalFormat(); ingo@562: ingo@562: try { ingo@562: saveLocationValues(locationPanel); ingo@562: } ingo@562: catch (Exception e) { ingo@562: errors.add(MESSAGES.wrongFormat()); ingo@562: } ingo@562: ingo@562: double[] values = getLocationValues(); ingo@562: double[] good = new double[values.length]; ingo@562: int idx = 0; ingo@562: ingo@562: for (double value: values) { ingo@562: if (value < min || value > max) { ingo@562: String tmp = MESSAGES.error_validate_range(); ingo@562: tmp = tmp.replace("$1", nf.format(value)); ingo@562: tmp = tmp.replace("$2", nf.format(min)); ingo@562: tmp = tmp.replace("$3", nf.format(max)); ingo@562: errors.add(tmp); ingo@562: } ingo@562: else { ingo@562: good[idx++] = value; ingo@562: } ingo@562: } ingo@562: ingo@562: double[] justGood = new double[idx]; ingo@562: for (int i = 0; i < justGood.length; i++) { ingo@562: justGood[i] = good[i]; ingo@562: } ingo@562: ingo@562: if (!errors.isEmpty()) { ingo@562: locationPanel.setValues(justGood); ingo@562: } ingo@562: ingo@562: return errors; ingo@562: } ingo@562: ingo@562: ingo@562: protected List validateRange() { ingo@562: List errors = new ArrayList(); ingo@562: NumberFormat nf = NumberFormat.getDecimalFormat(); ingo@562: ingo@562: try { ingo@562: saveDistanceValues(distancePanel); ingo@562: } ingo@562: catch (Exception e) { ingo@562: errors.add(MESSAGES.wrongFormat()); ingo@562: } ingo@562: ingo@562: double from = getFrom(); ingo@562: double to = getTo(); ingo@562: double step = getStep(); ingo@562: ingo@562: if (from < min || from > max) { tom@6996: String tmp = MESSAGES.error_validate_range(); ingo@562: tmp = tmp.replace("$1", nf.format(from)); ingo@562: tmp = tmp.replace("$2", nf.format(min)); tom@6996: tmp = tmp.replace("$3", nf.format(max)); ingo@562: errors.add(tmp); ingo@562: from = min; ingo@562: } ingo@562: ingo@562: if (to < min || to > max) { tom@6996: String tmp = MESSAGES.error_validate_range(); ingo@562: tmp = tmp.replace("$1", nf.format(to)); tom@6996: tmp = tmp.replace("$2", nf.format(min)); tom@6996: tmp = tmp.replace("$3", nf.format(max)); ingo@562: errors.add(tmp); ingo@562: to = max; ingo@562: } ingo@562: ingo@562: if (!errors.isEmpty()) { ingo@562: distancePanel.setValues(from, to, step); ingo@562: } ingo@562: ingo@562: return errors; ingo@562: } ingo@562: ingo@562: ingo@41: /** ingo@41: * This method returns the selected data. ingo@41: * ingo@41: * @return the selected/inserted data. ingo@41: */ christian@4131: @Override ingo@41: public Data[] getData() { ingo@1277: List data = new ArrayList(); ingo@1277: christian@4131: // If we have entered a value and click right afterwards on the ingo@59: // 'next' button, the BlurEvent is not fired, and the values are not ingo@59: // saved. So, we gonna save those values explicitly. ingo@59: if (isLocationMode()) { ingo@59: Canvas member = container.getMember(0); ingo@59: if (member instanceof DoubleArrayPanel) { ingo@59: DoubleArrayPanel form = (DoubleArrayPanel) member; ingo@59: saveLocationValues(form); ingo@59: } ingo@1277: ingo@1277: Data dLocations = getDataLocations(); ingo@1277: DataItem dFrom = new DefaultDataItem("ld_from", "ld_from", ""); ingo@1277: DataItem dTo = new DefaultDataItem("ld_to", "ld_to", ""); ingo@1277: DataItem dStep = new DefaultDataItem("ld_step", "ld_step", ""); ingo@1277: ingo@1277: data.add(dLocations); ingo@1277: data.add(new DefaultData( ingo@1277: "ld_from", null, null, new DataItem[] { dFrom } )); ingo@1277: data.add(new DefaultData( ingo@1277: "ld_to", null, null, new DataItem[] { dTo } )); ingo@1277: data.add(new DefaultData( ingo@1277: "ld_step", null, null, new DataItem[] { dStep } )); ingo@59: } ingo@59: else { ingo@59: Canvas member = container.getMember(0); ingo@59: if (member instanceof DoubleRangePanel) { ingo@59: DoubleRangePanel form = (DoubleRangePanel) member; ingo@59: saveDistanceValues(form); ingo@59: } ingo@59: ingo@1277: Data dFrom = getDataFrom(); ingo@1277: Data dTo = getDataTo(); ingo@1277: Data dStep = getDataStep(); tom@8856: DataItem loc = new DefaultDataItem( tom@8856: "ld_locations", "ld_locations",""); ingo@520: ingo@1277: data.add(dFrom); ingo@1277: data.add(dTo); ingo@1277: data.add(dStep); ingo@1277: data.add(new DefaultData( ingo@1277: "ld_locations", null, null, new DataItem[] { loc } )); ingo@520: } ingo@520: ingo@1277: Data dMode = getDataMode(); ingo@1277: if (dMode != null) { ingo@1277: data.add(dMode); ingo@520: } ingo@520: sascha@3379: return data.toArray(new Data[data.size()]); ingo@516: } ingo@516: ingo@516: ingo@516: /** ingo@516: * Returns the Data object for the 'mode' attribute. ingo@516: * ingo@516: * @return the Data object for the 'mode' attribute. ingo@516: */ ingo@516: protected Data getDataMode() { ingo@516: String value = mode.getValueAsString(FIELD_MODE); ingo@516: DataItem item = new DefaultDataItem("ld_mode", "ld_mode", value); ingo@516: return new DefaultData("ld_mode", null, null, new DataItem[] { item }); ingo@516: } ingo@516: ingo@516: ingo@516: protected Data getDataLocations() { ingo@516: double[] locations = getLocationValues(); ingo@516: boolean first = true; ingo@516: ingo@520: if (locations == null) { ingo@520: return null; ingo@520: } ingo@520: ingo@516: StringBuilder sb = new StringBuilder(); ingo@516: ingo@516: for (double l: locations) { ingo@516: if (!first) { ingo@516: sb.append(" "); ingo@516: } ingo@516: ingo@516: sb.append(l); ingo@516: ingo@516: first = false; ingo@516: } ingo@516: ingo@516: DataItem item = new DefaultDataItem( ingo@516: "ld_locations", ingo@516: "ld_locations", ingo@516: sb.toString()); ingo@516: ingo@516: return new DefaultData( ingo@516: "ld_locations", ingo@516: null, ingo@516: null, ingo@516: new DataItem[] { item }); ingo@46: } ingo@41: ingo@46: ingo@46: /** ingo@46: * Returns the Data object for the 'from' attribute. ingo@46: * ingo@46: * @return the Data object for the 'from' attribute. ingo@46: */ ingo@46: protected Data getDataFrom() { ingo@516: String value = Double.valueOf(getFrom()).toString(); ingo@46: DataItem item = new DefaultDataItem("ld_from", "ld_from", value); ingo@46: return new DefaultData( ingo@51: "ld_from", null, null, new DataItem[] { item }); ingo@46: } ingo@46: ingo@46: ingo@46: /** ingo@46: * Returns the Data object for the 'to' attribute. ingo@46: * ingo@46: * @return the Data object for the 'to' attribute. ingo@46: */ ingo@46: protected Data getDataTo() { ingo@516: String value = Double.valueOf(getTo()).toString(); ingo@46: DataItem item = new DefaultDataItem("ld_to", "ld_to", value); ingo@46: return new DefaultData( ingo@51: "ld_to", null, null, new DataItem[] { item }); ingo@46: } ingo@46: ingo@46: ingo@46: /** ingo@46: * Returns the Data object for the 'step' attribute. ingo@46: * ingo@46: * @return the Data object for the 'step' attribute. ingo@46: */ ingo@46: protected Data getDataStep() { ingo@516: String value = Double.valueOf(getStep()).toString(); ingo@46: DataItem item = new DefaultDataItem("ld_step","ld_step", value); ingo@46: return new DefaultData( ingo@51: "ld_step", null, null, new DataItem[] { item }); ingo@46: } ingo@46: ingo@46: ingo@46: /** ingo@46: * Determines the current input mode. ingo@46: * ingo@46: * @return true, if 'location' is the current input mode, otherwise false. ingo@46: */ ingo@46: public boolean isLocationMode() { ingo@516: String inputMode = mode.getValueAsString(FIELD_MODE); ingo@46: ingo@516: return inputMode.equals(FIELD_VALUE_LOCATION) ? true : false; ingo@516: } ingo@516: ingo@516: ingo@516: /** ingo@516: * Activates the location panel. ingo@516: */ andre@8448: protected void enableLocationMode() { andre@8448: mode.setValue(FIELD_MODE, FIELD_VALUE_LOCATION); rrenkert@8262: container.hideMember(distancePanel); rrenkert@8262: container.showMember(locationPanel); andre@8449: setupDistanceInfoTable(locationsTable, false, false); andre@8449: setupDistanceInfoTable(distanceTable, true, true); andre@8449: inputTables.updateTab(0, locationsTable); andre@8449: inputTables.updateTab(1, distanceTable); ingo@516: } ingo@516: ingo@516: ingo@516: /** ingo@516: * Activates the distance panel. ingo@516: */ andre@8448: protected void enableDistanceMode() { andre@8448: mode.setValue(FIELD_MODE, FIELD_VALUE_DISTANCE); rrenkert@8262: container.hideMember(locationPanel); rrenkert@8262: container.showMember(distancePanel); andre@8449: setupDistanceInfoTable(locationsTable, true, false); andre@8449: setupDistanceInfoTable(distanceTable, false, true); andre@8449: inputTables.updateTab(0, locationsTable); andre@8449: inputTables.updateTab(1, distanceTable); ingo@41: } ingo@41: ingo@41: ingo@41: /** ingo@41: * This method switches the input mode between location and distance input. ingo@41: * ingo@41: * @param event The click event fired by a RadioButtonGroupItem. ingo@41: */ christian@4131: @Override ingo@41: public void onChange(ChangeEvent event) { ingo@41: String value = (String) event.getValue(); ingo@41: ingo@41: if (value == null) { ingo@41: return; ingo@41: } ingo@516: if (value.equals(FIELD_VALUE_LOCATION)) { andre@8448: enableLocationMode(); raimund@1534: filterDescription.clear(); raimund@1537: filterRange.clear(); raimund@1567: filterResultCount.setValue(""); raimund@1567: raimund@863: // Bring this tab to front. raimund@235: inputTables.selectTab(0); ingo@41: } ingo@43: else { andre@8448: enableDistanceMode(); raimund@1534: filterDescription.clear(); raimund@1537: filterRange.clear(); raimund@1567: filterResultCount.setValue(""); raimund@1567: raimund@863: // Bring the distanceTable tab to front. raimund@235: inputTables.selectTab(1); ingo@41: } ingo@41: } ingo@41: ingo@41: ingo@41: /** ingo@41: * This method is used to validate the inserted data in the form fields. ingo@41: * ingo@41: * @param event The BlurEvent that gives information about the FormItem that ingo@41: * has been modified and its value. ingo@41: */ christian@4131: @Override ingo@41: public void onBlur(BlurEvent event) { ingo@41: FormItem item = event.getItem(); ingo@41: String field = item.getFieldName(); ingo@41: ingo@41: if (field == null) { ingo@41: return; ingo@41: } ingo@41: ingo@43: if (field.equals(DoubleArrayPanel.FIELD_NAME)) { ingo@43: DoubleArrayPanel p = (DoubleArrayPanel) event.getForm(); ingo@41: ingo@59: saveLocationValue(p, item); ingo@41: } ingo@43: else { ingo@43: DoubleRangePanel p = (DoubleRangePanel) event.getForm(); ingo@41: ingo@59: saveDistanceValue(p, item); ingo@59: } ingo@59: } ingo@59: ingo@59: raimund@235: ingo@59: /** ingo@59: * Validates and stores all values entered in the location mode. ingo@59: * ingo@59: * @param p The DoubleArrayPanel. ingo@59: */ ingo@59: protected void saveLocationValues(DoubleArrayPanel p) { ingo@59: FormItem[] formItems = p.getFields(); ingo@59: ingo@59: for (FormItem item: formItems) { ingo@59: if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { ingo@59: saveLocationValue(p, item); ingo@43: } ingo@41: } ingo@41: } ingo@41: ingo@41: ingo@41: /** ingo@59: * Validates and stores all values entered in the distance mode. ingo@59: * ingo@59: * @param p The DoubleRangePanel. ingo@59: */ ingo@59: protected void saveDistanceValues(DoubleRangePanel p) { ingo@59: FormItem[] formItems = p.getFields(); ingo@59: ingo@59: for (FormItem item: formItems) { ingo@59: saveDistanceValue(p, item); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@59: /** ingo@59: * Validates and stores a value entered in the location mode. ingo@59: * ingo@59: * @param p The DoubleArrayPanel. ingo@59: * @param item The item that needs to be validated. ingo@59: */ ingo@59: protected void saveLocationValue(DoubleArrayPanel p, FormItem item) { ingo@59: if (p.validateForm(item)) { ingo@59: setLocationValues(p.getInputValues(item)); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@59: /** ingo@59: * Validates and stores value entered in the distance mode. ingo@59: * ingo@59: * @param p The DoubleRangePanel. ingo@59: * @param item The item that needs to be validated. ingo@59: */ ingo@59: protected void saveDistanceValue(DoubleRangePanel p, FormItem item) { ingo@59: if (p.validateForm(item)) { ingo@59: setFrom(p.getFrom()); ingo@59: setTo(p.getTo()); ingo@59: setStep(p.getStep()); ingo@59: } ingo@59: } ingo@59: ingo@59: ingo@59: /** ingo@41: * This method creates the panel that contains the checkboxes to switch ingo@41: * between the input mode 'location' and 'distance'. ingo@41: * ingo@41: * @return the checkbox panel. ingo@41: */ ingo@41: protected Canvas createRadioButtonPanel() { ingo@43: mode = new DynamicForm(); ingo@41: ingo@516: RadioGroupItem radio = new RadioGroupItem(FIELD_MODE); ingo@41: radio.setShowTitle(false); ingo@41: radio.setVertical(false); raimund@1394: radio.setWrap(false); ingo@41: tom@8856: LinkedHashMap values = tom@8856: new LinkedHashMap(); ingo@516: values.put(FIELD_VALUE_LOCATION, MESSAGES.location()); ingo@516: values.put(FIELD_VALUE_DISTANCE, MESSAGES.distance()); ingo@43: tom@8856: LinkedHashMap initial = tom@8856: new LinkedHashMap(); ingo@588: initial.put(FIELD_MODE, FIELD_VALUE_DISTANCE); ingo@45: ingo@43: radio.setValueMap(values); ingo@41: radio.addChangeHandler(this); ingo@41: ingo@43: mode.setFields(radio); ingo@45: mode.setValues(initial); ingo@41: ingo@43: return mode; ingo@41: } ingo@41: ingo@41: raimund@235: protected void createDistanceInputPanel() { raimund@235: Config config = Config.getInstance(); raimund@235: String url = config.getServerUrl(); raimund@235: String river = ""; raimund@235: raimund@235: ArtifactDescription adescr = artifact.getArtifactDescription(); raimund@235: DataList[] data = adescr.getOldData(); raimund@235: raimund@235: if (data != null && data.length > 0) { raimund@235: for (int i = 0; i < data.length; i++) { raimund@235: DataList dl = data[i]; raimund@3526: if (dl.getState().endsWith("river")) { raimund@235: for (int j = 0; j < dl.size(); j++) { raimund@235: Data d = dl.get(j); raimund@235: DataItem[] di = d.getItems(); raimund@235: if (di != null && di.length == 1) { raimund@235: river = d.getItems()[0].getStringValue(); raimund@235: } raimund@235: } raimund@235: } raimund@235: } raimund@235: } raimund@235: raimund@863: distanceTable.setDataSource(new DistanceInfoDataSource( raimund@863: url, river, "distances")); raimund@863: locationsTable.setDataSource(new DistanceInfoDataSource( raimund@863: url, river, "locations")); raimund@235: } raimund@235: ingo@43: protected double getFrom() { ingo@43: return from; ingo@41: } ingo@41: andre@8449: protected void setTo(String to) { andre@8449: try { andre@8449: double toValue = Double.parseDouble(to); andre@8449: setTo(toValue); andre@8449: } andre@8449: catch(NumberFormatException nfe) { andre@8449: // Is there anything to do? andre@8449: } andre@8449: } andre@8449: andre@8449: protected void setFrom(String from) { andre@8449: try { andre@8449: double fromValue = Double.parseDouble(from); andre@8449: setFrom(fromValue); andre@8449: } andre@8449: catch(NumberFormatException nfe) { andre@8449: // Is there anything to do? andre@8449: } andre@8449: } ingo@41: ingo@43: protected void setFrom(double from) { ingo@43: this.from = from; andre@8449: /* The doubling should be removed and this.from abolished */ andre@8449: distancePanel.setFrom(from); ingo@43: } ingo@41: ingo@41: ingo@43: protected double getTo() { ingo@43: return to; ingo@43: } ingo@41: ingo@41: ingo@43: protected void setTo(double to) { ingo@43: this.to = to; andre@8449: /* The doubling should be removed and this.to abolished */ andre@8449: distancePanel.setTo(to); ingo@43: } ingo@41: ingo@43: ingo@43: protected double getStep() { ingo@43: return step; ingo@43: } ingo@43: ingo@43: ingo@43: protected void setStep(double step) { ingo@43: this.step = step; ingo@43: } ingo@43: ingo@43: ingo@43: protected double[] getLocationValues() { ingo@43: return values; ingo@43: } ingo@43: andre@8449: protected void appendLocation(String loc) { andre@8449: double[] selected; andre@8449: if (getLocationValues() != null) { andre@8449: double[] val = getLocationValues(); andre@8449: selected = new double[val.length + 1]; andre@8449: for(int i = 0; i < val.length; i++){ andre@8449: selected[i] = val[i]; andre@8449: } andre@8449: try { andre@8449: selected[val.length] = Double.parseDouble(loc); andre@8449: } andre@8449: catch(NumberFormatException nfe) { andre@8449: // Is there anything to do here? andre@8449: } andre@8449: } andre@8449: else { andre@8449: selected = new double[1]; andre@8449: selected[0] = Double.parseDouble(loc); andre@8449: } andre@8449: setLocationValues(selected); andre@8449: } ingo@43: ingo@43: protected void setLocationValues(double[] values) { ingo@43: this.values = values; raimund@235: locationPanel.setValues(values); raimund@235: } raimund@235: raimund@235: ingo@516: protected void setLocationValues(String values) { ingo@516: String[] vs = values.split(" "); ingo@516: ingo@516: if (vs == null) { ingo@516: return; ingo@516: } ingo@516: ingo@516: double[] ds = new double[vs.length]; ingo@516: int idx = 0; ingo@516: ingo@516: for (String s: vs) { ingo@516: try { ingo@516: ds[idx++] = Double.valueOf(s); ingo@516: } ingo@516: catch (NumberFormatException nfe) { ingo@516: // do nothing ingo@516: } ingo@516: } ingo@516: ingo@516: setLocationValues(ds); ingo@516: } ingo@516: ingo@516: raimund@235: protected void setDistanceValues (double from, double to) { raimund@235: setFrom(from); raimund@235: setTo(to); raimund@235: distancePanel.setValues(from, to, getStep()); ingo@41: } ingo@41: } ingo@41: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :