Skip to content

Commit

Permalink
convert ComboBox and its subtypes to class, phetsims/sun#456
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jan 20, 2019
1 parent 9b7368a commit a58e799
Showing 1 changed file with 51 additions and 45 deletions.
96 changes: 51 additions & 45 deletions js/realmolecules/view/RealMoleculesComboBox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014-2017, University of Colorado Boulder
// Copyright 2014-2019, University of Colorado Boulder

/**
* Combo box for choosing a real molecule.
Expand All @@ -9,62 +9,68 @@ define( function( require ) {
'use strict';

// modules
var ComboBox = require( 'SUN/ComboBox' );
var ComboBoxItem = require( 'SUN/ComboBoxItem' );
var inherit = require( 'PHET_CORE/inherit' );
var moleculePolarity = require( 'MOLECULE_POLARITY/moleculePolarity' );
var PhetFont = require( 'SCENERY_PHET/PhetFont' );
var RichText = require( 'SCENERY/nodes/RichText' );
var StringUtils = require( 'PHETCOMMON/util/StringUtils' );
var Text = require( 'SCENERY/nodes/Text' );
const ComboBox = require( 'SUN/ComboBox' );
const ComboBoxItem = require( 'SUN/ComboBoxItem' );
const moleculePolarity = require( 'MOLECULE_POLARITY/moleculePolarity' );
const PhetFont = require( 'SCENERY_PHET/PhetFont' );
const RichText = require( 'SCENERY/nodes/RichText' );
const StringUtils = require( 'PHETCOMMON/util/StringUtils' );
const Text = require( 'SCENERY/nodes/Text' );

// strings
var moleculeString = require( 'string!MOLECULE_POLARITY/molecule' );
var patternSymbolNameString = require( 'string!MOLECULE_POLARITY/pattern.symbolName' );
const moleculeString = require( 'string!MOLECULE_POLARITY/molecule' );
const patternSymbolNameString = require( 'string!MOLECULE_POLARITY/pattern.symbolName' );

/**
* @param {RealMolecule[]} molecules
* @param {Property.<RealMolecule>} moleculeProperty
* @param {Node} listParent
* @constructor
*/
function RealMoleculesComboBox( molecules, moleculeProperty, listParent ) {
class RealMoleculesComboBox extends ComboBox {

// label
var labelNode = new Text( moleculeString, {
font: new PhetFont( 22 ),
maxWidth: 150
} );
/**
* @param {RealMolecule[]} molecules
* @param {Property.<RealMolecule>} moleculeProperty
* @param {Node} listParent
* @constructor
*/
constructor( molecules, moleculeProperty, listParent ) {

// items
var items = [];
for ( var i = 0; i < molecules.length; i++ ) {
// label
const labelNode = new Text( moleculeString, {
font: new PhetFont( 22 ),
maxWidth: 150
} );

var molecule = molecules[ i ];
// {ComboBoxItem[]}
const items = molecules.map( createItem );

var text = StringUtils.fillIn( patternSymbolNameString, {
symbol: molecule.symbol,
name: molecule.name
super( items, moleculeProperty, listParent, {
labelNode: labelNode,
listPosition: 'above',
highlightFill: 'rgb(218,255,255)',
cornerRadius: 8,
maxWidth: 450
} );
}
}

var node = new RichText( text, {
maxWidth: 200,
font: new PhetFont( 18 )
} );
moleculePolarity.register( 'RealMoleculesComboBox', RealMoleculesComboBox );

items[ i ] = new ComboBoxItem( node, molecule );
}
/**
* Creates an item for the combo box.
* @param {RealMolecule} molecule
* @returns {ComboBoxItem}
*/
function createItem( molecule ) {

ComboBox.call( this, items, moleculeProperty, listParent, {
labelNode: labelNode,
listPosition: 'above',
highlightFill: 'rgb(218,255,255)',
cornerRadius: 8,
maxWidth: 450
const text = StringUtils.fillIn( patternSymbolNameString, {
symbol: molecule.symbol,
name: molecule.name
} );
}

moleculePolarity.register( 'RealMoleculesComboBox', RealMoleculesComboBox );
const node = new RichText( text, {
maxWidth: 200,
font: new PhetFont( 18 )
} );

return new ComboBoxItem( node, molecule );
}

return inherit( ComboBox, RealMoleculesComboBox );
return RealMoleculesComboBox;
} );

0 comments on commit a58e799

Please sign in to comment.