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-2023 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) {
77  throw new IllegalArgumentException("can't collect already collected archetypes");
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 {
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 }
net.sf.gridarta.commands.Collector.collectedDirectory
final File collectedDirectory
Definition: Collector.java:55
net.sf.gridarta.commands.Collector
Definition: Collector.java:37
net.sf.gridarta
net.sf.gridarta.commands.Collector.ACTION_BUILDER
static final ActionBuilder ACTION_BUILDER
Definition: Collector.java:43
net.sf.gridarta.model.resource.AbstractResources
Definition: AbstractResources.java:40
net.sf
net.sf.gridarta.model.resource.AbstractResources.writeCollected
void writeCollected(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Definition: AbstractResources.java:131
net.sf.gridarta.commands.Collector.waitUntilFinished
void waitUntilFinished()
Definition: Collector.java:96
net
net.sf.gridarta.commands.Collector.Collector
Collector(@NotNull final Progress progress, @NotNull final AbstractResources<?, ?, ?> resources, @NotNull final File collectedDirectory)
Definition: Collector.java:75
net.sf.gridarta.commands.Collector.progress
final Progress progress
Definition: Collector.java:61
net.sf.gridarta.model.resource
Definition: AbstractCollectedResourcesReader.java:20
net.sf.gridarta.commands.Collector.thread
Thread thread
Definition: Collector.java:67
net.sf.gridarta.commands.Collector.resources
final AbstractResources<?, ?, ?> resources
Definition: Collector.java:49
net.sf.gridarta.model
net.sf.gridarta.commands.Collector.start
void start()
Definition: Collector.java:87
net.sf.gridarta.commands.Collector.run
void run()
Definition: Collector.java:112
net.sf.gridarta.model.resource.AbstractResources.canWriteCollected
boolean canWriteCollected()
Definition: AbstractResources.java:119