Skip to content

Commit c384b9a

Browse files
authored
Merge pull request #8234 from makiam/improve-swing-templates
Improve Swing Templates
2 parents 102f069 + 9e75556 commit c384b9a

4 files changed

Lines changed: 22 additions & 42 deletions

File tree

java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/Application_java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ package ${package};
3333
*/
3434
public class ${name} extends javax.swing.JFrame {
3535

36+
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(${name}.class.getName());
37+
3638
/** Creates new form ${name} */
3739
public ${name}() {
3840
initComponents();
@@ -160,23 +162,13 @@ public class ${name} extends javax.swing.JFrame {
160162
break;
161163
}
162164
}
163-
} catch (ClassNotFoundException ex) {
164-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
165-
} catch (InstantiationException ex) {
166-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
167-
} catch (IllegalAccessException ex) {
168-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
169-
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
170-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
165+
} catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) {
166+
logger.log(java.util.logging.Level.SEVERE, null, ex);
171167
}
172168
//</editor-fold>
173169

174170
/* Create and display the form */
175-
java.awt.EventQueue.invokeLater(new Runnable() {
176-
public void run() {
177-
new ${name}().setVisible(true);
178-
}
179-
});
171+
java.awt.EventQueue.invokeLater(() -> new ${name}().setVisible(true));
180172
}
181173

182174
// Variables declaration - do not modify//GEN-BEGIN:variables

java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/OkCancelDialog_java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ import javax.swing.KeyStroke;
4141
* @author ${user}
4242
*/
4343
public class ${name} extends javax.swing.JDialog {
44+
45+
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(${name}.class.getName());
46+
4447
/** A return status code - returned if Cancel button has been pressed */
4548
public static final int RET_CANCEL = 0;
4649
/** A return status code - returned if OK button has been pressed */
@@ -57,6 +60,7 @@ public class ${name} extends javax.swing.JDialog {
5760
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
5861
ActionMap actionMap = getRootPane().getActionMap();
5962
actionMap.put(cancelName, new AbstractAction() {
63+
@Override
6064
public void actionPerformed(ActionEvent e) {
6165
doClose(RET_CANCEL);
6266
}
@@ -164,19 +168,14 @@ public class ${name} extends javax.swing.JDialog {
164168
break;
165169
}
166170
}
167-
} catch (ClassNotFoundException ex) {
168-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
169-
} catch (InstantiationException ex) {
170-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
171-
} catch (IllegalAccessException ex) {
172-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
173-
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
174-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
171+
} catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) {
172+
logger.log(java.util.logging.Level.SEVERE, null, ex);
175173
}
176174
//</editor-fold>
177175

178176
/* Create and display the dialog */
179177
java.awt.EventQueue.invokeLater(new Runnable() {
178+
@Override
180179
public void run() {
181180
${name} dialog = new ${name}(new javax.swing.JFrame(), true);
182181
dialog.addWindowListener(new java.awt.event.WindowAdapter() {

java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JDialog_java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ package ${package};
3333
*/
3434
public class ${name} extends javax.swing.JDialog {
3535

36+
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(${name}.class.getName());
37+
3638
/** Creates new form ${name} */
3739
public ${name}(java.awt.Frame parent, boolean modal) {
3840
super(parent, modal);
@@ -80,19 +82,14 @@ public class ${name} extends javax.swing.JDialog {
8082
break;
8183
}
8284
}
83-
} catch (ClassNotFoundException ex) {
84-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
85-
} catch (InstantiationException ex) {
86-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
87-
} catch (IllegalAccessException ex) {
88-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
89-
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
90-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
85+
} catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) {
86+
logger.log(java.util.logging.Level.SEVERE, null, ex);
9187
}
9288
//</editor-fold>
9389

9490
/* Create and display the dialog */
9591
java.awt.EventQueue.invokeLater(new Runnable() {
92+
@Override
9693
public void run() {
9794
${name} dialog = new ${name}(new javax.swing.JFrame(), true);
9895
dialog.addWindowListener(new java.awt.event.WindowAdapter() {

java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JFrame_java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ package ${package};
3333
*/
3434
public class ${name} extends javax.swing.JFrame {
3535

36+
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(${name}.class.getName());
37+
3638
/** Creates new form ${name} */
3739
public ${name}() {
3840
initComponents();
@@ -79,23 +81,13 @@ public class ${name} extends javax.swing.JFrame {
7981
break;
8082
}
8183
}
82-
} catch (ClassNotFoundException ex) {
83-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
84-
} catch (InstantiationException ex) {
85-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
86-
} catch (IllegalAccessException ex) {
87-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
88-
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
89-
java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
84+
} catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) {
85+
logger.log(java.util.logging.Level.SEVERE, null, ex);
9086
}
9187
//</editor-fold>
9288

9389
/* Create and display the form */
94-
java.awt.EventQueue.invokeLater(new Runnable() {
95-
public void run() {
96-
new ${name}().setVisible(true);
97-
}
98-
});
90+
java.awt.EventQueue.invokeLater(() -> new ${name}().setVisible(true));
9991
}
10092

10193
// Variables declaration - do not modify//GEN-BEGIN:variables

0 commit comments

Comments
 (0)