Java Code Examples for java.awt.Graphics2D#fill3DRect()

The following examples show how to use java.awt.Graphics2D#fill3DRect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FillingLabel.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    if (fillings == null || colors == null || fillings.length != colors.length) {
        return;
    }
    int h = getHeight() / fillings.length;
    if (h == 0) {
        return;
    }
    for (int i = 0; i < fillings.length; i++) {
        g2d.setColor(colors[i]);
        g2d.fill3DRect(0, i * h, (int) Math.rint(getWidth() * fillings[i]), h, true);
    }
    g2d.setColor(Color.LIGHT_GRAY);
    g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
    g2d.setColor(Color.BLACK);
    g2d.drawString(text, 1, getHeight() - 1);
}
 
Example 2
Source File: ColouredSquareMenuItem.java    From ontopia with Apache License 2.0 6 votes vote down vote up
/** Draw a coloured square at the end of the display. */
@Override
public void paintComponent(Graphics g) {
  super.paintComponent(g);

  Graphics2D g2 = (Graphics2D) g;

  Shape clip = g2.getClip();
  Rectangle bounds = clip.getBounds();
  double width = bounds.getWidth();
  double height = bounds.getHeight();

  g2.setColor(squareColor);
  g2.fill3DRect(((int) width - 25), 0, 25, (int) height, true);
  
  visibleIndicator.paintComponent(g);
}
 
Example 3
Source File: GraphPane.java    From Girinoscope with Apache License 2.0 6 votes vote down vote up
private void paintThresholdRule(Graphics2D g) {
    g.setColor(THRESHOLD_COLOR);
    Point point = toGraphArea(uMax, threshold);
    Stroke defaultStroke = g.getStroke();
    g.setStroke(DOTTED);
    g.drawLine(point.x, point.y, point.x + graphArea.width, point.y);
    g.setStroke(defaultStroke);

    Graphics2D gg = (Graphics2D) g.create();
    gg.translate(point.x, point.y);
    gg.rotate(Math.PI / 4);
    if (grabbedRule == Rule.THRESHOLD_RULE) {
        gg.fill3DRect(-4, -4, 9, 9, true);
    } else {
        gg.fill3DRect(-3, -3, 7, 7, true);
    }
}
 
Example 4
Source File: GraphPane.java    From Girinoscope with Apache License 2.0 6 votes vote down vote up
private void paintWaitDurationRule(Graphics2D g) {
    g.setColor(WAIT_DURATION_COLOR);
    Point point = toGraphArea(waitDuration, vMax);
    Stroke defaultStroke = g.getStroke();
    g.setStroke(DOTTED);
    g.drawLine(point.x, point.y, point.x, point.y + graphArea.height);
    g.setStroke(defaultStroke);

    Graphics2D gg = (Graphics2D) g.create();
    gg.translate(point.x, point.y);
    gg.rotate(Math.PI / 4);
    if (grabbedRule == Rule.WAIT_DURATION_RULE) {
        gg.fill3DRect(-4, -4, 9, 9, true);
    } else {
        gg.fill3DRect(-3, -3, 7, 7, true);
    }
}
 
Example 5
Source File: GraphRenderer.java    From energy2d with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void centerString(String s, Graphics2D g, int x, int y, Shape[] shapes) {
	int stringWidth = g.getFontMetrics().stringWidth(s);
	if (shapes == arrowButtons) {
		Color oldColor = g.getColor();
		g.setColor(Color.lightGray);
		ySelectButton.setBounds(x - stringWidth / 2 - 20, y - 10, stringWidth + 40, 16);
		g.fill3DRect(ySelectButton.x, ySelectButton.y, ySelectButton.width, ySelectButton.height, true);
		g.setColor(oldColor);
		int x2 = x - stringWidth / 2 - 15;
		arrowButtons[0].reset();
		arrowButtons[0].addPoint(x2 + 10, y - 6);
		arrowButtons[0].addPoint(x2 + 10, y);
		arrowButtons[0].addPoint(x2 + 4, y - 3);
		g.fillPolygon(arrowButtons[0]);
		x2 = x + stringWidth / 2 + 5;
		arrowButtons[1].reset();
		arrowButtons[1].addPoint(x2 + 4, y - 6);
		arrowButtons[1].addPoint(x2 + 4, y);
		arrowButtons[1].addPoint(x2 + 10, y - 3);
		g.fillPolygon(arrowButtons[1]);
	}
	g.drawString(s, x - stringWidth / 2, y);
}
 
Example 6
Source File: ScreenshotSaver.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    while (true) {
        if (mScreen != null) {
            try {
                Point2D.Double pos = MapPanel.getSingleton().getCurrentPosition();
                String first = "";
                first = "Zentrum: " + (int) Math.floor(pos.getX()) + "|" + (int) Math.floor(pos.getY());

                BufferedImage result = ImageUtils.createCompatibleBufferedImage(mScreen.getWidth(null), mScreen.getHeight(null), BufferedImage.OPAQUE);
                Graphics2D g2d = (Graphics2D) result.getGraphics();
                g2d.drawImage(mScreen, 0, 0, null);
                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
                FontMetrics fm = g2d.getFontMetrics();
                Rectangle2D firstBounds = fm.getStringBounds(first, g2d);
                String second = "Erstellt mit DS Workbench " + Constants.VERSION + Constants.VERSION_ADDITION;
                Rectangle2D secondBounds = fm.getStringBounds(second, g2d);
                g2d.setColor(Constants.DS_BACK_LIGHT);
                g2d.fill3DRect(0, (int) (result.getHeight() - firstBounds.getHeight() - secondBounds.getHeight() - 9), (int) (secondBounds.getWidth() + 6), (int) (firstBounds.getHeight() + secondBounds.getHeight() + 9), true);
                g2d.setColor(Color.BLACK);
                g2d.drawString(first, 3, (int) (result.getHeight() - firstBounds.getHeight() - secondBounds.getHeight() - firstBounds.getY() - 6));
                g2d.drawString(second, 3, (int) (result.getHeight() - secondBounds.getHeight() - secondBounds.getY() - 3));
                g2d.dispose();
                ImageIO.write(result, mTargetType, fTargetFile);
                DSWorkbenchMainFrame.getSingleton().fireMapShotDoneEvent();
            } catch (Exception e) {
                DSWorkbenchMainFrame.getSingleton().fireMapShotFailedEvent();
            }
            mScreen = null;
        }
        try {
            Thread.sleep(1000);
        } catch (Exception ignored) {
        }
    }
}
 
Example 7
Source File: ImageDrawBeveledRect.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{
	cfImageData im	= getImage( _session, argStruct );
	
	int x	= getNamedIntParam(argStruct, "x", Integer.MIN_VALUE );
	int y	= getNamedIntParam(argStruct, "y", Integer.MIN_VALUE );
	int w	= getNamedIntParam(argStruct, "width", Integer.MIN_VALUE );
	int h	= getNamedIntParam(argStruct, "height", Integer.MIN_VALUE );

	boolean bRaised	= getNamedBooleanParam(argStruct, "raised", false );
	boolean bFilled	= getNamedBooleanParam(argStruct, "filled", false );

	
	if ( x == Integer.MIN_VALUE )
		throwException(_session, "x not specifed" );
	
	if ( y == Integer.MIN_VALUE )
		throwException(_session, "y not specifed" );
	
	if ( w == Integer.MIN_VALUE )
		throwException(_session, "width not specifed" );
	
	if ( h == Integer.MIN_VALUE )
		throwException(_session, "height not specifed" );

	// Perform the operation
	Graphics2D g2 = im.createGraphics();
	
	if ( bFilled ){
		g2.fill3DRect( x, y, w, h, bRaised );	
	}else{
		g2.draw3DRect(x, y, w, h, bRaised );	
	}
	
	im.dispose(g2);
	return cfBooleanData.TRUE;
}
 
Example 8
Source File: JSoftGraph.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void paintBox(Graphics2D g,
              String   s,
              Color    bgCol,
              Color    fgCol,
              int      x,
              int      y,
              double   size,
              int minWidth, int minHeight,
              boolean bCenterX,
              boolean bCenterY) {
  Object oldComp = g.getComposite();
  g.setComposite((AlphaComposite)alphaHalf);

  String[] lines = split(s, "\n");

  int maxCols = 0;
  for(int i = 0; i <lines.length; i++) {
    if(lines[i].length() > maxCols) {
      maxCols = lines[i].length();
    }
  }

  Font font = g.getFont();

  g.setColor(bgCol);

  int w = Math.max(minWidth, font.getSize() * maxCols / 2 + 30);
  int h = Math.max(minHeight, (font.getSize() + 3) * lines.length + 10);

  if(bCenterX) {
    x -= w/2;
  }
  if(bCenterY) {
    y -= h/2;
  }

  g.fill3DRect(x, y,
               w, h,
               true);


  g.setColor(fgCol);

  x += 10;
  y += font.getSize() + 5;

  g.setComposite((AlphaComposite)oldComp);

  for(int i = 0; i <lines.length; i++) {
    int ix = lines[i].indexOf("\t");
    if(ix != -1) {
      g.drawString(lines[i].substring(0, ix),  x, y);
      g.drawString(lines[i].substring(ix + 1), x+font.getSize()*4, y);
    } else {
      g.drawString(lines[i], x, y);
    }
    y += font.getSize() + 3;
  }

}
 
Example 9
Source File: Fill3DRectEvent.java    From whyline with MIT License 2 votes vote down vote up
public void paint(Graphics2D g) {

	g.fill3DRect(getX(), getY(), getWidth(), getHeight(), getRaised());		

}