Search in sources :

Example 16 with Window

use of org.apache.pivot.wtk.Window in project pivot by apache.

the class TerraTextInputSkin method focusedChanged.

@Override
public void focusedChanged(Component component, Component obverseComponent) {
    super.focusedChanged(component, obverseComponent);
    TextInput textInput = (TextInput) component;
    Window window = textInput.getWindow();
    if (component.isFocused()) {
        // If focus was permanently transferred within this window, select all
        if (obverseComponent == null || obverseComponent.getWindow() == window) {
            if (Mouse.getCapturer() != component) {
                textInput.selectAll();
            }
        }
        if (textInput.getSelectionLength() == 0) {
            int selectionStart = textInput.getSelectionStart();
            if (selectionStart < textInput.getCharacterCount()) {
                scrollCharacterToVisible(selectionStart);
            }
            showCaret(true);
        } else {
            showCaret(false);
        }
    } else {
        // clear the selection
        if (obverseComponent == null || obverseComponent.getWindow() == window) {
            textInput.clearSelection();
        }
        showCaret(false);
    }
    repaintComponent();
}
Also used : Window(org.apache.pivot.wtk.Window) TextInput(org.apache.pivot.wtk.TextInput)

Example 17 with Window

use of org.apache.pivot.wtk.Window in project pivot by apache.

the class TerraSheetSkin method windowOpened.

@Override
public void windowOpened(Window window) {
    super.windowOpened(window);
    Display display = window.getDisplay();
    display.getContainerMouseListeners().add(displayMouseListener);
    display.reenterMouse();
    if (dropShadowDecorator != null) {
        dropShadowDecorator.setShadowOpacity(DropShadowDecorator.DEFAULT_SHADOW_OPACITY);
    }
    alignToOwner();
    Window owner = window.getOwner();
    owner.getComponentListeners().add(ownerListener);
    openTransition = new OpenTransition(false);
    openTransition.start(new TransitionListener() {

        @Override
        public void transitionCompleted(Transition transition) {
            openTransition = null;
        }
    });
    if (!window.requestFocus()) {
        Component.clearFocus();
    }
}
Also used : Window(org.apache.pivot.wtk.Window) Transition(org.apache.pivot.wtk.effects.Transition) TransitionListener(org.apache.pivot.wtk.effects.TransitionListener) Display(org.apache.pivot.wtk.Display)

Example 18 with Window

use of org.apache.pivot.wtk.Window in project pivot by apache.

the class TerraSheetSkin method previewSheetClose.

@Override
public Vote previewSheetClose(Sheet sheet, boolean result) {
    Vote vote = Vote.APPROVE;
    // Don't start the transition if the sheet is being closed as a result
    // of the owner closing
    Window owner = sheet.getOwner();
    if (!(owner.isClosing() || owner.isClosed() || doingFinalClose)) {
        if (openTransition == null) {
            // Setup for the close transition
            // Don't start it until we know that everyone
            // else is okay with it
            openTransition = new OpenTransition(true);
            closingResult = result;
        } else {
            // Reverse the open transition
            if (openTransition.isRunning()) {
                openTransition.reverse();
            }
        }
        vote = (openTransition != null) ? Vote.DEFER : Vote.APPROVE;
    }
    return vote;
}
Also used : Window(org.apache.pivot.wtk.Window) Vote(org.apache.pivot.util.Vote)

Example 19 with Window

use of org.apache.pivot.wtk.Window in project pivot by apache.

the class TerraSheetSkin method alignToOwner.

public void alignToOwner() {
    Sheet sheet = (Sheet) getComponent();
    Window owner = sheet.getOwner();
    if (owner != null) {
        Bounds clientArea = owner.getClientArea();
        Point location = owner.mapPointToAncestor(owner.getDisplay(), clientArea.x, clientArea.y);
        int x = location.x;
        int y = location.y;
        switch(slideSource) {
            case NORTH:
                x = location.x + (clientArea.width - getWidth()) / 2;
                y = location.y;
                break;
            case SOUTH:
                x = location.x + (clientArea.width - getWidth()) / 2;
                y = location.y + (clientArea.height - getHeight());
                break;
            case WEST:
                x = location.x;
                y = location.y + (clientArea.height - getHeight()) / 2;
                break;
            case EAST:
                x = location.x + (clientArea.width - getWidth());
                y = location.y + (clientArea.height - getHeight()) / 2;
                break;
            default:
                throw new IllegalStateException("slideSource is null or an unexpected value");
        }
        sheet.setLocation(x, y);
    }
}
Also used : Window(org.apache.pivot.wtk.Window) Bounds(org.apache.pivot.wtk.Bounds) Point(org.apache.pivot.wtk.Point) Sheet(org.apache.pivot.wtk.Sheet) Point(org.apache.pivot.wtk.Point)

Example 20 with Window

use of org.apache.pivot.wtk.Window in project pivot by apache.

the class TextInputValidatorTest method startup.

@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
    System.out.println("Starting TextInputValidatorTest ...");
    System.out.println("current Locale is " + locale);
    // sample different ways to format numbers in i18n compatible way
    NumberFormat nf = NumberFormat.getInstance();
    // 
    // String customDecimalPattern = ""###,###.###"";
    // DecimalFormat df = new DecimalFormat(customDecimalPattern);
    // 
    // StringBuffer sb = new StringBuffer();
    // Formatter formatter = new Formatter(sb, locale);
    // String customDecimalFormat = "%,.3f";
    // 
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = new Window((Component) bxmlSerializer.readObject(getClass().getResource("text_input_validator_test.bxml")));
    Map<String, Object> namespace = bxmlSerializer.getNamespace();
    textinputLocale = (TextInput) namespace.get("textinputLocale");
    textinputComparableBigDecimal = (TextInput) namespace.get("textinputComparableBigDecimal");
    textinputComparableRange = (TextInput) namespace.get("textinputComparableRange");
    textinputDouble = (TextInput) namespace.get("textinputDouble");
    textinputFloat = (TextInput) namespace.get("textinputFloat");
    textinputFloatRange = (TextInput) namespace.get("textinputFloatRange");
    textinputIntRange = (TextInput) namespace.get("textinputIntRange");
    textinputDateRegex = (TextInput) namespace.get("textinputDateRegex");
    textinputCustomBoolean = (TextInput) namespace.get("textinputCustomBoolean");
    textinputNotEmptyText = (TextInput) namespace.get("textinputNotEmptyText");
    textinputEmptyText = (TextInput) namespace.get("textinputEmptyText");
    textinputLocale.setText(locale.toString());
    String testValue = "123456789.0";
    // new, validate a value but using BigDecimalValidator (subclass of ComparableValidator)
    // huge value, and outside double range ...
    textinputComparableBigDecimal.setText("1e300");
    BigDecimalValidator bdComp = new BigDecimalValidator();
    System.out.println("BigDecimalValidator: created instance with value: " + bdComp);
    // enable auto-trim of input string, before validating
    bdComp.setAutoTrim(true);
    System.out.println("BigDecimalValidator: enable auto-trim of input string, before validating");
    textinputComparableBigDecimal.setValidator(bdComp);
    // new, validate in a range but using ComparableRangeValidator
    textinputComparableRange.setText(nf.format(new BigDecimal(testValue)));
    ComparableRangeValidator<BigDecimal> bdCompRange = new ComparableRangeValidator<>(new BigDecimal("2.0"), new BigDecimal("123456789"));
    System.out.println("ComparableRangeValidator: created instance with value: " + bdCompRange);
    // enable auto-trim of input string, before validating
    bdCompRange.setAutoTrim(true);
    System.out.println("ComparableRangeValidator: enable auto-trim of input string, before validating");
    textinputComparableRange.setValidator(bdCompRange);
    textinputComparableRange.getTextInputListeners().add(new TextInputListener() {

        @Override
        public void textValidChanged(final TextInput textInput) {
            invalidComparableRangeLabel.setText(validText(textInput));
        }
    });
    invalidComparableRangeLabel = (Label) namespace.get("invalidComparableRangeLabel");
    // positive infinity text
    textinputDouble.setText("+\u221E");
    textinputDouble.setValidator(new DoubleValidator());
    // textinputFloat.setText("123456.789");
    // new, show different ways to format decimal values in i18n format
    Double value = new Double(testValue);
    // textinputFloat.setText(value.toString());
    // textinputFloat.setText(String.format(customDecimalFormat, value)); // sample using String.format
    // formatter.format(customDecimalFormat, value); // sample using Formatter
    // textinputFloat.setText(sb.toString()); // sample using Formatter
    // textinputFloat.setText(nf.format(value)); // sample using NumberFormat
    // textinputFloat.setText(df.format(value)); // sample using DecimalFormat
    // using this as a sample
    textinputFloat.setText(nf.format(value));
    textinputFloat.setValidator(new FloatValidator());
    // standard float range model
    // note that float approximations could give errors,
    // try to increment/decrement the initial value near a range end, to see problems ...
    textinputFloatRange.setText(nf.format(new Float(testValue)));
    textinputFloatRange.setValidator(new FloatRangeValidator(2.0f, 123456789f));
    // test the listener by updating a label
    textinputFloatRange.getTextInputListeners().add(new TextInputListener() {

        @Override
        public void textValidChanged(final TextInput textInput) {
            invalidLabel.setText(validText(textInput));
        }
    });
    invalidLabel = (Label) namespace.get("invalidLabel");
    // standard int range model
    textinputIntRange.setText("0");
    textinputIntRange.setValidator(new IntRangeValidator(0, 100));
    // validate using a date regex.
    textinputDateRegex.setText("2009-09-01");
    textinputDateRegex.setValidator(new RegexTextValidator("(19|20)\\d\\d[- /.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])"));
    // creating a custom model that only accepts "true" or "false"
    textinputCustomBoolean.setText("true");
    textinputCustomBoolean.setValidator(new Validator() {

        @Override
        public boolean isValid(final String s) {
            return "true".equals(s) || "false".equals(s);
        }
    });
    // validate any not-empty text
    textinputNotEmptyText.setText("  Not Empty, and with spaces  ");
    textinputNotEmptyText.setValidator(new NotEmptyTextValidator());
    // validate any empty text, edge case
    textinputEmptyText.setText("    ");
    textinputEmptyText.setValidator(new EmptyTextValidator());
    window.setTitle("Text Input Validator Test");
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) BigDecimalValidator(org.apache.pivot.wtk.validation.BigDecimalValidator) ComparableRangeValidator(org.apache.pivot.wtk.validation.ComparableRangeValidator) NotEmptyTextValidator(org.apache.pivot.wtk.validation.NotEmptyTextValidator) EmptyTextValidator(org.apache.pivot.wtk.validation.EmptyTextValidator) NotEmptyTextValidator(org.apache.pivot.wtk.validation.NotEmptyTextValidator) RegexTextValidator(org.apache.pivot.wtk.validation.RegexTextValidator) BigDecimal(java.math.BigDecimal) DoubleValidator(org.apache.pivot.wtk.validation.DoubleValidator) FloatRangeValidator(org.apache.pivot.wtk.validation.FloatRangeValidator) FloatValidator(org.apache.pivot.wtk.validation.FloatValidator) Component(org.apache.pivot.wtk.Component) TextInput(org.apache.pivot.wtk.TextInput) IntRangeValidator(org.apache.pivot.wtk.validation.IntRangeValidator) TextInputListener(org.apache.pivot.wtk.TextInputListener) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) Validator(org.apache.pivot.wtk.validation.Validator) ComparableRangeValidator(org.apache.pivot.wtk.validation.ComparableRangeValidator) EmptyTextValidator(org.apache.pivot.wtk.validation.EmptyTextValidator) FloatValidator(org.apache.pivot.wtk.validation.FloatValidator) BigDecimalValidator(org.apache.pivot.wtk.validation.BigDecimalValidator) NotEmptyTextValidator(org.apache.pivot.wtk.validation.NotEmptyTextValidator) FloatRangeValidator(org.apache.pivot.wtk.validation.FloatRangeValidator) DoubleValidator(org.apache.pivot.wtk.validation.DoubleValidator) IntRangeValidator(org.apache.pivot.wtk.validation.IntRangeValidator) RegexTextValidator(org.apache.pivot.wtk.validation.RegexTextValidator) NumberFormat(java.text.NumberFormat)

Aggregations

Window (org.apache.pivot.wtk.Window)45 Component (org.apache.pivot.wtk.Component)14 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)13 PushButton (org.apache.pivot.wtk.PushButton)9 BoxPane (org.apache.pivot.wtk.BoxPane)8 Button (org.apache.pivot.wtk.Button)7 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)6 Display (org.apache.pivot.wtk.Display)5 Border (org.apache.pivot.wtk.Border)4 Label (org.apache.pivot.wtk.Label)4 Sheet (org.apache.pivot.wtk.Sheet)4 TablePane (org.apache.pivot.wtk.TablePane)4 File (java.io.File)3 Bounds (org.apache.pivot.wtk.Bounds)3 Point (org.apache.pivot.wtk.Point)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 Vote (org.apache.pivot.util.Vote)2 TaskExecutionException (org.apache.pivot.util.concurrent.TaskExecutionException)2