Close ProgressBarDialog on failure.
This commit is contained in:
parent
55e4f4dfdc
commit
e15d04eda9
@ -151,8 +151,8 @@ public class MainWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
StartActionEvent evt = (StartActionEvent) e;
|
StartActionEvent evt = (StartActionEvent) e;
|
||||||
ShortestPathData data = new ShortestPathData(graph, evt.getOrigin(), evt.getDestination(),
|
ShortestPathData data = new ShortestPathData(graph, evt.getOrigin(),
|
||||||
evt.getMode());
|
evt.getDestination(), evt.getMode());
|
||||||
try {
|
try {
|
||||||
ShortestPathAlgorithm spAlgorithm = ShortestPathAlgorithmFactory
|
ShortestPathAlgorithm spAlgorithm = ShortestPathAlgorithmFactory
|
||||||
.createAlgorithm(evt.getAlgorithmClass(), data);
|
.createAlgorithm(evt.getAlgorithmClass(), data);
|
||||||
@ -162,7 +162,8 @@ public class MainWindow extends JFrame {
|
|||||||
catch (Exception e1) {
|
catch (Exception e1) {
|
||||||
JOptionPane.showMessageDialog(MainWindow.this,
|
JOptionPane.showMessageDialog(MainWindow.this,
|
||||||
"An error occurred while creating the specified algorithm.",
|
"An error occurred while creating the specified algorithm.",
|
||||||
"Internal error: Algorithm instantiation failure", JOptionPane.ERROR_MESSAGE);
|
"Internal error: Algorithm instantiation failure",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,8 +187,9 @@ public class MainWindow extends JFrame {
|
|||||||
|
|
||||||
addWindowListener(new WindowAdapter() {
|
addWindowListener(new WindowAdapter() {
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
int confirmed = JOptionPane.showConfirmDialog(null, "Are you sure you want to close the application?",
|
int confirmed = JOptionPane.showConfirmDialog(null,
|
||||||
"Exit Confirmation", JOptionPane.YES_NO_OPTION);
|
"Are you sure you want to close the application?", "Exit Confirmation",
|
||||||
|
JOptionPane.YES_NO_OPTION);
|
||||||
|
|
||||||
if (confirmed == JOptionPane.YES_OPTION) {
|
if (confirmed == JOptionPane.YES_OPTION) {
|
||||||
dispose();
|
dispose();
|
||||||
@ -275,24 +277,27 @@ public class MainWindow extends JFrame {
|
|||||||
private void displayShortestPathSolution(ShortestPathSolution solution) {
|
private void displayShortestPathSolution(ShortestPathSolution solution) {
|
||||||
JPanel infoPanel = new JPanel();
|
JPanel infoPanel = new JPanel();
|
||||||
infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.PAGE_AXIS));
|
infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.PAGE_AXIS));
|
||||||
infoPanel.setBorder(new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.BLACK),
|
infoPanel.setBorder(
|
||||||
|
new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.BLACK),
|
||||||
new EmptyBorder(15, 15, 15, 15)));
|
new EmptyBorder(15, 15, 15, 15)));
|
||||||
|
|
||||||
ShortestPathData data = (ShortestPathData) solution.getInstance();
|
ShortestPathData data = (ShortestPathData) solution.getInstance();
|
||||||
|
|
||||||
String info = null;
|
String info = null;
|
||||||
if (solution == null || !solution.isFeasible()) {
|
if (solution == null || !solution.isFeasible()) {
|
||||||
info = String.format("Shortest path: No path found from node #%d to node #%d.", data.getOrigin().getId(),
|
info = String.format("Shortest path: No path found from node #%d to node #%d.",
|
||||||
data.getDestination().getId());
|
data.getOrigin().getId(), data.getDestination().getId());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info = String.format("Shortest path: Found a path from node #%d to node #%d", data.getOrigin().getId(),
|
info = String.format("Shortest path: Found a path from node #%d to node #%d",
|
||||||
data.getDestination().getId());
|
data.getOrigin().getId(), data.getDestination().getId());
|
||||||
if (data.getMode() == Mode.LENGTH) {
|
if (data.getMode() == Mode.LENGTH) {
|
||||||
info = String.format("%s, %.2f kilometers.", info, (solution.getPath().getLength() / 1000.0));
|
info = String.format("%s, %.2f kilometers.", info,
|
||||||
|
(solution.getPath().getLength() / 1000.0));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info = String.format("%s, %.2f minutes.", info, (solution.getPath().getMinimumTravelTime() / 60.0));
|
info = String.format("%s, %.2f minutes.", info,
|
||||||
|
(solution.getPath().getMinimumTravelTime() / 60.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
infoPanel.add(new JLabel(info));
|
infoPanel.add(new JLabel(info));
|
||||||
@ -327,17 +332,19 @@ public class MainWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String filepath = System.getProperty("user.dir");
|
String filepath = System.getProperty("user.dir");
|
||||||
filepath += File.separator + String.format("path_%#x_%d_%d.path", graph.getMapId(),
|
filepath += File.separator
|
||||||
|
+ String.format("path_%#x_%d_%d.path", graph.getMapId(),
|
||||||
data.getOrigin().getId(), data.getDestination().getId());
|
data.getOrigin().getId(), data.getDestination().getId());
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
fileChooser.setSelectedFile(new File(filepath));
|
fileChooser.setSelectedFile(new File(filepath));
|
||||||
fileChooser.setApproveButtonText("Save");
|
fileChooser.setApproveButtonText("Save");
|
||||||
|
|
||||||
if (fileChooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
if (fileChooser
|
||||||
|
.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
||||||
File file = fileChooser.getSelectedFile();
|
File file = fileChooser.getSelectedFile();
|
||||||
try {
|
try {
|
||||||
BinaryPathWriter writer = new BinaryPathWriter(
|
BinaryPathWriter writer = new BinaryPathWriter(new DataOutputStream(
|
||||||
new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))));
|
new BufferedOutputStream(new FileOutputStream(file))));
|
||||||
writer.writePath(solution.getPath());
|
writer.writePath(solution.getPath());
|
||||||
}
|
}
|
||||||
catch (IOException e1) {
|
catch (IOException e1) {
|
||||||
@ -420,12 +427,14 @@ public class MainWindow extends JFrame {
|
|||||||
// We need to draw MapView, we have to check if the file exists.
|
// We need to draw MapView, we have to check if the file exists.
|
||||||
File mfile = null;
|
File mfile = null;
|
||||||
if (isMapView) {
|
if (isMapView) {
|
||||||
String mfpath = graphFilePath.substring(0, graphFilePath.lastIndexOf(".map")) + ".mapfg";
|
String mfpath = graphFilePath.substring(0, graphFilePath.lastIndexOf(".map"))
|
||||||
|
+ ".mapfg";
|
||||||
mfile = new File(mfpath);
|
mfile = new File(mfpath);
|
||||||
if (!mfile.exists()) {
|
if (!mfile.exists()) {
|
||||||
if (JOptionPane.showConfirmDialog(this,
|
if (JOptionPane.showConfirmDialog(this,
|
||||||
"The associated mapsforge (.mapfg) file has not been found, do you want to specify it manually?",
|
"The associated mapsforge (.mapfg) file has not been found, do you want to specify it manually?",
|
||||||
"File not found", JOptionPane.YES_NO_CANCEL_OPTION) == JOptionPane.YES_OPTION) {
|
"File not found",
|
||||||
|
JOptionPane.YES_NO_CANCEL_OPTION) == JOptionPane.YES_OPTION) {
|
||||||
JFileChooser chooser = new JFileChooser(mfile.getParentFile());
|
JFileChooser chooser = new JFileChooser(mfile.getParentFile());
|
||||||
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||||
mfile = chooser.getSelectedFile();
|
mfile = chooser.getSelectedFile();
|
||||||
@ -497,14 +506,17 @@ public class MainWindow extends JFrame {
|
|||||||
graph = reader.read();
|
graph = reader.read();
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
JOptionPane.showMessageDialog(MainWindow.this, "Unable to read graph from the selected file.");
|
progressBar.setVisible(false);
|
||||||
|
progressBar = null;
|
||||||
|
JOptionPane.showMessageDialog(MainWindow.this,
|
||||||
|
"Unable to read graph from the selected file.");
|
||||||
exception.printStackTrace(System.out);
|
exception.printStackTrace(System.out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
notifyNewGraphLoaded();
|
notifyNewGraphLoaded();
|
||||||
|
|
||||||
graphInfoPanel
|
graphInfoPanel.setText(String.format("Map ID: %#x, %d nodes", graph.getMapId(),
|
||||||
.setText(String.format("Map ID: %#x, %d nodes", graph.getMapId(), graph.getNodes().size()));
|
graph.getNodes().size()));
|
||||||
drawGraph();
|
drawGraph();
|
||||||
|
|
||||||
for (JMenuItem item: graphLockItems) {
|
for (JMenuItem item: graphLockItems) {
|
||||||
@ -523,7 +535,8 @@ public class MainWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JFileChooser chooser = new JFileChooser();
|
JFileChooser chooser = new JFileChooser();
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Graph files", "mapgr");
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("Graph files",
|
||||||
|
"mapgr");
|
||||||
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
||||||
chooser.setFileFilter(filter);
|
chooser.setFileFilter(filter);
|
||||||
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
||||||
@ -531,11 +544,12 @@ public class MainWindow extends JFrame {
|
|||||||
|
|
||||||
DataInputStream stream;
|
DataInputStream stream;
|
||||||
try {
|
try {
|
||||||
stream = new DataInputStream(
|
stream = new DataInputStream(new BufferedInputStream(
|
||||||
new BufferedInputStream(new FileInputStream(chooser.getSelectedFile())));
|
new FileInputStream(chooser.getSelectedFile())));
|
||||||
}
|
}
|
||||||
catch (IOException e1) {
|
catch (IOException e1) {
|
||||||
JOptionPane.showMessageDialog(MainWindow.this, "Cannot open the selected file.");
|
JOptionPane.showMessageDialog(MainWindow.this,
|
||||||
|
"Cannot open the selected file.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loadGraph(new BinaryGraphReaderInsa2018(stream));
|
loadGraph(new BinaryGraphReaderInsa2018(stream));
|
||||||
@ -548,7 +562,8 @@ public class MainWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JFileChooser chooser = new JFileChooser();
|
JFileChooser chooser = new JFileChooser();
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Map & compressed map files", "map");
|
FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
||||||
|
"Map & compressed map files", "map");
|
||||||
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
||||||
chooser.setFileFilter(filter);
|
chooser.setFileFilter(filter);
|
||||||
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
||||||
@ -556,11 +571,12 @@ public class MainWindow extends JFrame {
|
|||||||
|
|
||||||
DataInputStream stream;
|
DataInputStream stream;
|
||||||
try {
|
try {
|
||||||
stream = new DataInputStream(
|
stream = new DataInputStream(new BufferedInputStream(
|
||||||
new BufferedInputStream(new FileInputStream(chooser.getSelectedFile())));
|
new FileInputStream(chooser.getSelectedFile())));
|
||||||
}
|
}
|
||||||
catch (IOException e1) {
|
catch (IOException e1) {
|
||||||
JOptionPane.showMessageDialog(MainWindow.this, "Cannot open the selected file.");
|
JOptionPane.showMessageDialog(MainWindow.this,
|
||||||
|
"Cannot open the selected file.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loadGraph(new BinaryGraphReaderInsa2016(stream));
|
loadGraph(new BinaryGraphReaderInsa2016(stream));
|
||||||
@ -576,18 +592,19 @@ public class MainWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JFileChooser chooser = new JFileChooser();
|
JFileChooser chooser = new JFileChooser();
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Path & compressed path files", "path",
|
FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
||||||
"path.gz");
|
"Path & compressed path files", "path", "path.gz");
|
||||||
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
||||||
chooser.setFileFilter(filter);
|
chooser.setFileFilter(filter);
|
||||||
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
||||||
BinaryPathReader reader;
|
BinaryPathReader reader;
|
||||||
try {
|
try {
|
||||||
reader = new BinaryPathReader(new DataInputStream(
|
reader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(
|
||||||
new BufferedInputStream(new FileInputStream(chooser.getSelectedFile()))));
|
new FileInputStream(chooser.getSelectedFile()))));
|
||||||
}
|
}
|
||||||
catch (IOException e1) {
|
catch (IOException e1) {
|
||||||
JOptionPane.showMessageDialog(MainWindow.this, "Cannot open the selected file.");
|
JOptionPane.showMessageDialog(MainWindow.this,
|
||||||
|
"Cannot open the selected file.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -600,7 +617,8 @@ public class MainWindow extends JFrame {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
JOptionPane.showMessageDialog(MainWindow.this, "Unable to read path from the selected file.");
|
JOptionPane.showMessageDialog(MainWindow.this,
|
||||||
|
"Unable to read path from the selected file.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -614,7 +632,8 @@ public class MainWindow extends JFrame {
|
|||||||
closeItem.addActionListener(new ActionListener() {
|
closeItem.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
MainWindow.this.dispatchEvent(new WindowEvent(MainWindow.this, WindowEvent.WINDOW_CLOSING));
|
MainWindow.this.dispatchEvent(
|
||||||
|
new WindowEvent(MainWindow.this, WindowEvent.WINDOW_CLOSING));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -656,7 +675,8 @@ public class MainWindow extends JFrame {
|
|||||||
}));
|
}));
|
||||||
graphLockItems.add(drawGraphBWItem);
|
graphLockItems.add(drawGraphBWItem);
|
||||||
JMenuItem drawGraphMapsforgeItem = new JMenuItem("Redraw (Map)", KeyEvent.VK_M);
|
JMenuItem drawGraphMapsforgeItem = new JMenuItem("Redraw (Map)", KeyEvent.VK_M);
|
||||||
drawGraphMapsforgeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.ALT_MASK));
|
drawGraphMapsforgeItem
|
||||||
|
.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.ALT_MASK));
|
||||||
drawGraphMapsforgeItem.addActionListener(baf.createBlockingAction(new ActionListener() {
|
drawGraphMapsforgeItem.addActionListener(baf.createBlockingAction(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@ -685,7 +705,8 @@ public class MainWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
WeaklyConnectedComponentsData instance = new WeaklyConnectedComponentsData(graph);
|
WeaklyConnectedComponentsData instance = new WeaklyConnectedComponentsData(graph);
|
||||||
WeaklyConnectedComponentsAlgorithm algo = new WeaklyConnectedComponentsAlgorithm(instance);
|
WeaklyConnectedComponentsAlgorithm algo = new WeaklyConnectedComponentsAlgorithm(
|
||||||
|
instance);
|
||||||
algo.addObserver(new WeaklyConnectedComponentGraphicObserver(drawing));
|
algo.addObserver(new WeaklyConnectedComponentGraphicObserver(drawing));
|
||||||
algo.addObserver(new WeaklyConnectedComponentTextObserver(printStream));
|
algo.addObserver(new WeaklyConnectedComponentTextObserver(printStream));
|
||||||
launchThread(new Runnable() {
|
launchThread(new Runnable() {
|
||||||
@ -731,7 +752,8 @@ public class MainWindow extends JFrame {
|
|||||||
private JPanel createStatusBar() {
|
private JPanel createStatusBar() {
|
||||||
// create the status bar panel and shove it down the bottom of the frame
|
// create the status bar panel and shove it down the bottom of the frame
|
||||||
JPanel statusPanel = new JPanel();
|
JPanel statusPanel = new JPanel();
|
||||||
statusPanel.setBorder(new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY),
|
statusPanel.setBorder(
|
||||||
|
new CompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY),
|
||||||
new EmptyBorder(0, 15, 0, 15)));
|
new EmptyBorder(0, 15, 0, 15)));
|
||||||
statusPanel.setPreferredSize(new Dimension(getWidth(), 38));
|
statusPanel.setPreferredSize(new Dimension(getWidth(), 38));
|
||||||
statusPanel.setLayout(new BorderLayout());
|
statusPanel.setLayout(new BorderLayout());
|
||||||
@ -749,8 +771,8 @@ public class MainWindow extends JFrame {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (currentThread.isRunning()) {
|
if (currentThread.isRunning()) {
|
||||||
int confirmed = JOptionPane.showConfirmDialog(null,
|
int confirmed = JOptionPane.showConfirmDialog(null,
|
||||||
"Are you sure you want to kill the running thread?", "Kill Confirmation",
|
"Are you sure you want to kill the running thread?",
|
||||||
JOptionPane.YES_NO_OPTION);
|
"Kill Confirmation", JOptionPane.YES_NO_OPTION);
|
||||||
if (confirmed == JOptionPane.YES_OPTION) {
|
if (confirmed == JOptionPane.YES_OPTION) {
|
||||||
currentThread.interrupt();
|
currentThread.interrupt();
|
||||||
}
|
}
|
||||||
@ -762,8 +784,8 @@ public class MainWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
long seconds = currentThread.getDuration().getSeconds();
|
long seconds = currentThread.getDuration().getSeconds();
|
||||||
threadTimerLabel
|
threadTimerLabel.setText(String.format("%02d:%02d:%02d", seconds / 3600,
|
||||||
.setText(String.format("%02d:%02d:%02d", seconds / 3600, seconds / 60 % 60, seconds % 60));
|
seconds / 60 % 60, seconds % 60));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
threadTimer.setInitialDelay(0);
|
threadTimer.setInitialDelay(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user