package bluej.stride.generic;

import bluej.Config;
import bluej.collect.StrideEditReason;
import bluej.stride.framedjava.ast.Loader;
import bluej.stride.framedjava.elements.CodeElement;
import bluej.stride.framedjava.frames.CodeFrame;
import bluej.stride.framedjava.frames.InterfaceFrame;
import bluej.stride.operations.AbstractOperation.Combine;
import bluej.stride.operations.FrameOperation;
import bluej.stride.slots.EditableSlot.MenuItemOrder;
import bluej.stride.slots.SlotLabel;
import bluej.utility.Utility;
import bluej.utility.javafx.JavaFXUtil;
import bluej.utility.javafx.SharedTransition;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Bounds;
import javafx.scene.control.CustomMenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import nu.xom.Element;
import threadchecker.OnThread;
import threadchecker.Tag;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public abstract class SingleLineFrame
extends Frame{    
   protected final SlotLabel previewSemi = new SlotLabel("", "preview-semi") {        
      @Override
       
      public void setView(View oldView, View v, SharedTransition animate)
       {
         if (v == View.JAVA_PREVIEW) {
            setText(";");

           
            
/*RotateTransition rt = new RotateTransition(Duration.millis(1000), previewSemi.getNode()); | |rt.setFromAngle(180.0); | |rt.setToAngle(360.0); | |rt.play(); getNode().opacityProperty().bind(animate.getProgress()); animate.addOnStopped(() -> getNode().opacityProperty().unbind()); } else { setText(""); } } }; private final ObservableList<FrameState> recentValues = FXCollections.observableArrayList(); public SingleLineFrame(InteractionManager editor, String caption, String stylePrefix) { super(editor, caption, stylePrefix); } @Override public double lowestCursorY() { Bounds sceneBounds = getNode().localToScene(getNode().getBoundsInLocal()); return sceneBounds.getMaxY(); } @Override public FrameCursor findCursor(double sceneX, double sceneY, FrameCursor prevCursor, FrameCursor nextCursor, List<Frame> exclude, boolean isDrag, boolean canDescend) { Bounds headBounds = getHeaderRow().getSceneBounds(); if (sceneY <= 2 + (headBounds.getMinY() + headBounds.getMaxY()) / 2) { return prevCursor; } return nextCursor; } protected boolean isInInterface(FrameCanvas parentCanvas) { if (parentCanvas == null) { bluej.utility.Debug.printCallStack("parentCanvas shouldn't be null"); return false; } return parentCanvas.getParent() instanceof InterfaceFrame; } @Override @OnThread(Tag.FXPlatform) public List getContextOperations() { List<FrameOperation> ops = new ArrayList<>(super.getContextOperations()); int i = 0; for (FrameState state : recentValues) { if (i > 0) { ops.add(new FrameOperation(getEditor(), "revert" + i, Combine.ONE) { @Override @OnThread(Tag.FXPlatform) protected void execute(List<Frame> frames) { editor.recordEdits(StrideEditReason.FLUSH); getParentCanvas().replaceBlock(SingleLineFrame.this, Loader.loadElement(state.value).createFrame(editor)); editor.recordEdits(StrideEditReason.UNDO_LOCAL); } @Override public List getLabels() { return Arrays.asList(l(Config.getString("frame.slot.recent"), MenuItemOrder.RECENT_VALUES), l("0", MenuItemOrder.RECENT_VALUES)); } @Override protected CustomMenuItem initializeCustomItem() { ImageView view = new ImageView(state.picture); CustomMenuItem item = new CustomMenuItem(view); return item; } @Override public boolean onlyOnContextMenu() { return true; } }); } i += 1; } return ops; } @Override @OnThread(Tag.FXPlatform) public void lostFocus() { super.lostFocus(); saveAsRecent(); } @OnThread(Tag.FXPlatform) protected void saveAsRecent() { if (!(this instanceof CodeFrame)) return; CodeElement code = ((CodeFrame)this).getCode(); if (code == null) return; Element el = code.toXML(); String xml = el.toXML(); int existingRecent = Utility.findIndex(recentValues, fs -> fs.cachedXML.equals(xml)); if (existingRecent != -1) { FrameState fs = recentValues.remove(existingRecent); recentValues.add(0, fs); } else { JavaFXUtil.runAfterCurrent(() -> { Image pic = takeShot(Arrays.asList(this), null); FrameState s = new FrameState(pic, el, xml); recentValues.add(0, s); while (recentValues.size() > 4) recentValues.remove(4); } }); } } private static class FrameState { public final Element value; public final String cachedXML; public final Image picture; public FrameState(Image picture, Element value, String xml) { this.picture = picture; this.value = new Element(value); this.cachedXML = xml; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; FrameState state = (FrameState) o; return cachedXML.equals(state.cachedXML); } @Override public int hashCode() { return cachedXML.hashCode(); } } }
top, use, map, abstract class SingleLineFrame

.   setView
.   SingleLineFrame
.   lowestCursorY
.   findCursor
.   isInInterface
.   getContextOperations
.   execute
.   getLabels
.   initializeCustomItem
.   onlyOnContextMenu
.   lostFocus
.   saveAsRecent

top, use, map, class FrameState

.   FrameState
.   equals
.   hashCode




257 neLoCode + 4 LoComm