Package cn.webwheel.template

Examples of cn.webwheel.template.TemplateRenderer$Block


    }

    private ArrayList<Block> getBlocksAroundBlockByState(int column, int row, BlockState blockState){
        ArrayList<Block> blocksWithBlockState = new ArrayList<Block>();
        for(Direction direction : Direction.values()){
            Block block = getBlockFromDirection(column, row, direction);
            if(block!=null && block.getBlockState()!=null && block.getBlockState()== blockState)
                blocksWithBlockState.add(block);
        }
        return blocksWithBlockState;
    }
View Full Code Here


    private void generateBlocks(int columns, int rows) {
        blocks = new Block[columns][rows];
        for(int c=0; c<columns; c++)
            for(int r=0; r<rows; r++)
                blocks[c][r] = new Block(c*blockSize, r*blockSize, blockSize, blockSize);
    }
View Full Code Here

                else
                    g.drawImage(emptyFieldImage, 0, 0,null);

                for(int c=0; c<mineSweeper.getBlocks().length; c++)
                    for(int r=0; r<mineSweeper.getBlocks()[0].length; r++) {
                        Block block = mineSweeper.getBlocks()[c][r];

                        if(block.getBlockNumber()!=null){
                            g.setColor(block.getBlockNumber().getColor());
                            g.drawString(""+block.getBlockNumber().getNumber(), block.x+4, block.y+12);
                        }
                        if(block.getBlockState()!=null)
                            switch(block.getBlockState()){
                                case FLAG:      g.drawImage(flagBlock, block.x, block.y, null);
                                    break;
                                case BOMB:      g.drawImage(bombBlock, block.x, block.y, null);
                                    break;
                                case EMPTY:     if(block.getBlockNumber()==null)
                                    g.drawImage(emptyBlock, block.x, block.y, null);
                            }
                    }

            }
View Full Code Here

    }

    private void handle(HttpExchange httpExchange, String path, String query, Map<String, Object> params) throws IOException {
        if (path.toLowerCase().endsWith(".html") || path.toLowerCase().endsWith(".htm")) {

            TemplateRenderer renderer;
            StringWriter sw = new StringWriter();
            String rCharset;
            try {
                renderer = rendererFactory.create(path, null, null);
                rCharset = renderer.charset == null ? "utf-8" : renderer.charset;

                StringBuilder sb = new StringBuilder();
                File file = new File(root, path);
                char[] buf = new char[8192];
                int rd;
                InputStreamReader reader = new InputStreamReader(new FileInputStream(file), rCharset);
                try {
                    while ((rd = reader.read(buf)) != -1) {
                        sb.append(buf, 0, rd);
                    }
                } finally {
                    reader.close();
                }
                Map<String, Object> ctx = null;
                Pattern pat = Pattern.compile("<script.*?>\\s*var _model\\s*=\\s*(.+?);?\\s*</script>",
                        Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
                Matcher matcher = pat.matcher(sb.toString());
                if (matcher.find()) {
                    Map<String, Object> map = mapper.readValue(matcher.group(1), Map.class);
                    if (map.size() == 1) {
                        ctx = (Map) map.entrySet().iterator().next().getValue();
                    } else if (map.size() > 1) {
                        String mi = null;
                        try {
                            Object o = params.get("_model");
                            if (o instanceof String[]) {
                                mi = ((String[]) o)[0];
                            }
                        } catch (Exception ignored) {
                        }
                        ctx = (Map) map.get(mi);
                        if (ctx == null) {
                            ModelSelectDlg dlg = new ModelSelectDlg(path, map.keySet());
                            dlg.setVisible(true);
                            if (dlg.selected != null) {
                                ctx = (Map) map.get(dlg.selected);
                            }
                        }
                    }
                }
                if (ctx == null) ctx = Collections.emptyMap();
                renderer.render(sw, ctx);
            } catch (Exception e) {
                except(httpExchange, e);
                return;
            }

View Full Code Here

    }

    private void renderResource(HttpExchange httpExchange, String resource, Map<String, Object> ctx) throws Exception {
        byte[] data;
        if (ctx != null) {
            TemplateRenderer renderer = rendererFactory.create(resource, new FileVisitor() {
                @Override
                public String read(File root, String file, String charset) throws IOException {
                    InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream(file), "utf-8");
                    try {
                        StringBuilder sb = new StringBuilder();
                        int rd;
                        char[] buf = new char[4096];
                        while ((rd = reader.read(buf)) != -1) {
                            sb.append(buf, 0, rd);
                        }
                        return sb.toString();
                    } finally {
                        reader.close();
                    }
                }
            }, null);
            StringWriter sw = new StringWriter();
            try {
                renderer.render(sw, ctx);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw new IOException(e);
            }
View Full Code Here

    } else return entityHeight;
  }

  @Override
  public AlmostBoolean isBlockSolid(final int id) {
    final Block block = Block.byId[id];
    if (block == null || block.material == null) return AlmostBoolean.MAYBE;
    else return AlmostBoolean.match(block.material.isSolid());
  }
View Full Code Here

    else return AlmostBoolean.match(block.material.isSolid());
  }

  @Override
  public AlmostBoolean isBlockLiquid(final int id) {
    final Block block = Block.byId[id];
    if (block == null || block.material == null) return AlmostBoolean.MAYBE;
    else return AlmostBoolean.match(block.material.isLiquid());
  }
View Full Code Here

    } else return entityHeight;
  }

  @Override
  public AlmostBoolean isBlockSolid(final int id) {
    final Block block = Block.byId[id];
    if (block == null || block.material == null) return AlmostBoolean.MAYBE;
    else return AlmostBoolean.match(block.material.isSolid());
  }
View Full Code Here

    else return AlmostBoolean.match(block.material.isSolid());
  }

  @Override
  public AlmostBoolean isBlockLiquid(final int id) {
    final Block block = Block.byId[id];
    if (block == null || block.material == null) return AlmostBoolean.MAYBE;
    else return AlmostBoolean.match(block.material.isLiquid());
  }
View Full Code Here

    } else return entityHeight;
  }

  @Override
  public AlmostBoolean isBlockSolid(final int id) {
    final Block block = Block.byId[id];
    if (block == null || block.material == null) return AlmostBoolean.MAYBE;
    else return AlmostBoolean.match(block.material.isSolid());
  }
View Full Code Here

TOP

Related Classes of cn.webwheel.template.TemplateRenderer$Block

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.