Skip to content

Commit

Permalink
Use nested File menu in DocumentController, and clean the code up a b…
Browse files Browse the repository at this point in the history
…it. [#4]
  • Loading branch information
marnen committed Dec 1, 2009
1 parent 118f8ce commit a0b7317
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 86 deletions.
7 changes: 1 addition & 6 deletions src/document/Bundle.properties
@@ -1,7 +1,2 @@
Document.title=Document
Document.jMenu2.text=Edit
FileMenu.text=File
FileMenu.New=New
FileMenu.Open=Open
Document.jMenu2.text_1=Edit
Document.file_menu.text=File
Document.jMenu2.text=Edit
47 changes: 3 additions & 44 deletions src/document/Document.form
Expand Up @@ -2,48 +2,7 @@

<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Menu class="javax.swing.JMenuBar" name="jMenuBar1">
<SubComponents>
<Menu class="javax.swing.JMenu" name="file_menu">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="document/Bundle.properties" key="Document.file_menu.text" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
<Property name="label" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="document/Bundle.properties" key="FileMenu.text" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<SubComponents>
<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="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;)"/>
</Property>
</Properties>
</MenuItem>
<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="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;)"/>
</Property>
</Properties>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="jMenu2">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="document/Bundle.properties" key="Document.jMenu2.text_1" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Menu>
</SubComponents>
<Menu class="javax.swing.JMenuBar" name="menu_bar">
</Menu>
</NonVisualComponents>
<Properties>
Expand All @@ -53,7 +12,7 @@
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
<SyntheticProperty name="menuBar" type="java.lang.String" value="menu_bar"/>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
Expand All @@ -76,7 +35,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="scroll_pane" alignment="1" pref="365" max="32767" attributes="0"/>
<Component id="scroll_pane" alignment="1" pref="386" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
Expand Down
32 changes: 4 additions & 28 deletions src/document/Document.java
Expand Up @@ -35,35 +35,15 @@ private void initComponents() {

scroll_pane = new javax.swing.JScrollPane();
data_table = new javax.swing.JTable();
jMenuBar1 = new javax.swing.JMenuBar();
file_menu = new javax.swing.JMenu();
file_new_menu_item = new javax.swing.JMenuItem();
file_open_menu_item = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
menu_bar = new javax.swing.JMenuBar();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("document/Bundle"); // NOI18N
setTitle(bundle.getString("Document.title")); // NOI18N

scroll_pane.setViewportView(data_table);

file_menu.setText(bundle.getString("Document.file_menu.text")); // NOI18N
file_menu.setLabel(bundle.getString("FileMenu.text")); // NOI18N

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(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);

jMenuBar1.add(file_menu);

jMenu2.setText(bundle.getString("Document.jMenu2.text_1")); // NOI18N
jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);
setJMenuBar(menu_bar);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
Expand All @@ -73,7 +53,7 @@ private void initComponents() {
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scroll_pane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE)
.addComponent(scroll_pane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
);

pack();
Expand All @@ -92,11 +72,7 @@ public void run() {

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTable data_table;
private javax.swing.JMenu file_menu;
private javax.swing.JMenuItem file_new_menu_item;
private javax.swing.JMenuItem file_open_menu_item;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuBar menu_bar;
private javax.swing.JScrollPane scroll_pane;
// End of variables declaration//GEN-END:variables

Expand Down
8 changes: 6 additions & 2 deletions src/document/document_controller.rb
@@ -1,6 +1,5 @@
class DocumentController < ApplicationController
require 'file_menu'
include FileMenu
require 'file_menu_controller'

set_model 'DocumentModel' do |model|
# Workaround since {DocumentModel.new @filename} doesn't work -- see http://kenai.com/jira/browse/MONKEYBARS-15
Expand All @@ -11,6 +10,11 @@ class DocumentController < ApplicationController
set_view 'DocumentView'
#set_close_action :exit

def initialize
super
add_nested_controller :menus, FileMenuController.create_instance
end

# Creates an instance of the controller for the specified file.
# If filename is nil, the user is prompted for a filename.
# If new_file? is true, then a new file is created; otherwise the controller expects the file to exist.
Expand Down
1 change: 1 addition & 0 deletions src/document/document_view.rb
Expand Up @@ -3,6 +3,7 @@ class DocumentView < ApplicationView
map :view => 'data_table.model', :model => :data
map :view => 'scroll_pane.row_header', :model => 'data.row_header'
raw_mapping :set_window_title, :get_window_title # map window title to model.title
nest :view => :menu_bar, :sub_view => :menus

protected

Expand Down
3 changes: 3 additions & 0 deletions src/file_menu/Bundle.properties
@@ -0,0 +1,3 @@
FileMenu.text=File
FileMenu.New=New
FileMenu.Open=Open
3 changes: 1 addition & 2 deletions src/file_menu/FileMenu.java
Expand Up @@ -24,8 +24,7 @@ private void initComponents() {
file_open_menu_item = new javax.swing.JMenuItem();

// TODO: Move bundle file to a more appropriate place.
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("document/Bundle"); // NOI18N
setText(bundle.getString("Document.file_menu.text")); // NOI18N
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("file_menu/Bundle"); // NOI18N
setLabel(bundle.getString("FileMenu.text")); // NOI18N

file_new_menu_item.setAccelerator(ViewUtilities.makeShortcut(java.awt.event.KeyEvent.VK_N));
Expand Down
1 change: 1 addition & 0 deletions src/file_menu/file_menu_controller.rb
@@ -1,4 +1,5 @@
class FileMenuController < ApplicationController
require 'file_menu_actions'
include FileMenuActions

set_view 'FileMenuView'
Expand Down
5 changes: 1 addition & 4 deletions src/intro_window/intro_window_controller.rb
@@ -1,14 +1,11 @@
class IntroWindowController < ApplicationController
require 'file_menu_actions'
require 'file_menu_controller'
include FileMenuActions

set_view 'IntroWindowView'
set_close_action :exit

def initialize
super
file_menu = FileMenuController.instance
add_nested_controller :menus, file_menu
add_nested_controller :menus, FileMenuController.create_instance
end
end

0 comments on commit a0b7317

Please sign in to comment.