From: <jg...@us...> - 2006-10-04 10:02:29
|
Revision: 78 http://svn.sourceforge.net/surveyforge/?rev=78&view=rev Author: jgongo Date: 2006-10-04 03:01:49 -0700 (Wed, 04 Oct 2006) Log Message: ----------- New version of runner with working binding and revamped MVC design Modified Paths: -------------- trunk/surveyforge-runner/pom.xml trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java Added Paths: ----------- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java trunk/surveyforge-runner/src/main/resources/jlfgr-1_0.jar trunk/surveyforge-runner/src/main/resources/org/ trunk/surveyforge-runner/src/main/resources/org/surveyforge/ trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/ trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame.properties trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame_es.properties Modified: trunk/surveyforge-runner/pom.xml =================================================================== --- trunk/surveyforge-runner/pom.xml 2006-10-04 09:10:26 UTC (rev 77) +++ trunk/surveyforge-runner/pom.xml 2006-10-04 10:01:49 UTC (rev 78) @@ -76,6 +76,10 @@ <artifactId>postgresql</artifactId> </dependency> <dependency> + <groupId>com.openinput.tools</groupId> + <artifactId>openinput-tools-swing</artifactId> + </dependency> + <dependency> <groupId>com.jgoodies</groupId> <artifactId>looks</artifactId> </dependency> Modified: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java 2006-10-04 09:10:26 UTC (rev 77) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireFrame.java 2006-10-04 10:01:49 UTC (rev 78) @@ -21,27 +21,38 @@ */ package org.surveyforge.runner; +import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.FlowLayout; -import java.awt.Toolkit; +import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.ResourceBundle; +import javax.persistence.EntityManagerFactory; import javax.swing.BorderFactory; +import javax.swing.Box; import javax.swing.BoxLayout; -import javax.swing.InputVerifier; +import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; +import javax.swing.JFormattedTextField; import javax.swing.JFrame; -import javax.swing.JOptionPane; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; +import javax.swing.JTextArea; import javax.swing.JTextField; +import javax.swing.JToolBar; +import javax.swing.UIDefaults; +import javax.swing.UIManager; import javax.swing.border.TitledBorder; +import javax.swing.plaf.ColorUIResource; import org.surveyforge.classification.Item; import org.surveyforge.classification.Level; @@ -70,45 +81,143 @@ */ public class QuestionnaireFrame extends JFrame { - private static final long serialVersionUID = -2135625525102812393L; + private static final long serialVersionUID = -2135625525102812393L; - private Questionnaire questionnaire; - private Map<QuestionnaireElement, Component> questionnaireComponents = new HashMap<QuestionnaireElement, Component>( ); - private ObjectData objectData; - private PresentationModel dataModel; + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle( "org.surveyforge.runner.QuestionnaireRunnerResourceBundle" ); - public QuestionnaireFrame( Questionnaire questionnaire ) + private QuestionnaireRunnerController controller; + + private Map<QuestionnaireElement, JComponent> elementToComponentMap = new HashMap<QuestionnaireElement, JComponent>( ); + private Map<JComponent, QuestionnaireElement> componentToElementMap = new HashMap<JComponent, QuestionnaireElement>( ); + + private EntityManagerFactory entityManagerFactory; + private Questionnaire questionnaire; + private ObjectData objectData; + private PresentationModel dataModel; + + /** + * @param entityManagerFactory + * @param questionnaire + * @throws IOException + */ + public QuestionnaireFrame( EntityManagerFactory entityManagerFactory, Questionnaire questionnaire ) throws IOException { - super( "QuestionnaireRunner" ); + super( "QuestionnaireRunner - " + questionnaire.getTitle( ) ); + this.entityManagerFactory = entityManagerFactory; this.questionnaire = questionnaire; + this.setObjectData( questionnaire.getRegister( ).getRegisterData( ).createEmptyObjectData( ) ); - JTabbedPane pagesPane = new JTabbedPane( ); - this.getContentPane( ).add( pagesPane ); + this.controller = new QuestionnaireRunnerController( this.entityManagerFactory, this ); - for( Feed pageFeed : questionnaire.getPageFeeds( ) ) - { - pagesPane.addTab( "Page", this.createPagePanel( questionnaire, pageFeed ) ); - } + this.createUI( ); } + /** + * @return + */ + protected Questionnaire getQuestionnaire( ) + { + return this.questionnaire; + } + + /** + * @return + */ protected ObjectData getObjectData( ) { return this.objectData; } + /** + * @param objectData + */ protected void setObjectData( ObjectData objectData ) { this.objectData = objectData; - this.dataModel = new JXPathPresentationModel( this.objectData ); + if( this.dataModel == null ) + this.dataModel = new JXPathPresentationModel( this.objectData ); + else + this.dataModel.setBean( this.objectData ); } + /** + * @return + */ protected PresentationModel getDataModel( ) { return this.dataModel; } + /** + * @return + */ + protected Map<QuestionnaireElement, JComponent> getElementToComponentMap( ) + { + return this.elementToComponentMap; + } + + /** + * @return + */ + protected Map<JComponent, QuestionnaireElement> getComponentToElementMap( ) + { + return this.componentToElementMap; + } + + /** + * + */ + private void createUI( ) + { + this.createMenuBar( ); + this.createToolBar( ); + this.createQuestionnairePanel( ); + } + + private void createMenuBar( ) + { + JMenuBar menuBar = new JMenuBar( ); + + // Sample menu + JMenu sampleMenu = new JMenu( QuestionnaireFrame.RESOURCE_BUNDLE.getString( "sampleMenu.title" ) ); + sampleMenu.setMnemonic( (Integer) QuestionnaireFrame.RESOURCE_BUNDLE.getObject( "sampleMenu.mnemonic" ) ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME ) ) ); + sampleMenu.add( new JMenuItem( this.controller.getActions( ).get( QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME ) ) ); + menuBar.add( sampleMenu ); + + this.setJMenuBar( menuBar ); + } + + private void createToolBar( ) + { + JToolBar toolbar = new JToolBar( ); + + JButton newButton = new JButton( this.controller.getActions( ).get( QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME ) ); + newButton.setText( "" ); + toolbar.add( newButton ); + JButton saveButton = new JButton( this.controller.getActions( ).get( QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME ) ); + saveButton.setText( "" ); + toolbar.add( saveButton ); + + this.getContentPane( ).add( toolbar, BorderLayout.NORTH ); + } + + private void createQuestionnairePanel( ) + { + JTabbedPane pagesPane = new JTabbedPane( ); + this.getContentPane( ).add( pagesPane, BorderLayout.CENTER ); + + int pageNumber = 1; + for( Feed pageFeed : questionnaire.getPageFeeds( ) ) + { + pagesPane.addTab( "Page " + pageNumber, this.createPagePanel( questionnaire, pageFeed ) ); + pageNumber++; + } + } + private JScrollPane createPagePanel( Questionnaire questionnaire, Feed pageFeed ) { JScrollPane pageScrollPane = new JScrollPane( ); @@ -120,6 +229,7 @@ { pagePanel.add( this.createSectionPanel( questionnaire, pageFeed, sectionFeed ) ); } + pagePanel.add( Box.createVerticalGlue( ) ); return pageScrollPane; } @@ -127,10 +237,9 @@ private JPanel createSectionPanel( Questionnaire questionnaire, Feed pageFeed, SectionFeed sectionFeed ) { StringBuffer rowSpecification = new StringBuffer( ); - for( int elementIndex = 0; elementIndex <= questionnaire.getElements( ).size( ); elementIndex++ ) + for( int elementIndex = 0; elementIndex <= questionnaire.getComponentElements( ).size( ); elementIndex++ ) rowSpecification.append( "3dlu, top:pref, 3dlu, pref, " ); - FormLayout sectionLayout = new FormLayout( "3dlu, pref, 5dlu, left:pref, 3dlu:grow", rowSpecification.toString( ) ); - + FormLayout sectionLayout = new FormLayout( "3dlu, max(150dlu;pref):grow, 5dlu, left:pref, 3dlu:grow", rowSpecification.toString( ) ); PanelBuilder pageSectionPanelBuilder = new PanelBuilder( sectionLayout ); pageSectionPanelBuilder.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder( Color.DARK_GRAY, 1 ), sectionFeed.getTitle( ), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, Color.DARK_GRAY ) ); @@ -152,7 +261,15 @@ pageSectionPanelBuilder.nextColumn( ); // Needed to place cursor in correct column if( element.getQuestion( ) != null ) - pageSectionPanelBuilder.addLabel( element.getQuestion( ).getText( ) ); + { + JTextArea questionText = new JTextArea( element.getQuestion( ).getText( ) ); + questionText.setFocusable( false ); + questionText.setEditable( false ); + questionText.setLineWrap( true ); + questionText.setWrapStyleWord( true ); + + pageSectionPanelBuilder.add( questionText ); + } else pageSectionPanelBuilder.nextColumn( 1 ); pageSectionPanelBuilder.nextColumn( 2 ); @@ -189,9 +306,13 @@ { QuantityValueDomain quantityValueDomain = (QuantityValueDomain) valueDomain; // JTextField field = new JTextField( quantityValueDomain.getPrecision( ) ); - JTextField field = BasicComponentFactory.createIntegerField( this.getDataModel( ).getModel( propertyName ) ); + JFormattedTextField field = BasicComponentFactory.createIntegerField( this.getDataModel( ).getModel( propertyName ) ); field.setColumns( quantityValueDomain.getPrecision( ) ); - this.questionnaireComponents.put( element, field ); + field.addFocusListener( this.controller.getSelectionController( ) ); + field.setInputVerifier( this.controller.getValidationController( ) ); + + this.elementToComponentMap.put( element, field ); + this.componentToElementMap.put( field, element ); return field; } else if( valueDomain instanceof ClassificationValueDomain ) @@ -204,41 +325,16 @@ .getModel( propertyName ) ) ) ); // JTextField classificationCode = new JTextField( 5 ); - final JTextField classificationCode = BasicComponentFactory.createTextField( this.dataModel.getModel( propertyName ) ); + JTextField classificationCode = BasicComponentFactory.createTextField( this.dataModel.getModel( propertyName ) ); classificationCode.setColumns( 5 ); - classificationCode.setInputVerifier( new InputVerifier( ) - { - Color defaultBackground = classificationCode.getBackground( ); - @Override - public boolean verify( JComponent component ) - { - if( classificationValueDomain.getLevel( ).includes( classificationCode.getText( ), false ) ) - { - classificationCode.setBackground( defaultBackground ); - return true; - } - else - { - classificationCode.setBackground( Color.RED ); - Toolkit.getDefaultToolkit( ).beep( ); - JOptionPane.showMessageDialog( classificationCode.getRootPane( ), - "El c\u00f3digo introducido no se encuentra entre las opciones disponibles.", "C\u00f3digo err\u00f3neo", - JOptionPane.ERROR_MESSAGE ); - return false; - } - } + classificationCode.addFocusListener( this.controller.getSelectionController( ) ); + classificationCode.setInputVerifier( this.controller.getValidationController( ) ); - @Override - public boolean shouldYieldFocus( JComponent input ) - { - return verify( input ); - } - } ); - classificationPanel.add( classificationCombo ); classificationPanel.add( classificationCode ); - this.questionnaireComponents.put( element, classificationPanel ); + this.elementToComponentMap.put( element, classificationPanel ); + this.componentToElementMap.put( classificationCode, element ); return classificationPanel; } else @@ -276,33 +372,12 @@ return propertyName.toString( ); } - // public static class ClassificationFormatter extends JFormattedTextField.AbstractFormatter - // { - // private Level level; - // - // public ClassificationFormatter( Level level ) - // { - // this.level = level; - // } - // - // @Override - // public Object stringToValue( String text ) throws ParseException - // { - // // TODO Auto-generated method stub - // return this.level.getItem( text, false ); - // } - // - // @Override - // public String valueToString( Object value ) throws ParseException - // { - // return value != null ? ((Item) value).getCode( ) : null; - // } - // } - // public static class ClassificationConverter extends AbstractConverter { - private Level level; + private static final long serialVersionUID = 5430851351776185423L; + private Level level; + public ClassificationConverter( Level level, ValueModel subject ) { super( subject ); Modified: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-10-04 09:10:26 UTC (rev 77) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunner.java 2006-10-04 10:01:49 UTC (rev 78) @@ -21,13 +21,18 @@ */ package org.surveyforge.runner; +import java.awt.Color; +import java.io.IOException; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; import javax.persistence.Query; import javax.swing.JFrame; +import javax.swing.UIDefaults; import javax.swing.UIManager; +import javax.swing.plaf.ColorUIResource; import org.surveyforge.core.survey.Questionnaire; @@ -36,7 +41,7 @@ */ public class QuestionnaireRunner { - public static void main( String[] args ) + public static void main( String[] args ) throws IOException { try { @@ -47,6 +52,11 @@ { // Likely PlasticXP is not in the class path; ignore. } + + // Default selection color + UIDefaults defaults = UIManager.getDefaults( ); + defaults.put( "TextField.selectionBackground", new ColorUIResource( Color.ORANGE ) ); + defaults.put( "FormattedTextField.selectionBackground", new ColorUIResource( Color.ORANGE ) ); EntityManager entityManager = null; EntityTransaction transaction = null; @@ -62,7 +72,7 @@ questionnaireQuery.setParameter( "questionnaireIdentifier", args[0] ); if( !questionnaireQuery.getResultList( ).isEmpty( ) ) { - questionnaireFrame = new QuestionnaireFrame( (Questionnaire) questionnaireQuery.getResultList( ).get( 0 ) ); + questionnaireFrame = new QuestionnaireFrame( entityManagerFactory, (Questionnaire) questionnaireQuery.getResultList( ).get( 0 ) ); questionnaireFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); questionnaireFrame.pack( ); } Added: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java (rev 0) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java 2006-10-04 10:01:49 UTC (rev 78) @@ -0,0 +1,316 @@ +/* + * surveyforge-runner - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.runner; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; +import java.text.ParseException; +import java.util.HashMap; +import java.util.Map; +import java.util.ResourceBundle; + +import javax.persistence.EntityManagerFactory; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.InputVerifier; +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JOptionPane; +import javax.swing.JFormattedTextField.AbstractFormatter; +import javax.swing.text.JTextComponent; + +import org.surveyforge.core.data.ObjectData; +import org.surveyforge.core.metadata.ValueDomain; +import org.surveyforge.core.survey.Questionnaire; +import org.surveyforge.core.survey.QuestionnaireElement; + +import com.openinput.tools.swing.ArrayActionMap; +import com.openinput.tools.swing.ResourceBundleBackedAction; + +/** + * @author jgonzalez + */ +public class QuestionnaireRunnerController + { + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle( "org.surveyforge.runner.QuestionnaireRunnerResourceBundle" ); + + public static final String NEW_SAMPLE_ACTION_NAME = "org.surveyforge.runner.QuestionnaireRunnerController.newSampleAction"; + public static final String SAVE_SAMPLE_ACTION_NAME = "org.surveyforge.runner.QuestionnaireRunnerController.saveSampleAction"; + + private Action[] supportedActionsArray; + private ActionMap supportedActions; + + private ValidationController validationController = new QuestionnaireRunnerController.ValidationController( ); + private SelectionController selectionController = new QuestionnaireRunnerController.SelectionController( ); + private RoutingController routingController = new QuestionnaireRunnerController.RoutingController( ); + + private EntityManagerFactory entityManagerFactory; + private QuestionnaireFrame questionnaireFrame; + private Questionnaire questionnaire; + + private Map<QuestionnaireElement, JComponent> elementToComponentMap; + private Map<JComponent, QuestionnaireElement> componentToElementMap; + + + public QuestionnaireRunnerController( EntityManagerFactory entityManagerFactory, QuestionnaireFrame questionnaireFrame ) + { + this.entityManagerFactory = entityManagerFactory; + this.questionnaireFrame = questionnaireFrame; + this.questionnaire = this.questionnaireFrame.getQuestionnaire( ); + + this.elementToComponentMap = this.questionnaireFrame.getElementToComponentMap( ); + this.componentToElementMap = this.questionnaireFrame.getComponentToElementMap( ); + + this.supportedActionsArray = new Action[] {new QuestionnaireRunnerController.NewSampleAction( ), + new QuestionnaireRunnerController.SaveSampleAction( )}; + this.supportedActions = new ArrayActionMap( this.supportedActionsArray ); + } + + public ActionMap getActions( ) + { + return this.supportedActions; + } + + public InputVerifier getValidationController( ) + { + return this.validationController; + } + + public FocusListener getSelectionController( ) + { + return this.selectionController; + } + + public ActionListener getRoutingController( ) + { + return this.routingController; + } + + /** + * @author jgonzalez + */ + class NewSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -7347987080988646268L; + + private final String questionTitle = RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".question.title" ); + private final String questionMessage = RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".question.message" ); + private final Object[] options = {RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".button.yes" ), + RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".button.no" ), + RESOURCE_BUNDLE.getString( NEW_SAMPLE_ACTION_NAME + ".button.cancel" )}; + + public NewSampleAction( ) + { + super( QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME, QuestionnaireRunnerController.RESOURCE_BUNDLE ); + } + + public void actionPerformed( ActionEvent e ) + { + int selectedOption = 1; + if( QuestionnaireRunnerController.this.questionnaireFrame.getDataModel( ).isChanged( ) ) + { + selectedOption = JOptionPane.showOptionDialog( QuestionnaireRunnerController.this.questionnaireFrame, this.questionMessage, + this.questionTitle, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[2] ); + } + + switch( selectedOption ) + { + case 0: + JOptionPane.showMessageDialog( QuestionnaireRunnerController.this.questionnaireFrame, "SAVING SAMPLE -- TODO!!!!" ); + + case 1: + Questionnaire questionnaire = QuestionnaireRunnerController.this.questionnaire; + ObjectData emptyObjectData = questionnaire.getRegister( ).getRegisterData( ).createEmptyObjectData( ); + QuestionnaireRunnerController.this.questionnaireFrame.setObjectData( emptyObjectData ); + break; + + default: + // Do nothing + break; + } + } + } + + /** + * @author jgonzalez + */ + class SaveSampleAction extends ResourceBundleBackedAction + { + private static final long serialVersionUID = -7347987080988646268L; + + public SaveSampleAction( ) + { + super( QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME, QuestionnaireRunnerController.RESOURCE_BUNDLE ); + QuestionnaireRunnerController.this.questionnaireFrame.getDataModel( ).addPropertyChangeListener( "changed", + new PropertyChangeListener( ) + { + public void propertyChange( PropertyChangeEvent event ) + { + SaveSampleAction.this.setEnabled( (Boolean) event.getNewValue( ) ); + } + } ); + this.setEnabled( false ); + } + + public void actionPerformed( ActionEvent e ) + { + JOptionPane.showMessageDialog( QuestionnaireRunnerController.this.questionnaireFrame, "SAVING SAMPLE -- TODO!!!!" ); + QuestionnaireRunnerController.this.questionnaireFrame.getDataModel( ).resetChanged( ); + } + } + + /** + * @author jgonzalez + */ + class ValidationController extends InputVerifier + { + // private EntityManagerFactory entityManagerFactory; + private Color errorColor = new Color( 1.0f, 0.625f, 0.625f ); + private Map<JComponent, ValueDomain> validationCache = new HashMap<JComponent, ValueDomain>( ); + private Map<JComponent, Color> defaultBackground = new HashMap<JComponent, Color>( ); + + protected ValueDomain getValueDomain( JComponent component ) + { + if( !this.validationCache.containsKey( component ) ) + { + // EntityManager entityManager = entityManagerFactory.createEntityManager( ); + + QuestionnaireElement questionnaireElement = QuestionnaireRunnerController.this.componentToElementMap.get( component ); + // entityManager.refresh( questionnaireElement ); + this.validationCache.put( component, questionnaireElement.getRegisterDataElement( ).getValueDomain( ) ); + + // entityManager.clear( ); + } + + return this.validationCache.get( component ); + } + + @Override + public boolean verify( JComponent component ) + { + // Get value from component + Object value = null; + if( component instanceof JFormattedTextField ) + { + // We must format the value manually, as the change still hasn't been committed + JFormattedTextField formattedComponent = (JFormattedTextField) component; + AbstractFormatter formatter = formattedComponent.getFormatter( ); + String textValue = formattedComponent.getText( ); + try + { + if( formatter != null ) + value = formatter.stringToValue( textValue ); + else + value = textValue; + } + catch( ParseException exc ) + { + // Cannot parse the value -> invalid value + this.showErrorStatus( component ); + return false; + } + } + else if( component instanceof JTextComponent ) + { + JTextComponent textComponent = (JTextComponent) component; + value = textComponent.getText( ); + } + + // Validate value using value domain + if( this.getValueDomain( component ).isValid( (Serializable) value ) ) + { + // We hava a valid value + this.showValidStatus( component ); + return true; + } + else + { + this.showErrorStatus( component ); + return false; + } + } + + /** + * @param component + */ + protected void showErrorStatus( JComponent component ) + { + if( !this.defaultBackground.containsKey( component ) ) this.defaultBackground.put( component, component.getBackground( ) ); + component.setBackground( this.errorColor ); + Toolkit.getDefaultToolkit( ).beep( ); + + // TODO: Include error messages in value domain + JOptionPane.showMessageDialog( component.getRootPane( ), "El valor introducido no es correcto.", "Error", + JOptionPane.ERROR_MESSAGE ); + } + + /** + * @param component + */ + protected void showValidStatus( JComponent component ) + { + if( this.defaultBackground.containsKey( component ) ) component.setBackground( this.defaultBackground.remove( component ) ); + } + } + + /** + * @author jgonzalez + */ + class SelectionController implements FocusListener + { + public void focusGained( FocusEvent event ) + { + Component component = event.getComponent( ); + if( component instanceof JTextComponent ) + { + JTextComponent textComponent = (JTextComponent) component; + textComponent.selectAll( ); + } + } + + public void focusLost( FocusEvent event ) + {} + } + + /** + * @author jgonzalez + */ + public class RoutingController implements ActionListener + { + /* + * (non-Javadoc) + * + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed( ActionEvent event ) + {} + } + } Property changes on: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerController.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java =================================================================== --- trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java (rev 0) +++ trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java 2006-10-04 10:01:49 UTC (rev 78) @@ -0,0 +1,79 @@ +/* + * surveyforge-runner - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to + * the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * $Id$ + */ +package org.surveyforge.runner; + +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.util.ListResourceBundle; + +import javax.swing.ImageIcon; +import javax.swing.KeyStroke; + +/** + * @author jgonzalez + */ +public class QuestionnaireRunnerResourceBundle extends ListResourceBundle + { + private static Object[][] CONTENTS = + { + // Sample menu + {"sampleMenu.title", "Sample"}, + {"sampleMenu.mnemonic", KeyEvent.VK_S}, + + // New sample action + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".name", "New"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".shortDescription", "Creates a new sample"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".longDescription", "Creates a new sample"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".smallIcon", new ImageIcon( ClassLoader.getSystemResource( "toolbarButtonGraphics/general/New16.gif" ) )}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".actionCommandKey", QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".acceleratorKey", KeyStroke.getKeyStroke( KeyEvent.VK_N, ActionEvent.CTRL_MASK )}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".mnemonicKey", new Integer( KeyEvent.VK_N )}, + + // New sample action messages + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".question.title", "Modified sample"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".question.message", "The sample has been modified, do you want to save it?"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".button.yes", "Yes"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".button.no", "No"}, + {QuestionnaireRunnerController.NEW_SAMPLE_ACTION_NAME + ".button.cancel", "Cancel"}, + + // Save sample action + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".name", "Save"}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".shortDescription", "Save current sample"}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".longDescription", "Save current sample"}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".smallIcon", new ImageIcon( ClassLoader.getSystemResource( "toolbarButtonGraphics/general/Save16.gif" ) )}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".actionCommandKey", QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".acceleratorKey", KeyStroke.getKeyStroke( KeyEvent.VK_S, ActionEvent.CTRL_MASK )}, + {QuestionnaireRunnerController.SAVE_SAMPLE_ACTION_NAME + ".mnemonicKey", new Integer( KeyEvent.VK_S )}, + + }; + + /* + * (non-Javadoc) + * + * @see java.util.ListResourceBundle#getContents() + */ + @Override + public Object[][] getContents( ) + { + return QuestionnaireRunnerResourceBundle.CONTENTS; + } + } Property changes on: trunk/surveyforge-runner/src/main/java/org/surveyforge/runner/QuestionnaireRunnerResourceBundle.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-runner/src/main/resources/jlfgr-1_0.jar =================================================================== (Binary files differ) Property changes on: trunk/surveyforge-runner/src/main/resources/jlfgr-1_0.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame.properties =================================================================== --- trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame.properties (rev 0) +++ trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame.properties 2006-10-04 10:01:49 UTC (rev 78) @@ -0,0 +1,5 @@ +action.new.name=New +action.new.tip=Create new sample +#action.new.shortcut=CTRL+N +action.new.mnemonic=N +action.new.icon=/toolbarButtonGraphics/general/New24.gif Added: trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame_es.properties =================================================================== --- trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame_es.properties (rev 0) +++ trunk/surveyforge-runner/src/main/resources/org/surveyforge/runner/QuestionnaireFrame_es.properties 2006-10-04 10:01:49 UTC (rev 78) @@ -0,0 +1,5 @@ +action.new.name=Nuevo +action.new.tip=Crear nueva muestra +#action.new.shortcut=CTRL+N +action.new.mnemonic=N +action.new.icon=/toolbarButtonGraphics/general/New24.gif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |