From 75714072b239c8eb2fdbc36446253777a33425c4 Mon Sep 17 00:00:00 2001 From: denny Date: Sun, 24 Jan 2016 15:46:55 -0500 Subject: [PATCH] Adds AliasModel, AliasController tab with new AliasEditor --- src/alias/Alias.java | 5 + src/alias/AliasActionListener.java | 30 ++ src/alias/AliasConfigurationEditor.java | 36 +++ src/alias/AliasController.java | 287 ++++++++++++++++++ src/alias/AliasEditor.java | 205 ++++--------- src/alias/AliasModel.java | 31 +- src/alias/AliasNameEditor.java | 232 ++++++++++++++ src/alias/AliasNode.java | 3 +- src/controller/ControllerPanel.java | 14 +- src/controller/channel/ChannelController.java | 2 +- src/controller/channel/ChannelEditor.java | 2 +- src/gui/SDRTrunk.java | 2 +- 12 files changed, 686 insertions(+), 163 deletions(-) create mode 100644 src/alias/AliasActionListener.java create mode 100644 src/alias/AliasConfigurationEditor.java create mode 100644 src/alias/AliasController.java create mode 100644 src/alias/AliasNameEditor.java diff --git a/src/alias/Alias.java b/src/alias/Alias.java index 76fca7a1..0634c434 100644 --- a/src/alias/Alias.java +++ b/src/alias/Alias.java @@ -41,6 +41,11 @@ public class Alias { } + public Alias( String name ) + { + mName = name; + } + public String toString() { return getName(); diff --git a/src/alias/AliasActionListener.java b/src/alias/AliasActionListener.java new file mode 100644 index 00000000..5c97948c --- /dev/null +++ b/src/alias/AliasActionListener.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * SDR Trunk + * Copyright (C) 2014-2016 Dennis Sheirer + * + * 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 3 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, see + ******************************************************************************/ +package alias; + +/** + * Interface for receiving alias events. Each listener will receive + * notification of all alias events. + */ +public interface AliasActionListener +{ + /** + * Notifies the listener that an alias event has occurred + */ + public void aliasChanged( AliasEvent event ); +} diff --git a/src/alias/AliasConfigurationEditor.java b/src/alias/AliasConfigurationEditor.java new file mode 100644 index 00000000..1add4761 --- /dev/null +++ b/src/alias/AliasConfigurationEditor.java @@ -0,0 +1,36 @@ +/******************************************************************************* + + * SDR Trunk + * Copyright (C) 2014-2016 Dennis Sheirer + * + * 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 3 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, see + ******************************************************************************/ +package alias; + +import javax.swing.JPanel; + +public abstract class AliasConfigurationEditor extends JPanel +{ + private static final long serialVersionUID = 1L; + + /** + * Sets or resets the configuration editor components + */ + public abstract void setAlias( Alias alias ); + + /** + * Saves the contents of the editor components to the configuration + */ + public abstract void save(); +} diff --git a/src/alias/AliasController.java b/src/alias/AliasController.java new file mode 100644 index 00000000..65844e57 --- /dev/null +++ b/src/alias/AliasController.java @@ -0,0 +1,287 @@ +package alias; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.DefaultTableCellRenderer; + +import net.coderazzi.filters.gui.AutoChoices; +import net.coderazzi.filters.gui.TableFilterHeader; +import net.miginfocom.swing.MigLayout; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import settings.SettingsManager; + +import com.jidesoft.swing.JideSplitPane; + +public class AliasController extends JPanel + implements ActionListener, ListSelectionListener +{ + private static final long serialVersionUID = 1L; + private final static Logger mLog = LoggerFactory.getLogger( AliasController.class ); + + private AliasModel mAliasModel; + private JTable mAliasTable; + private TableFilterHeader mTableFilterHeader; + private AliasEditor mEditor; + + private static final String NEW_ALIAS = "New"; + private static final String COPY_ALIAS = "Copy"; + private static final String DELETE_ALIAS = "Delete"; + + private JButton mNewButton = new JButton( NEW_ALIAS ); + private JButton mCopyButton = new JButton( COPY_ALIAS ); + private JButton mDeleteButton = new JButton( DELETE_ALIAS ); + + private IconCellRenderer mIconCellRenderer; + + public AliasController( AliasModel aliasModel, SettingsManager settingsManager ) + { + mAliasModel = aliasModel; + + mEditor = new AliasEditor( mAliasModel, settingsManager ); + mAliasModel.addAliasEventListener( mEditor ); + + mIconCellRenderer = new IconCellRenderer( settingsManager ); + + init(); + } + + private void init() + { + setLayout( new MigLayout( "insets 0 0 0 0", + "[grow,fill]", + "[grow,fill]") ); + + //System Configuration View and Editor + mAliasTable = new JTable( mAliasModel ); + mAliasTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); + mAliasTable.getSelectionModel().addListSelectionListener( this ); + mAliasTable.setAutoCreateRowSorter( true ); + + mAliasTable.getColumnModel().getColumn( AliasModel.COLUMN_COLOR ) + .setCellRenderer( new ColorCellRenderer() ); + + mAliasTable.getColumnModel().getColumn( AliasModel.COLUMN_ICON ) + .setCellRenderer( mIconCellRenderer ); + + mTableFilterHeader = new TableFilterHeader( mAliasTable, AutoChoices.ENABLED ); + mTableFilterHeader.setFilterOnUpdates( true ); + + JScrollPane tableScroller = new JScrollPane( mAliasTable ); + + JPanel buttonsPanel = new JPanel(); + + buttonsPanel.setLayout( + new MigLayout( "insets 0 0 0 0", "[grow,fill][grow,fill][grow,fill]", "[]") ); + + mNewButton.addActionListener( this ); + mNewButton.setToolTipText( "Adds a new alias" ); + buttonsPanel.add( mNewButton ); + + mCopyButton.addActionListener( this ); + mCopyButton.setEnabled( false ); + mCopyButton.setToolTipText( "Creates a copy of the currently selected alias and adds it" ); + buttonsPanel.add( mCopyButton ); + + mDeleteButton.addActionListener( this ); + mDeleteButton.setEnabled( false ); + mDeleteButton.setToolTipText( "Deletes the currently selected alias" ); + buttonsPanel.add( mDeleteButton ); + + JPanel listAndButtonsPanel = new JPanel(); + + listAndButtonsPanel.setLayout( + new MigLayout( "insets 0 0 0 0", "[grow,fill]", "[grow,fill][]") ); + + listAndButtonsPanel.add( tableScroller, "wrap" ); + listAndButtonsPanel.add( buttonsPanel ); + + JideSplitPane splitPane = new JideSplitPane( JideSplitPane.HORIZONTAL_SPLIT ); + splitPane.setDividerSize( 5 ); + splitPane.setShowGripper( true ); + splitPane.add( listAndButtonsPanel ); + splitPane.add( mEditor ); + + add( splitPane ); + } + + @Override + public void valueChanged( ListSelectionEvent event ) + { + //This limits event firing to only when selection is complete + if( !event.getValueIsAdjusting() ) + { + int selectedRow = mAliasTable.getSelectedRow(); + + if( selectedRow != -1 ) + { + int index = mAliasTable.convertRowIndexToModel( mAliasTable.getSelectedRow() ); + + Alias alias = mAliasModel.getAliasAtIndex( index ); + + if( alias != null ) + { + mEditor.setAlias( alias ); + mCopyButton.setEnabled( true ); + mDeleteButton.setEnabled( true ); + } + } + else + { + mEditor.setAlias( null ); + mCopyButton.setEnabled( false ); + mDeleteButton.setEnabled( false ); + } + } + } + + /** + * Adds the alias to the alias table/model and scrolls the view it + */ + private void addAlias( Alias alias ) + { + //HACK: when inserting a row to the model, the JTable gets + //notified and attempts to tell the coderazzi table filter + //adaptive choices filter to refresh before the table filter is + //notified of the row additions, causing an index out of bounds + //exception. We turn off adaptive choices temporarily, add the + //channel, and turn on adaptive choices again. + mTableFilterHeader.setAdaptiveChoices( false ); + + int index = mAliasModel.addAlias( alias ); + + mTableFilterHeader.setAdaptiveChoices( true ); + + if( index >= 0 ) + { + int translatedIndex = mAliasTable.convertRowIndexToView( index ); + mAliasTable.setRowSelectionInterval( translatedIndex, translatedIndex ); + mAliasTable.scrollRectToVisible( + new Rectangle( mAliasTable.getCellRect( translatedIndex, 0, true ) ) ); + } + } + + private Alias getSelectedAlias() + { + int index = mAliasTable.getSelectedRow(); + + if( index >= 0 ) + { + return mAliasModel.getAliasAtIndex( + mAliasTable.convertRowIndexToModel( index ) ); + } + + return null; + } + + /** + * Responds to New, Copy and Delete Channel button invocations + */ + @Override + public void actionPerformed( ActionEvent event ) + { + switch( event.getActionCommand() ) + { + case NEW_ALIAS: + addAlias( new Alias( "New Alias" ) ); + break; + case COPY_ALIAS: + Alias selected = getSelectedAlias(); + + if( selected != null ) + { +// addAlias( selected.copyOf() ); + } + break; + case DELETE_ALIAS: + Alias toDelete = getSelectedAlias(); + + if( toDelete != null ) + { + int choice = JOptionPane.showConfirmDialog( AliasController.this, + "Do you want to delete this alias?", "Delete Alias?", + JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE ); + + if( choice == JOptionPane.YES_OPTION ) + { + mAliasModel.removeAlias( toDelete ); + } + } + break; + default: + break; + } + } + + /** + * Colorizes the cell based on the cell's integer value + */ + public class ColorCellRenderer extends DefaultTableCellRenderer + { + private static final long serialVersionUID = 1L; + + @Override + public Component getTableCellRendererComponent( JTable table, + Object value, boolean isSelected, boolean hasFocus, int row, + int column ) + { + JLabel label = (JLabel)super.getTableCellRendererComponent( table, + value, isSelected, hasFocus, row, column ); + + label.setBackground( new Color( (int)value ) ); + + label.setText( "" ); + + return label; + } + } + + /** + * Displays cell's icon and name + */ + public class IconCellRenderer extends DefaultTableCellRenderer + { + private static final long serialVersionUID = 1L; + + private SettingsManager mSettingsManager; + + public IconCellRenderer( SettingsManager settingsManager ) + { + mSettingsManager = settingsManager; + } + + @Override + public Component getTableCellRendererComponent( JTable table, + Object value, boolean isSelected, boolean hasFocus, int row, + int column ) + { + JLabel label = (JLabel)super.getTableCellRendererComponent( table, + value, isSelected, hasFocus, row, column ); + + ImageIcon icon = mSettingsManager.getImageIcon( label.getText(), 12 ); + + if( icon != null ) + { + label.setIcon( icon ); + } + + return label; + } + } +} diff --git a/src/alias/AliasEditor.java b/src/alias/AliasEditor.java index cb4f9682..38e4c78d 100644 --- a/src/alias/AliasEditor.java +++ b/src/alias/AliasEditor.java @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer + * Copyright (C) 2014-2016 Dennis Sheirer * * 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 @@ -18,133 +18,76 @@ package alias; import java.awt.Color; -import java.awt.Dimension; -import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.BorderFactory; import javax.swing.JButton; -import javax.swing.JColorChooser; -import javax.swing.JComboBox; import javax.swing.JLabel; -import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.tree.TreePath; +import javax.swing.JSeparator; -import map.IconManager; -import map.MapIcon; -import map.MapIconListCellRenderer; import net.miginfocom.swing.MigLayout; +import sample.Listener; import settings.SettingsManager; -import controller.ConfigurableNode; +import alias.AliasEvent.Event; -public class AliasEditor extends JPanel implements ActionListener +import com.jidesoft.swing.JideTabbedPane; + +public class AliasEditor extends JPanel implements ActionListener, Listener { private static final long serialVersionUID = 1L; - private AliasNode mAliasNode; - private SettingsManager mSettingsManager; - - private JLabel mLabelName; - private JTextField mTextAlias; + private static final String DEFAULT_NAME = "select an alias"; - private JLabel mLabelMapColor; - private JButton mButtonColor; - private JComboBox mComboMapIcon; - private JButton mBtnIconManager; + private AliasModel mAliasModel; + + private JLabel mAliasLabel; + private AliasNameEditor mAliasNameEditor; - public AliasEditor( AliasNode aliasNode, - SettingsManager settingsManager ) + private Alias mAlias; + + + public AliasEditor( AliasModel aliasModel, SettingsManager settingsManager ) { - mAliasNode = aliasNode; - mSettingsManager = settingsManager; + mAliasModel = aliasModel; + mAliasNameEditor = new AliasNameEditor( mAliasModel, settingsManager ); initGUI(); } + + public void setAlias( Alias alias ) + { + mAlias = alias; + + if( mAlias != null ) + { + mAliasLabel.setText( alias.getName() ); + } + else + { + mAliasLabel.setText( DEFAULT_NAME ); + } + + mAliasNameEditor.setAlias( alias ); + + } private void initGUI() { - setLayout( new MigLayout( "", "[right][grow,fill]", "[][][][][][grow][]" ) ); + setLayout( new MigLayout( "fill,wrap 2", "[right][grow,fill]", "[][][][][grow,fill]" ) ); - setBorder( BorderFactory.createTitledBorder( "Alias" ) ); - - mLabelName = new JLabel( "Name:" ); - add( mLabelName ); + add( new JLabel( "Alias:" ) ); + mAliasLabel = new JLabel( DEFAULT_NAME ); + add( mAliasLabel ); - mTextAlias = new JTextField( mAliasNode.getAlias().getName() ); - add( mTextAlias, "wrap" ); - - mLabelMapColor = new JLabel( "Map Color:" ); - add( mLabelMapColor ); - - mButtonColor = new JButton( "Map Color" ); - mButtonColor.setBackground( mAliasNode.getAlias().getMapColor() ); - mButtonColor.setForeground( mAliasNode.getAlias().getMapColor() ); - mButtonColor.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - Color newColor = JColorChooser.showDialog( - AliasEditor.this, - "Choose color for map labels and routes", - mAliasNode.getAlias().getMapColor() ); - - mButtonColor.setForeground( newColor ); - mButtonColor.setBackground( newColor ); - } - } ); - add( mButtonColor, "wrap" ); + add( new JSeparator( JSeparator.HORIZONTAL ), "span,growx,push" ); - add( new JLabel( "Icon:" ) ); + JideTabbedPane tabs = new JideTabbedPane(); + tabs.setFont( this.getFont() ); + tabs.setForeground( Color.BLACK ); - mComboMapIcon = new JComboBox( mSettingsManager.getMapIcons() ); - - MapIconListCellRenderer renderer = new MapIconListCellRenderer(); - renderer.setPreferredSize( new Dimension( 200, 30 ) ); - mComboMapIcon.setRenderer( renderer ); - - String iconName = mAliasNode.getAlias().getIconName(); - - if( iconName == null ) - { - iconName = SettingsManager.DEFAULT_ICON; - } - - MapIcon savedIcon = mSettingsManager.getMapIcon( iconName ); - - if( savedIcon != null ) - { - mComboMapIcon.setSelectedItem( savedIcon ); - } - - add( mComboMapIcon, "wrap" ); - - //Dummy place holder - add( new JLabel() ); - - mBtnIconManager = new JButton( "Icon Manager" ); - mBtnIconManager.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) - { - final IconManager iconManager = - new IconManager( mSettingsManager, AliasEditor.this ); - - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - iconManager.setVisible( true ); - } - } ); - } - } ); - add( mBtnIconManager, "span 2,wrap" ); + tabs.addTab( "Alias", mAliasNameEditor ); + add( tabs, "span,grow" ); JButton btnSave = new JButton( "Save" ); btnSave.addActionListener( AliasEditor.this ); @@ -155,6 +98,16 @@ public class AliasEditor extends JPanel implements ActionListener add( btnReset, "wrap" ); } + @Override + public void receive( AliasEvent event ) + { + //If this is the currently displayed alias, reload it + if( mAlias != null && mAlias == event.getAlias() ) + { + setAlias( event.getAlias() ); + } + } + @Override public void actionPerformed( ActionEvent e ) { @@ -162,54 +115,14 @@ public class AliasEditor extends JPanel implements ActionListener if( command.contentEquals( "Save" ) ) { - String alias = mTextAlias.getText(); + mAliasNameEditor.save(); - if( alias != 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( selectedIcon != null ) - { - mAliasNode.getAlias().setIconName( selectedIcon.getName() ); - } - - mAliasNode.save(); - - mAliasNode.show(); - - if( expanded ) - { - mAliasNode.getModel().getTree() - .expandPath( new TreePath( mAliasNode ) ); - } - } - else - { - JOptionPane.showMessageDialog( AliasEditor.this, "Please enter an alias name" ); - } + //Broadcast an alias change event to save the updates + mAliasModel.broadcast( new AliasEvent( mAlias, Event.CHANGE ) ); } else if( command.contentEquals( "Reset" ) ) { - mTextAlias.setText( mAliasNode.getAlias().getName() ); - - mButtonColor.setBackground( mAliasNode.getAlias().getMapColor() ); - mButtonColor.setForeground( mAliasNode.getAlias().getMapColor() ); - - MapIcon savedIcon = mSettingsManager - .getMapIcon( mAliasNode.getAlias().getIconName() ); - - mComboMapIcon.setSelectedItem( savedIcon ); + setAlias( mAlias ); } - - mAliasNode.refresh(); } } diff --git a/src/alias/AliasModel.java b/src/alias/AliasModel.java index a9fe2540..4a1d11b1 100644 --- a/src/alias/AliasModel.java +++ b/src/alias/AliasModel.java @@ -39,6 +39,12 @@ import sample.Listener; public class AliasModel implements TableModel { private final static Logger mLog = LoggerFactory.getLogger( AliasModel.class ); + + public static final int COLUMN_LIST = 0; + public static final int COLUMN_GROUP = 1; + public static final int COLUMN_NAME = 2; + public static final int COLUMN_ICON = 3; + public static final int COLUMN_COLOR = 4; private List mAliases = new ArrayList<>(); private List mTableModelListeners = new CopyOnWriteArrayList<>(); @@ -181,15 +187,15 @@ public class AliasModel implements TableModel { switch( columnIndex ) { - case 0: + case COLUMN_LIST: return "List"; - case 1: + case COLUMN_GROUP: return "Group"; - case 2: + case COLUMN_NAME: return "Name"; - case 3: + case COLUMN_ICON: return "Icon"; - case 4: + case COLUMN_COLOR: return "Color"; } @@ -199,6 +205,11 @@ public class AliasModel implements TableModel @Override public Class getColumnClass( int columnIndex ) { + if( columnIndex == COLUMN_COLOR ) + { + return Integer.class; + } + return String.class; } @@ -215,15 +226,15 @@ public class AliasModel implements TableModel switch( columnIndex ) { - case 0: + case COLUMN_LIST: return alias.getList(); - case 1: + case COLUMN_GROUP: return alias.getGroup(); - case 2: + case COLUMN_NAME: return alias.getName(); - case 3: + case COLUMN_ICON: return alias.getIconName(); - case 4: + case COLUMN_COLOR: return alias.getColor(); } diff --git a/src/alias/AliasNameEditor.java b/src/alias/AliasNameEditor.java new file mode 100644 index 00000000..742fde37 --- /dev/null +++ b/src/alias/AliasNameEditor.java @@ -0,0 +1,232 @@ +package alias; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +import javax.swing.ComboBoxModel; +import javax.swing.DefaultComboBoxModel; +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; +import map.MapIcon; +import map.MapIconListCellRenderer; +import net.miginfocom.swing.MigLayout; +import settings.SettingsManager; + +public class AliasNameEditor extends AliasConfigurationEditor +{ + private static final long serialVersionUID = 1L; + + private static ComboBoxModel EMPTY_MODEL = new DefaultComboBoxModel<>(); + + private JComboBox mListCombo = new JComboBox<>( EMPTY_MODEL ); + private JComboBox mGroupCombo = new JComboBox<>( EMPTY_MODEL ); + private JTextField mName; + + private JLabel mLabelMapColor; + private JButton mButtonColor; + private JComboBox mComboMapIcon; + private JButton mBtnIconManager; + + private Alias mAlias; + private AliasModel mAliasModel; + private SettingsManager mSettingsManager; + + public AliasNameEditor( AliasModel aliasModel, SettingsManager settingsManager ) + { + mAliasModel = aliasModel; + mSettingsManager = settingsManager; + init(); + } + + private void init() + { + setLayout( new MigLayout( "fill,wrap 2", "[right][grow,fill]", "[][][][][][grow][]" ) ); + + add( new JLabel( "List:" ) ); + mListCombo.setEditable( true ); + add( mListCombo, "wrap" ); + + add( new JLabel( "Group:" ) ); + mGroupCombo.setEditable( true ); + add( mGroupCombo, "wrap" ); + + add( new JLabel( "Name:" ) ); + mName = new JTextField(); + add( mName, "wrap" ); + + add( new JLabel( "Color:" ) ); + + mButtonColor = new JButton( "Select ..." ); + mButtonColor.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + Color newColor = JColorChooser.showDialog( + AliasNameEditor.this, + "Choose color for this alias", + ( mAlias != null ? mAlias.getMapColor() : null ) ); + + if( newColor != null ) + { + mButtonColor.setForeground( newColor ); + mButtonColor.setBackground( newColor ); + } + } + } ); + add( mButtonColor, "wrap" ); + + add( new JLabel( "Icon:" ) ); + + mComboMapIcon = new JComboBox( mSettingsManager.getMapIcons() ); + + MapIconListCellRenderer renderer = new MapIconListCellRenderer(); + renderer.setPreferredSize( new Dimension( 200, 30 ) ); + mComboMapIcon.setRenderer( renderer ); + + add( mComboMapIcon, "wrap" ); + + //Dummy place holder + add( new JLabel() ); + + mBtnIconManager = new JButton( "Icon Manager" ); + mBtnIconManager.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent arg0 ) + { + final IconManager iconManager = + new IconManager( mSettingsManager, AliasNameEditor.this ); + + EventQueue.invokeLater( new Runnable() + { + @Override + public void run() + { + iconManager.setVisible( true ); + } + } ); + } + } ); + add( mBtnIconManager, "span 2,wrap" ); + + } + + @Override + public void setAlias( Alias alias ) + { + mAlias = alias; + + if( mAlias != null ) + { + mName.setText( alias.getName() ); + + List listNames = mAliasModel.getListNames(); + + if( listNames.isEmpty() ) + { + mListCombo.setModel( EMPTY_MODEL ); + } + else + { + mListCombo.setModel( new DefaultComboBoxModel( + listNames.toArray( new String[ listNames.size() ] ) ) );; + } + + mListCombo.setSelectedItem( mAlias.getList() ); + + List groupNames = mAliasModel.getGroupNames( mAlias.getList() ); + + if( groupNames.isEmpty() ) + { + mGroupCombo.setModel( EMPTY_MODEL ); + } + else + { + mGroupCombo.setModel( new DefaultComboBoxModel( + groupNames.toArray( new String[ groupNames.size() ] ) ) );; + } + + mGroupCombo.setSelectedItem( mAlias.getGroup() ); + + Color color = mAlias.getMapColor(); + + mButtonColor.setBackground( color ); + mButtonColor.setForeground( color ); + + String iconName = mAlias.getIconName(); + + if( iconName == null ) + { + iconName = SettingsManager.DEFAULT_ICON; + } + + MapIcon savedIcon = mSettingsManager.getMapIcon( iconName ); + + if( savedIcon != null ) + { + mComboMapIcon.setSelectedItem( savedIcon ); + } + } + else + { + mListCombo.setModel( EMPTY_MODEL ); + mGroupCombo.setModel( EMPTY_MODEL ); + mName.setText( null ); + + mButtonColor.setBackground( getBackground() ); + mButtonColor.setForeground( getForeground() ); + } + } + + @Override + public void save() + { + // TODO Auto-generated method stub + String alias = mName.getText(); + + if( alias != 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( selectedIcon != null ) +// { +// mAliasNode.getAlias().setIconName( selectedIcon.getName() ); +// } +// +// mAliasNode.save(); +// +// mAliasNode.show(); +// +// if( expanded ) +// { +// mAliasNode.getModel().getTree() +// .expandPath( new TreePath( mAliasNode ) ); +// } + } + else + { + JOptionPane.showMessageDialog( AliasNameEditor.this, "Please enter an alias name" ); + } + + } +} diff --git a/src/alias/AliasNode.java b/src/alias/AliasNode.java index 070e3b60..7346bb4c 100644 --- a/src/alias/AliasNode.java +++ b/src/alias/AliasNode.java @@ -81,7 +81,8 @@ public class AliasNode extends ConfigurableNode @Override public JPanel getEditor() { - return new AliasEditor( this, mSettingsManager ); + return null; +// return new AliasEditor( this, mSettingsManager ); } public Alias getAlias() diff --git a/src/controller/ControllerPanel.java b/src/controller/ControllerPanel.java index 8cb4232c..ef7d8619 100644 --- a/src/controller/ControllerPanel.java +++ b/src/controller/ControllerPanel.java @@ -37,6 +37,8 @@ import playlist.PlaylistManager; import settings.SettingsManager; import source.SourceManager; import spectrum.ChannelSpectrumPanel; +import alias.AliasController; +import alias.AliasModel; import audio.AudioManager; import audio.AudioPanel; @@ -58,8 +60,10 @@ public class ControllerPanel extends JPanel private MessageActivityPanel mMessageActivityPanel; private ChannelSpectrumPanel mChannelSpectrumPanel; + + private AliasController mAliasController; - private ChannelController mPlaylistEditor; + private ChannelController mChannelController; private JideTabbedPane mTabbedPane; @@ -77,6 +81,7 @@ public class ControllerPanel extends JPanel public ControllerPanel( AudioManager audioManager, ConfigurationControllerModel controller, + AliasModel aliasModel, ChannelModel channelModel, ChannelProcessingManager channelProcessingManager, MapService mapService, @@ -103,7 +108,9 @@ public class ControllerPanel extends JPanel mChannelStateList = new ChannelList( channelModel, channelProcessingManager, playlistManager, mSettingsManager ); - mPlaylistEditor = new ChannelController( channelModel, playlistManager, sourceManager ); + mChannelController = new ChannelController( channelModel, playlistManager, sourceManager ); + + mAliasController = new AliasController( aliasModel, mSettingsManager ); init(); } @@ -129,7 +136,8 @@ public class ControllerPanel extends JPanel mTabbedPane = new JideTabbedPane(); mTabbedPane.setFont( this.getFont() ); mTabbedPane.setForeground( Color.BLACK ); - mTabbedPane.addTab( "Channels", mPlaylistEditor ); + mTabbedPane.addTab( "Channels", mChannelController ); + mTabbedPane.addTab( "Aliases", mAliasController ); mTabbedPane.addTab( "Configuration", mSystemControlSplitPane ); mTabbedPane.addTab( "Channel Spectrum", mChannelSpectrumPanel ); mTabbedPane.addTab( "Events", mCallEventPanel ); diff --git a/src/controller/channel/ChannelController.java b/src/controller/channel/ChannelController.java index dbddfe84..88b9fe9e 100644 --- a/src/controller/channel/ChannelController.java +++ b/src/controller/channel/ChannelController.java @@ -140,7 +140,7 @@ public class ChannelController extends JPanel } /** - * Selects the channel's table row and scrolls the table's viewport to show it + * Adds the channel to the channel model/table and scrolls to view it */ private void addChannel( Channel channel ) { diff --git a/src/controller/channel/ChannelEditor.java b/src/controller/channel/ChannelEditor.java index 4e6c85e9..2e77fcab 100644 --- a/src/controller/channel/ChannelEditor.java +++ b/src/controller/channel/ChannelEditor.java @@ -120,7 +120,7 @@ public class ChannelEditor extends JPanel private void initGUI() { - setLayout( new MigLayout( "fill,wrap 2", "[right,grow][grow]", "[][][][][grow][]" ) ); + setLayout( new MigLayout( "fill,wrap 2", "[right,grow][grow]", "[][][][][grow]" ) ); mEnableButton.addActionListener( this ); mEnableButton.setEnabled( false ); diff --git a/src/gui/SDRTrunk.java b/src/gui/SDRTrunk.java index 41f5987e..473ea3e7 100644 --- a/src/gui/SDRTrunk.java +++ b/src/gui/SDRTrunk.java @@ -161,7 +161,7 @@ public class SDRTrunk playlistManager, mSettingsManager, sourceManager ); mControllerPanel = new ControllerPanel( audioManager, configurationControllerModel, - channelModel, channelProcessingManager, mapService, playlistManager, + aliasModel, channelModel, channelProcessingManager, mapService, playlistManager, mSettingsManager, sourceManager ); mSpectralPanel = new SpectralDisplayPanel( configurationControllerModel,