View Javadoc

1   /*
2    * telnetservice, Open Source Telnet Service Library
3    *
4    * Copyright (c) 2007-2008, Joseph Walid Gédéon, and individual
5    * contributors as indicated by the @authors tag. See copyright.txt in the
6    * distribution for a full listing of individual contributors.
7    * All rights reserved.
8    *
9    * This is free software; you can redistribute it and/or modify it
10   * under the terms of the Modified BSD License as published by the Free
11   * Software Foundation.
12   *
13   * This software is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Modified
16   * BSD License for more details.
17   *
18   * You should have received a copy of the Modified BSD License along with
19   * this software; if not, write to the Free Software Foundation, Inc.,
20   * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the
21   * FSF site: http://www.fsf.org.
22   */
23  package fr.gedeon.telnetservice.coreexample1;
24  
25  import fr.gedeon.telnetservice.OutputFormatSpi;
26  import fr.gedeon.telnetservice.OutputFormatVT100Impl;
27  import fr.gedeon.telnetservice.SessionState;
28  import fr.gedeon.telnetservice.coreexample1.ActionListenerExample1Impl.Command;
29  
30  class OutputFormatExample1Impl extends OutputFormatVT100Impl implements OutputFormatSpi
31  {
32  	@Override
33  	public boolean formats(Object subject) {
34  		return subject instanceof Command;
35  	}
36  	
37  	@Override
38      public StringBuffer format(SessionState sessionState, StringBuffer buffer, Object subject) {
39          if (subject instanceof Command) {
40              Command command = (Command)subject;
41              String eoln = sessionState.getSession().getConsoleDelegate().getEOLN();
42              setAttrs(buffer, new byte[][] { ATTRS_FORE_GREEN, STYLE_UNDERSCORE });
43              buffer.append(command.getName());
44              resetAttrs(buffer);
45              setAttrs(buffer, new byte[][] { ATTRS_FORE_YELLOW });
46              buffer.append(": ").append(command.getDescription());
47              resetAttrs(buffer);
48              buffer.append(eoln);
49          }
50          else {
51              buffer.append(subject);
52          }
53          return buffer;
54      }
55  }