Commit 477663bb authored by Minh Hiep Pham's avatar Minh Hiep Pham 💬

Updated window without border + help window location

parent 474b1c35
......@@ -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,17 +132,18 @@ public class JDialogCPUNode extends JDialogBase implements ActionListener {
//issue 183
private void buttonClick(JButton but, HelpEntry he) {
but.setSelected(true);
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,"Help",he);
cpuHelp.setLocationHelpWindow(but);
}else{
if(!cpuHelp.isVisible()) {
cpuHelp = new JFrameHWNodeHelp(mgui,"Help",he);
cpuHelp.setLocationRelativeTo(but);
cpuHelp = new TGComponentHelp(mgui,"Help",he);
cpuHelp.setLocationHelpWindow(but);
}else{
cpuHelp.setVisible(false);
}
......@@ -153,8 +154,6 @@ public class JDialogCPUNode extends JDialogBase implements ActionListener {
cpuHelp.getRootPane().getActionMap().put("close", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if(!cpuHelp.isVisible())
dispose();
cpuHelp.setVisible(false);
}
});
......@@ -592,10 +591,16 @@ 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() {
dispose();
if ((cpuHelp != null) && cpuHelp.isVisible()) {
cpuHelp.setVisible(false);
}
}
public boolean isRegularClose() {
......
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 JFrame implements ActionListener {
MainGUI mainGUI;
HelpEntry helpEntry;
HelpManager helpManager;
JButton helpBut;
JEditorPane pane;
public TGComponentHelp(MainGUI _mgui, String title, HelpEntry _he) {
super(title);
mainGUI = _mgui;
helpEntry = _he;
setUndecorated(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment