Example usage for java.awt Graphics setFont

List of usage examples for java.awt Graphics setFont

Introduction

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

Prototype

public abstract void setFont(Font font);

Source Link

Document

Sets this graphics context's font to the specified font.

Usage

From source file:bigdata.explorer.nutch.grapview.WebGraphZoomScrollPane.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoom features./*  w  ww.  ja  va 2s  .  c om*/
 * 
 */
public WebGraphZoomScrollPane() throws IOException {

    // create a simple graph for the demo
    graph = NutchGraphLoader.loadFullGraph("/home/kamir/ANALYSIS/Nutch/YellowMED_CORE");

    ImageIcon sandstoneIcon = null;
    String imageLocation = "/images/Sandstone.jpg";
    try {
        sandstoneIcon = new ImageIcon(getClass().getResource(imageLocation));
    } catch (Exception ex) {
        System.err.println("Can't load \"" + imageLocation + "\"");
    }
    final ImageIcon icon = sandstoneIcon;
    vv = new VisualizationViewer<String, Number>(new KKLayout<String, Number>(graph));

    if (icon != null) {
        vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Dimension d = vv.getSize();
                g.drawImage(icon.getImage(), 0, 0, d.width, d.height, vv);
            }

            public boolean useTransform() {
                return false;
            }
        });
    }
    vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {
        int x;
        int y;
        Font font;
        FontMetrics metrics;
        int swidth;
        int sheight;
        String str = "WebGraph Zoomer : Version 1.0.0";

        public void paint(Graphics g) {
            Dimension d = vv.getSize();
            if (font == null) {
                font = new Font(g.getFont().getName(), Font.BOLD, 30);
                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;
        }
    });

    vv.addGraphMouseListener(new TestGraphMouseListener<String>());
    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.lightGray));

    // add my listeners for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());
    vv.setEdgeToolTipTransformer(new Transformer<Number, String>() {
        public String transform(Number edge) {
            return "E" + graph.getEndpoints(edge).toString();
        }
    });

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
    vv.setForeground(Color.lightGray);

    // create a frome to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<String, Number>();
    vv.setGraphMouse(graphMouse);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode");

    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());
        }
    });

    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    content.add(controls, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(true);
}

From source file:com.google.code.facebook.graph.sna.applet.GraphZoomScrollPaneDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoom features./*from  www . ja  va 2  s .co  m*/
 * 
 */
public GraphZoomScrollPaneDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<String, Number>();
    String[] v = createVertices(10);
    createEdges(v);

    ImageIcon sandstoneIcon = null;
    String imageLocation = "/images/Sandstone.jpg";
    try {
        sandstoneIcon = new ImageIcon(getClass().getResource(imageLocation));
    } catch (Exception ex) {
        System.err.println("Can't load \"" + imageLocation + "\"");
    }
    final ImageIcon icon = sandstoneIcon;
    vv = new VisualizationViewer<String, Number>(new KKLayout<String, Number>(graph));

    if (icon != null) {
        vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Dimension d = vv.getSize();
                g.drawImage(icon.getImage(), 0, 0, d.width, d.height, vv);
            }

            public boolean useTransform() {
                return false;
            }
        });
    }
    vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {
        int x;
        int y;
        Font font;
        FontMetrics metrics;
        int swidth;
        int sheight;
        String str = "GraphZoomScrollPane Demo";

        public void paint(Graphics g) {
            Dimension d = vv.getSize();
            if (font == null) {
                font = new Font(g.getFont().getName(), Font.BOLD, 30);
                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;
        }
    });

    vv.addGraphMouseListener(new TestGraphMouseListener<String>());
    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.lightGray));

    // add my listeners for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());
    vv.setEdgeToolTipTransformer(new Transformer<Number, String>() {
        public String transform(Number edge) {
            return "E" + graph.getEndpoints(edge).toString();
        }
    });

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
    vv.setForeground(Color.lightGray);

    // create a frome to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<String, Number>();
    vv.setGraphMouse(graphMouse);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode");

    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());
        }
    });

    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    content.add(controls, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(true);
}

From source file:edu.uci.ics.jung.samples.GraphZoomScrollPaneDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoom features./*from  w  w  w  .j a v  a2 s . co  m*/
 * 
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public GraphZoomScrollPaneDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<String, Number>();
    String[] v = createVertices(10);
    createEdges(v);

    ImageIcon sandstoneIcon = null;
    String imageLocation = "/images/Sandstone.jpg";
    try {
        sandstoneIcon = new ImageIcon(getClass().getResource(imageLocation));
    } catch (Exception ex) {
        System.err.println("Can't load \"" + imageLocation + "\"");
    }
    final ImageIcon icon = sandstoneIcon;
    vv = new VisualizationViewer<String, Number>(new KKLayout<String, Number>(graph));

    if (icon != null) {
        vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Dimension d = vv.getSize();
                g.drawImage(icon.getImage(), 0, 0, d.width, d.height, vv);
            }

            public boolean useTransform() {
                return false;
            }
        });
    }
    vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {
        int x;
        int y;
        Font font;
        FontMetrics metrics;
        int swidth;
        int sheight;
        String str = "GraphZoomScrollPane Demo";

        public void paint(Graphics g) {
            Dimension d = vv.getSize();
            if (font == null) {
                font = new Font(g.getFont().getName(), Font.BOLD, 30);
                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;
        }
    });

    vv.addGraphMouseListener(new TestGraphMouseListener<String>());
    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.lightGray));

    // add my listeners for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());
    vv.setEdgeToolTipTransformer(new Transformer<Number, String>() {
        public String transform(Number edge) {
            return "E" + graph.getEndpoints(edge).toString();
        }
    });

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
    vv.setForeground(Color.lightGray);

    // create a frome to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<String, Number>();
    vv.setGraphMouse(graphMouse);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode");

    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());
        }
    });

    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    content.add(controls, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(true);
}

From source file:org.mwc.cmap.xyplot.views.XYPlotView.java

protected void bitmapToClipBoard(JComponent component) {
    Point size = _plotControl.getSize();
    final BufferedImage img = new BufferedImage(size.x, size.y, BufferedImage.TYPE_INT_ARGB);
    Graphics g = img.getGraphics();
    g.setColor(component.getForeground());
    g.setFont(component.getFont());
    component.setSize(size.x, size.y);//from  www. j ava2 s. c o m
    component.paint(g);
    Transferable t = new Transferable() {

        public DataFlavor[] getTransferDataFlavors() {
            return new DataFlavor[] { DataFlavor.imageFlavor };
        }

        public boolean isDataFlavorSupported(DataFlavor flavor) {
            if (flavor == DataFlavor.imageFlavor)
                return true;
            return false;
        }

        public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
            if (isDataFlavorSupported(flavor)) {
                return img;
            }
            return null;
        }

    };

    ClipboardOwner co = new ClipboardOwner() {

        public void lostOwnership(java.awt.datatransfer.Clipboard clipboard, Transferable contents) {
        }

    };
    java.awt.datatransfer.Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    cb.setContents(t, co);

}

From source file:com.jcraft.weirdx.Draw.java

static void reqPolyText8(Client c, XDrawable d, GC gc, int x, int y) throws IOException {
    int n = c.length;
    //int len;/*from www  . j av  a2  s  .  co m*/
    int foo;
    InputOutput io = c.client;

    Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCFont);
    if (graphics == null) {
        c.client.readPad(n * 4);
        return;
    }

    if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) {
        java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask());
        if (rec == null) {
            io.readPad(n * 4);
            return;
        }
    }

    XFont font = gc.font;

    int delta;
    n = n * 4;

    int sx = d.width;
    int sy = d.height;
    int lx = 0;
    int ly = 0;

    while (n != 0) {
        if (n < 2)
            break;
        foo = io.readByte();
        n--;
        if (foo == 255) {
            int i = 0;
            foo = io.readByte();
            n--;
            i = foo & 0xff;
            foo = io.readByte();
            n--;
            i = ((i << 8) & 0xffff) | foo & 0xff;
            foo = io.readByte();
            n--;
            i = ((i << 8) & 0xffffff) | foo & 0xff;
            foo = io.readByte();
            n--;
            i = (i << 8) | foo & 0xff;
            XFont tmp = (XFont) XResource.lookupIDByType(i, XResource.RT_FONT);
            if (tmp != null) {
                font = tmp;
                graphics.setFont(font.getFont());
            } else {
                LOG.warn("font is null!!");
            }
            continue;
        }

        delta = io.readByte();
        n--;
        x += delta;
        if (foo > 0) {
            io.readByte(c.bbuffer, 0, foo);
            n -= foo;

            if (font.encoding != null) {
                foo = font.encode(c.bbuffer, 0, foo, c.cbuffer);
            } else {
                char ccc = 0;
                for (int i = 0; i < foo; i++) {
                    ccc = c.cbuffer[i] = (char) (c.bbuffer[i] & 0xff);
                    if (ccc < 0x20) {
                        if (ccc == 11)
                            c.cbuffer[i] = (char) '+';
                        else if (ccc == 12)
                            c.cbuffer[i] = (char) '+';
                        else if (ccc == 13)
                            c.cbuffer[i] = (char) '+';
                        else if (ccc == 14)
                            c.cbuffer[i] = (char) '+';
                        else if (ccc == 15)
                            c.cbuffer[i] = (char) '+';
                        else if (ccc == 18)
                            c.cbuffer[i] = (char) '-';
                        else if (ccc == 21)
                            c.cbuffer[i] = (char) '+';
                        else if (ccc == 22)
                            c.cbuffer[i] = (char) '+';
                        else if (ccc == 23)
                            c.cbuffer[i] = (char) '+';
                        else if (ccc == 24)
                            c.cbuffer[i] = (char) '+';
                        else if (ccc == 25)
                            c.cbuffer[i] = (char) '|';
                        else
                            c.cbuffer[i] = (char) 0x20;
                    }
                }
            }
            graphics.drawChars(c.cbuffer, 0, foo, x, y);

            if (x < sx)
                sx = x;
            foo = font.charsWidth(c.cbuffer, 0, foo) + x;

            x = foo;

            if (lx < foo)
                lx = foo;
            if ((y - font.ascent) < sy)
                sy = y - font.ascent;
            if (ly < y + font.descent)
                ly = y + font.descent;
        }
    }

    if (n != 0) {
        io.readPad(n);
    }

    if (sx < 0)
        sx = 0;
    if (sy < 0)
        sy = 0;
    if (d instanceof XWindow) {
        ((XWindow) d).draw(sx, sy, lx - sx + 1, ly - sy + 1);
    }
    if (gc.function == GC.GXxor || gc.function == GC.GXinvert) {
        graphics.setPaintMode();
    }
    if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) {
        d.restoreClip();
    }
}

From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java

/**
 * Write a blank thumbnail image so user doesn't see the broken icon.
 *//*  ww w . j  a  va 2 s.  c om*/
private void writePlaceholderThumbnailImage(OutputStream os, int placeholderSize) throws IOException {
    // Make the image a bit bigger to account for the empty space around the generated image.
    // If we can find a way to remove this empty space, we don't need to make the chart bigger.
    BufferedImage buffer = new BufferedImage(placeholderSize + 16, placeholderSize + 9,
            BufferedImage.TYPE_INT_RGB);
    Graphics g = buffer.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, placeholderSize + 16, placeholderSize + 9);
    g.setColor(Color.gray);
    g.drawLine(8, placeholderSize + 5, placeholderSize + 8, placeholderSize + 5); // x-axis
    g.drawLine(8, 5, 8, placeholderSize + 5); // y-axis
    g.setColor(Color.black);
    Font font = g.getFont();
    g.setFont(new Font(font.getName(), font.getStyle(), 8));
    g.drawString("N/A", 9, placeholderSize);
    ImageIO.write(buffer, "png", os);
}

From source file:com.jcraft.weirdx.Draw.java

static void reqPolyText16(Client c, XDrawable d, GC gc, int x, int y) throws IOException {
    int n = c.length;
    //int len;//from  w  ww. j a  v  a2s  .c  o m
    int foo;

    Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCFont);
    if (graphics == null) {
        c.client.readPad(n * 4);
        return;
    }

    if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) {
        java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask());
        if (rec == null) {
            while (n > 0) {
                c.client.readPad(4);
                n--;
            }
            return;
        }
    }

    XFont font = gc.font;
    int delta;
    n = n * 4;

    int sx = d.width;
    int sy = d.height;
    int lx = 0;
    int ly = 0;

    while (n != 0) {
        if (n < 2)
            break;
        foo = c.client.readByte();
        n--;
        if (foo == 255) {
            int i = 0;
            foo = c.client.readByte();
            n--;
            i = foo & 0xff;
            foo = c.client.readByte();
            n--;
            i = ((i << 8) & 0xffff) | foo & 0xff;
            foo = c.client.readByte();
            n--;
            i = ((i << 8) & 0xffffff) | foo & 0xff;
            foo = c.client.readByte();
            n--;
            i = (i << 8) | foo & 0xff;
            XFont tmp = (XFont) XResource.lookupIDByType(i, XResource.RT_FONT);
            if (tmp != null) {
                font = tmp;
                graphics.setFont(font.getFont());
            } else {
                LOG.warn("font is null!!");
            }
            continue;
        }
        delta = c.client.readByte();
        n--;
        x += delta;
        if (foo > 0) {
            foo *= 2;
            c.client.readByte(c.bbuffer, 0, foo);
            n -= foo;
            if (font.encoding != null) {
                foo = font.encode(c.bbuffer, 0, foo, c.cbuffer);
                if (foo == 0) {
                    c.length = n;
                    return;
                }
            } else {
                for (int i = 0; i < foo; i++) {
                    c.cbuffer[i] = (char) (c.bbuffer[i] & 0xff);
                }
                for (int i = 0; i < foo; i++) {
                    if (c.cbuffer[i] != 0) {
                        c.cbuffer[i / 2] = c.cbuffer[i];
                    }
                }
                foo /= 2; // ????
            }

            graphics.drawChars(c.cbuffer, 0, foo, x, y);
            if (x < sx)
                sx = x;
            foo = font.charsWidth(c.cbuffer, 0, foo) + x;
            x = foo;
            if (lx < foo)
                lx = foo;
            if ((y - font.ascent) < sy)
                sy = y - font.ascent;
            if (ly < y + font.descent)
                ly = y + font.descent;
        }
    }

    if (n != 0) {
        c.client.readPad(n);
    }

    if (sx < 0)
        sx = 0;
    if (sy < 0)
        sy = 0;
    if (d instanceof XWindow) {
        ((XWindow) d).draw(sx, sy, lx - sx + 1, ly - sy + 1);
    }

    if (gc.function == GC.GXxor || gc.function == GC.GXinvert) {
        graphics.setPaintMode();
    }
    if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) {
        d.restoreClip();
    }
}

From source file:thesaurusEditor.gui.graph.MainGraph.java

/**
 * create an instance of a simple graph with basic controls
 *///from  w ww  .  j  a  v  a2  s  .  c o m
public MainGraph(List<Konzept> konzepte, Main main) {

    // create a simple graph for the demo
    this.konzepte = konzepte;
    this.main = main;

    main.getController().getThesaurus().addObserver(this);

    graph = new DirectedSparseGraph<Konzept, EdgeClass>();

    for (Konzept k : konzepte) {
        graph.addVertex(k);
    }
    createEdges(konzepte);

    layout = new PersistentLayoutImpl<Konzept, EdgeClass>(new FRLayout<Konzept, EdgeClass>(graph));
    //layout = new FRLayout<Konzept,EdgeClass>(graph);
    Dimension preferredSize = new Dimension(1300, 900);
    final VisualizationModel<Konzept, EdgeClass> visualizationModel = new DefaultVisualizationModel<Konzept, EdgeClass>(
            layout, preferredSize);
    vv = new VisualizationViewer<Konzept, EdgeClass>(visualizationModel, preferredSize);

    // this class will provide both label drawing and vertex shapes
    VertexLabelAsShapeRenderer<Konzept, EdgeClass> vlasr = new VertexLabelAsShapeRenderer<Konzept, EdgeClass>(
            vv.getRenderContext());

    // customize the render context
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<Konzept, String>() {
        public String transform(Konzept k) {
            return "";
        }
    });
    // this chains together Transformers so that the html tags
    // are prepended to the toString method output
    /*new ChainedTransformer<Konzept,String>(new Transformer[]{
    new ToStringLabeller<Konzept>(),
    new Transformer<Konzept,String>() {
     public String transform(Konzept input) {
        return input.toString();
     }}}));*/
    vv.getRenderContext().setVertexShapeTransformer(new Transformer<Konzept, Shape>() {
        public Shape transform(Konzept k) {
            return new Rectangle(-((k.toString().length() * 8 + 10) / 2), -(10), k.toString().length() * 7 + 18,
                    21);
        }
    });
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.black));
    vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f)));

    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Konzept>(vv.getPickedVertexState(), Color.white, Color.yellow));
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<EdgeClass>(vv.getPickedEdgeState(), Color.black, Color.red));

    vv.getRenderContext().setVertexIconTransformer(new Transformer<Konzept, Icon>() {

        /*
         * Implements the Icon interface to draw an Icon with background color and
         * a text label
         */
        public Icon transform(final Konzept v) {
            return new Icon() {
                private Konzept k;

                public int getIconHeight() {
                    return 20;
                }

                public int getIconWidth() {
                    if (k != null) {
                        return k.toString().length() * 7 + 10;
                    }
                    return v.toString().length() * 7 + 10;
                }

                public void paintIcon(Component c, Graphics g, int x, int y) {
                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.yellow);
                    } else {
                        g.setColor(Color.lightGray);
                    }
                    g.fillRect(x, y, v.toString().length() * 8 + 10, 20);

                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.black);
                    } else {
                        g.setColor(Color.black);
                    }
                    g.drawRect(x, y, v.toString().length() * 8 + 10, 20);
                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.black);
                    } else {
                        g.setColor(Color.black);
                    }
                    this.k = v;

                    if (vv.getPickedVertexState().isPicked(v)) {
                        Font font = new Font("DejaVu Sans Mono", Font.BOLD, 14);
                        g.setFont(font);
                        g.drawString("" + v, x + 6, y + 15);
                    } else {
                        Font font = new Font("DejaVu Sans Mono", Font.PLAIN, 14);
                        g.setFont(font);
                        g.drawString("" + v, x + 6, y + 15);
                    }
                    this.k = v;

                }
            };
        }
    });

    // customize the renderer
    /*GradientVertexRenderer<Konzept,EdgeClass> vertex = new GradientVertexRenderer<Konzept,EdgeClass>(Color.white, Color.white, true);
    vv.getRenderer().setVertexRenderer(vertex);
    vv.getRenderer().setVertexLabelRenderer(vlasr); */

    vv.setBackground(Color.white);

    // add a listener for ToolTips
    KonzeptParser<Konzept> parser = new KonzeptParser<Konzept>();
    vv.setVertexToolTipTransformer(parser);

    /*final DefaultModalGraphMouse<Konzept,Edge> graphMouse = 
    new DefaultModalGraphMouse<Konzept,Edge>();
    */

    Factory<Konzept> vertexFactory = new VertexFactory();
    Factory<EdgeClass> edgeFactory = new EdgeFactory();

    graphMouse = new MyModalGraphMouse<Konzept, EdgeClass>(vv.getRenderContext(), vertexFactory, edgeFactory,
            main, vv);

    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());
    // the EditingGraphMouse will pass mouse event coordinates to the
    // vertexLocations function to set the locations of the vertices as
    // they are created
    //        graphMouse.setVertexLocations(vertexLocations);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    graphMouse.setMode(ModalGraphMouse.Mode.EDITING);

    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    //graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton();
    plus.setIcon(new ImageIcon(getClass().getResource("/thesaurusEditor/img/zoom_in.png")));
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton();
    minus.setIcon(new ImageIcon(getClass().getResource("/thesaurusEditor/img/zoom_out.png")));
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JPanel controls = new JPanel();
    JPanel zoomControls = new JPanel(new GridLayout(1, 2));
    //zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
    zoomControls.add(plus);
    zoomControls.add(minus);
    controls.add(zoomControls);
    //controls.add(modeBox);
    /*
    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(gzsp);
    gzsp.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 374, Short.MAX_VALUE)
    );
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 106, Short.MAX_VALUE)
    );
            
            
    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(controls);
    controls.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 374, Short.MAX_VALUE)
    );
    jPanel2Layout.setVerticalGroup(
    jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 164, Short.MAX_VALUE)
    );*/

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(gzsp, javax.swing.GroupLayout.Alignment.TRAILING,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(controls, javax.swing.GroupLayout.Alignment.TRAILING,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
            javax.swing.GroupLayout.Alignment.TRAILING,
            layout.createSequentialGroup().addContainerGap()
                    .addComponent(gzsp, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(controls, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap()));

}

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;// w w  w.  j av  a  2s.co 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.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 ava 2s .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);
        }

    }
}