Example usage for java.awt Font TRUETYPE_FONT

List of usage examples for java.awt Font TRUETYPE_FONT

Introduction

In this page you can find the example usage for java.awt Font TRUETYPE_FONT.

Prototype

int TRUETYPE_FONT

To view the source code for java.awt Font TRUETYPE_FONT.

Click Source Link

Document

Identify a font resource of type TRUETYPE.

Usage

From source file:iqq.app.core.service.impl.SkinServiceImpl.java

private Font loadFontFromFile(File file) {
    BufferedInputStream in = null;
    try {//from  www . j a  va  2  s. com
        in = new BufferedInputStream(new FileInputStream(file));
        Font font = Font.createFont(Font.TRUETYPE_FONT, in);
        return font;
    } catch (FileNotFoundException e) {
        LOG.warn("font " + file + "not found!", e);
    } catch (FontFormatException e) {
        LOG.warn("invalid font file!", e);
    } catch (IOException e) {
        LOG.warn("read font error!", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                LOG.warn("close font file error!", e);
            }
        }
    }
    return null;
}

From source file:PolyGlot.IOHandler.java

/**
 * compares testfont to loaded file. returns file if it represents the font
 *
 * @param path full path of file to test
 * @param testFont font to test against/*from ww  w  .j  a v  a2 s.c o  m*/
 * @return file if path leads to passed font, null otherwise
 */
private static File loadFont(String path, Font testFont) {
    File fontFile = new File(path);
    File ret = null;

    // unrecgnized types won't be loaded
    if (path.toLowerCase().endsWith(".ttf") || path.toLowerCase().endsWith(".otf")
            || path.toLowerCase().endsWith(".ttc") || path.toLowerCase().endsWith(".ttc")
            || path.toLowerCase().endsWith(".dfont")) {
        try {
            Font f = Font.createFont(Font.TRUETYPE_FONT, fontFile);

            // if names match, set ret to return file
            if (f.getName().equals(testFont.getName()) || f.getName().equals(testFont.getName() + " Regular")) {
                ret = fontFile;
            }

        } catch (FontFormatException e) {
            // null detected and message bubbled to user elsewhere
            ret = null;
        } catch (IOException e) {
            // null detected and message bubbled to user elsewhere
            ret = null;
        }
    }

    return ret;
}

From source file:pcgen.system.Main.java

private static void initPrintPreviewFonts() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String fontDir = ConfigurationSettings.getOutputSheetsDir() + File.separator + "fonts" + File.separator
            + "NotoSans" + File.separator;
    try {/*from www  .  j  av  a  2 s . c o m*/
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Regular.ttf")));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Bold.ttf")));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Italic.ttf")));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-BoldItalic.ttf")));
    } catch (IOException | FontFormatException ex) {
        Logging.errorPrint("Unexpected exception loading fonts fo print p", ex);
    }
}

From source file:me.oriley.crate.CrateGenerator.java

@Nullable
private static String getFontName(@NonNull String filePath) {
    try {/*from  w  ww .  j a  v  a  2  s . c o m*/
        FileInputStream inputStream = new FileInputStream(filePath);
        Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
        inputStream.close();
        return font.getName();
    } catch (FontFormatException | IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:fr.fg.server.core.TerritoryManager.java

private static BufferedImage createTerritoryMap(int idSector) {
    List<Area> areas = new ArrayList<Area>(DataAccess.getAreasBySector(idSector));

    float[][] points = new float[areas.size()][2];
    int[] dominatingAllies = new int[areas.size()];
    int i = 0;//from   w  w  w .j  a va 2s .co  m
    for (Area area : areas) {
        points[i][0] = area.getX() * MAP_SCALE;
        points[i][1] = area.getY() * MAP_SCALE;
        dominatingAllies[i] = area.getIdDominatingAlly();
        i++;
    }

    Hull hull = new Hull(points);
    MPolygon hullPolygon = hull.getRegion();
    float[][] newPoints = new float[points.length + hullPolygon.count()][2];
    System.arraycopy(points, 0, newPoints, 0, points.length);

    float[][] hullCoords = hullPolygon.getCoords();

    for (i = 0; i < hullPolygon.count(); i++) {
        double angle = Math.atan2(hullCoords[i][1], hullCoords[i][0]);
        double length = Math.sqrt(hullCoords[i][0] * hullCoords[i][0] + hullCoords[i][1] * hullCoords[i][1]);

        newPoints[i + points.length][0] = (float) (Math.cos(angle) * (length + 8 * MAP_SCALE));
        newPoints[i + points.length][1] = (float) (Math.sin(angle) * (length + 8 * MAP_SCALE));
    }

    points = newPoints;

    Voronoi voronoi = new Voronoi(points);
    Delaunay delaunay = new Delaunay(points);

    // Dcoupage en rgions
    MPolygon[] regions = voronoi.getRegions();

    // Calcule le rayon de la galaxie
    int radius = 0;

    for (Area area : areas) {
        radius = Math.max(radius, area.getX() * area.getX() + area.getY() * area.getY());
    }

    radius = (int) Math.floor(Math.sqrt(radius) * MAP_SCALE) + 10 * MAP_SCALE;
    int diameter = 2 * radius + 1;

    // Construit l'image avec les quadrants
    BufferedImage territoriesImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = (Graphics2D) territoriesImage.getGraphics();

    // Affecte une couleur  chaque alliance
    HashMap<Integer, Color> alliesColors = new HashMap<Integer, Color>();

    for (Area area : areas) {
        int idDominatingAlly = area.getIdDominatingAlly();
        if (idDominatingAlly != 0)
            alliesColors.put(idDominatingAlly,
                    Ally.TERRITORY_COLORS[DataAccess.getAllyById(idDominatingAlly).getColor()]);
    }

    Polygon[] polygons = new Polygon[regions.length];
    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] != 0) {
            polygons[i] = createPolygon(regions[i].getCoords(), radius + 1, 3);
        }
    }

    // Dessine tous les secteurs
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0)
            continue;

        Polygon p = polygons[i];

        // Dessine le polygone
        g.setColor(alliesColors.get(dominatingAllies[i]));
        g.fill(p);

        // Rempli les espaces entre les polygones adjacents qui
        // correspondent au territoire d'une mme alliance
        int[] linkedRegions = delaunay.getLinked(i);
        for (int j = 0; j < linkedRegions.length; j++) {
            int linkedRegion = linkedRegions[j];

            if (linkedRegion >= areas.size())
                continue;

            if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                if (linkedRegion <= i)
                    continue;

                float[][] coords1 = regions[i].getCoords();
                float[][] coords2 = regions[linkedRegion].getCoords();

                int junctionIndex = 0;
                int[][] junctions = new int[2][2];

                search: for (int k = 0; k < coords1.length; k++) {
                    for (int l = 0; l < coords2.length; l++) {
                        if (coords1[k][0] == coords2[l][0] && coords1[k][1] == coords2[l][1]) {
                            junctions[junctionIndex][0] = k;
                            junctions[junctionIndex][1] = l;

                            junctionIndex++;

                            if (junctionIndex == 2) {
                                int[] xpts = new int[] { polygons[i].xpoints[junctions[0][0]],
                                        polygons[linkedRegion].xpoints[junctions[0][1]],
                                        polygons[linkedRegion].xpoints[junctions[1][1]],
                                        polygons[i].xpoints[junctions[1][0]], };
                                int[] ypts = new int[] { polygons[i].ypoints[junctions[0][0]],
                                        polygons[linkedRegion].ypoints[junctions[0][1]],
                                        polygons[linkedRegion].ypoints[junctions[1][1]],
                                        polygons[i].ypoints[junctions[1][0]], };

                                Polygon border = new Polygon(xpts, ypts, 4);
                                g.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
                                g.fill(border);
                                g.draw(border);
                                break search;
                            }
                            break;
                        }
                    }
                }
            }
        }
    }

    // Dessine des lignes de contours des territoires
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0)
            continue;

        g.setStroke(new BasicStroke(1.5f));
        g.setColor(alliesColors.get(dominatingAllies[i]).brighter().brighter());

        float[][] coords1 = regions[i].getCoords();

        lines: for (int j = 0; j < coords1.length; j++) {
            int[] linkedRegions = delaunay.getLinked(i);
            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size())
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                    float[][] coords2 = regions[linkedRegion].getCoords();

                    for (int m = 0; m < coords2.length; m++) {
                        if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1]
                                && ((coords1[(j + 1) % coords1.length][0] == coords2[(m + 1)
                                        % coords2.length][0]
                                        && coords1[(j + 1) % coords1.length][1] == coords2[(m + 1)
                                                % coords2.length][1])
                                        || (coords1[(j + 1)
                                                % coords1.length][0] == coords2[(m - 1 + coords2.length)
                                                        % coords2.length][0]
                                                && coords1[(j + 1)
                                                        % coords1.length][1] == coords2[(m - 1 + coords2.length)
                                                                % coords2.length][1]))) {
                            continue lines;
                        }
                    }
                }
            }

            g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]),
                    Math.round(polygons[i].xpoints[(j + 1) % coords1.length]),
                    Math.round(polygons[i].ypoints[(j + 1) % coords1.length]));
        }

        for (int j = 0; j < coords1.length; j++) {
            int neighbours = 0;
            int lastNeighbourRegion = -1;
            int neighbourCoordsIndex = -1;

            int[] linkedRegions = delaunay.getLinked(i);
            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size())
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion]) {
                    float[][] coords2 = regions[linkedRegion].getCoords();

                    for (int m = 0; m < coords2.length; m++) {
                        if (coords1[j][0] == coords2[m][0] && coords1[j][1] == coords2[m][1]) {
                            neighbours++;
                            lastNeighbourRegion = linkedRegion;
                            neighbourCoordsIndex = m;
                            break;
                        }
                    }
                }
            }

            if (neighbours == 1) {
                g.drawLine(Math.round(polygons[i].xpoints[j]), Math.round(polygons[i].ypoints[j]),
                        Math.round(polygons[lastNeighbourRegion].xpoints[neighbourCoordsIndex]),
                        Math.round(polygons[lastNeighbourRegion].ypoints[neighbourCoordsIndex]));
            }
        }
    }

    BufferedImage finalImage = new BufferedImage(diameter, diameter, BufferedImage.TYPE_INT_ARGB);

    g = (Graphics2D) finalImage.getGraphics();

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .15f));
    g.drawImage(territoriesImage, 0, 0, null);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, .5f));

    // Charge la police pour afficher le nom des alliances
    try {
        Font textFont = Font.createFont(Font.TRUETYPE_FONT,
                Action.class.getClassLoader().getResourceAsStream("fr/fg/server/resources/TinDog.ttf"));
        textFont = textFont.deriveFont(12f).deriveFont(Font.BOLD);
        g.setFont(textFont);
    } catch (Exception e) {
        LoggingSystem.getServerLogger().warn("Could not load quadrant map font.", e);
    }
    FontMetrics fm = g.getFontMetrics();

    ArrayList<Integer> closedRegions = new ArrayList<Integer>();

    for (i = 0; i < areas.size(); i++) {
        if (dominatingAllies[i] == 0 || closedRegions.contains(i))
            continue;

        ArrayList<Integer> allyRegions = new ArrayList<Integer>();
        ArrayList<Integer> openRegions = new ArrayList<Integer>();

        openRegions.add(i);

        while (openRegions.size() > 0) {
            int currentRegion = openRegions.remove(0);
            allyRegions.add(currentRegion);
            closedRegions.add(currentRegion);

            int[] linkedRegions = delaunay.getLinked(currentRegion);

            for (int k = 0; k < linkedRegions.length; k++) {
                int linkedRegion = linkedRegions[k];

                if (linkedRegion >= areas.size() || openRegions.contains(linkedRegion)
                        || allyRegions.contains(linkedRegion))
                    continue;

                if (dominatingAllies[i] == dominatingAllies[linkedRegion])
                    openRegions.add(linkedRegion);
            }
        }

        Area area = areas.get(i);
        long xsum = 0;
        long ysum = 0;

        for (int k = 0; k < allyRegions.size(); k++) {
            int allyRegion = allyRegions.get(k);
            area = areas.get(allyRegion);

            xsum += area.getX();
            ysum += area.getY();
        }

        int x = (int) (xsum / allyRegions.size()) * MAP_SCALE + radius + 1;
        int y = (int) (-ysum / allyRegions.size()) * MAP_SCALE + radius + 1;
        ;

        Point point = new Point(x, y);
        boolean validLocation = false;
        for (int k = 0; k < allyRegions.size(); k++) {
            int allyRegion = allyRegions.get(k);

            if (polygons[allyRegion].contains(point)) {
                validLocation = true;
                break;
            }
        }

        if (validLocation) {
            if (allyRegions.size() == 1)
                y -= 14;
        } else {
            int xmid = (int) (xsum / allyRegions.size());
            int ymid = (int) (ysum / allyRegions.size());

            area = areas.get(i);
            int dx = area.getX() - xmid;
            int dy = area.getY() - ymid;
            int distance = dx * dx + dy * dy;

            int nearestAreaIndex = i;
            int nearestDistance = distance;

            for (int k = 0; k < allyRegions.size(); k++) {
                int allyRegion = allyRegions.get(k);

                area = areas.get(allyRegion);
                dx = area.getX() - xmid;
                dy = area.getY() - ymid;
                distance = dx * dx + dy * dy;

                if (distance < nearestDistance) {
                    nearestAreaIndex = allyRegion;
                    nearestDistance = distance;
                }
            }

            area = areas.get(nearestAreaIndex);
            x = area.getX() * MAP_SCALE + radius + 1;
            y = -area.getY() * MAP_SCALE + radius - 13;
        }

        // Dessine le tag de l'alliance
        String allyTag = "[ " + DataAccess.getAllyById(dominatingAllies[i]).getTag() + " ]";
        g.setColor(Color.BLACK);
        g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2 + 1, y);
        g.setColor(alliesColors.get(dominatingAllies[i]));
        g.drawString(allyTag, x - fm.stringWidth(allyTag) / 2, y);
    }

    return finalImage;
}

From source file:cognitivej.vision.overlay.builder.ImageOverlayBuilder.java

private ImageOverlayBuilder(@NotNull BufferedImage bufferedImage) {
    this.bufferedImage = bufferedImage;
    try {/*  ww w .ja  va2  s .c om*/
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT,
                new File("src/main/resources/font/notosans/NotoSans-Bold.ttf")));
    } catch (IOException | FontFormatException ignored) {
    }

}

From source file:org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.java

/**
 * {@inheritDoc}/*w w w .  j  a  va  2s. c  o  m*/
 */
public Font getawtFont() throws IOException {
    PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary) getFontDescriptor();
    if (awtFont == null) {
        PDStream ff2Stream = fd.getFontFile2();
        if (ff2Stream != null) {
            try {
                // create a font with the embedded data
                awtFont = Font.createFont(Font.TRUETYPE_FONT, ff2Stream.createInputStream());
            } catch (FontFormatException f) {
                log.info("Can't read the embedded font " + fd.getFontName());
            }
            if (awtFont == null) {
                awtFont = FontManager.getAwtFont(fd.getFontName());
                if (awtFont != null) {
                    log.info("Using font " + awtFont.getName() + " instead");
                }
                setIsFontSubstituted(true);
            }
        } else {
            // check if the font is part of our environment
            awtFont = FontManager.getAwtFont(fd.getFontName());
            if (awtFont == null) {
                log.info("Can't find the specified font " + fd.getFontName());
                // check if there is a font mapping for an external font file
                TrueTypeFont ttf = getExternalFontFile2(fd);
                if (ttf != null) {
                    try {
                        awtFont = Font.createFont(Font.TRUETYPE_FONT, ttf.getOriginalData());
                    } catch (FontFormatException f) {
                        log.info("Can't read the external fontfile " + fd.getFontName());
                    }
                }
            }
        }
        if (awtFont == null) {
            // we can't find anything, so we have to use the standard font
            awtFont = FontManager.getStandardFont();
            log.info("Using font " + awtFont.getName() + " instead");
            setIsFontSubstituted(true);
        }
    }
    return awtFont;
}

From source file:org.geopublishing.geopublisher.AMLExporter.java

/**
 * Creates an aml:fonts tag that lists the names of all the fonts files in
 * ad/font folder. The list of fonts is determined while
 *//* w w w  . j a va2  s.  co m*/
protected Node exportFonts(Document document) {
    final Element fontsElement = document.createElementNS(AMLUtil.AMLURI, AMLUtil.TAG_FONTS);

    File fontsDir = getAce().getFontsDir();

    Collection<File> listFiles = FileUtils.listFiles(fontsDir, GpUtil.FontsFilesFilter,
            FilterUtil.BlacklistedFoldersFilter);
    for (File f : listFiles) {

        // Test whether the font is readable
        String relPath = f.getAbsolutePath().substring(fontsDir.getAbsolutePath().length() + 1);
        try {
            Font.createFont(Font.TRUETYPE_FONT, f);
            final Element fontElement = document.createElementNS(AMLUtil.AMLURI, AMLUtil.TAG_FONT);
            fontElement.setAttribute(AMLUtil.ATT_FONT_FILENAME, relPath);
            fontsElement.appendChild(fontElement);
        } catch (Exception e) {
            LOGGER.info("Not exporting a reference to broken font " + relPath + " in " + fontsDir, e);
        }

    }

    return fontsElement;
}

From source file:literarytermsquestionbank.RomeoAndJuliet.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    // Set custom  icon
    this.setIconImage(
            Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Resources/Images/book-icon_rj.png")));

    // Set custom fonts
    try {//w w w. ja  v a 2s .  c  o m
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

        // Load Old English from resources
        Font englishFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/OLDENGL.TTF"));
        ge.registerFont(englishFontFace);
        actLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 30f));
        sceneLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 16f));
        lineNumberLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 16f));

        // Load Matura Script font from resources
        Font maturaFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/MATURASC.TTF"));
        ge.registerFont(maturaFontFace);
        tabbedPane.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        questionLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        checkButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        stuckLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        rescueButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        answerLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        youAreViewingLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        quoteIndexTextField.setFont(maturaFontFace.deriveFont(Font.PLAIN, 24f));
        totalNumberLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 36f));
        goButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 24f));
        randomButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        previousButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        nextButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        backButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));

        // Load Corsova font from resources
        Font corsovaFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/MTCORSVA.TTF"));
        ge.registerFont(corsovaFontFace);
        clueLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f));
        passageLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f));
        examplesLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f));
        commentsLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 14f));

        // Load Imprint font from resources
        Font imprintFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/IMPRISHA.TTF"));
        ge.registerFont(imprintFontFace);
        quoteTopLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
        quoteBottomLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
    } catch (FontFormatException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    }

    JSONParser parser = new JSONParser();

    try {
        // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package.
        Object quoteObj = parser
                .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json")));

        // This casts the object to a JSONObject for future manipulation
        JSONObject jsonObject = (JSONObject) quoteObj;

        // This array holds all the quotes
        JSONArray quotesArray = (JSONArray) jsonObject.get("Romeo and Juliet");
        Iterator<JSONObject> iterator = quotesArray.iterator();

        // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList
        while (iterator.hasNext()) {
            Collections.addAll(quotesList, iterator.next());
            totalNumberOfQuotes++;
        }

        // Init randomizer
        Random rand = new Random();

        // Generate a random integer between 1 and size of the ArrayList
        quoteIndex = rand.nextInt(quotesList.size()) + 1;

        generateQuote(quoteIndex); // This calls a method to generate a quote and display it
    } catch (Exception e) { // This means something went very wrong when starting the program
        System.out.println("Uh oh, something bad happened. Possible database corruption.");
        JOptionPane.showMessageDialog(null,
                "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }
}

From source file:Gui.HistoryAdminGUINew.java

public void showStatHistory() {
    // method statGreensociety......  History 
    int tempRepair = history.statGreensocietyRepair();
    int tempBorrow = history.statGreensocietyBorrow();
    int tempReturn = history.statGreensocietyReturn();
    DefaultCategoryDataset barchartData = new DefaultCategoryDataset();

    barchartData.setValue(tempRepair, "0", "RepairHistory");
    barchartData.setValue(tempBorrow, "1", "BorrowHistory");
    barchartData.setValue(tempReturn, "2", "ReturnHistory");

    JFreeChart chart = ChartFactory.createBarChart("History Statictics", "History", "Times", barchartData,
            PlotOrientation.HORIZONTAL, false, true, false);

    //        chart.getTitle().setPaint(Color.WHITE);   //??

    //--------SET FONT--------------
    try {//  w  w w. j av  a  2  s.c o m
        File f = new File("leelawad.ttf");
        Font customFont = Font.createFont(Font.TRUETYPE_FONT, f);
        customFont = customFont.deriveFont(16f);
        chart.getTitle().setFont(customFont);
        System.out.println(customFont.getFontName());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (FontFormatException | IOException e) {
        e.printStackTrace();
    }
    //------------------------------
    chart.setBackgroundPaint(new Color(19, 175, 248)); //setBackground ?

    CategoryPlot barchartPlot = chart.getCategoryPlot();

    barchartPlot.setRangeGridlinePaint(Color.BLACK); //set ??

    //Customize renderer
    BarRenderer renderer = (BarRenderer) barchartPlot.getRenderer();
    java.awt.Paint paint1 = new Color(255, 0, 0);
    java.awt.Paint paint2 = new Color(0, 0, 255);
    java.awt.Paint paint3 = new Color(255, 255, 0);

    renderer.setSeriesPaint(0, paint1); //Color for RepairGraph
    renderer.setSeriesPaint(1, paint2); //Color for BorrowGraph
    renderer.setSeriesPaint(2, paint3); //Color for ReturnGraph

    ChartPanel barPanel = new ChartPanel(chart);
    jPanelShowGraph.removeAll();
    jPanelShowGraph.add(barPanel, BorderLayout.CENTER);
    jPanelShowGraph.validate();
}