001: /* SwingML
002: * Copyright (C) 2002 SwingML Team
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: *
019: * Authors:
020: * Ezequiel Cuellar <ecuellar@crosslogic.com>
021: * Bram Stieperaere <bramez@users.sourceforge.net>
022: */
023: package org.swingml.model;
024:
025: import java.net.*;
026:
027: import javax.swing.*;
028:
029: import org.swingml.*;
030: import org.swingml.system.*;
031:
032: public class JTreeModel extends SwingMLModel {
033:
034: private Icon closedFolderIcon;
035:
036: private boolean dndEnabled = false;
037: private Icon leafIcon;
038: private Icon openFolderIcon;
039: private String value = null;
040:
041: public JTreeModel() {
042: super ();
043: }
044:
045: public Icon getClosedFolderIcon() {
046: return closedFolderIcon;
047: }
048:
049: public Icon getLeafIcon() {
050: return leafIcon;
051: }
052:
053: public Icon getOpenFolderIcon() {
054: return openFolderIcon;
055: }
056:
057: public String getValue() {
058: return this .value;
059: }
060:
061: public boolean isDndEnabled() {
062: return this .dndEnabled;
063: }
064:
065: public void setClosedFolderIcon(Icon icon) {
066: this .closedFolderIcon = icon;
067: }
068:
069: public void setClosedFolderIcon(String url) {
070: try {
071: setClosedFolderIcon(new ImageIcon(new URL(url)));
072: } catch (MalformedURLException x) {
073: /* ignore and use default */
074: SwingMLLogger.getInstance().log(
075: "Unable to use URL: '" + url + "'.");
076: SwingMLLogger.getInstance().log(x);
077: }
078: }
079:
080: public void setDndEnabled(boolean aDragEnabled) {
081: this .dndEnabled = aDragEnabled;
082: }
083:
084: public void setLeafIcon(Icon icon) {
085: this .leafIcon = icon;
086: }
087:
088: public void setLeafIcon(String url) {
089: try {
090: setLeafIcon(new ImageIcon(new URL(url)));
091: } catch (MalformedURLException x) {
092: /* ignore and use default */
093: SwingMLLogger.getInstance().log(
094: "Unable to use URL: '" + url + "'.");
095: SwingMLLogger.getInstance().log(x);
096: }
097: }
098:
099: public void setOpenFolderIcon(Icon icon) {
100: this .openFolderIcon = icon;
101: }
102:
103: public void setOpenFolderIcon(String url) {
104: try {
105: setOpenFolderIcon(new ImageIcon(new URL(url)));
106: } catch (MalformedURLException x) {
107: /* ignore and use default */
108: SwingMLLogger.getInstance().log(
109: "Unable to use URL: '" + url + "'.");
110: SwingMLLogger.getInstance().log(x);
111: }
112: }
113:
114: public void setValue(String aValue) {
115: this .value = aValue;
116: }
117:
118: public String toString() {
119: String theText = super .getText();
120: if (theText == null) {
121: theText = "";
122: }
123: return theText;
124: }
125:
126: public void validate() {
127: if (super .getParent().getLayout() != null
128: && super .getParent().getLayout().equalsIgnoreCase(
129: Constants.BORDERLAYOUT)) {
130: if (super .getOrientation() == null) {
131: SwingMLLogger
132: .getInstance()
133: .log(
134: "Syntax error: The parameter ORIENTATION in the element "
135: + super .getName()
136: + " is required since its parent's LAYOUT is BorderLayout. Add the parameter ORIENTATION to the element "
137: + super .getName()
138: + " or change its parent's LAYOUT to other than BorderLayout.");
139: }
140: }
141: if (super .getParent().getLayout() != null
142: && !super .getParent().getLayout().equalsIgnoreCase(
143: Constants.BORDERLAYOUT)) {
144: if (super .getOrientation() != null) {
145: SwingMLLogger
146: .getInstance()
147: .log(
148: "Syntax error: The parameter ORIENTATION in the element "
149: + super .getName()
150: + " should be used only when its parent's LAYOUT is BorderLayout. Change its parent's LAYOUT to BorderLayout or delete the parameter ORIENTATION from the element "
151: + super .getName() + ".");
152: }
153: }
154: }
155: }
|