import java.awt.Color; import java.awt.Graphics; import java.util.ArrayList; import java.util.List; import javax.swing.JPanel; public class BubblePanel extends JPanel { private final List<Bubble> bubbles; public BubblePanel() { bubbles = new ArrayList<>(); for (int rowIndex = 0; rowIndex < 10; rowIndex++) for (int columnIndex = 0; columnIndex < 20; columnIndex++) bubbles.add(new Bubble(100 + columnIndex * 60, 100 + rowIndex * 60, 28, Color.YELLOW)); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); for (final Bubble bubble : bubbles) bubble.paintComponent(g); } }
if (Gdx.input.isTouched()) { float x = Gdx.input.getX(); float y = Gdx.input.getY(); float yR = viewport.height / (y - viewport.y); // the y ratio y = 480 / yR; float xR = viewport.width / (x - viewport.x); // the x ratio x = 800 / xR; bubbles.add(new Bubble(x, 480 - y)); }
private Stream<? extends K> performParse(Map<String, ParsedSentence> cache, ParseInModule parser, Scanner scanner, Bubble b) { int startLine = b.att().get("contentStartLine", Integer.class); int startColumn = b.att().get("contentStartColumn", Integer.class); Source source = b.att().get(Source.class); Tuple2<Either<java.util.Set<ParseFailedException>, K>, java.util.Set<ParseFailedException>> result; if (cache.containsKey(b.contents())) { ParsedSentence parse = cache.get(b.contents()); Optional<Source> cacheSource = parse.getParse().source(); //Cache might contain content from an identical file but another source path. //The content will have wrong Source attribute and must be invalidated. if (cacheSource.isPresent() && cacheSource.get().equals(source)) { cachedBubbles.getAndIncrement(); kem.addAllKException(parse.getWarnings().stream().map(e -> e.getKException()).collect(Collectors.toList())); return Stream.of(parse.getParse()); } } result = parser.parseString(b.contents(), START_SYMBOL, scanner, source, startLine, startColumn, !b.att().contains("macro") && !b.att().contains("alias")); parsedBubbles.getAndIncrement(); kem.addAllKException(result._2().stream().map(e -> e.getKException()).collect(Collectors.toList())); if (result._1().isRight()) { KApply k = (KApply) new TreeNodesToKORE(Outer::parseSort, isStrict).down(result._1().right().get()); k = KApply(k.klabel(), k.klist(), k.att().addAll(b.att().remove("contentStartLine").remove("contentStartColumn").remove(Source.class).remove(Location.class))); cache.put(b.contents(), new ParsedSentence(k, new HashSet<>(result._2()))); return Stream.of(k); } else { errors.addAll(result._1().left().get()); return Stream.empty(); } } }
.filter(s -> s instanceof Bubble) .map(b -> (Bubble) b) .filter(b -> !b.sentenceType().equals("config")).count() == 0) return module; .filter(s -> s instanceof Bubble) .map(b -> (Bubble) b) .filter(b -> b.sentenceType().equals("rule")) .flatMap(b -> performParse(cache.getCache(), parser, realScanner, b)) .map(this::upRule) .filter(s -> s instanceof Bubble) .map(b -> (Bubble) b) .filter(b -> b.sentenceType().equals("context")) .flatMap(b -> performParse(cache.getCache(), parser, realScanner, b)) .map(this::upContext)
getServer().getPluginManager().registerEvents(this, new Bubble());
.filter(s -> s instanceof Bubble) .map(b -> (Bubble) b) .filter(b -> b.sentenceType().equals("config")) .findFirst().isPresent();
.filter(s -> s instanceof Bubble) .map(b -> (Bubble) b) .filter(b -> b.sentenceType().equals("config")).count() == 0) return inputModule; .filter(s -> s instanceof Bubble) .map(b -> (Bubble) b) .filter(b -> b.sentenceType().equals("config")) .flatMap(b -> parseBubble.apply(module, b)) .map(contents -> {
public static final Dimension PREF_SIZE = new Dimension(70, 70); //in main method or you can override `getPreferredSize()` Bubble bub = new Bubble(50, 50); bub.setPreferredSize(PREF_SIZE);
public Rule parseRule(CompiledDefinition compiledDef, String contents, Source source) { errors = java.util.Collections.synchronizedSet(Sets.newHashSet()); gen = new RuleGrammarGenerator(compiledDef.kompiledDefinition); ParseInModule parser = RuleGrammarGenerator .getCombinedGrammar(gen.getRuleGrammar(compiledDef.executionModule()), isStrict); try (Scanner scanner = parser.getScanner()) { //required for Windows. java.util.Set<K> res = performParse(new HashMap<>(), parser, scanner, new Bubble("rule", contents, Att().add("contentStartLine", Integer.class, 1) .add("contentStartColumn", Integer.class, 1).add(Source.class, source))) .collect(Collectors.toSet()); if (!errors.isEmpty()) { throw errors.iterator().next(); } return upRule(res.iterator().next()); } }