Search in sources :

Example 1 with ClipDragInformation

use of com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation in project tactview by helospark.

the class TimelineCanvasOnDragOverHandler method setNewClipDragInformationAfterCopy.

private void setNewClipDragInformationAfterCopy(String channelId, AddExistingClipsCommand commands, List<TimelineClip> clips, Map<TimelineClip, TimelineClip> originalToNewClipMap) {
    TimelineClip clip = clips.get(0);
    if (commands.isSuccess()) {
        dragRepository.currentlyDraggedClip().setShouldCopyClip(false);
        List<String> elementIds = clips.stream().map(a -> a.getId()).collect(Collectors.toList());
        ClipDragInformation clipDragInformation = new ClipDragInformation(clip.getGlobalInterval().getStartPosition(), elementIds, channelId, dragRepository.getClipDragInformation().getAnchorPointX(), clip.getGlobalInterval());
        relinkClips(originalToNewClipMap);
        dragRepository.onClipDragged(clipDragInformation);
    }
}
Also used : Component(com.helospark.lightdi.annotation.Component) UiCommandInterpreterService(com.helospark.tactview.ui.javafx.UiCommandInterpreterService) TimelineUiCacheElement(com.helospark.tactview.ui.javafx.uicomponents.canvasdraw.domain.TimelineUiCacheElement) MouseEvent(javafx.scene.input.MouseEvent) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ClipDragInformation(com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation) DragEvent(javafx.scene.input.DragEvent) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) TransferMode(javafx.scene.input.TransferMode) ArrayList(java.util.ArrayList) Dragboard(javafx.scene.input.Dragboard) CloneRequestMetadata(com.helospark.tactview.core.clone.CloneRequestMetadata) Map(java.util.Map) TimelineChannel(com.helospark.tactview.core.timeline.TimelineChannel) AddExistingClipsCommand(com.helospark.tactview.ui.javafx.commands.impl.AddExistingClipsCommand) StatelessEffect(com.helospark.tactview.core.timeline.StatelessEffect) CurrentlyPressedKeyRepository(com.helospark.tactview.ui.javafx.key.CurrentlyPressedKeyRepository) AddClipsCommand(com.helospark.tactview.ui.javafx.commands.impl.AddClipsCommand) ClipChannelPair(com.helospark.tactview.core.timeline.ClipChannelPair) EffectDragAdder(com.helospark.tactview.ui.javafx.uicomponents.EffectDragAdder) AddExistingClipRequest(com.helospark.tactview.core.timeline.AddExistingClipRequest) DragRepository(com.helospark.tactview.ui.javafx.repository.DragRepository) KeyCode(javafx.scene.input.KeyCode) Logger(org.slf4j.Logger) SelectedNodeRepository(com.helospark.tactview.ui.javafx.repository.SelectedNodeRepository) TimelineDragAndDropHandler(com.helospark.tactview.ui.javafx.uicomponents.TimelineDragAndDropHandler) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) TimelineState(com.helospark.tactview.ui.javafx.uicomponents.TimelineState) Collectors(java.util.stream.Collectors) File(java.io.File) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) TimelineUiCacheType(com.helospark.tactview.ui.javafx.uicomponents.canvasdraw.domain.TimelineUiCacheType) List(java.util.List) LinkClipRepository(com.helospark.tactview.core.timeline.LinkClipRepository) TimelineManagerAccessor(com.helospark.tactview.core.timeline.TimelineManagerAccessor) Entry(java.util.Map.Entry) Optional(java.util.Optional) ClipDragInformation(com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip)

Example 2 with ClipDragInformation

use of com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation in project tactview by helospark.

the class TimelineCanvasElementClickHandler method onElementClick.

public void onElementClick(MouseEvent event, double currentX, TimelineUiCacheElement element) {
    boolean isResizing = isResizing(element, event.getX());
    if (element.elementType.equals(TimelineUiCacheType.CLIP)) {
        TimelineClip clip = timelineAccessor.findClipById(element.elementId).get();
        String channelId = timelineAccessor.findChannelForClipId(element.elementId).get().getId();
        double clipPositionAsDouble = clip.getGlobalInterval().getStartPosition().getSeconds().doubleValue();
        if (isResizing) {
            boolean resizingLeft = isResizingLeft(element, event.getX());
            TimelinePosition originalPosition = resizingLeft ? clip.getGlobalInterval().getStartPosition() : clip.getGlobalInterval().getEndPosition();
            List<String> clipIds = timelineAccessor.findLinkedClipsWithSameInterval(element.elementId);
            ClipDragInformation clipDragInformation = new ClipDragInformation(originalPosition, clipIds, channelId, currentX - clipPositionAsDouble, clip.getGlobalInterval());
            dragRepository.onClipResizing(clipDragInformation, resizingLeft ? DragDirection.LEFT : DragDirection.RIGHT);
        } else {
            ClipDragInformation clipDragInformation = new ClipDragInformation(clip.getGlobalInterval().getStartPosition(), List.of(element.elementId), channelId, currentX - clipPositionAsDouble, clip.getGlobalInterval());
            if (currentlyPressedKeyRepository.isKeyModifiersMatch(copyOnDragHotkey.getCombination())) {
                clipDragInformation.setShouldCopyClip(true);
            }
            dragRepository.onClipDragged(clipDragInformation);
        }
    } else {
        TimelineClip clip = timelineAccessor.findClipForEffect(element.elementId).get();
        StatelessEffect effect = timelineAccessor.findEffectById(element.elementId).get();
        if (isResizing) {
            boolean resizingLeft = isResizingLeft(element, event.getX());
            TimelinePosition originalPosition = resizingLeft ? effect.getGlobalInterval().getStartPosition() : effect.getGlobalInterval().getEndPosition();
            EffectDragInformation effectDragInformation = new EffectDragInformation(clip.getId(), effect.getId(), originalPosition, currentX);
            dragRepository.onEffectResized(effectDragInformation, resizingLeft ? DragDirection.LEFT : DragDirection.RIGHT);
        } else {
            TimelinePosition originalPosition = effect.getGlobalInterval().getStartPosition();
            double clipStartSecondDouble = effect.getGlobalInterval().getStartPosition().getSeconds().doubleValue();
            EffectDragInformation effectDragInformation = new EffectDragInformation(clip.getId(), effect.getId(), originalPosition, currentX - clipStartSecondDouble);
            dragRepository.onEffectDragged(effectDragInformation);
        }
    }
}
Also used : ClipDragInformation(com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation) StatelessEffect(com.helospark.tactview.core.timeline.StatelessEffect) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) EffectDragInformation(com.helospark.tactview.ui.javafx.uicomponents.EffectDragInformation) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip)

Example 3 with ClipDragInformation

use of com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation 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;
            }
        }
    }
}
Also used : TimelineChannel(com.helospark.tactview.core.timeline.TimelineChannel) ClipDragInformation(com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) File(java.io.File) AddClipsCommand(com.helospark.tactview.ui.javafx.commands.impl.AddClipsCommand)

Example 4 with ClipDragInformation

use of com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation in project tactview by helospark.

the class TimelineDragAndDropHandler method createMoveClipCommand.

public ClipMovedCommand createMoveClipCommand(String channelId, boolean revertable, TimelinePosition position) {
    ClipDragInformation currentlyDraggedClip = dragRepository.currentlyDraggedClip();
    if (currentlyDraggedClip != null) {
        String clipId = currentlyDraggedClip.getClipIds().get(0);
        if (position.isLessThan(TimelinePosition.ofZero())) {
            position = TimelinePosition.ofZero();
        }
        Set<String> clipIds = new HashSet<>(selectedNodeRepository.getSelectedClipIds());
        Set<TimelineClip> rippleElements = new HashSet<>();
        Optional<TimelinePosition> leftestPositionOptional = Streams.concat(clipIds.stream(), Stream.of(clipId)).flatMap(clip -> timelineManager.findClipById(clip).stream()).sorted((clip1, clip2) -> clip1.getInterval().getStartPosition().compareTo(clip2.getInterval().getStartPosition())).findFirst().map(a -> a.getInterval().getStartPosition());
        if (leftestPositionOptional.isEmpty()) {
            return null;
        }
        var leftestPosition = leftestPositionOptional.get();
        if (timelineEditModeRepository.getMode().equals(TimelineEditMode.ALL_CHANNEL_RIPPLE)) {
            rippleElements.addAll(timelineManager.findClipsRightFromPositionAndOnChannelIgnoring(leftestPosition, timelineManager.getAllChannelIndices(), List.of()));
        } else if (timelineEditModeRepository.getMode().equals(TimelineEditMode.SINGLE_CHANNEL_RIPPLE)) {
            List<Integer> channels = Streams.concat(clipIds.stream(), Stream.of(clipId)).flatMap(clip -> timelineManager.findChannelForClipId(clip).stream()).flatMap(channel -> timelineManager.findChannelIndexByChannelId(channel.getId()).stream()).collect(Collectors.toList());
            rippleElements.addAll(timelineManager.findClipsRightFromPositionAndOnChannelIgnoring(leftestPosition, channels, List.of()));
        }
        rippleElements.stream().forEach(element -> clipIds.add(element.getId()));
        boolean useSpecialPoints = timelineEditModeRepository.isMagnetEditModeEnabled(currentlyPressedKeyRepository.isKeyDown(SPECIAL_POSITION_DISABLE_KEY));
        return ClipMovedCommand.builder().withIsRevertable(revertable).withClipId(clipId).withAdditionalClipIds(new ArrayList<>(clipIds)).withNewPosition(position).withPreviousPosition(currentlyDraggedClip.getOriginalPosition()).withOriginalChannelId(currentlyDraggedClip.getOriginalChannelId()).withNewChannelId(channelId).withTimelineManager(timelineManager).withEnableJumpingToSpecialPosition(useSpecialPoints).withMoreMoveExpected(!revertable).withMaximumJumpLength(new TimelineLength(timelineState.pixelsToSecondsWithZoom(MAXIMUM_SPECIAL_POINT_JUMP_LENGTH_IN_PIXELS).getSeconds())).withAdditionalPositions(List.of(uiTimelineManager.getCurrentPosition())).build();
    } else {
        return null;
    }
}
Also used : Component(com.helospark.lightdi.annotation.Component) ClipInsertCommand(com.helospark.tactview.ui.javafx.commands.impl.ClipInsertCommand) TimelineEditModeRepository(com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditModeRepository) DragDirection(com.helospark.tactview.ui.javafx.repository.DragRepository.DragDirection) UiCommandInterpreterService(com.helospark.tactview.ui.javafx.UiCommandInterpreterService) ClipDragInformation(com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) ClipMovedCommand(com.helospark.tactview.ui.javafx.commands.impl.ClipMovedCommand) ArrayList(java.util.ArrayList) ChangeClipForEffectCommand(com.helospark.tactview.ui.javafx.commands.impl.ChangeClipForEffectCommand) HashSet(java.util.HashSet) Dragboard(javafx.scene.input.Dragboard) ClipResizedCommand(com.helospark.tactview.ui.javafx.commands.impl.ClipResizedCommand) CurrentlyPressedKeyRepository(com.helospark.tactview.ui.javafx.key.CurrentlyPressedKeyRepository) AddClipsCommand(com.helospark.tactview.ui.javafx.commands.impl.AddClipsCommand) UiTimelineManager(com.helospark.tactview.ui.javafx.UiTimelineManager) EffectResizedCommand(com.helospark.tactview.ui.javafx.commands.impl.EffectResizedCommand) DragRepository(com.helospark.tactview.ui.javafx.repository.DragRepository) KeyCode(javafx.scene.input.KeyCode) TimelineEditMode(com.helospark.tactview.ui.javafx.repository.timelineeditmode.TimelineEditMode) Logger(org.slf4j.Logger) SelectedNodeRepository(com.helospark.tactview.ui.javafx.repository.SelectedNodeRepository) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) Set(java.util.Set) Slf4j(com.helospark.tactview.core.util.logger.Slf4j) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength) MessagingService(com.helospark.tactview.core.util.messaging.MessagingService) File(java.io.File) List(java.util.List) Stream(java.util.stream.Stream) TimelineManagerAccessor(com.helospark.tactview.core.timeline.TimelineManagerAccessor) Optional(java.util.Optional) ClipDragInformation(com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation) ArrayList(java.util.ArrayList) List(java.util.List) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) HashSet(java.util.HashSet) TimelineClip(com.helospark.tactview.core.timeline.TimelineClip) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength)

Example 5 with ClipDragInformation

use of com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation in project tactview by helospark.

the class TimelineDragAndDropHandler method resizeClip.

public void resizeClip(TimelinePosition position, boolean revertable, TimelinePosition relativeMove) {
    ClipDragInformation currentlyDraggedEffect = dragRepository.currentlyDraggedClip();
    if (currentlyDraggedEffect != null) {
        List<String> clipId = currentlyDraggedEffect.getClipIds();
        boolean useSpecialPoints = timelineEditModeRepository.isMagnetEditModeEnabled(currentlyPressedKeyRepository.isKeyDown(SPECIAL_POSITION_DISABLE_KEY));
        ClipResizedCommand command = ClipResizedCommand.builder().withClipIds(clipId).withLeft(dragRepository.getDragDirection().equals(DragRepository.DragDirection.LEFT)).withPosition(position).withOriginalPosition(currentlyDraggedEffect.getOriginalPosition()).withOriginalInterval(currentlyDraggedEffect.getOriginalInterval()).withRevertable(revertable).withTimelineManager(timelineManager).withUseSpecialPoints(useSpecialPoints).withMinimumSize(new TimelineLength(timelineState.pixelsToSecondsWithZoom(MINIMUM_CLIP_SIZE).getSeconds())).withMoreResizeExpected(!revertable).withMaximumJumpLength(new TimelineLength(timelineState.pixelsToSecondsWithZoom(MAXIMUM_SPECIAL_POINT_JUMP_LENGTH_IN_PIXELS).getSeconds())).withTimelineEditMode(timelineEditModeRepository.getMode()).withRelativeMove(relativeMove).build();
        commandInterpreter.sendWithResult(command).join();
    }
}
Also used : ClipDragInformation(com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation) ClipResizedCommand(com.helospark.tactview.ui.javafx.commands.impl.ClipResizedCommand) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength)

Aggregations

ClipDragInformation (com.helospark.tactview.ui.javafx.repository.drag.ClipDragInformation)5 TimelineClip (com.helospark.tactview.core.timeline.TimelineClip)3 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)3 AddClipsCommand (com.helospark.tactview.ui.javafx.commands.impl.AddClipsCommand)3 File (java.io.File)3 Component (com.helospark.lightdi.annotation.Component)2 StatelessEffect (com.helospark.tactview.core.timeline.StatelessEffect)2 TimelineChannel (com.helospark.tactview.core.timeline.TimelineChannel)2 TimelineInterval (com.helospark.tactview.core.timeline.TimelineInterval)2 TimelineLength (com.helospark.tactview.core.timeline.TimelineLength)2 TimelineManagerAccessor (com.helospark.tactview.core.timeline.TimelineManagerAccessor)2 UiCommandInterpreterService (com.helospark.tactview.ui.javafx.UiCommandInterpreterService)2 ClipResizedCommand (com.helospark.tactview.ui.javafx.commands.impl.ClipResizedCommand)2 CurrentlyPressedKeyRepository (com.helospark.tactview.ui.javafx.key.CurrentlyPressedKeyRepository)2 DragRepository (com.helospark.tactview.ui.javafx.repository.DragRepository)2 SelectedNodeRepository (com.helospark.tactview.ui.javafx.repository.SelectedNodeRepository)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2