From 379784e2ec22d8973cae0ecb0ffd21ca6eefde75 Mon Sep 17 00:00:00 2001 From: Mikael Capelle Date: Tue, 20 Feb 2018 12:24:55 +0100 Subject: [PATCH] Start to create a topPanel to add information. --- src/main/org/insa/base/MainWindow.java | 32 +++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/org/insa/base/MainWindow.java b/src/main/org/insa/base/MainWindow.java index a589c55..129e915 100644 --- a/src/main/org/insa/base/MainWindow.java +++ b/src/main/org/insa/base/MainWindow.java @@ -114,7 +114,6 @@ public class MainWindow extends JFrame { */ public void enable(int nTargetPoints, CallableWithNodes callable) { this.enabled = true; - MainWindow.this.getJMenuBar().setEnabled(false); this.nTargetPoints = nTargetPoints; this.points.clear(); this.callable = callable; @@ -125,7 +124,6 @@ public class MainWindow extends JFrame { */ public void disable() { this.enabled = false; - MainWindow.this.getJMenuBar().setEnabled(true); } public void mouseClicked(MouseEvent evt) { @@ -182,8 +180,8 @@ public class MainWindow extends JFrame { private JMenuItem openMapItem; // List of items that cannot be used without a graph - private ArrayList graphItems = new ArrayList(); - + private ArrayList graphLockItems = new ArrayList(); + // Label containing the map ID of the current graph. private JLabel mapIdPanel; @@ -246,7 +244,9 @@ public class MainWindow extends JFrame { sp.add(drawing); sp.add(new JScrollPane(infoPanel)); this.add(sp, BorderLayout.CENTER); - + + // Top Panel + this.add(createTopPanel(), BorderLayout.NORTH); this.add(createStatusBar(), BorderLayout.SOUTH); } @@ -342,7 +342,7 @@ public class MainWindow extends JFrame { drawing.clear(); new GraphDrawing(drawing).drawGraph(graph); - for (JMenuItem item: graphItems) { + for (JMenuItem item: graphLockItems) { item.setEnabled(true); } mapIdPanel.setText("Map ID: 0x" + Integer.toHexString(graph.getMapId())); @@ -388,7 +388,7 @@ public class MainWindow extends JFrame { } } }); - graphItems.add(openPathItem); + graphLockItems.add(openPathItem); // Close item JMenuItem closeItem = new JMenuItem("Quit", KeyEvent.VK_Q); @@ -425,7 +425,7 @@ public class MainWindow extends JFrame { }); } }); - graphItems.add(drawGraphItem); + graphLockItems.add(drawGraphItem); JMenuItem drawGraphBWItem = new JMenuItem("Redraw (B&W)", KeyEvent.VK_B); drawGraphBWItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_B, ActionEvent.ALT_MASK)); @@ -442,7 +442,7 @@ public class MainWindow extends JFrame { }); } }); - graphItems.add(drawGraphBWItem); + graphLockItems.add(drawGraphBWItem); JMenu graphMenu = new JMenu("Graph"); graphMenu.add(drawGraphItem); @@ -491,8 +491,8 @@ public class MainWindow extends JFrame { } } }); - graphItems.add(wccItem); - graphItems.add(bellmanItem); + graphLockItems.add(wccItem); + graphLockItems.add(bellmanItem); algoMenu.add(wccItem); algoMenu.addSeparator(); @@ -507,10 +507,10 @@ public class MainWindow extends JFrame { menuBar.add(graphMenu); menuBar.add(algoMenu); - for (JMenuItem item: graphItems) { + for (JMenuItem item: graphLockItems) { item.setEnabled(false); } - + return menuBar; } @@ -574,6 +574,12 @@ public class MainWindow extends JFrame { return statusPanel; } + protected JPanel createTopPanel() { + JPanel topPanel = new JPanel(); + + return topPanel; + } + public static void main(final String[] args) { // Try to set system look and feel.