예제 #1
0
  public static void main(String[] args) throws Exception {

    final String devId = (args.length > 0) ? args[0] : "" /*"fb0"*/;

    Surface g = null;
    try {
      Device dev = null;
      if ("".equals(devId)) {
        final Collection<Device> devs = DeviceUtils.getDevicesByAPI(FrameBufferAPI.class);
        int dev_count = devs.size();
        if (dev_count > 0) {
          Device[] dev_a = devs.toArray(new Device[dev_count]);
          dev = dev_a[0];
        }
      }

      if (dev == null) {
        final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
        dev = dm.getDevice(devId);
      }

      final FrameBufferAPI api = dev.getAPI(FrameBufferAPI.class);
      final FrameBufferConfiguration conf = api.getConfigurations()[0];

      g = api.open(conf);

      TextScreenConsoleManager mgr = new TextScreenConsoleManager();

      ScrollableTextScreen ts =
          new FBConsole.FBPcTextScreen(g).createCompatibleScrollableBufferScreen(500);

      ScrollableTextScreenConsole first =
          new ScrollableTextScreenConsole(
              mgr,
              "console",
              ts,
              ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE);

      mgr.registerConsole(first);
      mgr.focus(first);

      new CommandShell(first).run();
      Thread.sleep(60 * 1000);

    } catch (Throwable ex) {
      log.error("Error in FBConsole", ex);
    } finally {
      if (g != null) {
        log.info("Close graphics");
        g.close();
      }
    }
  }
예제 #2
0
 protected void paintComponent() {
   ig.setColor(Color.BLACK);
   ig.fillRect(0, 0, sw, sh);
   ig.setColor(Color.WHITE);
   ig.setFont(font);
   for (int i = 0; i < FBPcTextScreen.SCREEN_HEIGHT; i++) {
     int offset = i * FBPcTextScreen.SCREEN_WIDTH;
     int lenght = FBPcTextScreen.SCREEN_WIDTH;
     ig.drawChars(buffer, offset, lenght, margin, h + i * h);
   }
   g.drawCompatibleRaster(bi.getRaster(), 0, 0, 0, 0, sw, sh, Color.BLACK);
 }
예제 #3
0
  public void render(
      Surface surface, Shape clip, AffineTransform tx, CharSequence text, int x, int y, Color c) {
    try {
      final GeneralPath gp = new GeneralPath();
      gp.moveTo(x, y);

      final GlyphTable glyphTable = fontData.getGlyphTable();
      final CMapTable cmapTable = fontData.getCMapTable();
      final HorizontalHeaderTable hheadTable = fontData.getHorizontalHeaderTable();
      final HorizontalMetricsTable hmTable = fontData.getHorizontalMetricsTable();

      if (!(cmapTable.getNrEncodingTables() > 0)) {
        throw new RuntimeException("No Encoding is found!");
      }
      final CMapTable.EncodingTable encTable = cmapTable.getEncodingTable(0);
      if (encTable.getTableFormat() == null) {
        throw new RuntimeException("The table is NUll!!");
      }
      final double ascent = hheadTable.getAscent();

      final AffineTransform tx2 = new AffineTransform();
      final double scale = fontSize / (-hheadTable.getDescent() + ascent);

      tx2.translate(x, y + fontSize);
      tx2.scale(scale, -scale);
      tx2.translate(0, ascent);

      for (int i = 0; i < text.length(); i++) {
        // get the index for the needed glyph
        final char character = text.charAt(i);
        final int index = encTable.getTableFormat().getGlyphIndex(character);
        if (character != ' ') {
          Shape shape = ((ShapedGlyph) glyphTable.getGlyph(index)).getShape();
          gp.append(shape.getPathIterator(tx2), false);
        }
        tx2.translate(hmTable.getAdvanceWidth(index), 0);
      }
      surface.draw(gp, clip, tx, c, Surface.PAINT_MODE);
    } catch (IOException ex) {
      log.error("Error drawing text", ex);
    }
  }