Example usage for java.awt Graphics getFont

List of usage examples for java.awt Graphics getFont

Introduction

In this page you can find the example usage for java.awt Graphics getFont.

Prototype

public abstract Font getFont();

Source Link

Document

Gets the current font.

Usage

From source file:lu.fisch.unimozer.Diagram.java

private void printHeaderFooter(Graphics g, PageFormat pageFormat, int page, String className) {
    int origPage = page + 1;

    // Add header
    g.setColor(Color.BLACK);//  w ww. j  a va 2  s .com
    int xOffset = (int) pageFormat.getImageableX();
    int topOffset = (int) pageFormat.getImageableY() + 20;
    int bottom = (int) (pageFormat.getImageableY() + pageFormat.getImageableHeight());
    // header line
    g.drawLine(xOffset, topOffset - 8, xOffset + (int) pageFormat.getImageableWidth(), topOffset - 8);
    // footer line
    g.drawLine(xOffset, bottom - 11, xOffset + (int) pageFormat.getImageableWidth(), bottom - 11);
    g.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 10));

    Graphics2D gg = (Graphics2D) g;
    String pageString = "Page " + origPage;
    int tw = (int) gg.getFont().getStringBounds(pageString, gg.getFontRenderContext()).getWidth();
    // footer text
    g.drawString(pageString, xOffset + (int) pageFormat.getImageableWidth() - tw, bottom - 2);

    //System.err.println("Printing: "+directoryName);
    if (directoryName != null) {
        g.setFont(new Font(g.getFont().getFontName(), Font.ITALIC, 10));
        String filename = directoryName;
        if (!className.equals(""))
            filename += System.getProperty("file.separator") + className + ".java";
        // header text
        g.drawString(filename, xOffset, bottom - 2);
        File f = new File(filename);
        //System.err.println("Printing: "+filename);
        if (f.exists()) {
            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            java.util.Date date = new java.util.Date();
            date.setTime(f.lastModified());
            String myDate = dateFormat.format(date);
            int w = (int) gg.getFont().getStringBounds(myDate, gg.getFontRenderContext()).getWidth();
            // header text
            g.drawString("File last modified on " + myDate, xOffset, topOffset - 10);
        }
    }
}

From source file:org.deegree.portal.standard.wms.control.DynLegendListener.java

/**
 * In case the legend can not be obtained from the OGCLayer, this method is called to create a dummy legend image
 * plus the legend title// w ww .  j  av  a 2s.  co m
 * 
 * @param layerName
 * @return BufferedImage holding the created dummy legend
 */
private BufferedImage createMissingLegend(String layerName) {
    LOG.logDebug("URL is null. Drawing the image from a missingImage variable in init params");
    BufferedImage missingLegend = new BufferedImage(80, 15, BufferedImage.TYPE_INT_RGB);
    Graphics g = missingLegend.getGraphics();
    Rectangle2D rect = g.getFontMetrics().getStringBounds(layerName, g);
    g.dispose();
    missingLegend = new BufferedImage(rect.getBounds().width + 80, missingImg.getHeight() + 15,
            BufferedImage.TYPE_INT_ARGB);
    g = missingLegend.getGraphics();
    g.drawImage(missingImg, 0, 0, null);
    g.setColor(Color.RED);
    if (useLayerTitle) {
        g.drawString(layerName, missingImg.getWidth() + 5,
                missingImg.getHeight() / 2 + g.getFont().getSize() / 2);
    }
    g.dispose();

    return missingLegend;
}

From source file:org.jtrfp.trcl.core.ResourceManager.java

/**
 * Returns RAW image as an R8-G8-B8 buffer with a side-width which is the square root of the total number of pixels
 * @param name// w w w .  j  av a 2 s  .  c o  m
 * @param palette
 * @param proc
 * @return
 * @throws IOException
 * @throws FileLoadException
 * @throws IllegalAccessException
 * @throws NotSquareException 
 * @since Oct 26, 2012
 */
public BufferedImage getRAWImage(String name, Color[] palette) throws IOException, FileLoadException,
        IllegalAccessException, NotSquareException, NonPowerOfTwoException {
    final RAWFile dat = getRAW(name);
    final byte[] raw = dat.getRawBytes();
    if (raw.length != dat.getSideLength() * dat.getSideLength())
        throw new NotSquareException(name);
    if ((dat.getSideLength() & (dat.getSideLength() - 1)) != 0)
        throw new NonPowerOfTwoException(name);
    final BufferedImage stamper = new BufferedImage(dat.getSideLength(), dat.getSideLength(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics stG = stamper.getGraphics();
    for (int i = 0; i < raw.length; i++) {
        Color c = palette[(int) raw[i] & 0xFF];
        stG.setColor(c);
        stG.fillRect(i % dat.getSideLength(), i / dat.getSideLength(), 1, 1);
    }
    stG.dispose();
    Graphics g = stamper.getGraphics();
    //The following code stamps the filename into the texture for debugging purposes
    if (tr.isStampingTextures()) {
        g.setFont(new Font(g.getFont().getName(), g.getFont().getStyle(), 9));
        g.drawString(name, 1, 16);
    }

    g.dispose();
    return stamper;
}

From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

protected void paintComponentLane(Graphics g, int imageWidth, int imageHeight, boolean isModel) {
    g.setFont(g.getFont().deriveFont((float) 10.0));
    // set initial colors
    Color fgColor = null;//from   w w  w. j  a  v  a  2s. c  o  m
    Color bgColor = null;
    Color tmpColor = null;
    fgColor = null;
    bgColor = null;
    int clipL, clipR;

    // calculate common coordinates
    int yTop, yBottom, tempBorder, upper, bottom;
    if (isModel) {
        yTop = BORDER;
        yBottom = imageHeight - BORDER;
        clipL = coUtil.getClipL();
        clipR = coUtil.getClipR();
        upper = coUtil.getClipU();
        bottom = coUtil.getClipB();
        tempBorder = BORDER;
    } else {
        yTop = 0;
        yBottom = imageHeight;
        clipL = 0;
        clipR = imageWidth;
        upper = 0;
        bottom = this.getHeight();
        tempBorder = BUFFERBORDER;
    }

    int pixStart = 0;

    // initialize start color
    fgColor = dca.getSettingPanel().getFBcolor();
    bgColor = dca.getSettingPanel().getSBcolor();
    ;

    // paint actual log lane (only the part in the clipping range
    // determined)
    Iterator<String> itr = dcModel.getSortedMapModel().getSortedItemArrayList(dcop.getTimeOption(),
            dcop.getComponentType(), dcop.getSortStandard(), dcop.isDescCheckBoxSelected()).iterator();
    g.setFont(new Font("Dialog", Font.BOLD, 13));

    int size = dcModel.getComponentSize(dca.getDottedChartOptionPanel().getComponentType());
    int index = 0;

    while (itr.hasNext()) {
        String dimName = itr.next();
        g.setColor(bgColor);
        int top = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder);
        int bot = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder);
        if (bot >= upper && top <= bottom) {
            if (top < upper)
                top = upper;
            if (bot > bottom)
                bot = bottom;
            g.fillRect(pixStart, top - coUtil.getClipU(), clipR, bottom - coUtil.getClipU());
            g.setColor(fgColor);
            if (isModel) {
                if (top + 20 - coUtil.getClipU() <= imageHeight - tempBorder)
                    g.drawString(dimName, pixStart + 5, top + 20 - coUtil.getClipU());
            }
        }
        if (coUtil.unit2CordHeight(index + 1, size, imageHeight, tempBorder) > bottom)
            break;
        index++;
        // swap colors
        tmpColor = fgColor;
        fgColor = bgColor;
        bgColor = tmpColor;

    }

    g.setFont(new Font("Dialog", Font.PLAIN, 12));
    // draw horizontal delimiters
    g.setColor(colorTimeLine);
    g.drawLine(clipL, yTop, clipR, yTop);
    g.drawLine(clipL, yBottom, clipR, yBottom);
}

From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java

protected void paintComponentLane(Graphics g) {

    double percentileL = dcModel.getTimeStatistics().get(0)
            .getPercentile(dca.getSettingPanel().getPercentileforInstanceL());
    double percentileU = dcModel.getTimeStatistics().get(0)
            .getPercentile(dca.getSettingPanel().getPercentileforInstanceU());
    g.setFont(g.getFont().deriveFont((float) 10.0));
    // set initial colors
    Color fgColor = null;//w  w  w  . j  a v  a 2 s  . c om
    Color bgColor = null;
    Color tmpColor = null;
    fgColor = null;
    bgColor = null;
    // calculate common coordinates
    int unitHeight = (this.getHeight() - 2 * border) / getHashMapSize();
    int yTop = border;
    int yBottom = this.getHeight() - border;
    int pixStart = 0;
    String dateStr, timeStr, millisStr = null;

    // calculate area to be painted
    clipL = (int) g.getClipBounds().getMinX() - 1;
    clipR = (int) g.getClipBounds().getMaxX() + 1;

    // initialze start color
    fgColor = colorLogDark;
    bgColor = colorLogBright;

    // calculate current top
    int currentTop = yTop;

    // paint actual log lane (only the part in the clipping range
    // determined)
    Iterator itr = dcModel.getSortedKeySetList().iterator();
    g.setFont(new Font("Dialog", Font.BOLD, 13));
    int index = 0;
    currentTop = yTop;
    while (itr.hasNext()) {

        String dimName = (String) itr.next();
        LogUnitList tempList = ((LogUnitList) dcModel.getItemMap().get(dimName));
        long tempDuration;
        try {
            tempDuration = (tempList
                    .getRightBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep())
                    .getTime()
                    - tempList.getLeftBoundaryTimestamp(dcModel.getEventTypeToKeep(),
                            dcModel.getInstanceTypeToKeep()).getTime());
        } catch (Exception ce) {
            tempDuration = 0;
        }

        if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName))
            continue;
        g.setColor(bgColor);
        g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight);

        g.setColor(fgColor);

        // for bottleneck
        if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances
                && tempDuration >= percentileL && tempDuration <= percentileU)
            g.setColor(Color.red);
        else
            g.setColor(Color.black);
        g.drawString(dimName, pixStart + 5, currentTop + 20);

        index++;
        currentTop = unit2Cord(index);

        // swap colors
        tmpColor = fgColor;
        fgColor = bgColor;
        bgColor = tmpColor;

    }

    g.setFont(new Font("Dialog", Font.PLAIN, 12));

    // draw horizontal delimiters
    g.setColor(colorTimeLine);
    g.drawLine(clipL, yTop, clipR, yTop);
    g.drawLine(clipL, yBottom, clipR, yBottom);

    clipLeftTs = coord2timeMillis(clipL);
    clipRightTs = coord2timeMillis(clipR);

    // draw vertical lines
    // adjust width
    if (bAdjust) {
        adjustWidth();
        bAdjust = false;
    }

    for (long timeStart = dcModel.getLogBoundaryLeft()
            .getTime(); timeStart < clipRightTs; timeStart += dcOptionPanel.getWidthDivider()) {
        pixStart = time2coord(timeStart) + border;
        cal.setTimeInMillis(timeStart);
        g.setColor(colorTimeLine);
        g.drawLine(pixStart, yTop, pixStart, yBottom);
        g.setColor(colorLogDark);
        g.setColor(Color.black); // to be deleted
        if (timeOption.equals(TIME_ACTUAL)) {
            dateStr = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "."
                    + cal.get(Calendar.YEAR);
            g.drawString(dateStr, pixStart + 2, yTop);
            timeStr = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":"
                    + cal.get(Calendar.SECOND);
            g.drawString(timeStr, pixStart + 2, yTop + 10);
        } else if (timeOption.equals(TIME_RELATIVE_TIME)) {
            long days = timeStart / 1000 / 60 / 60 / 24;
            long hours = (timeStart - days * 24 * 60 * 60 * 1000) / 1000 / 60 / 60;
            long minutes = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60;
            long seconds = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000
                    - minutes * 60 * 1000) / 1000;
            timeStr = days + "days:" + hours + ":" + minutes + ":" + seconds;
            g.drawString(timeStr, pixStart + 2, yTop);
        } else if (timeOption.equals(TIME_RELATIVE_RATIO)) {
            timeStr = timeStart / 100 + "." + (timeStart - timeStart / 100 * 100) + "%";
            g.drawString(timeStr, pixStart + 2, yTop);
        } else if (timeOption.equals(TIME_LOGICAL) || timeOption.equals(TIME_LOGICAL_RELATIVE)) {
            timeStr = String.valueOf(timeStart);
            g.drawString(timeStr, pixStart + 2, yTop);
        }

    }
}

From source file:org.prom5.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

protected void paintComponentLane(Graphics g, int imageWidth, int imageHeight, boolean isModel) {
    g.setFont(g.getFont().deriveFont((float) 10.0));
    // set initial colors
    Color fgColor = null;// w  w w. ja v  a  2  s  .co m
    Color bgColor = null;
    Color tmpColor = null;
    fgColor = null;
    bgColor = null;
    int clipL, clipR;

    // calculate common coordinates
    int yTop, yBottom, tempBorder, upper, bottom;
    if (isModel) {
        yTop = BORDER;
        yBottom = imageHeight - BORDER;
        clipL = coUtil.getClipL();
        clipR = coUtil.getClipR();
        upper = coUtil.getClipU();
        bottom = coUtil.getClipB();
        tempBorder = BORDER;
    } else {
        yTop = 0;
        yBottom = imageHeight;
        clipL = 0;
        clipR = imageWidth;
        upper = 0;
        bottom = this.getHeight();
        tempBorder = BUFFERBORDER;
    }

    int pixStart = 0;

    // initialize start color
    fgColor = dca.getSettingPanel().getFBcolor();
    bgColor = dca.getSettingPanel().getSBcolor();
    ;

    // paint actual log lane (only the part in the clipping range determined)
    Iterator<String> itr = dcModel.getSortedMapModel().getSortedItemArrayList(dcop.getTimeOption(),
            dcop.getComponentType(), dcop.getSortStandard(), dcop.isDescCheckBoxSelected()).iterator();
    g.setFont(new Font("Dialog", Font.BOLD, 13));

    int size = dcModel.getComponentSize(dca.getDottedChartOptionPanel().getComponentType());
    int index = 0;

    while (itr.hasNext()) {
        String dimName = itr.next();
        g.setColor(bgColor);
        int top = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder);
        int bot = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder);
        if (bot >= upper && top <= bottom) {
            if (top < upper)
                top = upper;
            if (bot > bottom)
                bot = bottom;
            g.fillRect(pixStart, top - coUtil.getClipU(), clipR, bottom - coUtil.getClipU());
            g.setColor(fgColor);
            if (isModel) {
                if (top + 20 - coUtil.getClipU() <= imageHeight - tempBorder)
                    g.drawString(dimName, pixStart + 5, top + 20 - coUtil.getClipU());
            }
        }
        if (coUtil.unit2CordHeight(index + 1, size, imageHeight, tempBorder) > bottom)
            break;
        index++;
        // swap colors
        tmpColor = fgColor;
        fgColor = bgColor;
        bgColor = tmpColor;

    }

    g.setFont(new Font("Dialog", Font.PLAIN, 12));
    // draw horizontal delimiters
    g.setColor(colorTimeLine);
    g.drawLine(clipL, yTop, clipR, yTop);
    g.drawLine(clipL, yBottom, clipR, yBottom);
}

From source file:org.prom5.analysis.performance.dottedchart.ui.DottedChartPanel.java

protected void paintComponentLane(Graphics g) {

    double percentileL = dcModel.getTimeStatistics().get(0)
            .getPercentile(dca.getSettingPanel().getPercentileforInstanceL());
    double percentileU = dcModel.getTimeStatistics().get(0)
            .getPercentile(dca.getSettingPanel().getPercentileforInstanceU());
    g.setFont(g.getFont().deriveFont((float) 10.0));
    // set initial colors
    Color fgColor = null;//from   w  w w.  j  a  v a2s . c o  m
    Color bgColor = null;
    Color tmpColor = null;
    fgColor = null;
    bgColor = null;
    // calculate common coordinates
    int unitHeight = (this.getHeight() - 2 * border) / getHashMapSize();
    int yTop = border;
    int yBottom = this.getHeight() - border;
    int pixStart = 0;
    String dateStr, timeStr, millisStr = null;

    // calculate area to be painted
    clipL = (int) g.getClipBounds().getMinX() - 1;
    clipR = (int) g.getClipBounds().getMaxX() + 1;

    // initialze start color
    fgColor = colorLogDark;
    bgColor = colorLogBright;

    // calculate current top
    int currentTop = yTop;

    // paint actual log lane (only the part in the clipping range determined)
    Iterator itr = dcModel.getSortedKeySetList().iterator();
    g.setFont(new Font("Dialog", Font.BOLD, 13));
    int index = 0;
    currentTop = yTop;
    while (itr.hasNext()) {

        String dimName = (String) itr.next();
        LogUnitList tempList = ((LogUnitList) dcModel.getItemMap().get(dimName));
        long tempDuration;
        try {
            tempDuration = (tempList
                    .getRightBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep())
                    .getTime()
                    - tempList.getLeftBoundaryTimestamp(dcModel.getEventTypeToKeep(),
                            dcModel.getInstanceTypeToKeep()).getTime());
        } catch (Exception ce) {
            tempDuration = 0;
        }

        if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName))
            continue;
        g.setColor(bgColor);
        g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight);

        g.setColor(fgColor);

        // for bottleneck
        if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances
                && tempDuration >= percentileL && tempDuration <= percentileU)
            g.setColor(Color.red);
        else
            g.setColor(Color.black);
        g.drawString(dimName, pixStart + 5, currentTop + 20);

        index++;
        currentTop = unit2Cord(index);

        // swap colors
        tmpColor = fgColor;
        fgColor = bgColor;
        bgColor = tmpColor;

    }

    g.setFont(new Font("Dialog", Font.PLAIN, 12));

    // draw horizontal delimiters
    g.setColor(colorTimeLine);
    g.drawLine(clipL, yTop, clipR, yTop);
    g.drawLine(clipL, yBottom, clipR, yBottom);

    clipLeftTs = coord2timeMillis(clipL);
    clipRightTs = coord2timeMillis(clipR);

    // draw vertical lines
    // adjust width
    if (bAdjust) {
        adjustWidth();
        bAdjust = false;
    }

    for (long timeStart = dcModel.getLogBoundaryLeft()
            .getTime(); timeStart < clipRightTs; timeStart += dcOptionPanel.getWidthDivider()) {
        pixStart = time2coord(timeStart) + border;
        cal.setTimeInMillis(timeStart);
        g.setColor(colorTimeLine);
        g.drawLine(pixStart, yTop, pixStart, yBottom);
        g.setColor(colorLogDark);
        g.setColor(Color.black); // to be deleted
        if (timeOption.equals(TIME_ACTUAL)) {
            dateStr = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "."
                    + cal.get(Calendar.YEAR);
            g.drawString(dateStr, pixStart + 2, yTop);
            timeStr = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":"
                    + cal.get(Calendar.SECOND);
            g.drawString(timeStr, pixStart + 2, yTop + 10);
        } else if (timeOption.equals(TIME_RELATIVE_TIME)) {
            long days = timeStart / 1000 / 60 / 60 / 24;
            long hours = (timeStart - days * 24 * 60 * 60 * 1000) / 1000 / 60 / 60;
            long minutes = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60;
            long seconds = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000
                    - minutes * 60 * 1000) / 1000;
            timeStr = days + "days:" + hours + ":" + minutes + ":" + seconds;
            g.drawString(timeStr, pixStart + 2, yTop);
        } else if (timeOption.equals(TIME_RELATIVE_RATIO)) {
            timeStr = timeStart / 100 + "." + (timeStart - timeStart / 100 * 100) + "%";
            g.drawString(timeStr, pixStart + 2, yTop);
        } else if (timeOption.equals(TIME_LOGICAL) || timeOption.equals(TIME_LOGICAL_RELATIVE)) {
            timeStr = String.valueOf(timeStart);
            g.drawString(timeStr, pixStart + 2, yTop);
        }

    }
}

From source file:org.yawlfoundation.yawl.procletService.editor.pconns.VertexDemo.java

public VertexDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<Number, Number>();
    createGraph(VERTEX_COUNT);// w  w w. j  a v a 2  s . com

    // a Map for the labels
    Map<Number, String> map = new HashMap<Number, String>();
    for (int i = 0; i < VERTEX_COUNT; i++) {
        map.put(i, iconNames[i % iconNames.length]);
    }

    // a Map for the Icons
    Map<Number, Icon> iconMap = new HashMap<Number, Icon>();
    for (int i = 0; i < VERTEX_COUNT; i++) {
        String name = "/images/topic" + iconNames[i] + ".gif";
        try {
            Icon icon = new LayeredIcon(new ImageIcon(VertexDemo.class.getResource(name)).getImage());
            iconMap.put(i, icon);
        } catch (Exception ex) {
            System.err.println("You need slashdoticons.jar in your classpath to see the image " + name);
        }
    }

    FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph);
    layout.setMaxIterations(100);
    layout.setInitializer(new RandomLocationTransformer<Number>(new Dimension(400, 400), 0));
    vv = new VisualizationViewer<Number, Number>(layout, new Dimension(400, 400));

    // This demo uses a special renderer to turn outlines on and off.
    // you do not need to do this in a real application.
    // Instead, just let vv use the Renderer it already has
    vv.getRenderer().setVertexRenderer(new DemoRenderer<Number, Number>());

    Transformer<Number, Paint> vpf = new PickableVertexPaintTransformer<Number>(vv.getPickedVertexState(),
            Color.white, Color.yellow);
    vv.getRenderContext().setVertexFillPaintTransformer(vpf);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan));

    vv.setBackground(Color.white);

    final Transformer<Number, String> vertexStringerImpl = new VertexStringerImpl<Number, String>(map);
    vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl);
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));
    //        vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Number,String>() {
    //           URL url = getClass().getResource("/images/lightning-s.gif");
    //         public String transform(Number input) {
    //            
    //            return "<html><img src="+url+" height=10 width=21>"+input.toString();
    //         }});

    // For this demo only, I use a special class that lets me turn various
    // features on and off. For a real application, use VertexIconShapeTransformer instead.
    final DemoVertexIconShapeTransformer<Number> vertexIconShapeTransformer = new DemoVertexIconShapeTransformer<Number>(
            new EllipseVertexShapeTransformer<Number>());

    final DemoVertexIconTransformer<Number> vertexIconTransformer = new DemoVertexIconTransformer<Number>();

    vertexIconShapeTransformer.setIconMap(iconMap);
    vertexIconTransformer.setIconMap(iconMap);

    vv.getRenderContext().setVertexShapeTransformer(vertexIconShapeTransformer);
    vv.getRenderContext().setVertexIconTransformer(vertexIconTransformer);

    // un-comment for RStar Tree visual testing
    //vv.addPostRenderPaintable(new BoundingRectanglePaintable(vv.getRenderContext(), vv.getGraphLayout()));

    // Get the pickedState and add a listener that will decorate the
    // Vertex images with a checkmark icon when they are picked
    PickedState<Number> ps = vv.getPickedVertexState();
    ps.addItemListener(new PickWithIconListener<Number>(vertexIconTransformer));

    vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {
        int x;
        int y;
        Font font;
        FontMetrics metrics;
        int swidth;
        int sheight;
        String str = "Thank You, slashdot.org, for the images!";

        public void paint(Graphics g) {
            Dimension d = vv.getSize();
            if (font == null) {
                font = new Font(g.getFont().getName(), Font.BOLD, 20);
                metrics = g.getFontMetrics(font);
                swidth = metrics.stringWidth(str);
                sheight = metrics.getMaxAscent() + metrics.getMaxDescent();
                x = (d.width - swidth) / 2;
                y = (int) (d.height - sheight * 1.5);
            }
            g.setFont(font);
            Color oldColor = g.getColor();
            g.setColor(Color.lightGray);
            g.drawString(str, x, y);
            g.setColor(oldColor);
        }

        public boolean useTransform() {
            return false;
        }
    });

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<Number>());

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);

    final DefaultModalGraphMouse<Number, Number> graphMouse = new DefaultModalGraphMouse<Number, Number>();
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());
    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JCheckBox shape = new JCheckBox("Shape");
    shape.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            vertexIconShapeTransformer.setShapeImages(e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });
    shape.setSelected(true);

    JCheckBox fill = new JCheckBox("Fill");
    fill.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            vertexIconTransformer.setFillImages(e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });
    fill.setSelected(true);

    JCheckBox drawOutlines = new JCheckBox("Outline");
    drawOutlines.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            vertexIconTransformer.setOutlineImages(e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });

    JComboBox modeBox = graphMouse.getModeComboBox();
    JPanel modePanel = new JPanel();
    modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modePanel.add(modeBox);

    JPanel scaleGrid = new JPanel(new GridLayout(1, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));
    JPanel labelFeatures = new JPanel(new GridLayout(1, 0));
    labelFeatures.setBorder(BorderFactory.createTitledBorder("Image Effects"));
    JPanel controls = new JPanel();
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(scaleGrid);
    labelFeatures.add(shape);
    labelFeatures.add(fill);
    labelFeatures.add(drawOutlines);

    controls.add(labelFeatures);
    controls.add(modePanel);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:org.zaproxy.zap.extension.callgraph.CallGraphFrame.java

public CallGraphFrame(Pattern urlPattern) {
    // visibility needs to be temporarily set, so we can get the font metrics
    this.setVisible(true);
    Graphics graphics = this.getGraphics();
    Font font = graphics.getFont();
    this.fontmetrics = graphics.getFontMetrics(font);
    this.setVisible(false);

    // now retrieve the call Graph data
    try {// w  ww .j a v  a2 s  .  c o m
        setupGraph(urlPattern);
        setupFrame();
    } catch (SQLException e) {
        log.error("Failed to setup the graph", e);
    }
}

From source file:ro.nextreports.designer.ui.sqleditor.syntax.SyntaxStyles.java

/**
 * Set the graphics font and others to the style for the given token
 * @param g/*from w  w  w  . j a v a 2  s .  c  om*/
 * @param type
 */
@Deprecated
public void setGraphicsStyle(Graphics g, TokenType type) {
    SyntaxStyle ss = styles.get(type);
    if (ss != null) {
        g.setFont(g.getFont().deriveFont(ss.getFontStyle()));
        g.setColor(ss.getColor());
    } else {
        g.setFont(g.getFont().deriveFont(Font.PLAIN));
        g.setColor(Color.BLACK);
    }
}