001/*
002 * To change this template, choose Tools | Templates
003 * and open the template in the editor.
004 */
005package org.anarres.qemu.exec.host.chardev;
006
007import java.util.Map;
008
009/**
010 *
011 * @author shevek
012 */
013public class VirtualConsoleCharDevice extends AbstractCharDevice {
014
015    private final Integer width;
016    private final Integer height;
017    private final boolean chars;
018
019    public VirtualConsoleCharDevice(int width, int height, boolean chars) {
020        super("vc");
021        this.width = width;
022        this.height = height;
023        this.chars = chars;
024    }
025
026    public VirtualConsoleCharDevice(int width, int height) {
027        this(width, height, true);
028    }
029
030    public VirtualConsoleCharDevice() {
031        super("vc");
032        this.width = null;
033        this.height = null;
034        this.chars = false;
035    }
036
037    @Override
038    protected void addProperties(Map<String, Object> m) {
039        super.addProperties(m);
040        if (width == null || height == null)
041            return;
042        if (chars) {
043            m.put("cols", width);
044            m.put("rows", height);
045        } else {
046            m.put("width", width);
047            m.put("height", height);
048        }
049    }
050
051    @Override
052    public String toString() {
053        StringBuilder buf = new StringBuilder("vc");
054        if (width != null) {
055            buf.append(':').append(String.valueOf(width));
056            if (chars)
057                buf.append('C');
058            buf.append('x').append(String.valueOf(height));
059            if (chars)
060                buf.append('C');
061        }
062        return buf.toString();
063    }
064}