Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java @ 528:39d9291513cc
Connected the actions in the navigation panel with the theme list in the ChartThemePanel - themes can be moved now.
flys-client/trunk@2009 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 26 May 2011 13:53:36 +0000 |
parents | 96e60e0a4345 |
children | f6fbfdc813f0 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java Wed May 25 16:23:16 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/ThemeList.java Thu May 26 13:53:36 2011 +0000 @@ -63,5 +63,38 @@ themes.add(theme); } } + + + /** + * Modifies the order of themes in this list and the position of the + * <i>theme</i> itself. + * + * @param theme The theme which position has to be modified. + * @param newPos The new position. + */ + public void setThemePosition(Theme theme, int newPos) { + int count = getThemeCount(); + int oldPos = theme.getPosition(); + + if (newPos == oldPos || newPos > count || newPos < 1) { + return; + } + + boolean moveUp = newPos < oldPos; + + for (Theme aTheme: themes) { + int tmpPos = aTheme.getPosition(); + + if (theme.equals(aTheme)) { + theme.setPosition(newPos); + } + else if (tmpPos >= newPos && tmpPos < oldPos && moveUp) { + aTheme.setPosition(tmpPos+1); + } + else if (tmpPos <= newPos && tmpPos > oldPos && !moveUp) { + aTheme.setPosition(tmpPos-1); + } + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :