+ /**
+ * Actually set the title <b>inside</b> the window. Will also call
+ * {@link BasicWindow#setTitle} with the computed parameters.
+ */
+ private void setTitle() {
+ String prefix = " " + Main.APPLICATION_TITLE + " (version "
+ + Main.APPLICATION_VERSION + ")";
+
+ String title = null;
+ int count = -1;
+
+ MainContent content = getContent();
+ if (content != null) {
+ title = content.getTitle();
+ count = content.getCount();
+ }
+
+ if (title == null)
+ title = "";
+
+ if (title.length() > 0) {
+ prefix = prefix + ": ";
+ title = StringUtils.sanitize(title, Main.isUnicode());
+ }
+
+ String countStr = "";
+ if (count > -1) {
+ countStr = "[" + count + "]";
+ }
+
+ int width = -1;
+ if (getSize() != null) {
+ width = getSize().getColumns();
+ }
+
+ if (width > 0) {
+ int padding = width - prefix.length() - title.length()
+ - countStr.length();
+ if (padding > 0) {
+ if (title.length() > 0)
+ title = StringUtils.padString(title, title.length()
+ + padding);
+ else
+ prefix = StringUtils.padString(prefix, prefix.length()
+ + padding);
+ }
+ }
+
+ String titleCache = prefix + title + count;
+ if (!titleCache.equals(this.titleCache)) {
+ super.setTitle(prefix);
+
+ Label lblPrefix = new Label(prefix);
+ UiColors.Element.TITLE_MAIN.themeLabel(lblPrefix);
+
+ Label lblTitle = null;
+ if (title.length() > 0) {
+ lblTitle = new Label(title);
+ UiColors.Element.TITLE_VARIABLE.themeLabel(lblTitle);
+ }
+
+ Label lblCount = null;
+ if (countStr != null) {
+ lblCount = new Label(countStr);
+ UiColors.Element.TITLE_COUNT.themeLabel(lblCount);
+ }
+
+ titlePanel.removeAllComponents();
+
+ titlePanel.addComponent(lblPrefix, BorderLayout.Location.LEFT);
+ if (lblTitle != null)
+ titlePanel.addComponent(lblTitle, BorderLayout.Location.CENTER);
+ if (lblCount != null)
+ titlePanel.addComponent(lblCount, BorderLayout.Location.RIGHT);
+ }
+ }
+
+ /**
+ * Return the current {@link MainContent} from the stack if any.
+ *
+ * @return the current {@link MainContent}
+ */
+ private MainContent getContent() {
+ if (contentStack.size() > 0) {
+ return contentStack.get(contentStack.size() - 1);
+ }