1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package org.openoffice.setup; 29 import java.awt.BorderLayout; 30 import java.awt.CardLayout; 31 import java.awt.ComponentOrientation; 32 import java.awt.Dimension; 33 import java.awt.Insets; 34 import java.awt.event.WindowAdapter; 35 import java.io.File; 36 import javax.swing.Box; 37 import javax.swing.BoxLayout; 38 import javax.swing.Icon; 39 import javax.swing.JButton; 40 import javax.swing.JDialog; 41 import javax.swing.JLabel; 42 import javax.swing.JPanel; 43 import javax.swing.JSeparator; 44 import javax.swing.border.EmptyBorder; 45 46 public class SetupFrame extends WindowAdapter { 47 48 String StringPrevious; 49 String StringNext; 50 String StringCancel; 51 String StringFinish; 52 String StringHelp; 53 String StringAppTitle; 54 55 Icon IconStarOffice; 56 57 public static final String ACTION_NEXT = "ActionNext"; 58 public static final String ACTION_PREVIOUS = "ActionPrevious"; 59 public static final String ACTION_CANCEL = "ActionCancel"; 60 public static final String ACTION_HELP = "ActionHelp"; 61 public static final String ACTION_DETAILS = "ActionDetails"; 62 public static final String ACTION_STOP = "ActionStop"; 63 64 public static final int CODE_OK = 0; 65 public static final int CODE_CANCEL = 1; 66 public static final int CODE_ERROR = 2; 67 68 public static final int BUTTON_NEXT = 1; 69 public static final int BUTTON_PREVIOUS = 2; 70 public static final int BUTTON_CANCEL = 3; 71 public static final int BUTTON_HELP = 4; 72 73 private JButton mNextButton; 74 private JButton mPreviousButton; 75 private JButton mCancelButton; 76 private JButton mHelpButton; 77 78 private JDialog mDialog; 79 80 private JPanel mCardPanel; 81 private CardLayout mCardLayout; 82 83 private SetupActionListener mActionListener; 84 private DeckOfPanels mDeck; 85 86 public SetupFrame() { 87 88 StringPrevious = ResourceManager.getString("String_Previous"); 89 StringNext = ResourceManager.getString("String_Next"); 90 StringCancel = ResourceManager.getString("String_Cancel"); 91 StringFinish = ResourceManager.getString("String_Finish"); 92 StringHelp = ResourceManager.getString("String_Help"); 93 94 InstallData data = InstallData.getInstance(); 95 if ( data.isInstallationMode() ) { 96 StringAppTitle = ResourceManager.getString("String_ApplicationTitle"); 97 } else { 98 StringAppTitle = ResourceManager.getString("String_ApplicationTitleUninstallation"); 99 } 100 101 // The setup icon has to be flexible for customization, not included into the jar file 102 File iconFile = data.getInfoRoot("images"); 103 iconFile = new File(iconFile, "Setup.gif"); 104 IconStarOffice = ResourceManager.getIconFromPath(iconFile); 105 106 mActionListener = new SetupActionListener(this); 107 mDeck = new DeckOfPanels(); 108 109 mDialog = new JDialog(); 110 mDialog.setTitle(StringAppTitle); 111 initFrame(); 112 } 113 114 public void addPanel(PanelController panel, String name) { 115 mCardPanel.add(panel.getPanel(), name); 116 panel.setSetupFrame(this); 117 mDeck.addPanel(panel, name); 118 } 119 120 public PanelController getCurrentPanel() { 121 return mDeck.getCurrentPanel(); 122 } 123 124 public void setCurrentPanel(String name, boolean ignoreRepeat, boolean isNext) { 125 if (name == null) 126 close(CODE_ERROR); 127 128 PanelController panel = mDeck.getCurrentPanel(); 129 boolean repeatDialog = false; 130 if (panel != null) { 131 repeatDialog = panel.afterShow(isNext); 132 if ( isNext ) { 133 name = panel.getNext(); // afterShow() could have changed the "next" dialog 134 } 135 if ( ignoreRepeat ) { 136 repeatDialog = false; 137 } 138 } 139 140 if ( repeatDialog ) { 141 name = panel.getName(); 142 } 143 144 panel = mDeck.setCurrentPanel(name); 145 if (panel != null) 146 { 147 setButtonsForPanel(panel); 148 panel.beforeShow(); 149 mCardLayout.show(mCardPanel, name); 150 panel.duringShow(); 151 } 152 } 153 154 void setButtonsForPanel(PanelController panel) { 155 156 setButtonText(StringCancel, BUTTON_CANCEL); 157 setButtonText(StringHelp, BUTTON_HELP); 158 setButtonText(StringPrevious, BUTTON_PREVIOUS); 159 // setButtonEnabled((panel.getPrevious() != null), BUTTON_PREVIOUS); 160 // setButtonEnabled((panel.getNext() != null), BUTTON_CANCEL); 161 if (panel.getNext() == null) { 162 setButtonText(StringFinish, BUTTON_NEXT); 163 } else { 164 setButtonText(StringNext, BUTTON_NEXT); 165 } 166 } 167 168 public void setButtonText(String text, int button) { 169 switch (button) { 170 case BUTTON_NEXT: mNextButton.setText(text); break; 171 case BUTTON_PREVIOUS: mPreviousButton.setText(text); break; 172 case BUTTON_CANCEL: mCancelButton.setText(text); break; 173 case BUTTON_HELP: mHelpButton.setText(text); break; 174 } 175 } 176 177 public void setButtonSelected(int button) { 178 switch (button) { 179 case BUTTON_NEXT: mNextButton.grabFocus(); break; 180 case BUTTON_PREVIOUS: mPreviousButton.grabFocus(); break; 181 case BUTTON_CANCEL: mCancelButton.grabFocus(); break; 182 case BUTTON_HELP: mHelpButton.grabFocus(); break; 183 } 184 } 185 186 public void setButtonEnabled(boolean enabled, int button) { 187 switch (button) { 188 case BUTTON_NEXT: mNextButton.setEnabled(enabled); break; 189 case BUTTON_PREVIOUS: mPreviousButton.setEnabled(enabled); break; 190 case BUTTON_CANCEL: mCancelButton.setEnabled(enabled); break; 191 case BUTTON_HELP: mHelpButton.setEnabled(enabled); break; 192 } 193 } 194 195 public void removeButtonIcon(int button) { 196 switch (button) { 197 case BUTTON_NEXT: mNextButton.setIcon(null); break; 198 case BUTTON_PREVIOUS: mPreviousButton.setIcon(null); break; 199 case BUTTON_CANCEL: mCancelButton.setIcon(null); break; 200 case BUTTON_HELP: mHelpButton.setIcon(null); break; 201 } 202 } 203 204 public SetupActionListener getSetupActionListener() { 205 return mActionListener; 206 } 207 208 void close(int code) { 209 mDialog.dispose(); 210 } 211 212 public JDialog getDialog() { 213 return mDialog; 214 } 215 216 public int showFrame() { 217 mDialog.pack(); 218 mDialog.setLocationRelativeTo(null); 219 mDialog.setModal(true); 220 mDialog.setResizable(false); 221 // mDialog.setMinimumSize(new Dimension(679, 459)); 222 mDialog.setVisible(true); 223 // System.err.println("Width: " + mDialog.getWidth() + ", Height: " + mDialog.getHeight()); 224 225 return 0; 226 } 227 228 private void initFrame() { 229 230 mDialog.getContentPane().setLayout(new BorderLayout()); 231 232 mCardLayout = new CardLayout(); 233 mCardPanel = new JPanel(); 234 mCardPanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10))); 235 mCardPanel.setLayout(mCardLayout); 236 237 mPreviousButton = new JButton(); 238 mNextButton = new JButton(); 239 mCancelButton = new JButton(); 240 mHelpButton = new JButton(); 241 242 mPreviousButton.setHorizontalTextPosition(JButton.RIGHT); 243 mNextButton.setHorizontalTextPosition(JButton.LEFT); 244 245 mPreviousButton.setIcon(ResourceManager.getIcon("Icon_Previous")); 246 mNextButton.setIcon(ResourceManager.getIcon("Icon_Next")); 247 248 mPreviousButton.setActionCommand(ACTION_PREVIOUS); 249 mNextButton.setActionCommand(ACTION_NEXT); 250 mCancelButton.setActionCommand(ACTION_CANCEL); 251 mHelpButton.setActionCommand(ACTION_HELP); 252 253 mPreviousButton.addActionListener(mActionListener); 254 mNextButton.addActionListener(mActionListener); 255 mCancelButton.addActionListener(mActionListener); 256 mHelpButton.addActionListener(mActionListener); 257 258 InstallData data = InstallData.getInstance(); 259 260 if (data.useRtl()) { 261 mPreviousButton.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 262 mNextButton.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 263 mCancelButton.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 264 mHelpButton.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 265 } 266 267 Box ButtonBox = new Box(BoxLayout.X_AXIS); 268 ButtonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10))); 269 ButtonBox.add(mPreviousButton); 270 ButtonBox.add(Box.createHorizontalStrut(10)); 271 ButtonBox.add(mNextButton); 272 ButtonBox.add(Box.createHorizontalStrut(30)); 273 ButtonBox.add(mCancelButton); 274 ButtonBox.add(Box.createHorizontalStrut(10)); 275 ButtonBox.add(mHelpButton); 276 if (data.useRtl()) { 277 ButtonBox.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 278 } 279 280 JPanel ButtonPanel = new JPanel(); 281 JSeparator Separator = new JSeparator(); 282 ButtonPanel.setLayout(new BorderLayout()); 283 ButtonPanel.setPreferredSize(new Dimension(612, 44)); 284 ButtonPanel.add(Separator, BorderLayout.NORTH); 285 ButtonPanel.add(ButtonBox, java.awt.BorderLayout.EAST); 286 287 JPanel IconPanel = new JPanel(); 288 JLabel Icon = new JLabel(); 289 Icon.setIcon(IconStarOffice); 290 // IconPanel.setPreferredSize(new Dimension(142, 372)); 291 // IconPanel.setBorder(new EmptyBorder(new Insets(10, 10, 10, 10))); 292 IconPanel.setLayout(new BorderLayout()); 293 IconPanel.add(Icon); 294 295 mDialog.getContentPane().add(ButtonPanel, java.awt.BorderLayout.SOUTH); 296 mDialog.getContentPane().add(mCardPanel, java.awt.BorderLayout.CENTER); 297 mDialog.getContentPane().add(IconPanel, java.awt.BorderLayout.WEST); 298 } 299 300 } 301