diff --git a/src/main/java/info/istlab/Zemi01/RectangleFrame.java b/src/main/java/info/istlab/Zemi01/RectangleFrame.java index d70beec..0275eb1 100644 --- a/src/main/java/info/istlab/Zemi01/RectangleFrame.java +++ b/src/main/java/info/istlab/Zemi01/RectangleFrame.java @@ -24,7 +24,8 @@ rf.setVisible(true); JPopupMenu menu = new JPopupMenu(); - menu.add("cancel"); + JMenuItem cancelMI = new JMenuItem("(close menu)"); //なにもしないメニュー。メニューを閉じるためのメニュー + menu.add(cancelMI); menu.addSeparator(); JMenuItem captureMI = new JMenuItem("capture"); captureMI.addActionListener(e -> ScreenCapture.capture(rf.getInnerRect(), System.getProperty("user.dir") )); @@ -89,12 +90,16 @@ for (int i = 0; i < 4; i++) { rects[i] = new TransparentRect(this); + // rects[i].setFocusableWindowState(true); } layout(); } public void registerPopupMenu(JPopupMenu pM) { popupMenu = pM; + // for (int i = 0; i < 4; i++) { + // rects[i].addKeyListener( new EscapeCloseKeyListener(popupMenu)); + // } } public void layout() { @@ -106,8 +111,9 @@ rects[2].setSize(frameWidth, height - frameWidth * 2); rects[3].setLocation(location.x, location.y + height - frameWidth); rects[3].setSize(width, frameWidth); - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++){ rects[i].toFront(); + } } public void setLocation(int px, int py) { @@ -160,6 +166,7 @@ if (e.getButton() == MouseEvent.BUTTON3) { if (popupMenu != null) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); + // e.getComponent().requestFocus(); } // System.exit(0); } if (e.getComponent() == rects[3] && @@ -167,6 +174,7 @@ resizeMode = true; dim = new Dimension(width, height); } + // e.getComponent().requestFocusInWindow(); } @Override @@ -177,7 +185,7 @@ @Override public void mouseEntered(MouseEvent e) { - setBackground(new Color(0, 0, 0, 50)); + setBackground(new Color(0, 0, 0, 80)); if (e.getComponent() == rects[3] && e.getPoint().x > rects[3].getWidth() - frameWidth) { rects[3].setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR)); @@ -189,17 +197,41 @@ @Override public void mouseExited(MouseEvent e) { - setBackground(new Color(0, 0, 0, 10)); + setBackground(new Color(0, 0, 0, 30)); e.getComponent().setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } +/** + * 半透明の部品 + * + * 0000000000000000000000000 + * 11 22 + * 11 22 + * 11 22 + * 11 22 + * 3333333333333333333333333 + * + */ class TransparentRect extends JWindow { public TransparentRect(RectangleFrame parent) { - setBackground(new Color(0, 0, 0, 10)); + setBackground(new Color(0, 0, 0, 30)); addMouseListener(parent); addMouseMotionListener(parent); } } + +// class EscapeCloseKeyListener extends KeyAdapter { +// JPopupMenu target; +// public EscapeCloseKeyListener(JPopupMenu t){ +// target = t; +// } +// public void keyPressed(KeyEvent e){ +// System.out.println(e.getKeyCode()); +// if (e.getKeyCode() == KeyEvent.VK_ESCAPE){ +// target.setVisible(false); +// } +// } +// }