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:
042: package org.netbeans.modules.vmd.midp.screen.display;
043:
044: import org.netbeans.modules.vmd.api.model.DesignComponent;
045: import org.netbeans.modules.vmd.api.model.PropertyValue;
046: import org.netbeans.modules.vmd.api.screen.display.ScreenDeviceInfo;
047: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
048: import org.netbeans.modules.vmd.api.screen.display.ScreenPropertyDescriptor;
049: import org.netbeans.modules.vmd.api.screen.display.ScreenPropertyEditor;
050: import org.netbeans.modules.vmd.midp.components.MidpValueSupport;
051: import org.netbeans.modules.vmd.midp.components.displayables.DisplayableCD;
052: import org.netbeans.modules.vmd.midp.components.resources.TickerCD;
053: import org.netbeans.modules.vmd.midp.screen.display.property.ResourcePropertyEditor;
054: import org.netbeans.modules.vmd.midp.screen.display.property.ScreenStringPropertyEditor;
055: import org.openide.util.NbBundle;
056: import org.openide.util.Utilities;
057:
058: import javax.swing.*;
059: import java.awt.*;
060: import java.util.Arrays;
061: import java.util.Collection;
062: import java.util.Collections;
063:
064: /**
065: * A presenter for Displayable MIDP class. ALl other presenters should
066: * inherit from this presenter (e.g. TextBoxDisplayPresenter,
067: * FormDisplayPresenter, ...)
068: *
069: * @author breh
070: */
071: public class DisplayableDisplayPresenter extends ScreenDisplayPresenter {
072:
073: private static final Image BATTERY = Utilities
074: .loadImage("org/netbeans/modules/vmd/midp/screen/display/resources/battery.png"); // NOI18N
075: private static final Image SIGNAL = Utilities
076: .loadImage("org/netbeans/modules/vmd/midp/screen/display/resources/signal.png"); // NOI18N
077:
078: private DisplayableDisplayPanel panel;
079:
080: public DisplayableDisplayPresenter() {
081: panel = new DisplayableDisplayPanel(this );
082: panel.getBattery().setIcon(new ImageIcon(BATTERY));
083: panel.getSignal().setIcon(new ImageIcon(SIGNAL));
084: }
085:
086: public DisplayableDisplayPresenter(Image image) {
087: this ();
088: panel.add(new JLabel(new ImageIcon(image)));
089: }
090:
091: public boolean isTopLevelDisplay() {
092: return true;
093: }
094:
095: public Collection<DesignComponent> getChildren() {
096: return Collections.emptyList();
097: }
098:
099: public JComponent getView() {
100: return panel;
101: }
102:
103: protected DisplayableDisplayPanel getPanel() {
104: return panel;
105: }
106:
107: public Shape getSelectionShape() {
108: return new Rectangle(panel.getSize());
109: }
110:
111: public void reload(ScreenDeviceInfo deviceInfo) {
112: String tickerText = null;
113: if (getComponent().readProperty(DisplayableCD.PROP_TICKER)
114: .getKind() == PropertyValue.Kind.USERCODE)
115: tickerText = NbBundle
116: .getMessage(DisplayableDisplayPresenter.class,
117: "DISP_user_code"); // NOI18N
118: else {
119: DesignComponent ticker = getComponent().readProperty(
120: DisplayableCD.PROP_TICKER).getComponent();
121: if (ticker != null) {
122: PropertyValue value = ticker
123: .readProperty(TickerCD.PROP_STRING);
124: if (value.getKind() == PropertyValue.Kind.USERCODE)
125: tickerText = NbBundle.getMessage(
126: DisplayableDisplayPresenter.class,
127: "DISP_ticker_string_user_code"); // NOI18N
128: else {
129: tickerText = MidpValueSupport
130: .getHumanReadableString(value);
131: if (tickerText == null || tickerText.length() == 0) {
132: tickerText = NbBundle.getMessage(
133: DisplayableDisplayPresenter.class,
134: "DISP_empty_ticker_string"); // NOI18N
135: }
136: }
137: }
138: }
139: panel.getTicker().setText(tickerText);
140: panel.getTitle().setText(
141: MidpValueSupport.getHumanReadableString(getComponent()
142: .readProperty(DisplayableCD.PROP_TITLE)));
143: }
144:
145: public Collection<ScreenPropertyDescriptor> getPropertyDescriptors() {
146: DesignComponent ticker = getComponent().readProperty(
147: DisplayableCD.PROP_TICKER).getComponent();
148: ScreenPropertyEditor tickerEditor;
149: if (ticker == null)
150: tickerEditor = new ResourcePropertyEditor(
151: DisplayableCD.PROP_TICKER, getComponent());
152: else
153: tickerEditor = new ScreenStringPropertyEditor(
154: TickerCD.PROP_STRING, DisplayableCD.PROP_TICKER,
155: JTextField.CENTER);
156: return Arrays.asList(new ScreenPropertyDescriptor(
157: getComponent(), panel.getTitle(),
158: new ScreenStringPropertyEditor(
159: DisplayableCD.PROP_TITLE, JTextField.CENTER)),
160: new ScreenPropertyDescriptor(getComponent(), panel
161: .getTicker(), tickerEditor));
162: }
163:
164: }
|