package bluej.stride.slots;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import bluej.stride.framedjava.ast.JavaFragment;
import bluej.stride.framedjava.slots.UnderlineContainer;
import bluej.utility.javafx.FXRunnable;
import bluej.utility.javafx.binding.DeepListBinding;
import javafx.beans.value.ObservableBooleanValue;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import bluej.stride.framedjava.errors.CodeError;
import bluej.stride.framedjava.errors.ErrorShower;
import bluej.stride.framedjava.slots.ExpressionSlot;
import bluej.stride.generic.Frame;
import bluej.stride.generic.RecallableFocus;
import bluej.utility.Utility;
import bluej.utility.javafx.ErrorUnderlineCanvas.UnderlineInfo;
import bluej.utility.javafx.JavaFXUtil;
import bluej.utility.javafx.binding.ConcatListBinding;
import threadchecker.OnThread;
import threadchecker.Tag;
| EditableSlot is used to access functionality common to all slots. EditableSlot extends HeaderItem,
| but also several other interfaces (see their documentation).
|
public interface EditableSlot
extends HeaderItem, RecallableFocus, UnderlineInfo, ErrorShower, UnderlineContainer{
| Requests focus on the slot, at whatever position makes sense (should not perform a select-all)
|
default public void requestFocus()
{
requestFocus(Focus.LEFT);
}
| Requests focus at the given position.
| @param on Where to focus: LEFT, RIGHT or ALL
| @see bluej.stride.slots.Focus
|
public void requestFocus(Focus on);
| Called by the editor to indicate that we have lost focus. We can't just listen to when our components
| lose focus, because focus may transfer from one component of the slot to another in the same slot (e.g. in
| expression slots, cursor may move between text fields in the expression), so a component losing focus doesn't
| always mean the whole slot has lost focus. The editor keeps track of who has focus, and calls this method
| on all slots which do not have focus.
|
| Note that this method may currently be called on a slot which did not have focus -- it is more like
| "notifyHasNoFocus" than "youHadFocusButJustLostIt"
|*/
@OnThread(Tag.FXPlatform)
public void lostFocus();
/**
* A property reflecting whether the field is "effectively focused"
*
* "Effectively focused" means that either the field has actual JavaFX GUI
* focus, or code completion is showing for this slot, meaning it doesn't
* have GUI focus, but for our purposes it is logically the focus owner
| within the editor.
|
public ObservableBooleanValue effectivelyFocusedProperty();
| Called to cleanup any state or overlays when the slot is going to be removed.
| TODO May not be needed any more; might be covered by lostFocus
|
public void cleanup();
| Called when the whole top level frame has been saved, so slots can perform any necessary updates
| (e.g. method prompts)
|
@OnThread(Tag.FXPlatform)
public void saved();
default public @Override
EditableSlot asEditable() { return this;
}
| Gets the parent Frame of the slot
| @return The parent frame
|
public Frame getParentFrame();
| A method used to check/access this slot as an ExpressionSlot (nicer than using cast/instanceof)
| @return Get this slot as an expression slot (type cast)
|
default public ExpressionSlot asExpressionSlot()
{
return null;
}
| Checks whether the slot is blank or close enough. Definition is context-dependent on the slot
| @return True, if the slot is (essentially) blank
|
public boolean isAlmostBlank();
| The amount of effort (roughly, keypresses) required to create this slot's content
|
| See the documentation of Frame.calculateEffort for more information.
|
public int calculateEffort();
public static enum TopLevelMenu { EDIT, VIEW
}
public static enum MenuItemOrder
{
CLOSE(0),
UNDO(10), REDO(10),
RECENT_VALUES(20),
CUT(30), COPY(30), PASTE(30),
DELETE(40), ENABLE_FRAME(40), DISABLE_FRAME(40),
INSERT_FRAME(60),
TRANSFORM(70), TOGGLE_BOOLEAN(70), TOGGLE_ABSTRACT(70), TOGGLE_EXTENDS(70), TOGGLE_IMPLEMENTS(70), OVERRIDE(70),
GOTO_DEFINITION(80), GOTO_OVERRIDE(80), SHOW_HIDE_USES(80);
private final int block;
MenuItemOrder(int block)
{
this.block = block;
}
public SortedMenuItem item(MenuItem fxItem)
{
return new SortedMenuItem(fxItem, this);
}
}
public static class SortedMenuItem
{
private final MenuItem item;
private MenuItemOrder sortOrder;
private SortedMenuItem(MenuItem item, MenuItemOrder sortOrder)
{
this.item = item;
this.sortOrder = sortOrder;
}
public MenuItem getItem()
{
return item;
}
private static final Comparator<SortedMenuItem> COMPARATOR = (a, b) -> a.sortOrder.compareTo(b.sortOrder);
public MenuItemOrder getMenuItemOrder()
{
return sortOrder;
}
public static ObservableList
top,
use,
map,
interface EditableSlot
. requestFocus
. requestFocus
. effectivelyFocusedProperty
. cleanup
. saved
. getParentFrame
. asExpressionSlot
. isAlmostBlank
. calculateEffort
. item
top,
use,
map,
class SortedMenuItem
. SortedMenuItem
. getItem
. getMenuItemOrder
. sortAndAddDividers
. calculateValues
. getListenTargets
. calculateList
top,
use,
map,
class MenuItems
. MenuItems
. onShowing
. onHidden
. concat
. onShowing
. onHidden
. makeSubMenu
. makeContextMenu
. makeContextMenu
. isEmpty
. getItems
. getMenuItems
. getRelevantNodeForError
. addError
. removeOldErrors
. flagErrorsAsOld
. getCurrentErrors
. getSlotElement
. setEditable
. isEditable
338 neLoCode
+ 55 LoComm