Skip to content

Commit

Permalink
Continued resizable implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukflug committed Apr 24, 2021
1 parent 1d12ccf commit f08d596
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.lukflug.panelstudio.component;

import java.awt.Dimension;

public interface IResizable {
public Dimension getSize();

public void setSize (Dimension size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.awt.Dimension;
import java.awt.Point;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

Expand All @@ -12,22 +11,22 @@
import com.lukflug.panelstudio.base.SimpleToggleable;
import com.lukflug.panelstudio.component.IComponent;
import com.lukflug.panelstudio.component.IFixedComponent;
import com.lukflug.panelstudio.component.IResizable;
import com.lukflug.panelstudio.component.IScrollSize;
import com.lukflug.panelstudio.container.IContainer;
import com.lukflug.panelstudio.theme.RendererTuple;
import com.lukflug.panelstudio.theme.ThemeTuple;
import com.lukflug.panelstudio.widget.ClosableComponent;
import com.lukflug.panelstudio.widget.ResizableComponent;

public class PanelAdder implements IComponentAdder {
protected IContainer<? super IFixedComponent> container;
protected boolean resizable,open;
protected boolean open;
protected IBoolean isVisible;
protected UnaryOperator<String> configName;
protected Dimension minSize=new Dimension(20,20);

public PanelAdder (IContainer<? super IFixedComponent> container, boolean resizable, boolean open, IBoolean isVisible, UnaryOperator<String> configName) {
public PanelAdder (IContainer<? super IFixedComponent> container, boolean open, IBoolean isVisible, UnaryOperator<String> configName) {
this.container=container;
this.resizable=resizable;
this.open=open;
this.isVisible=isVisible;
this.configName=configName;
Expand All @@ -37,34 +36,20 @@ public PanelAdder (IContainer<? super IFixedComponent> container, boolean resiza
public <S extends IComponent,T extends IComponent> void addComponent(S title, T content, ThemeTuple theme, Point position, int width, Supplier<Animation> animation) {
AnimatedToggleable toggle=new AnimatedToggleable(new SimpleToggleable(open),animation.get());
RendererTuple<Void> renderer=new RendererTuple<Void>(Void.class,theme);
Supplier<Dimension> sizeGetter=null;
Consumer<Dimension> sizeSetter=null;
if (resizable) {
Dimension dimension=new Dimension(width,getDefaultHeight());
sizeGetter=()->new Dimension(dimension);
sizeSetter=newDim->{
dimension.width=newDim.width;
dimension.height=newDim.height;
};
}
IFixedComponent draggable=ClosableComponent.createDraggableComponent(title,content,()->null,toggle,renderer,getScrollSize(sizeGetter,sizeSetter),position,width,true,configName.apply(content.getTitle()));
if (resizable) {
container.addComponent(new ResizableComponent<>(draggable,theme.theme.getResizeRenderer(),sizeGetter,sizeSetter),isVisible);
} else {
container.addComponent(draggable,isVisible);
}
IResizable size=getResizable(width);
container.addComponent(ResizableComponent.createResizableComponent(title,content,()->null,toggle,renderer,theme.theme.getResizeRenderer(),size,getScrollSize(size),position,width,true,configName.apply(content.getTitle())),isVisible);
}

@Override
public void addPopup(IFixedComponent popup) {
container.addComponent(popup,isVisible);
}

protected IScrollSize getScrollSize (Supplier<Dimension> sizeGetter, Consumer<Dimension> sizeSetter) {
return new IScrollSize() {};
protected IResizable getResizable (int width) {
return null;
}

protected int getDefaultHeight() {
return 0;
protected IScrollSize getScrollSize (IResizable size) {
return new IScrollSize(){};
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.lukflug.panelstudio.layout;

import java.awt.Dimension;
import java.awt.Point;
import java.util.function.Consumer;
import java.util.function.Supplier;

import com.lukflug.panelstudio.base.AnimatedToggleable;
Expand All @@ -13,47 +11,38 @@
import com.lukflug.panelstudio.component.HorizontalComponent;
import com.lukflug.panelstudio.component.IComponent;
import com.lukflug.panelstudio.component.IFixedComponent;
import com.lukflug.panelstudio.component.IResizable;
import com.lukflug.panelstudio.component.IScrollSize;
import com.lukflug.panelstudio.container.HorizontalContainer;
import com.lukflug.panelstudio.container.IContainer;
import com.lukflug.panelstudio.setting.ILabeled;
import com.lukflug.panelstudio.theme.ITheme;
import com.lukflug.panelstudio.theme.RendererTuple;
import com.lukflug.panelstudio.theme.ThemeTuple;
import com.lukflug.panelstudio.widget.ClosableComponent;
import com.lukflug.panelstudio.widget.ResizableComponent;
import com.lukflug.panelstudio.widget.ScrollBarComponent;

public class SinglePanelAdder implements IComponentAdder,IScrollSize {
public class SinglePanelAdder implements IComponentAdder {
protected IContainer<? super IFixedComponent> container;
protected boolean resizable;
protected IBoolean isVisible;
protected HorizontalContainer title,content;
protected final IScrollSize size;

public SinglePanelAdder (IContainer<? super IFixedComponent> container, boolean resizable, ILabeled label, ITheme theme, Point position, int width, Supplier<Animation> animation, IBoolean isVisible, String configName) {
public SinglePanelAdder (IContainer<? super IFixedComponent> container, ILabeled label, ITheme theme, Point position, int width, Supplier<Animation> animation, IBoolean isVisible, String configName) {
this.container=container;
this.resizable=resizable;
this.isVisible=isVisible;
title=new HorizontalContainer(label,theme.getContainerRenderer(-1,-1,true));
content=new HorizontalContainer(label,theme.getContainerRenderer(-1,-1,true));
AnimatedToggleable toggle=new AnimatedToggleable(new SimpleToggleable(true),animation.get());
RendererTuple<Void> renderer=new RendererTuple<Void>(Void.class,new ThemeTuple(theme,-1,-1));
Supplier<Dimension> sizeGetter=null;
Consumer<Dimension> sizeSetter=null;
if (resizable) {
Dimension dimension=new Dimension(width,getDefaultHeight());
sizeGetter=()->new Dimension(dimension);
sizeSetter=newDim->{
dimension.width=newDim.width;
dimension.height=newDim.height;
};
}
IFixedComponent draggable=ClosableComponent.createDraggableComponent(title,content,()->null,toggle,renderer,new IScrollSize(){},position,width,true,configName);
if (resizable) {
container.addComponent(new ResizableComponent<>(draggable,theme.getResizeRenderer(),sizeGetter,sizeSetter),isVisible);
} else {
container.addComponent(draggable,isVisible);
}
IResizable size=getResizable(width);
this.size=getScrollSize(size);
container.addComponent(ResizableComponent.createResizableComponent(title,content,()->null,toggle,renderer,theme.getResizeRenderer(),size,new IScrollSize() {
@Override
public int getComponentWidth(Context context) {
return SinglePanelAdder.this.size.getComponentWidth(context);
}
},position,width,true,configName),isVisible);
}

@Override
Expand All @@ -62,12 +51,7 @@ public <S extends IComponent,T extends IComponent> void addComponent(S title, T
this.content.addComponent(new HorizontalComponent<>(new ScrollBarComponent<Void,T>(content,theme.getScrollBarRenderer(Void.class),theme.getEmptySpaceRenderer(Void.class,false),theme.getEmptySpaceRenderer(Void.class,true)) {
@Override
public int getScrollHeight(Context context, int componentHeight) {
return SinglePanelAdder.this.getScrollHeight(context,componentHeight);
}

@Override
public int getComponentWidth(Context context) {
return SinglePanelAdder.this.getComponentWidth(context);
return size.getScrollHeight(context,componentHeight);
}

@Override
Expand All @@ -82,11 +66,11 @@ public void addPopup(IFixedComponent popup) {
container.addComponent(popup,isVisible);
}

protected IScrollSize getScrollSize (Supplier<Dimension> sizeGetter, Consumer<Dimension> sizeSetter) {
return new IScrollSize() {};
protected IResizable getResizable (int width) {
return null;
}

protected int getDefaultHeight() {
return 0;
protected IScrollSize getScrollSize (IResizable size) {
return new IScrollSize(){};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.lukflug.panelstudio.base.SimpleToggleable;
import com.lukflug.panelstudio.component.IComponent;
import com.lukflug.panelstudio.component.IFixedComponent;
import com.lukflug.panelstudio.component.IResizable;
import com.lukflug.panelstudio.component.IScrollSize;
import com.lukflug.panelstudio.container.IContainer;
import com.lukflug.panelstudio.container.VerticalContainer;
Expand All @@ -21,7 +22,7 @@
import com.lukflug.panelstudio.theme.RendererTuple;
import com.lukflug.panelstudio.theme.ThemeTuple;
import com.lukflug.panelstudio.widget.Button;
import com.lukflug.panelstudio.widget.ClosableComponent;
import com.lukflug.panelstudio.widget.ResizableComponent;

public class StackedPanelAdder implements IComponentAdder,IScrollSize {
protected IContainer<? super IFixedComponent> container;
Expand All @@ -35,7 +36,9 @@ public StackedPanelAdder (IContainer<? super IFixedComponent> container, ILabele
this.mode=mode;
this.isVisible=isVisible;
content=new VerticalContainer(label,theme.getContainerRenderer(-1,-1,true));
container.addComponent(ClosableComponent.createDraggableComponent(new Button(label,theme.getButtonRenderer(Void.class,-1,-1,true)),content,()->null,new AnimatedToggleable(new SimpleToggleable(true),animation.get()),new RendererTuple<Void>(Void.class,new ThemeTuple(theme,-1,-1)),this,position,width,true,configName),isVisible);
IResizable size=getResizable(width);
IScrollSize scrollSize=getScrollSize(size);
container.addComponent(ResizableComponent.createResizableComponent(new Button(label,theme.getButtonRenderer(Void.class,-1,-1,true)),content,()->null,new AnimatedToggleable(new SimpleToggleable(true),animation.get()),new RendererTuple<Void>(Void.class,new ThemeTuple(theme,-1,-1)),theme.getResizeRenderer(),size,scrollSize,position,width,true,configName),isVisible);
util=new ChildUtil(width,animation,new PopupTuple(popupPos,false,this));
}

Expand All @@ -48,4 +51,12 @@ public <S extends IComponent,T extends IComponent> void addComponent(S title, T
public void addPopup(IFixedComponent popup) {
container.addComponent(popup,isVisible);
}

protected IResizable getResizable (int width) {
return null;
}

protected IScrollSize getScrollSize (IResizable size) {
return new IScrollSize(){};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Supplier;

import com.lukflug.panelstudio.base.AnimatedToggleable;
Expand All @@ -13,24 +11,23 @@
import com.lukflug.panelstudio.component.IComponent;
import com.lukflug.panelstudio.component.IFixedComponent;
import com.lukflug.panelstudio.component.IFixedComponentProxy;
import com.lukflug.panelstudio.component.IResizable;
import com.lukflug.panelstudio.component.IScrollSize;
import com.lukflug.panelstudio.theme.IResizeBorderRenderer;
import com.lukflug.panelstudio.theme.RendererTuple;

public class ResizableComponent<T extends IFixedComponent> implements IFixedComponentProxy<T> {
protected T component;
protected IResizeBorderRenderer renderer;
protected Supplier<Dimension> sizeGetter;
protected Consumer<Dimension> sizeSetter;
protected IResizable size;
protected boolean resizing[]={false,false,false,false};
protected Point attachPoint;
protected Rectangle attachRect;
protected Point attachPoint=null;
protected Rectangle attachRect=null;

public ResizableComponent (T component, IResizeBorderRenderer renderer, Supplier<Dimension> sizeGetter, Consumer<Dimension> sizeSetter) {
public ResizableComponent (T component, IResizeBorderRenderer renderer, IResizable size) {
this.component=component;
this.renderer=renderer;
this.sizeGetter=sizeGetter;
this.sizeSetter=sizeSetter;
this.size=size;
}

@Override
Expand All @@ -44,7 +41,7 @@ public void handleButton (Context context, int button) {
IFixedComponentProxy.super.handleButton(context,button);
if (context.isClicked()) {
attachPoint=context.getInterface().getMouse();
attachRect=new Rectangle(getComponent().getPosition(context.getInterface()),sizeGetter.get());
attachRect=new Rectangle(getComponent().getPosition(context.getInterface()),size.getSize());
Rectangle r=context.getRect();
if (new Rectangle(r.x,r.y,r.width,renderer.getBorder()).contains(attachPoint)) {
resizing[0]=true;
Expand All @@ -66,24 +63,24 @@ public void handleButton (Context context, int button) {

@Override
public int getHeight (int height) {
return sizeGetter.get().height+2*renderer.getBorder();
return size.getSize().height+2*renderer.getBorder();
}

@Override
public Context getContext (Context context) {
if (resizing[0]) {
Point p=getComponent().getPosition(context.getInterface());
getComponent().setPosition(context.getInterface(),new Point(p.x,p.y+context.getInterface().getMouse().y-attachPoint.y));
sizeSetter.accept(new Dimension(attachRect.width,attachRect.height-context.getInterface().getMouse().y+attachPoint.y));
size.setSize(new Dimension(attachRect.width,attachRect.height-context.getInterface().getMouse().y+attachPoint.y));
} else if (resizing[1]) {
sizeSetter.accept(new Dimension(attachRect.width,attachRect.height+context.getInterface().getMouse().y-attachPoint.y));
size.setSize(new Dimension(attachRect.width,attachRect.height+context.getInterface().getMouse().y-attachPoint.y));
}
if (resizing[2]) {
Point p=getComponent().getPosition(context.getInterface());
getComponent().setPosition(context.getInterface(),new Point(p.x+context.getInterface().getMouse().x-attachPoint.x,p.y));
sizeSetter.accept(new Dimension(attachRect.width-context.getInterface().getMouse().x+attachPoint.x,attachRect.height));
size.setSize(new Dimension(attachRect.width-context.getInterface().getMouse().x+attachPoint.x,attachRect.height));
} else if (resizing[3]) {
sizeSetter.accept(new Dimension(attachRect.width+context.getInterface().getMouse().x-attachPoint.x,attachRect.height));
size.setSize(new Dimension(attachRect.width+context.getInterface().getMouse().x-attachPoint.x,attachRect.height));
}
Point p=context.getPos();
p.translate(renderer.getBorder(),renderer.getBorder());
Expand All @@ -105,28 +102,18 @@ public void setPosition (IInterface inter, Point position) {

@Override
public int getWidth (IInterface inter) {
return sizeGetter.get().width+2*renderer.getBorder();
return size.getSize().width+2*renderer.getBorder();
}

@Override
public T getComponent() {
return component;
}

public static <S extends IComponent,T extends IComponent,U> IFixedComponent createResizableComponent (S title, T content, Supplier<U> state, AnimatedToggleable open, RendererTuple<U> renderer, IResizeBorderRenderer resizeRenderer, BiFunction<Supplier<Dimension>,Consumer<Dimension>,IScrollSize> scrollSize, Point position, int width, int height, boolean savesState, String configName, boolean resizable) {
Supplier<Dimension> sizeGetter=null;
Consumer<Dimension> sizeSetter=null;
if (resizable) {
Dimension dimension=new Dimension(width,height);
sizeGetter=()->new Dimension(dimension);
sizeSetter=newDim->{
dimension.width=newDim.width;
dimension.height=newDim.height;
};
}
IFixedComponent draggable=ClosableComponent.createDraggableComponent(title,content,state,open,renderer,scrollSize.apply(sizeGetter,sizeSetter),position,width,true,configName);
if (resizable) {
return new ResizableComponent<>(draggable,resizeRenderer,sizeGetter,sizeSetter);
public static <S extends IComponent,T extends IComponent,U> IFixedComponent createResizableComponent (S title, T content, Supplier<U> state, AnimatedToggleable open, RendererTuple<U> renderer, IResizeBorderRenderer resizeRenderer, IResizable size, IScrollSize scrollSize, Point position, int width, boolean savesState, String configName) {
IFixedComponent draggable=ClosableComponent.createDraggableComponent(title,content,state,open,renderer,scrollSize,position,width,savesState,configName);
if (size!=null) {
return new ResizableComponent<>(draggable,resizeRenderer,size);
} else {
return draggable;
}
Expand Down

0 comments on commit f08d596

Please sign in to comment.