001: /*
002: * Copyright (C) 2005 Jeff Tassin
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.1 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 Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.images;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Dimension;
023:
024: import javax.swing.BorderFactory;
025: import javax.swing.ImageIcon;
026:
027: import com.jeta.forms.components.panel.FormPanel;
028: import com.jeta.forms.project.ProjectManager;
029: import com.jeta.forms.store.properties.IconProperty;
030: import com.jeta.open.gui.framework.JETAPanel;
031: import com.jeta.open.registry.JETARegistry;
032: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
033:
034: /**
035: * View for editing the properties of an image in a form.
036: *
037: * @author Jeff Tassin
038: */
039: public class ImagePropertiesView extends JETAPanel {
040: /**
041: * The form view
042: */
043: private FormPanel m_view;
044:
045: private ImageIcon m_image;
046:
047: /**
048: * ctor
049: */
050: public ImagePropertiesView(String formName, IconProperty iProp) {
051: m_view = new FormPanel(formName);
052: setLayout(new BorderLayout());
053: add(m_view, BorderLayout.CENTER);
054: setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
055: m_view.getButton(ImagePropertiesNames.ID_FILE_BUTTON)
056: .setPreferredSize(new Dimension(24, 10));
057: setIconProperty(iProp);
058: }
059:
060: /**
061: * @return the description
062: */
063: public String getDescription() {
064: return m_view
065: .getText(ImagePropertiesNames.ID_DESCRIPTION_FIELD);
066: }
067:
068: /**
069: * @return the image for this view
070: */
071: public ImageIcon getImage() {
072: return m_image;
073: }
074:
075: public IconProperty getIconProperty() {
076: String relpath = FormDesignerUtils.fastTrim(getRelativePath());
077: if (relpath.length() == 0)
078: return null;
079:
080: IconProperty iprop = new IconProperty();
081: iprop.setDescription(getDescription());
082: iprop.setRelativePath(getRelativePath());
083: return iprop;
084: }
085:
086: String getRelativePath() {
087: return m_view.getText(ImagePropertiesNames.ID_FILE_FIELD);
088: }
089:
090: public FormPanel getView() {
091: return m_view;
092: }
093:
094: void setDescription(String desc) {
095: m_view.setText(ImagePropertiesNames.ID_DESCRIPTION_FIELD, desc);
096: }
097:
098: /**
099: * Sets the image for this view
100: */
101: public void setImage(ImageIcon image) {
102: m_image = image;
103: }
104:
105: /**
106: * Initializes this view with the settings of the given icon property
107: */
108: public void setIconProperty(IconProperty iProp) {
109: if (iProp == null) {
110:
111: } else {
112: setDescription(iProp.getDescription());
113: setRelativePath(iProp.getRelativePath());
114: ProjectManager pmgr = (ProjectManager) JETARegistry
115: .lookup(ProjectManager.COMPONENT_ID);
116: setImage(pmgr.loadImage(iProp.getRelativePath()));
117: }
118: }
119:
120: void setRelativePath(String path) {
121: m_view.setText(ImagePropertiesNames.ID_FILE_FIELD, path);
122: }
123:
124: }
|