List of usage examples for java.awt Graphics drawString
public abstract void drawString(AttributedCharacterIterator iterator, int x, int y);
From source file:edu.upf.bioevo.manhattanPlotter.QQPlot.java
void drawPlot() { int dotRadius; int xIncrement = (IMAGE_WIDTH - (xMargin * 2)) / (int) (maxExpectedLogValue + 1); int yIncrement = (IMAGE_HEIGHT - (yMargin * 2)) / (int) (maxObservedLogValue + 1); Graphics g = image.getGraphics(); // Cleans image g.setColor(Color.WHITE);//from w ww.ja v a2s. c o m g.fillRect(0, 0, image.getWidth(), image.getHeight()); // Draws axis lines g.setColor(Color.black); g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, IMAGE_WIDTH - xMargin, IMAGE_HEIGHT - yMargin); g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin, yMargin); // Draws confidence interval if (ic95Option) { g.setColor(Color.lightGray); for (int i = 0; i < upperCI.length - 1; i++) { int[] xPoints = { xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement) }; int[] yPoints = { IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i + 1] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i + 1] * yIncrement))) }; g.fillPolygon(xPoints, yPoints, 4); } } // Draws dots dotRadius = 4; g.setColor(Color.black); for (int i = 0; i < orderedLog10ObservedValues.length; i++) { int xPosition = xMargin + ((int) (orderedLog10ExpectedValues[i] * xIncrement)); int yPosition = IMAGE_HEIGHT - (yMargin + ((int) (orderedLog10ObservedValues[i] * yIncrement))); g.fillOval(xPosition - dotRadius, yPosition - dotRadius, dotRadius * 2, dotRadius * 2); } // --draw y axis scale // ----Calculates interval between labels in y axis int yInterval = 1; int verticalMaxValue = (int) maxObservedLogValue + 1; if (verticalMaxValue > 20) { yInterval = 5; } if (verticalMaxValue > 100) { yInterval = 50; } if (verticalMaxValue > 1000) { yInterval = verticalMaxValue; } g.setColor(Color.BLACK); for (int i = 0; i <= verticalMaxValue; i = i + yInterval) { int yPos = IMAGE_HEIGHT - (yMargin + (int) (((float) i / verticalMaxValue) * (IMAGE_HEIGHT - 2 * yMargin))); g.fillRect(45, yPos, 15, 3); g.setFont(new Font("courier", 1, 30)); String value = String.valueOf(i); if (value.length() == 1) { value = " " + value; } g.drawString(value, 5, yPos + 10); } // --draw x axis scale // ----Calculates interval between labels in x axis int xInterval = 1; int horizontalMaxValue = (int) maxExpectedLogValue + 1; if (horizontalMaxValue > 20) { xInterval = 5; } if (horizontalMaxValue > 100) { xInterval = 50; } if (horizontalMaxValue > 1000) { xInterval = verticalMaxValue; } g.setColor(Color.BLACK); for (int i = 0; i <= horizontalMaxValue; i = i + xInterval) { int xPos = (xMargin + (int) (((float) i / horizontalMaxValue) * (IMAGE_WIDTH - 2 * xMargin))); g.fillRect(xPos, IMAGE_HEIGHT - yMargin, 3, 15); g.setFont(new Font("courier", 1, 30)); String value = String.valueOf(i); if (value.length() == 1) { value = " " + value; } g.drawString(value, xPos - 15, IMAGE_HEIGHT - yMargin + 45); } // Draws identity line g.setColor(Color.RED); int endLineValue = horizontalMaxValue < verticalMaxValue ? horizontalMaxValue : verticalMaxValue; g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin + ((int) (endLineValue * xIncrement)), IMAGE_HEIGHT - (yMargin + ((int) (endLineValue * yIncrement)))); // -- title g.setColor(Color.blue); g.setFont(new Font("arial", 1, 35)); g.drawString(label, IMAGE_WIDTH / 7, 40); }
From source file:com.cburch.logisim.gui.start.AboutCredits.java
@Override protected void paintComponent(Graphics g) { FontMetrics[] fms = new FontMetrics[font.length]; for (int i = 0; i < fms.length; i++) { fms[i] = g.getFontMetrics(font[i]); }/*from w w w . j a v a 2s . c o m*/ if (linesHeight == 0) { int y = 0; int index = -1; for (CreditsLine line : lines) { index++; if (index == initialLines) initialHeight = y; if (line.type == 0) y += 10; FontMetrics fm = fms[line.type]; line.y = y + fm.getAscent(); y += fm.getHeight(); } linesHeight = y; } Paint[] paint = paintSteady; int yPos = 0; int height = getHeight(); int initY = Math.min(0, initialHeight - height + About.IMAGE_BORDER); int maxY = linesHeight - height - initY; int totalMillis = 2 * MILLIS_FREEZE + (linesHeight + height) * MILLIS_PER_PIXEL; int offs = scroll % totalMillis; if (offs >= 0 && offs < MILLIS_FREEZE) { // frozen before starting the credits scroll int a = 255 * (MILLIS_FREEZE - offs) / MILLIS_FREEZE; if (a > 245) { paint = null; } else if (a < 15) { paint = paintSteady; } else { paint = new Paint[colorBase.length]; for (int i = 0; i < paint.length; i++) { Color hue = colorBase[i]; paint[i] = new GradientPaint(0.0f, 0.0f, derive(hue, a), 0.0f, fadeStop, hue); } } yPos = initY; } else if (offs < MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) { // scrolling through credits yPos = initY + (offs - MILLIS_FREEZE) / MILLIS_PER_PIXEL; } else if (offs < 2 * MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) { // freezing at bottom of scroll yPos = initY + maxY; } else if (offs < 2 * MILLIS_FREEZE + (linesHeight - initY) * MILLIS_PER_PIXEL) { // scrolling bottom off screen yPos = initY + (offs - 2 * MILLIS_FREEZE) / MILLIS_PER_PIXEL; } else { // scrolling next credits onto screen int millis = offs - 2 * MILLIS_FREEZE - (linesHeight - initY) * MILLIS_PER_PIXEL; paint = null; yPos = -height + millis / MILLIS_PER_PIXEL; } int width = getWidth(); int centerX = width / 2; maxY = getHeight(); for (CreditsLine line : lines) { int y = line.y - yPos; if (y < -100 || y > maxY + 50) continue; int type = line.type; if (paint == null) { g.setColor(colorBase[type]); } else { ((Graphics2D) g).setPaint(paint[type]); } g.setFont(font[type]); int textWidth = fms[type].stringWidth(line.text); g.drawString(line.text, centerX - textWidth / 2, line.y - yPos); Image img = line.img; if (img != null) { int x = width - line.imgWidth - About.IMAGE_BORDER; int top = y - fms[type].getAscent(); g.drawImage(img, x, top, this); } } }
From source file:org.prom5.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java
protected void paintComponentLane(Graphics g, int imageWidth, int imageHeight, boolean isModel) { g.setFont(g.getFont().deriveFont((float) 10.0)); // set initial colors Color fgColor = null;/*w w w.j av a 2 s . co m*/ Color bgColor = null; Color tmpColor = null; fgColor = null; bgColor = null; int clipL, clipR; // calculate common coordinates int yTop, yBottom, tempBorder, upper, bottom; if (isModel) { yTop = BORDER; yBottom = imageHeight - BORDER; clipL = coUtil.getClipL(); clipR = coUtil.getClipR(); upper = coUtil.getClipU(); bottom = coUtil.getClipB(); tempBorder = BORDER; } else { yTop = 0; yBottom = imageHeight; clipL = 0; clipR = imageWidth; upper = 0; bottom = this.getHeight(); tempBorder = BUFFERBORDER; } int pixStart = 0; // initialize start color fgColor = dca.getSettingPanel().getFBcolor(); bgColor = dca.getSettingPanel().getSBcolor(); ; // paint actual log lane (only the part in the clipping range determined) Iterator<String> itr = dcModel.getSortedMapModel().getSortedItemArrayList(dcop.getTimeOption(), dcop.getComponentType(), dcop.getSortStandard(), dcop.isDescCheckBoxSelected()).iterator(); g.setFont(new Font("Dialog", Font.BOLD, 13)); int size = dcModel.getComponentSize(dca.getDottedChartOptionPanel().getComponentType()); int index = 0; while (itr.hasNext()) { String dimName = itr.next(); g.setColor(bgColor); int top = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder); int bot = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder); if (bot >= upper && top <= bottom) { if (top < upper) top = upper; if (bot > bottom) bot = bottom; g.fillRect(pixStart, top - coUtil.getClipU(), clipR, bottom - coUtil.getClipU()); g.setColor(fgColor); if (isModel) { if (top + 20 - coUtil.getClipU() <= imageHeight - tempBorder) g.drawString(dimName, pixStart + 5, top + 20 - coUtil.getClipU()); } } if (coUtil.unit2CordHeight(index + 1, size, imageHeight, tempBorder) > bottom) break; index++; // swap colors tmpColor = fgColor; fgColor = bgColor; bgColor = tmpColor; } g.setFont(new Font("Dialog", Font.PLAIN, 12)); // draw horizontal delimiters g.setColor(colorTimeLine); g.drawLine(clipL, yTop, clipR, yTop); g.drawLine(clipL, yBottom, clipR, yBottom); }
From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java
protected void paintComponentLane(Graphics g, int imageWidth, int imageHeight, boolean isModel) { g.setFont(g.getFont().deriveFont((float) 10.0)); // set initial colors Color fgColor = null;//from ww w. ja v a 2s .c om Color bgColor = null; Color tmpColor = null; fgColor = null; bgColor = null; int clipL, clipR; // calculate common coordinates int yTop, yBottom, tempBorder, upper, bottom; if (isModel) { yTop = BORDER; yBottom = imageHeight - BORDER; clipL = coUtil.getClipL(); clipR = coUtil.getClipR(); upper = coUtil.getClipU(); bottom = coUtil.getClipB(); tempBorder = BORDER; } else { yTop = 0; yBottom = imageHeight; clipL = 0; clipR = imageWidth; upper = 0; bottom = this.getHeight(); tempBorder = BUFFERBORDER; } int pixStart = 0; // initialize start color fgColor = dca.getSettingPanel().getFBcolor(); bgColor = dca.getSettingPanel().getSBcolor(); ; // paint actual log lane (only the part in the clipping range // determined) Iterator<String> itr = dcModel.getSortedMapModel().getSortedItemArrayList(dcop.getTimeOption(), dcop.getComponentType(), dcop.getSortStandard(), dcop.isDescCheckBoxSelected()).iterator(); g.setFont(new Font("Dialog", Font.BOLD, 13)); int size = dcModel.getComponentSize(dca.getDottedChartOptionPanel().getComponentType()); int index = 0; while (itr.hasNext()) { String dimName = itr.next(); g.setColor(bgColor); int top = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder); int bot = coUtil.unit2CordHeight(index, size, imageHeight, tempBorder); if (bot >= upper && top <= bottom) { if (top < upper) top = upper; if (bot > bottom) bot = bottom; g.fillRect(pixStart, top - coUtil.getClipU(), clipR, bottom - coUtil.getClipU()); g.setColor(fgColor); if (isModel) { if (top + 20 - coUtil.getClipU() <= imageHeight - tempBorder) g.drawString(dimName, pixStart + 5, top + 20 - coUtil.getClipU()); } } if (coUtil.unit2CordHeight(index + 1, size, imageHeight, tempBorder) > bottom) break; index++; // swap colors tmpColor = fgColor; fgColor = bgColor; bgColor = tmpColor; } g.setFont(new Font("Dialog", Font.PLAIN, 12)); // draw horizontal delimiters g.setColor(colorTimeLine); g.drawLine(clipL, yTop, clipR, yTop); g.drawLine(clipL, yBottom, clipR, yBottom); }
From source file:com.actelion.research.table.view.JVisualization.java
protected void paintTouchIcon(Graphics g) { if (mTouchFunctionActive) { g.setColor(Color.red);// w w w.j a v a 2 s . com // g.setFont(Font.); g.drawString("touch", 10, 20); } }
From source file:org.prom5.analysis.performance.dottedchart.ui.DottedChartPanel.java
protected void paintComponentLane(Graphics g) { double percentileL = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceL()); double percentileU = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceU()); g.setFont(g.getFont().deriveFont((float) 10.0)); // set initial colors Color fgColor = null;//from w w w. ja v a 2 s . co m Color bgColor = null; Color tmpColor = null; fgColor = null; bgColor = null; // calculate common coordinates int unitHeight = (this.getHeight() - 2 * border) / getHashMapSize(); int yTop = border; int yBottom = this.getHeight() - border; int pixStart = 0; String dateStr, timeStr, millisStr = null; // calculate area to be painted clipL = (int) g.getClipBounds().getMinX() - 1; clipR = (int) g.getClipBounds().getMaxX() + 1; // initialze start color fgColor = colorLogDark; bgColor = colorLogBright; // calculate current top int currentTop = yTop; // paint actual log lane (only the part in the clipping range determined) Iterator itr = dcModel.getSortedKeySetList().iterator(); g.setFont(new Font("Dialog", Font.BOLD, 13)); int index = 0; currentTop = yTop; while (itr.hasNext()) { String dimName = (String) itr.next(); LogUnitList tempList = ((LogUnitList) dcModel.getItemMap().get(dimName)); long tempDuration; try { tempDuration = (tempList .getRightBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()) .getTime() - tempList.getLeftBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()).getTime()); } catch (Exception ce) { tempDuration = 0; } if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName)) continue; g.setColor(bgColor); g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight); g.setColor(fgColor); // for bottleneck if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances && tempDuration >= percentileL && tempDuration <= percentileU) g.setColor(Color.red); else g.setColor(Color.black); g.drawString(dimName, pixStart + 5, currentTop + 20); index++; currentTop = unit2Cord(index); // swap colors tmpColor = fgColor; fgColor = bgColor; bgColor = tmpColor; } g.setFont(new Font("Dialog", Font.PLAIN, 12)); // draw horizontal delimiters g.setColor(colorTimeLine); g.drawLine(clipL, yTop, clipR, yTop); g.drawLine(clipL, yBottom, clipR, yBottom); clipLeftTs = coord2timeMillis(clipL); clipRightTs = coord2timeMillis(clipR); // draw vertical lines // adjust width if (bAdjust) { adjustWidth(); bAdjust = false; } for (long timeStart = dcModel.getLogBoundaryLeft() .getTime(); timeStart < clipRightTs; timeStart += dcOptionPanel.getWidthDivider()) { pixStart = time2coord(timeStart) + border; cal.setTimeInMillis(timeStart); g.setColor(colorTimeLine); g.drawLine(pixStart, yTop, pixStart, yBottom); g.setColor(colorLogDark); g.setColor(Color.black); // to be deleted if (timeOption.equals(TIME_ACTUAL)) { dateStr = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "." + cal.get(Calendar.YEAR); g.drawString(dateStr, pixStart + 2, yTop); timeStr = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); g.drawString(timeStr, pixStart + 2, yTop + 10); } else if (timeOption.equals(TIME_RELATIVE_TIME)) { long days = timeStart / 1000 / 60 / 60 / 24; long hours = (timeStart - days * 24 * 60 * 60 * 1000) / 1000 / 60 / 60; long minutes = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60; long seconds = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000; timeStr = days + "days:" + hours + ":" + minutes + ":" + seconds; g.drawString(timeStr, pixStart + 2, yTop); } else if (timeOption.equals(TIME_RELATIVE_RATIO)) { timeStr = timeStart / 100 + "." + (timeStart - timeStart / 100 * 100) + "%"; g.drawString(timeStr, pixStart + 2, yTop); } else if (timeOption.equals(TIME_LOGICAL) || timeOption.equals(TIME_LOGICAL_RELATIVE)) { timeStr = String.valueOf(timeStart); g.drawString(timeStr, pixStart + 2, yTop); } } }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
protected void paintComponentLane(Graphics g) { double percentileL = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceL()); double percentileU = dcModel.getTimeStatistics().get(0) .getPercentile(dca.getSettingPanel().getPercentileforInstanceU()); g.setFont(g.getFont().deriveFont((float) 10.0)); // set initial colors Color fgColor = null;// w w w . jav a 2 s. c om Color bgColor = null; Color tmpColor = null; fgColor = null; bgColor = null; // calculate common coordinates int unitHeight = (this.getHeight() - 2 * border) / getHashMapSize(); int yTop = border; int yBottom = this.getHeight() - border; int pixStart = 0; String dateStr, timeStr, millisStr = null; // calculate area to be painted clipL = (int) g.getClipBounds().getMinX() - 1; clipR = (int) g.getClipBounds().getMaxX() + 1; // initialze start color fgColor = colorLogDark; bgColor = colorLogBright; // calculate current top int currentTop = yTop; // paint actual log lane (only the part in the clipping range // determined) Iterator itr = dcModel.getSortedKeySetList().iterator(); g.setFont(new Font("Dialog", Font.BOLD, 13)); int index = 0; currentTop = yTop; while (itr.hasNext()) { String dimName = (String) itr.next(); LogUnitList tempList = ((LogUnitList) dcModel.getItemMap().get(dimName)); long tempDuration; try { tempDuration = (tempList .getRightBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()) .getTime() - tempList.getLeftBoundaryTimestamp(dcModel.getEventTypeToKeep(), dcModel.getInstanceTypeToKeep()).getTime()); } catch (Exception ce) { tempDuration = 0; } if (dcModel.getTypeHashMap().equals(ST_INST) && !dcModel.getInstanceTypeToKeep().contains(dimName)) continue; g.setColor(bgColor); g.fillRect(pixStart, currentTop, clipR, currentTop + unitHeight); g.setColor(fgColor); // for bottleneck if (dcOptionPanel.getComponentType().equals(DottedChartPanel.ST_INST) && bBottleneckforInstances && tempDuration >= percentileL && tempDuration <= percentileU) g.setColor(Color.red); else g.setColor(Color.black); g.drawString(dimName, pixStart + 5, currentTop + 20); index++; currentTop = unit2Cord(index); // swap colors tmpColor = fgColor; fgColor = bgColor; bgColor = tmpColor; } g.setFont(new Font("Dialog", Font.PLAIN, 12)); // draw horizontal delimiters g.setColor(colorTimeLine); g.drawLine(clipL, yTop, clipR, yTop); g.drawLine(clipL, yBottom, clipR, yBottom); clipLeftTs = coord2timeMillis(clipL); clipRightTs = coord2timeMillis(clipR); // draw vertical lines // adjust width if (bAdjust) { adjustWidth(); bAdjust = false; } for (long timeStart = dcModel.getLogBoundaryLeft() .getTime(); timeStart < clipRightTs; timeStart += dcOptionPanel.getWidthDivider()) { pixStart = time2coord(timeStart) + border; cal.setTimeInMillis(timeStart); g.setColor(colorTimeLine); g.drawLine(pixStart, yTop, pixStart, yBottom); g.setColor(colorLogDark); g.setColor(Color.black); // to be deleted if (timeOption.equals(TIME_ACTUAL)) { dateStr = cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH) + 1) + "." + cal.get(Calendar.YEAR); g.drawString(dateStr, pixStart + 2, yTop); timeStr = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); g.drawString(timeStr, pixStart + 2, yTop + 10); } else if (timeOption.equals(TIME_RELATIVE_TIME)) { long days = timeStart / 1000 / 60 / 60 / 24; long hours = (timeStart - days * 24 * 60 * 60 * 1000) / 1000 / 60 / 60; long minutes = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000) / 1000 / 60; long seconds = (timeStart - days * 24 * 60 * 60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000) / 1000; timeStr = days + "days:" + hours + ":" + minutes + ":" + seconds; g.drawString(timeStr, pixStart + 2, yTop); } else if (timeOption.equals(TIME_RELATIVE_RATIO)) { timeStr = timeStart / 100 + "." + (timeStart - timeStart / 100 * 100) + "%"; g.drawString(timeStr, pixStart + 2, yTop); } else if (timeOption.equals(TIME_LOGICAL) || timeOption.equals(TIME_LOGICAL_RELATIVE)) { timeStr = String.valueOf(timeStart); g.drawString(timeStr, pixStart + 2, yTop); } } }
From source file:com.projity.contrib.calendar.JXXMonthView.java
/** * {@inheritDoc}//www. j a v a 2s. co m */ protected void paintComponent(Graphics g) { Object oldAAValue = null; Graphics2D g2 = (g instanceof Graphics2D) ? (Graphics2D) g : null; if (g2 != null && _antiAlias) { oldAAValue = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } Rectangle clip = g.getClipBounds(); updateIfNecessary(); if (isOpaque()) { g.setColor(getBackground()); g.fillRect(clip.x, clip.y, clip.width, clip.height); } g.setColor(getForeground()); Color shadowColor = g.getColor(); shadowColor = new Color(shadowColor.getRed(), shadowColor.getGreen(), shadowColor.getBlue(), (int) (.20 * 255)); FontMetrics fm = g.getFontMetrics(); // Reset the calendar. _cal.setTimeInMillis(_firstDisplayedDate); // Center the calendars vertically in the available space. int y = _startY; for (int row = 0; row < _numCalRows; row++) { // Center the calendars horizontally in the available space. int x = _startX; int tmpX, tmpY; // Check if this row falls in the clip region. _bounds.x = 0; _bounds.y = _startY + row * (_calendarHeight + CALENDAR_SPACING); _bounds.width = getWidth(); _bounds.height = _calendarHeight; if (!_bounds.intersects(clip)) { _cal.add(Calendar.MONTH, _numCalCols); y += _calendarHeight + CALENDAR_SPACING; continue; } for (int column = 0; column < _numCalCols; column++) { String monthName = _monthsOfTheYear[_cal.get(Calendar.MONTH)]; monthName = monthName + " " + _cal.get(Calendar.YEAR); _bounds.x = _ltr ? x : x - _calendarWidth; _bounds.y = y + _boxPaddingY; _bounds.width = _calendarWidth; _bounds.height = _boxHeight; if (_bounds.intersects(clip)) { // Paint month name background. paintMonthStringBackground(g, _bounds.x, _bounds.y, _bounds.width, _bounds.height); // Paint month name. g.setColor(getForeground()); tmpX = _ltr ? x + (_calendarWidth / 2) - (fm.stringWidth(monthName) / 2) : x - (_calendarWidth / 2) - (fm.stringWidth(monthName) / 2) - 1; tmpY = y + _boxPaddingY + _boxHeight - fm.getDescent(); g.drawString(monthName, tmpX, tmpY); if ((_dropShadowMask & MONTH_DROP_SHADOW) != 0) { g.setColor(shadowColor); g.drawString(monthName, tmpX + 1, tmpY + 1); g.setColor(getForeground()); } } _bounds.x = _ltr ? x : x - _calendarWidth; _bounds.y = y + _boxPaddingY + _boxHeight + _boxPaddingY + _boxPaddingY; _bounds.width = _calendarWidth; _bounds.height = _boxHeight; if (_bounds.intersects(clip)) { _cal.set(Calendar.DAY_OF_MONTH, _cal.getActualMinimum(Calendar.DAY_OF_MONTH)); Calendar weekCal = (Calendar) _cal.clone(); // Paint short representation of day of the week. int dayIndex = _firstDayOfWeek - 1; int month = weekCal.get(Calendar.MONTH); // dayIndex = (_cal.get(Calendar.DAY_OF_WEEK) -1) %7; for (int i = 0; i < DAYS_IN_WEEK; i++) { // PROJITY_MODIFICATION // set the week calendar to the current day of week and make sure it's still in this month weekCal.set(Calendar.DAY_OF_WEEK, dayIndex + 1); if (weekCal.get(Calendar.MONTH) != month) weekCal.roll(Calendar.DAY_OF_YEAR, 7); // make sure in this month tmpX = _ltr ? x + (i * (_boxPaddingX + _boxWidth + _boxPaddingX)) + _boxPaddingX + (_boxWidth / 2) - (fm.stringWidth(_daysOfTheWeek[dayIndex]) / 2) : x - (i * (_boxPaddingX + _boxWidth + _boxPaddingX)) - _boxPaddingX - (_boxWidth / 2) - (fm.stringWidth(_daysOfTheWeek[dayIndex]) / 2); tmpY = y + _boxPaddingY + _boxHeight + _boxPaddingY + _boxPaddingY + fm.getAscent(); boolean flagged = _flaggedWeekDates[dayIndex]; boolean colored = _coloredWeekDates[dayIndex]; calculateBoundsForDay(_bounds, weekCal, true); drawDay(colored, flagged, false, g, _daysOfTheWeek[dayIndex], tmpX, tmpY); // if ((_dropShadowMask & WEEK_DROP_SHADOW) != 0) { // calculateBoundsForDay(_bounds,weekCal,true); // add shadow arg // drawDay(colored,flagged,false,g,_daysOfTheWeek[dayIndex], tmpX + 1, // tmpY + 1); // } if (_selectedWeekDays[dayIndex]) { paintSelectedDayBackground(g, _bounds.x, _bounds.y, _bounds.width, _bounds.height); } dayIndex++; if (dayIndex == 7) { dayIndex = 0; } } int lineOffset = 2; // Paint a line across bottom of days of the week. g.drawLine(_ltr ? x + 2 : x - 3, lineOffset + y + (_boxPaddingY * 3) + (_boxHeight * 2), _ltr ? x + _calendarWidth - 3 : x - _calendarWidth + 2, lineOffset + y + (_boxPaddingY * 3) + (_boxHeight * 2)); if ((_dropShadowMask & MONTH_LINE_DROP_SHADOW) != 0) { g.setColor(shadowColor); g.drawLine(_ltr ? x + 3 : x - 2, y + (_boxPaddingY * 3) + (_boxHeight * 2) + 1, _ltr ? x + _calendarWidth - 2 : x - _calendarWidth + 3, y + (_boxPaddingY * 3) + (_boxHeight * 2) + 1); g.setColor(getForeground()); } } // Check if the month to paint falls in the clip. _bounds.x = _startX + (_ltr ? column * (_calendarWidth + CALENDAR_SPACING) : -(column * (_calendarWidth + CALENDAR_SPACING) + _calendarWidth)); _bounds.y = _startY + row * (_calendarHeight + CALENDAR_SPACING); _bounds.width = _calendarWidth; _bounds.height = _calendarHeight; // Paint the month if it intersects the clip. If we don't move // the calendar forward a month as it would have if paintMonth // was called. if (_bounds.intersects(clip)) { paintMonth(g, column, row); } else { _cal.add(Calendar.MONTH, 1); } x += _ltr ? _calendarWidth + CALENDAR_SPACING : -(_calendarWidth + CALENDAR_SPACING); } y += _calendarHeight + CALENDAR_SPACING; } // Restore the calendar. _cal.setTimeInMillis(_firstDisplayedDate); if (g2 != null && _antiAlias) { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, oldAAValue); } }
From source file:FourByFour.java
/** * Render the current face set in the 2D window. *//* ww w. j av a2 s. c om*/ public void render2D(Graphics gc) { gc.setColor(background); gc.fillRect(0, 0, width, height); int id; int x, y; float begX; float begY; for (int l = 0; l < 3; l++) { begY = 28.0f + l * (5.f * 23.3f); for (int k = 0; k < 6; k++) { begX = 11.65f + k * (5.f * 11.65f); int count = 0; int face = l * 6 + k; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { x = (int) begX + i * 12; y = (int) begY + j * 12; id = faces[face][count + 2]; if (occupied[id] == HUMAN) { x -= 2; y -= 2; gc.setColor(red); gc.fillRect(x, y, 5, 5); } else if (occupied[id] == MACHINE) { x -= 2; y -= 2; gc.setColor(blue); gc.fillRect(x, y, 5, 5); } else { x -= 1; y -= 1; gc.setColor(gray); gc.fillRect(x, y, 2, 2); } if (highlight[face]) { gc.setColor(yellow); positions.setHighlight(faces[face][count + 2]); } count++; } } if (highlight[face]) gc.setColor(yellow); else gc.setColor(white); if ((face + 1) < 10) gc.drawString("Face " + (face + 1), (int) begX - 2, (int) begY + 60); else gc.drawString("Face " + (face + 1), (int) begX - 4, (int) begY + 60); } } }
From source file:lu.fisch.unimozer.Diagram.java
private void printHeaderFooter(Graphics g, PageFormat pageFormat, int page, String className) { int origPage = page + 1; // Add header g.setColor(Color.BLACK);/*from w w w.j a va2 s .c o m*/ int xOffset = (int) pageFormat.getImageableX(); int topOffset = (int) pageFormat.getImageableY() + 20; int bottom = (int) (pageFormat.getImageableY() + pageFormat.getImageableHeight()); // header line g.drawLine(xOffset, topOffset - 8, xOffset + (int) pageFormat.getImageableWidth(), topOffset - 8); // footer line g.drawLine(xOffset, bottom - 11, xOffset + (int) pageFormat.getImageableWidth(), bottom - 11); g.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 10)); Graphics2D gg = (Graphics2D) g; String pageString = "Page " + origPage; int tw = (int) gg.getFont().getStringBounds(pageString, gg.getFontRenderContext()).getWidth(); // footer text g.drawString(pageString, xOffset + (int) pageFormat.getImageableWidth() - tw, bottom - 2); //System.err.println("Printing: "+directoryName); if (directoryName != null) { g.setFont(new Font(g.getFont().getFontName(), Font.ITALIC, 10)); String filename = directoryName; if (!className.equals("")) filename += System.getProperty("file.separator") + className + ".java"; // header text g.drawString(filename, xOffset, bottom - 2); File f = new File(filename); //System.err.println("Printing: "+filename); if (f.exists()) { DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); java.util.Date date = new java.util.Date(); date.setTime(f.lastModified()); String myDate = dateFormat.format(date); int w = (int) gg.getFont().getStringBounds(myDate, gg.getFontRenderContext()).getWidth(); // header text g.drawString("File last modified on " + myDate, xOffset, topOffset - 10); } } }