forked from j62/ctbrec
Code cleanup
This commit is contained in:
parent
91b82b16a9
commit
92fa017b6b
|
@ -1,25 +1,8 @@
|
|||
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.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.GlobalThreadPool;
|
||||
import ctbrec.Model;
|
||||
|
@ -31,7 +14,6 @@ import ctbrec.ui.Icon;
|
|||
import ctbrec.ui.SiteUiFactory;
|
||||
import ctbrec.ui.action.EditGroupAction;
|
||||
import ctbrec.ui.action.PlayAction;
|
||||
import ctbrec.ui.action.StartRecordingAction;
|
||||
import ctbrec.ui.action.StopRecordingAction;
|
||||
import ctbrec.ui.controls.Dialogs;
|
||||
import ctbrec.ui.controls.RecordingIndicator;
|
||||
|
@ -50,7 +32,6 @@ import javafx.geometry.Pos;
|
|||
import javafx.scene.Cursor;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.image.Image;
|
||||
|
@ -69,6 +50,22 @@ import javafx.scene.text.TextAlignment;
|
|||
import javafx.util.Duration;
|
||||
import okhttp3.Request;
|
||||
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 {
|
||||
|
||||
|
@ -76,47 +73,46 @@ public class ThumbCell extends StackPane {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(ThumbCell.class);
|
||||
private static final Duration ANIMATION_DURATION = new Duration(250);
|
||||
|
||||
private static Image imgRecordIndicator = new Image(MEDIA_RECORD_16.url());
|
||||
private static Image imgPauseIndicator = new Image(MEDIA_PLAYBACK_PAUSE_16.url());
|
||||
private static Image imgBookmarkIndicator = new Image(BOOKMARK_16.url());
|
||||
private static Image imgGroupIndicator = new Image(Icon.GROUP_16.url());
|
||||
private static final Image imgRecordIndicator = new Image(MEDIA_RECORD_16.url());
|
||||
private static final Image imgPauseIndicator = new Image(MEDIA_PLAYBACK_PAUSE_16.url());
|
||||
private static final Image imgBookmarkIndicator = new Image(BOOKMARK_16.url());
|
||||
private static final Image imgGroupIndicator = new Image(Icon.GROUP_16.url());
|
||||
|
||||
private ModelRecordingState modelRecordingState = ModelRecordingState.NOT;
|
||||
private Model model;
|
||||
private StreamPreview streamPreview;
|
||||
private ImageView iv;
|
||||
private Rectangle resolutionBackground;
|
||||
private final Model model;
|
||||
private final StreamPreview streamPreview;
|
||||
private final ImageView iv;
|
||||
private final Rectangle resolutionBackground;
|
||||
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 Rectangle nameBackground;
|
||||
private Rectangle topicBackground;
|
||||
private Rectangle selectionOverlay;
|
||||
private Text name;
|
||||
private Text topic;
|
||||
private Text resolutionTag;
|
||||
private Recorder recorder;
|
||||
private RecordingIndicator recordingIndicator;
|
||||
private Tooltip recordingIndicatorTooltip;
|
||||
private final Rectangle nameBackground;
|
||||
private final Rectangle topicBackground;
|
||||
private final Rectangle selectionOverlay;
|
||||
private final Text name;
|
||||
private final Text topic;
|
||||
private final Text resolutionTag;
|
||||
private final Recorder recorder;
|
||||
private final RecordingIndicator recordingIndicator;
|
||||
private final Tooltip recordingIndicatorTooltip;
|
||||
private StackPane previewTrigger;
|
||||
private StackPane groupIndicator;
|
||||
private Label groupIndicatorTooltipTrigger;
|
||||
private final StackPane groupIndicator;
|
||||
private final Label groupIndicatorTooltipTrigger;
|
||||
private int index = 0;
|
||||
ContextMenu popup;
|
||||
private static final Color colorNormal = Color.BLACK;
|
||||
private static final Color colorHighlight = Color.WHITE;
|
||||
private final Color colorRecording = new Color(0.8, 0.28, 0.28, .8);
|
||||
private SimpleBooleanProperty selectionProperty = new SimpleBooleanProperty(false);
|
||||
private double imgAspectRatio = 3.0 / 4.0;
|
||||
private SimpleBooleanProperty preserveAspectRatio = new SimpleBooleanProperty(true);
|
||||
private final SimpleBooleanProperty selectionProperty = new SimpleBooleanProperty(false);
|
||||
private double imgAspectRatio;
|
||||
private final SimpleBooleanProperty preserveAspectRatio = new SimpleBooleanProperty(true);
|
||||
|
||||
private ObservableList<Node> thumbCellList;
|
||||
private final ObservableList<Node> thumbCellList;
|
||||
private boolean mouseHovering = false;
|
||||
private boolean recording = false;
|
||||
private boolean recording;
|
||||
static LoadingCache<Model, int[]> resolutionCache = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(5, TimeUnit.MINUTES)
|
||||
.maximumSize(10000)
|
||||
.build(CacheLoader.from(ThumbCell::getStreamResolution));
|
||||
private ThumbOverviewTab parent;
|
||||
private final ThumbOverviewTab parent;
|
||||
private CompletableFuture<Boolean> startPreview;
|
||||
|
||||
public ThumbCell(ThumbOverviewTab parent, Model model, Recorder recorder, double aspectRatio) {
|
||||
|
@ -259,24 +255,24 @@ public class ThumbCell extends StackPane {
|
|||
}
|
||||
|
||||
private void recordingInidicatorClicked(MouseEvent evt) {
|
||||
switch(modelRecordingState) {
|
||||
case RECORDING:
|
||||
pauseResumeAction(true);
|
||||
break;
|
||||
case PAUSED:
|
||||
pauseResumeAction(false);
|
||||
break;
|
||||
case BOOKMARKED:
|
||||
forgetModel();
|
||||
break;
|
||||
default:
|
||||
switch (modelRecordingState) {
|
||||
case RECORDING:
|
||||
pauseResumeAction(true);
|
||||
break;
|
||||
case PAUSED:
|
||||
pauseResumeAction(false);
|
||||
break;
|
||||
case BOOKMARKED:
|
||||
forgetModel();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
private void forgetModel() {
|
||||
new StopRecordingAction(this, List.of(model), recorder)
|
||||
.execute()
|
||||
.thenAccept(r -> update());
|
||||
.execute()
|
||||
.thenAccept(r -> update());
|
||||
}
|
||||
|
||||
private Node createPreviewTrigger() {
|
||||
|
@ -321,7 +317,7 @@ public class ThumbCell extends StackPane {
|
|||
}
|
||||
}, GlobalThreadPool.get()).whenComplete((result, exception) -> {
|
||||
startPreview = null;
|
||||
if (result.booleanValue()) {
|
||||
if (Boolean.TRUE.equals(result)) {
|
||||
setPreviewVisible(previewTrigger, true);
|
||||
}
|
||||
});
|
||||
|
@ -443,7 +439,8 @@ public class ThumbCell extends StackPane {
|
|||
if (resp.isSuccessful()) {
|
||||
double width = 480;
|
||||
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) {
|
||||
Platform.runLater(() -> {
|
||||
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) {
|
||||
setCursor(Cursor.WAIT);
|
||||
GlobalThreadPool.submit(() -> {
|
||||
|
@ -625,7 +614,7 @@ public class ThumbCell extends StackPane {
|
|||
topic.setText(txt);
|
||||
recorder.getModelGroup(model).ifPresentOrElse(group -> {
|
||||
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));
|
||||
groupIndicator.setVisible(true);
|
||||
}, () -> groupIndicator.setVisible(false));
|
||||
|
@ -658,11 +647,8 @@ public class ThumbCell extends StackPane {
|
|||
return false;
|
||||
ThumbCell other = (ThumbCell) obj;
|
||||
if (model == null) {
|
||||
if (other.model != null)
|
||||
return false;
|
||||
} else if (!model.equals(other.model))
|
||||
return false;
|
||||
return true;
|
||||
return other.model == null;
|
||||
} else return model.equals(other.model);
|
||||
}
|
||||
|
||||
public void setThumbWidth(int width) {
|
||||
|
@ -722,12 +708,6 @@ public class ThumbCell extends StackPane {
|
|||
return preserveAspectRatio;
|
||||
}
|
||||
|
||||
void addInPausedState() {
|
||||
model.setSuspended(true);
|
||||
model.setMarkedForLaterRecording(false);
|
||||
startStopAction(true);
|
||||
}
|
||||
|
||||
private enum ModelRecordingState {
|
||||
RECORDING,
|
||||
PAUSED,
|
||||
|
|
Loading…
Reference in New Issue