use of com.helospark.tactview.core.timeline.TimelineChannel in project tactview by helospark.
the class TimelineCanvasClickHandler method onClick.
public boolean onClick(TimelineCanvasClickHandlerRequest request) {
var optionalElement = request.selectedElement;
var event = request.event;
if (optionalElement.isPresent() && event.isStillSincePress() && event.getButton().equals(MouseButton.PRIMARY)) {
TimelineUiCacheElement element = optionalElement.get();
selectElementOnClick(event, element);
if (event.getClickCount() == 2 && optionalElement.get().elementType.equals(TimelineUiCacheType.EFFECT)) {
String effectId = optionalElement.get().elementId;
String clipId = timelineAccessor.findClipForEffect(effectId).get().getId();
StatelessEffect effect = timelineAccessor.findEffectById(effectId).get();
extendsClipToMaximizeLengthService.extendEffectToClipSize(clipId, effect);
}
return true;
} else if (event.isStillSincePress() && optionalElement.isEmpty()) {
if (event.getY() > TimelineCanvas.TIMELINE_TIMESCALE_HEIGHT) {
if (event.getButton().equals(MouseButton.PRIMARY)) {
selectedNodeRepository.clearAllSelectedItems();
} else if (event.getButton().equals(MouseButton.SECONDARY)) {
Optional<TimelineChannel> channel = request.channelSelected;
if (channel.isPresent()) {
TimelinePosition position = request.xPosition;
ContextMenu contextMenu = channelContextMenuAppender.createContextMenu(channel.get().getId(), Optional.of(position));
contextMenu.show(request.parentWindow, event.getScreenX(), event.getScreenY());
}
}
}
return false;
}
return false;
}
use of com.helospark.tactview.core.timeline.TimelineChannel in project tactview by helospark.
the class TimelineCanvasOnDragOverHandler method onClipDraggedToCanvas.
private void onClipDraggedToCanvas(DragEvent event, Dragboard db, TimelineCanvasOnDragOverHandlerRequest request) {
Optional<TimelineChannel> optionalChannel = request.channel;
if (optionalChannel.isPresent()) {
List<File> dbFiles = db.getFiles();
String dbString = db.getString();
double currentX = event.getX();
String channelId = optionalChannel.get().getId();
if (!isLoadingInprogress && dragRepository.currentlyDraggedClip() == null && ((dbFiles != null && !dbFiles.isEmpty()) || timelineDragAndDropHandler.isStringClip(db))) {
selectedNodeRepository.clearAllSelectedItems();
isLoadingInprogress = true;
try {
AddClipsCommand command = timelineDragAndDropHandler.buildAddClipsCommand(channelId, dbFiles, dbString, currentX);
AddClipsCommand result = commandInterpreter.synchronousSend(command);
List<String> addedClipIds = result.getAddedClipIds();
if (addedClipIds.size() > 0) {
TimelineInterval originalInterval = timelineAccessor.findClipById(addedClipIds.get(0)).get().getInterval();
selectedNodeRepository.clearAndSetSelectedClips(addedClipIds);
ClipDragInformation clipDragInformation = new ClipDragInformation(result.getRequestedPosition(), addedClipIds, channelId, 0, originalInterval);
dragRepository.onClipDragged(clipDragInformation);
}
db.clear();
} catch (Exception e1) {
e1.printStackTrace();
} finally {
isLoadingInprogress = false;
}
}
}
}
use of com.helospark.tactview.core.timeline.TimelineChannel in project tactview by helospark.
the class TimelineCanvasOnDragOverHandler method copyCurrentClipOnDrag.
private void copyCurrentClipOnDrag(List<String> clipIds, String channelId, TimelinePosition newX) {
TimelineChannel channel = timelineAccessor.findChannelWithId(channelId).get();
int relativeChannelMove = timelineAccessor.findChannelIndexByChannelId(channelId).get() - timelineAccessor.findChannelIndexForClipId(clipIds.get(0)).get();
List<TimelineClip> clips = new ArrayList<>();
List<TimelineClip> allClipsToCopyOriginal = timelineAccessor.resolveClipIdsWithAllLinkedClip(clipIds);
for (var clip : allClipsToCopyOriginal) {
int currentChannelIndex = timelineAccessor.findChannelIndexForClipId(clip.getId()).get();
int newChannelIndex = currentChannelIndex + relativeChannelMove;
if (newChannelIndex < 0 || newChannelIndex >= timelineAccessor.getChannels().size()) {
LOGGER.debug("Cannot copy clip, becase {} would be in non-existent channel {}", clip.getId(), newChannelIndex);
return;
}
}
Map<TimelineClip, TimelineClip> originalToNewClipMap = new HashMap<>();
List<ClipChannelPair> allClonedClips = allClipsToCopyOriginal.stream().filter(a -> !a.getId().equals(clipIds.get(0))).map(a -> {
TimelineClip newClip = a.cloneClip(CloneRequestMetadata.ofDefault());
int currentChannelIndex = timelineAccessor.findChannelIndexForClipId(a.getId()).get();
int newChannelIndex = currentChannelIndex + relativeChannelMove;
TimelineChannel newChannel = timelineAccessor.findChannelOnIndex(newChannelIndex).get();
originalToNewClipMap.put(a, newClip);
return new ClipChannelPair(newClip, newChannel);
}).collect(Collectors.toList());
TimelineClip clip = timelineAccessor.findClipById(clipIds.get(0)).get();
TimelineClip clonedClip = clip.cloneClip(CloneRequestMetadata.ofDefault());
originalToNewClipMap.put(clip, clonedClip);
AddExistingClipRequest request = AddExistingClipRequest.builder().withChannel(channel).withClipToAdd(clonedClip).withPosition(Optional.of(newX)).withAdditionalClipsToAdd(allClonedClips).build();
AddExistingClipsCommand addClipCommand = new AddExistingClipsCommand(request, timelineAccessor);
clips.add(clonedClip);
commandInterpreter.synchronousSend(addClipCommand);
setNewClipDragInformationAfterCopy(channelId, addClipCommand, clips, originalToNewClipMap);
}
use of com.helospark.tactview.core.timeline.TimelineChannel in project tactview by helospark.
the class FakeUi method pasteClipAt.
public TimelineClip pasteClipAt(int channelIndex, TimelinePosition position) {
TimelineChannel channel = timelineManagerAccessor.getChannels().get(0);
TimelineClip clonedClip = clipCopyPasteBoard.cloneClip(CloneRequestMetadata.ofDefault());
clonedClip.setInterval(clonedClip.getInterval().butMoveStartPostionTo(position));
timelineManagerAccessor.addClip(channel, clonedClip);
return clonedClip;
}
Aggregations