| 67 | } |
| 68 | |
| 69 | public Util.ExceptionlessAutoClosable save() { |
| 70 | |
| 71 | try { |
| 72 | if (GraphicsContext.currentGraphicsContext == null) throw new IllegalStateException(" save() only valid inside draw method "); |
| 73 | for (Field f : this.getClass() |
| 74 | .getDeclaredFields()) { |
| 75 | if (f.getType() |
| 76 | .isAssignableFrom(State.class)) { |
| 77 | try { |
| 78 | State s = (State) f.get(this); |
| 79 | allStates.put(f.getName(), s); |
| 80 | } catch (Exception e) { |
| 81 | e.printStackTrace(); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | List<AutoCloseable> r = new ArrayList<>(); |
| 87 | for (State s : allStates.values()) { |
| 88 | |
| 89 | r.add(s.save()); |
| 90 | GraphicsContext.checkError(() -> "" + s); |
| 91 | } |
| 92 | |
| 93 | return () -> { |
| 94 | |
| 95 | r.forEach(x -> { |
| 96 | try { |
| 97 | x.close(); |
| 98 | } catch (Exception e) { |
| 99 | e.printStackTrace(); |
| 100 | } |
| 101 | }); |
| 102 | }; |
| 103 | } finally { |
| 104 | // GraphicsContext.checkError(); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * dumps the current state to a string |