diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java index 9c3a94f69759f1d6e6f9bf692e2ae09c700bdbc0..fef7fd3ded0e238801f124269521b56e32c6657d 100644 --- a/src/main/java/ui/MainGUI.java +++ b/src/main/java/ui/MainGUI.java @@ -712,6 +712,10 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per return helpManager; } + public void setHelpManager(HelpManager hm) { + helpManager = hm; + } + public void showIntegratedHelp() { if (helpManager != null) { openHelpFrame(helpManager); diff --git a/src/main/java/ui/window/JDialogCPUNode.java b/src/main/java/ui/window/JDialogCPUNode.java index 500d67241ad6fef1c6a80f00d02c2180636d2c15..a385a031e940ca8c00916dcbaae6bd0eb2bc3db7 100644 --- a/src/main/java/ui/window/JDialogCPUNode.java +++ b/src/main/java/ui/window/JDialogCPUNode.java @@ -103,7 +103,7 @@ public class JDialogCPUNode extends JDialogBase implements ActionListener { //issue 183 List<JButton> buttons = new ArrayList<>(); List<HelpEntry> helpEntries; - JFrameHWNodeHelp cpuHelp; + TGComponentHelp cpuHelp; /* Creates new form */ public JDialogCPUNode(MainGUI _mgui, Frame _frame, String _title, TMLArchiCPUNode _node, ArchUnitMEC _MECType, @@ -132,33 +132,20 @@ public class JDialogCPUNode extends JDialogBase implements ActionListener { //issue 183 private void buttonClick(JButton but, HelpEntry he) { - //setModalityType(ModalityType.MODELESS); but.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(cpuHelp == null ) { - cpuHelp = new JFrameHWNodeHelp(mgui,"Help",he); - cpuHelp.setLocationRelativeTo(but); + cpuHelp = new TGComponentHelp(mgui, he); + cpuHelp.setLocationHelpWindow(but); }else{ if(!cpuHelp.isVisible()) { - cpuHelp = new JFrameHWNodeHelp(mgui,"Help",he); - cpuHelp.setLocationRelativeTo(but); + cpuHelp = new TGComponentHelp(mgui, he); + cpuHelp.setLocationHelpWindow(but); }else{ cpuHelp.setVisible(false); } } - - if(cpuHelp != null) { - cpuHelp.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close"); - cpuHelp.getRootPane().getActionMap().put("close", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if(!cpuHelp.isVisible()) - dispose(); - cpuHelp.setVisible(false); - } - }); - } } }); } @@ -593,12 +580,18 @@ public class JDialogCPUNode extends JDialogBase implements ActionListener { regularClose = true; MECType = ArchUnitMEC.Types.get( MECTypeCB.getSelectedIndex() ); dispose(); + if ((cpuHelp != null) && cpuHelp.isVisible()) { + cpuHelp.setVisible(false); + } } public void cancelDialog() { //TraceManager.addDev("Cancel dialog"); dispose(); + if ((cpuHelp != null) && cpuHelp.isVisible()) { + cpuHelp.setVisible(false); + } } public boolean isRegularClose() { diff --git a/src/main/java/ui/window/JFrameHelp.java b/src/main/java/ui/window/JFrameHelp.java index 446c62f886d72c5928402ea978c4d4c949e86e33..afbb63ad2a4c29a8e09f4cf6bdd6db4526e06f0b 100644 --- a/src/main/java/ui/window/JFrameHelp.java +++ b/src/main/java/ui/window/JFrameHelp.java @@ -83,6 +83,7 @@ public class JFrameHelp extends JFrame implements ActionListener { visitedEntries = new Vector<>(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); Container framePanel = getContentPane(); framePanel.setLayout(new BorderLayout()); Font f = new Font("Courrier", Font.BOLD, 12); diff --git a/src/main/java/ui/window/TGComponentHelp.java b/src/main/java/ui/window/TGComponentHelp.java new file mode 100644 index 0000000000000000000000000000000000000000..5124ea9a9d15cc95da0703fbab6c8419158b5449 --- /dev/null +++ b/src/main/java/ui/window/TGComponentHelp.java @@ -0,0 +1,112 @@ +package ui.window; + +import help.HelpEntry; +import help.HelpManager; +import myutil.TraceManager; +import ui.MainGUI; +import ui.util.IconManager; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class TGComponentHelp extends JDialog implements ActionListener { + + MainGUI mainGUI; + HelpEntry helpEntry; + HelpManager helpManager; + JButton helpBut; + JEditorPane pane; + + + public TGComponentHelp(MainGUI _mgui, HelpEntry _he) { + mainGUI = _mgui; + helpEntry = _he; + + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close"); + getRootPane().getActionMap().put("close", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + setUndecorated(true); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); + Container framePanel = getContentPane(); + framePanel.setLayout(new BorderLayout()); + Font f = new Font("Courrier", Font.BOLD, 12); + + JPanel helpPanel = new JPanel(); + helpPanel.setLayout(new BorderLayout()); + pane = new JEditorPane("text/html;charset=UTF-8", ""); + pane.setEditable(false); + pane.setText(helpEntry.getHTMLContent()); + + JScrollPane jsp = new JScrollPane(pane); + jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + helpPanel.add(jsp, BorderLayout.CENTER); + + framePanel.add(helpPanel, BorderLayout.CENTER); + + helpBut = new JButton("Help", IconManager.imgic32); + + helpManager = new HelpManager(); + if(helpManager.loadEntries()) { + mainGUI.setHelpManager(helpManager); + } + + helpBut.addActionListener(this); + + JPanel jp = new JPanel(); + jp.add(helpBut); + framePanel.add(jp, BorderLayout.SOUTH); + + setSize(300, 200); + + setVisible(true); + + } + + @Override + public void actionPerformed(ActionEvent e) { + if(e.getSource() == helpBut) { + mainGUI.openHelpFrame(helpEntry); + } + } + + public void setLocationHelpWindow(Component c) { + // target location + int dx, dy; + // target GC + GraphicsDevice gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + Rectangle gcBounds; + + Dimension windowSize = getSize(); + //TraceManager.addDev("window size ==> height = " + windowSize.height + " width = " + windowSize.width); + + gcBounds = gc.getDefaultConfiguration().getBounds(); + + //TraceManager.addDev("gc bounds ==> (x,y) = " + "(" + gcBounds.x + "," + gcBounds.y + ")" + " gc bound width = " + gcBounds.width + " gc " + + // "bound height = " + gcBounds.height); + + Dimension compSize = c.getSize(); + + Point compLocation = c.getLocationOnScreen(); + //TraceManager.addDev("button location ==> (x,y) = " + "(" + compLocation.x + "," + compLocation.y + ")" ); + + dx = compLocation.x + compSize.width; + dy = compLocation.y + compSize.height; + + if (dy + windowSize.height > gcBounds.y + gcBounds.height) { + dy = gcBounds.y + gcBounds.height - windowSize.height; + } + + if (compLocation.x + windowSize.width > gcBounds.width + gcBounds.x) { + dx = compLocation.x - windowSize.width; + } + //TraceManager.addDev("help window location ==> (x,y) = " + "(" + dx+ "," + dy + ")" ); + setLocation(dx, dy); + } +} \ No newline at end of file