List of usage examples for java.awt Graphics setColor
public abstract void setColor(Color c);
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());/*from w w w.j a va 2s .com*/ component.setSize(size.x, size.y); 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:CustomAlphaTest.java
protected void drawAxes(Graphics g, long lMaxTime) { // draw the frame drawAreaRect(g, 0, 0, m_nMaxWidth, m_nMaxHeight); drawGraphString(g, -1, "Alpha vs. Time (secs)", m_nGraphMaxWidth / 2, m_nGraphMaxHeight + 20); // draw the X axis drawGraphLine(g, 0, 0, m_nGraphMaxWidth, 0); // draw the Y axis drawGraphLine(g, 0, 0, 0, m_nGraphMaxHeight); // draw the horizontal Y axis lines for (double yAxisTick = 0; yAxisTick <= 1.0; yAxisTick += 0.2) { double yTick = yAxisTick * m_nGraphMaxHeight; g.setColor(Color.gray); drawGraphLine(g, 0, yTick, m_nGraphMaxWidth, yTick); g.setColor(Color.black);//from w w w . jav a 2 s .c o m drawGraphString(g, 3, "" + yAxisTick, -20, yTick); } }
From source file:jtrace.Scene.java
/** * Add a set of axes to an image. If the object parameter is not null, * the axes corresponding to the object's coordinate system are drawn. * /* w ww .j a va 2s.c o m*/ * @param image Image generated using scene's camera * @param object (Possibly null) object */ private void renderAxes(BufferedImage image, SceneObject object) { Graphics gr = image.getGraphics(); int[] origin, xhat, yhat, zhat; if (object == null) { origin = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.ZERO); xhat = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.PLUS_I); yhat = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.PLUS_J); zhat = camera.getPixel(image.getWidth(), image.getHeight(), Vector3D.PLUS_K); } else { origin = camera.getPixel(image.getWidth(), image.getHeight(), object.objectToSceneVector(Vector3D.ZERO)); xhat = camera.getPixel(image.getWidth(), image.getHeight(), object.objectToSceneVector(Vector3D.PLUS_I)); yhat = camera.getPixel(image.getWidth(), image.getHeight(), object.objectToSceneVector(Vector3D.PLUS_J)); zhat = camera.getPixel(image.getWidth(), image.getHeight(), object.objectToSceneVector(Vector3D.PLUS_K)); } String objName; if (object == null) objName = ""; else objName = "(" + object.getClass().getSimpleName() + ")"; gr.setColor(Color.red); gr.drawLine(origin[0], origin[1], xhat[0], xhat[1]); gr.setColor(Color.white); gr.drawString("x " + objName, xhat[0], xhat[1]); gr.setColor(Color.green); gr.drawLine(origin[0], origin[1], yhat[0], yhat[1]); gr.setColor(Color.white); gr.drawString("y " + objName, yhat[0], yhat[1]); gr.setColor(Color.blue); gr.drawLine(origin[0], origin[1], zhat[0], zhat[1]); gr.setColor(Color.white); gr.drawString("z " + objName, zhat[0], zhat[1]); }
From source file:org.apache.cayenne.swing.components.textpane.JCayenneTextPane.java
public void paint(Graphics g) { super.paint(g); int start = getStartPositionInDocument(); int end = getEndPositionInDocument(); // end pos in doc // translate offsets to lines Document doc = pane.getDocument(); int startline = doc.getDefaultRootElement().getElementIndex(start) + 1; int endline = doc.getDefaultRootElement().getElementIndex(end) + 1; int fontHeight = g.getFontMetrics(pane.getFont()).getHeight(); int fontDesc = g.getFontMetrics(pane.getFont()).getDescent(); int starting_y = -1; try {//ww w . j a v a 2s. c o m if (pane.modelToView(start) == null) { starting_y = -1; } else { starting_y = pane.modelToView(start).y - scrollPane.getViewport().getViewPosition().y + fontHeight - fontDesc; } } catch (Exception e1) { logObj.warn("Error: ", e1); } for (int line = startline, y = starting_y; line <= endline; y += fontHeight, line++) { Color color = g.getColor(); if (line - 1 == doc.getDefaultRootElement().getElementIndex(pane.getCaretPosition())) { g.setColor(new Color(224, 224, 255)); g.fillRect(0, y - fontHeight + 3, 30, fontHeight + 1); } if (imageError) { Image img = ModelerUtil.buildIcon("error.gif").getImage(); g.drawImage(img, 0, endYPositionToolTip, this); } g.setColor(color); } }
From source file:org.cloudml.ui.graph.Visu.java
public void createFrame() { final VisualizationViewer<Vertex, Edge> vv = v.getVisualisationViewer(); vv.getRenderContext().setVertexIconTransformer(new Transformer<Vertex, Icon>() { public Icon transform(final Vertex v) { return new Icon() { public int getIconHeight() { return 40; }/* w w w .j ava 2 s . c om*/ public int getIconWidth() { return 40; } public void paintIcon(java.awt.Component c, Graphics g, int x, int y) { ImageIcon img; if (v.getType() == "node") { img = new ImageIcon(this.getClass().getResource("/server.png")); } else if (v.getType() == "platform") { img = new ImageIcon(this.getClass().getResource("/dbms.png")); } else { img = new ImageIcon(this.getClass().getResource("/soft.png")); } ImageObserver io = new ImageObserver() { public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { // TODO Auto-generated method stub return false; } }; g.drawImage(img.getImage(), x, y, getIconHeight(), getIconWidth(), io); if (!vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.black); } else { g.setColor(Color.red); properties.setModel(new CPIMTable(v)); runtimeProperties.setModel(new CPSMTable(v)); } g.drawString(v.getName(), x - 10, y + 50); } }; } }); // create a frame to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); 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 save = new JButton("save"); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(frame, "save"); File result = fc.getSelectedFile(); JsonCodec codec = new JsonCodec(); OutputStream streamResult; try { streamResult = new FileOutputStream(result); codec.save(dmodel, streamResult); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); JButton saveImage = new JButton("save as image"); saveImage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(frame, "save"); File result = fc.getSelectedFile(); JsonCodec codec = new JsonCodec(); v.writeJPEGImage(result); } }); //WE NEED TO UPDATE THE FACADE AND THE GUI JButton load = new JButton("load"); load.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(frame, "load"); File result = fc.getSelectedFile(); JsonCodec codec = new JsonCodec(); try { InputStream stream = new FileInputStream(result); Deployment model = (Deployment) codec.load(stream); dmodel = model; v.setDeploymentModel(dmodel); ArrayList<Vertex> V = v.drawFromDeploymentModel(); nodeTypes.removeAll(); nodeTypes.setModel(fillList()); properties.setModel(new CPIMTable(V.get(0))); runtimeProperties.setModel(new CPSMTable(V.get(0))); CommandFactory fcommand = new CommandFactory(); CloudMlCommand load = fcommand.loadDeployment(result.getPath()); cml.fireAndWait(load); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton deploy = new JButton("Deploy!"); deploy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //cad.deploy(dmodel); System.out.println("deploy"); CommandFactory fcommand = new CommandFactory(); CloudMlCommand deploy = fcommand.deploy(); cml.fireAndWait(deploy); } }); //right panel JPanel intermediary = new JPanel(); intermediary.setLayout(new BoxLayout(intermediary, BoxLayout.PAGE_AXIS)); intermediary.setBorder(BorderFactory.createLineBorder(Color.black)); JLabel jlCPIM = new JLabel(); jlCPIM.setText("CPIM"); JLabel jlCPSM = new JLabel(); jlCPSM.setText("CPSM"); properties = new JTable(null); //properties.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); JTableHeader h = properties.getTableHeader(); JPanel props = new JPanel(); props.setLayout(new BorderLayout()); props.add(new JScrollPane(properties), BorderLayout.CENTER); props.add(h, BorderLayout.NORTH); runtimeProperties = new JTable(null); //runtimeProperties.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); JTableHeader h2 = runtimeProperties.getTableHeader(); JPanel runProps = new JPanel(); runProps.setLayout(new BorderLayout()); runProps.add(h2, BorderLayout.NORTH); runProps.add(new JScrollPane(runtimeProperties), BorderLayout.CENTER); intermediary.add(jlCPIM); intermediary.add(props); intermediary.add(jlCPSM); intermediary.add(runProps); content.add(intermediary, BorderLayout.EAST); //Left panel JPanel selection = new JPanel(); JLabel nodes = new JLabel(); nodes.setText("Types"); selection.setLayout(new BoxLayout(selection, BoxLayout.PAGE_AXIS)); nodeTypes = new JList(fillList()); nodeTypes.setLayoutOrientation(JList.VERTICAL); nodeTypes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); nodeTypes.setVisibleRowCount(10); JScrollPane types = new JScrollPane(nodeTypes); types.setPreferredSize(new Dimension(150, 80)); selection.add(nodes); selection.add(types); content.add(selection, BorderLayout.WEST); ((DefaultModalGraphMouse<Integer, Number>) gm) .add(new MyEditingGraphMousePlugin(0, vv, v.getGraph(), nodeTypes, dmodel)); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(save); controls.add(saveImage); controls.add(load); controls.add(deploy); controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox()); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:WeatherWizard.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension size = getSize();/*from ww w. ja va2 s .co 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:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java
/** * Creates the center panel.//from w ww. ja va 2 s . c o m * * @return the created center panel */ private Container createCenter() { JPanel centerPanel = new JPanel(new GridBagLayout()); centerPanel.setBackground(Color.WHITE); centerPanel.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 3)); GridBagConstraints constraints = new GridBagConstraints(); initSmsLabel(centerPanel); initTextArea(centerPanel); smsCharCountLabel = new JLabel(String.valueOf(smsCharCount)); smsCharCountLabel.setForeground(Color.GRAY); smsCharCountLabel.setVisible(false); constraints.anchor = GridBagConstraints.NORTHEAST; constraints.fill = GridBagConstraints.NONE; constraints.gridx = 3; constraints.gridy = 0; constraints.weightx = 0f; constraints.weighty = 0f; constraints.insets = new Insets(0, 2, 0, 2); constraints.gridheight = 1; constraints.gridwidth = 1; centerPanel.add(smsCharCountLabel, constraints); smsNumberLabel = new JLabel(String.valueOf(smsNumberCount)) { @Override public void paintComponent(Graphics g) { AntialiasingManager.activateAntialiasing(g); g.setColor(getBackground()); g.fillOval(0, 0, getWidth(), getHeight()); super.paintComponent(g); } }; smsNumberLabel.setHorizontalAlignment(JLabel.CENTER); smsNumberLabel.setPreferredSize(new Dimension(18, 18)); smsNumberLabel.setMinimumSize(new Dimension(18, 18)); smsNumberLabel.setForeground(Color.WHITE); smsNumberLabel.setBackground(Color.GRAY); smsNumberLabel.setVisible(false); constraints.anchor = GridBagConstraints.NORTHEAST; constraints.fill = GridBagConstraints.NONE; constraints.gridx = 4; constraints.gridy = 0; constraints.weightx = 0f; constraints.weighty = 0f; constraints.insets = new Insets(0, 2, 0, 2); constraints.gridheight = 1; constraints.gridwidth = 1; centerPanel.add(smsNumberLabel, constraints); return centerPanel; }
From source file:es.emergya.ui.gis.CustomMapView.java
/** * Dibuja una brujula apuntando al norte * //from w w w . j a v a2 s . c o m * @param g */ @SuppressWarnings("unused") private void drawCompass(Graphics g) { int x = 50, y = getHeight() - 50; // ((Graphics2D)g).rotate(Math.PI + lastFollowAngle, x, y); ((Graphics2D) g).rotate(-PI_MEDIO - getAngle(), x, y); g.setColor(Color.LIGHT_GRAY); g.fillOval(0, getHeight() - 100, 100, 100); g.setColor(Color.BLACK); g.fillRect(x - 3, y - 3, 50, 6); g.setColor(Color.RED); g.fillRect(x + 42, y - 3, 6, 6); }
From source file:Base64.java
/** * Draws a line on the screen at the specified index. Default is green. * <p/>//from w w w . j a v a 2 s . co m * Available colours: red, green, cyan, purple, white. * * @param render The Graphics object to be used. * @param row The index where you want the text. * @param text The text you want to render. Colours can be set like [red]. */ public static void drawLine(Graphics render, int row, String text) { FontMetrics metrics = render.getFontMetrics(); int height = metrics.getHeight() + 4; // height + gap int y = row * height + 15 + 19; String[] texts = text.split("\\["); int xIdx = 7; Color cur = Color.GREEN; for (String t : texts) { for (@SuppressWarnings("unused") String element : COLOURS_STR) { // String element = COLOURS_STR[i]; // Don't search for a starting '[' cause it they don't exists. // we split on that. int endIdx = t.indexOf(']'); if (endIdx != -1) { String colorName = t.substring(0, endIdx); if (COLOR_MAP.containsKey(colorName)) { cur = COLOR_MAP.get(colorName); } else { try { Field f = Color.class.getField(colorName); int mods = f.getModifiers(); if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) { cur = (Color) f.get(null); COLOR_MAP.put(colorName, cur); } } catch (Exception ignored) { } } t = t.replace(colorName + "]", ""); } } render.setColor(Color.BLACK); render.drawString(t, xIdx, y + 1); render.setColor(cur); render.drawString(t, xIdx, y); xIdx += metrics.stringWidth(t); } }
From source file:rod_design_compute.ShowPanel.java
private void drawBasePoint(Point point, Graphics g) { int x = toScreenX(point.X); int y = toScreenY(point.Y); int lengthTri = 4 * radiusBase; int x1 = (int) (x - lengthTri * Math.sin(Math.toRadians(30))); int y1 = (int) (y + lengthTri * Math.cos(Math.toRadians(30))); int x2 = (int) (x + lengthTri * Math.sin(Math.toRadians(30))); int y2 = (int) (y + lengthTri * Math.cos(Math.toRadians(30))); g.drawLine(x, y, x1, y1);/*www . j a va2 s . c o m*/ g.drawLine(x, y, x2, y2); g.drawLine(x1 - radiusBase, y1, x2 + radiusBase, y2); g.drawLine(x1, y1, x1 - radiusBase, y1 + radiusBase); g.drawLine(x1 + radiusBase, y1, x1 + radiusBase - radiusBase, y1 + radiusBase); g.drawLine(x1 + 2 * radiusBase, y1, x1 + 2 * radiusBase - radiusBase, y1 + radiusBase); g.drawLine(x1 + 3 * radiusBase, y1, x1 + 3 * radiusBase - radiusBase, y1 + radiusBase); g.drawLine(x1 + 4 * radiusBase, y1, x1 + 4 * radiusBase - radiusBase, y1 + radiusBase); g.setColor(Color.white); g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2); g.setColor(Color.black); g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2); }