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;
043:
044: import java.awt.Color;
045: import java.awt.Dimension;
046: import java.awt.Font;
047: import java.awt.font.TextAttribute;
048: import java.util.ArrayList;
049: import java.util.Collection;
050: import java.util.EnumSet;
051: import java.util.HashMap;
052: import java.util.Map;
053: import org.netbeans.modules.vmd.api.screen.display.DeviceBorder;
054: import org.netbeans.modules.vmd.api.screen.display.DeviceTheme;
055: import org.netbeans.modules.vmd.api.screen.display.ScreenDeviceInfo;
056: import org.openide.util.Utilities;
057:
058: /**
059: * Main class hodling bas device info for the device.
060: *
061: * TODO this class should be made abstract and the implementation
062: * should be moved either to the MIDP module or to a completely
063: * separate module defining L&F of the view
064: *
065: * @author breh
066: *
067: */
068: public class MidpScreenDeviceInfo extends ScreenDeviceInfo {
069:
070: protected DeviceBorder[] deviceBorders;
071:
072: private static final String IMAGE_BASE = "org/netbeans/modules/vmd/screen/resources/display/"; // NOI18N
073: private static final String[] IMAGE_NAMES = new String[] {
074: "top.png", "top_right.png", "right.png",
075: "bottom_right.png", "bottom.png", "bottom_left.png",
076: "left.png", "top_left.png" // NOI18N
077: };
078:
079: private Dimension currentScreenSize;
080: private ArrayList<Dimension> customScreenSizes = new ArrayList<Dimension>();
081: private DeviceTheme deviceTheme;
082:
083: public MidpScreenDeviceInfo() {
084: loadImages();
085: customScreenSizes.add(new Dimension(240, 320));
086: customScreenSizes.add(new Dimension(128, 160));
087: currentScreenSize = customScreenSizes.get(0);
088: }
089:
090: /**
091: * Gets device info ID. Used to identify the device info.
092: * @return
093: */
094: public String getDeviceInfoID() {
095: return "DefaultDevice"; // NOI18N
096: }
097:
098: /**
099: * Gets device view resource (e.g. colors, images, fonts ...)
100: * @return
101: */
102: public DeviceTheme getDeviceTheme() {
103: if (deviceTheme == null) {
104: deviceTheme = new MidpDeviceTheme();
105: }
106: return deviceTheme;
107: }
108:
109: /**
110: * Gets current screen size
111: * @return
112: */
113: public Dimension getCurrentScreenSize() {
114: // TODO somehow obtain the screen size from the project
115: return currentScreenSize;
116: }
117:
118: /**
119: * Checks whether this device support custom screen sizes
120: * @return
121: */
122: public boolean supportsCustomScreenSize() {
123: return true;
124: }
125:
126: /**
127: * Returns a collection of the arbitrary sceeen sizes
128: * @return
129: */
130: public Collection<Dimension> getCustomScreenSizes() {
131: return customScreenSizes;
132: }
133:
134: /**
135: * returns true if this device supports arbitrary screen size
136: * @return
137: */
138: public boolean supportsArbitraryScreenSize() {
139: return true;
140: }
141:
142: /**
143: * Sets the arbitrary screen size to be used
144: * @param newScreenSize
145: */
146: public void setArbitraryScreenSize(Dimension newScreenSize) {
147: currentScreenSize = newScreenSize;
148: }
149:
150: /**
151: * Gets image for the given edge of the device
152: * @param edge
153: * @return
154: */
155: @Override
156: public DeviceBorder getDeviceBorder(Edge edge) {
157: return deviceBorders[edge.ordinal()];
158: }
159:
160: protected void loadImages() {
161: deviceBorders = new DeviceBorder[IMAGE_NAMES.length];
162: for (int i = 0; i < IMAGE_NAMES.length; i++) {
163: deviceBorders[i] = new DeviceBorder(Utilities
164: .loadImage(IMAGE_BASE + IMAGE_NAMES[i]));
165: }
166: }
167:
168: /**
169: * Describes basic device resource. This class should be redesigned
170: * to allow more independence on the actual implementation. Current
171: * version is too MIDP2 specific.
172: *
173: * TODO this should be redesigned so it is not MIDP2 specific here !!!
174: *
175: * @author breh
176: * @author Anton Chechel
177: */
178: public static class MidpDeviceTheme extends DeviceTheme {
179:
180: private static final int FONT_SIZE_SMALL = 10;
181: private static final int FONT_SIZE_MEDIUM = 12;
182: private static final int FONT_SIZE_LARGE = 16;
183:
184: private static final String FONT_FACE_MONOSPACE = "Monospaced"; // NOI18N
185: private static final String FONT_FACE_PROPORTIONAL = "Dialog"; // NOI18N
186: private static final String FONT_FACE_SYSTEM = "Dialog"; // NOI18N
187:
188: private static final Font FONT_DEFAULT = new Font(
189: FONT_FACE_PROPORTIONAL, Font.PLAIN, FONT_SIZE_MEDIUM);
190: private static final Font FONT_INPUT_TEXT = new Font(
191: FONT_FACE_PROPORTIONAL, Font.PLAIN, FONT_SIZE_MEDIUM);
192: private static final Font FONT_STATIC_TEXT = new Font(
193: FONT_FACE_PROPORTIONAL, Font.PLAIN, FONT_SIZE_MEDIUM);
194:
195: private static final Map<TextAttribute, Integer> ATTR_MAP = new HashMap<TextAttribute, Integer>(
196: 1);
197:
198: static {
199: ATTR_MAP.put(TextAttribute.UNDERLINE,
200: TextAttribute.UNDERLINE_ON);
201: }
202:
203: public Font getFont(FontType type) {
204: switch (type) {
205: case INPUT_TEXT:
206: return FONT_INPUT_TEXT;
207: case STATIC_TEXT:
208: return FONT_STATIC_TEXT;
209: default:
210: return FONT_DEFAULT;
211: }
212: }
213:
214: public Font getFont(FontFace face, EnumSet<FontStyle> style,
215: FontSize size) {
216: String name = FONT_FACE_SYSTEM;
217: if (face == FontFace.MONOSPACE) {
218: name = FONT_FACE_MONOSPACE;
219: } else if (face == FontFace.PROPORTIONAL) {
220: name = FONT_FACE_PROPORTIONAL;
221: }
222:
223: int styleInt = Font.PLAIN;
224: if (style.contains(FontStyle.BOLD)) {
225: styleInt |= Font.BOLD;
226: }
227: if (style.contains(FontStyle.ITALIC)) {
228: styleInt |= Font.ITALIC;
229: }
230:
231: int sizeInt = FONT_SIZE_MEDIUM;
232: if (size == FontSize.LARGE) {
233: sizeInt = FONT_SIZE_LARGE;
234: } else if (size == FontSize.SMALL) {
235: sizeInt = FONT_SIZE_SMALL;
236: }
237:
238: Font font = new Font(name, styleInt, sizeInt);
239: if (style.contains(FontStyle.UNDERLINED)) {
240: font = font.deriveFont(ATTR_MAP);
241: }
242:
243: return font;
244: }
245:
246: public Color getColor(DeviceTheme.Colors colorType) {
247: if (DeviceTheme.Colors.BACKGROUND == colorType)
248: return Color.WHITE;
249: if (DeviceTheme.Colors.FOREGROUND == colorType)
250: return Color.BLACK;
251: if (DeviceTheme.Colors.HIGHLIGHTED == colorType)
252: return Color.RED;
253: return null;
254: }
255: }
256: }
|