Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/MeasurementStationTree.java @ 4641:f3325079dacc
Improve the up and down arrows in the theme navigation panel
Don't stretch the arrow icons and fit to their actual size. Also put the up
buttons on the left and the down buttons on the right.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Tue, 04 Dec 2012 16:16:43 +0100 |
parents | bbd82bd8e541 |
children |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.DecoratorPanel; import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Tree; import com.google.gwt.user.client.ui.TreeItem; import com.smartgwt.client.widgets.layout.HLayout; import de.intevation.flys.client.client.FLYS; import de.intevation.flys.client.shared.model.MeasurementStation; import de.intevation.flys.client.shared.model.RiverInfo; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> */ public class MeasurementStationTree extends InfoTree { public MeasurementStationTree(FLYS flys) { this.flys = flys; tree = new Tree(); setWidget(tree); } /** * Resets the items of the tree. * If the list of gauges is empty or null the tree will be empty. */ @Override public void setRiverInfo(RiverInfo riverinfo) { tree.clear(); List<MeasurementStation> stations = riverinfo.getMeasurementStations(); if (stations != null && !stations.isEmpty()) { ArrayList<MeasurementStation> emptystations = new ArrayList<MeasurementStation>(); if (!riverinfo.isKmUp()) { for (MeasurementStation station : stations) { addStation(station, emptystations); } } else { for (int i = stations.size()-1; i >= 0; i--) { MeasurementStation station = stations.get(i); addStation(station, emptystations); } } // put empty stations to the end for (MeasurementStation station : emptystations) { addStation(station); } } } private void addStation(MeasurementStation station, List<MeasurementStation> empty) { if (station.getKmStart() != null && station.getKmEnd() != null) { addStation(station); } else { empty.add(station); } } private void addStation(MeasurementStation station) { MeasurementStationItem sitem = new MeasurementStationItem(flys, station); tree.addItem(sitem); } class MeasurementStationItem extends TreeItem { private MeasurementStation station; public MeasurementStationItem(FLYS flys, MeasurementStation station) { MeasurementStationHead head = new MeasurementStationHead(flys, station); MeasurementStationDecoratorPanel panel = new MeasurementStationDecoratorPanel(station); setWidget(head); addItem(panel); this.station = station; } public Double getStart() { return station.getKmStart(); } public Double getEnd() { return station.getKmEnd(); } public Integer getID() { return station.getID(); } } class MeasurementStationHead extends HLayout { public MeasurementStationHead(FLYS flys, MeasurementStation station) { setStyleName("infohead"); setAutoHeight(); setAutoWidth(); NumberFormat nf = NumberFormat.getDecimalFormat(); Label label = new Label(station.getName(), true); addMember(label); Double start; Double end; if (!station.isKmUp()) { start = station.getKmStart(); end = station.getKmEnd(); } else { start = station.getKmEnd(); end = station.getKmStart(); } String kmtext = ""; if (start != null) { kmtext += nf.format(start); kmtext += " - "; } if (end != null) { kmtext += nf.format(end); } if (start != null || end != null) { kmtext += " km"; } label = new Label(kmtext); addMember(label); Double dstation = station.getStation(); if (dstation != null) { String stext = nf.format(dstation); stext += " km"; label = new Label(stext); addMember(label); } Integer number = station.getID(); String url = number != null ? MSG.measurement_station_url() + number : MSG.measurement_station_url(); Anchor anchor = new Anchor(MSG.measurement_station_info_link(), url, "_blank"); addMember(anchor); } } class MeasurementStationDecoratorPanel extends DecoratorPanel { public MeasurementStationDecoratorPanel(MeasurementStation station) { setStyleName("infopanel"); Grid grid = new Grid(5, 2); String type = station.getMeasurementType(); if (type != null) { grid.setText(0, 0, MSG.measurement_station_type()); grid.setText(0, 1, type); } String riverside = station.getRiverSide(); if (riverside != null) { grid.setText(1, 0, MSG.riverside()); grid.setText(1, 1, riverside); } String gaugename = station.getGaugeName(); if (gaugename != null) { grid.setText(2, 0, MSG.measurement_station_gauge_name()); grid.setText(2, 1, gaugename); } DateTimeFormat df = DateTimeFormat.getFormat( PredefinedFormat.DATE_MEDIUM); Date starttime = station.getStartTime(); if (starttime != null) { grid.setText(3, 0, MSG.measurement_station_start_time()); grid.setText(3, 1, df.format(starttime)); } String moperator = station.getOperator(); if (moperator != null) { grid.setText(4, 0, MSG.measurement_station_operator()); grid.setText(4, 1, moperator); } setWidget(grid); } } @Override public void open() { } }