/** Creates and initializes the graphics object if required. */ private void ensureGraphics() { if (graphics == null) { graphics = (Graphics2D) parentComponent.getGraphics().create(); graphics.setColor(Color.WHITE); graphics.setXORMode(Color.RED); } } }
public void setFont(Font font) { super.setFont(font); Graphics g = this.getGraphics(); if (g != null) { FontMetrics fm = g.getFontMetrics(font); int height = fm.getHeight(); _rowHeight = height + height / 3; setRowHeight(_rowHeight); } }
update(getGraphics());
public void setFont(Font font) { super.setFont(font); Graphics g = this.getGraphics(); if (g != null) { FontMetrics fm = g.getFontMetrics(font); int height = fm.getHeight(); _rowHeight = height + height / 3; setRowHeight(_rowHeight); } }
/** * Creates and initializes the graphics object if required. */ private void ensureGraphics() { if (graphics == null) { graphics = (Graphics2D) parentComponent.getGraphics().create(); graphics.setColor(Color.WHITE); graphics.setXORMode(Color.RED); } }
public void setFont(Font font) { super.setFont(font); Graphics g = this.getGraphics(); if (g != null) { FontMetrics fm = g.getFontMetrics(font); int height = fm.getHeight(); _rowHeight = height + height / 3; setRowHeight(_rowHeight); } }
public void setFont(Font font) { super.setFont(font); Graphics g = this.getGraphics(); if (g != null) { FontMetrics fm = g.getFontMetrics(font); int height = fm.getHeight(); _rowHeight = height + height / 3; setRowHeight(_rowHeight); } }
/** * Check if any label text is obscured. */ private static boolean isTextObscured(JComponent c, String s) { Graphics g = c.getGraphics(); FontMetrics fm = g.getFontMetrics(c.getFont()); int sw = fm.stringWidth(s); return ( sw > c.getWidth() ); }
public void setFont(Font font) { super.setFont(font); Graphics g = this.getGraphics(); if (g != null) { FontMetrics fm = g.getFontMetrics(font); int height = fm.getHeight(); _rowHeight = height + height / 3; setRowHeight(_rowHeight); } }
public void setFont(Font font) { super.setFont(font); Graphics g = this.getGraphics(); if (g != null) { FontMetrics fm = g.getFontMetrics(font); int height = fm.getHeight(); _rowHeight = height + height / 3; setRowHeight(_rowHeight); } }
/** * Creates a graphics context for this component. This method will return * null if this component is currently not displayable. * * @return a graphics context for this component, or null if it has none */ public Graphics getGraphics() { if (frame != null) { return frame.getGraphics(); } else { return component.getGraphics(); } }
private void drawRect(JComponent c, int x, int y, boolean bx, boolean by) { _xdraw = x; _ydraw = y; int xmin = bx?min(_xbegin,_xdraw):-1; int xmax = bx?max(_xbegin,_xdraw):c.getWidth(); int ymin = by?min(_ybegin,_ydraw):-1; int ymax = by?max(_ybegin,_ydraw):c.getHeight(); Graphics g = c.getGraphics(); g.setColor(Color.RED); g.setXORMode(c.getBackground()); g.drawRect(xmin,ymin,xmax-xmin,ymax-ymin); g.dispose(); } }
public void mousePressed(MouseEvent e) { if(e.getX() < 1 || e.getX() > 256) return; if(e.getY() < 1 || e.getY() > 256) return; s = e.getX() - 1; if(s < 0) s = 0; else if(s > 255) s = 255; int y = e.getY() - 1; if(y < 0) y = 0; else if(y > 255) y = 255; mousePressed = true; b = 255 - y; paint(ColorSelector.this.getGraphics()); theColor = Color.getHSBColor(hue, (float)(s / 255.0), (float)(b / 255.0)); colorChanged(theColor); }
public void mouseDragged(MouseEvent e) { s = e.getX() - 1; if(s < 0) s = 0; else if(s > 255) s = 255; int y = e.getY() - 1; if(y < 0) y = 0; else if(y > 255) y = 255; b = 255 - y; paint(ColorSelector.this.getGraphics()); theColor = Color.getHSBColor(hue, (float)(s / 255.0), (float)(b / 255.0)); colorChanged(theColor); } }
/** Clears the current view. **/ synchronized public void clearView() { Rectangle r = getVisibleRect(); getGraphics().clearRect(r.x, r.y, r.width, r.height); }
/** * Retrieve the preferred size of the math component. * * @param c * the math component to measure * @return the preferred size. */ private Dimension getMathComponentSize(final JComponent c) { JEuclidView jEuclidView = this.getJeuclidView(c.getGraphics(), c); return this.calculatePreferredSize(c, jEuclidView); }
/** * Get the effective Graphics object for a component. */ public static Graphics getGraphics(JComponent comp) { Graphics g = comp.getGraphics(); if (g == null) { JFrame frame = getParentFrame(comp); if (frame != null) g = frame.getGraphics(); } return g; }
/** * Zooms the view to the given scale. * @param p anchor point for the zoom * @param scale scale for the zoom */ public void zoom(Point2D p, float scale) { Graphics2D g = ((Graphics2D) this.getViewJComponent().getGraphics()); double x = p.getX(), y = p.getY(); this.trsf.translate(x, y); this.trsf.scale(scale, scale); this.trsf.translate(-x, -y); g.clearRect(0, 0, getViewJComponent().getSize().width, getViewJComponent().getSize().height); g.setTransform(trsf); this.customPanel.setScaleValue(scale); this.customPanel.setPanValues(x, y); this.paint(g); }
/** * Pans the view provided in screen coordinates. * @param indx the amount to pan along the x-dimension, in pixel units * @param indy the amount to pan along the y-dimension, in pixel units */ public void pan(float indx, float indy) { this.trsf.translate(indx, indy); Graphics2D g = ((Graphics2D) this.getViewJComponent().getGraphics()); g.clearRect(0, 0, getViewJComponent().getSize().width, getViewJComponent().getSize().height); g.setTransform(trsf); Rectangle2D bounds = new Rectangle2D.Float( 0, 0, getViewJComponent().getWidth() + indx, getViewJComponent().getHeight() + indy); this.customPanel.setBounds(bounds); this.customPanel.setPanValues((double) indx, (double) indy); this.paint(g); }
@Override public void setLabel(ViewCanvas<?> view2d, Double xPos, Double yPos, String... labels) { if (labels == null || labels.length == 0) { reset(); } else { this.labels = labels; Font defaultFont = view2d == null ? FontTools.getFont12() : view2d.getFont(); Graphics2D g2d = view2d == null ? null : (Graphics2D) view2d.getJComponent().getGraphics(); FontRenderContext fontRenderContext = g2d == null ? new FontRenderContext(null, false, false) : g2d.getFontRenderContext(); updateBoundsSize(defaultFont, fontRenderContext); labelBounds = new Rectangle.Double(xPos + GROWING_BOUND, yPos + GROWING_BOUND, labelWidth + GROWING_BOUND, (labelHeight * labels.length) + GROWING_BOUND); GeomUtil.growRectangle(labelBounds, GROWING_BOUND); } }