Package ch.fork.AdHocRailway.domain.locomotives

Examples of ch.fork.AdHocRailway.domain.locomotives.LocomotiveControlface


        Preferences.getInstance().getKeyBoardLayout().assignKeys
            (getInputMap(WHEN_IN_FOCUSED_WINDOW), "LocomotiveStop");
    }

    public void update() {
        LocomotiveControlface locomotiveControl = AdHocRailway.getInstance()
                .getLocomotiveControl();
        locomotiveControl.removeAllLocomotiveChangeListener();

        controlPanel.removeAll();
        locomotiveWidgets.clear();
        if (Preferences.getInstance()
                .getStringValue(PreferencesKeys.KEYBOARD_LAYOUT)
View Full Code Here


            t.start();
        }

        public void run() {
            try {
                LocomotiveControlface locomotiveControl = AdHocRailway
                        .getInstance().getLocomotiveControl();
                for (LocomotiveWidget widget : locomotiveWidgets) {
                    Locomotive myLocomotive = widget.getMyLocomotive();
                    if (myLocomotive == null)
                        continue;
                    if (locomotiveControl.isLocked(myLocomotive)
                            && !locomotiveControl.isLockedByMe(myLocomotive))
                        continue;
                    locomotiveControl.setSpeed(myLocomotive, 0, null);
                    widget.updateWidget();
                }
            } catch (LocomotiveException e3) {
                ExceptionProcessor.getInstance().processException(e3);
            }
View Full Code Here

            ("ToggleDirection" + number, new LocomotiveToggleDirectionAction());
        kbl.assignKeys(inputMap, "ToggleDirection" + number);
    }

    private boolean isFree() {
        LocomotiveControlface locomotiveControl = AdHocRailway.getInstance()
                .getLocomotiveControl();
        if (myLocomotive == null)
            return true;
        if (locomotiveControl.getCurrentSpeed(myLocomotive) == 0) {
            if (locomotiveControl.isLocked(myLocomotive)) {
                if (locomotiveControl.isLockedByMe(myLocomotive))
                    return false;
                else {
                    return true;
                }
            } else {
                return true;
            }
        } else {
            if (locomotiveControl.isLocked(myLocomotive)) {
                if (locomotiveControl.isLockedByMe(myLocomotive))
                    return false;
                else {
                    return true;
                }
            } else {
View Full Code Here

            }
        }
    }

    protected void updateWidget() {
        LocomotiveControlface locomotiveControl = AdHocRailway.getInstance()
                .getLocomotiveControl();
        if (myLocomotive == null)
            return;
        double speedInPercent = ((double) locomotiveControl
                .getCurrentSpeed(myLocomotive))
                / ((double) myLocomotive.getLocomotiveType().getDrivingSteps());
        if (speedInPercent > 0.9) {
            speedBar.setForeground(new Color(255, 0, 0));
        } else if (speedInPercent > 0.7) {
            speedBar.setForeground(new Color(255, 255, 0));
        } else {
            speedBar.setForeground(new Color(0, 255, 0));
        }
        speedBar.setMinimum(0);
        speedBar.setMaximum(myLocomotive.getLocomotiveType().getDrivingSteps());
        speedBar.setValue(locomotiveControl.getCurrentSpeed(myLocomotive));
        boolean functions[] = locomotiveControl.getFunctions(myLocomotive);
        for (int i = 0; i < functions.length; i++) {
            functionToggleButtons[i].setSelected(functions[i]);
        }
        switch (locomotiveControl.getDirection(myLocomotive)) {
        case FORWARD:
            directionButton.setIcon(createImageIcon("locomotives/forward.png"));
            break;
        case REVERSE:
            directionButton.setIcon(createImageIcon("locomotives/back.png"));
            break;
        default:
            directionButton.setIcon(createImageIcon("locomotives/forward.png"));
        }

        boolean locked = locomotiveControl.isLocked(myLocomotive);
        lockButton.setSelected(locked);
        if (locked) {
            if (locomotiveControl.isLockedByMe(myLocomotive)) {
                lockButton.setSelectedIcon(ImageTools
                        .createImageIcon("locomotives/locked_by_me.png"));

            } else {
                lockButton.setSelectedIcon(ImageTools
View Full Code Here

        }
    }

    private class LocomotiveSelectAction extends AbstractAction {
        public void actionPerformed(ActionEvent e) {
            LocomotiveControlface locomotiveControl = AdHocRailway
                    .getInstance().getLocomotiveControl();
            if (locomotiveComboBox.getItemCount() == 0
                    || locomotiveComboBox.getSelectedIndex() == 0) {
                myLocomotive = null;
                return;
            }
            if (isFree()) {
                locomotiveComboBox
                        .setBackground(UIConstants.DEFAULT_PANEL_COLOR);
                lockButton.setBackground(UIConstants.DEFAULT_PANEL_COLOR);
                myLocomotive = (Locomotive) locomotiveComboBox
                        .getSelectedItem();
                locomotiveControl.addLocomotiveChangeListener(myLocomotive,
                        LocomotiveWidget.this);
                updateWidget();
                speedBar.requestFocus();
            } else {
                locomotiveGroupComboBox.setSelectedItem(myLocomotive
View Full Code Here

        public void actionPerformed(ActionEvent e) {

            if (myLocomotive == null)
                return;
            LocomotiveControlface locomotiveControl = AdHocRailway
                    .getInstance().getLocomotiveControl();
            try {
                boolean[] functions = locomotiveControl
                        .getFunctions(myLocomotive);
                functions[function] = functionToggleButtons[function]
                        .isSelected();
                locomotiveControl.setFunctions(myLocomotive, functions);
            } catch (LocomotiveException e1) {
                ExceptionProcessor.getInstance().processException(e1);
            }
            speedBar.requestFocus();
        }
View Full Code Here

        public void actionPerformed(ActionEvent e) {
            if (myLocomotive == null)
                return;
            try {
                LocomotiveControlface locomotiveControl = AdHocRailway
                        .getInstance().getLocomotiveControl();
                doPerformAction(locomotiveControl, myLocomotive);
                if (time == 0) {
                    time = System.currentTimeMillis();
                } else {
View Full Code Here

    private class StopAction extends AbstractAction {
        public void actionPerformed(ActionEvent e) {
            if (myLocomotive == null)
                return;
            try {
                LocomotiveControlface locomotiveControl = AdHocRailway
                        .getInstance().getLocomotiveControl();
                locomotiveControl.setSpeed(myLocomotive, 0, null);
                updateWidget();
                speedBar.requestFocus();
            } catch (LocomotiveException e3) {
                ExceptionProcessor.getInstance().processException(e3);
            }
View Full Code Here

    private class ToggleDirectionAction extends AbstractAction {
        public void actionPerformed(ActionEvent e) {
            if (myLocomotive == null)
                return;
            try {
                LocomotiveControlface locomotiveControl = AdHocRailway
                        .getInstance().getLocomotiveControl();
                if (Preferences.getInstance().getBooleanValue
                    (PreferencesKeys.STOP_ON_DIRECTION_CHANGE)
                    && locomotiveControl.getCurrentSpeed(myLocomotive) != 0) {
                    locomotiveControl.setSpeed
                        (myLocomotive, 0,
                         locomotiveControl.getFunctions(myLocomotive));
                }
                locomotiveControl.toggleDirection(myLocomotive);
                speedBar.requestFocus();
                updateWidget();
            } catch (LocomotiveException e1) {
                ExceptionProcessor.getInstance().processException(e1);
            }
View Full Code Here

    private class IncreaseSpeedAction extends AbstractAction {
        public void actionPerformed(ActionEvent e) {
            if (myLocomotive == null)
                return;
            try {
                LocomotiveControlface locomotiveControl = AdHocRailway
                        .getInstance().getLocomotiveControl();
                locomotiveControl.increaseSpeed(myLocomotive);
                updateWidget();
                speedBar.requestFocus();
            } catch (LocomotiveException e3) {
                ExceptionProcessor.getInstance().processException(e3);
            }
View Full Code Here

TOP

Related Classes of ch.fork.AdHocRailway.domain.locomotives.LocomotiveControlface

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.