use of org.apache.pivot.wtk.Component in project pivot by apache.
the class TerraPanoramaSkin method mouseWheel.
@Override
public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount, int wheelRotation, int x, int y) {
boolean consumed = false;
Panorama panorama = (Panorama) getComponent();
Component view = panorama.getView();
if (view != null) {
// presssed while the mouse wheel was scrolled
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
// Treat the mouse wheel as a horizontal scroll event
int previousScrollLeft = panorama.getScrollLeft();
int newScrollLeft = previousScrollLeft + (scrollAmount * wheelRotation * (int) INITIAL_SCROLL_DISTANCE);
if (wheelRotation > 0) {
int maxScrollLeft = getMaxScrollLeft();
newScrollLeft = Math.min(newScrollLeft, maxScrollLeft);
if (previousScrollLeft < maxScrollLeft) {
consumed = true;
}
} else {
newScrollLeft = Math.max(newScrollLeft, 0);
if (previousScrollLeft > 0) {
consumed = true;
}
}
panorama.setScrollLeft(newScrollLeft);
} else {
// Treat the mouse wheel as a vertical scroll event
int previousScrollTop = panorama.getScrollTop();
int newScrollTop = previousScrollTop + (scrollAmount * wheelRotation * (int) INITIAL_SCROLL_DISTANCE);
if (wheelRotation > 0) {
int maxScrollTop = getMaxScrollTop();
newScrollTop = Math.min(newScrollTop, maxScrollTop);
if (previousScrollTop < maxScrollTop) {
consumed = true;
}
} else {
newScrollTop = Math.max(newScrollTop, 0);
if (previousScrollTop > 0) {
consumed = true;
}
}
panorama.setScrollTop(newScrollTop);
}
}
return consumed;
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class TerraPanoramaSkin method getMaxScrollTop.
protected int getMaxScrollTop() {
int maxScrollTop = 0;
Panorama panorama = (Panorama) getComponent();
int height = getHeight();
Component view = panorama.getView();
if (view != null) {
maxScrollTop = Math.max(view.getHeight() - height, 0);
}
return maxScrollTop;
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class TerraPanoramaSkin method scrollTopChanged.
// Viewport events
@Override
public void scrollTopChanged(Viewport panorama, int previousScrollTop) {
Component view = panorama.getView();
if (view != null) {
int maxScrollTop = getMaxScrollTop();
int scrollTop = Math.min(panorama.getScrollTop(), maxScrollTop);
view.setLocation(view.getX(), -scrollTop);
updateScrollButtonVisibility();
}
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class TerraPromptSkin method install.
@Override
public void install(Component component) {
super.install(component);
Prompt prompt = (Prompt) component;
prompt.setPreferredWidth(320);
prompt.setMinimumWidth(160);
prompt.getPromptListeners().add(this);
// Load the prompt content
BXMLSerializer bxmlSerializer = new BXMLSerializer();
Component content;
try {
content = (Component) bxmlSerializer.readObject(TerraPromptSkin.class, "terra_prompt_skin.bxml");
} catch (Exception exception) {
throw new RuntimeException(exception);
}
prompt.setContent(content);
typeImageView = (ImageView) bxmlSerializer.getNamespace().get("typeImageView");
messageLabel = (Label) bxmlSerializer.getNamespace().get("messageLabel");
messageBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("messageBoxPane");
optionButtonBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("optionButtonBoxPane");
for (Object option : prompt.getOptions()) {
PushButton optionButton = new PushButton(option);
optionButton.setStyleName(BUTTON_STYLE_NAME);
optionButton.getButtonPressListeners().add(optionButtonPressListener);
optionButtonBoxPane.add(optionButton);
}
messageTypeChanged(prompt, null);
messageChanged(prompt, null);
bodyChanged(prompt, null);
}
use of org.apache.pivot.wtk.Component in project pivot by apache.
the class TerraRollupSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
Rollup rollup = (Rollup) getComponent();
Component heading = rollup.getHeading();
int baseline = -1;
if (heading != null) {
int headingWidth, headingHeight;
if (fill) {
headingWidth = Math.max(width - rollupButton.getPreferredWidth(-1) - buffer, 0);
headingHeight = heading.getPreferredHeight(headingWidth);
} else {
Dimensions headingPreferredSize = heading.getPreferredSize();
headingWidth = headingPreferredSize.width;
headingHeight = headingPreferredSize.height;
}
baseline = heading.getBaseline(headingWidth, headingHeight);
}
return baseline;
}
Aggregations