001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.vmd.midpnb.screen.display;
042:
043: import java.awt.Color;
044: import java.util.ArrayList;
045: import java.util.Arrays;
046: import java.util.Collection;
047: import javax.swing.JComponent;
048: import javax.swing.JPanel;
049: import javax.swing.JTextField;
050: import org.netbeans.modules.vmd.api.model.DesignComponent;
051: import org.netbeans.modules.vmd.api.model.PropertyValue;
052: import org.netbeans.modules.vmd.api.screen.display.ScreenDeviceInfo;
053: import org.netbeans.modules.vmd.api.screen.display.ScreenPropertyDescriptor;
054: import org.netbeans.modules.vmd.midp.screen.display.DisplayableDisplayPresenter;
055: import org.netbeans.modules.vmd.midp.screen.display.property.ScreenStringPropertyEditor;
056: import org.netbeans.modules.vmd.midp.screen.display.property.ScreenTextAreaPropertyEditor;
057: import org.netbeans.modules.vmd.midpnb.components.displayables.SMSComposerCD;
058: import org.openide.util.NbBundle;
059:
060: /**
061: *
062: * @author Karol Harezlak
063: */
064: public class SMSComposerDisplayPresenter extends
065: DisplayableDisplayPresenter {
066:
067: private JComponent view;
068: private SMSView smsView;
069: private static final String USER_CODE = NbBundle.getMessage(
070: LoginScreenDisplayPresenter.class, "LBL_UserCode"); //NOI18N
071: private static final String NULL_TEXT = NbBundle.getMessage(
072: LoginScreenDisplayPresenter.class, "LBL_NULL"); //NOI18N
073:
074: @Override
075: public void reload(ScreenDeviceInfo deviceInfo) {
076: super .reload(deviceInfo);
077: if (smsView != null) {
078: smsView.updateView();
079: }
080: }
081:
082: @Override
083: public JComponent getView() {
084: if (view == null) {
085: view = super .getView();
086: smsView = new SMSView();
087: super .getView().add(smsView);
088: }
089: return view;
090: }
091:
092: @Override
093: public Collection<ScreenPropertyDescriptor> getPropertyDescriptors() {
094: Collection<ScreenPropertyDescriptor> desciptors = new ArrayList<ScreenPropertyDescriptor>(
095: super .getPropertyDescriptors());
096: desciptors.addAll(Arrays.asList(new ScreenPropertyDescriptor(
097: getComponent(), smsView.messageLabel,
098: new ScreenStringPropertyEditor(
099: SMSComposerCD.PROP_MESSAGE_LABEL,
100: JTextField.CENTER)),
101: new ScreenPropertyDescriptor(getComponent(),
102: smsView.messageTextrArea,
103: new ScreenTextAreaPropertyEditor(
104: SMSComposerCD.PROP_MESSAGE)),
105: new ScreenPropertyDescriptor(getComponent(),
106: smsView.phoneNumberLabel,
107: new ScreenStringPropertyEditor(
108: SMSComposerCD.PROP_PHONE_NUMEBR_LABEL,
109: JTextField.CENTER)),
110: new ScreenPropertyDescriptor(getComponent(),
111: smsView.phoneNumberTextField,
112: new ScreenStringPropertyEditor(
113: SMSComposerCD.PROP_PHONE_NUMBER,
114: JTextField.CENTER))));
115: return desciptors;
116: }
117:
118: private class SMSView extends JPanel {
119:
120: private javax.swing.JTextArea messageTextrArea;
121: private javax.swing.JLabel messageLabel;
122: private javax.swing.JScrollPane messageScrollPane;
123: private javax.swing.JTextField phoneNumberTextField;
124: private javax.swing.JLabel phoneNumberLabel;
125:
126: SMSView() {
127: initComponents();
128: }
129:
130: private void initComponents() {
131: java.awt.GridBagConstraints gridBagConstraints;
132: phoneNumberLabel = new javax.swing.JLabel();
133: messageLabel = new javax.swing.JLabel();
134: phoneNumberTextField = new javax.swing.JTextField();
135: messageScrollPane = new javax.swing.JScrollPane();
136: messageTextrArea = new javax.swing.JTextArea();
137:
138: setLayout(new java.awt.GridBagLayout());
139:
140: gridBagConstraints = new java.awt.GridBagConstraints();
141: gridBagConstraints.gridx = 0;
142: gridBagConstraints.gridy = 0;
143: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
144: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
145: gridBagConstraints.insets = new java.awt.Insets(50, 20, 0,
146: 0);
147: add(phoneNumberLabel, gridBagConstraints);
148:
149: gridBagConstraints = new java.awt.GridBagConstraints();
150: gridBagConstraints.gridx = 0;
151: gridBagConstraints.gridy = 1;
152: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
153: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
154: gridBagConstraints.insets = new java.awt.Insets(0, 20, 0, 0);
155: add(messageLabel, gridBagConstraints);
156: gridBagConstraints = new java.awt.GridBagConstraints();
157: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
158: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
159: gridBagConstraints.insets = new java.awt.Insets(50, 4, 0,
160: 30);
161: add(phoneNumberTextField, gridBagConstraints);
162:
163: messageTextrArea.setColumns(20);
164: messageTextrArea.setRows(5);
165: messageScrollPane.setViewportView(messageTextrArea);
166:
167: gridBagConstraints = new java.awt.GridBagConstraints();
168: gridBagConstraints.gridx = 0;
169: gridBagConstraints.gridy = 2;
170: gridBagConstraints.gridwidth = 2;
171: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
172: gridBagConstraints.weightx = 1.0;
173: gridBagConstraints.weighty = 1.0;
174: gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
175: add(messageScrollPane, gridBagConstraints);
176: updateView();
177: }
178:
179: void updateView() {
180: final DesignComponent component = SMSComposerDisplayPresenter.this
181: .getComponent();
182: component.getDocument().getTransactionManager().readAccess(
183: new Runnable() {
184:
185: public void run() {
186: PropertyValue phoneNumberLabelTextPV = component
187: .readProperty(SMSComposerCD.PROP_PHONE_NUMEBR_LABEL);
188: String phoneNumberLabelText;
189: if (phoneNumberLabelTextPV.getKind() == PropertyValue.Kind.VALUE) {
190: phoneNumberLabelText = (String) phoneNumberLabelTextPV
191: .getPrimitiveValue();
192: } else if (phoneNumberLabelTextPV.getKind() == PropertyValue.Kind.USERCODE) {
193: phoneNumberLabelText = USER_CODE;
194: } else {
195: phoneNumberLabelText = NULL_TEXT;
196: }
197: phoneNumberLabel
198: .setText(phoneNumberLabelText);
199:
200: PropertyValue phoneNumberTextFieldPV = component
201: .readProperty(SMSComposerCD.PROP_PHONE_NUMBER);
202: String phoneNumberText = null;
203: if (phoneNumberTextFieldPV.getKind() == PropertyValue.Kind.VALUE) {
204: phoneNumberTextField.setEditable(true);
205: phoneNumberText = (String) phoneNumberTextFieldPV
206: .getPrimitiveValue();
207: } else if (phoneNumberTextFieldPV.getKind() == PropertyValue.Kind.USERCODE) {
208: phoneNumberText = USER_CODE;
209: phoneNumberTextField.setEnabled(false);
210: }
211: phoneNumberTextField
212: .setText(phoneNumberText);
213:
214: PropertyValue messageLabelStringPV = component
215: .readProperty(SMSComposerCD.PROP_MESSAGE_LABEL);
216: String messageLabelString = null;
217: if (messageLabelStringPV.getKind() == PropertyValue.Kind.VALUE) {
218: messageLabelString = (String) messageLabelStringPV
219: .getPrimitiveValue();
220: } else if (messageLabelStringPV.getKind() == PropertyValue.Kind.USERCODE) {
221: messageLabelString = USER_CODE;
222: } else {
223: phoneNumberText = NULL_TEXT;
224: }
225: messageLabel.setText(messageLabelString);
226:
227: PropertyValue messageTextAreaPV = component
228: .readProperty(SMSComposerCD.PROP_MESSAGE);
229: String messageText = null;
230: if (messageTextAreaPV.getKind() == PropertyValue.Kind.VALUE) {
231: messageTextrArea.setEnabled(true);
232: messageText = (String) messageTextAreaPV
233: .getPrimitiveValue();
234: } else if (messageTextAreaPV.getKind() == PropertyValue.Kind.USERCODE) {
235: messageText = USER_CODE;
236: messageTextrArea.setEnabled(false);
237: }
238: messageTextrArea.setText(messageText);
239: Integer bkgColor = (Integer) component
240: .readProperty(
241: SMSComposerCD.PROP_BGK_COLOR)
242: .getPrimitiveValue();
243: if (bkgColor != null) {
244: SMSView.this .setBackground(new Color(
245: bkgColor));
246: }
247: Integer frgColor = (Integer) component
248: .readProperty(
249: SMSComposerCD.PROP_FRG_COLOR)
250: .getPrimitiveValue();
251: if (frgColor != null) {
252: Color color = new Color(frgColor);
253: SMSView.this.setForeground(color);
254: phoneNumberLabel.setForeground(color);
255: messageLabel.setForeground(color);
256: phoneNumberTextField
257: .setForeground(color);
258: messageTextrArea.setForeground(color);
259: }
260: }
261: });
262: }
263: }
264: }
|