List of usage examples for java.awt Graphics drawString
public abstract void drawString(AttributedCharacterIterator iterator, int x, int y);
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFFloatColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//www. j a v a 2 s . c om } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Float) { Float val = (Float) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFDoubleColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from w ww. j a v a 2 s. c o m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Double) { Double val = (Double) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFInt32ColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/*www. ja va2 s . co m*/ } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Integer) { Integer val = (Integer) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFUInt64ColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//w ww . j ava 2s . c o m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof BigDecimal) { BigDecimal val = (BigDecimal) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
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);//from w ww . ja v a 2s. c o m 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 source file:bigdata.explorer.nutch.grapview.WebGraphZoomScrollPane.java
/** * create an instance of a simple graph with controls to * demo the zoom features./*from www . j av a 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:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFNumberColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from ww w . ja v a 2s . co m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof BigDecimal) { BigDecimal val = (BigDecimal) value; Format fmt = getNumberFormat(digits, precis); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:components.Rule.java
protected void paintComponent(Graphics g) { Rectangle drawHere = g.getClipBounds(); // Fill clipping area with dirty brown/orange. g.setColor(new Color(230, 163, 4)); g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); // Do the ruler labels in a small font that's black. g.setFont(new Font("SansSerif", Font.PLAIN, 10)); g.setColor(Color.black);// w ww . j av a 2s . c o m // Some vars we need. int end = 0; int start = 0; int tickLength = 0; String text = null; // Use clipping bounds to calculate first and last tick locations. if (orientation == HORIZONTAL) { start = (drawHere.x / increment) * increment; end = (((drawHere.x + drawHere.width) / increment) + 1) * increment; } else { start = (drawHere.y / increment) * increment; end = (((drawHere.y + drawHere.height) / increment) + 1) * increment; } // Make a special case of 0 to display the number // within the rule and draw a units label. if (start == 0) { text = Integer.toString(0) + (isMetric ? " cm" : " in"); tickLength = 10; if (orientation == HORIZONTAL) { g.drawLine(0, SIZE - 1, 0, SIZE - tickLength - 1); g.drawString(text, 2, 21); } else { g.drawLine(SIZE - 1, 0, SIZE - tickLength - 1, 0); g.drawString(text, 9, 10); } text = null; start = increment; } // ticks and labels for (int i = start; i < end; i += increment) { if (i % units == 0) { tickLength = 10; text = Integer.toString(i / units); } else { tickLength = 7; text = null; } if (tickLength != 0) { if (orientation == HORIZONTAL) { g.drawLine(i, SIZE - 1, i, SIZE - tickLength - 1); if (text != null) g.drawString(text, i - 3, 21); } else { g.drawLine(SIZE - 1, i, SIZE - tickLength - 1, i); if (text != null) g.drawString(text, 9, i + 3); } } } }
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 w ww. 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.//www . j a v a 2 s . c o 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); }