All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wings.plaf.css.PageScrollerCG Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2005 Your Corporation. All Rights Reserved.
 */
package org.wings.plaf.css;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wings.*;
import org.wings.io.Device;

import java.io.IOException;

/**
 * CG for a pagescroller.
 *
 * @author holger
 */
public final class PageScrollerCG extends AbstractComponentCG implements org.wings.plaf.PageScrollerCG {
    private static final long serialVersionUID = 1L;

    private final static Logger log = LoggerFactory.getLogger(PageScrollerCG.class);

    public static final int FORWARD = 0;
    public static final int BACKWARD = 1;
    public static final int FORWARD_BLOCK = 2;
    public static final int BACKWARD_BLOCK = 3;
    public static final int FIRST = 4;
    public static final int LAST = 5;
    private final static SIcon[][][] DEFAULT_ICONS = new SIcon[2][6][2];

    static {
        String[] postfixes = new String[6];
        String[] prefixes = new String[6];
        for (int orientation = 0; orientation < 2; orientation++) {
            prefixes[BACKWARD] = "";
            prefixes[FORWARD] = "";
            prefixes[FIRST] = "Margin";
            prefixes[LAST] = "Margin";
            prefixes[FORWARD_BLOCK] = "Block";
            prefixes[BACKWARD_BLOCK] = "Block";
            if (orientation == SConstants.VERTICAL) {
                postfixes[BACKWARD] = "Up";
                postfixes[FORWARD] = "Down";
                postfixes[FIRST] = "Up";
                postfixes[LAST] = "Down";
                postfixes[BACKWARD_BLOCK] = "Up";
                postfixes[FORWARD_BLOCK] = "Down";
            } else {
                postfixes[BACKWARD] = "Left";
                postfixes[FORWARD] = "Right";
                postfixes[FIRST] = "Left";
                postfixes[LAST] = "Right";
                postfixes[BACKWARD_BLOCK] = "Left";
                postfixes[FORWARD_BLOCK] = "Right";
            }

            for (int direction = 0; direction < postfixes.length; direction++) {
                DEFAULT_ICONS[orientation][direction][0] =
                        new SResourceIcon("org/wings/icons/"
                        + prefixes[direction]
                        + "Scroll"
                        + postfixes[direction] + ".gif");
                DEFAULT_ICONS[orientation][direction][1] =
                        new SResourceIcon("org/wings/icons/Disabled"
                        + prefixes[direction]
                        + "Scroll"
                        + postfixes[direction] + ".gif");
            }
        }
    }

    @Override
    public void writeInternal(Device d, SComponent c)
            throws IOException {
        log.debug("write = " + c);
        SPageScroller sb = (SPageScroller) c;

        String style = sb.getStyle();
        if (sb.getLayoutMode() == SConstants.VERTICAL) {
            sb.setStyle(style + " SPageScroller_vertical");
            writeVerticalPageScroller(d, sb);
        }
        else {
            sb.setStyle(style + " SPageScroller_horizontal");
            writeHorizontalPageScroller(d, sb);
        }
        sb.setStyle(style);
    }

    private static void writeVerticalPageScroller(Device d, SPageScroller sb) throws IOException {
        int value = sb.getValue();
        int extent = sb.getExtent();
        int minimum = sb.getMinimum();
        int maximum = sb.getMaximum();

        d.print("")
            .print("");

        d.print("");
        writeIcon(d, DEFAULT_ICONS[SConstants.VERTICAL][FIRST][0]);
        d.print("");

        d.print(" minimum;
        Utils.printClickability(d, sb, String.valueOf(value - extent), backEnabled, sb.getShowAsFormComponent());
        d.print(">");
        writeIcon(d, DEFAULT_ICONS[SConstants.VERTICAL][BACKWARD][0]);
        d.print("");

        d.print("
") .print("") .print("") .print(""); int firstDirectPage = sb.getCurrentPage() - (sb.getDirectPages() - 1) / 2; firstDirectPage = Math.min(firstDirectPage, sb.getPageCount() - sb.getDirectPages()); firstDirectPage = Math.max(firstDirectPage, 0); for (int i = 0; i < Math.min(sb.getDirectPages(), sb.getPageCount() - firstDirectPage); i++) { int page = firstDirectPage + i; d.print(""); d.print(Integer.toString(page + 1)); d.print(""); } d.print("
") .print("") .print("") .print(""); d.print(""); writeIcon(d, DEFAULT_ICONS[SConstants.VERTICAL][FORWARD][0]); d.print(""); d.print(""); writeIcon(d, DEFAULT_ICONS[SConstants.VERTICAL][LAST][0]); d.print(""); d.print("
") .print("") .print(""); } private static void verticalArea(Device d, String s, int v) throws IOException { d.print(""); } private static void writeHorizontalPageScroller(Device d, SPageScroller sb) throws IOException { int value = sb.getValue(); int extent = sb.getExtent(); int minimum = sb.getMinimum(); int maximum = sb.getMaximum(); d.print("") .print(""); d.print(""); writeIcon(d, DEFAULT_ICONS[SConstants.HORIZONTAL][FIRST][0]); d.print(""); d.print(" minimum; Utils.printClickability(d, sb, String.valueOf(value - extent), backEnabled, sb.getShowAsFormComponent()); d.print(">"); writeIcon(d, DEFAULT_ICONS[SConstants.HORIZONTAL][BACKWARD][0]); d.print(""); d.print("
") .print(""); int firstDirectPage = sb.getCurrentPage() - (sb.getDirectPages() - 1) / 2; firstDirectPage = Math.min(firstDirectPage, sb.getPageCount() - sb.getDirectPages()); firstDirectPage = Math.max(firstDirectPage, 0); for (int i = 0; i < Math.min(sb.getDirectPages(), sb.getPageCount() - firstDirectPage); i++) { int page = firstDirectPage + i; d.print(""); d.print(Integer.toString(page + 1)); d.print(""); } d.print("
") .print(""); d.print(""); writeIcon(d, DEFAULT_ICONS[SConstants.HORIZONTAL][FORWARD][0]); d.print(""); d.print("= (maximum - extent)); boolean enabled1 = !lastPage; Utils.printClickability(d, sb, String.valueOf((sb.getPageCount() - 1) * extent), enabled1, sb.getShowAsFormComponent()); d.print(">"); writeIcon(d, DEFAULT_ICONS[SConstants.HORIZONTAL][LAST][0]); d.print(""); d.print("
") .print(""); } private static void writeIcon(Device device, SIcon icon) throws IOException { device.print(""); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy