Package ch.fork.AdHocRailway.domain.turnouts

Examples of ch.fork.AdHocRailway.domain.turnouts.TurnoutPersistenceIface


                    TurnoutConfigurationDialog.this,
                    "Enter the name of the new Turnout-Group",
                    "Add Turnout-Group", JOptionPane.QUESTION_MESSAGE);
            if (newGroupName == null)
                return;
            TurnoutPersistenceIface turnoutPersistence = AdHocRailway
                    .getInstance().getTurnoutPersistence();
            TurnoutGroup newTurnoutGroup = new TurnoutGroup();
            newTurnoutGroup.setName(newGroupName);
            if (Preferences.getInstance().getBooleanValue(
                    PreferencesKeys.USE_FIXED_TURNOUT_AND_ROUTE_GROUP_SIZES)) {
                String newAmount = JOptionPane.showInputDialog(
                        TurnoutConfigurationDialog.this,
                        "How many Turnouts should be in this group?", "10");
                int newOffset = 1;
                for (TurnoutGroup group : turnoutPersistence
                        .getAllTurnoutGroups()) {
                    newOffset += group.getTurnoutNumberAmount();
                }
                newTurnoutGroup.setTurnoutNumberOffset(newOffset);
                newTurnoutGroup.setTurnoutNumberAmount(Integer
                        .parseInt(newAmount));
            }

            previousSelectedGroup = null;
            turnoutPersistence.addTurnoutGroup(newTurnoutGroup);
            turnoutGroupConfig.setTurnoutGroup(null);

        }
View Full Code Here


                    TurnoutConfigurationDialog.this,
                    "Really remove Turnout-Group '" + groupToDelete.getName()
                            + "' ?", "Remove Turnout-Group",
                    JOptionPane.YES_NO_OPTION);
            if (response == JOptionPane.YES_OPTION) {
                TurnoutPersistenceIface turnoutPersistence = AdHocRailway
                        .getInstance().getTurnoutPersistence();
                previousSelectedGroup = null;
                turnoutPersistence.deleteTurnoutGroup(groupToDelete);
                turnoutGroupConfig.setTurnoutGroup(null);
                List<TurnoutGroup> turnoutGroups = new ArrayList<TurnoutGroup>(
                        turnoutPersistence.getAllTurnoutGroups());
                turnoutGroupModel.setList(turnoutGroups);
            }
        }
View Full Code Here

                        "Please select a switch group", "Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
            int nextNumber = 0;
            TurnoutPersistenceIface turnoutPersistence = AdHocRailway
                    .getInstance().getTurnoutPersistence();
            if (Preferences.getInstance().getBooleanValue(
                    PreferencesKeys.USE_FIXED_TURNOUT_AND_ROUTE_GROUP_SIZES)) {
                nextNumber = turnoutPersistence
                        .getNextFreeTurnoutNumberOfGroup(selectedTurnoutGroup);
                if (nextNumber == -1) {
                    JOptionPane.showMessageDialog(
                            TurnoutConfigurationDialog.this,
                            "No more free numbers in this group", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            } else {
                nextNumber = turnoutPersistence.getNextFreeTurnoutNumber();
            }
            Turnout newTurnout = new Turnout();
            newTurnout.setNumber(nextNumber);

            newTurnout.setBus1(Preferences.getInstance().getIntValue(
                    PreferencesKeys.DEFAULT_TURNOUT_BUS));
            newTurnout.setBus2(Preferences.getInstance().getIntValue(
                    PreferencesKeys.DEFAULT_TURNOUT_BUS));

            newTurnout.setTurnoutGroup(selectedTurnoutGroup);
            newTurnout.setDefaultStateEnum(SRCPTurnoutState.STRAIGHT);
            newTurnout.setOrientationEnum(TurnoutOrientation.EAST);
            newTurnout.setTurnoutType(turnoutPersistence
                    .getTurnoutType(SRCPTurnoutTypes.DEFAULT));

            TurnoutConfig switchConfig = new TurnoutConfig(
                    TurnoutConfigurationDialog.this, newTurnout);
            if (switchConfig.isOkPressed()) {
View Full Code Here

            int i = 0;
            for (int row : rows) {
                numbers[i] = (Integer) turnoutsTable.getValueAt(row, 0);
                i++;
            }
            TurnoutPersistenceIface turnoutPersistence = AdHocRailway
                    .getInstance().getTurnoutPersistence();
            for (int number : numbers) {
                turnoutPersistence.deleteTurnout(turnoutPersistence
                        .getTurnoutByNumber(number));
            }
            List<Turnout> turnouts = new ArrayList<Turnout>(
                    selectedTurnoutGroup.getTurnouts());
            turnoutModel.setList(turnouts);
View Full Code Here

            // PresentationModel<Turnout> model = new
            // PresentationModel<Turnout>(
            // turnoutModel);
            int row = turnoutsTable.getSelectedRow();
            int number = (Integer) turnoutsTable.getValueAt(row, 0);
            TurnoutPersistenceIface turnoutPersistence = AdHocRailway
                    .getInstance().getTurnoutPersistence();
            PresentationModel<Turnout> model = new PresentationModel<Turnout>(
                    turnoutPersistence.getTurnoutByNumber(number));
            if (model == null)
                return;
            new TurnoutConfig(TurnoutConfigurationDialog.this, model);
        }
View Full Code Here

            digitDisplay.reset();
        }

        private void handleSwitchChange(ActionEvent e, int enteredNumber)
                throws TurnoutException {
            TurnoutPersistenceIface turnoutPersistence = AdHocRailway
                    .getInstance().getTurnoutPersistence();
            Turnout searchedTurnout = null;
            searchedTurnout = turnoutPersistence
                    .getTurnoutByNumber(enteredNumber);
            if (searchedTurnout == null) {
                return;
            }
            TurnoutControlIface turnoutControl = AdHocRailway.getInstance()
View Full Code Here

        add(turnoutCanvas);

    }

    private void validateTurnout() {
        TurnoutPersistenceIface turnoutPersistence = AdHocRailway.getInstance()
                .getTurnoutPersistence();
        boolean bus1Valid = true;
        if (turnout.getBus1() == 0) {
            setBackground(UIConstants.ERROR_COLOR);
            bus1Valid = false;
        } else {
            setBackground(UIConstants.DEFAULT_PANEL_COLOR);
        }
        boolean address1Valid = true;
        if (turnout.getAddress1() == 0
                || turnout.getAddress1() > MMTurnout.MAX_MM_TURNOUT_ADDRESS) {
            setBackground(UIConstants.ERROR_COLOR);
            address1Valid = false;

        } else {
            setBackground(UIConstants.DEFAULT_PANEL_COLOR);

        }
        if (bus1Valid && address1Valid) {
            int bus1 = turnout.getBus1();
            int address1 = turnout.getAddress1();

            boolean unique1 = true;
            for (Turnout t : turnoutPersistence.getAllTurnouts()) {
                if (t.getBus1() == bus1 && t.getAddress1() == address1
                        && !t.equals(turnout))
                    unique1 = false;
            }
            if (!unique1) {
                setBackground(UIConstants.WARN_COLOR);
            } else {
                setBackground(UIConstants.DEFAULT_PANEL_COLOR);
            }
        }

        if (turnout.isThreeWay()) {
            boolean bus2Valid = true;
            if (turnout.getBus2() == 0) {
                setBackground(UIConstants.ERROR_COLOR);
                bus2Valid = false;
            } else {
                setBackground(UIConstants.DEFAULT_PANEL_COLOR);
            }
            boolean address2Valid = true;
            if (turnout.getAddress2() == 0
                    || turnout.getAddress2() > MMTurnout.MAX_MM_TURNOUT_ADDRESS) {
                setBackground(UIConstants.ERROR_COLOR);
                address2Valid = false;
            } else {
                setBackground(UIConstants.DEFAULT_PANEL_COLOR);
            }
            if (bus2Valid && address2Valid) {
                int bus2 = turnout.getBus2();
                int address2 = turnout.getAddress2();
                boolean unique2 = true;
                for (Turnout t : turnoutPersistence.getAllTurnouts()) {
                    if (t.equals(turnout))
                        continue;
                    if ((t.getBus1() == bus2 && t.getAddress1() == address2)
                            || (t.getBus2() == bus2 && t.getAddress2() == address2))
                        unique2 = false;
View Full Code Here

        JLabel iconLabel = (JLabel) super.getTableCellRendererComponent(table,
                value, isSelected, hasFocus, row, column);
        iconLabel.setHorizontalAlignment(SwingConstants.CENTER);
        Turnout currentTurnout;
        iconLabel.setText("");
        TurnoutPersistenceIface persistence = AdHocRailway.getInstance()
                .getTurnoutPersistence();
        currentTurnout = persistence.getTurnoutByNumber(Integer
                .valueOf((Integer) table.getValueAt(row, 0)));
        if (currentTurnout == null) {
            return iconLabel;
        }
        SRCPTurnoutState routedState = (SRCPTurnoutState) value;
View Full Code Here

TOP

Related Classes of ch.fork.AdHocRailway.domain.turnouts.TurnoutPersistenceIface

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.