List of usage examples for java.awt Graphics drawLine
public abstract void drawLine(int x1, int y1, int x2, int y2);
(x1, y1)
and (x2, y2)
in this graphics context's coordinate system. From source file:AppletMenuBarDemo.java
/** * This method is called to draw tell the component to redraw itself. If we * were implementing a Swing component, we'd override paintComponent() * instead//w w w . j ava2 s. c om */ public void paint(Graphics g) { if (remeasure) measure(); // Remeasure everything first, if needed // Figure out Y coordinate to draw at Dimension size = getSize(); int baseline = size.height - margins.bottom - descent; // Set the font to draw with g.setFont(getFont()); // Loop through the labels int nummenus = labels.size(); for (int i = 0; i < nummenus; i++) { // Set the drawing color. Highlight the current item if ((i == highlightedItem) && (highlightColor != null)) g.setColor(getHighlightColor()); else g.setColor(getForeground()); // Draw the menu label at the position computed in measure() g.drawString((String) labels.elementAt(i), startPositions[i], baseline); } // Now draw a groove at the bottom of the menubar. Color bg = getBackground(); g.setColor(bg.darker()); g.drawLine(0, size.height - 2, size.width, size.height - 2); g.setColor(bg.brighter()); g.drawLine(0, size.height - 1, size.width, size.height - 1); }
From source file:net.sf.taverna.t2.activities.spreadsheet.views.SpreadsheetImportConfigView.java
/** * Adds a light gray or etched border to the top or bottom of a JComponent. * * @param component//from w w w .j a va 2s .c o m */ protected void addDivider(JComponent component, final int position, final boolean etched) { component.setBorder(new Border() { private final Color borderColor = new Color(.6f, .6f, .6f); public Insets getBorderInsets(Component c) { if (position == SwingConstants.TOP) { return new Insets(5, 0, 0, 0); } else { return new Insets(0, 0, 5, 0); } } public boolean isBorderOpaque() { return false; } public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if (position == SwingConstants.TOP) { if (etched) { g.setColor(borderColor); g.drawLine(x, y, x + width, y); g.setColor(Color.WHITE); g.drawLine(x, y + 1, x + width, y + 1); } else { g.setColor(Color.LIGHT_GRAY); g.drawLine(x, y, x + width, y); } } else { if (etched) { g.setColor(borderColor); g.drawLine(x, y + height - 2, x + width, y + height - 2); g.setColor(Color.WHITE); g.drawLine(x, y + height - 1, x + width, y + height - 1); } else { g.setColor(Color.LIGHT_GRAY); g.drawLine(x, y + height - 1, x + width, y + height - 1); } } } }); }
From source file:uk.co.modularaudio.mads.base.soundfile_player.ui.SoundfilePlayerWaveOverviewUiJComponent.java
@Override public void paintComponent(final Graphics g) { // log.trace("WaveOverview paint() called"); final int xWaveOffset = WAVE_OVERVIEW_BORDER_PIXELS + WAVE_OVERVIEW_INTRO_PIXELS; g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_BACKGROUND_COLOR); g.fillRect(1, 1, lastWidth - 1, lastHeight - 1); g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_BORDER_COLOR); g.drawRect(0, 0, lastWidth, lastHeight); if (staticThumbnail != null) { g.drawImage(staticThumbnail, xWaveOffset, WAVE_OVERVIEW_BORDER_PIXELS, null); } else {/*w ww . ja va 2 s . c om*/ g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_WAVE_BG_COLOR); g.fillRect(xWaveOffset, WAVE_OVERVIEW_BORDER_PIXELS, lastOverviewWidth, lastOverviewHeight); if (internalPercentComplete >= 0) { g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_WAVE_FG_COLOR); final int yOffset = WAVE_OVERVIEW_BORDER_PIXELS + (lastOverviewHeight / 2); final int widthOfLine = (lastOverviewWidth * internalPercentComplete) / 100; g.drawLine(xWaveOffset, yOffset, xWaveOffset + widthOfLine, yOffset); } } g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_CURRENT_POSITION_COLOUR); final int actualPos = xWaveOffset + desiredNormalisedPositionPixel; g.drawLine(actualPos, WAVE_OVERVIEW_BORDER_PIXELS, actualPos, lastOverviewHeight); displayedNormalisedPositionPixel = desiredNormalisedPositionPixel; }
From source file:uk.co.modularaudio.mads.base.oscilloscope.ui.OscilloscopeDisplayUiJComponent.java
private void plotAllDataValues(final Graphics g, final int plotWidth, final int plotStart, final int plotHeight, final int numSamplesInBuffer, final float[] dataToPlot, final boolean firstMags) { previousX = -1;/*from w w w. j a v a 2 s .c om*/ previousY = -1; for (int i = 0; i < numSamplesInBuffer; i++) { final double pixelIndex = ((float) i / numSamplesInBuffer) * plotWidth; final int intPixelIndex = (int) pixelIndex; final float origVal = dataToPlot[i]; final float scaledVal = origVal / (firstMags ? maxMag0 : maxMag1); // log.debug("MaxMag0 is " + maxMag0); // Curval goes from +1.0 to -1.0 // We need it to go from 0 to height final int actualY = (int) (((scaledVal + 1.0) / 2.0) * (plotHeight - 1)); final int curX = SCALE_WIDTH + intPixelIndex; final int curY = (plotHeight - 1) - actualY; if (curX != previousX || curY != previousY) { if (previousX != -1) { g.drawLine(previousX, previousY, curX, curY); } previousX = curX; previousY = curY; } final float absY = Math.abs(origVal); if (firstMags) { if (absY > newMaxMag0) { newMaxMag0 = absY; } } else { if (absY > newMaxMag1) { newMaxMag1 = absY; } } } }
From source file:components.Rule.java
protected void paintComponent(Graphics g) { Rectangle drawHere = g.getClipBounds(); // Fill clipping area with dirty brown/orange. g.setColor(new Color(230, 163, 4)); g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); // Do the ruler labels in a small font that's black. g.setFont(new Font("SansSerif", Font.PLAIN, 10)); g.setColor(Color.black);/*w w w . jav a 2 s. c o m*/ // Some vars we need. int end = 0; int start = 0; int tickLength = 0; String text = null; // Use clipping bounds to calculate first and last tick locations. if (orientation == HORIZONTAL) { start = (drawHere.x / increment) * increment; end = (((drawHere.x + drawHere.width) / increment) + 1) * increment; } else { start = (drawHere.y / increment) * increment; end = (((drawHere.y + drawHere.height) / increment) + 1) * increment; } // Make a special case of 0 to display the number // within the rule and draw a units label. if (start == 0) { text = Integer.toString(0) + (isMetric ? " cm" : " in"); tickLength = 10; if (orientation == HORIZONTAL) { g.drawLine(0, SIZE - 1, 0, SIZE - tickLength - 1); g.drawString(text, 2, 21); } else { g.drawLine(SIZE - 1, 0, SIZE - tickLength - 1, 0); g.drawString(text, 9, 10); } text = null; start = increment; } // ticks and labels for (int i = start; i < end; i += increment) { if (i % units == 0) { tickLength = 10; text = Integer.toString(i / units); } else { tickLength = 7; text = null; } if (tickLength != 0) { if (orientation == HORIZONTAL) { g.drawLine(i, SIZE - 1, i, SIZE - tickLength - 1); if (text != null) g.drawString(text, i - 3, 21); } else { g.drawLine(SIZE - 1, i, SIZE - tickLength - 1, i); if (text != null) g.drawString(text, 9, i + 3); } } } }
From source file:org.trianacode.gui.main.imp.TrianaTask.java
protected void paintProcessProgress(Graphics g) { if (processled) { Color col = ColorManager.getColor(PROGRESS_ELEMENT, getTaskInterface()); if (col.getAlpha() > 0) { Dimension size = getSize(); int width = (int) (size.width * PROCESS_LED_WIDTH_FACTOR); int height = (int) (size.height * PROCESS_LED_HEIGHT_FACTOR); int left = (size.width / 2) - (width / 2); int top = 0; if (getTaskInterface() instanceof TaskGraph) { int processCount = (getStartProcessCount() % 3); left = (size.width / 2) - (width / 2 * 3) + (processCount * width); }/*from ww w . ja v a 2 s . com*/ g.setColor(col); g.fill3DRect(left, top, width, height, true); left += width + 1; int offset = height / 2; for (int count = 0; (count < getStartProcessCount() - getStopProcessCount() - 1) && (left + height < size.width); count++) { g.drawLine(left, top + offset, left + height, top + offset); g.drawLine(left + offset, top, left + offset, top + height); left += height + 1; } } } }
From source file:de.tor.tribes.ui.views.DSWorkbenchReportFrame.java
@Override public void actionPerformed(ActionEvent e) { ReportTableTab activeTab = getActiveTab(); if (e.getActionCommand() != null && activeTab != null) { if (e.getActionCommand().equals("Copy")) { activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD); } else if (e.getActionCommand().equals("BBCopy")) { activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.CLIPBOARD_BB); } else if (e.getActionCommand().equals("Cut")) { activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD); } else if (e.getActionCommand().equals("Paste")) { activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD); } else if (e.getActionCommand().equals("Delete")) { activeTab.deleteSelection(true); } else 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); g.dispose();//from w w w .j ava 2 s . com 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.getReportTable().getColumnCount(); i++) { TableColumnExt col = activeTab.getReportTable().getColumnExt(i); if (col.isVisible()) { if (!col.getTitle().equals("Status") && !col.getTitle().equals("Typ") && !col.getTitle().equals("Sonstiges")) { model.addElement(col.getTitle()); } } } jXColumnList.setModel(model); jXColumnList.setSelectedIndex(0); jxSearchPane.setVisible(true); } } }
From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java
/** * Write a blank thumbnail image so user doesn't see the broken icon. *//* w ww . j av a2 s . co m*/ private void writePlaceholderThumbnailImage(OutputStream os, int placeholderSize) throws IOException { // Make the image a bit bigger to account for the empty space around the generated image. // If we can find a way to remove this empty space, we don't need to make the chart bigger. BufferedImage buffer = new BufferedImage(placeholderSize + 16, placeholderSize + 9, BufferedImage.TYPE_INT_RGB); Graphics g = buffer.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, placeholderSize + 16, placeholderSize + 9); g.setColor(Color.gray); g.drawLine(8, placeholderSize + 5, placeholderSize + 8, placeholderSize + 5); // x-axis g.drawLine(8, 5, 8, placeholderSize + 5); // y-axis g.setColor(Color.black); Font font = g.getFont(); g.setFont(new Font(font.getName(), font.getStyle(), 8)); g.drawString("N/A", 9, placeholderSize); ImageIO.write(buffer, "png", os); }
From source file:biogenesis.Organism.java
/** * Draws this organism to a graphics context. * The organism is drawn at its position in the world. * //from w w w . j av a2 s. com * @param g The graphics context to draw to. */ public void draw(Graphics g) { int i; if (_framesColor > 0) { // Draw all the organism in the same color g.setColor(_color); _framesColor--; for (i = 0; i < _segments; i++) g.drawLine(x1[i] + _centerX, y1[i] + _centerY, x2[i] + _centerX, y2[i] + _centerY); } else { if (alive) { for (i = 0; i < _segments; i++) { g.setColor(_segColor[i]); g.drawLine(x1[i] + _centerX, y1[i] + _centerY, x2[i] + _centerX, y2[i] + _centerY); } } else { g.setColor(Utils.ColorBROWN); for (i = 0; i < _segments; i++) { g.drawLine(x1[i] + _centerX, y1[i] + _centerY, x2[i] + _centerX, y2[i] + _centerY); } } } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
private void xorConnection(AnnotationObject selection, Point start_point, Point end_point) { Graphics g = getGraphics(); g.setXORMode(Color.white);// www .ja v a 2s . c o m g.setColor(Color.gray); Rectangle rect = rectangles_complete.get(selection); Point2D peak = dataToScreenCoords(selection.getPeakPoint()); // select anchor Point2D anchor = computeAnchor(rect, end_point, peak); // draw connection g.drawLine((int) anchor.getX(), (int) anchor.getY(), (int) end_point.getX(), (int) end_point.getY()); g.drawLine((int) end_point.getX(), (int) end_point.getY(), (int) peak.getX(), (int) peak.getY()); }