1  /**************************************************************
2   *
3   * Licensed to the Apache Software Foundation (ASF) under one
4   * or more contributor license agreements.  See the NOTICE file
5   * distributed with this work for additional information
6   * regarding copyright ownership.  The ASF licenses this file
7   * to you under the Apache License, Version 2.0 (the
8   * "License"); you may not use this file except in compliance
9   * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   *
20   *************************************************************/
21  
22  
23  
24  package org.openoffice.setup.Dialogs;
25  
26  import org.openoffice.setup.InstallData;
27  import org.openoffice.setup.ResourceManager;
28  import org.openoffice.setup.SetupFrame;
29  import org.openoffice.setup.Util.DialogFocusTraversalPolicy;
30  import java.awt.BorderLayout;
31  import java.awt.ComponentOrientation;
32  import java.awt.Dimension;
33  import java.awt.Insets;
34  import java.awt.event.ActionListener;
35  import java.io.File;
36  import javax.swing.JButton;
37  import javax.swing.JComponent;
38  import javax.swing.JDialog;
39  import javax.swing.JEditorPane;
40  import javax.swing.JPanel;
41  import javax.swing.JScrollPane;
42  import javax.swing.JSeparator;
43  import javax.swing.border.EmptyBorder;
44  
45  public class HelpDialog extends JDialog implements ActionListener {
46  
47      private JButton okButton;
48      private JEditorPane editorPane;
49      private JScrollPane editorScrollPane;
50      private String helpFileName;
51      private String helpFileString;
52  
HelpDialog(SetupFrame setupFrame)53      public HelpDialog(SetupFrame setupFrame) {
54  
55          super(setupFrame.getDialog());
56  
57          InstallData data = InstallData.getInstance();
58  
59          helpFileString = setupFrame.getCurrentPanel().getHelpFileName();
60          helpFileName = ResourceManager.getFileName(helpFileString);
61          // String dialogName = setupFrame.getCurrentPanel().getName();
62  
63          String helpTitle = ResourceManager.getString("String_Help");
64          setTitle(helpTitle);
65          // setLayout(new java.awt.BorderLayout());
66          this.getContentPane().setLayout(new java.awt.BorderLayout());
67  
68          JPanel toppanel = new JPanel();
69          toppanel.setLayout(new java.awt.BorderLayout());
70          toppanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
71          if ( data.useRtl() ) { toppanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }
72  
73          JPanel buttonpanel = new JPanel();
74          buttonpanel.setLayout(new java.awt.FlowLayout());
75          buttonpanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
76          if ( data.useRtl() ) { buttonpanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }
77  
78          //Create an editor pane.
79          editorPane = createEditorPane();
80          editorScrollPane = new JScrollPane(editorPane);
81          editorScrollPane.setPreferredSize(new Dimension(250, 145));
82          editorScrollPane.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
83          if ( data.useRtl() ) { editorScrollPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }
84  
85          // String helpTitle1 = null;
86          // InstallData data = InstallData.getInstance();
87          // if ( data.isInstallationMode() ) {
88          //     helpTitle1 = ResourceManager.getString("String_Help_Title_1");
89          // } else {
90          //     helpTitle1 = ResourceManager.getString("String_Help_Title_1_Uninstallation");
91          // }
92  
93          // PanelLabel label1 = new PanelLabel(helpTitle1, true);
94          // String helpTitle2 = ResourceManager.getString("String_Help_Title_2");
95          // PanelLabel label2 = new PanelLabel(helpTitle2);
96  
97          String okString = ResourceManager.getString("String_OK");
98          okButton = new JButton(okString);
99          okButton.setEnabled(true);
100          okButton.addActionListener(this);
101          if ( data.useRtl() ) { okButton.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); }
102  
103          JSeparator separator = new JSeparator();
104  
105          // toppanel.add(label1, BorderLayout.NORTH);
106          // toppanel.add(label2, BorderLayout.CENTER);
107          buttonpanel.add(okButton);
108  
109          this.getContentPane().add(toppanel, BorderLayout.NORTH);
110          this.getContentPane().add(editorScrollPane, BorderLayout.CENTER);
111          this.getContentPane().add(buttonpanel, BorderLayout.SOUTH);
112  
113          // Setting tab-order and focus on okButton
114          DialogFocusTraversalPolicy policy = new DialogFocusTraversalPolicy(new JComponent[] {okButton, editorScrollPane});
115          this.setFocusTraversalPolicy(policy);  // set policy
116          this.setFocusCycleRoot(true); // enable policy
117      }
118  
createEditorPane()119       private JEditorPane createEditorPane() {
120          JEditorPane editorPane = new JEditorPane();
121          editorPane.setEditable(false);
122  
123          InstallData data = InstallData.getInstance();
124          File htmlDirectory = data.getInfoRoot("html");
125  
126          if ( htmlDirectory != null) {
127              File htmlFile = new File(htmlDirectory, helpFileName);
128              if (! htmlFile.exists()) {
129                  System.err.println("Couldn't find file: " + htmlFile.toString());
130              }
131  
132              try {
133                  // System.err.println("URLPath: " + htmlFile.toURL());
134                  editorPane.setContentType("text/html;charset=utf-8");
135                  editorPane.setPage(htmlFile.toURL());
136              } catch (Exception e) {
137                  e.printStackTrace();
138                  System.err.println("Attempted to read a bad URL");
139              }
140          }
141          else {
142              System.err.println("Did not find html directory");
143          }
144  
145          return editorPane;
146      }
147  
148  //    public void setTabForScrollPane() {
149  //        JScrollBar ScrollBar = editorScrollPane.getVerticalScrollBar();
150  //        editorPane.setFocusable(true);
151  //        if ( ScrollBar.isShowing() ) {
152  //        } else {
153  //            editorPane.setFocusable(false);
154  //        }
155  //    }
156  
actionPerformed(java.awt.event.ActionEvent evt)157      public void actionPerformed (java.awt.event.ActionEvent evt) {
158          setVisible(false);
159          dispose();
160      }
161  
162  }
163