Gridarta Editor
Collector.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.commands;
21 
22 import java.io.File;
23 import java.io.IOException;
25 import net.sf.japi.swing.action.ActionBuilder;
26 import net.sf.japi.swing.action.ActionBuilderFactory;
27 import net.sf.japi.swing.misc.Progress;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
37 public class Collector implements Runnable {
38 
42  @NotNull
43  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
44 
48  @NotNull
50 
54  @NotNull
55  private final File collectedDirectory;
56 
60  @NotNull
61  private final Progress progress;
62 
66  @Nullable
67  private Thread thread;
68 
75  public Collector(@NotNull final Progress progress, @NotNull final AbstractResources<?, ?, ?> resources, @NotNull final File collectedDirectory) {
76  if (!resources.canWriteCollected()) {
77  throw new IllegalArgumentException();
78  }
79  this.progress = progress;
80  this.resources = resources;
81  this.collectedDirectory = collectedDirectory;
82  }
83 
87  public void start() {
88  thread = new Thread(this);
89  thread.start();
90  }
91 
96  public void waitUntilFinished() throws InterruptedException {
97  if (thread != null) {
98  thread.join();
99  thread = null;
100  }
101  }
102 
103  /*
104  * Collect the existing arches and create archive-files for editor use as
105  * well as the Crossfire or Daimonin server. The arches also get a special path variable
106  * included which is used in the editor to categorize the arches.
107  * <p>
108  * Output is: "archetypes", "daimonin.0" / "crossfire.0", "animations", "bmaps"
109  */
110 
111  @Override
112  public void run() {
113  try {
114  try {
115  resources.writeCollected(progress, collectedDirectory);
116  } catch (final IOException e) {
117  ACTION_BUILDER.showMessageDialog(progress.getParentComponent(), "archCollectErrorIOException", "arches, animations and animtree, images", e);
118  }
119  } finally {
120  progress.finished();
121  }
122  }
123 
124 }
A Collector is capable of iterating over a collection of Collectables and collecting them in a separa...
Definition: Collector.java:37
void waitUntilFinished()
Waits until collection has finished.
Definition: Collector.java:96
Collector(@NotNull final Progress progress, @NotNull final AbstractResources<?, ?, ?> resources, @NotNull final File collectedDirectory)
Create a Collector.
Definition: Collector.java:75
void start()
Starts collecting.
Definition: Collector.java:87
static final ActionBuilder ACTION_BUILDER
Action Builder.
Definition: Collector.java:43
Base package of all Gridarta classes.
final Progress progress
The Progress to use.
Definition: Collector.java:61
Thread thread
The worker thread.
Definition: Collector.java:67
final AbstractResources<?, ?, ?> resources
The Collectables.
Definition: Collector.java:49
void writeCollected(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Writes the resources in collected form.
final File collectedDirectory
The destination directory to write files to.
Definition: Collector.java:55