From bca39e74cee4b56f3f531cc8251700c76c7fec04 Mon Sep 17 00:00:00 2001 From: denny Date: Sun, 24 Jan 2016 19:27:26 -0500 Subject: [PATCH] Work in progress - more updates to the alias controller and alias editor panels. --- src/alias/Alias.java | 26 ----- src/alias/AliasController.java | 2 +- src/alias/AliasEditor.java | 14 ++- src/alias/AliasFactory.java | 138 +++++++++++++++++++++++++++ src/alias/AliasID.java | 12 --- src/alias/AliasIdentifierEditor.java | 86 +++++++++++++++++ src/alias/AliasModel.java | 7 ++ src/alias/AliasNameEditor.java | 89 +++++++++-------- 8 files changed, 289 insertions(+), 85 deletions(-) create mode 100644 src/alias/AliasFactory.java create mode 100644 src/alias/AliasIdentifierEditor.java diff --git a/src/alias/Alias.java b/src/alias/Alias.java index 0634c434..1c6ddb87 100644 --- a/src/alias/Alias.java +++ b/src/alias/Alias.java @@ -166,32 +166,6 @@ public class Alias return !mAliasActions.isEmpty(); } - public boolean hasAudioType() - { - for( AliasID id: mAliasIDs ) - { - if( id.hasAudioType() ) - { - return true; - } - } - - return false; - } - - public AudioType getAudioType() - { - for( AliasID id: mAliasIDs ) - { - if( id.hasAudioType() ) - { - return id.getAudioType(); - } - } - - return AudioType.NORMAL; - } - /** * Returns the priority level of this alias, if defined, or the default priority */ diff --git a/src/alias/AliasController.java b/src/alias/AliasController.java index 65844e57..dbe45414 100644 --- a/src/alias/AliasController.java +++ b/src/alias/AliasController.java @@ -206,7 +206,7 @@ public class AliasController extends JPanel if( selected != null ) { -// addAlias( selected.copyOf() ); + addAlias( AliasFactory.copyOf( selected ) ); } break; case DELETE_ALIAS: diff --git a/src/alias/AliasEditor.java b/src/alias/AliasEditor.java index 38e4c78d..28e6ecb6 100644 --- a/src/alias/AliasEditor.java +++ b/src/alias/AliasEditor.java @@ -43,6 +43,7 @@ public class AliasEditor extends JPanel implements ActionListener, Listener EMPTY_MODEL = new DefaultListModel<>(); + private JList mAliasIDList = new JList<>( EMPTY_MODEL ); + + private Alias mAlias; + + public AliasIdentifierEditor() + { + init(); + } + + private void init() + { + setLayout( new MigLayout( "fill,wrap 3", + "[grow,fill][grow,fill][grow,fill]", "[grow,fill][][grow,fill]" ) ); + + mAliasIDList.setVisibleRowCount( 6 ); + mAliasIDList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + mAliasIDList.setLayoutOrientation( JList.VERTICAL ); + + JScrollPane scroller = new JScrollPane( mAliasIDList ); + add( scroller, "span,grow" ); + + add( new JButton( "New" ) ); + add( new JButton( "Copy" ) ); + add( new JButton( "Delete" ), "wrap" ); + } + + @Override + public void setAlias( Alias alias ) + { + mAlias = alias; + + if( mAlias == null || mAlias.getId().isEmpty() ) + { + mAliasIDList.setModel( EMPTY_MODEL ); + } + else + { + DefaultListModel model = new DefaultListModel(); + + List ids = mAlias.getId(); + + Collections.sort( ids, new Comparator() + { + @Override + public int compare( AliasID o1, AliasID o2 ) + { + return o1.toString().compareTo( o2.toString() ); + } + } ); + + for( AliasID id: ids ) + { + model.addElement( id ); + } + + mAliasIDList.setModel( model ); + } + } + + @Override + public void save() + { + // TODO Auto-generated method stub + + } +} diff --git a/src/alias/AliasModel.java b/src/alias/AliasModel.java index 4a1d11b1..3206a57e 100644 --- a/src/alias/AliasModel.java +++ b/src/alias/AliasModel.java @@ -270,6 +270,13 @@ public class AliasModel implements TableModel public void broadcast( AliasEvent event ) { mAliasEventBroadcaster.broadcast( event ); + + if( event.getEvent() == Event.CHANGE ) + { + int index = mAliases.indexOf( event.getAlias() ); + + broadcast( new TableModelEvent( this, index ) ); + } } public void addAliasEventListener( Listener listener ) diff --git a/src/alias/AliasNameEditor.java b/src/alias/AliasNameEditor.java index 742fde37..69768e3a 100644 --- a/src/alias/AliasNameEditor.java +++ b/src/alias/AliasNameEditor.java @@ -13,7 +13,6 @@ import javax.swing.JButton; import javax.swing.JColorChooser; import javax.swing.JComboBox; import javax.swing.JLabel; -import javax.swing.JOptionPane; import javax.swing.JTextField; import map.IconManager; @@ -30,11 +29,9 @@ public class AliasNameEditor extends AliasConfigurationEditor private JComboBox mListCombo = new JComboBox<>( EMPTY_MODEL ); private JComboBox mGroupCombo = new JComboBox<>( EMPTY_MODEL ); + private JComboBox mMapIconCombo; private JTextField mName; - - private JLabel mLabelMapColor; private JButton mButtonColor; - private JComboBox mComboMapIcon; private JButton mBtnIconManager; private Alias mAlias; @@ -50,10 +47,33 @@ public class AliasNameEditor extends AliasConfigurationEditor private void init() { - setLayout( new MigLayout( "fill,wrap 2", "[right][grow,fill]", "[][][][][][grow][]" ) ); + setLayout( new MigLayout( "fill,wrap 2", "[right][grow,fill]", + "[][][][][][][grow]" ) ); add( new JLabel( "List:" ) ); mListCombo.setEditable( true ); + mListCombo.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + if( mListCombo.getSelectedItem() != null ) + { + List groups = mAliasModel + .getGroupNames( (String)mListCombo.getSelectedItem() ); + + if( groups.isEmpty() ) + { + mGroupCombo.setModel( EMPTY_MODEL ); + } + else + { + mGroupCombo.setModel( new DefaultComboBoxModel( + groups.toArray( new String[ groups.size() ] ) ) );; + } + } + } + } ); add( mListCombo, "wrap" ); add( new JLabel( "Group:" ) ); @@ -88,13 +108,13 @@ public class AliasNameEditor extends AliasConfigurationEditor add( new JLabel( "Icon:" ) ); - mComboMapIcon = new JComboBox( mSettingsManager.getMapIcons() ); + mMapIconCombo = new JComboBox( mSettingsManager.getMapIcons() ); MapIconListCellRenderer renderer = new MapIconListCellRenderer(); renderer.setPreferredSize( new Dimension( 200, 30 ) ); - mComboMapIcon.setRenderer( renderer ); + mMapIconCombo.setRenderer( renderer ); - add( mComboMapIcon, "wrap" ); + add( mMapIconCombo, "wrap" ); //Dummy place holder add( new JLabel() ); @@ -175,7 +195,7 @@ public class AliasNameEditor extends AliasConfigurationEditor if( savedIcon != null ) { - mComboMapIcon.setSelectedItem( savedIcon ); + mMapIconCombo.setSelectedItem( savedIcon ); } } else @@ -192,41 +212,26 @@ public class AliasNameEditor extends AliasConfigurationEditor @Override public void save() { - // TODO Auto-generated method stub - String alias = mName.getText(); - - if( alias != null ) + if( mAlias != null ) { -// boolean expanded = mAliasNode.getModel().getTree() -// .isExpanded( new TreePath( mAliasNode ) ); -// -// mAliasNode.getAlias().setName( alias ); -// ((ConfigurableNode)mAliasNode.getParent()).sort(); -// -// mAliasNode.getAlias().setColor( -// mButtonColor.getBackground().getRGB() ); - - MapIcon selectedIcon = (MapIcon)mComboMapIcon.getSelectedItem(); + if( mListCombo.getSelectedItem() != null ) + { + mAlias.setList( (String)mListCombo.getSelectedItem() ); + } -// if( selectedIcon != null ) -// { -// mAliasNode.getAlias().setIconName( selectedIcon.getName() ); -// } -// -// mAliasNode.save(); -// -// mAliasNode.show(); -// -// if( expanded ) -// { -// mAliasNode.getModel().getTree() -// .expandPath( new TreePath( mAliasNode ) ); -// } + if( mGroupCombo.getSelectedItem() != null ) + { + mAlias.setGroup( (String)mGroupCombo.getSelectedItem() ); + } + + mAlias.setName( mName.getText() ); + + mAlias.setColor( mButtonColor.getBackground().getRGB() ); + + if( mMapIconCombo.getSelectedItem() != null ) + { + mAlias.setIconName( ((MapIcon)mMapIconCombo.getSelectedItem()).getName() ); + } } - else - { - JOptionPane.showMessageDialog( AliasNameEditor.this, "Please enter an alias name" ); - } - } }