KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > yagga > miniinstaller > gui > StepPanel


1 /*
2  * This file is part of MiniInstaller, a self installer builder for Java
3  * Copyright (C) 2002 Walter Gamba
4  * mailto:walter@yagga.net
5  * http://www.yagga.net/java/miniinstaller
6  *
7  * MiniInstaller is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * MiniInstaller is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * As the time of writing, the GNU General Public Licene can be
22  * found at http://www.gnu.org/licenses/gpl.txt
23  *
24  */

25
26 package net.yagga.miniinstaller.gui;
27
28 import net.yagga.util.*;
29 import net.yagga.miniinstaller.Step;
30 import java.awt.*;
31 import javax.swing.*;
32 import java.net.*;
33 import java.io.*;
34
35 /**
36  * class that represents steps through installation
37  * as a list of uneditable items...
38  * with a triangle, lightrd near the current step.
39  * Current step is bold
40  *
41  * @author Walter Gamba
42  * @version 1.0
43  */

44 public class StepPanel extends JPanel implements InstallPanel{
45
46   private Step steps[];
47 // GridLayout gridLayout1 = new GridLayout();
48
JLabel ico1 = new JLabel();
49   JLabel step1 = new JLabel();
50   //
51
Icon icoOff=ResourceMgr.retrieveImageIcon("img/triOff.gif");
52   Icon icoOn=ResourceMgr.retrieveImageIcon("img/triOn.gif");
53
54   JLabel lbSteps[];
55   JLabel lbIcos[];
56   Font normal=null;
57   Font bold=null;
58
59   public StepPanel(Step steps[]) {
60     this.steps=steps;
61     try {
62       jbInit();
63     }
64     catch (Exception JavaDoc ex) {
65       ex.printStackTrace();
66     }
67   }
68   private ImageIcon loadImage(String JavaDoc image) {
69   ImageIcon img = new ImageIcon(StepPanel.class.getResource(image));
70     return img;
71   }
72
73
74   void jbInit() throws Exception JavaDoc {
75       normal=GuiProperties.stepFont;
76     bold=GuiProperties.selectedStepFont;
77
78     JPanel rows=new JPanel();
79     BoxLayout boxLayout=new BoxLayout(rows,BoxLayout.Y_AXIS);
80     rows.setLayout(boxLayout);
81     rows.setOpaque(false);
82     lbSteps=new JLabel[steps.length];
83     lbIcos=new JLabel[steps.length];
84
85         this.setBackground(InstallFrame.BK_COL);
86     for(int i=0;i<steps.length;i++){
87       JPanel jp=new JPanel();
88       //jp.setLayout(new BorderLayout());
89
jp.setLayout(new BoxLayout(jp,SwingConstants.HORIZONTAL));
90       jp.setAlignmentX(Component.LEFT_ALIGNMENT);
91       lbSteps[i]=new JLabel();
92       lbSteps[i].setOpaque(false);
93       lbSteps[i].setText(steps[i].name);
94       lbSteps[i].setFont(normal);
95       lbSteps[i].setForeground(InstallFrame.STEP_COL);
96       lbIcos[i]=new JLabel();
97       lbIcos[i].setOpaque(false);
98       lbIcos[i].setIcon(icoOff);
99       jp.add(lbIcos[i],BorderLayout.WEST);
100       jp.add(lbSteps[i],BorderLayout.CENTER);
101       jp.setOpaque(false);
102       jp.doLayout();
103       rows.add(jp);
104     }
105     rows.add(Box.createVerticalGlue());
106     //rows.add(Box.createVerticalStrut(500));
107
this.setLayout(new BorderLayout());
108     this.add(rows,BorderLayout.CENTER);
109     JPanel p=new JPanel();
110     p.setOpaque(false);
111     p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
112     p.add(Box.createHorizontalStrut(5));
113     javax.swing.border.EtchedBorder JavaDoc eBorder=new javax.swing.border.EtchedBorder JavaDoc();
114     JSeparator spSep=new JSeparator(SwingConstants.VERTICAL);
115     spSep.setBorder(eBorder);
116     p.add(spSep);
117     p.add(Box.createHorizontalStrut(5));
118     this.add(p,BorderLayout.EAST);
119     rows.doLayout();
120     //this.add(jPanel1, null);
121
this.doLayout();
122         Dimension d=this.getPreferredSize();
123         //adjust for bold... 10..15px should do
124
d.width+=10;
125         this.setPreferredSize(d);
126         this.setOpaque(true);
127   }
128
129   private int curStep=-1;
130   private int precStep=-1;
131
132   public void refresh(){
133         try {
134       jbInit();
135     }
136     catch (Exception JavaDoc ex) {
137       ex.printStackTrace();
138     }
139   }
140
141   public void resetStep(){
142     curStep=-1;
143     precStep=-1;
144     //incStep();
145
}
146   public void incStep(){
147     curStep++;
148     setStep(curStep);
149   }
150   public void decStep(){
151     curStep--;
152     setStep(curStep);
153   }
154   public void goStep(int to){
155     for(int i=0;i<steps.length;i++)
156       if(steps[i].index==to)
157         curStep=i;
158     setStep(curStep);
159   }
160   private void setStep(int i){
161     //curStep=i;
162
if(i<0 || i>=steps.length)
163       return;
164     if(precStep!=-1){
165       lbIcos[precStep].setIcon(icoOff);
166       lbSteps[precStep].setFont(normal);
167     }
168       //System.out.println("Step:"+i);
169
lbIcos[i].setIcon(icoOn);
170     lbSteps[i].setFont(bold);
171
172     precStep=i;
173   }
174     public void setDims(Dimension d){
175         double w=getPreferredSize().getWidth();
176         this.setPreferredSize(new Dimension((int)w,(int)d.getHeight()));
177         this.invalidate();
178     }
179
180 }
181
182
183
184
Popular Tags