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