List of usage examples for java.awt Graphics setFont
public abstract void setFont(Font font);
From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java
public InteractiveColumnsResults generateInteractiveColumn(Dataset dataset, int[] selection) { interactiveColumnImg = null;/*from ww w .j a v a 2 s . co m*/ interactiveColumnImg = new BufferedImage(squareW + squareW, (sideTree.getHeight()), BufferedImage.TYPE_INT_ARGB); BufferedImage navgBackGroungImg = new BufferedImage(400, 10, BufferedImage.TYPE_INT_ARGB); Graphics navGr = navgBackGroungImg.getGraphics(); int navUnit = (dataset.getDataLength() / 200) + 1; Graphics g = interactiveColumnImg.getGraphics(); g.setFont(getTableFont(5)); drawTable(g, new Point(0, 0), dataset, selection, navGr, navUnit); navgBackGroungImg = rotateImage(navgBackGroungImg, 180); navgStringImg = this.generateEncodedImg(navgBackGroungImg); InteractiveColumnsResults results = new InteractiveColumnsResults(); results.setInteractiveColumn(splitImage(interactiveColumnImg)); results.setNavgUrl(navgStringImg); return results; }
From source file:VASSAL.build.module.map.LOS_Thread.java
/** * Writes text showing the range/* w w w . j ava 2s . co m*/ * * @param range the range to display, in whatever units returned * by the {@link MapGrid} containing the thread */ public void drawRange(Graphics g, int range) { Point mapArrow = map.componentCoordinates(arrow); Point mapAnchor = map.componentCoordinates(anchor); g.setColor(Color.black); g.setFont(RANGE_FONT); final FontMetrics fm = g.getFontMetrics(); final StringBuilder buffer = new StringBuilder(); int dummy = range; while (dummy >= 1) { dummy = dummy / 10; buffer.append("8"); } if (buffer.length() == 0) { buffer.append("8"); } String rangeMess = Resources.getString("LOS_Thread.range"); int wid = fm.stringWidth(" " + rangeMess + " " + buffer.toString()); int hgt = fm.getAscent() + 2; int w = mapArrow.x - mapAnchor.x; int h = mapArrow.y - mapAnchor.y; int x0 = mapArrow.x + (int) ((wid / 2 + 20) * w / Math.sqrt(w * w + h * h)); int y0 = mapArrow.y + (int) ((hgt / 2 + 20) * h / Math.sqrt(w * w + h * h)); g.fillRect(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid, hgt); g.setColor(Color.white); g.drawString(rangeMess + " " + range, x0 - wid / 2 + fm.stringWidth(" "), y0 + hgt / 2); lastRangeRect = new Rectangle(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid + 1, hgt + 1); Point np = map.mapCoordinates(new Point(lastRangeRect.x, lastRangeRect.y)); lastRangeRect.x = np.x; lastRangeRect.y = np.y; lastRange = String.valueOf(range); }
From source file:edu.uci.ics.jung.samples.HyperbolicVertexImageShaperDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features.//from www .jav a2 s . c om * */ public HyperbolicVertexImageShaperDemo() { // 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(HyperbolicVertexImageShaperDemo.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); FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph); layout.setMaxIterations(100); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(400, 400)); 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>(map); vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); // features on and off. For a real application, use VertexIconAndShapeFunction instead. final VertexIconShapeTransformer<Number> vertexImageShapeFunction = new VertexIconShapeTransformer<Number>( new EllipseVertexShapeTransformer<Number>()); final DefaultVertexIconTransformer<Number> vertexIconFunction = new DefaultVertexIconTransformer<Number>(); vertexImageShapeFunction.setIconMap(iconMap); vertexIconFunction.setIconMap(iconMap); vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction); vv.getRenderContext().setVertexIconTransformer(vertexIconFunction); // 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(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); 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()); } }); 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 controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); this.viewSupport = new HyperbolicImageLensSupport<Number, Number>(vv); this.modelSupport = new LayoutLensSupport<Number, Number>(vv); graphMouse.addItemListener(modelSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(viewSupport.getGraphMouse().getModeListener()); ButtonGroup radio = new ButtonGroup(); JRadioButton none = new JRadioButton("None"); none.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (viewSupport != null) { viewSupport.deactivate(); } if (modelSupport != null) { modelSupport.deactivate(); } } }); 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) { modelSupport.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); JPanel lensPanel = new JPanel(new GridLayout(2, 0)); lensPanel.setBorder(BorderFactory.createTitledBorder("Lens")); lensPanel.add(none); lensPanel.add(hyperView); lensPanel.add(hyperModel); controls.add(lensPanel); }
From source file:io.datalayer.jung.LensVertexImageShaperDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features./*w w w.j a va 2 s .c om*/ * */ public LensVertexImageShaperDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<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(LensVertexImageShaperDemo.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); FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph); layout.setMaxIterations(100); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(600, 600)); 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>(map); vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); // features on and off. For a real application, use VertexIconAndShapeFunction instead. final VertexIconShapeTransformer<Number> vertexImageShapeFunction = new VertexIconShapeTransformer<Number>( new EllipseVertexShapeTransformer<Number>()); final DefaultVertexIconTransformer<Number> vertexIconFunction = new DefaultVertexIconTransformer<Number>(); vertexImageShapeFunction.setIconMap(iconMap); vertexIconFunction.setIconMap(iconMap); vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction); vv.getRenderContext().setVertexIconTransformer(vertexIconFunction); // 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(vertexIconFunction)); 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 graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); 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()); } }); 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 controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); this.viewSupport = new MagnifyImageLensSupport<Number, Number>(vv); // new ViewLensSupport<Number,Number>(vv, new HyperbolicShapeTransformer(vv, // vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), // new ModalLensGraphMouse()); this.modelSupport = new LayoutLensSupport<Number, Number>(vv); graphMouse.addItemListener(modelSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(viewSupport.getGraphMouse().getModeListener()); ButtonGroup radio = new ButtonGroup(); JRadioButton none = new JRadioButton("None"); none.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (viewSupport != null) { viewSupport.deactivate(); } if (modelSupport != null) { modelSupport.deactivate(); } } }); 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) { modelSupport.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); JPanel lensPanel = new JPanel(new GridLayout(2, 0)); lensPanel.setBorder(BorderFactory.createTitledBorder("Lens")); lensPanel.add(none); lensPanel.add(hyperView); lensPanel.add(hyperModel); controls.add(lensPanel); }
From source file:edu.uci.ics.jung.samples.LensVertexImageShaperDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features.//from w w w. ja va2 s . c om * */ @SuppressWarnings("rawtypes") public LensVertexImageShaperDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<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(LensVertexImageShaperDemo.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); FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph); layout.setMaxIterations(100); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(600, 600)); 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>(map); vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); // features on and off. For a real application, use VertexIconAndShapeFunction instead. final VertexIconShapeTransformer<Number> vertexImageShapeFunction = new VertexIconShapeTransformer<Number>( new EllipseVertexShapeTransformer<Number>()); final DefaultVertexIconTransformer<Number> vertexIconFunction = new DefaultVertexIconTransformer<Number>(); vertexImageShapeFunction.setIconMap(iconMap); vertexIconFunction.setIconMap(iconMap); vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction); vv.getRenderContext().setVertexIconTransformer(vertexIconFunction); // 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(vertexIconFunction)); 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 graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); 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()); } }); 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 controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); this.viewSupport = new MagnifyImageLensSupport<Number, Number>(vv); // new ViewLensSupport<Number,Number>(vv, new HyperbolicShapeTransformer(vv, // vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), // new ModalLensGraphMouse()); this.modelSupport = new LayoutLensSupport<Number, Number>(vv); graphMouse.addItemListener(modelSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(viewSupport.getGraphMouse().getModeListener()); ButtonGroup radio = new ButtonGroup(); JRadioButton none = new JRadioButton("None"); none.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (viewSupport != null) { viewSupport.deactivate(); } if (modelSupport != null) { modelSupport.deactivate(); } } }); 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) { modelSupport.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); JPanel lensPanel = new JPanel(new GridLayout(2, 0)); lensPanel.setBorder(BorderFactory.createTitledBorder("Lens")); lensPanel.add(none); lensPanel.add(hyperView); lensPanel.add(hyperModel); controls.add(lensPanel); }
From source file:WeatherWizard.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension size = getSize();/* w ww . j a va 2 s.c o m*/ Composite origComposite; setupWeatherReport(); origComposite = g2.getComposite(); if (alpha0 != null) g2.setComposite(alpha0); g2.drawImage(img0, 0, 0, size.width, size.height, 0, 0, img0.getWidth(null), img0.getHeight(null), null); if (img1 != null) { if (alpha1 != null) g2.setComposite(alpha1); g2.drawImage(img1, 0, 0, size.width, size.height, 0, 0, img1.getWidth(null), img1.getHeight(null), null); } g2.setComposite(origComposite); // Freezing, Cold, Cool, Warm, Hot, // Blue, Green, Yellow, Orange, Red Font font = new Font("Serif", Font.PLAIN, 36); g.setFont(font); String tempString = feels + " " + temperature + "F"; FontRenderContext frc = ((Graphics2D) g).getFontRenderContext(); Rectangle2D boundsTemp = font.getStringBounds(tempString, frc); Rectangle2D boundsCond = font.getStringBounds(condStr, frc); int wText = Math.max((int) boundsTemp.getWidth(), (int) boundsCond.getWidth()); int hText = (int) boundsTemp.getHeight() + (int) boundsCond.getHeight(); int rX = (size.width - wText) / 2; int rY = (size.height - hText) / 2; g.setColor(Color.LIGHT_GRAY); g2.fillRect(rX, rY, wText, hText); g.setColor(textColor); int xTextTemp = rX - (int) boundsTemp.getX(); int yTextTemp = rY - (int) boundsTemp.getY(); g.drawString(tempString, xTextTemp, yTextTemp); int xTextCond = rX - (int) boundsCond.getX(); int yTextCond = rY - (int) boundsCond.getY() + (int) boundsTemp.getHeight(); g.drawString(condStr, xTextCond, yTextCond); }
From source file:org.jtrfp.trcl.core.ResourceManager.java
/** * Returns RAW image as an R8-G8-B8 buffer with a side-width which is the square root of the total number of pixels * @param name// w w w .j ava 2 s. c o m * @param palette * @param proc * @return * @throws IOException * @throws FileLoadException * @throws IllegalAccessException * @throws NotSquareException * @since Oct 26, 2012 */ public BufferedImage getRAWImage(String name, Color[] palette) throws IOException, FileLoadException, IllegalAccessException, NotSquareException, NonPowerOfTwoException { final RAWFile dat = getRAW(name); final byte[] raw = dat.getRawBytes(); if (raw.length != dat.getSideLength() * dat.getSideLength()) throw new NotSquareException(name); if ((dat.getSideLength() & (dat.getSideLength() - 1)) != 0) throw new NonPowerOfTwoException(name); final BufferedImage stamper = new BufferedImage(dat.getSideLength(), dat.getSideLength(), BufferedImage.TYPE_INT_ARGB); Graphics stG = stamper.getGraphics(); for (int i = 0; i < raw.length; i++) { Color c = palette[(int) raw[i] & 0xFF]; stG.setColor(c); stG.fillRect(i % dat.getSideLength(), i / dat.getSideLength(), 1, 1); } stG.dispose(); Graphics g = stamper.getGraphics(); //The following code stamps the filename into the texture for debugging purposes if (tr.isStampingTextures()) { g.setFont(new Font(g.getFont().getName(), g.getFont().getStyle(), 9)); g.drawString(name, 1, 16); } g.dispose(); return stamper; }
From source file:ChartPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); if (values == null || values.length == 0) return;// w ww .j a va 2 s. com double minValue = 0; double maxValue = 0; for (int i = 0; i < values.length; i++) { if (minValue > values[i]) minValue = values[i]; if (maxValue < values[i]) maxValue = values[i]; } Dimension d = getSize(); int clientWidth = d.width; int clientHeight = d.height; int barWidth = clientWidth / values.length; Font titleFont = new Font("SansSerif", Font.BOLD, 20); FontMetrics titleFontMetrics = g.getFontMetrics(titleFont); Font labelFont = new Font("SansSerif", Font.PLAIN, 10); FontMetrics labelFontMetrics = g.getFontMetrics(labelFont); int titleWidth = titleFontMetrics.stringWidth(title); int y = titleFontMetrics.getAscent(); int x = (clientWidth - titleWidth) / 2; g.setFont(titleFont); g.drawString(title, x, y); int top = titleFontMetrics.getHeight(); int bottom = labelFontMetrics.getHeight(); if (maxValue == minValue) return; double scale = (clientHeight - top - bottom) / (maxValue - minValue); y = clientHeight - labelFontMetrics.getDescent(); g.setFont(labelFont); for (int i = 0; i < values.length; i++) { int valueX = i * barWidth + 1; int valueY = top; int height = (int) (values[i] * scale); if (values[i] >= 0) valueY += (int) ((maxValue - values[i]) * scale); else { valueY += (int) (maxValue * scale); height = -height; } g.setColor(Color.red); g.fillRect(valueX, valueY, barWidth - 2, height); g.setColor(Color.black); g.drawRect(valueX, valueY, barWidth - 2, height); int labelWidth = labelFontMetrics.stringWidth(names[i]); x = i * barWidth + (barWidth - labelWidth) / 2; g.drawString(names[i], x, y); } }
From source file:ubic.basecode.graphics.MatrixDisplay.java
/** * Draws column names vertically (turned 90 degrees counter-clockwise) * /*from w w w. j a v a 2 s . c om*/ * @param g Graphics */ protected void drawColumnNames(Graphics g, boolean leaveRoomForScalebar) { if (colorMatrix == null) return; Color oldColor = g.getColor(); int y = m_columnLabelHeight; if (leaveRoomForScalebar) { y += SCALE_BAR_ROOM; } g.setColor(Color.white); g.fillRect(0, 0, this.getWidth(), y); g.setColor(Color.black); g.setFont(m_labelFont); int columnCount = colorMatrix.getColumnCount(); for (int j = 0; j < columnCount; j++) { // compute the coordinates int x = m_cellSize.width + j * m_cellSize.width - m_fontGutter; Object columnName = colorMatrix.getColumnName(j); if (null == columnName) { columnName = "Undefined"; } // fix the name length as 20 characters // add ellipses (...) if > 20 // spacepad to 20 if < 20 String columnNameString = columnName.toString(); if (m_maxColumnLength > 0) { columnNameString = padColumnString(columnNameString); } // print the text vertically Util.drawVerticalString(g, columnNameString, m_labelFont, x, y); } g.setColor(oldColor); }
From source file:MyCanvas.java
public void paintComponent(Graphics g) { super.paintComponent(g); // draw entire component white g.setColor(Color.white);//from w ww . j a v a 2 s.c o m g.fillRect(0, 0, getWidth(), getHeight()); // yellow circle g.setColor(Color.yellow); g.fillOval(0, 0, 240, 240); // magenta circle g.setColor(Color.magenta); g.fillOval(160, 160, 240, 240); // paint the icon below blue sqaure int w = java2sLogo.getIconWidth(); int h = java2sLogo.getIconHeight(); java2sLogo.paintIcon(this, g, 280 - (w / 2), 120 - (h / 2)); // paint the icon below red sqaure java2sLogo.paintIcon(this, g, 120 - (w / 2), 280 - (h / 2)); // transparent red square g.setColor(m_tRed); g.fillRect(60, 220, 120, 120); // transparent green circle g.setColor(m_tGreen); g.fillOval(140, 140, 120, 120); // transparent blue square g.setColor(m_tBlue); g.fillRect(220, 60, 120, 120); g.setColor(Color.black); g.setFont(monoFont); FontMetrics fm = g.getFontMetrics(); w = fm.stringWidth("Java Source"); h = fm.getAscent(); g.drawString("Java Source", 120 - (w / 2), 120 + (h / 4)); g.setFont(sanSerifFont); fm = g.getFontMetrics(); w = fm.stringWidth("and"); h = fm.getAscent(); g.drawString("and", 200 - (w / 2), 200 + (h / 4)); g.setFont(serifFont); fm = g.getFontMetrics(); w = fm.stringWidth("Support."); h = fm.getAscent(); g.drawString("Support.", 280 - (w / 2), 280 + (h / 4)); }