From 9e75556d9ab9d0915c37465dedab9fcdb3ced48c Mon Sep 17 00:00:00 2001 From: Maksim Khramov Date: Tue, 11 Feb 2025 21:36:10 +0300 Subject: [PATCH] Improve Swing Templates Signed-off-by: makiam --- .../templates/Dialogs/Application_java | 18 +++++------------- .../templates/Dialogs/OkCancelDialog_java | 15 +++++++-------- .../templates/SwingForms/JDialog_java | 13 +++++-------- .../resources/templates/SwingForms/JFrame_java | 18 +++++------------- 4 files changed, 22 insertions(+), 42 deletions(-) diff --git a/java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/Application_java b/java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/Application_java index c36b1218ed83..9382a5ebc732 100644 --- a/java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/Application_java +++ b/java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/Application_java @@ -33,6 +33,8 @@ package ${package}; */ public class ${name} extends javax.swing.JFrame { + private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(${name}.class.getName()); + /** Creates new form ${name} */ public ${name}() { initComponents(); @@ -160,23 +162,13 @@ public class ${name} extends javax.swing.JFrame { break; } } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) { + logger.log(java.util.logging.Level.SEVERE, null, ex); } // /* Create and display the form */ - java.awt.EventQueue.invokeLater(new Runnable() { - public void run() { - new ${name}().setVisible(true); - } - }); + java.awt.EventQueue.invokeLater(() -> new ${name}().setVisible(true)); } // Variables declaration - do not modify//GEN-BEGIN:variables diff --git a/java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/OkCancelDialog_java b/java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/OkCancelDialog_java index 4d41792af89f..04f535f189b8 100644 --- a/java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/OkCancelDialog_java +++ b/java/form/src/org/netbeans/modules/form/resources/templates/Dialogs/OkCancelDialog_java @@ -41,6 +41,9 @@ import javax.swing.KeyStroke; * @author ${user} */ public class ${name} extends javax.swing.JDialog { + + private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(${name}.class.getName()); + /** A return status code - returned if Cancel button has been pressed */ public static final int RET_CANCEL = 0; /** A return status code - returned if OK button has been pressed */ @@ -57,6 +60,7 @@ public class ${name} extends javax.swing.JDialog { inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); ActionMap actionMap = getRootPane().getActionMap(); actionMap.put(cancelName, new AbstractAction() { + @Override public void actionPerformed(ActionEvent e) { doClose(RET_CANCEL); } @@ -164,19 +168,14 @@ public class ${name} extends javax.swing.JDialog { break; } } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) { + logger.log(java.util.logging.Level.SEVERE, null, ex); } // /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { + @Override public void run() { ${name} dialog = new ${name}(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { diff --git a/java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JDialog_java b/java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JDialog_java index efb597ebae31..611f3cbcb825 100644 --- a/java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JDialog_java +++ b/java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JDialog_java @@ -33,6 +33,8 @@ package ${package}; */ public class ${name} extends javax.swing.JDialog { + private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(${name}.class.getName()); + /** Creates new form ${name} */ public ${name}(java.awt.Frame parent, boolean modal) { super(parent, modal); @@ -80,19 +82,14 @@ public class ${name} extends javax.swing.JDialog { break; } } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) { + logger.log(java.util.logging.Level.SEVERE, null, ex); } // /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { + @Override public void run() { ${name} dialog = new ${name}(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { diff --git a/java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JFrame_java b/java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JFrame_java index 8e2600ffeb86..95dda921be1d 100644 --- a/java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JFrame_java +++ b/java/form/src/org/netbeans/modules/form/resources/templates/SwingForms/JFrame_java @@ -33,6 +33,8 @@ package ${package}; */ public class ${name} extends javax.swing.JFrame { + private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(${name}.class.getName()); + /** Creates new form ${name} */ public ${name}() { initComponents(); @@ -79,23 +81,13 @@ public class ${name} extends javax.swing.JFrame { break; } } - } catch (ClassNotFoundException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (InstantiationException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (IllegalAccessException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } catch (javax.swing.UnsupportedLookAndFeelException ex) { - java.util.logging.Logger.getLogger(${name}.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) { + logger.log(java.util.logging.Level.SEVERE, null, ex); } // /* Create and display the form */ - java.awt.EventQueue.invokeLater(new Runnable() { - public void run() { - new ${name}().setVisible(true); - } - }); + java.awt.EventQueue.invokeLater(() -> new ${name}().setVisible(true)); } // Variables declaration - do not modify//GEN-BEGIN:variables