Code cleanup
This commit is contained in:
parent
91b82b16a9
commit
92fa017b6b
|
@ -1,25 +1,8 @@
|
||||||
package ctbrec.ui.tabs;
|
package ctbrec.ui.tabs;
|
||||||
|
|
||||||
import static ctbrec.Model.State.*;
|
|
||||||
import static ctbrec.io.HttpConstants.*;
|
|
||||||
import static ctbrec.ui.Icon.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.GlobalThreadPool;
|
import ctbrec.GlobalThreadPool;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
|
@ -31,7 +14,6 @@ import ctbrec.ui.Icon;
|
||||||
import ctbrec.ui.SiteUiFactory;
|
import ctbrec.ui.SiteUiFactory;
|
||||||
import ctbrec.ui.action.EditGroupAction;
|
import ctbrec.ui.action.EditGroupAction;
|
||||||
import ctbrec.ui.action.PlayAction;
|
import ctbrec.ui.action.PlayAction;
|
||||||
import ctbrec.ui.action.StartRecordingAction;
|
|
||||||
import ctbrec.ui.action.StopRecordingAction;
|
import ctbrec.ui.action.StopRecordingAction;
|
||||||
import ctbrec.ui.controls.Dialogs;
|
import ctbrec.ui.controls.Dialogs;
|
||||||
import ctbrec.ui.controls.RecordingIndicator;
|
import ctbrec.ui.controls.RecordingIndicator;
|
||||||
|
@ -50,7 +32,6 @@ import javafx.geometry.Pos;
|
||||||
import javafx.scene.Cursor;
|
import javafx.scene.Cursor;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.ContextMenu;
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.Tooltip;
|
import javafx.scene.control.Tooltip;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
|
@ -69,6 +50,22 @@ import javafx.scene.text.TextAlignment;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static ctbrec.Model.State.OFFLINE;
|
||||||
|
import static ctbrec.Model.State.ONLINE;
|
||||||
|
import static ctbrec.io.HttpConstants.*;
|
||||||
|
import static ctbrec.ui.Icon.*;
|
||||||
|
|
||||||
public class ThumbCell extends StackPane {
|
public class ThumbCell extends StackPane {
|
||||||
|
|
||||||
|
@ -76,47 +73,46 @@ public class ThumbCell extends StackPane {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ThumbCell.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ThumbCell.class);
|
||||||
private static final Duration ANIMATION_DURATION = new Duration(250);
|
private static final Duration ANIMATION_DURATION = new Duration(250);
|
||||||
|
|
||||||
private static Image imgRecordIndicator = new Image(MEDIA_RECORD_16.url());
|
private static final Image imgRecordIndicator = new Image(MEDIA_RECORD_16.url());
|
||||||
private static Image imgPauseIndicator = new Image(MEDIA_PLAYBACK_PAUSE_16.url());
|
private static final Image imgPauseIndicator = new Image(MEDIA_PLAYBACK_PAUSE_16.url());
|
||||||
private static Image imgBookmarkIndicator = new Image(BOOKMARK_16.url());
|
private static final Image imgBookmarkIndicator = new Image(BOOKMARK_16.url());
|
||||||
private static Image imgGroupIndicator = new Image(Icon.GROUP_16.url());
|
private static final Image imgGroupIndicator = new Image(Icon.GROUP_16.url());
|
||||||
|
|
||||||
private ModelRecordingState modelRecordingState = ModelRecordingState.NOT;
|
private ModelRecordingState modelRecordingState = ModelRecordingState.NOT;
|
||||||
private Model model;
|
private final Model model;
|
||||||
private StreamPreview streamPreview;
|
private final StreamPreview streamPreview;
|
||||||
private ImageView iv;
|
private final ImageView iv;
|
||||||
private Rectangle resolutionBackground;
|
private final Rectangle resolutionBackground;
|
||||||
private final Paint resolutionOnlineColor = new Color(0.22, 0.8, 0.29, 1);
|
private final Paint resolutionOnlineColor = new Color(0.22, 0.8, 0.29, 1);
|
||||||
private final Color resolutionOfflineColor = new Color(0.8, 0.28, 0.28, 1);
|
private final Color resolutionOfflineColor = new Color(0.8, 0.28, 0.28, 1);
|
||||||
private Rectangle nameBackground;
|
private final Rectangle nameBackground;
|
||||||
private Rectangle topicBackground;
|
private final Rectangle topicBackground;
|
||||||
private Rectangle selectionOverlay;
|
private final Rectangle selectionOverlay;
|
||||||
private Text name;
|
private final Text name;
|
||||||
private Text topic;
|
private final Text topic;
|
||||||
private Text resolutionTag;
|
private final Text resolutionTag;
|
||||||
private Recorder recorder;
|
private final Recorder recorder;
|
||||||
private RecordingIndicator recordingIndicator;
|
private final RecordingIndicator recordingIndicator;
|
||||||
private Tooltip recordingIndicatorTooltip;
|
private final Tooltip recordingIndicatorTooltip;
|
||||||
private StackPane previewTrigger;
|
private StackPane previewTrigger;
|
||||||
private StackPane groupIndicator;
|
private final StackPane groupIndicator;
|
||||||
private Label groupIndicatorTooltipTrigger;
|
private final Label groupIndicatorTooltipTrigger;
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
ContextMenu popup;
|
|
||||||
private static final Color colorNormal = Color.BLACK;
|
private static final Color colorNormal = Color.BLACK;
|
||||||
private static final Color colorHighlight = Color.WHITE;
|
private static final Color colorHighlight = Color.WHITE;
|
||||||
private final Color colorRecording = new Color(0.8, 0.28, 0.28, .8);
|
private final Color colorRecording = new Color(0.8, 0.28, 0.28, .8);
|
||||||
private SimpleBooleanProperty selectionProperty = new SimpleBooleanProperty(false);
|
private final SimpleBooleanProperty selectionProperty = new SimpleBooleanProperty(false);
|
||||||
private double imgAspectRatio = 3.0 / 4.0;
|
private double imgAspectRatio;
|
||||||
private SimpleBooleanProperty preserveAspectRatio = new SimpleBooleanProperty(true);
|
private final SimpleBooleanProperty preserveAspectRatio = new SimpleBooleanProperty(true);
|
||||||
|
|
||||||
private ObservableList<Node> thumbCellList;
|
private final ObservableList<Node> thumbCellList;
|
||||||
private boolean mouseHovering = false;
|
private boolean mouseHovering = false;
|
||||||
private boolean recording = false;
|
private boolean recording;
|
||||||
static LoadingCache<Model, int[]> resolutionCache = CacheBuilder.newBuilder()
|
static LoadingCache<Model, int[]> resolutionCache = CacheBuilder.newBuilder()
|
||||||
.expireAfterAccess(5, TimeUnit.MINUTES)
|
.expireAfterAccess(5, TimeUnit.MINUTES)
|
||||||
.maximumSize(10000)
|
.maximumSize(10000)
|
||||||
.build(CacheLoader.from(ThumbCell::getStreamResolution));
|
.build(CacheLoader.from(ThumbCell::getStreamResolution));
|
||||||
private ThumbOverviewTab parent;
|
private final ThumbOverviewTab parent;
|
||||||
private CompletableFuture<Boolean> startPreview;
|
private CompletableFuture<Boolean> startPreview;
|
||||||
|
|
||||||
public ThumbCell(ThumbOverviewTab parent, Model model, Recorder recorder, double aspectRatio) {
|
public ThumbCell(ThumbOverviewTab parent, Model model, Recorder recorder, double aspectRatio) {
|
||||||
|
@ -321,7 +317,7 @@ public class ThumbCell extends StackPane {
|
||||||
}
|
}
|
||||||
}, GlobalThreadPool.get()).whenComplete((result, exception) -> {
|
}, GlobalThreadPool.get()).whenComplete((result, exception) -> {
|
||||||
startPreview = null;
|
startPreview = null;
|
||||||
if (result.booleanValue()) {
|
if (Boolean.TRUE.equals(result)) {
|
||||||
setPreviewVisible(previewTrigger, true);
|
setPreviewVisible(previewTrigger, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -443,7 +439,8 @@ public class ThumbCell extends StackPane {
|
||||||
if (resp.isSuccessful()) {
|
if (resp.isSuccessful()) {
|
||||||
double width = 480;
|
double width = 480;
|
||||||
double height = width * imgAspectRatio;
|
double height = width * imgAspectRatio;
|
||||||
var img = new Image(resp.body().byteStream(), width, height, preserveAspectRatio.get(), true);
|
InputStream bodyStream = Objects.requireNonNull(resp.body(), "HTTP body is null").byteStream();
|
||||||
|
var img = new Image(bodyStream, width, height, preserveAspectRatio.get(), true);
|
||||||
if (img.progressProperty().get() == 1.0) {
|
if (img.progressProperty().get() == 1.0) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
iv.setImage(img);
|
iv.setImage(img);
|
||||||
|
@ -525,14 +522,6 @@ public class ThumbCell extends StackPane {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void startStopAction(boolean start) {
|
|
||||||
if (start) {
|
|
||||||
new StartRecordingAction(this, List.of(getModel()), recorder).execute();
|
|
||||||
} else {
|
|
||||||
new StopRecordingAction(this, List.of(getModel()), recorder).execute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pauseResumeAction(boolean pause) {
|
void pauseResumeAction(boolean pause) {
|
||||||
setCursor(Cursor.WAIT);
|
setCursor(Cursor.WAIT);
|
||||||
GlobalThreadPool.submit(() -> {
|
GlobalThreadPool.submit(() -> {
|
||||||
|
@ -625,7 +614,7 @@ public class ThumbCell extends StackPane {
|
||||||
topic.setText(txt);
|
topic.setText(txt);
|
||||||
recorder.getModelGroup(model).ifPresentOrElse(group -> {
|
recorder.getModelGroup(model).ifPresentOrElse(group -> {
|
||||||
var tooltip = group.getName() + ": " + group.getModelUrls().size() + " models:\n";
|
var tooltip = group.getName() + ": " + group.getModelUrls().size() + " models:\n";
|
||||||
tooltip += group.getModelUrls().stream().collect(Collectors.joining("\n"));
|
tooltip += String.join("\n", group.getModelUrls());
|
||||||
groupIndicatorTooltipTrigger.setTooltip(new Tooltip(tooltip));
|
groupIndicatorTooltipTrigger.setTooltip(new Tooltip(tooltip));
|
||||||
groupIndicator.setVisible(true);
|
groupIndicator.setVisible(true);
|
||||||
}, () -> groupIndicator.setVisible(false));
|
}, () -> groupIndicator.setVisible(false));
|
||||||
|
@ -658,11 +647,8 @@ public class ThumbCell extends StackPane {
|
||||||
return false;
|
return false;
|
||||||
ThumbCell other = (ThumbCell) obj;
|
ThumbCell other = (ThumbCell) obj;
|
||||||
if (model == null) {
|
if (model == null) {
|
||||||
if (other.model != null)
|
return other.model == null;
|
||||||
return false;
|
} else return model.equals(other.model);
|
||||||
} else if (!model.equals(other.model))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThumbWidth(int width) {
|
public void setThumbWidth(int width) {
|
||||||
|
@ -722,12 +708,6 @@ public class ThumbCell extends StackPane {
|
||||||
return preserveAspectRatio;
|
return preserveAspectRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addInPausedState() {
|
|
||||||
model.setSuspended(true);
|
|
||||||
model.setMarkedForLaterRecording(false);
|
|
||||||
startStopAction(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum ModelRecordingState {
|
private enum ModelRecordingState {
|
||||||
RECORDING,
|
RECORDING,
|
||||||
PAUSED,
|
PAUSED,
|
||||||
|
|
Loading…
Reference in New Issue