/* * This file is part of Arduino. * * Arduino is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * As a special exception, you may use this file as part of a free software * library without restriction. Specifically, if other files instantiate * templates or use macros or inline functions from this file, or you compile * this file and link it with other files to produce an executable, this * file does not by itself cause the resulting executable to be covered by * the GNU General Public License. This exception does not however * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * * Copyright 2015 Arduino LLC (http://www.arduino.cc/) */ package cc.arduino.view; import processing.app.Base; import processing.app.BaseNoGui; import javax.swing.*; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import java.awt.*; import java.awt.event.*; import java.nio.file.Paths; public class NotificationPopup extends JDialog { private final ComponentAdapter parentMovedListener; public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener, String message) { super(parent, false); initComponents(); updateLocation(parent); parentMovedListener = new ComponentAdapter() { @Override public void componentMoved(ComponentEvent e) { updateLocation(parent); } }; parent.addComponentListener(parentMovedListener); text.setText("
" + message + ""); text.addHyperlinkListener(hyperlinkListener); text.addHyperlinkListener(e -> { if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) { return; } close(); }); addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { parent.removeComponentListener(parentMovedListener); } }); Base.registerWindowCloseKeys(getRootPane(), e -> close()); MouseAdapter closeOnClick = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { close(); } }; addMouseListener(closeOnClick); text.addMouseListener(closeOnClick); icon.addMouseListener(closeOnClick); } private void updateLocation(Frame parent) { Point parentLocation = parent.getLocation(); int parentX = Double.valueOf(parentLocation.getX()).intValue(); int parentY = Double.valueOf(parentLocation.getY()).intValue(); setLocation(parentX, parentY + parent.getHeight() - getHeight()); } public void close() { dispatchEvent(new WindowEvent(NotificationPopup.this, WindowEvent.WINDOW_CLOSING)); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") //