Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39d1dfc

Browse files
author
Federico Fissore
committed
Added warning for uncertified boards
1 parent 25ddcb8 commit 39d1dfc

File tree

16 files changed

+573
-25
lines changed

16 files changed

+573
-25
lines changed

app/src/cc/arduino/view/Event.java

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Arduino is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package cc.arduino.view;
31+
32+
import java.awt.event.ActionEvent;
33+
import java.util.HashMap;
34+
import java.util.Map;
35+
36+
public class Event extends ActionEvent {
37+
38+
private final Map<String, Object> payload;
39+
40+
public Event(Object source, int id, String command) {
41+
super(source, id, command);
42+
this.payload = new HashMap<String, Object>();
43+
}
44+
45+
public Map<String, Object> getPayload() {
46+
return payload;
47+
}
48+
49+
@Override
50+
public String toString() {
51+
StringBuilder sb = new StringBuilder();
52+
sb.append(super.toString());
53+
sb.append("\n").append(payload.toString());
54+
return sb.toString();
55+
}
56+
57+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Arduino is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package cc.arduino.view;
31+
32+
public interface EventListener {
33+
34+
void eventHappened(Event event);
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Arduino is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package cc.arduino.view;
31+
32+
import processing.app.Preferences;
33+
34+
import java.awt.*;
35+
36+
public class ShowUncertifiedBoardWarning implements Runnable {
37+
38+
private final Frame parent;
39+
40+
public ShowUncertifiedBoardWarning(Frame parent) {
41+
this.parent = parent;
42+
}
43+
44+
@Override
45+
public void run() {
46+
UncertifiedBoardWarning uncertifiedBoardWarning = new UncertifiedBoardWarning(parent, new EventListener() {
47+
@Override
48+
public void eventHappened(cc.arduino.view.Event event) {
49+
if (!"uncertified_board_warning_ok_pressed".equals(event.getActionCommand())) {
50+
return;
51+
}
52+
Preferences.set("uncertifiedBoardWarning_dontShowMeAgain", event.getPayload().get("dontShowMeAgain").toString());
53+
}
54+
});
55+
uncertifiedBoardWarning.setLocationRelativeTo(parent);
56+
uncertifiedBoardWarning.setVisible(true);
57+
}
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
4+
<Properties>
5+
<Property name="defaultCloseOperation" type="int" value="2"/>
6+
<Property name="title" type="java.lang.String" value="_(&quot;Not supported board&quot;)"/>
7+
<Property name="modal" type="boolean" value="true"/>
8+
<Property name="name" type="java.lang.String" value="uncertifiedBoardWarning" noResource="true"/>
9+
<Property name="resizable" type="boolean" value="false"/>
10+
</Properties>
11+
<SyntheticProperties>
12+
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
13+
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
14+
</SyntheticProperties>
15+
<AuxValues>
16+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
17+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
18+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
19+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
20+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
21+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
22+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
23+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
24+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
25+
</AuxValues>
26+
27+
<Layout>
28+
<DimensionLayout dim="0">
29+
<Group type="103" groupAlignment="0" attributes="0">
30+
<Group type="102" alignment="0" attributes="0">
31+
<EmptySpace max="-2" attributes="0"/>
32+
<Group type="103" groupAlignment="0" attributes="0">
33+
<Component id="jLabel1" pref="0" max="32767" attributes="0"/>
34+
<Group type="102" attributes="0">
35+
<Component id="dontShowMeAgain" min="-2" max="-2" attributes="0"/>
36+
<EmptySpace pref="206" max="32767" attributes="0"/>
37+
<Component id="ok" min="-2" pref="82" max="-2" attributes="0"/>
38+
</Group>
39+
</Group>
40+
<EmptySpace max="-2" attributes="0"/>
41+
</Group>
42+
</Group>
43+
</DimensionLayout>
44+
<DimensionLayout dim="1">
45+
<Group type="103" groupAlignment="0" attributes="0">
46+
<Group type="102" alignment="0" attributes="0">
47+
<EmptySpace max="-2" attributes="0"/>
48+
<Component id="jLabel1" min="-2" pref="87" max="-2" attributes="0"/>
49+
<EmptySpace max="-2" attributes="0"/>
50+
<Group type="103" groupAlignment="3" attributes="0">
51+
<Component id="dontShowMeAgain" alignment="3" min="-2" max="-2" attributes="0"/>
52+
<Component id="ok" alignment="3" min="-2" max="-2" attributes="0"/>
53+
</Group>
54+
<EmptySpace max="32767" attributes="0"/>
55+
</Group>
56+
</Group>
57+
</DimensionLayout>
58+
</Layout>
59+
<SubComponents>
60+
<Component class="javax.swing.JLabel" name="jLabel1">
61+
<Properties>
62+
<Property name="text" type="java.lang.String" value="&lt;html&gt;&lt;body&gt;This board comes from an non certified manufacturer.&lt;br&gt;We won&apos;t be able to provide any support if it doesn&apos;t work as expected.&lt;/body&gt;&lt;/html&gt;"/>
63+
<Property name="verticalAlignment" type="int" value="1"/>
64+
</Properties>
65+
</Component>
66+
<Component class="javax.swing.JCheckBox" name="dontShowMeAgain">
67+
<Properties>
68+
<Property name="text" type="java.lang.String" value="Don&apos;t show me again"/>
69+
<Property name="name" type="java.lang.String" value="dontShowMeAgain" noResource="true"/>
70+
</Properties>
71+
</Component>
72+
<Component class="javax.swing.JButton" name="ok">
73+
<Properties>
74+
<Property name="text" type="java.lang.String" value="OK"/>
75+
</Properties>
76+
<Events>
77+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okActionPerformed"/>
78+
</Events>
79+
</Component>
80+
</SubComponents>
81+
</Form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Arduino is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package cc.arduino.view;
31+
32+
import javax.swing.*;
33+
import java.awt.*;
34+
35+
import static processing.app.I18n._;
36+
37+
public class UncertifiedBoardWarning extends javax.swing.JDialog {
38+
39+
private final EventListener listener;
40+
41+
public UncertifiedBoardWarning(Frame parent, EventListener listener) {
42+
super(parent);
43+
initComponents();
44+
this.listener = listener;
45+
}
46+
47+
/**
48+
* This method is called from within the constructor to initialize the form.
49+
* WARNING: Do NOT modify this code. The content of this method is always
50+
* regenerated by the Form Editor.
51+
*/
52+
@SuppressWarnings("unchecked")
53+
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
54+
private void initComponents() {
55+
56+
jLabel1 = new javax.swing.JLabel();
57+
dontShowMeAgain = new javax.swing.JCheckBox();
58+
ok = new javax.swing.JButton();
59+
60+
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
61+
setTitle(_("Uncertified board"));
62+
setModal(true);
63+
setName("uncertifiedBoardWarning"); // NOI18N
64+
setResizable(false);
65+
66+
jLabel1.setText("<html><body>" + _("This board comes from an uncertified manufacturer.") + "<br>" + _("We won't be able to provide any support if it doesn't work as expected.") + "</body></html>");
67+
jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);
68+
69+
dontShowMeAgain.setText("Don't show me again");
70+
dontShowMeAgain.setName("dontShowMeAgain"); // NOI18N
71+
72+
ok.setText("OK");
73+
ok.addActionListener(new java.awt.event.ActionListener() {
74+
public void actionPerformed(java.awt.event.ActionEvent evt) {
75+
okActionPerformed(evt);
76+
}
77+
});
78+
79+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
80+
getContentPane().setLayout(layout);
81+
layout.setHorizontalGroup(
82+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
83+
.addGroup(layout.createSequentialGroup()
84+
.addContainerGap()
85+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
86+
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
87+
.addGroup(layout.createSequentialGroup()
88+
.addComponent(dontShowMeAgain)
89+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 206, Short.MAX_VALUE)
90+
.addComponent(ok, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))
91+
.addContainerGap())
92+
);
93+
layout.setVerticalGroup(
94+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
95+
.addGroup(layout.createSequentialGroup()
96+
.addContainerGap()
97+
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
98+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
99+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
100+
.addComponent(dontShowMeAgain)
101+
.addComponent(ok))
102+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
103+
);
104+
105+
pack();
106+
}// </editor-fold>//GEN-END:initComponents
107+
108+
private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
109+
Event event = new Event(evt.getSource(), evt.getID(), "uncertified_board_warning_ok_pressed");
110+
event.getPayload().put("dontShowMeAgain", dontShowMeAgain.isSelected());
111+
listener.eventHappened(event);
112+
this.dispose();
113+
}//GEN-LAST:event_okActionPerformed
114+
115+
/**
116+
* @param args the command line arguments
117+
*/
118+
public static void main(String args[]) throws Exception {
119+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
120+
/* Create and display the dialog */
121+
java.awt.EventQueue.invokeLater(new Runnable() {
122+
public void run() {
123+
UncertifiedBoardWarning dialog = new UncertifiedBoardWarning(new javax.swing.JFrame(), new EventListener() {
124+
125+
@Override
126+
public void eventHappened(Event event) {
127+
System.out.println(event);
128+
}
129+
});
130+
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
131+
@Override
132+
public void windowClosing(java.awt.event.WindowEvent e) {
133+
System.exit(0);
134+
}
135+
});
136+
dialog.setVisible(true);
137+
}
138+
});
139+
}
140+
141+
// Variables declaration - do not modify//GEN-BEGIN:variables
142+
private javax.swing.JCheckBox dontShowMeAgain;
143+
private javax.swing.JLabel jLabel1;
144+
private javax.swing.JButton ok;
145+
// End of variables declaration//GEN-END:variables
146+
}

0 commit comments

Comments
 (0)