final TAction action) {
// Set parent and window
- super(parent, false, x, y, StringUtils.width(text), 1);
+ super(parent, false, x, y, 0, 1);
- mnemonic = new MnemonicString(text);
+ setLabel(text);
this.colorKey = colorKey;
this.useWindowBackground = useWindowBackground;
this.action = action;
// TWidget ----------------------------------------------------------------
// ------------------------------------------------------------------------
+ /**
+ * Override TWidget's width: we can only set width at construction time.
+ *
+ * @param width new widget width (ignored)
+ */
+ @Override
+ public void setWidth(final int width) {
+ // Do nothing
+ }
+
/**
* Override TWidget's height: we can only set height at construction
* time.
*/
public void setLabel(final String label) {
mnemonic = new MnemonicString(label);
+ super.setWidth(StringUtils.width(mnemonic.getRawLabel()));
}
/**
import jexer.bits.CellAttributes;
import jexer.bits.GraphicsChars;
+import jexer.bits.StringUtils;
/**
* TProgressBar implements a simple progress bar.
*/
private int value = 0;
+ /**
+ * The left border character.
+ */
+ private int leftBorderChar = GraphicsChars.CP437[0xC3];
+
+ /**
+ * The filled-in part of the bar.
+ */
+ private int completedChar = GraphicsChars.BOX;
+
+ /**
+ * The remaining to be filled in part of the bar.
+ */
+ private int remainingChar = GraphicsChars.SINGLE_BAR;
+
+ /**
+ * The right border character.
+ */
+ private int rightBorderChar = GraphicsChars.CP437[0xB4];
+
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
// ------------------------------------------------------------------------
int progressInt = (int)(progress * 100);
int progressUnit = 100 / (getWidth() - 2);
- putCharXY(0, 0, GraphicsChars.CP437[0xC3], incompleteColor);
- for (int i = 0; i < getWidth() - 2; i++) {
+ putCharXY(0, 0, leftBorderChar, incompleteColor);
+ for (int i = StringUtils.width(leftBorderChar); i < getWidth() - 2;) {
float iProgress = (float)i / (getWidth() - 2);
int iProgressInt = (int)(iProgress * 100);
if (iProgressInt <= progressInt - progressUnit) {
- putCharXY(i + 1, 0, GraphicsChars.BOX, completeColor);
+ putCharXY(i, 0, completedChar, completeColor);
+ i += StringUtils.width(completedChar);
} else {
- putCharXY(i + 1, 0, GraphicsChars.SINGLE_BAR, incompleteColor);
+ putCharXY(i, 0, remainingChar, incompleteColor);
+ i += StringUtils.width(remainingChar);
}
}
if (value >= maxValue) {
- putCharXY(getWidth() - 2, 0, GraphicsChars.BOX, completeColor);
+ putCharXY(getWidth() - StringUtils.width(leftBorderChar) -
+ StringUtils.width(rightBorderChar), 0, completedChar,
+ completeColor);
} else {
- putCharXY(getWidth() - 2, 0, GraphicsChars.SINGLE_BAR,
+ putCharXY(getWidth() - StringUtils.width(leftBorderChar) -
+ StringUtils.width(rightBorderChar), 0, remainingChar,
incompleteColor);
}
- putCharXY(getWidth() - 1, 0, GraphicsChars.CP437[0xB4],
- incompleteColor);
+ putCharXY(getWidth() - StringUtils.width(rightBorderChar), 0,
+ rightBorderChar, incompleteColor);
}
// ------------------------------------------------------------------------
this.value = value;
}
+ /**
+ * Set the left border character.
+ *
+ * @param ch the char to use
+ */
+ public void setLeftBorderChar(final int ch) {
+ leftBorderChar = ch;
+ }
+
+ /**
+ * Get the left border character.
+ *
+ * @return the char
+ */
+ public int getLeftBorderChar() {
+ return leftBorderChar;
+ }
+
+ /**
+ * Set the filled-in part of the bar.
+ *
+ * @param ch the char to use
+ */
+ public void setCompletedChar(final int ch) {
+ completedChar = ch;
+ }
+
+ /**
+ * Get the filled-in part of the bar.
+ *
+ * @return the char
+ */
+ public int getCompletedChar() {
+ return completedChar;
+ }
+
+ /**
+ * Set the remaining to be filled in part of the bar.
+ *
+ * @param ch the char to use
+ */
+ public void setRemainingChar(final int ch) {
+ remainingChar = ch;
+ }
+
+ /**
+ * Get the remaining to be filled in part of the bar.
+ *
+ * @return the char
+ */
+ public int getRemainingChar() {
+ return remainingChar;
+ }
+
+ /**
+ * Set the right border character.
+ *
+ * @param ch the char to use
+ */
+ public void setRightBorderChar(final int ch) {
+ rightBorderChar = ch;
+ }
+
+ /**
+ * Get the right border character.
+ *
+ * @return the char
+ */
+ public int getRightBorderChar() {
+ return rightBorderChar;
+ }
+
}
/**
* Timer that increments a number.
*/
- private TTimer timer;
+ private TTimer timer1;
+
+ /**
+ * Timer that increments a number.
+ */
+ private TTimer timer2;
/**
* Timer label is updated with timer ticks.
* Timer increment used by the timer loop. Has to be at class scope so
* that it can be accessed by the anonymous TAction class.
*/
- int timerI = 0;
+ int timer1I = 0;
+
+ /**
+ * Timer increment used by the timer loop. Has to be at class scope so
+ * that it can be accessed by the anonymous TAction class.
+ */
+ int timer2I = 0;
/**
* Progress bar used by the timer loop. Has to be at class scope so that
* it can be accessed by the anonymous TAction class.
*/
- TProgressBar progressBar;
+ TProgressBar progressBar1;
+
+ /**
+ * Progress bar used by the timer loop. Has to be at class scope so that
+ * it can be accessed by the anonymous TAction class.
+ */
+ TProgressBar progressBar2;
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
);
row = 15;
- progressBar = addProgressBar(48, row, 12, 0);
+ progressBar1 = addProgressBar(48, row, 12, 0);
row++;
timerLabel = addLabel(i18n.getString("timerLabel"), 48, row);
- timer = getApplication().addTimer(250, true,
+ timer1 = getApplication().addTimer(250, true,
new TAction() {
public void DO() {
timerLabel.setLabel(String.format(i18n.
- getString("timerText"), timerI));
+ getString("timerText"), timer1I));
timerLabel.setWidth(timerLabel.getLabel().length());
- if (timerI < 100) {
- timerI++;
+ if (timer1I < 100) {
+ timer1I++;
+ } else {
+ timer1.setRecurring(false);
+ }
+ progressBar1.setValue(timer1I);
+ }
+ }
+ );
+
+ row += 2;
+ progressBar2 = addProgressBar(48, row, 12, 0);
+ progressBar2.setLeftBorderChar('\u255e');
+ progressBar2.setRightBorderChar('\u2561');
+ progressBar2.setCompletedChar('\u2592');
+ progressBar2.setRemainingChar('\u2550');
+ row++;
+ timer2 = getApplication().addTimer(125, true,
+ new TAction() {
+
+ public void DO() {
+ if (timer2I < 100) {
+ timer2I++;
} else {
- timer.setRecurring(false);
+ timer2.setRecurring(false);
}
- progressBar.setValue(timerI);
+ progressBar2.setValue(timer2I);
}
}
);
*/
@Override
public void onClose() {
- getApplication().removeTimer(timer);
+ getApplication().removeTimer(timer1);
+ getApplication().removeTimer(timer2);
}
/**