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: /*
043: * Created on Jul 15, 2003
044: *
045: */
046: package org.netbeans.modules.uml.ui.controls.newdialog;
047:
048: import java.awt.Frame;
049: import java.awt.GraphicsConfiguration;
050: import java.awt.GridBagConstraints;
051: import java.awt.event.ActionEvent;
052: import java.awt.event.ActionListener;
053:
054: import javax.swing.Icon;
055: import javax.swing.ImageIcon;
056: import javax.swing.JLabel;
057: import javax.swing.JPanel;
058: import javax.swing.JTabbedPane;
059:
060: import org.netbeans.modules.uml.ui.support.wizard.IWizardPage;
061: import org.netbeans.modules.uml.ui.support.wizard.WizardSheet;
062:
063: /**
064: * @author sumitabhk
065: *
066: */
067: public class JDefaultNewDialog extends WizardSheet implements
068: ActionListener {
069: private IWizardPage m_FirstPage = null;
070: private IWizardPage m_SecondPage = null;
071: private IWizardPage m_ThirdPage = null;
072:
073: // Variables declaration - do not modify
074: private javax.swing.JButton jButton1;
075: private javax.swing.JButton jButton2;
076: private javax.swing.JButton jButton3;
077: private javax.swing.JButton jButton4;
078: private javax.swing.JPanel jButtonsPanel;
079: private javax.swing.JPanel jHelpPanel;
080: private javax.swing.JTextArea jTextArea1;
081: private JLabel jLabel1 = null;
082: private javax.swing.JPanel jUIPanel;
083:
084: private JTabbedPane m_TabbedPane = null;
085: private boolean m_FirstScreen = true;
086: private INewDialogUI m_ShownUI = null;
087: private GridBagConstraints m_Constraints = null;
088:
089: private INewDialogTabDetails m_Result = null;
090:
091: // End of variables declaration
092:
093: public JDefaultNewDialog(int nIDCaption, Frame pParentWnd,
094: int iSelectPage, Icon hbmWatermark,
095: GraphicsConfiguration hpalWatermark, Icon hbmHeader) {
096: this (
097: "", pParentWnd, iSelectPage, hbmWatermark, hpalWatermark, hbmHeader); //$NON-NLS-1$
098: }
099:
100: public JDefaultNewDialog(String pszCaption, Frame pParentWnd,
101: int iSelectPage, Icon hbmWatermark,
102: GraphicsConfiguration hpalWatermark, Icon hbmHeader) {
103: super (pszCaption, pParentWnd, iSelectPage, hbmWatermark,
104: hpalWatermark, hbmHeader);
105: init(hbmWatermark, hpalWatermark, hbmHeader);
106: }
107:
108: public JDefaultNewDialog(Frame frame, String title, boolean modal) {
109: super (frame, title, modal);
110: }
111:
112: public JDefaultNewDialog() {
113: super ();
114: }
115:
116: public void init(Icon hbmWatermark,
117: GraphicsConfiguration hpalWatermark, Icon hbmHeader) {
118: if (hbmWatermark != null && hbmHeader != null) {
119: super .init(hbmWatermark, hpalWatermark, hbmHeader);
120: }
121:
122: else {
123: // just load up the default images
124: // super.init(new ImageIcon(JDefaultNewDialog.class.getResource(
125: // NewDialogResources.getString("JDefaultNewDialog.WATERMARK"))), // NOI18N
126: // null,
127: // new ImageIcon(JDefaultNewDialog.class.getResource(
128: // NewDialogResources.getString("JDefaultNewDialog.BANNER")))); // NOI18N
129: }
130: }
131:
132: public void init(Icon hbmWatermark,
133: GraphicsConfiguration hpalWatermark, Icon hbmHeader,
134: INewDialogTabDetails details) {
135: this .init(hbmWatermark, hpalWatermark, hbmHeader);
136:
137: initWithDefaults(details);
138: }
139:
140: /**
141: *
142: */
143: // public JDefaultNewDialog()
144: // {
145: // super();
146: // setSize(450, 450);
147: // m_TabbedPane = new JTabbedPane();
148: // initComponents();
149: // showFirstScreen();
150: // doLayout();
151: // setVisible(true);
152: //
153: // addWindowListener(new WindowAdapter()
154: // {
155: // public void windowClosed(WindowEvent e)
156: // {
157: // //System.exit(0);
158: // }
159: //
160: // public void windowClosing(WindowEvent e)
161: // {
162: // dispose();
163: // }
164: //
165: // });
166: //
167: // setModal(true);
168: // }
169: //
170: // public JDefaultNewDialog(Frame parent)
171: // {
172: // super(parent, true);
173: // setSize(450, 450);
174: // m_TabbedPane = new JTabbedPane();
175: // initComponents();
176: // doLayout();
177: //
178: // addWindowListener(new WindowAdapter()
179: // {
180: // public void windowClosed(WindowEvent e)
181: // {
182: // //System.exit(0);
183: // }
184: //
185: // public void windowClosing(WindowEvent e)
186: // {
187: // dispose();
188: // }
189: //
190: // });
191: // }
192: /**
193: * @param pValidateProcessor
194: */
195: public void init(INewDialogValidateProcessor pValidateProcessor) {
196: // TODO Auto-generated method stub
197:
198: }
199:
200: public void initWithDefaults(INewDialogTabDetails details) {
201: if (details != null) {
202: if (details instanceof INewDialogDiagramDetails) {
203: //m_FirstPage = new NewDiagramSelectionUI(this, details);
204: m_FirstPage = new NewDiagramUI(this , details);
205: this .addPage(m_FirstPage,
206: "Select Diagram Kind To Create"); //$NON-NLS-1$
207: //this.addPage(m_SecondPage, "Create Diagram");
208: } else if (details instanceof INewDialogElementDetails) {
209: //m_FirstPage = new NewElementSelectionUI(this, details);
210: m_FirstPage = new NewElementUI(this , details);
211: this .addPage(m_FirstPage,
212: "Select Element Kind To Create"); //$NON-NLS-1$
213: //this.addPage(m_SecondPage, "Create Element");
214: } else if (details instanceof INewDialogPackageDetails) {
215: m_FirstPage = new NewPackageUI(this ,
216: (INewDialogPackageDetails) details);
217: this .addPage(m_FirstPage, "Create Package"); //$NON-NLS-1$
218: } else if (details instanceof INewDialogProjectDetails) {
219: m_FirstPage = new NewProjectUI(this );
220: this .addPage(m_FirstPage, "Create Project"); //$NON-NLS-1$
221: } else if (details instanceof INewDialogWorkspaceDetails) {
222: m_FirstPage = new NewWorkspaceUI(this );
223: m_SecondPage = new NewProjectUI(this );
224: this .addPage(m_FirstPage, "Create Workspace"); //$NON-NLS-1$
225: this .addPage(m_SecondPage, "Create Project"); //$NON-NLS-1$
226: }
227: } else {
228: m_FirstPage = new ElementSelectionUI(this );
229: this .addPage(m_FirstPage, "Select Type"); //$NON-NLS-1$
230: }
231:
232: this .setActivePage(0);
233: }
234:
235: public void setNextPage(IWizardPage page, String name) {
236: this .addPage(page, name);
237: }
238:
239: /* (non-Javadoc)
240: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
241: */
242: public void actionPerformed(ActionEvent arg0) {
243: // TODO Auto-generated method stub
244: //set the default tab to selected tab at this time.
245: // set the results.
246: Object source = arg0.getSource();
247: if (source.equals(jButton1)) {
248: if (!m_FirstScreen) {
249: showFirstScreen();
250: setupHelpText();
251: }
252: } else if (source.equals(jButton2)) {
253: if (m_ShownUI != null) {
254: JPanel panel = m_ShownUI.nextButtonClicked();
255: if (panel != null) {
256: if (m_Constraints == null) {
257: m_Constraints = new GridBagConstraints();
258: m_Constraints.fill = GridBagConstraints.BOTH;
259: m_Constraints.weightx = 0.7;
260: m_Constraints.weighty = 0.7;
261: }
262: jUIPanel.removeAll();
263: jUIPanel.add(panel, m_Constraints);
264: if (panel instanceof INewDialogUI) {
265: m_ShownUI = null;
266: m_ShownUI = (INewDialogUI) panel;
267: }
268: m_FirstScreen = false;
269: enableDisableButtons();
270: setupHelpText();
271: doLayout();
272: pack();
273: setVisible(true);
274: show();
275: }
276: }
277: } else if (source.equals(jButton3)) {
278: if (m_ShownUI != null) {
279: if (m_ShownUI instanceof JPanel) {
280: JPanel panel = (JPanel) m_ShownUI;
281: m_Result = m_ShownUI.finishButtonClicked();
282: //if the ui has closed itself after finish button processing,
283: //we should close this dialog.
284: // if (!panel.isShowing())
285: // {
286: // closeDialog(null);
287: // }
288: //
289: // //now dispose the dialog
290: // dispose();
291: closeDialog(null);
292: }
293: }
294: } else if (source.equals(jButton4)) {
295: //cancel button clicked - close dialog
296: dispose();
297: //System.exit(0);
298: }
299: }
300:
301: /**
302: *
303: */
304: private void setupHelpText() {
305: if (m_FirstScreen) {
306: jTextArea1.setText("Select item to add"); //$NON-NLS-1$
307: jLabel1.setIcon(null);
308: } else {
309: jTextArea1.setText(m_ShownUI.getHelpText());
310: Icon icon = m_ShownUI.getHelpIcon();
311: jLabel1.setIcon(icon);
312: }
313: }
314:
315: /**
316: *
317: */
318: private void showFirstScreen() {
319: jUIPanel.removeAll();
320: m_ShownUI = null;//new ElementSelectionUI();
321: if (m_ShownUI instanceof JPanel) {
322: if (m_Constraints == null) {
323: m_Constraints = new GridBagConstraints();
324: m_Constraints.fill = GridBagConstraints.BOTH;
325: m_Constraints.weightx = 0.7;
326: m_Constraints.weighty = 0.7;
327: }
328: jUIPanel.add((JPanel) m_ShownUI, m_Constraints);
329: }
330: m_FirstScreen = true;
331: enableDisableButtons();
332: setupHelpText();
333: doLayout();
334: pack();
335: show();
336: }
337:
338: public INewDialogTabDetails getResult() {
339: return m_Result;
340: }
341:
342: public void setResult(INewDialogTabDetails result) {
343: m_Result = result;
344: }
345:
346: public void enableDisableButtons() {
347: if (m_FirstScreen) {
348: jButton1.setEnabled(false); //disable Back button
349: jButton2.setEnabled(true); //enable Next button
350: jButton3.setEnabled(false); //disable Finish button
351: jButton4.setEnabled(true); //enable Cancel button
352: } else {
353: jButton1.setEnabled(true);
354: if (m_ShownUI != null) {
355: boolean val = m_ShownUI.enableNextButton();
356: jButton2.setEnabled(val);
357: } else {
358: jButton2.setEnabled(false);
359: }
360: jButton3.setEnabled(true);
361: jButton4.setEnabled(true);
362: }
363: }
364:
365: private void initComponents() {
366: java.awt.GridBagConstraints gridBagConstraints;
367:
368: jHelpPanel = new javax.swing.JPanel();
369: jTextArea1 = new javax.swing.JTextArea();
370: jUIPanel = new javax.swing.JPanel();
371: jButtonsPanel = new javax.swing.JPanel();
372: jButton1 = new javax.swing.JButton();
373: jButton2 = new javax.swing.JButton();
374: jButton3 = new javax.swing.JButton();
375: jButton4 = new javax.swing.JButton();
376: jLabel1 = new JLabel();
377:
378: //none of these buttons should steal focus
379: jButton1.setFocusable(false);
380: jButton2.setFocusable(false);
381: jButton3.setFocusable(false);
382: jButton4.setFocusable(false);
383:
384: getContentPane().setLayout(new java.awt.GridBagLayout());
385:
386: addWindowListener(new java.awt.event.WindowAdapter() {
387: public void windowClosing(java.awt.event.WindowEvent evt) {
388: closeDialog(evt);
389: }
390: });
391:
392: jHelpPanel.setLayout(new java.awt.GridBagLayout());
393:
394: jHelpPanel.setBorder(new javax.swing.border.LineBorder(
395: new java.awt.Color(0, 0, 0)));
396: gridBagConstraints = new java.awt.GridBagConstraints();
397: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
398: gridBagConstraints.gridx = 0;
399: gridBagConstraints.gridy = 0;
400: gridBagConstraints.weightx = 0.5;
401: gridBagConstraints.weighty = 0.5;
402: //gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
403: jHelpPanel.add(jTextArea1, gridBagConstraints);
404: jTextArea1.setWrapStyleWord(true);
405: jTextArea1.setLineWrap(true);
406: jTextArea1.setAutoscrolls(true);
407: jTextArea1.setEnabled(false);
408: jTextArea1.setEditable(false);
409: jTextArea1.setRows(3);
410:
411: gridBagConstraints = new java.awt.GridBagConstraints();
412: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
413: gridBagConstraints.gridx = 1;
414: gridBagConstraints.gridy = 0;
415: gridBagConstraints.weightx = 0.1;
416: gridBagConstraints.weighty = 0.1;
417: gridBagConstraints.ipadx = 10;
418: jHelpPanel.add(jLabel1, gridBagConstraints);
419: jLabel1.setBackground(jTextArea1.getBackground());
420: jLabel1.setOpaque(true);
421: jLabel1.setEnabled(true);
422:
423: gridBagConstraints = new java.awt.GridBagConstraints();
424: gridBagConstraints.gridx = 0;
425: gridBagConstraints.gridy = 0;
426: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
427: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0);
428: gridBagConstraints.weightx = 0.2;
429: gridBagConstraints.weighty = 0.2;
430: getContentPane().add(jHelpPanel, gridBagConstraints);
431:
432: jUIPanel.setBorder(new javax.swing.border.LineBorder(
433: new java.awt.Color(0, 0, 0)));
434: gridBagConstraints = new java.awt.GridBagConstraints();
435: gridBagConstraints.gridx = 0;
436: gridBagConstraints.gridy = 1;
437: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
438: gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
439: gridBagConstraints.weightx = 0.7;
440: gridBagConstraints.weighty = 0.7;
441: getContentPane().add(jUIPanel, gridBagConstraints);
442:
443: jButtonsPanel.setLayout(new java.awt.GridBagLayout());
444:
445: jButton1.setText(NewDialogResources
446: .getString("JDefaultNewDialog.BACK_BTN")); //$NON-NLS-1$
447: gridBagConstraints = new java.awt.GridBagConstraints();
448: gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
449: jButtonsPanel.add(jButton1, gridBagConstraints);
450: jButton1.addActionListener(this );
451:
452: jButton2.setText(NewDialogResources
453: .getString("JDefaultNewDialog.NEXT_BTN")); //$NON-NLS-1$
454: gridBagConstraints = new java.awt.GridBagConstraints();
455: gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
456: jButtonsPanel.add(jButton2, gridBagConstraints);
457: jButton2.addActionListener(this );
458:
459: jButton3.setText(NewDialogResources
460: .getString("JDefaultNewDialog.FINSH_BTN")); //$NON-NLS-1$
461: gridBagConstraints = new java.awt.GridBagConstraints();
462: gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
463: jButtonsPanel.add(jButton3, gridBagConstraints);
464: jButton3.addActionListener(this );
465:
466: jButton4.setText(NewDialogResources
467: .getString("JDefaultNewDialog.CANCEL_BTN")); //$NON-NLS-1$
468: gridBagConstraints = new java.awt.GridBagConstraints();
469: gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
470: jButtonsPanel.add(jButton4, gridBagConstraints);
471: jButton4.addActionListener(this );
472:
473: gridBagConstraints = new java.awt.GridBagConstraints();
474: gridBagConstraints.gridx = 0;
475: gridBagConstraints.gridy = 2;
476: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
477: gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
478: gridBagConstraints.weightx = 0.1;
479: gridBagConstraints.weighty = 0.1;
480: getContentPane().add(jButtonsPanel, gridBagConstraints);
481:
482: pack();
483: enableDisableButtons();
484: }
485:
486: /** Closes the dialog */
487: private void closeDialog(java.awt.event.WindowEvent evt) {
488: setVisible(false);
489: dispose();
490: }
491:
492: /* (non-Javadoc)
493: * @see org.netbeans.modules.uml.ui.support.wizard.WizardSheet#canAddNavigationButtons()
494: */
495: protected boolean canAddNavigationButtons() {
496: return false;
497: }
498:
499: /* (non-Javadoc)
500: * @see org.netbeans.modules.uml.ui.support.wizard.WizardSheet#getCommitButtonCaption()
501: */
502: protected String getCommitButtonCaption() {
503: return NewDialogResources.getString("JDefaultNewDialog.OK_BTN"); //$NON-NLS-1$
504: }
505:
506: }
|