package com.gwesm.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Sash;
import com.gwesm.presenters.CharacterPresenter;
public class CharacterView extends SWTView {
CTabFolder characterTabFolder;
CharacterPresenter presenter;
Composite leftComposite;
Composite rightComposite;
public CharacterView(final Composite parent,
final CharacterPresenter presenter) {
super(parent, presenter);
this.presenter = presenter;
setLayout(new FillLayout());
this.leftComposite = new Composite(this, SWT.NONE);
final Sash sash = new Sash(this, SWT.VERTICAL);
this.rightComposite = new Composite(this, SWT.BORDER);
final FormLayout form = new FormLayout();
this.setLayout(form);
FormData leftCompositeData = new FormData();
leftCompositeData.left = new FormAttachment(0, 0);
leftCompositeData.right = new FormAttachment(sash, 0);
leftCompositeData.top = new FormAttachment(0, 0);
leftCompositeData.bottom = new FormAttachment(100, 0);
this.leftComposite.setLayoutData(leftCompositeData);
final int limit = 20;
final int percent = 20;
final FormData sashData = new FormData();
sashData.left = new FormAttachment(percent, 0);
sashData.top = new FormAttachment(0, 0);
sashData.bottom = new FormAttachment(100, 0);
sash.setLayoutData(sashData);
sash.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(final Event e) {
Rectangle sashRect = sash.getBounds();
Rectangle shellRect = CharacterView.this.getClientArea();
int right = shellRect.width - sashRect.width - limit;
e.x = Math.max(Math.min(e.x, right), limit);
if (e.x != sashRect.x) {
sashData.left = new FormAttachment(0, e.x);
CharacterView.this.layout();
}
}
});
FormData rightCompositeData = new FormData();
rightCompositeData.left = new FormAttachment(sash, 0);
rightCompositeData.right = new FormAttachment(100, 0);
rightCompositeData.top = new FormAttachment(0, 0);
rightCompositeData.bottom = new FormAttachment(100, 0);
this.rightComposite.setLayoutData(rightCompositeData);
refresh();
}
@Override
public void refresh() {
this.leftComposite.setLayout(new FillLayout());
StatisticsView statisticsView = new StatisticsView(this.leftComposite,
this.presenter.getStatsPresenter());
this.rightComposite.setLayout(new FillLayout());
CharacterProfessionsView characterProfessionsView = new CharacterProfessionsView(
this.rightComposite, this.presenter);
}
}