From d0e2746eb1aa0af14342aea95c2833cb674a0e73 Mon Sep 17 00:00:00 2001 From: Jochen Keil Date: Fri, 2 Jul 2010 11:48:32 +0200 Subject: [PATCH] implement popupmenulistener event handler for tspfile chooser This will update the file list every time the file chooser dropdown box is activated so that newly added files to the directory will show up immediately --- src/aco/TspAcoGui.java | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/aco/TspAcoGui.java b/src/aco/TspAcoGui.java index 2347f37..1dc809e 100644 --- a/src/aco/TspAcoGui.java +++ b/src/aco/TspAcoGui.java @@ -2,12 +2,13 @@ package aco; import java.awt.*; import java.awt.event.*; import javax.swing.*; +import javax.swing.event.*; import java.io.*; public class TspAcoGui extends JFrame - implements ItemListener, ActionListener, Runnable { + implements PopupMenuListener, ItemListener, ActionListener, Runnable { static final long serialVersionUID = 100000000L; @@ -90,6 +91,7 @@ public class TspAcoGui c.add(jp2, BorderLayout.CENTER); c.add(jp3, BorderLayout.SOUTH); algorithms.addItemListener(this); + cases.addPopupMenuListener(this); this.setTitle("TSP Ant Colony Optimization"); this.setSize(400,385); this.setLocation(100,100); @@ -97,6 +99,26 @@ public class TspAcoGui this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } + /* only a stub method here */ + public void popupMenuCanceled(PopupMenuEvent e) {} + + /* only a stub method here */ + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} + + /* called before the popup menu will be shown */ + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + File tspfile = new File(tspdir); + cases.removeAllItems(); + + for (String s : tspfile.list(new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.matches(".*\\.tsp"); + } + } + )) + cases.addItem(s); + } + /**ActionListener for start button*/ public void actionPerformed(ActionEvent e){ boolean stop = false; -- 2.11.4.GIT