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