List of usage examples for java.awt Graphics drawRect
public void drawRect(int x, int y, int width, int height)
From source file:ColorSwatch.java
/** * Paints this Icon into the provided graphics context. *///from ww w.j ava 2 s . co m public void paintIcon(Component c, Graphics g, int x, int y) { if (ourSwatchIsVoid) return; Color oldColor = g.getColor(); if (ourSwatchIsMultiColor) { g.setColor(Color.white); g.fillRect(x, y, ourSwatchSize, ourSwatchSize); g.setColor(ourBorderColor); for (int i = 0; i < ourSwatchSize; i += 2) { g.drawLine(x + i, y, x + i, y + ourSwatchSize); } } else if (ourSwatchColor != null) { g.setColor(ourSwatchColor); g.fillRect(x, y, ourSwatchSize, ourSwatchSize); } else { g.setColor(Color.white); g.fillRect(x, y, ourSwatchSize, ourSwatchSize); g.setColor(ourBorderColor); g.drawLine(x, y, x + ourSwatchSize, y + ourSwatchSize); g.drawLine(x, y + ourSwatchSize, x + ourSwatchSize, y); } if (ourBorderPainted) { g.setColor(ourBorderColor); g.drawRect(x, y, ourSwatchSize, ourSwatchSize); } g.setColor(oldColor); }
From source file:com.hexidec.ekit.component.RelativeImageView.java
/** * Paints the image./*from w ww.j av a2 s . c o m*/ * * @param g the rendering surface to use * @param a the allocated region to render into * @see View#paint */ public void paint(Graphics g, Shape a) { Color oldColor = g.getColor(); fBounds = a.getBounds(); int border = getBorder(); int x = fBounds.x + border + getSpace(X_AXIS); int y = fBounds.y + border + getSpace(Y_AXIS); int width = fWidth; int height = fHeight; int sel = getSelectionState(); // If no pixels yet, draw gray outline and icon if (!hasPixels(this)) { g.setColor(Color.lightGray); g.drawRect(x, y, width - 1, height - 1); g.setColor(oldColor); loadImageStatusIcons(); Icon icon = ((fImage == null) ? sMissingImageIcon : sPendingImageIcon); if (icon != null) { icon.paintIcon(getContainer(), g, x, y); } } // Draw image if (fImage != null) { g.drawImage(fImage, x, y, width, height, this); } // If selected exactly, we need a black border & grow-box Color bc = getBorderColor(); if (sel == 2) { // Make sure there's room for a border int delta = 2 - border; if (delta > 0) { x += delta; y += delta; width -= delta << 1; height -= delta << 1; border = 2; } bc = null; g.setColor(Color.black); // Draw grow box g.fillRect(x + width - 5, y + height - 5, 5, 5); } // Draw border if (border > 0) { if (bc != null) { g.setColor(bc); } // Draw a thick rectangle: for (int i = 1; i <= border; i++) { g.drawRect(x - i, y - i, width - 1 + i + i, height - 1 + i + i); } g.setColor(oldColor); } }
From source file:thesaurusEditor.gui.graph.MainGraph.java
/** * create an instance of a simple graph with basic controls *///from w ww . j a va2 s . c om public MainGraph(List<Konzept> konzepte, Main main) { // create a simple graph for the demo this.konzepte = konzepte; this.main = main; main.getController().getThesaurus().addObserver(this); graph = new DirectedSparseGraph<Konzept, EdgeClass>(); for (Konzept k : konzepte) { graph.addVertex(k); } createEdges(konzepte); layout = new PersistentLayoutImpl<Konzept, EdgeClass>(new FRLayout<Konzept, EdgeClass>(graph)); //layout = new FRLayout<Konzept,EdgeClass>(graph); Dimension preferredSize = new Dimension(1300, 900); final VisualizationModel<Konzept, EdgeClass> visualizationModel = new DefaultVisualizationModel<Konzept, EdgeClass>( layout, preferredSize); vv = new VisualizationViewer<Konzept, EdgeClass>(visualizationModel, preferredSize); // this class will provide both label drawing and vertex shapes VertexLabelAsShapeRenderer<Konzept, EdgeClass> vlasr = new VertexLabelAsShapeRenderer<Konzept, EdgeClass>( vv.getRenderContext()); // customize the render context vv.getRenderContext().setVertexLabelTransformer(new Transformer<Konzept, String>() { public String transform(Konzept k) { return ""; } }); // this chains together Transformers so that the html tags // are prepended to the toString method output /*new ChainedTransformer<Konzept,String>(new Transformer[]{ new ToStringLabeller<Konzept>(), new Transformer<Konzept,String>() { public String transform(Konzept input) { return input.toString(); }}}));*/ vv.getRenderContext().setVertexShapeTransformer(new Transformer<Konzept, Shape>() { public Shape transform(Konzept k) { return new Rectangle(-((k.toString().length() * 8 + 10) / 2), -(10), k.toString().length() * 7 + 18, 21); } }); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red)); vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.black)); vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f))); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<Konzept>(vv.getPickedVertexState(), Color.white, Color.yellow)); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<EdgeClass>(vv.getPickedEdgeState(), Color.black, Color.red)); vv.getRenderContext().setVertexIconTransformer(new Transformer<Konzept, Icon>() { /* * Implements the Icon interface to draw an Icon with background color and * a text label */ public Icon transform(final Konzept v) { return new Icon() { private Konzept k; public int getIconHeight() { return 20; } public int getIconWidth() { if (k != null) { return k.toString().length() * 7 + 10; } return v.toString().length() * 7 + 10; } public void paintIcon(Component c, Graphics g, int x, int y) { if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.yellow); } else { g.setColor(Color.lightGray); } g.fillRect(x, y, v.toString().length() * 8 + 10, 20); if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.black); } else { g.setColor(Color.black); } g.drawRect(x, y, v.toString().length() * 8 + 10, 20); if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.black); } else { g.setColor(Color.black); } this.k = v; if (vv.getPickedVertexState().isPicked(v)) { Font font = new Font("DejaVu Sans Mono", Font.BOLD, 14); g.setFont(font); g.drawString("" + v, x + 6, y + 15); } else { Font font = new Font("DejaVu Sans Mono", Font.PLAIN, 14); g.setFont(font); g.drawString("" + v, x + 6, y + 15); } this.k = v; } }; } }); // customize the renderer /*GradientVertexRenderer<Konzept,EdgeClass> vertex = new GradientVertexRenderer<Konzept,EdgeClass>(Color.white, Color.white, true); vv.getRenderer().setVertexRenderer(vertex); vv.getRenderer().setVertexLabelRenderer(vlasr); */ vv.setBackground(Color.white); // add a listener for ToolTips KonzeptParser<Konzept> parser = new KonzeptParser<Konzept>(); vv.setVertexToolTipTransformer(parser); /*final DefaultModalGraphMouse<Konzept,Edge> graphMouse = new DefaultModalGraphMouse<Konzept,Edge>(); */ Factory<Konzept> vertexFactory = new VertexFactory(); Factory<EdgeClass> edgeFactory = new EdgeFactory(); graphMouse = new MyModalGraphMouse<Konzept, EdgeClass>(vv.getRenderContext(), vertexFactory, edgeFactory, main, vv); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); // the EditingGraphMouse will pass mouse event coordinates to the // vertexLocations function to set the locations of the vertices as // they are created // graphMouse.setVertexLocations(vertexLocations); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); graphMouse.setMode(ModalGraphMouse.Mode.EDITING); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); //graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton(); plus.setIcon(new ImageIcon(getClass().getResource("/thesaurusEditor/img/zoom_in.png"))); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton(); minus.setIcon(new ImageIcon(getClass().getResource("/thesaurusEditor/img/zoom_out.png"))); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(1, 2)); //zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); //controls.add(modeBox); /* javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(gzsp); gzsp.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 374, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 106, Short.MAX_VALUE) ); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(controls); controls.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 374, Short.MAX_VALUE) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 164, Short.MAX_VALUE) );*/ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(gzsp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(controls, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap() .addComponent(gzsp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(controls, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
private void xorRectangle(Point start_point, Point end_point) { Graphics g = getGraphics(); g.setXORMode(Color.white);//from ww w . j a v a2s . c om g.setColor(Color.gray); Rectangle rect = makeRectangle(start_point, end_point); g.drawRect(rect.x, rect.y, rect.width, rect.height); }
From source file:cish.CISH.java
@Override public void drawInformationPreNuclei(TMAspot ts, Graphics g, double z, int x_min, int y_min, int x_max, int y_max) { if (tss != null && !tss.isEmpty() && jCheckBox1.isSelected()) { int i = tss.indexOf(ts); if (i >= 0) { double x, y; int r = getParam_PointSignalRadius(); for (int[] coords : ps[i]) { x = coords[0];// w w w . j a v a2 s .c o m y = coords[1]; if (x >= x_min && y >= y_min && x < x_max && y < y_max) { g.setColor(new Color(coords[2], coords[3], coords[4])); g.drawRect((int) ((x - r) * z), (int) ((y - r) * z), (int) (2 * r * z), (int) (2 * r * z)); } } } } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
private void xorSelections(Point start_point, Point end_point) { Graphics g = getGraphics(); g.setXORMode(Color.white);// w w w . j a v a 2 s . co m g.setColor(Color.gray); int dx = end_point.x - start_point.x; int dy = end_point.y - start_point.y; for (AnnotationObject a : selections) { Rectangle rect = rectangles_complete.get(a); g.drawRect(dx + rect.x, dy + rect.y, rect.width, rect.height); } }
From source file:org.pmedv.core.components.RelativeImageView.java
/** * Paints the image.//w w w .j a v a2 s . co m * * @param g * the rendering surface to use * @param a * the allocated region to render into * @see View#paint */ public void paint(Graphics g, Shape a) { Color oldColor = g.getColor(); fBounds = a.getBounds(); int border = getBorder(); int x = fBounds.x + border + getSpace(X_AXIS); int y = fBounds.y + border + getSpace(Y_AXIS); int width = fWidth; int height = fHeight; int sel = getSelectionState(); // If no pixels yet, draw gray outline and icon if (!hasPixels(this)) { g.setColor(Color.lightGray); g.drawRect(x, y, width - 1, height - 1); g.setColor(oldColor); loadImageStatusIcons(); Icon icon = ((fImage == null) ? sMissingImageIcon : sPendingImageIcon); if (icon != null) { icon.paintIcon(getContainer(), g, x, y); } } // Draw image if (fImage != null) { g.drawImage(fImage, x, y, width, height, this); } // If selected exactly, we need a black border & grow-box Color bc = getBorderColor(); if (sel == 2) { // Make sure there's room for a border int delta = 2 - border; if (delta > 0) { x += delta; y += delta; width -= delta << 1; height -= delta << 1; border = 2; } bc = null; g.setColor(Color.black); // Draw grow box g.fillRect(x + width - 5, y + height - 5, 5, 5); } // Draw border if (border > 0) { if (bc != null) { g.setColor(bc); } // Draw a thick rectangle: for (int i = 1; i <= border; i++) { g.drawRect(x - i, y - i, width - 1 + i + i, height - 1 + i + i); } g.setColor(oldColor); } }
From source file:tufts.vue.RichTextBox.java
public void Xpaint(Graphics g) { super.paint(g); g.setColor(Color.gray);//w w w. j av a 2 s . com g.setClip(null); g.drawRect(0, 0, getWidth(), getHeight()); }
From source file:MyJava3D.java
public void drawPoint(Graphics graphics, Point3d[] pointArray) { graphics.drawRect((int) pointArray[0].x, (int) pointArray[0].y, POINT_WIDTH, POINT_HEIGHT); }
From source file:com.jcraft.weirdx.Draw.java
static void reqPolyRectangle(Client c, XDrawable d, GC gc) throws IOException { int n = c.length; //int foo;//from w ww. j a va 2 s . co m Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode); if (graphics == null) { c.client.readPad(n * 4); return; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { while (n > 0) { c.client.readPad(4); n--; } return; } } n /= 2; short x, y; int ww, hh; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; while (n != 0) { x = (short) c.client.readShort(); y = (short) c.client.readShort(); ww = c.client.readShort(); hh = c.client.readShort(); if (x < sx) sx = x; if (lx < x + ww) lx = x + ww; if (y < sy) sy = y; if (ly < y + hh) ly = y + hh; if (gc.lineWidth > 1) { int l2 = gc.lineWidth / 2; x -= l2; y -= l2; ww += gc.lineWidth; hh += gc.lineWidth; for (int i = 0; i < gc.lineWidth; i++) { ww -= 2; hh -= 2; x += 1; y += 1; graphics.drawRect(x, y, ww, hh); } } else { graphics.drawRect(x, y, ww, hh); } n--; } if (sx < 0) sx = 0; if (sy < 0) sy = 0; if (d instanceof XWindow) { ((XWindow) d).draw(sx, sy, lx - sx + 2, ly - sy + 2); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }