Normand Briere
2019-06-26 89b25e7cc97f6fe221dfd41c4d463500f8a31bc1
timeflow/app/TimeflowApp.java
....@@ -1,5 +1,6 @@
11 package timeflow.app;
22
3
+import java.net.URL;
34 import timeflow.app.ui.*;
45 import timeflow.app.actions.*;
56 import timeflow.app.ui.filter.*;
....@@ -72,7 +73,7 @@
7273 public JMenuBar TimeFlowWindow(Container container) throws HeadlessException
7374 {
7475 // read example directory
75
- String[] ex = getVisibleFiles("settings/examples");
76
+ String[] ex = getVisibleFiles("timeflow/settings/examples");
7677 int n = ex.length;
7778 examples = new String[n][2];
7879 for (int i = 0; i < n; i++)
....@@ -82,10 +83,10 @@
8283 if (dot >= 0 && dot < s.length() - 1);
8384 s = s.substring(0, dot);
8485 examples[i][0] = s;
85
- examples[i][1] = "settings/examples/" + ex[i];
86
+ examples[i][1] = "timeflow/settings/examples/" + ex[i];
8687 }
8788
88
- templates = getVisibleFiles("settings/templates");
89
+ templates = getVisibleFiles("timeflow/settings/templates");
8990 fileChooser = new JFileChooser(state.getCurrentFile());
9091
9192 container.setLayout(new BorderLayout());
....@@ -554,7 +555,7 @@
554555 }
555556 try
556557 {
557
- final File f = new File(fileName);
558
+ final File f = new File(TimeflowApp.class.getClassLoader().getResource(fileName).toURI());
558559 ActDB db = importer.importFile(f);
559560 model.setDB(db, fileName, readOnly, TimeflowApp.this);
560561 if (!readOnly)
....@@ -693,15 +694,26 @@
693694
694695 static String[] getVisibleFiles(String dir)
695696 {
696
- String[] s = new File(dir).list();
697
- ArrayList<String> real = new ArrayList<String>();
698
- for (int i = 0; i < s.length; i++)
697
+ System.out.println("getVisibleFiles = " + dir);
698
+ try
699699 {
700
- if (!s[i].startsWith("."))
700
+ final URL resource = TimeflowApp.class.getClassLoader().getResource(dir);
701
+ System.out.println("resource = " + resource);
702
+ String[] s = new File(resource.toURI()).list();
703
+ ArrayList<String> real = new ArrayList<String>();
704
+ for (int i = 0; i < s.length; i++)
701705 {
702
- real.add(s[i]);
706
+ if (!s[i].startsWith("."))
707
+ {
708
+ real.add(s[i]);
709
+ }
703710 }
711
+ return (String[]) real.toArray(new String[0]);
704712 }
705
- return (String[]) real.toArray(new String[0]);
713
+ catch (Exception e)
714
+ {
715
+ e.printStackTrace();
716
+ return new String[0];
717
+ }
706718 }
707719 }