001: /*
002: * WindowTitleBuilder.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui;
013:
014: import java.io.File;
015: import workbench.db.ConnectionProfile;
016: import workbench.resource.ResourceMgr;
017: import workbench.resource.Settings;
018: import workbench.util.StringUtil;
019:
020: /**
021: *
022: * @author support@sql-workbench.net
023: */
024: public class WindowTitleBuilder {
025:
026: public WindowTitleBuilder() {
027: }
028:
029: public String getWindowTitle(ConnectionProfile profile,
030: String workspaceFile, String editorFile) {
031: final StringBuilder title = new StringBuilder(50);
032:
033: boolean showProductNameAtEnd = Settings.getInstance()
034: .getShowProductNameAtEnd();
035: boolean showProfileGroup = Settings.getInstance()
036: .getShowProfileGroupInWindowTitle();
037: boolean showWorkspace = Settings.getInstance()
038: .getShowWorkspaceInWindowTitle();
039: String enclose = Settings.getInstance().getTitleGroupBracket();
040: String sep = Settings.getInstance().getTitleGroupSeparator();
041:
042: if (!showProductNameAtEnd) {
043: title.append(ResourceMgr.TXT_PRODUCT_NAME);
044: title.append(" - ");
045: }
046:
047: if (profile == null) {
048: title.append(ResourceMgr.getString("TxtNotConnected"));
049: } else {
050: if (showProfileGroup) {
051: char open = getOpeningBracket(enclose);
052: char close = getClosingBracket(enclose);
053:
054: if (open != 0 && close != 0) {
055: title.append(open);
056: }
057: title.append(profile.getGroup());
058: if (open != 0 && close != 0) {
059: title.append(close);
060: }
061: if (sep != null)
062: title.append(sep);
063: }
064: title.append(profile.getName());
065: }
066:
067: if (workspaceFile != null && showWorkspace) {
068: File f = new File(workspaceFile);
069: String baseName = f.getName();
070: title.append(" - ");
071: title.append(baseName);
072: title.append(" ");
073: }
074:
075: int showTitle = Settings.getInstance()
076: .getShowFilenameInWindowTitle();
077: if (editorFile != null
078: && showTitle != Settings.SHOW_NO_FILENAME) {
079:
080: title.append(" - ");
081: if (showTitle == Settings.SHOW_FULL_PATH) {
082: title.append(editorFile);
083: } else {
084: File f = new File(editorFile);
085: title.append(f.getName());
086: }
087: }
088:
089: if (showProductNameAtEnd) {
090: title.append(" - ");
091: title.append(ResourceMgr.TXT_PRODUCT_NAME);
092: }
093:
094: return title.toString();
095: }
096:
097: private char getOpeningBracket(String settingsValue) {
098: if (StringUtil.isEmptyString(settingsValue))
099: return 0;
100: return settingsValue.charAt(0);
101: }
102:
103: private char getClosingBracket(String settingsValue) {
104: if (StringUtil.isEmptyString(settingsValue))
105: return 0;
106: char open = getOpeningBracket(settingsValue);
107: if (open == '{')
108: return '}';
109: if (open == '[')
110: return ']';
111: if (open == '(')
112: return ')';
113: if (open == '<')
114: return '>';
115: return 0;
116:
117: }
118:
119: }
|