Code Search for Developers
 
 
  

ConsoleModel.java from Riot in Emerald city at Krugle


Show ConsoleModel.java syntax highlighted

/*
 * Copyright (C) 2001-2005 Pleasant nightmare studio
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.pleasantnightmare.riotinecity.console;

import java.util.LinkedList;
import java.util.ListIterator;

/**
 * @author deus
 * @version 1.0
 * @since Apr 9, 2007 1:54:41 PM
 */
public class ConsoleModel {
    private ConsoleSpatial spatial;
    private LinkedList<String> model;
    private StringBuilder currentLine;

    public ConsoleModel(ConsoleSpatial spatial) {
        this.spatial = spatial;
        model = new LinkedList<String>();
        currentLine = new StringBuilder();
    }

    public void newLine() {
        model.add(currentLine.toString());
        currentLine.delete(0, currentLine.length());
        updateSpatialAll();
    }

    public String getCurrentLine() {
        return currentLine.toString();
    }

    public void backspace() {
//        if (currentLine.length() > 2)
        currentLine.delete(currentLine.length() - 1, currentLine.length());
        updateSpatialLine();
    }

    public void append(char c) {
        currentLine.append(c);
        updateSpatialLine();
    }

    public void append(String string) {
        currentLine.append(string);
        updateSpatialLine();
    }

    public void writeLine(String message) {
        currentLine.delete(0, currentLine.length());
        append(message);
        newLine();
    }

    private void updateSpatialLine() {
        spatial.setLine(0, currentLine.toString());
    }

    private void updateSpatialAll() {
        ListIterator<String> it = model.listIterator(model.size());
        for (int i = 1; i < spatial.linesCount(); i++)
            if (it.hasPrevious())
                spatial.setLine(i, it.previous());

        // SINCE JSE 6.0 :-D
//        Iterator<String> it = model.descendingIterator();
//        for (int i = 1; i < spatial.linesCount(); i++)
//            if (it.hasNext())
//                spatial.setLine(i, it.next());
        updateSpatialLine();
    }

    public String getCommitedLine() {
        return model.getLast();
    }
}




See more files for this project here

Riot in Emerald city

Cyberpunk third-person 2100. noir RPG thriller using JMonkey. Its going to be mix between Bloodnet, Neuromancer, DeusEx in gameplay, with pieces of Uplink and many other mini-games for dealing with variety of tasks (lockpicking, hacking...)

Project homepage: http://sourceforge.net/projects/riot-in-ecity
Programming language(s): Java,XML
License: other

  ActionList.java
  Call.java
  ConsoleEngine.java
  ConsoleModel.java
  ConsoleSpatial.java
  ConsoleToggleAction.java
  Help.java
  InputProcessor.java
  ProcessingError.java
  Select.java
  Test.java