1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package installer;
23 
24 import javax.swing.*;
25 import java.awt.*;
26 import java.awt.event.*;
27 public class NavPanel extends JPanel implements ActionListener {
28 
NavPanel(InstallWizard wizard, boolean bBack, boolean bNext, boolean bCancel, String prev, String next)29     NavPanel(InstallWizard wizard, boolean bBack, boolean bNext, boolean bCancel, String prev, String next) {
30         setBackground(Color.white);
31         setBorder(new javax.swing.border.EtchedBorder(javax.swing.border.EtchedBorder.LOWERED));
32         this.wizard = wizard;
33         this.next = next;
34         this.prev = prev;
35         navBack = new javax.swing.JButton("<< Back");
36         navNext = new javax.swing.JButton("Next >>");
37         navCancel = new javax.swing.JButton("Cancel");
38         setLayout(new GridBagLayout());
39 
40         gridBagConstraints1 = new java.awt.GridBagConstraints();
41         gridBagConstraints1.insets = new java.awt.Insets(1, 1, 1, 1);
42 	  gridBagConstraints1.anchor = gridBagConstraints1.WEST;
43 
44         gridBagConstraints2 = new java.awt.GridBagConstraints();
45         gridBagConstraints2.gridx = 2;
46         gridBagConstraints2.gridy = 0;
47 
48         gridBagConstraints3 = new java.awt.GridBagConstraints();
49         gridBagConstraints3.gridx = 6;
50         gridBagConstraints3.gridy = 0;
51 
52         navNext.setEnabled(bNext);
53         navBack.setEnabled(bBack);
54         navCancel.setEnabled(bCancel);
55         navNext.addActionListener(this);
56         navBack.addActionListener(this);
57         navCancel.addActionListener(this);
58         add(navBack, gridBagConstraints1);
59         add(navNext, gridBagConstraints2);
60         add(navCancel, gridBagConstraints3);
61     }
62 
enableNext(boolean bEnable)63     public void enableNext(boolean bEnable) {
64         navNext.setEnabled(bEnable);
65     }
66 
enableBack(boolean bEnable)67     public void enableBack(boolean bEnable) {
68         navBack.setEnabled(bEnable);
69     }
70 
enableCancel(boolean bEnable)71     public void enableCancel(boolean bEnable) {
72         navCancel.setEnabled(bEnable);
73     }
74 
enableIDE(boolean bEnable)75     public void enableIDE(boolean bEnable) {
76 	ideDetected = bEnable;
77     }
78 
actionPerformed(ActionEvent ev)79     public void actionPerformed(ActionEvent ev) {
80         if ((ev.getSource() == navNext) && (next.length() != 0)) {
81             wizard.show(next);
82         }
83         if ((ev.getSource() == navBack) && (prev.length() != 0)) {
84             wizard.show(prev);
85         }
86         if (ev.getSource() == navCancel) {
87 	    if( ideDetected ) {
88 		    wizard.show(InstallWizard.IDEWELCOME);
89 	    }
90 	    else {
91 		    wizard.exitForm(null);
92 	    }
93 	    enableIDE(false);
94         }
95     }
96 
setNextListener(ActionListener listener)97     public void setNextListener(ActionListener listener) {
98         navNext.addActionListener(listener);
99     }
100 
setBackListener(ActionListener listener)101     public void setBackListener(ActionListener listener) {
102         navBack.addActionListener(listener);
103     }
104 
setCancelListener(ActionListener listener)105     public void setCancelListener(ActionListener listener) {
106         navCancel.addActionListener(listener);
107     }
108 
removeNextListener(ActionListener listener)109 	public void removeNextListener(ActionListener listener)
110 	{
111 		navNext.removeActionListener(listener);
112 	}
113 
removeBackListener(ActionListener listener)114 	public void removeBackListener(ActionListener listener)
115 	{
116 		navBack.removeActionListener(listener);
117 	}
118 
removeCancelListener(ActionListener listener)119 	public void removeCancelListener(ActionListener listener)
120 	{
121 		navCancel.removeActionListener(listener);
122 	}
123 
124     public JButton navBack;
125     public JButton navNext;
126     public JButton navCancel;
127     private GridBagConstraints gridBagConstraints1;
128     private GridBagConstraints gridBagConstraints2;
129     private GridBagConstraints gridBagConstraints3;
130     private InstallWizard wizard;
131     private String next;
132     private String prev;
133     private boolean ideDetected = false;
134 }
135