mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +01:00
Notification pop-up is now correctly scaled
This commit is contained in:
parent
4659c6f985
commit
57c6d096f6
@ -83,11 +83,11 @@ public class ContributionsSelfCheck extends TimerTask {
|
||||
|
||||
String text;
|
||||
if (updatableLibraries > 0 && updatablePlatforms <= 0) {
|
||||
text = I18n.format(tr("<br/>Update available for some of your {0}libraries{1}"), "<a href=\"http://librarymanager\">", "</a>");
|
||||
text = I18n.format(tr("Updates available for some of your {0}libraries{1}"), "<a href=\"http://librarymanager\">", "</a>");
|
||||
} else if (updatableLibraries <= 0 && updatablePlatforms > 0) {
|
||||
text = I18n.format(tr("<br/>Update available for some of your {0}boards{1}"), "<a href=\"http://boardsmanager\">", "</a>");
|
||||
text = I18n.format(tr("Updates available for some of your {0}boards{1}"), "<a href=\"http://boardsmanager\">", "</a>");
|
||||
} else {
|
||||
text = I18n.format(tr("<br/>Update available for some of your {0}boards{1} and {2}libraries{3}"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>");
|
||||
text = I18n.format(tr("Updates available for some of your {0}boards{1} and {2}libraries{3}"), "<a href=\"http://boardsmanager\">", "</a>", "<a href=\"http://librarymanager\">", "</a>");
|
||||
}
|
||||
|
||||
if (cancelled) {
|
||||
|
@ -1,89 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="2"/>
|
||||
<Property name="alwaysOnTop" type="boolean" value="true"/>
|
||||
<Property name="focusable" type="boolean" value="false"/>
|
||||
<Property name="focusableWindowState" type="boolean" value="false"/>
|
||||
<Property name="undecorated" type="boolean" value="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[350, 70]"/>
|
||||
</Property>
|
||||
<Property name="resizable" type="boolean" value="false"/>
|
||||
<Property name="size" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[350, 70]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,0,0,0,2,14"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="icon">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="new ImageIcon(Paths.get(BaseNoGui.getContentFile("lib").getAbsolutePath(), "arduino_small.png").toFile().getAbsolutePath())" type="code"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
|
||||
<AbsoluteConstraints x="10" y="10" width="50" height="50"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="javax.swing.JEditorPane" name="text">
|
||||
<Properties>
|
||||
<Property name="editable" type="boolean" value="false"/>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
|
||||
<LineBorder roundedCorners="true" thickness="0"/>
|
||||
</Border>
|
||||
</Property>
|
||||
<Property name="contentType" type="java.lang.String" value="text/html" noResource="true"/>
|
||||
<Property name="opaque" type="boolean" value="false"/>
|
||||
</Properties>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
|
||||
<AbsoluteConstraints x="70" y="10" width="270" height="50"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="closeButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="new ImageIcon(Paths.get(BaseNoGui.getContentFile("lib").getAbsolutePath(), "theme", "close.png").toFile().getAbsolutePath())" type="code"/>
|
||||
</Property>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="null"/>
|
||||
</Property>
|
||||
<Property name="borderPainted" type="boolean" value="false"/>
|
||||
<Property name="hideActionText" type="boolean" value="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="closeButtonActionPerformed"/>
|
||||
</Events>
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
|
||||
<AbsoluteConstraints x="328" y="0" width="22" height="22"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
@ -29,26 +29,80 @@
|
||||
|
||||
package cc.arduino.view;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.BaseNoGui;
|
||||
import java.awt.Color;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.WindowConstants;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import processing.app.Theme;
|
||||
import static processing.app.Theme.scale;
|
||||
|
||||
public class NotificationPopup extends JDialog {
|
||||
|
||||
private final ComponentAdapter parentMovedListener;
|
||||
|
||||
public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener, String message) {
|
||||
public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener,
|
||||
String message) {
|
||||
super(parent, false);
|
||||
initComponents();
|
||||
setLayout(new FlowLayout());
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setAlwaysOnTop(true);
|
||||
setUndecorated(true);
|
||||
setResizable(false);
|
||||
|
||||
Image arduino = Theme.getLibImage("arduino", this, scale(40), scale(40));
|
||||
JLabel arduinoIcon = new JLabel(new ImageIcon(arduino));
|
||||
add(arduinoIcon);
|
||||
|
||||
JEditorPane text = new JEditorPane();
|
||||
text.setBorder(new LineBorder(new Color(0, 0, 0), 0, true));
|
||||
text.setContentType("text/html"); // NOI18N
|
||||
text.setOpaque(false);
|
||||
text.setEditable(false);
|
||||
text.setText("<html><body style=\"font-family:sans-serif; font-size: "
|
||||
+ scale(14) + ";\"> " + message + " </body></html>");
|
||||
text.addHyperlinkListener(hyperlinkListener);
|
||||
add(text);
|
||||
|
||||
Image close = Theme.getThemeImage("close", this, scale(22), scale(22));
|
||||
JButton closeButton = new JButton(new ImageIcon(close));
|
||||
closeButton.setBorder(null);
|
||||
closeButton.setBorderPainted(false);
|
||||
closeButton.setHideActionText(true);
|
||||
closeButton.setOpaque(false);
|
||||
closeButton.setBackground(new Color(0, 0, 0, 0));
|
||||
add(closeButton);
|
||||
|
||||
MouseAdapter closeOnClick = new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
close();
|
||||
}
|
||||
};
|
||||
addMouseListener(closeOnClick);
|
||||
text.addMouseListener(closeOnClick);
|
||||
arduinoIcon.addMouseListener(closeOnClick);
|
||||
closeButton.addMouseListener(closeOnClick);
|
||||
|
||||
pack();
|
||||
|
||||
updateLocation(parent);
|
||||
parentMovedListener = new ComponentAdapter() {
|
||||
ComponentAdapter parentMovedListener = new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
updateLocation(parent);
|
||||
@ -60,35 +114,12 @@ public class NotificationPopup extends JDialog {
|
||||
}
|
||||
};
|
||||
parent.addComponentListener(parentMovedListener);
|
||||
|
||||
text.setText("<html><body style=\"font-family:sans-serif;font-size:12pt\">" + message + "</body></html>");
|
||||
|
||||
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) {
|
||||
@ -100,87 +131,20 @@ public class NotificationPopup extends JDialog {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
dispatchEvent(new WindowEvent(NotificationPopup.this, WindowEvent.WINDOW_CLOSING));
|
||||
dispatchEvent(new WindowEvent(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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
icon = new javax.swing.JLabel();
|
||||
text = new javax.swing.JEditorPane();
|
||||
closeButton = new javax.swing.JButton();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setAlwaysOnTop(true);
|
||||
setFocusable(false);
|
||||
setFocusableWindowState(false);
|
||||
setUndecorated(true);
|
||||
setPreferredSize(new java.awt.Dimension(350, 70));
|
||||
setResizable(false);
|
||||
setSize(new java.awt.Dimension(350, 70));
|
||||
getContentPane().setLayout(null);
|
||||
|
||||
icon.setIcon(new ImageIcon(Paths.get(BaseNoGui.getContentFile("lib").getAbsolutePath(), "arduino_small.png").toFile().getAbsolutePath()));
|
||||
getContentPane().add(icon);
|
||||
icon.setBounds(10, 10, 50, 50);
|
||||
|
||||
text.setEditable(false);
|
||||
text.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 0, true));
|
||||
text.setContentType("text/html"); // NOI18N
|
||||
text.setOpaque(false);
|
||||
getContentPane().add(text);
|
||||
text.setBounds(70, 10, 270, 50);
|
||||
|
||||
closeButton.setIcon(new ImageIcon(Paths.get(BaseNoGui.getContentFile("lib").getAbsolutePath(), "theme", "close.png").toFile().getAbsolutePath()));
|
||||
closeButton.setBorder(null);
|
||||
closeButton.setBorderPainted(false);
|
||||
closeButton.setHideActionText(true);
|
||||
closeButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
closeButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
getContentPane().add(closeButton);
|
||||
closeButton.setBounds(328, 0, 22, 22);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
|
||||
close();
|
||||
}//GEN-LAST:event_closeButtonActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
|
||||
/* Create and display the dialog */
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
NotificationPopup dialog = new NotificationPopup(new JFrame(), System.out::println, "<a href='arduinoide://boardsmanager'>test</a> test test test test test test test test\n" +
|
||||
" test test test test test test test test test test test");
|
||||
dialog.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
dialog.setVisible(true);
|
||||
NotificationPopup dialog = new NotificationPopup(new JFrame(),
|
||||
System.out::println,
|
||||
"<a href='arduinoide://boardsmanager'>test</a> test test test test test test test test\n"
|
||||
+ " test test test test test test test test test test test");
|
||||
dialog.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton closeButton;
|
||||
private javax.swing.JLabel icon;
|
||||
private javax.swing.JEditorPane text;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user