Gridarta Editor
AsynchronousProgress.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.gui.utils;
21 
22 import java.awt.Component;
23 import java.awt.EventQueue;
24 import java.lang.reflect.InvocationTargetException;
25 import net.sf.japi.swing.misc.Progress;
26 import org.jetbrains.annotations.NotNull;
27 
33 public class AsynchronousProgress implements Progress {
34 
38  @NotNull
39  private final Progress progress;
40 
45  public AsynchronousProgress(@NotNull final Progress progress) {
46  this.progress = progress;
47  }
48 
49  @Override
50  public void finished() {
51  try {
52  EventQueue.invokeAndWait(progress::finished);
53  } catch (final InterruptedException ignored) {
54  Thread.currentThread().interrupt();
55  } catch (final InvocationTargetException ex) {
56  // XXX: ignore?
57  }
58  }
59 
60  @Override
61  public Component getParentComponent() {
62  return progress.getParentComponent();
63  }
64 
65  @Override
66  public void setLabel(final String msg, final int max) {
67  EventQueue.invokeLater(() -> progress.setLabel(msg, max));
68  }
69 
70  @Override
71  public void setValue(final int value) {
72  EventQueue.invokeLater(() -> progress.setValue(value));
73  }
74 
75 }
net.sf
net.sf.gridarta.gui.utils.AsynchronousProgress.progress
final Progress progress
The Progress instance to forward to.
Definition: AsynchronousProgress.java:39
net.sf.gridarta.gui.utils.AsynchronousProgress.getParentComponent
Component getParentComponent()
Definition: AsynchronousProgress.java:61
net
net.sf.gridarta.gui.utils.AsynchronousProgress.setValue
void setValue(final int value)
Definition: AsynchronousProgress.java:71
net.sf.gridarta.gui.utils.AsynchronousProgress
Implements a Progress that forwards to another.
Definition: AsynchronousProgress.java:33
net.sf.gridarta.gui.utils.AsynchronousProgress.setLabel
void setLabel(final String msg, final int max)
Definition: AsynchronousProgress.java:66
net.sf.gridarta.gui.utils.AsynchronousProgress.finished
void finished()
Definition: AsynchronousProgress.java:50
net.sf.gridarta.gui.utils.AsynchronousProgress.AsynchronousProgress
AsynchronousProgress(@NotNull final Progress progress)
Creates a new instance.
Definition: AsynchronousProgress.java:45