Better, Faster, Freer

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: i386 ]
Version: HEAD ]

001 /*************************************************************************
002  *
003  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004  * 
005  * Copyright 2008 by Sun Microsystems, Inc.
006  *
007  * OpenOffice.org - a multi-platform office productivity suite
008  *
009  * $RCSfile: SetupFrame.java,v $
010  * $Revision: 1.4 $
011  *
012  * This file is part of OpenOffice.org.
013  *
014  * OpenOffice.org is free software: you can redistribute it and/or modify
015  * it under the terms of the GNU Lesser General Public License version 3
016  * only, as published by the Free Software Foundation.
017  *
018  * OpenOffice.org is distributed in the hope that it will be useful,
019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021  * GNU Lesser General Public License version 3 for more details
022  * (a copy is included in the LICENSE file that accompanied this code).
023  *
024  * You should have received a copy of the GNU Lesser General Public License
025  * version 3 along with OpenOffice.org.  If not, see
026  * <http://www.openoffice.org/license.html>
027  * for a copy of the LGPLv3 License.
028  *
029  ************************************************************************/
030 
031 package org.openoffice.setup;
032 import org.openoffice.setup.Util.SystemManager;
033 import java.awt.BorderLayout;
034 import java.awt.CardLayout;
035 import java.awt.Dimension;
036 import java.awt.Insets;
037 import java.awt.event.WindowAdapter;
038 import java.io.File;
039 import javax.swing.Box;
040 import javax.swing.BoxLayout;
041 import javax.swing.Icon;
042 import javax.swing.JButton;
043 import javax.swing.JDialog;
044 import javax.swing.JLabel;
045 import javax.swing.JPanel;
046 import javax.swing.JSeparator;
047 import javax.swing.border.EmptyBorder;
048 
049 public class SetupFrame extends WindowAdapter {
050 
051     String StringPrevious;
052     String StringNext;
053     String StringCancel;
054     String StringFinish;
055     String StringHelp;
056     String StringAppTitle;
057     
058     Icon   IconStarOffice;
059 
060     public static final String ACTION_NEXT      = "ActionNext";
061     public static final String ACTION_PREVIOUS  = "ActionPrevious";
062     public static final String ACTION_CANCEL    = "ActionCancel";
063     public static final String ACTION_HELP      = "ActionHelp";
064     public static final String ACTION_DETAILS   = "ActionDetails";
065     public static final String ACTION_STOP      = "ActionStop";
066 
067     public static final int CODE_OK         = 0;
068     public static final int CODE_CANCEL     = 1;
069     public static final int CODE_ERROR      = 2;
070      
071     public static final int BUTTON_NEXT     = 1;
072     public static final int BUTTON_PREVIOUS = 2;
073     public static final int BUTTON_CANCEL   = 3;
074     public static final int BUTTON_HELP     = 4;
075 
076     private JButton     mNextButton;
077     private JButton     mPreviousButton;
078     private JButton     mCancelButton;
079     private JButton     mHelpButton;
080 
081     private JDialog     mDialog;
082 
083     private JPanel      mCardPanel;
084     private CardLayout  mCardLayout;
085     
086     private SetupActionListener mActionListener;
087     private DeckOfPanels        mDeck; 
088 
089     public SetupFrame() {
090 
091         StringPrevious   = ResourceManager.getString("String_Previous");
092         StringNext       = ResourceManager.getString("String_Next");
093         StringCancel     = ResourceManager.getString("String_Cancel");
094         StringFinish     = ResourceManager.getString("String_Finish");
095         StringHelp       = ResourceManager.getString("String_Help");
096         
097         InstallData data = InstallData.getInstance();
098         if ( data.isInstallationMode() ) {
099             StringAppTitle   = ResourceManager.getString("String_ApplicationTitle");        
100         } else {
101             StringAppTitle   = ResourceManager.getString("String_ApplicationTitleUninstallation");            
102         }
103         
104         // The setup icon has to be flexible for customization, not included into the jar file
105         File iconFile = data.getInfoRoot("images");
106         iconFile = new File(iconFile, "Setup.gif");
107         IconStarOffice   = ResourceManager.getIconFromPath(iconFile);
108            
109         mActionListener = new SetupActionListener(this);
110         mDeck           = new DeckOfPanels(); 
111         
112         mDialog = new JDialog();
113         mDialog.setTitle(StringAppTitle);
114         initFrame();
115     }
116     
117     public void addPanel(PanelController panel, String name) {
118         mCardPanel.add(panel.getPanel(), name);
119         panel.setSetupFrame(this);
120         mDeck.addPanel(panel, name);
121     }  
122    
123     public PanelController getCurrentPanel() {
124         return mDeck.getCurrentPanel();
125     }
126  
127     public void setCurrentPanel(String name, boolean ignoreRepeat, boolean isNext) {
128         if (name == null)
129             close(CODE_ERROR);
130         
131         PanelController panel = mDeck.getCurrentPanel();
132         boolean repeatDialog = false;
133         if (panel != null) {
134             repeatDialog = panel.afterShow(isNext);
135             if ( isNext ) {
136                 name = panel.getNext();   // afterShow() could have changed the "next" dialog
137             }
138             if ( ignoreRepeat ) {
139                 repeatDialog = false;
140             }
141         }
142             
143         if ( repeatDialog ) {
144             name = panel.getName();
145         }
146         
147         panel = mDeck.setCurrentPanel(name);
148         if (panel != null)
149         {
150             setButtonsForPanel(panel);
151             panel.beforeShow();
152             mCardLayout.show(mCardPanel, name);
153             panel.duringShow();
154         }
155     }
156 
157     void setButtonsForPanel(PanelController panel) {
158 
159         setButtonText(StringCancel,     BUTTON_CANCEL);
160         setButtonText(StringHelp,       BUTTON_HELP);
161         setButtonText(StringPrevious,   BUTTON_PREVIOUS);
162         // setButtonEnabled((panel.getPrevious() != null), BUTTON_PREVIOUS);
163         // setButtonEnabled((panel.getNext() != null),     BUTTON_CANCEL);
164         if (panel.getNext() == null) {   
165             setButtonText(StringFinish, BUTTON_NEXT);
166         } else {
167             setButtonText(StringNext,   BUTTON_NEXT);
168         }
169     }
170 
171     public void setButtonText(String text, int button) {
172         switch (button) {
173             case BUTTON_NEXT:       mNextButton.setText(text);        break;
174             case BUTTON_PREVIOUS:   mPreviousButton.setText(text);    break;
175             case BUTTON_CANCEL:     mCancelButton.setText(text);      break;
176             case BUTTON_HELP:       mHelpButton.setText(text);        break;
177         }
178     }
179 
180     public void setButtonSelected(int button) {
181         switch (button) {
182             case BUTTON_NEXT:       mNextButton.grabFocus();     break;
183             case BUTTON_PREVIOUS:   mPreviousButton.grabFocus(); break;
184             case BUTTON_CANCEL:     mCancelButton.grabFocus();   break;
185             case BUTTON_HELP:       mHelpButton.grabFocus();     break;
186         }
187     }
188 
189     public void setButtonEnabled(boolean enabled, int button) {
190         switch (button) {
191             case BUTTON_NEXT:       mNextButton.setEnabled(enabled);     break;
192             case BUTTON_PREVIOUS:   mPreviousButton.setEnabled(enabled); break;
193             case BUTTON_CANCEL:     mCancelButton.setEnabled(enabled);   break;
194             case BUTTON_HELP:       mHelpButton.setEnabled(enabled);     break;
195         }
196     }
197 
198     public void removeButtonIcon(int button) {
199         switch (button) {
200             case BUTTON_NEXT:       mNextButton.setIcon(null);           break;
201             case BUTTON_PREVIOUS:   mPreviousButton.setIcon(null);       break;
202             case BUTTON_CANCEL:     mCancelButton.setIcon(null);         break;
203             case BUTTON_HELP:       mHelpButton.setIcon(null);           break;
204         }
205     }
206     
207     public SetupActionListener getSetupActionListener() {
208         return mActionListener;
209     }
210             
211     void close(int code) {
212         mDialog.dispose();
213     }
214     
215     public JDialog getDialog() {
216         return mDialog;
217     }
218     
219     public int showFrame() {
220         mDialog.pack();
221         mDialog.setLocationRelativeTo(null);
222         mDialog.setModal(true);    
223         mDialog.setResizable(false);
224         // mDialog.setMinimumSize(new Dimension(679, 459));
225         mDialog.setVisible(true);
226         // System.err.println("Width: " + mDialog.getWidth() + ", Height: " + mDialog.getHeight());
227 
228         return 0;
229     }
230     
231     private void initFrame() {
232 
233         mDialog.getContentPane().setLayout(new BorderLayout());
234         
235         mCardLayout = new CardLayout(); 
236         mCardPanel  = new JPanel();
237         mCardPanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));       
238         mCardPanel.setLayout(mCardLayout);
239         
240         mPreviousButton = new JButton();
241         mNextButton     = new JButton();
242         mCancelButton   = new JButton();
243         mHelpButton     = new JButton();       
244  
245         mPreviousButton.setHorizontalTextPosition(JButton.RIGHT);
246         mNextButton.setHorizontalTextPosition(JButton.LEFT);
247         
248         mPreviousButton.setIcon(ResourceManager.getIcon("Icon_Previous"));
249         mNextButton.setIcon(ResourceManager.getIcon("Icon_Next"));
250         
251         mPreviousButton.setActionCommand(ACTION_PREVIOUS);
252         mNextButton.setActionCommand(ACTION_NEXT);
253         mCancelButton.setActionCommand(ACTION_CANCEL);
254         mHelpButton.setActionCommand(ACTION_HELP);
255 
256         mPreviousButton.addActionListener(mActionListener);
257         mNextButton.addActionListener(mActionListener);
258         mCancelButton.addActionListener(mActionListener);
259         mHelpButton.addActionListener(mActionListener);
260         
261         Box ButtonBox   = new Box(BoxLayout.X_AXIS);
262         ButtonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));       
263         ButtonBox.add(mPreviousButton);
264         ButtonBox.add(Box.createHorizontalStrut(10));
265         ButtonBox.add(mNextButton);
266         ButtonBox.add(Box.createHorizontalStrut(30));
267         ButtonBox.add(mCancelButton);
268         ButtonBox.add(Box.createHorizontalStrut(10));
269         ButtonBox.add(mHelpButton);
270 
271         JPanel ButtonPanel = new JPanel();
272         JSeparator Separator = new JSeparator();
273         ButtonPanel.setLayout(new BorderLayout());
274         ButtonPanel.setPreferredSize(new Dimension(612, 44));
275         ButtonPanel.add(Separator, BorderLayout.NORTH);
276         ButtonPanel.add(ButtonBox, java.awt.BorderLayout.EAST);
277  
278         JPanel IconPanel = new JPanel();
279         JLabel Icon = new JLabel();
280         Icon.setIcon(IconStarOffice);
281 //        IconPanel.setPreferredSize(new Dimension(142, 372));
282 //        IconPanel.setBorder(new EmptyBorder(new Insets(10, 10, 10, 10)));
283         IconPanel.setLayout(new BorderLayout());
284         IconPanel.add(Icon);
285         
286         mDialog.getContentPane().add(ButtonPanel, java.awt.BorderLayout.SOUTH);
287         mDialog.getContentPane().add(mCardPanel, java.awt.BorderLayout.CENTER);
288         mDialog.getContentPane().add(IconPanel, java.awt.BorderLayout.WEST); 
289     }
290 
291 }

source navigation ] diff markup ] identifier search ] general search ]

This page was automatically generated by the LXR engine.
The LXR team
Valid HTML 4.01!