Crossfire JXClient, Trunk  R20561
GaugeUpdater.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.gauge;
23 
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
27 
32 public abstract class GaugeUpdater {
33 
37  @NotNull
39 
43  @Nullable
45 
49  private final boolean hideIfEmpty;
50 
56  protected GaugeUpdater(@NotNull final ExperienceTable experienceTable, final boolean hideIfEmpty) {
57  this.experienceTable = experienceTable;
58  this.hideIfEmpty = hideIfEmpty;
59  }
60 
64  public abstract void dispose();
65 
70  @SuppressWarnings("NullableProblems")
71  public void setGauge(@NotNull final GUIGaugeListener gauge) {
72  this.gauge = gauge;
73  // hide the gauge initially, so if it's never updated it doesn't appear
74  if (hideIfEmpty) {
75  gauge.setHidden(true);
76  }
77  }
78 
85  protected void setValues(final int curValue, final int minValue, final int maxValue) {
86  if (gauge != null) {
87  final String curValueString = Integer.toString(curValue);
88  final String tooltipText = minValue == 0 ? curValue+"/"+maxValue : curValueString;
89  assert gauge != null;
90  gauge.setValues(curValue, minValue, maxValue, curValueString, tooltipText);
91  if (hideIfEmpty) {
92  assert gauge != null;
93  gauge.setHidden(curValue == 0 && minValue == 0 && maxValue == 0);
94  }
95  }
96  }
97 
106  protected void setValues(final int curValue, final int minValue, final int maxValue, @NotNull final String labelText, @NotNull final String tooltipText) {
107  if (gauge != null) {
108  gauge.setValues(curValue, minValue, maxValue, labelText, tooltipText);
109  }
110  }
111 
118  protected int getPercentsToNextLevel(final int level, final long experience) {
119  return experienceTable.getPercentsToNextLevel(level, experience);
120  }
121 
128  protected long getExperienceToNextLevel(final int level, final long experience) {
129  return experienceTable.getExperienceToNextLevel(level, experience);
130  }
131 
132 }
Interface which is implemented by all listener classes.
int getPercentsToNextLevel(final int level, final long experience)
Returns the experience fraction of the current level.
long getExperienceToNextLevel(final int currentLevel, final long currentExp)
Returns the experience needed to reach the next level.
int getPercentsToNextLevel(final int currentLevel, final long currentExp)
Returns the experience fraction of the current level in percents.
GaugeUpdater(@NotNull final ExperienceTable experienceTable, final boolean hideIfEmpty)
Creates a new instance.
void setValues(final int curValue, final int minValue, final int maxValue, @NotNull final String labelText, @NotNull final String tooltipText)
Updates the gauge values.
GUIGaugeListener gauge
Set the gauge to update.
final ExperienceTable experienceTable
The experience table to query.
Updates the displayed values in a GUIGauge.
void setGauge(@NotNull final GUIGaugeListener gauge)
Sets the gauge to update.
long getExperienceToNextLevel(final int level, final long experience)
Returns the experience needed to reach next level.
void setValues(final int curValue, final int minValue, final int maxValue)
Updates the gauge values.
void setValues(int curValue, int minValue, int maxValue, @NotNull String labelText, @NotNull String tooltipText)
Sets the values to display.
final boolean hideIfEmpty
If true then the gauge should be hidden if all values are 0.
void setHidden(boolean hidden)
Specify whether this item should hide itself, independent of the "visibility" state.
abstract void dispose()
Frees allocated resources.