001: /*
002: * LnFDefinition.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.lnf;
013:
014: import workbench.util.StringUtil;
015:
016: /**
017: * The definition of a pluggable look and feel. It stores the classname
018: * of the Look & Feel together with the library from which the class
019: * should be loaded
020: *
021: * @author support@sql-workbench.net
022: */
023: public class LnFDefinition implements Comparable<LnFDefinition> {
024: private String name;
025: private String className;
026: private String library;
027: private boolean isBuiltIn;
028: public static final String LNF_PATH_SEPARATOR = "$|$";
029:
030: public LnFDefinition(String desc) {
031: this (desc, null, null);
032: this .isBuiltIn = false;
033: }
034:
035: public LnFDefinition(String desc, String clazz) {
036: this (desc, clazz, null);
037: this .isBuiltIn = true;
038: }
039:
040: public LnFDefinition(String desc, String clazz, String libs) {
041: this .name = desc;
042: this .className = (clazz == null ? clazz : clazz.trim());
043: this .library = libs;
044: this .isBuiltIn = (libs == null);
045: }
046:
047: public boolean isBuiltInLnF() {
048: return this .isBuiltIn;
049: }
050:
051: public boolean isComplete() {
052: if (this .isBuiltIn)
053: return true;
054: return !StringUtil.isEmptyString(this .name)
055: && !StringUtil.isEmptyString(this .className)
056: && !StringUtil.isEmptyString(this .library);
057: }
058:
059: public String toString() {
060: return getName();
061: }
062:
063: public String getName() {
064: return name;
065: }
066:
067: public String getClassName() {
068: return className;
069: }
070:
071: public void setName(String name) {
072: this .name = name;
073: }
074:
075: public void setClassName(String className) {
076: this .className = className;
077: }
078:
079: public String getLibrary() {
080: if (this .isBuiltIn)
081: return "rt.jar";
082: return library;
083: }
084:
085: public void setLibrary(String library) {
086: this .library = library;
087: }
088:
089: public LnFDefinition createCopy() {
090: return new LnFDefinition(getName(), getClassName(),
091: getLibrary());
092: }
093:
094: public int compareTo(LnFDefinition o) {
095: String cls = o.getClassName();
096: return this .className.compareTo(cls);
097: }
098:
099: @Override
100: public boolean equals(Object o) {
101: if (o instanceof LnFDefinition) {
102: LnFDefinition other = (LnFDefinition) o;
103: return this .className.equals(other.className);
104: }
105: if (o instanceof String) {
106: return this .className.equals((String) o);
107: }
108: return false;
109: }
110:
111: @Override
112: public int hashCode() {
113: return this.className.hashCode();
114: }
115:
116: }
|