1 /*******************************************************************************
2 * jArduino: Arduino C++ Code Generation From Java
3 * Copyright 2020 Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 ******************************************************************************/
17 package net.sourceforge.jarduino.gui;
18
19 import net.sourceforge.jarduino.ArduinoException;
20
21 import javax.swing.JDialog;
22 import javax.swing.JFrame;
23 import java.awt.Dialog;
24
25 /**
26 * Dialog for help.
27 */
28 public class ArduinoDialogHelp {
29 /**
30 * The master frame.
31 */
32 private final JFrame theFrame;
33
34 /**
35 * The main window.
36 */
37 private final ArduinoPanelMain theMain;
38
39 /**
40 * The help panel.
41 */
42 private final ArduinoPanelHelp theHelp;
43
44 /**
45 * The help dialog.
46 */
47 private JDialog theDialog;
48
49 /**
50 * Constructor.
51 * @param pFrame the frame
52 * @param pMain the main window
53 * @throws ArduinoException on error
54 */
55 ArduinoDialogHelp(final JFrame pFrame,
56 final ArduinoPanelMain pMain) throws ArduinoException {
57 /* Store parameters */
58 theFrame = pFrame;
59 theMain = pMain;
60
61 /* Create the help panel */
62 theHelp = new ArduinoPanelHelp();
63 }
64
65 /**
66 * Show the dialog.
67 */
68 void showDialog() {
69 /* If we have no dialog */
70 if (theDialog == null) {
71 theDialog = makeDialog();
72 }
73
74 /* If the dialog is not currently displayed */
75 if (!theDialog.isVisible()) {
76 /* Fix location and display */
77 theDialog.setLocationRelativeTo(theFrame);
78 theDialog.setVisible(true);
79 }
80 }
81
82 /**
83 * create the dialog.
84 * @return the dialog
85 */
86 private JDialog makeDialog() {
87 /* Create the dialog */
88 final JDialog myDialog = new JDialog(theFrame);
89 myDialog.setModalityType(Dialog.ModalityType.MODELESS);
90 myDialog.setTitle("jArduino Help");
91
92 /* Attach the help panel to the dialog */
93 myDialog.getContentPane().add(theHelp.getComponent());
94 myDialog.pack();
95 return myDialog;
96 }
97 }