<commit_before>package com.itmill.toolkit.demo;

import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.GridLayout;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.Window;

// Calculator is created by extending Application-class. Application is
// deployed by adding ApplicationServlet to web.xml and this class as
// "application" parameter to the servlet.
public class Calc extends com.itmill.toolkit.Application {

    // Calculation data model is automatically stored in the user session
    private double current = 0.0;
    private double stored = 0.0;
    private char lastOperationRequested = 'C';

    // User interface components
    private final Label display = new Label("0.0");
    private final GridLayout layout = new GridLayout(4, 5);

    // Application initialization creates UI and connects it to business logic
    @Override
    public void init() {

        // Place the layout to a floating dialog inside the browser main window
        setMainWindow(new Window("Calculator Application"));
        getMainWindow().addWindow(new Window("Calc", layout));

        // Create and add the components to the layout
        layout.addComponent(display, 0, 0, 3, 0);
        for (String caption : new String[] { "7", "8", "9", "/", "4", "5", "6",
                "*", "1", "2", "3", "-", "0", "=", "C", "+" }) {
            Button button = new Button(caption, new Button.ClickListener() {
                public void buttonClick(Button.ClickEvent event) {

                    // On button click, calculate and show the result
                    display.setValue(calculate(event.getButton()));
                }
            });
            layout.addComponent(button);
        }
    }

    // Calculator "business logic" implemented here to keep the example minimal
    private double calculate(Button buttonClicked) {
        char requestedOperation = buttonClicked.getCaption().charAt(0);
        if ('0' <= requestedOperation && requestedOperation <= '9') {
            current = current * 10
                    + Double.parseDouble("" + requestedOperation);
            return current;
        }
        switch (lastOperationRequested) {
        case '+':
            stored += current;
            break;
        case '-':
            stored -= current;
            break;
        case '/':
            stored /= current;
            break;
        case '*':
            stored *= current;
            break;
        case 'C':
            stored = current;
            break;
        }
        lastOperationRequested = requestedOperation;
        current = 0.0;
        if (requestedOperation == 'C') {
            stored = 0.0;
        }
        return stored;
    }
}
<commit_msg>NEW - # 2641: Remove the child window from the Calculator example  http://dev.itmill.com/ticket/2641<commit_after>package com.itmill.toolkit.demo;

import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.GridLayout;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.Window;

// Calculator is created by extending Application-class. Application is
// deployed by adding ApplicationServlet to web.xml and this class as
// "application" parameter to the servlet.
public class Calc extends com.itmill.toolkit.Application {

    // Calculation data model is automatically stored in the user session
    private double current = 0.0;
    private double stored = 0.0;
    private char lastOperationRequested = 'C';

    // User interface components
    private final Label display = new Label("0.0");
    private final GridLayout layout = new GridLayout(4, 5);

    // Application initialization creates UI and connects it to business logic
    @Override
    public void init() {

        // Place the layout to the browser main window
        setMainWindow(new Window("Calculator Application", layout));

        // Create and add the components to the layout
        layout.addComponent(display, 0, 0, 3, 0);
        for (String caption : new String[] { "7", "8", "9", "/", "4", "5", "6",
                "*", "1", "2", "3", "-", "0", "=", "C", "+" }) {
            Button button = new Button(caption, new Button.ClickListener() {
                public void buttonClick(Button.ClickEvent event) {

                    // On button click, calculate and show the result
                    display.setValue(calculate(event.getButton()));
                }
            });
            layout.addComponent(button);
        }
    }

    // Calculator "business logic" implemented here to keep the example minimal
    private double calculate(Button buttonClicked) {
        char requestedOperation = buttonClicked.getCaption().charAt(0);
        if ('0' <= requestedOperation && requestedOperation <= '9') {
            current = current * 10
                    + Double.parseDouble("" + requestedOperation);
            return current;
        }
        switch (lastOperationRequested) {
        case '+':
            stored += current;
            break;
        case '-':
            stored -= current;
            break;
        case '/':
            stored /= current;
            break;
        case '*':
            stored *= current;
            break;
        case 'C':
            stored = current;
            break;
        }
        lastOperationRequested = requestedOperation;
        current = 0.0;
        if (requestedOperation == 'C') {
            stored = 0.0;
        }
        return stored;
    }
}

{'fraction_non_alphanumeric': 0.10930360080424054, 'fraction_numerical': 0.012794735880095047, 'mean_word_length': 2.0604026845637584, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3816065', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1391, 'n_words': 444}