List of usage examples for java.awt Graphics fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:CalIcon.java
/** paintIcon: draw the calendar page. */ public void paintIcon(Component c, Graphics g, int x, int y) { // Allow clock to get painted (voodoo magic) if (showTime) super.paint(g); // Outline it. g.setColor(Color.black);//from ww w .ja v a 2s.c o m g.draw3DRect(x, y, d.width - 2, d.height - 2, true); // Show the date: First, a white page with a drop shadow. g.setColor(Color.gray); g.fillRect(x + RBX + 3, y + RBY + 3, RBW, RBH); g.setColor(Color.white); g.fillRect(x + RBX, y + RBY, RBW, RBH); // g.setColor(getForeground()); g.setColor(Color.black); String s = days[myCal.get(Calendar.DAY_OF_WEEK) - 1]; g.setFont(dayNameFont); int w = dayNameFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 10); s = Integer.toString(myCal.get(Calendar.DAY_OF_MONTH)); g.setFont(dayNumbFont); w = dayNumbFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 25); s = mons[myCal.get(Calendar.MONTH)]; g.setFont(monNameFont); w = monNameFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 35); }
From source file:uk.co.modularaudio.util.audio.gui.patternsequencer.PatternSequenceNoteGrid.java
@Override public void paint(final Graphics g) { // log.debug("Paint called"); getBounds(curClipBounds);//from w w w.j av a 2 s .com // log.debug( "Curclipbounds after get bounds are " + curClipBounds.toString() ); g.getClipBounds(curClipBounds); g.setColor(backgroundColour); // log.debug( "Curclipbounds after get clip bounds are " + curClipBounds.toString() ); g.fillRect(curClipBounds.x, curClipBounds.y, curClipBounds.width, curClipBounds.height); // Work out our boundings values +/- the individual cell width so we paint the edge cases too minPointToPaint.x = curClipBounds.x - cellDimensions.width; minPointToPaint.y = curClipBounds.y - cellDimensions.height; maxPointToPaint.x = curClipBounds.x + curClipBounds.width + (cellDimensions.width); maxPointToPaint.y = curClipBounds.y + curClipBounds.height + (cellDimensions.height); final int startCol = (minPointToPaint.x < 0 ? 0 : (minPointToPaint.x / cellDimensions.width)); final int endCol = (maxPointToPaint.x >= size.width ? numCols : (maxPointToPaint.x / cellDimensions.width)); final int startRow = (minPointToPaint.y < 0 ? 0 : (minPointToPaint.y / cellDimensions.height)); final int endRow = (maxPointToPaint.y >= size.height ? numMidiNotes : (maxPointToPaint.y / cellDimensions.height)); // log.debug( "So for minpoint(" + minPointToPaint.toString() + ") and maxpoint(" + maxPointToPaint.toString() + ")"); // log.debug( "We get startCol(" + startCol + ") and endCol(" + endCol +")"); // log.debug( "We get startRow(" + startRow + ") and endRow(" + endRow +")"); paintGrid(g, startCol, endCol, startRow, endRow); paintCells(g, startCol, endCol, startRow, endRow); // g.setColor( Color.RED ); // g.drawLine( lastPoint.x-2, lastPoint.y, lastPoint.x+2, lastPoint.y ); // g.drawLine( lastPoint.x, lastPoint.y-2, lastPoint.x, lastPoint.y+2 ); }
From source file:FileTree3.java
public void paintComponent(Graphics g) { Color bColor = getBackground(); Icon icon = getIcon();// w w w. ja v a 2 s. co m g.setColor(bColor); int offset = 0; if (icon != null && getText() != null) offset = (icon.getIconWidth() + getIconTextGap()); g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); if (m_selected) { g.setColor(m_borderSelectionColor); g.drawRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); } super.paintComponent(g); }
From source file:com.openkm.servlet.admin.StampServlet.java
/** * View text color/*from w ww.j ava2 s. c om*/ */ private void textColor(Session session, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DatabaseException { log.debug("textColor({}, {}, {})", new Object[] { session, request, response }); int stId = WebUtils.getInt(request, "st_id"); StampText st = StampTextDAO.findByPk(stId); BufferedImage bi = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.decode(st.getColor())); g.fillRect(0, 0, 16, 16); response.setContentType("image/jpeg"); ImageIO.write(bi, "jpg", response.getOutputStream()); log.debug("textColor: void"); }
From source file:Main.java
public void paint(Graphics g) { int fontSize = 20; g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); FontMetrics fm = g.getFontMetrics(); String s = "www.java2s.com"; int stringWidth = fm.stringWidth(s); int w = 200;//from w w w. j av a 2 s . com int h = 200; int x = (w - stringWidth) / 2; int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2; int ascent = fm.getMaxAscent(); int descent = fm.getMaxDecent(); int fontHeight = fm.getMaxAscent() + fm.getMaxDecent(); g.setColor(Color.white); g.fillRect(x, baseline - ascent, stringWidth, fontHeight); g.setColor(Color.gray); g.drawLine(x, baseline, x + stringWidth, baseline); g.setColor(Color.red); g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent); g.setColor(Color.blue); g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent); g.setColor(Color.black); g.drawString(s, x, baseline); }
From source file:MainClass.java
public void paint(Graphics g) { int fontSize = 20; g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); FontMetrics fm = g.getFontMetrics(); String s = "www.java2s.com"; int stringWidth = fm.stringWidth(s); int w = 200;//from w ww . j a va 2 s . co m int h = 200; int x = (w - stringWidth) / 2; int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2; int ascent = fm.getMaxAscent(); int descent = fm.getMaxDecent(); int fontHeight = fm.getMaxAscent() + fm.getMaxDecent(); g.setColor(Color.white); g.fillRect(x, baseline - ascent, stringWidth, fontHeight); g.setColor(Color.gray); g.drawLine(x, baseline, x + stringWidth, baseline); g.setColor(Color.red); g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent); g.setColor(Color.blue); g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent); g.setColor(Color.black); g.drawString(s, x, baseline); }
From source file:de.tor.tribes.ui.views.DSWorkbenchRankFrame.java
@Override public void actionPerformed(ActionEvent e) { RankTableTab activeTab = getActiveTab(); if (e.getActionCommand() != null && activeTab != null) { if (e.getActionCommand().equals("Find")) { BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT); Graphics g = back.getGraphics(); g.setColor(new Color(120, 120, 120, 120)); g.fillRect(0, 0, back.getWidth(), back.getHeight()); g.setColor(new Color(120, 120, 120)); g.drawLine(0, 0, 3, 3);// w w w . j a va 2s .co m g.dispose(); TexturePaint paint = new TexturePaint(back, new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight())); jxSearchPane.setBackgroundPainter(new MattePainter(paint)); DefaultListModel model = new DefaultListModel(); for (int i = 0; i < activeTab.getRankTable().getColumnCount(); i++) { TableColumnExt col = activeTab.getRankTable().getColumnExt(i); if (col.isVisible()) { if (col.getTitle().equals("Name") || col.getTitle().equals("Tag") || col.getTitle().equals("Stamm")) { model.addElement(col.getTitle()); } } } jXColumnList.setModel(model); jXColumnList.setSelectedIndex(0); jxSearchPane.setVisible(true); } } }
From source file:org.sbs.util.ImageCompress.java
/** * gif//from ww w. j a va 2s . c o m * * @param originalFile * * @param resizedFile * ? * @param newWidth * * @param newHeight * -1? * @param quality * () * @throws IOException */ public void resize(File originalFile, File resizedFile, int newWidth, int newHeight, float quality) throws IOException { if (quality < 0 || quality > 1) { throw new IllegalArgumentException("Quality has to be between 0 and 1"); } ImageIcon ii = new ImageIcon(originalFile.getCanonicalPath()); Image i = ii.getImage(); Image resizedImage = null; int iWidth = i.getWidth(null); int iHeight = i.getHeight(null); if (newHeight == -1) { if (iWidth > iHeight) { resizedImage = i.getScaledInstance(newWidth, (newWidth * iHeight) / iWidth, Image.SCALE_SMOOTH); } else { resizedImage = i.getScaledInstance((newWidth * iWidth) / iHeight, newWidth, Image.SCALE_SMOOTH); } } else { resizedImage = i.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH); } // This code ensures that all the pixels in the image are loaded. Image temp = new ImageIcon(resizedImage).getImage(); // Create the buffered image. BufferedImage bufferedImage = new BufferedImage(temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB); // Copy image to buffered image. Graphics g = bufferedImage.createGraphics(); // Clear background and paint the image. g.setColor(Color.white); g.fillRect(0, 0, temp.getWidth(null), temp.getHeight(null)); g.drawImage(temp, 0, 0, null); g.dispose(); // Soften. float softenFactor = 0.05f; float[] softenArray = { 0, softenFactor, 0, softenFactor, 1 - (softenFactor * 4), softenFactor, 0, softenFactor, 0 }; Kernel kernel = new Kernel(3, 3, softenArray); ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); bufferedImage = cOp.filter(bufferedImage, null); // Write the jpeg to a file. FileOutputStream out = FileUtils.openOutputStream(resizedFile); // Encodes image as a JPEG data stream JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bufferedImage); param.setQuality(quality, true); encoder.setJPEGEncodeParam(param); encoder.encode(bufferedImage); }
From source file:Main.java
public void paint(Graphics g) { int fontSize = 20; Font font = new Font("TimesRoman", Font.PLAIN, fontSize); g.setFont(font);/*from w ww .j ava2 s .c o m*/ FontMetrics fm = g.getFontMetrics(font); String s = "www.java2s.com"; int stringWidth = fm.stringWidth(s); int w = 200; int h = 200; int x = (w - stringWidth) / 2; int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2; int ascent = fm.getMaxAscent(); int descent = fm.getMaxDecent(); int fontHeight = fm.getMaxAscent() + fm.getMaxDecent(); g.setColor(Color.white); g.fillRect(x, baseline - ascent, stringWidth, fontHeight); g.setColor(Color.gray); g.drawLine(x, baseline, x + stringWidth, baseline); g.setColor(Color.red); g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent); g.setColor(Color.blue); g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent); g.setColor(Color.black); g.drawString(s, x, baseline); }
From source file:RedGreenBorder.java
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Insets insets = getBorderInsets(c); Color horizontalColor;/*from w ww . j a va 2 s.co m*/ if (c.isEnabled()) { boolean pressed = false; if (c instanceof AbstractButton) { ButtonModel model = ((AbstractButton) c).getModel(); pressed = model.isPressed(); } if (pressed) { horizontalColor = Color.RED; } else { horizontalColor = Color.GREEN; } } else { horizontalColor = Color.LIGHT_GRAY; } g.setColor(horizontalColor); g.fillRect(0, 0, width, insets.top); }