MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / getLayerPane

Method getLayerPane

src/test/Test_Video.java:439–486  ·  view source on GitHub ↗
(Dimension dim)

Source from the content-addressed store, hash-verified

437 //private StateHelper helper;
438
439 private JPanel getLayerPane(Dimension dim) {
440 lockDim(label, dim);
441 label.setBounds(0, 0, dim.width, dim.height);
442
443 drawLayer = new JPanel() {
444 @Override
445 public void paintComponent(Graphics g) {
446 super.paintComponent(g); // takes care of the background clearing
447 g.setColor(Color.red);
448 for (int i = 0, n = points.size(); i < n; i++) {
449 Point p = points.get(i);
450 g.drawLine(p.x - 5, p.y, p.x + 5, p.y);
451 g.drawLine(p.x, p.y - 5, p.x, p.y + 5);
452 }
453 }
454 };
455 drawLayer.setBounds(0, 0, dim.width, dim.height);
456 drawLayer.setOpaque(false);
457 // drawLayer.setBackground(new Color(255,255,255,0));
458 // note -- setting this to opaque/{255 255 255 0} does not quite work as
459 // expected.
460 // rather than paint a white background over the image in Java, Java paints
461 // the default background color. This of course makes no sense; I consider it a
462 // Java bug.
463 //
464 drawLayer.putClientProperty("jscanvas", "true");
465
466 drawLayer.addMouseListener(new MouseAdapter() {
467
468 @Override
469 public void mouseClicked(MouseEvent e) {
470 System.out.println("Draw layer mouse click " + e.getX() + " " + e.getY());
471 points.add(new Point(e.getX(), e.getY()));
472 drawLayer.repaint();
473 }
474 });
475
476 layerPane = new JLayeredPane();
477 lockDim(layerPane, dim);
478 layerPane.add(drawLayer, JLayeredPane.PALETTE_LAYER);
479 layerPane.add(label, JLayeredPane.DEFAULT_LAYER);
480
481 JPanel p = new JPanel();
482 p.add(layerPane, BorderLayout.CENTER);
483 lockDim(p, dim);
484
485 return p;
486 }
487
488 private void lockDim(JComponent c, Dimension dim) {
489 c.setPreferredSize(dim);

Callers 1

Test_VideoMethod · 0.95

Calls 4

lockDimMethod · 0.95
addMouseListenerMethod · 0.80
setBoundsMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected