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-2007 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.cnd.makewizard;
043:
044: import java.awt.Dimension;
045: import java.util.ArrayList;
046: import java.util.Enumeration;
047: import java.util.ResourceBundle;
048: import java.util.Vector;
049: import javax.swing.JPanel;
050: import javax.swing.event.ChangeEvent;
051: import javax.swing.event.ChangeListener;
052: import org.openide.loaders.TemplateWizard;
053: import org.openide.util.NbBundle;
054:
055: public abstract class MakefileWizardPanel extends JPanel {
056:
057: /** Serial version number */
058: static final long serialVersionUID = -7158070292016837684L;
059:
060: /*
061: * Default preferred width of the panel - should be the same for
062: * all panels within one wizard.
063: */
064: protected static final int DEFAULT_WIDTH = 400;
065:
066: /* Default preferred height of the panel - should be the same for
067: * all panels within one wizard.
068: */
069: protected static final int DEFAULT_HEIGHT = 325;
070:
071: private Vector listvec;
072:
073: /** The MakefileWizard controlling this panel */
074: private MakefileWizard wd;
075:
076: /** Show up to this many items in validating lists */
077: protected final static int MAX_ITEMS_TO_SHOW = 5;
078:
079: protected final static String WARN_CWD_NOT_DIR;
080: protected final static String WARN_CWD_DOES_NOT_EXIST;
081: protected final static String WARN_MAKEFILE_NOT_READABLE;
082: protected final static String WARN_MAKEFILE_NOT_WRITABLE;
083: protected final static String WARN_PARENT_DOES_NOT_EXIST;
084: protected final static String WARN_PARENT_NOT_WRITABLE;
085: protected final static String WARN_BINDIR_DOES_NOT_EXIST;
086: protected final static String WARN_BINDIR_NOT_WRITABLE;
087: protected final static String WARN_CANNOT_CREATE_OUTPUT_DIR;
088: protected final static String WARN_CANNOT_WRITE_TO_OUTPUT_DIR;
089: protected final static String WARN_GUIDIR_NOT_WRITABLE;
090: protected final static String WARN_NO_SRC_FILES;
091: protected final static String WARN_ABSPATH_SRC_COUNT;
092: protected final static String WARN_HDR_SRC_COUNT;
093: protected final static String WARN_DNE_FILES;
094: protected final static String WARN_DNE_COUNT;
095: protected final static String WARN_NO_INC_DIRS;
096: protected final static String WARN_DNE_INCDIR;
097: protected final static String WARN_DNE_INCDIR_COUNT;
098: protected final static String WARN_INC_NOT_DIR;
099: protected final static String WARN_INC_NOT_DIR_COUNT;
100: protected final static String WARN_SUBDIR_DOES_NOT_EXIST;
101: protected final static String WARN_SUBDIR_NOT_WRITABLE;
102: protected final static String WARN_INFINITE_RECURSION;
103: protected final static String WARN_INVALID_MAKEFLAGS;
104: protected final static String WARN_EXTRA_LINES_IN_TARGET;
105: protected final static String WARN_INVALID_LINES_IN_TARGET;
106:
107: static {
108: WARN_CWD_NOT_DIR = "WARN_CWD_NOT_DIR"; // NOI18N
109: WARN_CWD_DOES_NOT_EXIST = "WARN_CWD_DOES_NOT_EXIST"; // NOI18N
110: WARN_MAKEFILE_NOT_READABLE = "WARN_MAKEFILE_NOT_READABLE"; // NOI18N
111: WARN_MAKEFILE_NOT_WRITABLE = "WARN_MAKEFILE_NOT_WRITABLE"; // NOI18N
112: WARN_PARENT_DOES_NOT_EXIST = "WARN_PARENT_DOES_NOT_EXIST"; // NOI18N
113: WARN_PARENT_NOT_WRITABLE = "WARN_PARENT_NOT_WRITABLE"; // NOI18N
114: WARN_BINDIR_DOES_NOT_EXIST = "WARN_BINDIR_DOES_NOT_EXIST"; // NOI18N
115: WARN_BINDIR_NOT_WRITABLE = "WARN_BINDIR_NOT_WRITABLE"; // NOI18N
116: WARN_CANNOT_CREATE_OUTPUT_DIR = "WARN_CANNOT_CREATE_OUTPUT_DIR";// NOI18N
117: WARN_CANNOT_WRITE_TO_OUTPUT_DIR = "WARN_CANNOT_WRITE_TO_OUTPUT_DIR"; // NOI18N
118: WARN_GUIDIR_NOT_WRITABLE = "WARN_GUIDIR_NOT_WRITABLE"; // NOI18N
119: WARN_NO_SRC_FILES = "WARN_NO_SRC_FILES"; // NOI18N
120: WARN_ABSPATH_SRC_COUNT = "WARN_ABSPATH_SRC_COUNT"; // NOI18N
121: WARN_HDR_SRC_COUNT = "WARN_HDR_SRC_COUNT"; // NOI18N
122: WARN_DNE_FILES = "WARN_DNE_FILES"; // NOI18N
123: WARN_DNE_COUNT = "WARN_DNE_COUNT"; // NOI18N
124: WARN_NO_INC_DIRS = "WARN_NO_INC_DIRS"; // NOI18N
125: WARN_DNE_INCDIR = "WARN_DNE_INCDIR"; // NOI18N
126: WARN_DNE_INCDIR_COUNT = "WARN_DNE_INCDIR_COUNT"; // NOI18N
127: WARN_INC_NOT_DIR = "WARN_INC_NOT_DIR"; // NOI18N
128: WARN_INC_NOT_DIR_COUNT = "WARN_INC_NOT_DIR_COUNT"; // NOI18N
129: WARN_SUBDIR_DOES_NOT_EXIST = "WARN_SUBDIR_DOES_NOT_EXIST"; // NOI18N
130: WARN_SUBDIR_NOT_WRITABLE = "WARN_SUBDIR_NOT_WRITABLE"; // NOI18N
131: WARN_INFINITE_RECURSION = "WARN_INFINITE_RECURSION"; // NOI18N
132: WARN_INVALID_MAKEFLAGS = "WARN_INVALID_MAKEFLAGS"; // NOI18N
133: WARN_EXTRA_LINES_IN_TARGET = "WARN_EXTRA_LINES_IN_TARGET"; // NOI18N
134: WARN_INVALID_LINES_IN_TARGET = "WARN_INVALID_LINES_IN_TARGET"; // NOI18N
135: }
136:
137: // for strings...
138: private ResourceBundle bundle;
139:
140: MakefileWizardPanel(MakefileWizard wd) {
141: bundle = NbBundle.getBundle(MakefileWizardPanel.class);
142: this .wd = wd;
143: putClientProperty("WizardPanel_leftDimension",
144: getLeftDimension()); // NOI18N
145: }
146:
147: /** @return preferred size of the wizard panel - it should be the
148: * same for all panels within one Wizard so that the wizard dialog
149: * does not change its size when switching between panels */
150: public Dimension getPreferredSize() {
151: return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT);
152: }
153:
154: /** Get the the subtitle of this panel */
155: public String getSubTitle() {
156: return getName();
157: }
158:
159: /** Set the subtitle of this panel */
160: public void setSubTitle(String subtitle) {
161: setName(subtitle);
162: }
163:
164: /** Get the MakefileData of this panel */
165: protected MakefileData getMakefileData() {
166: return wd.getMakefileData();
167: }
168:
169: /** Get the TemplateWizard of this panel */
170: protected TemplateWizard getTemplateWizard() {
171: return wd.getTemplateWizard();
172: }
173:
174: /** Used by panels which don't use removeNotify to update their data */
175: public void removeNotify() {
176: super .removeNotify();
177: }
178:
179: /**
180: * Default validation method for derived classes which do not need to
181: * write their own validation method.
182: */
183: public void validateData(ArrayList msgs, int key) {
184: }
185:
186: /**
187: * Put together the proper warning int he msgs ArrayList
188: */
189: protected void warn(ArrayList msgs, String prop) {
190: msgs.add(NbBundle.getMessage(getClass(), prop, new String(
191: " "))); // NOI18N
192: }
193:
194: /**
195: * Put together the proper warning int he msgs ArrayList
196: */
197: protected void warn(ArrayList msgs, String prop, String arg1) {
198: msgs.add(NbBundle.getMessage(getClass(), prop, new String(
199: " "), arg1)); // NOI18N
200: }
201:
202: /**
203: * Put together the proper warning int he msgs ArrayList
204: */
205: protected void warn(ArrayList msgs, String prop, String arg1,
206: String arg2) {
207: msgs.add(NbBundle.getMessage(getClass(), prop, new String(
208: " "), arg1, arg2)); // NOI18N
209: }
210:
211: /** Make sure the Steps panel is wide enough */
212: private Dimension getLeftDimension() {
213: return new Dimension(220, 233);
214: }
215:
216: /**
217: * Fire a {@link PropertyChangeEvent} to each listener.
218: * @param propertyName the programmatic name of the property that
219: * was changed
220: * @param oldValue the old value of the property
221: * @param newValue the new value of the property
222: */
223: protected void fireChange() {
224: Vector vecclone = (Vector) listvec.clone();
225: Enumeration en = vecclone.elements();
226: ChangeEvent evt = new ChangeEvent(this );
227: while (en.hasMoreElements()) {
228: ChangeListener elist = (ChangeListener) en.nextElement();
229: elist.stateChanged(evt);
230: }
231: }
232:
233: /** Helper method for getting a string from a bundle */
234: protected String getString(String s) {
235: return bundle.getString(s);
236: }
237:
238: /**
239: * The default validation method. Most panels don't do validation so don't
240: * need to override this.
241: */
242: public boolean isPanelValid() {
243: return true;
244: }
245: }
|