List of usage examples for java.awt Graphics getColor
public abstract Color getColor();
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
protected void paintItemLineBottleneck(int x1, int y1, int x2, Graphics g) { Color tempColor = g.getColor(); g.setColor(Color.red);//w w w. ja v a 2 s . com g.fillRoundRect(x1, y1 - 1, x2 - x1, 2, 1, 1); g.setColor(tempColor); }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * convenience method for internal use. paints a log item handle * visualization.//from www . j av a2 s.c om * * @param x * horizontal anchor coordinate of the handle * @param y * vertical anchor coordinate of the handle * @param g * the Graphics object used for painting */ protected void paintHighligtedItem(int x, int y, Graphics g, String shape) { Color color = g.getColor(); if (shape.equals(STR_NONE)) { return; } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DOT)) { if (!color.equals(Color.red)) g.setColor(Color.red); else g.setColor(Color.black); g.fillOval(x - 3, y - 3, 6, 6); g.setColor(color); g.fillOval(x - 2, y - 2, 4, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_BOX)) { if (!color.equals(Color.black)) g.setColor(Color.black); else g.setColor(Color.red); g.fillRect(x - 6, y - 6, 12, 12); g.setColor(color); g.fill3DRect(x - 5, y - 5, 10, 10, false); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_CIRCLE)) { if (!color.equals(Color.black)) g.setColor(Color.black); else g.setColor(Color.red); g.fillOval(x - 6, y - 6, 13, 13); g.setColor(color); g.fillOval(x - 5, y - 5, 11, 11); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_RHOMBUS)) { int rhombX[] = { x, x - 5, x, x + 5 }; int rhombY[] = { y - 5, y, y + 5, y }; g.fillPolygon(rhombX, rhombY, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_TRIANGLE)) { int triX[] = { x, x - 5, x + 5 }; int triY[] = { y + 5, y - 5, y - 5 }; g.fillPolygon(triX, triY, 3); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_ROUND_BOX)) { if (!color.equals(Color.black)) g.setColor(Color.black); else g.setColor(Color.red); g.fillRoundRect(x - 6, y - 6, 13, 13, 2, 2); g.setColor(color); g.fillRoundRect(x - 5, y - 5, 10, 10, 2, 2); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_BOX)) { g.drawRect(x - 5, y - 5, 10, 10); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_CIRCLE)) { if (!color.equals(Color.black)) g.setColor(Color.black); else g.setColor(Color.red); g.fillOval(x - 6, y - 6, 13, 13); g.setColor(color); g.drawOval(x - 5, y - 5, 11, 11); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_RHOMBUS)) { int rhombX[] = { x, x - 5, x, x + 5 }; int rhombY[] = { y - 5, y, y + 5, y }; g.drawPolygon(rhombX, rhombY, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_TRIANGLE)) { int triX[] = { x, x - 5, x + 5 }; int triY[] = { y + 5, y - 5, y - 5 }; g.drawPolygon(triX, triY, 3); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_ROUND_BOX)) { g.drawRoundRect(x - 5, y - 5, 10, 10, 2, 2); } }
From source file:com.projity.contrib.calendar.JXXMonthView.java
private void drawDay(boolean colored, boolean flagged, boolean today, Graphics g, String text, int x, int y) { Color defaultColor = g.getColor(); Font oldFont = getFont();/*from ww w .j av a 2s.c o m*/ if (colored) { g.setColor(Color.LIGHT_GRAY); g.fillRect(_bounds.x, _bounds.y, _bounds.width, _bounds.height); g.setColor(defaultColor); } if (today) g.setColor(Color.BLUE); if (flagged) { g.setColor(Color.RED); g.setFont(_derivedFont); } g.drawString(text, x, y); g.setColor(defaultColor); g.setFont(oldFont); }
From source file:com.jcraft.weirdx.DDXWindowImp.java
public final Graphics getGraphics(GC gc, int mask) { if (!isVisible()) { return null; }/*from w ww . jav a 2 s. c o m*/ if (offg == null) allocImage(); Graphics graphics = offg; if ((mask & GC.GCSubwindowMode) != 0 && (gc.attr & GC.IncludeInferiors) != 0) { graphics = getGraphics(); window.currentGC = null; } else { if (gc == window.currentGC && gc.time == window.gctime && (mask & ~window.gmask) == 0) { //System.out.println("DDXWindow skip"); return graphics; } window.gctime = gc.time; window.currentGC = gc; window.gmask = mask; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec != null) { graphics = offg; } if (rec == null || (rec.x == 0 && rec.y == 0 && rec.width == window.width && rec.height == window.height)) { // return graphics; } else { graphics.setClip(rec.x, rec.y, rec.width, rec.height); } } if ((mask & GC.GCFunction) != 0) { Color color = window.getColormap().getColor(gc.fgPixel); if (gc.function == GC.GXxor) { window.gmask &= ~GC.GCFunction; graphics.setXORMode(new Color((color.getRGB() ^ graphics.getColor().getRGB()) & 0xffffff)); } else if (gc.function == GC.GXinvert) { window.gmask &= ~GC.GCFunction; graphics.setXORMode(window.screen.defaultColormap.getColor(window.background.pixel)); } else { graphics.setColor(color); } } if ((mask & GC.GCFont) != 0) { XFont font = gc.font; graphics.setFont(font.getFont()); } if ((mask & GC.GCLineWidth) != 0 || (mask & GC.GCLineStyle) != 0 || (mask & GC.GCCapStyle) != 0 || (mask & GC.GCJoinStyle) != 0) { } return graphics; }
From source file:com.projity.contrib.calendar.JXXMonthView.java
/** * {@inheritDoc}//from w w w. j a v a 2s . c o 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:com.jcraft.weirdx.XPixmap.java
Graphics getGraphics(GC gc, int mask) { Graphics graphics = imgg; if (gc == currentGC && gc.time == gctime && (mask & ~gmask) == 0) { return graphics; }//from w w w . j a v a 2s. c o m gctime = gc.time; currentGC = gc; gmask = mask; if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { return graphics; } graphics.setClip(rec.x, rec.y, rec.width, rec.height); } if ((mask & GC.GCFunction) != 0) { Color color = getColormap().getColor(gc.fgPixel); if (gc.function == GC.GXxor) { gmask &= ~GC.GCFunction; graphics.setXORMode(new Color((color.getRGB() ^ graphics.getColor().getRGB()) & 0xffffff)); } else if (gc.function == GC.GXinvert) { //System.out.println("Pimxpa: GXinvert"); } else { graphics.setColor(color); } } if ((mask & GC.GCFont) != 0) { XFont font = gc.font; graphics.setFont(font.getFont()); } if ((mask & GC.GCLineWidth) != 0 || (mask & GC.GCLineStyle) != 0 || (mask & GC.GCCapStyle) != 0 || (mask & GC.GCJoinStyle) != 0) { } return graphics; }
From source file:edu.ku.brc.services.mapping.LocalityMapper.java
/** * Grabs a new map from the web service and appropriately adorns it * with labels and markers./* www. j a v a 2s .com*/ * * @return a map image as an icon * @throws HttpException a network error occurred while grabbing the map from the service * @throws IOException a network error occurred while grabbing the map from the service */ protected Icon grabNewMap() throws HttpException, IOException { recalculateBoundingBox(); if (!cacheValid) { // Image mapImage = getMapFromService("mapus.jpl.nasa.gov", // "/wms.cgi?request=GetMap&srs=EPSG:4326&format=image/png&styles=visual", // "global_mosaic", // mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth); // // Image overlayImage = getMapFromService("129.237.201.132", // "/cgi-bin/mapserv?map=/var/www/maps/specify.map&service=WMS&request=GetMap&srs=EPSG:4326&version=1.3.1&format=image/png&transparent=true", // "states,rivers", // mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth); Image mapImage = getMapFromService("lifemapper.org", //$NON-NLS-1$ "/ogc?map=specify.map&service=WMS&request=GetMap&srs=EPSG:4326&version=1.3.1&STYLES=&format=image/png&transparent=TRUE", //$NON-NLS-1$ "global_mosaic,states,rivers", //$NON-NLS-1$ mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth); mapIcon = new ImageIcon(mapImage); // overlayIcon = new ImageIcon(overlayImage); cacheValid = true; mapWidth = mapIcon.getIconWidth(); mapHeight = mapIcon.getIconHeight(); if (mapWidth < 0 || mapHeight < 0) { throw new IOException("Request for map failed. Received map has negative width or height."); //$NON-NLS-1$ } mapLatRange = mapMaxLat - mapMinLat; mapLongRange = mapMaxLong - mapMinLong; pixelPerLatRatio = mapHeight / mapLatRange; pixelPerLongRatio = mapWidth / mapLongRange; for (int i = 0; i < mapLocations.size(); ++i) { MapLocationIFace loc = mapLocations.get(i); Point iconLoc = determinePixelCoordsOfMapLocationIFace(loc); markerLocations.set(i, iconLoc); } cacheValid = true; } Icon icon = new Icon() { public void paintIcon(Component c, Graphics g, int x, int y) { // this helps keep the labels inside the map g.setClip(x, y, mapWidth, mapHeight); // log the x and y for the MouseMotionListener mostRecentPaintedX = x; mostRecentPaintedY = y; Point currentLocPoint = null; if (currentLoc != null) { currentLocPoint = determinePixelCoordsOfMapLocationIFace(currentLoc); } mapIcon.paintIcon(c, g, x, y); // overlayIcon.paintIcon(c, g, x, y); Point lastLoc = null; for (int i = 0; i < mapLocations.size(); ++i) { Point markerLoc = markerLocations.get(i); String label = labels.get(i); boolean current = (currentLoc != null) && markerLoc.equals(currentLocPoint); if (markerLoc == null) { log.error("A marker location is null"); //$NON-NLS-1$ continue; } if (!pointIsOnMapIcon(x + markerLoc.x, y + markerLoc.y)) { log.error("A marker location is off the map"); //$NON-NLS-1$ continue; } if (showArrows && lastLoc != null) { int x1 = x + lastLoc.x; int y1 = y + lastLoc.y; int x2 = x + markerLoc.x; int y2 = y + markerLoc.y; Color origColor = g.getColor(); if (current && !animationInProgress) { g.setColor(getCurrentLocColor()); } else { g.setColor(arrowColor); } GraphicsUtils.drawArrow(g, x1, y1, x2, y2, 2, 2); g.setColor(origColor); } if (current) { currentLocMarker.paintIcon(c, g, markerLoc.x + x, markerLoc.y + y); } else { marker.paintIcon(c, g, markerLoc.x + x, markerLoc.y + y); } if (label != null) { Color origColor = g.getColor(); FontMetrics fm = g.getFontMetrics(); int length = fm.stringWidth(label); g.setColor(Color.WHITE); g.fillRect(markerLoc.x + x - (length / 2), markerLoc.y + y - (fm.getHeight() / 2), length, fm.getHeight()); g.setColor(labelColor); GraphicsUtils.drawCenteredString(label, g, markerLoc.x + x, markerLoc.y + y); g.setColor(origColor); } lastLoc = markerLoc; } if (showArrowAnimations && animationInProgress) { int startIndex = mapLocations.indexOf(animStartLoc); int endIndex = mapLocations.indexOf(animEndLoc); if (startIndex != -1 && endIndex != -1) { Point startPoint = markerLocations.get(startIndex); Point endPoint = markerLocations.get(endIndex); Point arrowEnd = GraphicsUtils.getPointAlongLine(startPoint, endPoint, percent); Color orig = g.getColor(); g.setColor(getCurrentLocColor()); GraphicsUtils.drawArrow(g, startPoint.x + x, startPoint.y + y, arrowEnd.x + x, arrowEnd.y + y, 5, 3); g.setColor(orig); } } } public int getIconWidth() { return mapWidth; } public int getIconHeight() { return mapHeight; } }; return icon; }