Package ch.fork.AdHocRailway.domain.locomotives

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


    private Component buildMainButtonBar() {
        return ButtonBarFactory.buildRightAlignedBar(okButton);
    }

    private void initComponents() {
        LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                .getInstance().getLocomotivePersistence();
        ArrayListModel<LocomotiveGroup> locomotiveGroups = locomotivePersistence
                .getAllLocomotiveGroups();
        locomotiveGroupModel = new SelectionInList<LocomotiveGroup>(
                (ListModel) locomotiveGroups);

        locomotiveGroupList = BasicComponentFactory
                .createList(locomotiveGroupModel);
        locomotiveGroupList
                .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        locomotiveGroupList
                .setCellRenderer(new LocomotiveGroupListCellRenderer());

        addGroupButton = new JButton(new AddLocomotiveGroupAction());
        removeGroupButton = new JButton(new RemoveLocomotiveGroupAction());

        locomotiveModel = new SelectionInList<Locomotive>();
        locomotivesTable = new JTable();
        locomotivesTable.setModel(new LocomotiveTableModel(locomotiveModel));
        locomotivesTable.setSelectionModel(new SingleListSelectionAdapter(
                locomotiveModel.getSelectionIndexHolder()));

        addLocomotiveButton = new JButton(new AddLocomotiveAction());
        removeLocomotiveButton = new JButton(new RemoveLocomotiveAction());

        okButton = new JButton("OK");
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                            .getInstance().getLocomotivePersistence();
                    locomotivePersistence.flush();
                } catch (LocomotivePersistenceException e1) {
                    ExceptionProcessor.getInstance().processException(e1);
                } finally {
                    okPressed = true;
                    setVisible(false);
View Full Code Here


            String newGroupName = JOptionPane.showInputDialog(
                    LocomotiveConfigurationDialog.this,
                    "Enter the name of the new Locomotive-Group",
                    "Add Locomotive-Group", JOptionPane.QUESTION_MESSAGE);
            LocomotiveGroup newSection = new LocomotiveGroup(0, newGroupName);
            LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                    .getInstance().getLocomotivePersistence();
            locomotivePersistence.addLocomotiveGroup(newSection);
        }
View Full Code Here

                    "Really remove Locomotive-Group '"
                            + groupToDelete.getName() + "' ?",
                    "Remove Locomotive-Group", JOptionPane.YES_NO_OPTION);
            if (response == JOptionPane.YES_OPTION) {
                try {
                    LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                            .getInstance().getLocomotivePersistence();
                    locomotivePersistence.deleteLocomotiveGroup(groupToDelete);
                } catch (LocomotivePersistenceException e) {
                    ExceptionProcessor.getInstance().processException(e);
                }
            }
        }
View Full Code Here

            }
        }
    }

    public void updateLocomotiveGroups() {
        LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                .getInstance().getLocomotivePersistence();
        locomotiveComboBox.removeActionListener(locomotiveSelectAction);
        locomotiveGroupComboBox.removeActionListener(groupSelectAction);

        locomotiveGroupComboBox.addItem("All");
        locomotiveComboBox.addItem("");
        for (LocomotiveGroup lg : locomotivePersistence
                .getAllLocomotiveGroups()) {
            locomotiveGroupComboBox.addItem(lg);
            for (Locomotive l : lg.getLocomotives()) {
                locomotiveComboBox.addItem(l);
            }
View Full Code Here

        locomotiveGroupComboBox.addActionListener(groupSelectAction);
    }

    private class LocomotiveGroupSelectAction extends AbstractAction {
        public void actionPerformed(ActionEvent e) {
            LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                    .getInstance().getLocomotivePersistence();

            locomotiveComboBox.removeAllItems();
            if (locomotiveGroupComboBox.getSelectedIndex() == 0) {
                ArrayListModel<Locomotive> sl = locomotivePersistence
                        .getAllLocomotives();

                locomotiveComboBox.addItem("");
                for (Locomotive l : sl) {
                    locomotiveComboBox.addItem(l);
View Full Code Here

            if (myLocomotive == null)
                return;
            LocomotiveControlface locomotiveControl = AdHocRailway
                    .getInstance().getLocomotiveControl();
            if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON3) {
                LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                        .getInstance().getLocomotivePersistence();
                LocomotiveConfig locomotiveConfig = new LocomotiveConfig(frame,
                        myLocomotive);
                if (locomotiveConfig.isOkPressed()) {
                    locomotivePersistence.updateLocomotive(myLocomotive);
                }
                locomotiveChanged(myLocomotive);
                locomotiveControl.update();
            } else if (e.getButton() == MouseEvent.BUTTON2) {
                ToggleDirectionAction a = new ToggleDirectionAction();
View Full Code Here

            selectedLocomotiveGroup.getLocomotives().add(newLocomotive);
            LocomotiveConfig locomotiveConfig = new LocomotiveConfig(
                    LocomotiveConfigurationDialog.this, newLocomotive);
            if (locomotiveConfig.isOkPressed()) {
                selectedLocomotiveGroup.getLocomotives().add(newLocomotive);
                LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                    .getInstance().getLocomotivePersistence();
                locomotivePersistence.addLocomotive(newLocomotive);
            }
            List<Locomotive> locomotives = new ArrayList<Locomotive>(
                    selectedLocomotiveGroup.getLocomotives());
            locomotiveModel.setList(locomotives);
        }
View Full Code Here

                    .getSelectedValue();

            int row = locomotivesTable.getSelectedRow();
            Locomotive locomotiveToDelete = locomotiveModel.getElementAt(row);

            LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                    .getInstance().getLocomotivePersistence();
            locomotivePersistence.deleteLocomotive(locomotiveToDelete);
            List<Locomotive> locomotives = new ArrayList<Locomotive>(
                    selectedLocomotiveGroup.getLocomotives());
            locomotiveModel.setList(locomotives);
        }
View Full Code Here

        setVisible(true);
    }

    private void initComponents() {

        LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                .getInstance().getLocomotivePersistence();
        nameTextField = BasicComponentFactory.createTextField(presentationModel
                .getModel(Locomotive.PROPERTYNAME_NAME));
        nameTextField.setColumns(10);

        descTextField = BasicComponentFactory.createTextField(presentationModel
                .getModel(Locomotive.PROPERTYNAME_DESCRIPTION));
        descTextField.setColumns(10);

        imageTextField = BasicComponentFactory
                .createTextField(presentationModel
                        .getModel(Locomotive.PROPERTYNAME_IMAGE));
        imageTextField.setColumns(10);

        busTextField = new JSpinner();
        busTextField.setModel(SpinnerAdapterFactory.createNumberAdapter(
                presentationModel.getModel(Locomotive.PROPERTYNAME_BUS), 1, // defaultValue
                0, // minValue
                100, // maxValue
                1)); // step

        addressTextField = new JSpinner();
        addressTextField.setModel(SpinnerAdapterFactory.createNumberAdapter(
                presentationModel.getModel(Locomotive.PROPERTYNAME_ADDRESS), 1, // defaultValue
                0, // minValue
                324, // maxValue
                1)); // step

        List<LocomotiveType> locomotiveTypes = new ArrayList<LocomotiveType>(
                locomotivePersistence.getAllLocomotiveTypes());

        ValueModel locomotiveTypeModel = presentationModel
                .getModel(Locomotive.PROPERTYNAME_LOCOMOTIVE_TYPE);
        locomotiveTypeComboBox = BasicComponentFactory
                .createComboBox(new SelectionInList<LocomotiveType>(
View Full Code Here

            return;
    }

    private boolean validate(Locomotive locomotive, PropertyChangeEvent event) {

        LocomotivePersistenceIface locomotivePersistence = AdHocRailway
                .getInstance().getLocomotivePersistence();
        boolean validate = true;
        if (event == null
                || event.getPropertyName().equals(Locomotive.PROPERTYNAME_NAME)) {
            if (locomotive.getName() == null || locomotive.getName().equals("")) {
                validate = false;
                nameTextField.setBackground(UIConstants.ERROR_COLOR);
            } else {
                nameTextField
                        .setBackground(UIConstants.DEFAULT_TEXTFIELD_COLOR);
            }
        }
        if (event == null
                || event.getPropertyName().equals(Locomotive.PROPERTYNAME_BUS)
                || event.getPropertyName().equals(
                        Locomotive.PROPERTYNAME_ADDRESS)) {
            boolean busValid = true;

            if (locomotive.getBus() == 0) {
                setSpinnerColor(busTextField, UIConstants.ERROR_COLOR);
                validate = false;
                busValid = false;
            } else {
                setSpinnerColor(busTextField,
                        UIConstants.DEFAULT_TEXTFIELD_COLOR);
            }

            boolean addressValid = true;

            if (locomotive.getAddress() == 0
                    || locomotive.getAddress() > MMTurnout.MAX_MM_TURNOUT_ADDRESS) {
                setSpinnerColor(addressTextField, UIConstants.ERROR_COLOR);
                validate = false;
                addressValid = false;
            } else {
                setSpinnerColor(addressTextField,
                        UIConstants.DEFAULT_TEXTFIELD_COLOR);
            }

            if (busValid && addressValid) {

                int bus = ((Integer) busTextField.getValue()).intValue();
                int address = ((Integer) addressTextField.getValue())
                        .intValue();
                boolean unique = true;
                for (Locomotive l : locomotivePersistence.getAllLocomotives()) {
                    if (l.getBus() == bus && l.getAddress() == address
                            && !l.equals(locomotive))
                        unique = false;
                }
                if (!unique) {
View Full Code Here

TOP

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

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.