xref: /AOO41X/main/javainstaller2/src/JavaSetup/org/openoffice/setup/Dialogs/HelpDialog.java (revision 67e470dafe1997e73f56ff7ff4878983707e3e07)
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.Dialogs;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import org.openoffice.setup.InstallData;
27cdf0e10cSrcweir import org.openoffice.setup.ResourceManager;
28cdf0e10cSrcweir import org.openoffice.setup.SetupFrame;
29cdf0e10cSrcweir import org.openoffice.setup.Util.DialogFocusTraversalPolicy;
30cdf0e10cSrcweir import java.awt.BorderLayout;
31cdf0e10cSrcweir import java.awt.ComponentOrientation;
32cdf0e10cSrcweir import java.awt.Dimension;
33cdf0e10cSrcweir import java.awt.Insets;
34cdf0e10cSrcweir import java.awt.event.ActionListener;
35cdf0e10cSrcweir import java.io.File;
36cdf0e10cSrcweir import javax.swing.JButton;
37cdf0e10cSrcweir import javax.swing.JComponent;
38cdf0e10cSrcweir import javax.swing.JDialog;
39cdf0e10cSrcweir import javax.swing.JEditorPane;
40cdf0e10cSrcweir import javax.swing.JPanel;
41cdf0e10cSrcweir import javax.swing.JScrollPane;
42cdf0e10cSrcweir import javax.swing.JSeparator;
43cdf0e10cSrcweir import javax.swing.border.EmptyBorder;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir public class HelpDialog extends JDialog implements ActionListener {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     private JButton okButton;
48cdf0e10cSrcweir     private JEditorPane editorPane;
49cdf0e10cSrcweir     private JScrollPane editorScrollPane;
50cdf0e10cSrcweir     private String helpFileName;
51cdf0e10cSrcweir     private String helpFileString;
52cdf0e10cSrcweir 
HelpDialog(SetupFrame setupFrame)53cdf0e10cSrcweir     public HelpDialog(SetupFrame setupFrame) {
54cdf0e10cSrcweir 
55cdf0e10cSrcweir         super(setupFrame.getDialog());
56cdf0e10cSrcweir 
57cdf0e10cSrcweir         InstallData data = InstallData.getInstance();
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         helpFileString = setupFrame.getCurrentPanel().getHelpFileName();
60cdf0e10cSrcweir         helpFileName = ResourceManager.getFileName(helpFileString);
61cdf0e10cSrcweir         // String dialogName = setupFrame.getCurrentPanel().getName();
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         String helpTitle = ResourceManager.getString("String_Help");
64cdf0e10cSrcweir         setTitle(helpTitle);
65cdf0e10cSrcweir         // setLayout(new java.awt.BorderLayout());
66cdf0e10cSrcweir         this.getContentPane().setLayout(new java.awt.BorderLayout());
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         JPanel toppanel = new JPanel();
69cdf0e10cSrcweir         toppanel.setLayout(new java.awt.BorderLayout());
70cdf0e10cSrcweir         toppanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
71cdf0e10cSrcweir         if ( data.useRtl() ) { toppanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir         JPanel buttonpanel = new JPanel();
74cdf0e10cSrcweir         buttonpanel.setLayout(new java.awt.FlowLayout());
75cdf0e10cSrcweir         buttonpanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
76cdf0e10cSrcweir         if ( data.useRtl() ) { buttonpanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         //Create an editor pane.
79cdf0e10cSrcweir         editorPane = createEditorPane();
80cdf0e10cSrcweir         editorScrollPane = new JScrollPane(editorPane);
81cdf0e10cSrcweir         editorScrollPane.setPreferredSize(new Dimension(250, 145));
82cdf0e10cSrcweir         editorScrollPane.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
83cdf0e10cSrcweir         if ( data.useRtl() ) { editorScrollPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         // String helpTitle1 = null;
86cdf0e10cSrcweir         // InstallData data = InstallData.getInstance();
87cdf0e10cSrcweir         // if ( data.isInstallationMode() ) {
88cdf0e10cSrcweir         //     helpTitle1 = ResourceManager.getString("String_Help_Title_1");
89cdf0e10cSrcweir         // } else {
90cdf0e10cSrcweir         //     helpTitle1 = ResourceManager.getString("String_Help_Title_1_Uninstallation");
91cdf0e10cSrcweir         // }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         // PanelLabel label1 = new PanelLabel(helpTitle1, true);
94cdf0e10cSrcweir         // String helpTitle2 = ResourceManager.getString("String_Help_Title_2");
95cdf0e10cSrcweir         // PanelLabel label2 = new PanelLabel(helpTitle2);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         String okString = ResourceManager.getString("String_OK");
98cdf0e10cSrcweir         okButton = new JButton(okString);
99cdf0e10cSrcweir         okButton.setEnabled(true);
100cdf0e10cSrcweir         okButton.addActionListener(this);
101cdf0e10cSrcweir         if ( data.useRtl() ) { okButton.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         JSeparator separator = new JSeparator();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         // toppanel.add(label1, BorderLayout.NORTH);
106cdf0e10cSrcweir         // toppanel.add(label2, BorderLayout.CENTER);
107cdf0e10cSrcweir         buttonpanel.add(okButton);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         this.getContentPane().add(toppanel, BorderLayout.NORTH);
110cdf0e10cSrcweir         this.getContentPane().add(editorScrollPane, BorderLayout.CENTER);
111cdf0e10cSrcweir         this.getContentPane().add(buttonpanel, BorderLayout.SOUTH);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         // Setting tab-order and focus on okButton
114cdf0e10cSrcweir         DialogFocusTraversalPolicy policy = new DialogFocusTraversalPolicy(new JComponent[] {okButton, editorScrollPane});
115cdf0e10cSrcweir         this.setFocusTraversalPolicy(policy);  // set policy
116cdf0e10cSrcweir         this.setFocusCycleRoot(true); // enable policy
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
createEditorPane()119cdf0e10cSrcweir      private JEditorPane createEditorPane() {
120cdf0e10cSrcweir         JEditorPane editorPane = new JEditorPane();
121cdf0e10cSrcweir         editorPane.setEditable(false);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         InstallData data = InstallData.getInstance();
124cdf0e10cSrcweir         File htmlDirectory = data.getInfoRoot("html");
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         if ( htmlDirectory != null) {
127cdf0e10cSrcweir             File htmlFile = new File(htmlDirectory, helpFileName);
128cdf0e10cSrcweir             if (! htmlFile.exists()) {
129cdf0e10cSrcweir                 System.err.println("Couldn't find file: " + htmlFile.toString());
130cdf0e10cSrcweir             }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir             try {
133cdf0e10cSrcweir                 // System.err.println("URLPath: " + htmlFile.toURL());
134cdf0e10cSrcweir                 editorPane.setContentType("text/html;charset=utf-8");
135cdf0e10cSrcweir                 editorPane.setPage(htmlFile.toURL());
136cdf0e10cSrcweir             } catch (Exception e) {
137cdf0e10cSrcweir                 e.printStackTrace();
138cdf0e10cSrcweir                 System.err.println("Attempted to read a bad URL");
139cdf0e10cSrcweir             }
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir         else {
142cdf0e10cSrcweir             System.err.println("Did not find html directory");
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         return editorPane;
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir //    public void setTabForScrollPane() {
149cdf0e10cSrcweir //        JScrollBar ScrollBar = editorScrollPane.getVerticalScrollBar();
150cdf0e10cSrcweir //        editorPane.setFocusable(true);
151cdf0e10cSrcweir //        if ( ScrollBar.isShowing() ) {
152cdf0e10cSrcweir //        } else {
153cdf0e10cSrcweir //            editorPane.setFocusable(false);
154cdf0e10cSrcweir //        }
155cdf0e10cSrcweir //    }
156cdf0e10cSrcweir 
actionPerformed(java.awt.event.ActionEvent evt)157cdf0e10cSrcweir     public void actionPerformed (java.awt.event.ActionEvent evt) {
158cdf0e10cSrcweir         setVisible(false);
159cdf0e10cSrcweir         dispose();
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir }
163