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.project;
020:
021: import java.awt.BorderLayout;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024:
025: import com.jeta.forms.components.panel.FormPanel;
026: import com.jeta.forms.gui.beans.factories.LabelBeanFactory;
027: import com.jeta.forms.gui.common.FormUtils;
028: import com.jeta.forms.project.ProjectManager;
029: import com.jeta.open.gui.framework.JETAPanel;
030: import com.jeta.open.registry.JETARegistry;
031: import com.jeta.swingbuilder.gui.components.FloatDocument;
032: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
033: import com.jeta.swingbuilder.interfaces.userprops.TSUserPropertiesUtils;
034:
035: /**
036: * Displays the view for editing the current project settings
037: *
038: * @author Jeff Tassin
039: */
040: public class UserPreferencesView extends JETAPanel {
041: /**
042: * The projectSettings.jfrm form
043: */
044: private FormPanel m_view;
045:
046: /**
047: * ctor
048: */
049: public UserPreferencesView() {
050: initialize();
051: }
052:
053: /**
054: * Initializes the view
055: */
056: public void initialize() {
057: setLayout(new BorderLayout());
058: m_view = new FormPanel(
059: "com/jeta/swingbuilder/gui/project/envPreferences2.jfrm");
060: add(m_view, BorderLayout.CENTER);
061: setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10,
062: 10, 10));
063:
064: getTextField(UserPreferencesNames.ID_COL_STD_SEP_SIZE)
065: .setDocument(new FloatDocument(false));
066: getTextField(UserPreferencesNames.ID_COL_LARGE_SEP_SIZE)
067: .setDocument(new FloatDocument(false));
068: getTextField(UserPreferencesNames.ID_ROW_STD_SEP_SIZE)
069: .setDocument(new FloatDocument(false));
070: getTextField(UserPreferencesNames.ID_ROW_LARGE_SEP_SIZE)
071: .setDocument(new FloatDocument(false));
072: getButton(UserPreferencesNames.ID_CLEAR_CACHE)
073: .addActionListener(new ActionListener() {
074: public void actionPerformed(ActionEvent evt) {
075: ProjectManager pmgr = (ProjectManager) JETARegistry
076: .lookup(ProjectManager.COMPONENT_ID);
077: if (pmgr != null)
078: pmgr.clearResourceCache();
079: }
080: });
081: loadModel();
082: }
083:
084: /**
085: * Loads the view with the current model settings
086: */
087: private void loadModel() {
088: setSeparatorSize(UserPreferencesNames.ID_COL_STD_SEP_SIZE,
089: UserPreferencesNames.ID_COL_STD_SEP_UNITS);
090: setSeparatorSize(UserPreferencesNames.ID_COL_LARGE_SEP_SIZE,
091: UserPreferencesNames.ID_COL_LARGE_SEP_UNITS);
092: setSeparatorSize(UserPreferencesNames.ID_ROW_STD_SEP_SIZE,
093: UserPreferencesNames.ID_ROW_STD_SEP_UNITS);
094: setSeparatorSize(UserPreferencesNames.ID_ROW_LARGE_SEP_SIZE,
095: UserPreferencesNames.ID_ROW_LARGE_SEP_UNITS);
096:
097: setSelected(UserPreferencesNames.ID_CACHE_IMAGES,
098: TSUserPropertiesUtils.getBoolean(
099: UserPreferencesNames.ID_CACHE_IMAGES, true));
100: setSelected(
101: UserPreferencesNames.ID_OPEN_LAST_PROJECT,
102: TSUserPropertiesUtils
103: .getBoolean(
104: UserPreferencesNames.ID_OPEN_LAST_PROJECT,
105: true));
106: setSelected(UserPreferencesNames.ID_STORE_AS_XML,
107: TSUserPropertiesUtils.getBoolean(
108: UserPreferencesNames.ID_STORE_AS_XML, false));
109:
110: setSelected(UserPreferencesNames.ID_SHOW_RESIZE_HANDLES,
111: TSUserPropertiesUtils.getBoolean(
112: UserPreferencesNames.ID_SHOW_RESIZE_HANDLES,
113: true));
114:
115: javax.swing.JLabel label = new javax.swing.JLabel();
116: String halign = TSUserPropertiesUtils.getString(
117: LabelBeanFactory.ID_DEFAULT_HORIZONTAL_ALIGNMENT,
118: LabelBeanFactory.getHorizontalAlignmentString(label
119: .getHorizontalAlignment()));
120:
121: setSelectedItem(UserPreferencesNames.ID_LABEL_H_ALIGN, halign);
122: setSelectedItem(UserPreferencesNames.ID_DEFAULT_RESIZE_UNITS,
123: TSUserPropertiesUtils.getString(
124: UserPreferencesNames.ID_DEFAULT_RESIZE_UNITS,
125: "PX"));
126: }
127:
128: /**
129: * Saves the separator settings to the model.
130: */
131: private void saveSeparatorSize(String sz_field, String units_field) {
132: TSUserPropertiesUtils.setString(units_field,
133: (String) getSelectedItem(units_field));
134: TSUserPropertiesUtils.setString(sz_field, FormDesignerUtils
135: .fastTrim(getText(sz_field)));
136: }
137:
138: private void setSeparatorSize(String sz_field, String units_field) {
139: String units = TSUserPropertiesUtils.getString(units_field,
140: "DLU");
141: String defsize = FormUtils.getReasonableSize(units);
142: if ("DLU".equalsIgnoreCase(units)) {
143: if (UserPreferencesNames.ID_COL_STD_SEP_SIZE
144: .equals(sz_field))
145: defsize = "4";
146: else if (UserPreferencesNames.ID_COL_LARGE_SEP_SIZE
147: .equals(sz_field))
148: defsize = "8";
149: else if (UserPreferencesNames.ID_ROW_STD_SEP_SIZE
150: .equals(sz_field))
151: defsize = "2";
152: else if (UserPreferencesNames.ID_ROW_LARGE_SEP_SIZE
153: .equals(sz_field))
154: defsize = "4";
155:
156: }
157: String sz = TSUserPropertiesUtils.getString(sz_field, defsize);
158:
159: setSelectedItem(units_field, units);
160: setText(sz_field, sz);
161: }
162:
163: /**
164: * Saves the settings in the view to the model
165: */
166: public void saveToModel() {
167: saveSeparatorSize(UserPreferencesNames.ID_COL_STD_SEP_SIZE,
168: UserPreferencesNames.ID_COL_STD_SEP_UNITS);
169: saveSeparatorSize(UserPreferencesNames.ID_COL_LARGE_SEP_SIZE,
170: UserPreferencesNames.ID_COL_LARGE_SEP_UNITS);
171: saveSeparatorSize(UserPreferencesNames.ID_ROW_STD_SEP_SIZE,
172: UserPreferencesNames.ID_ROW_STD_SEP_UNITS);
173: saveSeparatorSize(UserPreferencesNames.ID_ROW_LARGE_SEP_SIZE,
174: UserPreferencesNames.ID_ROW_LARGE_SEP_UNITS);
175: TSUserPropertiesUtils.setBoolean(
176: UserPreferencesNames.ID_CACHE_IMAGES,
177: isSelected(UserPreferencesNames.ID_CACHE_IMAGES));
178: TSUserPropertiesUtils.setBoolean(
179: UserPreferencesNames.ID_OPEN_LAST_PROJECT,
180: isSelected(UserPreferencesNames.ID_OPEN_LAST_PROJECT));
181: TSUserPropertiesUtils.setBoolean(
182: UserPreferencesNames.ID_STORE_AS_XML,
183: isSelected(UserPreferencesNames.ID_STORE_AS_XML));
184: TSUserPropertiesUtils
185: .setBoolean(
186: UserPreferencesNames.ID_SHOW_RESIZE_HANDLES,
187: isSelected(UserPreferencesNames.ID_SHOW_RESIZE_HANDLES));
188:
189: TSUserPropertiesUtils
190: .setString(
191: LabelBeanFactory.ID_DEFAULT_HORIZONTAL_ALIGNMENT,
192: (String) m_view
193: .getSelectedItem(UserPreferencesNames.ID_LABEL_H_ALIGN));
194: TSUserPropertiesUtils
195: .setString(
196: UserPreferencesNames.ID_DEFAULT_RESIZE_UNITS,
197: (String) getSelectedItem(UserPreferencesNames.ID_DEFAULT_RESIZE_UNITS));
198:
199: }
200: }
|