Skip to content

Commit

Permalink
Application: Change orientation of editor groups
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Aug 10, 2024
1 parent b792181 commit 9b9cb58
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.shade.platform.ui.editors.menu;

import com.shade.platform.ui.PlatformDataKeys;
import com.shade.platform.ui.editors.stack.EditorStackContainer;
import com.shade.platform.ui.menus.MenuItem;
import com.shade.platform.ui.menus.MenuItemContext;
import com.shade.platform.ui.menus.MenuItemRegistration;
import com.shade.util.NotNull;

import javax.swing.*;

import static com.shade.platform.ui.PlatformMenuConstants.*;

@MenuItemRegistration(parent = CTX_MENU_EDITOR_STACK_ID, name = "Change Split O&rientation", group = CTX_MENU_EDITOR_STACK_GROUP_SPLIT, order = 4000)
public class ChangeSplitOrientationItem extends MenuItem {
@Override
public void perform(@NotNull MenuItemContext ctx) {
EditorStackContainer container = ctx.getData(PlatformDataKeys.EDITOR_STACK_KEY).getContainer().getSplitContainer();
if (container == null) {
return;
}

if (container.getSplitOrientation() == JSplitPane.VERTICAL_SPLIT) {
container.setSplitOrientation(JSplitPane.HORIZONTAL_SPLIT);
} else {
container.setSplitOrientation(JSplitPane.VERTICAL_SPLIT);
}
}

@Override
public boolean isVisible(@NotNull MenuItemContext ctx) {
return ctx.getData(PlatformDataKeys.EDITOR_STACK_KEY).getContainer().getSplitContainer() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import static com.shade.platform.ui.PlatformMenuConstants.*;

@MenuItemRegistration(parent = CTX_MENU_EDITOR_STACK_ID, name = "Move to Opposite Group", group = CTX_MENU_EDITOR_STACK_GROUP_SPLIT, order = 3000)
@MenuItemRegistration(parent = CTX_MENU_EDITOR_STACK_ID, name = "&Move to Opposite Group", group = CTX_MENU_EDITOR_STACK_GROUP_SPLIT, order = 3000)
public class MoveToOppositeGroupItem extends MenuItem {
@Override
public void perform(@NotNull MenuItemContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,31 @@ private EditorStackContainer getParentContainer() {
}

@Nullable
public EditorStackContainer getOpposite(@NotNull EditorStackContainer container) {
if (isSplit()) {
EditorStackContainer left = getLeftContainer();
EditorStackContainer right = getRightContainer();

if (left == container) {
return right;
} else if (right == container) {
return left;
} else {
throw new IllegalStateException("Container is not a child of this container");
}
public EditorStackContainer getSplitContainer() {
EditorStackContainer container = this;
while (container != null && !container.isSplit()) {
container = container.getParentContainer();
}
return container;
}

EditorStackContainer parent = getParentContainer();
if (parent != null) {
return parent.getOpposite(container);
@Nullable
public EditorStackContainer getOpposite(@NotNull EditorStackContainer container) {
EditorStackContainer parent = getSplitContainer();
if (parent == null) {
return null;
}

return null;
EditorStackContainer left = parent.getLeftContainer();
EditorStackContainer right = parent.getRightContainer();

if (left == container) {
return right;
} else if (right == container) {
return left;
} else {
throw new IllegalStateException("Container is not a child of this container");
}
}

public boolean isSplit() {
Expand Down Expand Up @@ -158,6 +163,16 @@ public int getSplitOrientation() {
}
}

public void setSplitOrientation(int orientation) {
if (getComponent(0) instanceof JSplitPane pane) {
double location = getSplitPosition();
pane.setOrientation(orientation);
pane.setDividerLocation(location);
} else {
throw new IllegalStateException("Container is not split");
}
}

@NotNull
public Component[] getChildren() {
final Component component = getComponent(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.shade.platform.ui.editors.stack;

import com.google.gson.Gson;
import com.shade.platform.model.SaveableElement;
import com.shade.platform.model.Service;
import com.shade.platform.model.app.ApplicationManager;
Expand Down Expand Up @@ -38,7 +37,6 @@
@Persistent("EditorManager")
public class EditorStackManager implements EditorManager, PropertyChangeListener, PersistableComponent<EditorStackManager.Container> {
private static final Logger log = LoggerFactory.getLogger(EditorStackManager.class);
private static final Gson gson = new Gson();

private static final ServiceLoader<EditorProvider> EDITOR_PROVIDERS = ServiceLoader.load(EditorProvider.class);
private static final DataKey<EditorInput> NEW_INPUT_KEY = new DataKey<>("newInput", EditorInput.class);
Expand Down

0 comments on commit 9b9cb58

Please sign in to comment.