Search in sources :

Example 1 with PFont

use of processing.core.PFont in project OpenTripPlanner by opentripplanner.

the class ShowGraph method setup.

/*
     * Setup Processing applet
     */
public void setup() {
    size(getSize().width, getSize().height, P2D);
    /* Build spatial index of vertices and edges */
    buildSpatialIndex();
    /* Set model bounds to encompass all vertices in the index, and then some */
    modelBounds = (Envelope) (vertexIndex.getRoot().getBounds());
    modelBounds.expandBy(0.02);
    matchAspect();
    /* save this zoom level to allow returning to default later */
    modelOuterBounds = new Envelope(modelBounds);
    /* find and set up the appropriate font */
    String[] fonts = PFont.list();
    String[] preferredFonts = { "Mono", "Courier" };
    PFont font = null;
    for (String preferredFontName : preferredFonts) {
        for (String fontName : fonts) {
            if (fontName.contains(preferredFontName)) {
                font = createFont(fontName, 16);
                break;
            }
        }
        if (font != null) {
            break;
        }
    }
    textFont(font);
    textMode(SCREEN);
    addMouseWheelListener(this);
    addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            super.mouseMoved(e);
            Point p = e.getPoint();
            mouseModelX = toModelX(p.x);
            mouseModelY = toModelY(p.y);
        }
    });
    addComponentListener(new ComponentAdapter() {

        public void componentResized(ComponentEvent e) {
            matchAspect();
            drawLevel = DRAW_PARTIAL;
        }
    });
    frameRate(FRAME_RATE);
}
Also used : MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) PFont(processing.core.PFont) Point(java.awt.Point) ComponentEvent(java.awt.event.ComponentEvent) Envelope(com.vividsolutions.jts.geom.Envelope) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 2 with PFont

use of processing.core.PFont in project WordCram by danbernier.

the class PlacerHeatMap method draw.

public void draw(PApplet sketch) {
    RectStack rectStack = new RectStack();
    for (int i = 0; i < words.length; i++) {
        Word word = words[i];
        PFont wordFont = word.getFont(fonter);
        float wordSize = word.getSize(sizer, i, words.length);
        float wordAngle = word.getAngle(angler);
        Shape shape = shaper.getShapeFor(word.word, wordFont, wordSize, wordAngle);
        Rectangle2D rect = shape.getBounds2D();
        // return r.getHeight() < minShapeSize || r.getWidth() < minShapeSize;
        int wordImageWidth = (int) rect.getWidth();
        int wordImageHeight = (int) rect.getHeight();
        PVector desiredLocation = word.getTargetPlace(placer, i, words.length, wordImageWidth, wordImageHeight, sketch.width, sketch.height);
        // sketch.rect(desiredLocation.x, desiredLocation.y, wordImageWidth, wordImageHeight);
        rectStack.add((int) desiredLocation.x, (int) desiredLocation.y, wordImageWidth, wordImageHeight);
    }
    RectGrid grid = new RectGrid(rectStack);
    grid.draw(sketch);
}
Also used : PVector(processing.core.PVector) Shape(java.awt.Shape) PFont(processing.core.PFont) Rectangle2D(java.awt.geom.Rectangle2D)

Example 3 with PFont

use of processing.core.PFont in project WordCram by danbernier.

the class WordCramEngine method wordsIntoEngineWords.

private ArrayList<EngineWord> wordsIntoEngineWords(Word[] words, WordShaper wordShaper, BBTreeBuilder bbTreeBuilder) {
    ArrayList<EngineWord> engineWords = new ArrayList<EngineWord>();
    int maxNumberOfWords = words.length;
    if (renderOptions.maxNumberOfWordsToDraw >= 0) {
        maxNumberOfWords = Math.min(maxNumberOfWords, renderOptions.maxNumberOfWordsToDraw);
    }
    for (int i = 0; i < maxNumberOfWords; i++) {
        Word word = words[i];
        EngineWord eWord = new EngineWord(word, i, words.length, bbTreeBuilder);
        PFont wordFont = word.getFont(fonter);
        float wordSize = word.getSize(sizer, i, words.length);
        float wordAngle = word.getAngle(angler);
        Shape shape = wordShaper.getShapeFor(eWord.word.word, wordFont, wordSize, wordAngle);
        if (isTooSmall(shape, renderOptions.minShapeSize)) {
            skipWord(word, WordSkipReason.SHAPE_WAS_TOO_SMALL);
        } else {
            eWord.setShape(shape, renderOptions.wordPadding);
            // DON'T add eWords with no shape.
            engineWords.add(eWord);
        }
    }
    for (int i = maxNumberOfWords; i < words.length; i++) {
        skipWord(words[i], WordSkipReason.WAS_OVER_MAX_NUMBER_OF_WORDS);
    }
    return engineWords;
}
Also used : Shape(java.awt.Shape) PFont(processing.core.PFont) ArrayList(java.util.ArrayList)

Example 4 with PFont

use of processing.core.PFont in project WordCram by danbernier.

the class AWordCramEngine method canBeCreatedAndWillShapeWords.

// http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html
@Test
public void canBeCreatedAndWillShapeWords() {
    Word[] words = new Word[] { new Word("ten", 10), new Word("nine", 9), new Word("eight", 8) };
    float[] sizes = new float[] { 100, 80, 60 };
    float[] angles = new float[] { 0, 1, 2 };
    PFont pFont = mock(PFont.class);
    for (int i = 0; i < words.length; i++) {
        when(fonter.fontFor(words[i])).thenReturn(pFont);
        when(sizer.sizeFor(eq(words[i]), anyInt(), anyInt())).thenReturn(sizes[i]);
        when(angler.angleFor(words[i])).thenReturn(angles[i]);
        when(shaper.getShapeFor(words[i].word, pFont, sizes[i], angles[i])).thenReturn(new Rectangle(0, 0, 20, 20));
    }
    WordCramEngine engine = getEngine(words);
    for (int i = 0; i < words.length; i++) {
        verify(shaper).getShapeFor(words[i].word, pFont, sizes[i], angles[i]);
    }
}
Also used : PFont(processing.core.PFont) Rectangle(java.awt.Rectangle) Test(org.junit.Test)

Aggregations

PFont (processing.core.PFont)4 Shape (java.awt.Shape)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 MouseEvent (java.awt.event.MouseEvent)1 MouseMotionAdapter (java.awt.event.MouseMotionAdapter)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 PVector (processing.core.PVector)1