Skip to content

Commit

Permalink
Refactor common Java view stuff into a utility class. [#4]
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed Nov 30, 2009
1 parent 96504a9 commit 2326619
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/document/Document.form
Expand Up @@ -17,7 +17,7 @@
<MenuItem class="javax.swing.JMenuItem" name="file_new_menu_item">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="makeShortcut(java.awt.event.KeyEvent.VK_N)" type="code"/>
<Connection code="ViewUtilities.makeShortcut(java.awt.event.KeyEvent.VK_N)" type="code"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="document/Bundle.properties" key="FileMenu.New" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
Expand All @@ -27,7 +27,7 @@
<MenuItem class="javax.swing.JMenuItem" name="file_open_menu_item">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="makeShortcut(java.awt.event.KeyEvent.VK_O)" type="code"/>
<Connection code="ViewUtilities.makeShortcut(java.awt.event.KeyEvent.VK_O)" type="code"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="document/Bundle.properties" key="FileMenu.Open" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
Expand Down
36 changes: 15 additions & 21 deletions src/document/Document.java
Expand Up @@ -11,23 +11,25 @@

package document;

import org.marnen.hive.ViewUtilities;

/**
*
* @author marnen
*/
public class Document extends javax.swing.JFrame {

/** Creates new form Document */
public Document() {
initComponents();
}

/** 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")
/** Creates new form Document */
public Document() {
initComponents();
}

/** 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() {

Expand All @@ -48,11 +50,11 @@ private void initComponents() {
file_menu.setText(bundle.getString("Document.file_menu.text")); // NOI18N
file_menu.setLabel(bundle.getString("FileMenu.text")); // NOI18N

file_new_menu_item.setAccelerator(makeShortcut(java.awt.event.KeyEvent.VK_N));
file_new_menu_item.setAccelerator(ViewUtilities.makeShortcut(java.awt.event.KeyEvent.VK_N));
file_new_menu_item.setText(bundle.getString("FileMenu.New")); // NOI18N
file_menu.add(file_new_menu_item);

file_open_menu_item.setAccelerator(makeShortcut(java.awt.event.KeyEvent.VK_O));
file_open_menu_item.setAccelerator(ViewUtilities.makeShortcut(java.awt.event.KeyEvent.VK_O));
file_open_menu_item.setText(bundle.getString("FileMenu.Open")); // NOI18N
file_menu.add(file_open_menu_item);

Expand Down Expand Up @@ -88,14 +90,6 @@ public void run() {
});
}

/**
* Creates a shortcut key with the default modifier (Cmd on Mac OS, Ctrl in most other places)
* @param key the VK_* keycode of the shortcut key
*/
public javax.swing.KeyStroke makeShortcut(int key) {
return javax.swing.KeyStroke.getKeyStroke(key, java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTable data_table;
private javax.swing.JMenu file_menu;
Expand Down
4 changes: 2 additions & 2 deletions src/intro_window/IntroWindow.form
Expand Up @@ -35,7 +35,7 @@
<MenuItem class="javax.swing.JMenuItem" name="file_new_menu_item">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="makeShortcut(java.awt.event.KeyEvent.VK_N)" type="code"/>
<Connection code="ViewUtilities.makeShortcut(java.awt.event.KeyEvent.VK_N)" type="code"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="document/Bundle.properties" key="FileMenu.New" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
Expand All @@ -45,7 +45,7 @@
<MenuItem class="javax.swing.JMenuItem" name="file_open_menu_item">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="makeShortcut(java.awt.event.KeyEvent.VK_O)" type="code"/>
<Connection code="ViewUtilities.makeShortcut(java.awt.event.KeyEvent.VK_O)" type="code"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="document/Bundle.properties" key="FileMenu.Open" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
Expand Down
37 changes: 15 additions & 22 deletions src/intro_window/IntroWindow.java
Expand Up @@ -11,23 +11,25 @@

package intro_window;

import org.marnen.hive.ViewUtilities;

/**
*
* @author marnen
*/
public class IntroWindow extends javax.swing.JFrame {

/** Creates new form IntroWindow */
public IntroWindow() {
initComponents();
}

/** 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")
/** Creates new form IntroWindow */
public IntroWindow() {
initComponents();
}

/** 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() {

Expand Down Expand Up @@ -57,11 +59,11 @@ private void initComponents() {
file_menu.setText(bundle1.getString("Document.file_menu.text")); // NOI18N
file_menu.setLabel(bundle1.getString("FileMenu.text")); // NOI18N

file_new_menu_item.setAccelerator(makeShortcut(java.awt.event.KeyEvent.VK_N));
file_new_menu_item.setAccelerator(ViewUtilities.makeShortcut(java.awt.event.KeyEvent.VK_N));
file_new_menu_item.setText(bundle1.getString("FileMenu.New")); // NOI18N
file_menu.add(file_new_menu_item);

file_open_menu_item.setAccelerator(makeShortcut(java.awt.event.KeyEvent.VK_O));
file_open_menu_item.setAccelerator(ViewUtilities.makeShortcut(java.awt.event.KeyEvent.VK_O));
file_open_menu_item.setText(bundle1.getString("FileMenu.Open")); // NOI18N
file_menu.add(file_open_menu_item);

Expand Down Expand Up @@ -100,15 +102,6 @@ public void run() {
});
}

/**
* Creates a shortcut key with the default modifier (Cmd on Mac OS, Ctrl in most other places)
* @param key the VK_* keycode of the shortcut key
*/
// TODO: Unify this and file menu with document.Document.java.
public javax.swing.KeyStroke makeShortcut(int key) {
return javax.swing.KeyStroke.getKeyStroke(key, java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
}


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenu file_menu;
Expand Down
16 changes: 16 additions & 0 deletions src/org/marnen/hive/ViewUtilities.java
@@ -0,0 +1,16 @@
package org.marnen.hive;

/**
* This class contains common methods for the various views in the application.
* @author marnen
*/

public class ViewUtilities {
/**
* Creates a shortcut key with the default modifier (Cmd on Mac OS, Ctrl in most other places)
* @param key the VK_* keycode of the shortcut key
*/
public static javax.swing.KeyStroke makeShortcut(int key) {
return javax.swing.KeyStroke.getKeyStroke(key, java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
}
}

0 comments on commit 2326619

Please sign in to comment.