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: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);/*from  www. j av  a 2 s .c o  m*/

    // 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:com.google.code.facebook.graph.sna.applet.VertexImageShaperDemo.java

public VertexImageShaperDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<Number, Number>();
    createGraph(VERTEX_COUNT);/*from w  w w  .  j  av a2  s.  co m*/

    // 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(VertexImageShaperDemo.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:demo.VertexImageShaperDemo.java

public VertexImageShaperDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<Number, Number>();
    createGraph(VERTEX_COUNT);//from w  ww. j av a 2s .  co m

    // 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(VertexImageShaperDemo.class.getResource(name)).getImage());
            //iconMap.put(i, icon);
            iconMap.put(i, new ImageIcon("transferir.png"));
        } 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.esa.nest.dat.views.polarview.Axis.java

public void draw(Graphics g) {
    if (!visible)
        return;// w  w w .  j  ava  2s.  c om
    gr.setGraphics(g);
    final FontMetrics fm = g.getFontMetrics(font);
    g.setColor(axisColor);
    gr.drawLine(0, 0, length + 2 * spacing, 0);
    int tickLength = this.tickLength;
    if (ticksInside)
        tickLength = -tickLength;
    final int maxTickCount = (int) (((float) length + 0.5F)
            / (float) gr.maxTickSize(tickNames, tickCount, font));
    final int minTickCount = Math.min(maxTickCount, bestTickCount);
    if (tickCount > maxTickCount)
        setTickCount(maxTickCount);
    else if (tickCount < minTickCount)
        setTickCount(minTickCount);
    for (int i = 0; i < tickCount; i++) {
        gr.drawTick(tickPos[i], tickLength);
    }
    g.setColor(labelColor);
    g.setFont(font);
    for (int i = 0; i < tickCount; i++) {
        gr.drawMultiLineTickName(tickNames[i], tickPos[i], tickLength, fm);
    }

    g.setFont(titleFont);
    gr.drawTitle(title, titleFont, length);
    if (!withGrid)
        return;
    g.setColor(gridColor);
    for (int i = 0; i < tickCount; i++) {
        gr.drawTick(tickPos[i], breadth);
    }
}

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

/**
 * create an instance of a simple graph with controls to
 * demo the zoom features./*from   w w  w.  ja  v a 2  s .c  o m*/
 * 
 */
@SuppressWarnings("serial")
public PerspectiveVertexImageShaperDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseMultigraph<Number, Number>();
    Number[] vertices = createVertices(11);

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

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

    createEdges(vertices);

    final VertexStringerImpl<Number> vertexStringerImpl = new VertexStringerImpl<Number>(map);

    final VertexIconShapeTransformer<Number> vertexImageShapeFunction = new VertexIconShapeTransformer<Number>(
            new EllipseVertexShapeTransformer<Number>());

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

    vv.setBackground(Color.decode("0xffffdd"));
    final DefaultVertexIconTransformer<Number> vertexIconFunction = new DefaultVertexIconTransformer<Number>();
    vertexImageShapeFunction.setIconMap(iconMap);
    vertexIconFunction.setIconMap(iconMap);
    vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction);
    vv.getRenderContext().setVertexIconTransformer(vertexIconFunction);
    vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl);
    PickedState<Number> ps = vv.getPickedVertexState();
    ps.addItemListener(new PickWithIconListener(vertexIconFunction));

    vv.addPostRenderPaintable(new VisualizationServer.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);

    this.viewSupport = new PerspectiveImageLensSupport<Number, Number>(vv);
    this.layoutSupport = new PerspectiveLayoutTransformSupport<Number, Number>(vv);

    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, 0.9f, vv.getCenter());
        }
    });
    final JSlider horizontalSlider = new JSlider(-120, 120, 0) {

        /* (non-Javadoc)
         * @see javax.swing.JComponent#getPreferredSize()
         */
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(80, super.getPreferredSize().height);
        }
    };

    final JSlider verticalSlider = new JSlider(-120, 120, 0) {

        /* (non-Javadoc)
         * @see javax.swing.JComponent#getPreferredSize()
         */
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(super.getPreferredSize().width, 80);
        }
    };
    verticalSlider.setOrientation(JSlider.VERTICAL);
    final ChangeListener changeListener = new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            int vval = -verticalSlider.getValue();
            int hval = horizontalSlider.getValue();

            Dimension d = vv.getSize();
            PerspectiveTransform pt = null;
            pt = PerspectiveTransform.getQuadToQuad(vval, hval, d.width - vval, -hval, d.width + vval,
                    d.height + hval, -vval, d.height - hval,

                    0, 0, d.width, 0, d.width, d.height, 0, d.height);

            viewSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
            layoutSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
            vv.repaint();
        }
    };
    horizontalSlider.addChangeListener(changeListener);
    verticalSlider.addChangeListener(changeListener);

    JPanel perspectivePanel = new JPanel(new BorderLayout());
    JPanel perspectiveCenterPanel = new JPanel(new BorderLayout());
    perspectivePanel.setBorder(BorderFactory.createTitledBorder("Perspective Controls"));
    final JButton center = new JButton("Center");
    center.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            horizontalSlider.setValue(0);
            verticalSlider.setValue(0);
        }
    });

    final JCheckBox noText = new JCheckBox("No Text");
    noText.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            JCheckBox cb = (JCheckBox) e.getSource();
            vertexStringerImpl.setEnabled(!cb.isSelected());
            vv.repaint();
        }
    });
    JPanel centerPanel = new JPanel();
    centerPanel.add(noText);

    ButtonGroup radio = new ButtonGroup();
    JRadioButton none = new JRadioButton("None");
    none.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            boolean selected = e.getStateChange() == ItemEvent.SELECTED;
            if (selected) {
                if (viewSupport != null) {
                    viewSupport.deactivate();
                }
                if (layoutSupport != null) {
                    layoutSupport.deactivate();
                }
            }
            center.setEnabled(!selected);
            horizontalSlider.setEnabled(!selected);
            verticalSlider.setEnabled(!selected);
        }
    });
    none.setSelected(true);

    JRadioButton hyperView = new JRadioButton("View");
    hyperView.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    JRadioButton hyperModel = new JRadioButton("Layout");
    hyperModel.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            layoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    radio.add(none);
    radio.add(hyperView);
    radio.add(hyperModel);

    JMenuBar menubar = new JMenuBar();
    JMenu modeMenu = graphMouse.getModeMenu();
    menubar.add(modeMenu);

    panel.setCorner(menubar);

    JPanel scaleGrid = new JPanel(new GridLayout(2, 0));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));
    JPanel controls = new JPanel(new BorderLayout());
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(scaleGrid, BorderLayout.WEST);

    JPanel lensPanel = new JPanel(new GridLayout(2, 0));
    lensPanel.add(none);
    lensPanel.add(hyperView);
    lensPanel.add(hyperModel);

    perspectivePanel.add(lensPanel, BorderLayout.WEST);
    perspectiveCenterPanel.add(horizontalSlider, BorderLayout.SOUTH);
    perspectivePanel.add(verticalSlider, BorderLayout.EAST);
    perspectiveCenterPanel.add(center);
    perspectivePanel.add(perspectiveCenterPanel);
    controls.add(perspectivePanel, BorderLayout.EAST);

    controls.add(centerPanel);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:ubic.basecode.graphics.MatrixDisplay.java

/**
 * Draws row names (horizontally)/*from ww w . j av a  2  s .  c  o m*/
 * 
 * @param g Graphics
 * @param showScalebar
 */
protected void drawRowNames(Graphics g, boolean showScalebar) {

    if (colorMatrix == null)
        return;

    Color oldColor = g.getColor();

    g.setColor(Color.white);
    g.fillRect(colorMatrix.getColumnCount() * m_cellSize.width, 0,
            colorMatrix.getColumnCount() * m_cellSize.width, this.getHeight());

    int rowCount = colorMatrix.getRowCount();
    int xLabelStartPosition = colorMatrix.getColumnCount() * m_cellSize.width + m_labelGutter;
    g.setColor(Color.black);
    g.setFont(m_labelFont);

    for (int i = 0; i < rowCount; i++) {
        int y = i * m_cellSize.height + m_columnLabelHeight + m_labelGutter;
        int yLabelPosition = y + m_cellSize.height - m_fontGutter;
        if (showScalebar) {
            yLabelPosition += SCALE_BAR_ROOM;
        }

        Object rowName = colorMatrix.getRowName(i);
        if (null == rowName) {
            rowName = "Undefined";
        }

        g.drawString(rowName.toString(), xLabelStartPosition, yLabelPosition);

    } // end drawing row names
    g.setColor(oldColor);
}

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  2  s  .  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.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  va  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:BeanContainer.java

public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Color colorRetainer = g.getColor();

        g.setColor(getBackground());/*from   ww w  .  ja  v a2s  . co  m*/
        g.fillRect(0, 0, getWidth(), getHeight());
        getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

        m_calendar.setTime(new Date()); // get current time
        int hrs = m_calendar.get(Calendar.HOUR_OF_DAY);
        int min = m_calendar.get(Calendar.MINUTE);

        g.setColor(getForeground());
        if (m_digital) {
            String time = "" + hrs + ":" + min;
            g.setFont(getFont());
            FontMetrics fm = g.getFontMetrics();
            int y = (getHeight() + fm.getAscent()) / 2;
            int x = (getWidth() - fm.stringWidth(time)) / 2;
            g.drawString(time, x, y);
        } else {
            int x = getWidth() / 2;
            int y = getHeight() / 2;
            int rh = getHeight() / 4;
            int rm = getHeight() / 3;

            double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI;
            double am = min / 30.0 * Math.PI;

            g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah)));
            g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am)));
        }

        g.setColor(colorRetainer);
    }

From source file:se.llbit.chunky.ui.Minimap.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // NB lock the lock ordering here is critical!
    // we access ChunkMap via Chunky but here we also need to lock Chunky
    synchronized (chunky) {
        synchronized (this) {
            ChunkView mapView = chunky.getMapView();

            WorldRenderer renderer = chunky.getWorldRenderer();
            World world = chunky.getWorld();
            ChunkSelectionTracker selection = chunky.getChunkSelection();

            renderer.render(world, mapBuffer, Chunk.biomeRenderer, selection);
            mapBuffer.renderBuffered(g);

            renderer.renderPlayer(world, g, view, true);
            renderer.renderSpawn(world, g, view, true);

            // draw view rectangle
            g.setColor(Color.orange);
            g.drawRect((int) FastMath.round(mapView.x0 - view.x0), (int) FastMath.round(mapView.z0 - view.z0),
                    FastMath.round(mapView.width / (float) mapView.scale),
                    FastMath.round(mapView.height / (float) mapView.scale));

            // draw North indicator
            g.setFont(font);
            g.setColor(Color.red);
            g.drawString("N", view.width / 2 - 4, 12);

            g.setColor(Color.black);
            g.drawString(world.levelName(), 10, view.height - 10);
        }/*from   w w  w. j a  v a  2s. c  o  m*/
    }
}