com.imaginedreal.gwt.palantir.client.activities.settings.SettingsActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.imaginedreal.gwt.palantir.client.activities.settings.SettingsActivity.java

Source

/*
 * Copyright 2015 Wayne Dyck
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.imaginedreal.gwt.palantir.client.activities.settings;

import com.imaginedreal.gwt.palantir.client.ClientFactory;
import com.imaginedreal.gwt.palantir.client.event.ActionEvent;
import com.imaginedreal.gwt.palantir.client.event.ActionNames;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.googlecode.mgwt.mvp.client.MGWTAbstractActivity;

public class SettingsActivity extends MGWTAbstractActivity implements SettingsView.Presenter {

    private final ClientFactory clientFactory;
    private SettingsView view;
    private EventBus eventBus;

    public SettingsActivity(ClientFactory clientFactory) {
        this.clientFactory = clientFactory;
    }

    @Override
    public void start(AcceptsOneWidget panel, final EventBus eventBus) {
        view = clientFactory.getSettingsView();
        this.eventBus = eventBus;
        view.setPresenter(this);

        addHandlerRegistration(view.getSliderValue().addValueChangeHandler(new ValueChangeHandler<Integer>() {

            @Override
            public void onValueChange(ValueChangeEvent<Integer> event) {
                view.getTextField().setText("" + event.getValue());
            }
        }));

        view.getSliderValue().setValue(12); // Initial text size

        panel.setWidget(view);

    }

    @Override
    public void onStop() {
        view.setPresenter(null);
    }

    @Override
    public void onBackButtonPressed() {
        ActionEvent.fire(eventBus, ActionNames.BACK);
    }

}