diff --git a/src/alias/AliasController.java b/src/alias/AliasController.java index 0619672c..7dc27ccf 100644 --- a/src/alias/AliasController.java +++ b/src/alias/AliasController.java @@ -1,369 +1,356 @@ package alias; import audio.broadcast.BroadcastModel; +import com.jidesoft.swing.JideSplitPane; import gui.editor.Editor; +import icon.IconManager; +import net.coderazzi.filters.gui.AutoChoices; +import net.coderazzi.filters.gui.TableFilterHeader; +import net.miginfocom.swing.MigLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Rectangle; +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.DefaultTableCellRenderer; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; -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 settings.SettingsManager; - -import com.jidesoft.swing.JideSplitPane; - -public class AliasController extends JPanel - implements ActionListener, ListSelectionListener +public class AliasController extends JPanel + implements ActionListener, ListSelectionListener { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private AliasModel mAliasModel; - private JTable mAliasTable; - private TableFilterHeader mTableFilterHeader; - private AliasEditor mAliasEditor; - private MultipleAliasEditor mMultipleAliasEditor; - private JideSplitPane mSplitPane; - - 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; + private AliasModel mAliasModel; + private JTable mAliasTable; + private TableFilterHeader mTableFilterHeader; + private AliasEditor mAliasEditor; + private MultipleAliasEditor mMultipleAliasEditor; + private JideSplitPane mSplitPane; - public AliasController(AliasModel aliasModel, BroadcastModel broadcastModel, SettingsManager settingsManager ) - { - mAliasModel = aliasModel; + private static final String NEW_ALIAS = "New"; + private static final String COPY_ALIAS = "Copy"; + private static final String DELETE_ALIAS = "Delete"; - mAliasEditor = new AliasEditor( mAliasModel, broadcastModel, settingsManager ); - mMultipleAliasEditor = new MultipleAliasEditor( mAliasModel, broadcastModel, settingsManager ); + private JButton mNewButton = new JButton(NEW_ALIAS); + private JButton mCopyButton = new JButton(COPY_ALIAS); + private JButton mDeleteButton = new JButton(DELETE_ALIAS); - mIconCellRenderer = new IconCellRenderer( settingsManager ); - - init(); - - mAliasModel.addListener( mAliasEditor ); - } - - private void init() - { - setLayout( new MigLayout( "insets 0 0 0 0", - "[grow,fill]", - "[grow,fill]") ); + private IconCellRenderer mIconCellRenderer; - //System Configuration View and Editor - mAliasTable = new JTable( mAliasModel ); - mAliasTable.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_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 ); + public AliasController(AliasModel aliasModel, BroadcastModel broadcastModel, IconManager iconManager) + { + mAliasModel = aliasModel; - mTableFilterHeader = new TableFilterHeader( mAliasTable, AutoChoices.ENABLED ); - mTableFilterHeader.setFilterOnUpdates( true ); - - JScrollPane tableScroller = new JScrollPane( mAliasTable ); + mAliasEditor = new AliasEditor(mAliasModel, broadcastModel, iconManager); + mMultipleAliasEditor = new MultipleAliasEditor(mAliasModel, broadcastModel, iconManager); - JPanel buttonsPanel = new JPanel(); - - buttonsPanel.setLayout( - new MigLayout( "insets 0 0 0 0", "[grow,fill][grow,fill][grow,fill]", "[]") ); + mIconCellRenderer = new IconCellRenderer(iconManager); - 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 ); + init(); - mDeleteButton.addActionListener( this ); - mDeleteButton.setEnabled( false ); - mDeleteButton.setToolTipText( "Deletes the currently selected alias" ); - buttonsPanel.add( mDeleteButton ); - - JPanel listAndButtonsPanel = new JPanel(); + mAliasModel.addListener(mAliasEditor); + } - listAndButtonsPanel.setLayout( - new MigLayout( "insets 0 0 0 0", "[grow,fill]", "[grow,fill][]") ); + private void init() + { + setLayout(new MigLayout("insets 0 0 0 0", + "[grow,fill]", + "[grow,fill]")); - listAndButtonsPanel.add( tableScroller, "wrap" ); - listAndButtonsPanel.add( buttonsPanel ); - - mSplitPane = new JideSplitPane( JideSplitPane.HORIZONTAL_SPLIT ); - mSplitPane.setDividerSize( 5 ); - mSplitPane.setShowGripper( true ); - mSplitPane.add( listAndButtonsPanel ); - mSplitPane.add( mAliasEditor ); + //System Configuration View and Editor + mAliasTable = new JTable(mAliasModel); + mAliasTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + mAliasTable.getSelectionModel().addListSelectionListener(this); + mAliasTable.setAutoCreateRowSorter(true); - add( mSplitPane ); - } + mAliasTable.getColumnModel().getColumn(AliasModel.COLUMN_COLOR) + .setCellRenderer(new ColorCellRenderer()); - /** - * Sets the editor argument as the currently visible alias editor - */ - private void setEditor( Editor editor ) - { - if( mSplitPane.getComponentCount() == 3 ) - { - Component component = mSplitPane.getComponent( 2 ); - - if( component instanceof Editor && component != editor ) - { - //Get current divider location so that we can reapply it after - //changing out the editors, so that the interface doesn't move - int location = mSplitPane.getDividerLocation( 0 ); - - ((Editor)component).setItem( null ); - - mSplitPane.remove( component ); - editor.setPreferredSize( new Dimension( 100, 100 ) ); - mSplitPane.add( editor ); - - mSplitPane.validate(); - mSplitPane.setDividerLocation( 0, location ); - mSplitPane.repaint(); - } - } - } - - private Alias getAlias( int selectedRow ) - { - if( selectedRow >= 0 ) - { - int index = mAliasTable.convertRowIndexToModel( selectedRow ); - - return mAliasModel.getAliasAtIndex( index ); - } - - return null; - } + mAliasTable.getColumnModel().getColumn(AliasModel.COLUMN_ICON) + .setCellRenderer(mIconCellRenderer); - @Override - public void valueChanged( ListSelectionEvent event ) - { - //Limits event firing to only when selection is complete - if( !event.getValueIsAdjusting() ) - { - int[] selectedRows = mAliasTable.getSelectedRows(); + mTableFilterHeader = new TableFilterHeader(mAliasTable, AutoChoices.ENABLED); + mTableFilterHeader.setFilterOnUpdates(true); - if( selectedRows.length == 0 ) - { - mAliasEditor.setItem( null ); - mCopyButton.setEnabled( false ); - mDeleteButton.setEnabled( false ); - } - else if( selectedRows.length == 1 ) - { - setEditor( mAliasEditor ); - - Alias selectedAlias = getAlias( selectedRows[ 0 ] ); - - mAliasEditor.setItem( selectedAlias ); - - if( selectedAlias != null ) - { - mCopyButton.setEnabled( true ); - mDeleteButton.setEnabled( true ); - } - else - { - mCopyButton.setEnabled( false ); - mDeleteButton.setEnabled( false ); - } - } - else - { - setEditor( mMultipleAliasEditor ); - - mCopyButton.setEnabled( true ); - mDeleteButton.setEnabled( true ); + JScrollPane tableScroller = new JScrollPane(mAliasTable); - List selectedAliases = new ArrayList(); - - for( int selectedRow: selectedRows ) - { - Alias alias = getAlias( selectedRow ); + JPanel buttonsPanel = new JPanel(); - selectedAliases.add( alias ); - } - - mMultipleAliasEditor.setItem( selectedAliases ); - } - } - } + buttonsPanel.setLayout( + new MigLayout("insets 0 0 0 0", "[grow,fill][grow,fill][grow,fill]", "[]")); - /** - * 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 ); + mNewButton.addActionListener(this); + mNewButton.setToolTipText("Adds a new alias"); + buttonsPanel.add(mNewButton); - mTableFilterHeader.setAdaptiveChoices( true ); + mCopyButton.addActionListener(this); + mCopyButton.setEnabled(false); + mCopyButton.setToolTipText("Creates a copy of the currently selected alias and adds it"); + buttonsPanel.add(mCopyButton); - if( index >= 0 ) - { - int translatedIndex = mAliasTable.convertRowIndexToView( index ); - mAliasTable.setRowSelectionInterval( translatedIndex, translatedIndex ); - mAliasTable.scrollRectToVisible( - new Rectangle( mAliasTable.getCellRect( translatedIndex, 0, true ) ) ); - } - } - - private List getSelectedAliases() - { - List selected = new ArrayList<>(); - - int[] rows = mAliasTable.getSelectedRows(); + mDeleteButton.addActionListener(this); + mDeleteButton.setEnabled(false); + mDeleteButton.setToolTipText("Deletes the currently selected alias"); + buttonsPanel.add(mDeleteButton); - for( int row: rows ) - { - if( row >= 0 ) - { - Alias alias = mAliasModel.getAliasAtIndex( mAliasTable.convertRowIndexToModel( row ) ); - - if( alias != null ) - { - selected.add( alias ); - } - } - } - - return selected; - } + JPanel listAndButtonsPanel = new JPanel(); - /** - * 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: - for( Alias alias: getSelectedAliases() ) - { - addAlias( AliasFactory.copyOf( alias ) ); - } - break; - case DELETE_ALIAS: - List toDelete = getSelectedAliases(); + listAndButtonsPanel.setLayout( + new MigLayout("insets 0 0 0 0", "[grow,fill]", "[grow,fill][]")); - if( toDelete != null && !toDelete.isEmpty() ) - { - String title = toDelete.size() == 1 ? "Delete Alias?" : "Delete Aliases?"; - String prompt = toDelete.size() == 1 ? "Do you want to delete this alias?" : - "Do you want to delete these " + toDelete.size() + " aliases?"; - - int choice = JOptionPane.showConfirmDialog( AliasController.this, - prompt, title, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE ); - - if( choice == JOptionPane.YES_OPTION ) - { - for( Alias alias: toDelete ) - { - mAliasModel.removeAlias( alias ); - } - } - } - break; - default: - break; - } - } + listAndButtonsPanel.add(tableScroller, "wrap"); + listAndButtonsPanel.add(buttonsPanel); - /** - * Colorizes the cell based on the cell's integer value - */ - public class ColorCellRenderer extends DefaultTableCellRenderer - { - private static final long serialVersionUID = 1L; + mSplitPane = new JideSplitPane(JideSplitPane.HORIZONTAL_SPLIT); + mSplitPane.setDividerSize(5); + mSplitPane.setShowGripper(true); + mSplitPane.add(listAndButtonsPanel); + mSplitPane.add(mAliasEditor); - @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 ); + add(mSplitPane); + } - 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; - } + /** + * Sets the editor argument as the currently visible alias editor + */ + private void setEditor(Editor editor) + { + if(mSplitPane.getComponentCount() == 3) + { + Component component = mSplitPane.getComponent(2); - @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 ); + if(component instanceof Editor && component != editor) + { + //Get current divider location so that we can reapply it after + //changing out the editors, so that the interface doesn't move + int location = mSplitPane.getDividerLocation(0); - ImageIcon icon = mSettingsManager.getImageIcon( label.getText(), 12 ); + ((Editor) component).setItem(null); - if( icon != null ) - { - label.setIcon( icon ); - } - - return label; - } - } + mSplitPane.remove(component); + editor.setPreferredSize(new Dimension(100, 100)); + mSplitPane.add(editor); + + mSplitPane.validate(); + mSplitPane.setDividerLocation(0, location); + mSplitPane.repaint(); + } + } + } + + private Alias getAlias(int selectedRow) + { + if(selectedRow >= 0) + { + int index = mAliasTable.convertRowIndexToModel(selectedRow); + + return mAliasModel.getAliasAtIndex(index); + } + + return null; + } + + @Override + public void valueChanged(ListSelectionEvent event) + { + //Limits event firing to only when selection is complete + if(!event.getValueIsAdjusting()) + { + int[] selectedRows = mAliasTable.getSelectedRows(); + + if(selectedRows.length == 0) + { + mAliasEditor.setItem(null); + mCopyButton.setEnabled(false); + mDeleteButton.setEnabled(false); + } + else if(selectedRows.length == 1) + { + setEditor(mAliasEditor); + + Alias selectedAlias = getAlias(selectedRows[0]); + + mAliasEditor.setItem(selectedAlias); + + if(selectedAlias != null) + { + mCopyButton.setEnabled(true); + mDeleteButton.setEnabled(true); + } + else + { + mCopyButton.setEnabled(false); + mDeleteButton.setEnabled(false); + } + } + else + { + setEditor(mMultipleAliasEditor); + + mCopyButton.setEnabled(true); + mDeleteButton.setEnabled(true); + + List selectedAliases = new ArrayList(); + + for(int selectedRow : selectedRows) + { + Alias alias = getAlias(selectedRow); + + selectedAliases.add(alias); + } + + mMultipleAliasEditor.setItem(selectedAliases); + } + } + } + + /** + * 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 List getSelectedAliases() + { + List selected = new ArrayList<>(); + + int[] rows = mAliasTable.getSelectedRows(); + + for(int row : rows) + { + if(row >= 0) + { + Alias alias = mAliasModel.getAliasAtIndex(mAliasTable.convertRowIndexToModel(row)); + + if(alias != null) + { + selected.add(alias); + } + } + } + + return selected; + } + + /** + * 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: + for(Alias alias : getSelectedAliases()) + { + addAlias(AliasFactory.copyOf(alias)); + } + break; + case DELETE_ALIAS: + List toDelete = getSelectedAliases(); + + if(toDelete != null && !toDelete.isEmpty()) + { + String title = toDelete.size() == 1 ? "Delete Alias?" : "Delete Aliases?"; + String prompt = toDelete.size() == 1 ? "Do you want to delete this alias?" : + "Do you want to delete these " + toDelete.size() + " aliases?"; + + int choice = JOptionPane.showConfirmDialog(AliasController.this, + prompt, title, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + + if(choice == JOptionPane.YES_OPTION) + { + for(Alias alias : toDelete) + { + mAliasModel.removeAlias(alias); + } + } + } + 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 IconManager mIconManager; + + public IconCellRenderer(IconManager iconManager) + { + mIconManager = iconManager; + } + + @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 = mIconManager.getIcon(label.getText(), 12); + + if(icon != null) + { + label.setIcon(icon); + } + + return label; + } + } } diff --git a/src/alias/AliasEditor.java b/src/alias/AliasEditor.java index 9cdd4632..706ef5e4 100644 --- a/src/alias/AliasEditor.java +++ b/src/alias/AliasEditor.java @@ -28,6 +28,7 @@ import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JSeparator; +import icon.IconManager; import net.miginfocom.swing.MigLayout; import sample.Listener; import settings.SettingsManager; @@ -50,10 +51,10 @@ public class AliasEditor extends Editor private AliasIdentifierEditor mAliasIdentifierEditor; private AliasActionEditor mAliasActionEditor; - public AliasEditor(AliasModel aliasModel, BroadcastModel broadcastModel, SettingsManager settingsManager ) + public AliasEditor(AliasModel aliasModel, BroadcastModel broadcastModel, IconManager iconManager ) { mAliasModel = aliasModel; - mAliasNameEditor = new AliasNameEditor( mAliasModel, settingsManager ); + mAliasNameEditor = new AliasNameEditor( mAliasModel, iconManager ); mAliasIdentifierEditor = new AliasIdentifierEditor( aliasModel, broadcastModel ); mAliasActionEditor = new AliasActionEditor( aliasModel ); diff --git a/src/alias/AliasNameEditor.java b/src/alias/AliasNameEditor.java index f628cd59..70b5cd66 100644 --- a/src/alias/AliasNameEditor.java +++ b/src/alias/AliasNameEditor.java @@ -1,291 +1,333 @@ +/******************************************************************************* + * sdrtrunk + * Copyright (C) 2014-2017 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 alias.AliasEvent.Event; import gui.editor.Editor; +import icon.Icon; +import icon.IconListCellRenderer; +import icon.IconManager; +import icon.IconTableModel; +import net.miginfocom.swing.MigLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.EventQueue; +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import java.awt.*; 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.JTextField; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; - -import map.IconManager; -import map.MapIcon; -import map.MapIconListCellRenderer; -import net.miginfocom.swing.MigLayout; -import settings.SettingsManager; -import alias.AliasEvent.Event; - public class AliasNameEditor extends Editor { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private static ComboBoxModel EMPTY_MODEL = new DefaultComboBoxModel<>(); + private static ComboBoxModel EMPTY_MODEL = new DefaultComboBoxModel<>(); - private JComboBox mListCombo = new JComboBox<>( EMPTY_MODEL ); - private JComboBox mGroupCombo = new JComboBox<>( EMPTY_MODEL ); - private JComboBox mMapIconCombo; + private JComboBox mListCombo = new JComboBox<>(EMPTY_MODEL); + private JComboBox mGroupCombo = new JComboBox<>(EMPTY_MODEL); + private JComboBox mIconCombo; private JTextField mName; private JButton mButtonColor; private JButton mBtnIconManager; - + 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]" ) ); + private IconManager mIconManager; - add( new JLabel( "Name:" ) ); - mName = new JTextField(); - mName.getDocument().addDocumentListener( new DocumentListener() - { - @Override - public void removeUpdate( DocumentEvent e ) - { - setModified( true ); - } - - @Override - public void insertUpdate( DocumentEvent e ) - { - setModified( true ); - } - - @Override - public void changedUpdate( DocumentEvent e ){} - } ); - add( mName, "wrap" ); + public AliasNameEditor(AliasModel aliasModel, IconManager iconManager) + { + mAliasModel = aliasModel; + mIconManager = iconManager; - 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() ] ) ) );; - } - } - - setModified( true ); - } - } ); - add( mListCombo, "wrap" ); - - add( new JLabel( "Group:" ) ); - mGroupCombo.setEditable( true ); - mGroupCombo.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - setModified( true ); - } - } ); - add( mGroupCombo, "wrap" ); - - add( new JLabel( "Color:" ) ); - - mButtonColor = new JButton( "Select ..." ); - mButtonColor.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) + mIconManager.getModel().addTableModelListener(new TableModelListener() + { + @Override + public void tableChanged(TableModelEvent e) { - Color newColor = JColorChooser.showDialog( - AliasNameEditor.this, - "Choose color for this alias", - ( hasItem() ? getItem().getMapColor() : null ) ); - - if( newColor != null ) - { - mButtonColor.setForeground( newColor ); - mButtonColor.setBackground( newColor ); - - setModified( true ); - } + refreshIcons(); } - } ); - add( mButtonColor, "wrap" ); - - add( new JLabel( "Icon:" ) ); - - mMapIconCombo = new JComboBox( mSettingsManager.getMapIcons() ); + }); - MapIconListCellRenderer renderer = new MapIconListCellRenderer(); - renderer.setPreferredSize( new Dimension( 200, 30 ) ); - mMapIconCombo.setRenderer( renderer ); - mMapIconCombo.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - setModified( true ); - } - } ); + init(); + } - add( mMapIconCombo, "wrap" ); + private void init() + { + setLayout(new MigLayout("fill,wrap 2", "[right][grow,fill]", "[][][][][][][grow]")); - //Dummy place holder - add( new JLabel() ); - - mBtnIconManager = new JButton( "Icon Manager" ); - mBtnIconManager.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent arg0 ) + add(new JLabel("Name:")); + mName = new JTextField(); + mName.getDocument().addDocumentListener(new DocumentListener() + { + @Override + public void removeUpdate(DocumentEvent e) { - final IconManager iconManager = - new IconManager( mSettingsManager, AliasNameEditor.this ); - - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - iconManager.setVisible( true ); - } - } ); + setModified(true); } - } ); - - add( mBtnIconManager, "span 2,wrap" ); - setModified( false ); - } + @Override + public void insertUpdate(DocumentEvent e) + { + setModified(true); + } - @Override - public void setItem( Alias alias ) - { - super.setItem( alias ); - - if( hasItem() ) - { - 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( alias.getList() ); - - List groupNames = mAliasModel.getGroupNames( alias.getList() ); - - if( groupNames.isEmpty() ) - { - mGroupCombo.setModel( EMPTY_MODEL ); - } - else - { - mGroupCombo.setModel( new DefaultComboBoxModel( - groupNames.toArray( new String[ groupNames.size() ] ) ) );; - } - - mGroupCombo.setSelectedItem( alias.getGroup() ); - - Color color = alias.getMapColor(); - - mButtonColor.setBackground( color ); - mButtonColor.setForeground( color ); - - String iconName = alias.getIconName(); - - if( iconName == null ) - { - iconName = SettingsManager.DEFAULT_ICON; - } - - MapIcon savedIcon = mSettingsManager.getMapIcon( iconName ); - - if( savedIcon != null ) - { - mMapIconCombo.setSelectedItem( savedIcon ); - } - } - else - { - mListCombo.setModel( EMPTY_MODEL ); - mGroupCombo.setModel( EMPTY_MODEL ); - mName.setText( null ); - - mButtonColor.setBackground( getBackground() ); - mButtonColor.setForeground( getForeground() ); - } - - repaint(); - - setModified( false ); - } + @Override + public void changedUpdate(DocumentEvent e) + { + } + }); + add(mName, "wrap"); - @Override - public void save() - { - if( hasItem() && isModified() ) - { - Alias alias = getItem(); - - if( mListCombo.getSelectedItem() != null ) - { - alias.setList( (String)mListCombo.getSelectedItem() ); - } - - if( mGroupCombo.getSelectedItem() != null ) - { - alias.setGroup( (String)mGroupCombo.getSelectedItem() ); - } + 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()); - alias.setName( mName.getText() ); + if(groups.isEmpty()) + { + mGroupCombo.setModel(EMPTY_MODEL); + } + else + { + mGroupCombo.setModel(new DefaultComboBoxModel( + groups.toArray(new String[groups.size()]))); + ; + } + } - alias.setColor( mButtonColor.getBackground().getRGB() ); + setModified(true); + } + }); + add(mListCombo, "wrap"); - if( mMapIconCombo.getSelectedItem() != null ) - { - alias.setIconName( ((MapIcon)mMapIconCombo.getSelectedItem()).getName() ); - } - - setModified( false ); + add(new JLabel("Group:")); + mGroupCombo.setEditable(true); + mGroupCombo.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + setModified(true); + } + }); + add(mGroupCombo, "wrap"); - //Broadcast an alias change event to save the updates - mAliasModel.broadcast( new AliasEvent( getItem(), Event.CHANGE ) ); - } - } + 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", + (hasItem() ? getItem().getMapColor() : null)); + + if(newColor != null) + { + mButtonColor.setForeground(newColor); + mButtonColor.setBackground(newColor); + + setModified(true); + } + } + }); + add(mButtonColor, "wrap"); + + add(new JLabel("Icon:")); + + mIconCombo = new JComboBox(mIconManager.getIcons()); + + IconListCellRenderer renderer = new IconListCellRenderer(mIconManager); + renderer.setPreferredSize(new Dimension(200, 30)); + mIconCombo.setRenderer(renderer); + mIconCombo.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + setModified(true); + } + }); + + add(mIconCombo, "wrap"); + + //Dummy place holder + add(new JLabel()); + + mBtnIconManager = new JButton("Icon Manager"); + mBtnIconManager.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent arg0) + { + mIconManager.showEditor(AliasNameEditor.this); + } + }); + + add(mBtnIconManager, "span 2,wrap"); + + setModified(false); + } + + private void refreshIcons() + { + if(mIconCombo != null) + { + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + mIconCombo.setModel(new DefaultComboBoxModel<>(mIconManager.getIcons())); + + if(hasItem()) + { + String iconName = getItem().getIconName(); + Icon aliasIcon = mIconManager.getModel().getIcon(iconName); + + if(aliasIcon != null) + { + mIconCombo.setSelectedItem(aliasIcon); + } + } + } + }); + } + } + + @Override + public void setItem(Alias alias) + { + super.setItem(alias); + + if(hasItem()) + { + mName.setText(alias.getName()); + + mIconCombo.setModel(new DefaultComboBoxModel<>(mIconManager.getIcons())); + + List listNames = mAliasModel.getListNames(); + + if(listNames.isEmpty()) + { + mListCombo.setModel(EMPTY_MODEL); + } + else + { + mListCombo.setModel(new DefaultComboBoxModel( + listNames.toArray(new String[listNames.size()]))); + ; + } + + mListCombo.setSelectedItem(alias.getList()); + + List groupNames = mAliasModel.getGroupNames(alias.getList()); + + if(groupNames.isEmpty()) + { + mGroupCombo.setModel(EMPTY_MODEL); + } + else + { + mGroupCombo.setModel(new DefaultComboBoxModel( + groupNames.toArray(new String[groupNames.size()]))); + ; + } + + mGroupCombo.setSelectedItem(alias.getGroup()); + + Color color = alias.getMapColor(); + + mButtonColor.setBackground(color); + mButtonColor.setForeground(color); + + String iconName = alias.getIconName(); + + if(iconName == null) + { + iconName = IconTableModel.DEFAULT_ICON; + } + + Icon savedIcon = mIconManager.getModel().getIcon(iconName); + + if(savedIcon != null) + { + mIconCombo.setSelectedItem(savedIcon); + } + } + else + { + mListCombo.setModel(EMPTY_MODEL); + mGroupCombo.setModel(EMPTY_MODEL); + mName.setText(null); + + mButtonColor.setBackground(getBackground()); + mButtonColor.setForeground(getForeground()); + } + + repaint(); + + setModified(false); + } + + @Override + public void save() + { + if(hasItem() && isModified()) + { + Alias alias = getItem(); + + if(mListCombo.getSelectedItem() != null) + { + alias.setList((String) mListCombo.getSelectedItem()); + } + + if(mGroupCombo.getSelectedItem() != null) + { + alias.setGroup((String) mGroupCombo.getSelectedItem()); + } + + alias.setName(mName.getText()); + + alias.setColor(mButtonColor.getBackground().getRGB()); + + if(mIconCombo.getSelectedItem() != null) + { + alias.setIconName(((Icon) mIconCombo.getSelectedItem()).getName()); + } + + setModified(false); + + //Broadcast an alias change event to save the updates + mAliasModel.broadcast(new AliasEvent(getItem(), Event.CHANGE)); + } + } } diff --git a/src/alias/MultipleAliasEditor.java b/src/alias/MultipleAliasEditor.java index ba6861d1..796379b4 100644 --- a/src/alias/MultipleAliasEditor.java +++ b/src/alias/MultipleAliasEditor.java @@ -1,41 +1,28 @@ package alias; +import alias.AliasEvent.Event; import alias.id.AliasIDType; import alias.id.broadcast.BroadcastChannel; +import alias.id.priority.Priority; import audio.broadcast.BroadcastModel; import gui.editor.Editor; - -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.Arrays; -import java.util.List; - -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JColorChooser; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JSeparator; -import javax.swing.JSlider; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import map.IconManager; -import map.MapIcon; -import map.MapIconListCellRenderer; +import icon.Icon; +import icon.IconListCellRenderer; +import icon.IconManager; import net.miginfocom.swing.MigLayout; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import sample.Listener; -import settings.SettingsManager; -import alias.AliasEvent.Event; -import alias.id.priority.Priority; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; public class MultipleAliasEditor extends Editor> implements Listener @@ -54,7 +41,7 @@ public class MultipleAliasEditor extends Editor> private JCheckBox mGroupCheckBox = new JCheckBox("Group"); private JComboBox mGroupCombo = new JComboBox<>(); private JCheckBox mIconCheckBox = new JCheckBox("Icon"); - private JComboBox mMapIconCombo; + private JComboBox mIconCombo; private JCheckBox mColorCheckBox = new JCheckBox("Color"); private JButton mButtonColor; private JButton mBtnIconManager; @@ -68,15 +55,23 @@ public class MultipleAliasEditor extends Editor> private AliasModel mAliasModel; private BroadcastModel mBroadcastModel; - private SettingsManager mSettingsManager; + private IconManager mIconManager; - public MultipleAliasEditor(AliasModel aliasModel, BroadcastModel broadcastModel, SettingsManager settingsManager) + public MultipleAliasEditor(AliasModel aliasModel, BroadcastModel broadcastModel, IconManager iconManager) { mAliasModel = aliasModel; mBroadcastModel = broadcastModel; - mSettingsManager = settingsManager; + mIconManager = iconManager; mAliasModel.addListener(this); + mIconManager.getModel().addTableModelListener(new TableModelListener() + { + @Override + public void tableChanged(TableModelEvent e) + { + refreshIcons(); + } + }); init(); } @@ -139,12 +134,12 @@ public class MultipleAliasEditor extends Editor> add(mIconCheckBox); - mMapIconCombo = new JComboBox(mSettingsManager.getMapIcons()); + mIconCombo = new JComboBox(mIconManager.getIcons()); - MapIconListCellRenderer renderer = new MapIconListCellRenderer(); + IconListCellRenderer renderer = new IconListCellRenderer(mIconManager); renderer.setPreferredSize(new Dimension(200, 30)); - mMapIconCombo.setRenderer(renderer); - add(mMapIconCombo, "wrap"); + mIconCombo.setRenderer(renderer); + add(mIconCombo, "wrap"); //Dummy place holder add(new JLabel()); @@ -155,17 +150,7 @@ public class MultipleAliasEditor extends Editor> @Override public void actionPerformed(ActionEvent arg0) { - final IconManager iconManager = - new IconManager(mSettingsManager, MultipleAliasEditor.this); - - EventQueue.invokeLater(new Runnable() - { - @Override - public void run() - { - iconManager.setVisible(true); - } - }); + mIconManager.showEditor(MultipleAliasEditor.this); } }); @@ -243,6 +228,21 @@ public class MultipleAliasEditor extends Editor> setModified(false); } + private void refreshIcons() + { + if(mIconCombo != null) + { + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + mIconCombo.setModel(new DefaultComboBoxModel<>(mIconManager.getIcons())); + } + }); + } + } + @Override public void setItem(List item) { @@ -277,6 +277,8 @@ public class MultipleAliasEditor extends Editor> List streamNames = mBroadcastModel.getBroadcastConfigurationNames(); mStreamCombo.setModel(new DefaultComboBoxModel(streamNames.toArray(new String[streamNames.size()]))); + mIconCombo.setModel(new DefaultComboBoxModel<>(mIconManager.getIcons())); + setCheckBoxesUnselected(); setModified(false); @@ -363,9 +365,9 @@ public class MultipleAliasEditor extends Editor> if (mIconCheckBox.isSelected()) { - if (mMapIconCombo.getSelectedItem() != null) + if (mIconCombo.getSelectedItem() != null) { - alias.setIconName(((MapIcon) mMapIconCombo.getSelectedItem()).getName()); + alias.setIconName(((Icon)mIconCombo.getSelectedItem()).getName()); } else { diff --git a/src/audio/AudioChannelPanel.java b/src/audio/AudioChannelPanel.java index 58540f88..72f4a091 100644 --- a/src/audio/AudioChannelPanel.java +++ b/src/audio/AudioChannelPanel.java @@ -1,12 +1,29 @@ +/******************************************************************************* + * sdrtrunk + * Copyright (C) 2014-2017 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 audio; -import java.awt.Color; -import java.awt.EventQueue; -import java.awt.Font; - -import javax.swing.JLabel; -import javax.swing.JPanel; - +import alias.Alias; +import audio.metadata.AudioMetadata; +import audio.metadata.Metadata; +import audio.metadata.MetadataType; +import audio.output.AudioOutput; +import icon.IconManager; import net.miginfocom.swing.MigLayout; import sample.Listener; import settings.ColorSetting; @@ -14,278 +31,279 @@ import settings.ColorSetting.ColorSettingName; import settings.Setting; import settings.SettingChangeListener; import settings.SettingsManager; -import alias.Alias; -import audio.metadata.AudioMetadata; -import audio.metadata.Metadata; -import audio.metadata.MetadataType; -import audio.output.AudioOutput; -public class AudioChannelPanel extends JPanel - implements Listener, SettingChangeListener +import javax.swing.*; +import java.awt.*; + +public class AudioChannelPanel extends JPanel + implements Listener, SettingChangeListener { - private static final long serialVersionUID = 1L; - - private Font mFont = new Font( Font.MONOSPACED, Font.PLAIN, 12 ); + private static final long serialVersionUID = 1L; + + private Font mFont = new Font(Font.MONOSPACED, Font.PLAIN, 12); private Color mLabelColor; private Color mDetailsColor; + private IconManager mIconManager; private SettingsManager mSettingsManager; - private AudioOutput mAudioOutput; + private AudioOutput mAudioOutput; - private JLabel mChannelName = new JLabel( " " ); - private JLabel mToLabel = new JLabel( "TO:" ); - private JLabel mTo = new JLabel( "" ); - private JLabel mToAlias = new JLabel( "" ); - - private JLabel mMutedLabel = new JLabel( " " ); - private JLabel mFromLabel = new JLabel( "FROM:" ); - private JLabel mFrom = new JLabel( "" ); - private JLabel mFromAlias = new JLabel( "" ); - - private boolean mConfigured = false; - - public AudioChannelPanel( SettingsManager settingsManager, AudioOutput audioOutput ) - { - mSettingsManager = settingsManager; - mSettingsManager.addListener( this ); + private JLabel mChannelName = new JLabel(" "); + private JLabel mToLabel = new JLabel("TO:"); + private JLabel mTo = new JLabel(""); + private JLabel mToAlias = new JLabel(""); - mAudioOutput = audioOutput; - - if( mAudioOutput != null ) - { - mAudioOutput.addAudioEventListener( this ); - mAudioOutput.setAudioMetadataListener( new AudioMetadataProcessor() ); - } + private JLabel mMutedLabel = new JLabel(" "); + private JLabel mFromLabel = new JLabel("FROM:"); + private JLabel mFrom = new JLabel(""); + private JLabel mFromAlias = new JLabel(""); - mLabelColor = mSettingsManager.getColorSetting( - ColorSettingName.CHANNEL_STATE_LABEL_DECODER ).getColor(); - mDetailsColor = mSettingsManager.getColorSetting( - ColorSettingName.CHANNEL_STATE_LABEL_DETAILS ).getColor(); - - init(); - } - - private void init() - { - setLayout( new MigLayout( "insets 0 0 0 0", "[][right][][grow,fill]", "[]0[]0[grow,fill]" ) ); - setBackground( Color.BLACK ); - - mChannelName = new JLabel( mAudioOutput != null ? mAudioOutput.getChannelName() : " " ); - mChannelName.setFont( mFont ); - mChannelName.setForeground( mDetailsColor ); - add( mChannelName ); - - mToLabel.setFont( mFont ); - if( mAudioOutput != null ) - { - mToLabel.setForeground( mLabelColor ); - } - else - { - mToLabel.setForeground( getBackground() ); - } - add( mToLabel ); + private boolean mConfigured = false; - mTo.setFont( mFont ); - mTo.setForeground( mLabelColor ); - add( mTo ); - - mToAlias.setFont( mFont ); - mToAlias.setForeground( mLabelColor ); - add( mToAlias,"wrap" ); - - mMutedLabel.setFont( mFont ); - mMutedLabel.setForeground( Color.RED ); - add( mMutedLabel ); - - mFromLabel.setFont( mFont ); - if( mAudioOutput != null ) - { - mFromLabel.setForeground( mLabelColor ); - } - else - { - mFromLabel.setForeground( getBackground() ); - } - add( mFromLabel ); - - mFrom.setFont( mFont ); - mFrom.setForeground( mLabelColor ); - add( mFrom ); - - mFromAlias.setFont( mFont ); - mFromAlias.setForeground( mLabelColor ); - add( mFromAlias,"wrap" ); - - } - - @Override - public void receive( final AudioEvent audioEvent ) - { - switch( audioEvent.getType() ) - { - case AUDIO_STOPPED: - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - resetLabels(); - } - } ); - break; - case AUDIO_MUTED: - case AUDIO_UNMUTED: - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - mMutedLabel.setText( mAudioOutput.isMuted() ? "M" : " " ); - } - } ); - break; - default: - break; - } - } - - /** - * Resets the from and to labels. Note: this does not happen on the swing - * event thread. Only invoke from the swing thread. - */ - private void resetLabels() - { - mFrom.setText( "" ); - updateAlias( mFromAlias, null ); - - mTo.setText( "" ); - updateAlias( mToAlias, null ); - - mConfigured = false; - } - - /** - * Updates the alias label with text and icon from the alias. Note: this - * does not occur on the Swing event thread -- wrap any calls to this - * method with an event thread call. - */ - private void updateAlias( JLabel label, Alias alias ) - { - if( alias != null ) - { - label.setText( alias.getName() ); - - String icon = alias.getIconName(); - - if( icon != null ) - { - label.setIcon( mSettingsManager.getImageIcon( icon, - SettingsManager.DEFAULT_ICON_SIZE ) ); - } - else - { - label.setIcon( null ); - } - } - else - { - label.setText( "" ); - label.setIcon( null ); - } - } - - - /** - * Processes audio metadata to update this panel's display values - */ - public class AudioMetadataProcessor implements Listener - { - @Override - public void receive( AudioMetadata audioMetadata ) - { - if( !mConfigured || audioMetadata.isUpdated() ) - { - final Metadata from = audioMetadata.getMetadata( MetadataType.FROM ); - - final Metadata to = audioMetadata.getMetadata( MetadataType.TO ); - - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - if( from != null ) - { - mFrom.setText( from.getValue() ); - updateAlias( mFromAlias, from.getAlias() ); - } - else - { - mFrom.setText( "-----" ); - } - - if( to != null ) - { - mTo.setText( to.getValue() ); - updateAlias( mToAlias, to.getAlias() ); - } - else - { - mTo.setText( "-----" ); - } - } - } ); - - mConfigured = true; - } - } - } - - - @Override - public void settingChanged( Setting setting ) + public AudioChannelPanel(IconManager iconManager, SettingsManager settingsManager, AudioOutput audioOutput) { - if( setting instanceof ColorSetting ) - { - ColorSetting colorSetting = (ColorSetting)setting; - - switch( colorSetting.getColorSettingName() ) - { - case CHANNEL_STATE_LABEL_DECODER: - if( mFrom != null ) - { - mFrom.setForeground( mLabelColor ); - } - if( mFromAlias != null ) - { - mFromAlias.setForeground( mLabelColor ); - } - if( mTo != null ) - { - mTo.setForeground( mLabelColor ); - } - if( mToAlias != null ) - { - mToAlias.setForeground( mLabelColor ); - } - break; - case CHANNEL_STATE_LABEL_DETAILS: - if( mFromLabel != null ) - { - mFromLabel.setForeground( mDetailsColor ); - } - if( mToLabel != null ) - { - mToLabel.setForeground( mDetailsColor ); - } - break; - default: - break; - } - } + mIconManager = iconManager; + mSettingsManager = settingsManager; + mSettingsManager.addListener(this); + + mAudioOutput = audioOutput; + + if(mAudioOutput != null) + { + mAudioOutput.addAudioEventListener(this); + mAudioOutput.setAudioMetadataListener(new AudioMetadataProcessor()); + } + + mLabelColor = mSettingsManager.getColorSetting( + ColorSettingName.CHANNEL_STATE_LABEL_DECODER).getColor(); + mDetailsColor = mSettingsManager.getColorSetting( + ColorSettingName.CHANNEL_STATE_LABEL_DETAILS).getColor(); + + init(); } - @Override - public void settingDeleted( Setting setting ) {} + private void init() + { + setLayout(new MigLayout("insets 0 0 0 0", "[][right][][grow,fill]", "[]0[]0[grow,fill]")); + setBackground(Color.BLACK); + + mChannelName = new JLabel(mAudioOutput != null ? mAudioOutput.getChannelName() : " "); + mChannelName.setFont(mFont); + mChannelName.setForeground(mDetailsColor); + add(mChannelName); + + mToLabel.setFont(mFont); + if(mAudioOutput != null) + { + mToLabel.setForeground(mLabelColor); + } + else + { + mToLabel.setForeground(getBackground()); + } + add(mToLabel); + + mTo.setFont(mFont); + mTo.setForeground(mLabelColor); + add(mTo); + + mToAlias.setFont(mFont); + mToAlias.setForeground(mLabelColor); + add(mToAlias, "wrap"); + + mMutedLabel.setFont(mFont); + mMutedLabel.setForeground(Color.RED); + add(mMutedLabel); + + mFromLabel.setFont(mFont); + if(mAudioOutput != null) + { + mFromLabel.setForeground(mLabelColor); + } + else + { + mFromLabel.setForeground(getBackground()); + } + add(mFromLabel); + + mFrom.setFont(mFont); + mFrom.setForeground(mLabelColor); + add(mFrom); + + mFromAlias.setFont(mFont); + mFromAlias.setForeground(mLabelColor); + add(mFromAlias, "wrap"); + + } + + @Override + public void receive(final AudioEvent audioEvent) + { + switch(audioEvent.getType()) + { + case AUDIO_STOPPED: + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + resetLabels(); + } + }); + break; + case AUDIO_MUTED: + case AUDIO_UNMUTED: + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + mMutedLabel.setText(mAudioOutput.isMuted() ? "M" : " "); + } + }); + break; + default: + break; + } + } + + /** + * Resets the from and to labels. Note: this does not happen on the swing + * event thread. Only invoke from the swing thread. + */ + private void resetLabels() + { + mFrom.setText(""); + updateAlias(mFromAlias, null); + + mTo.setText(""); + updateAlias(mToAlias, null); + + mConfigured = false; + } + + /** + * Updates the alias label with text and icon from the alias. Note: this + * does not occur on the Swing event thread -- wrap any calls to this + * method with an event thread call. + */ + private void updateAlias(JLabel label, Alias alias) + { + if(alias != null) + { + label.setText(alias.getName()); + + String icon = alias.getIconName(); + + if(icon != null) + { + label.setIcon(mIconManager.getIcon(icon, IconManager.DEFAULT_ICON_SIZE)); + } + else + { + label.setIcon(null); + } + } + else + { + label.setText(""); + label.setIcon(null); + } + } + + + /** + * Processes audio metadata to update this panel's display values + */ + public class AudioMetadataProcessor implements Listener + { + @Override + public void receive(AudioMetadata audioMetadata) + { + if(!mConfigured || audioMetadata.isUpdated()) + { + final Metadata from = audioMetadata.getMetadata(MetadataType.FROM); + + final Metadata to = audioMetadata.getMetadata(MetadataType.TO); + + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + if(from != null) + { + mFrom.setText(from.getValue()); + updateAlias(mFromAlias, from.getAlias()); + } + else + { + mFrom.setText("-----"); + } + + if(to != null) + { + mTo.setText(to.getValue()); + updateAlias(mToAlias, to.getAlias()); + } + else + { + mTo.setText("-----"); + } + } + }); + + mConfigured = true; + } + } + } + + + @Override + public void settingChanged(Setting setting) + { + if(setting instanceof ColorSetting) + { + ColorSetting colorSetting = (ColorSetting) setting; + + switch(colorSetting.getColorSettingName()) + { + case CHANNEL_STATE_LABEL_DECODER: + if(mFrom != null) + { + mFrom.setForeground(mLabelColor); + } + if(mFromAlias != null) + { + mFromAlias.setForeground(mLabelColor); + } + if(mTo != null) + { + mTo.setForeground(mLabelColor); + } + if(mToAlias != null) + { + mToAlias.setForeground(mLabelColor); + } + break; + case CHANNEL_STATE_LABEL_DETAILS: + if(mFromLabel != null) + { + mFromLabel.setForeground(mDetailsColor); + } + if(mToLabel != null) + { + mToLabel.setForeground(mDetailsColor); + } + break; + default: + break; + } + } + } + + @Override + public void settingDeleted(Setting setting) + { + } } diff --git a/src/audio/AudioChannelsPanel.java b/src/audio/AudioChannelsPanel.java index 4043d4de..bf28bcb4 100644 --- a/src/audio/AudioChannelsPanel.java +++ b/src/audio/AudioChannelsPanel.java @@ -1,51 +1,67 @@ +/******************************************************************************* + * sdrtrunk + * Copyright (C) 2014-2017 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 audio; -import java.awt.Color; -import java.util.List; - -import javax.swing.JPanel; -import javax.swing.JSeparator; - +import audio.output.AudioOutput; +import icon.IconManager; import net.miginfocom.swing.MigLayout; import settings.SettingsManager; -import audio.output.AudioOutput; + +import javax.swing.*; +import java.awt.*; +import java.util.List; public class AudioChannelsPanel extends JPanel { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public AudioChannelsPanel( SettingsManager settingsManager, - IAudioController controller ) - { - setLayout( new MigLayout( "insets 0 0 0 0", "[grow,fill]", "[]0[]") ); - - setBackground( Color.BLACK ); + public AudioChannelsPanel(IconManager iconManager, SettingsManager settingsManager, IAudioController controller) + { + setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[]0[]")); - List outputs = controller.getAudioOutputs(); + setBackground(Color.BLACK); - for( int x = 0; x < outputs.size(); x++ ) - { - add( new AudioChannelPanel( settingsManager, outputs.get( x ) ), "wrap" ); - - if( x < outputs.size() - 1 ) - { - addSeparator(); - } - } + List outputs = controller.getAudioOutputs(); + + for(int x = 0; x < outputs.size(); x++) + { + add(new AudioChannelPanel(iconManager, settingsManager, outputs.get(x)), "wrap"); + + if(x < outputs.size() - 1) + { + addSeparator(); + } + } /* Add an empty channel panel so that the panel is sized appropriately - * for either a single channel or two channels */ - if( outputs.size() == 1 ) - { - addSeparator(); - add( new AudioChannelPanel( settingsManager, null ), "wrap" ); - } - } - - private void addSeparator() - { - JSeparator separator = new JSeparator( JSeparator.HORIZONTAL ); - separator.setBackground( Color.DARK_GRAY ); - add( separator, "span,growx" ); - } + * for either a single channel or two channels */ + if(outputs.size() == 1) + { + addSeparator(); + add(new AudioChannelPanel(iconManager, settingsManager, null), "wrap"); + } + } + + private void addSeparator() + { + JSeparator separator = new JSeparator(JSeparator.HORIZONTAL); + separator.setBackground(Color.DARK_GRAY); + add(separator, "span,growx"); + } } diff --git a/src/audio/AudioPanel.java b/src/audio/AudioPanel.java index a9e10b4d..589c959b 100644 --- a/src/audio/AudioPanel.java +++ b/src/audio/AudioPanel.java @@ -1,382 +1,411 @@ +/******************************************************************************* + * sdrtrunk + * Copyright (C) 2014-2017 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 audio; -import java.awt.Color; -import java.awt.EventQueue; +import audio.output.AudioOutput; +import icon.IconManager; +import net.miginfocom.swing.MigLayout; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import sample.Listener; +import settings.SettingsManager; +import source.SourceManager; +import source.mixer.MixerChannelConfiguration; + +import javax.sound.sampled.FloatControl; +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import javax.sound.sampled.FloatControl; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JSlider; -import javax.swing.SwingUtilities; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import net.miginfocom.swing.MigLayout; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import sample.Listener; -import settings.SettingsManager; -import source.SourceManager; -import source.mixer.MixerChannelConfiguration; -import audio.output.AudioOutput; - public class AudioPanel extends JPanel implements Listener { - private static final long serialVersionUID = 1L; - - private static final Logger mLog = LoggerFactory.getLogger( AudioPanel.class ); - - private static ImageIcon MUTED_ICON = SettingsManager.getScaledIcon( - new ImageIcon( "images/audio_muted.png" ), 38 ); - private static ImageIcon UNMUTED_ICON = SettingsManager.getScaledIcon( - new ImageIcon( "images/audio_unmuted.png" ), 38 ); + private static final long serialVersionUID = 1L; - private SettingsManager mSettingsManager; - private SourceManager mSourceManager; - private IAudioController mController; + private static final Logger mLog = LoggerFactory.getLogger(AudioPanel.class); - private JButton mMuteButton; - private AudioChannelsPanel mAudioChannelsPanel; - - public AudioPanel( SettingsManager settingsManager, - SourceManager sourceManager, - IAudioController controller ) - { - mSettingsManager = settingsManager; - mSourceManager = sourceManager; - mController = controller; - - mController.addControllerListener( this ); - - init(); - } - - private void init() - { - setLayout( new MigLayout( "insets 0 0 0 0", "[]0[grow,fill]", "[fill]0[]") ); - setBackground( Color.BLACK ); + private static ImageIcon MUTED_ICON = IconManager.getScaledIcon( + new ImageIcon("images/audio_muted.png"), 38); + private static ImageIcon UNMUTED_ICON = IconManager.getScaledIcon( + new ImageIcon("images/audio_unmuted.png"), 38); - mMuteButton = new MuteButton(); - mMuteButton.setBackground( getBackground() ); - add( mMuteButton ); - - mAudioChannelsPanel = new AudioChannelsPanel( mSettingsManager, mController ); - - add( mAudioChannelsPanel ); - - addMouseListener( new MouseSelectionListener() ); - } - - @Override - public void receive( AudioEvent event ) - { - switch( event.getType() ) - { - case AUDIO_CONFIGURATION_CHANGE_STARTED: - break; - case AUDIO_CONFIGURATION_CHANGE_COMPLETE: - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - remove( mAudioChannelsPanel ); + private IconManager mIconManager; + private SettingsManager mSettingsManager; + private SourceManager mSourceManager; + private IAudioController mController; - mAudioChannelsPanel = new AudioChannelsPanel( - mSettingsManager, mController ); - - add( mAudioChannelsPanel ); + private JButton mMuteButton; + private AudioChannelsPanel mAudioChannelsPanel; - mAudioChannelsPanel.repaint(); + public AudioPanel(IconManager iconManager, SettingsManager settingsManager, SourceManager sourceManager, + IAudioController controller) + { + mIconManager = iconManager; + mSettingsManager = settingsManager; + mSourceManager = sourceManager; + mController = controller; - revalidate(); - repaint(); - } - } ); - break; - default: - break; - } - } + mController.addControllerListener(this); - /** - * Audio output mute control menu item. - */ - public class AudioOutputMuteItem extends JMenuItem - { - private static final long serialVersionUID = 1L; - - private AudioOutput mAudioOutput; - - public AudioOutputMuteItem( AudioOutput audioOutput ) - { - super( audioOutput.isMuted() ? "Unmute" : "Mute" ); - - mAudioOutput = audioOutput; - - addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - mAudioOutput.setMuted( !mAudioOutput.isMuted() ); - } - } ); - } - } - - /** - * Mouse listener - */ - public class MouseSelectionListener implements MouseListener - { - @Override - public void mouseClicked( MouseEvent event ) - { - if( SwingUtilities.isRightMouseButton( event ) ) - { - JPopupMenu popup = new JPopupMenu(); + init(); + } + + private void init() + { + setLayout(new MigLayout("insets 0 0 0 0", "[]0[grow,fill]", "[fill]0[]")); + setBackground(Color.BLACK); + + mMuteButton = new MuteButton(); + mMuteButton.setBackground(getBackground()); + add(mMuteButton); + + mAudioChannelsPanel = new AudioChannelsPanel(mIconManager, mSettingsManager, mController); + + add(mAudioChannelsPanel); + + addMouseListener(new MouseSelectionListener()); + } + + @Override + public void receive(AudioEvent event) + { + switch(event.getType()) + { + case AUDIO_CONFIGURATION_CHANGE_STARTED: + break; + case AUDIO_CONFIGURATION_CHANGE_COMPLETE: + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + remove(mAudioChannelsPanel); + + mAudioChannelsPanel = new AudioChannelsPanel(mIconManager, mSettingsManager, mController); + + add(mAudioChannelsPanel); + + mAudioChannelsPanel.repaint(); + + revalidate(); + repaint(); + } + }); + break; + default: + break; + } + } + + /** + * Audio output mute control menu item. + */ + public class AudioOutputMuteItem extends JMenuItem + { + private static final long serialVersionUID = 1L; + + private AudioOutput mAudioOutput; + + public AudioOutputMuteItem(AudioOutput audioOutput) + { + super(audioOutput.isMuted() ? "Unmute" : "Mute"); + + mAudioOutput = audioOutput; + + addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + mAudioOutput.setMuted(!mAudioOutput.isMuted()); + } + }); + } + } + + /** + * Mouse listener + */ + public class MouseSelectionListener implements MouseListener + { + @Override + public void mouseClicked(MouseEvent event) + { + if(SwingUtilities.isRightMouseButton(event)) + { + JPopupMenu popup = new JPopupMenu(); /* Audio mixer/output selection menus */ - JMenu outputMenu = new JMenu( "Audio Output" ); + JMenu outputMenu = new JMenu("Audio Output"); - MixerChannelConfiguration[] mixerConfigurations = - mSourceManager.getMixerManager().getOutputMixers(); + MixerChannelConfiguration[] mixerConfigurations = + mSourceManager.getMixerManager().getOutputMixers(); - for( MixerChannelConfiguration mixerConfig: mixerConfigurations ) - { - MixerSelectionItem mixerItem = new MixerSelectionItem( mixerConfig ); - - try - { - MixerChannelConfiguration current = mController.getMixerChannelConfiguration(); + for(MixerChannelConfiguration mixerConfig : mixerConfigurations) + { + MixerSelectionItem mixerItem = new MixerSelectionItem(mixerConfig); - if( current != null && current.equals( mixerConfig ) ) - { - mixerItem.setSelected( true ); - } - } - catch( AudioException e ) - { - mLog.error( "Error while detecting current mixer " - + "channel configuration", e ); - } - - outputMenu.add( mixerItem ); - } - - popup.add( outputMenu ); + try + { + MixerChannelConfiguration current = mController.getMixerChannelConfiguration(); + + if(current != null && current.equals(mixerConfig)) + { + mixerItem.setSelected(true); + } + } + catch(AudioException e) + { + mLog.error("Error while detecting current mixer " + + "channel configuration", e); + } + + outputMenu.add(mixerItem); + } + + popup.add(outputMenu); /* Audio output mute and volume control */ - for( AudioOutput output: mController.getAudioOutputs() ) - { - JMenu menu = new JMenu( "Channel: " + output.getChannelName() ); - - menu.add( new AudioOutputMuteItem( output ) ); - - if( output.hasGainControl() ) - { - JMenu volume = new JMenu( "Volume" ); - volume.add( new VolumeSlider( output.getGainControl() ) ); - menu.add( volume ); - } - - popup.add( menu ); - } - - popup.show( event.getComponent(), event.getX(), event.getY() ); - } - } + for(AudioOutput output : mController.getAudioOutputs()) + { + JMenu menu = new JMenu("Channel: " + output.getChannelName()); - @Override - public void mousePressed( MouseEvent e ) {} - @Override - public void mouseReleased( MouseEvent e ) {} - @Override - public void mouseEntered( MouseEvent e ) {} - @Override - public void mouseExited( MouseEvent e ) {} - } - - /** - * Audio volume (gain) adjustment slider control - */ - public class VolumeSlider extends JSlider - { - private static final long serialVersionUID = 1L; - - private FloatControl mFloatControl; - - public VolumeSlider( FloatControl control ) - { - super( 0, 100, 0 ); - - setMajorTickSpacing( 25 ); - setMinorTickSpacing( 5 ); - setPaintTicks( true ); - setPaintLabels( true ); + menu.add(new AudioOutputMuteItem(output)); - mFloatControl = control; - - setValue( getIntegerValue( mFloatControl.getValue() ) ); - - addChangeListener( new ChangeListener() - { - @Override - public void stateChanged( ChangeEvent event ) - { - mFloatControl.shift( mFloatControl.getValue(), - getFloatValue( VolumeSlider.this.getValue() ), - 1000 ); - } - } ); - - addMouseListener( new MouseListener() - { - @Override - public void mouseClicked( MouseEvent event ) - { - if( event.getClickCount() == 2 ) - { - VolumeSlider.this.setValue( 50 ); - } - } - - public void mouseReleased( MouseEvent arg0 ) {} - public void mousePressed( MouseEvent arg0 ) {} - public void mouseExited( MouseEvent arg0 ) {} - public void mouseEntered( MouseEvent arg0 ) {} - } ); - } + if(output.hasGainControl()) + { + JMenu volume = new JMenu("Volume"); + volume.add(new VolumeSlider(output.getGainControl())); + menu.add(volume); + } - /** - * Converts the integer value to a floating point value to use in the - * float control. Assumes an integer value of 50 is the 0.0 dB mid - * point (ie no gain ) value. - */ - private int getIntegerValue( float value ) - { - if( value == 0.0f ) - { - return 50; - } - else if( value < 0.0f ) - { - float ratio = value / mFloatControl.getMinimum(); - - return 50 - (int)( ratio * 50.0f ); - } - else - { - float ratio = value / mFloatControl.getMaximum(); - - return 50 + (int)( ratio * 50.0f ); - } - } - - private float getFloatValue( int value ) - { - if( value == 50 ) - { - return 0.0f; - } - else if( value < 50 ) - { - return (float)( 50 - value ) / 50.0f * mFloatControl.getMinimum(); - } - else - { - return (float)( value - 50 ) / 50.0f * mFloatControl.getMaximum(); - } - } - } - - /** - * Mixer/Channel configuration selection item - */ - public class MixerSelectionItem extends JMenuItem - { - private static final long serialVersionUID = 1L; + popup.add(menu); + } - private MixerChannelConfiguration mConfiguration; - - public MixerSelectionItem( MixerChannelConfiguration config ) - { - super( config.toString() ); - - mConfiguration = config; - - addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - try - { - mController.setMixerChannelConfiguration( mConfiguration ); - } - catch ( AudioException e1 ) - { - mLog.error( "Couldn't set mixer channel configuration " - + "to: " + mConfiguration.toString() ); - - JOptionPane.showMessageDialog( MixerSelectionItem.this, - "Couldn't set [" + mConfiguration.toString() + - "] as the audio output device" ); - } - } - } ); - } - } + popup.show(event.getComponent(), event.getX(), event.getY()); + } + } - /** - * Mute button to mute all audio output channels exposed by the audio - * controller - */ - public class MuteButton extends JButton - { - private static final long serialVersionUID = 1L; - - private boolean mMuted = false; - - public MuteButton() - { - setIcon( UNMUTED_ICON ); - setBorderPainted( false ); - - addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - mMuted = !mMuted; - - for( AudioOutput output: mController.getAudioOutputs() ) - { - output.setMuted( mMuted ); - } - - EventQueue.invokeLater( new Runnable() - { - @Override - public void run() - { - setIcon( mMuted ? MUTED_ICON : UNMUTED_ICON ); - } - } ); - } - } ); - } - } + @Override + public void mousePressed(MouseEvent e) + { + } + + @Override + public void mouseReleased(MouseEvent e) + { + } + + @Override + public void mouseEntered(MouseEvent e) + { + } + + @Override + public void mouseExited(MouseEvent e) + { + } + } + + /** + * Audio volume (gain) adjustment slider control + */ + public class VolumeSlider extends JSlider + { + private static final long serialVersionUID = 1L; + + private FloatControl mFloatControl; + + public VolumeSlider(FloatControl control) + { + super(0, 100, 0); + + setMajorTickSpacing(25); + setMinorTickSpacing(5); + setPaintTicks(true); + setPaintLabels(true); + + mFloatControl = control; + + setValue(getIntegerValue(mFloatControl.getValue())); + + addChangeListener(new ChangeListener() + { + @Override + public void stateChanged(ChangeEvent event) + { + mFloatControl.shift(mFloatControl.getValue(), + getFloatValue(VolumeSlider.this.getValue()), + 1000); + } + }); + + addMouseListener(new MouseListener() + { + @Override + public void mouseClicked(MouseEvent event) + { + if(event.getClickCount() == 2) + { + VolumeSlider.this.setValue(50); + } + } + + public void mouseReleased(MouseEvent arg0) + { + } + + public void mousePressed(MouseEvent arg0) + { + } + + public void mouseExited(MouseEvent arg0) + { + } + + public void mouseEntered(MouseEvent arg0) + { + } + }); + } + + /** + * Converts the integer value to a floating point value to use in the + * float control. Assumes an integer value of 50 is the 0.0 dB mid + * point (ie no gain ) value. + */ + private int getIntegerValue(float value) + { + if(value == 0.0f) + { + return 50; + } + else if(value < 0.0f) + { + float ratio = value / mFloatControl.getMinimum(); + + return 50 - (int) (ratio * 50.0f); + } + else + { + float ratio = value / mFloatControl.getMaximum(); + + return 50 + (int) (ratio * 50.0f); + } + } + + private float getFloatValue(int value) + { + if(value == 50) + { + return 0.0f; + } + else if(value < 50) + { + return (float) (50 - value) / 50.0f * mFloatControl.getMinimum(); + } + else + { + return (float) (value - 50) / 50.0f * mFloatControl.getMaximum(); + } + } + } + + /** + * Mixer/Channel configuration selection item + */ + public class MixerSelectionItem extends JMenuItem + { + private static final long serialVersionUID = 1L; + + private MixerChannelConfiguration mConfiguration; + + public MixerSelectionItem(MixerChannelConfiguration config) + { + super(config.toString()); + + mConfiguration = config; + + addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + try + { + mController.setMixerChannelConfiguration(mConfiguration); + } + catch(AudioException e1) + { + mLog.error("Couldn't set mixer channel configuration " + + "to: " + mConfiguration.toString()); + + JOptionPane.showMessageDialog(MixerSelectionItem.this, + "Couldn't set [" + mConfiguration.toString() + + "] as the audio output device"); + } + } + }); + } + } + + /** + * Mute button to mute all audio output channels exposed by the audio + * controller + */ + public class MuteButton extends JButton + { + private static final long serialVersionUID = 1L; + + private boolean mMuted = false; + + public MuteButton() + { + setIcon(UNMUTED_ICON); + setBorderPainted(false); + + addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + mMuted = !mMuted; + + for(AudioOutput output : mController.getAudioOutputs()) + { + output.setMuted(mMuted); + } + + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + setIcon(mMuted ? MUTED_ICON : UNMUTED_ICON); + } + }); + } + }); + } + } } diff --git a/src/audio/broadcast/BroadcastConfigurationEditor.java b/src/audio/broadcast/BroadcastConfigurationEditor.java index 678ba383..4c1b5f71 100644 --- a/src/audio/broadcast/BroadcastConfigurationEditor.java +++ b/src/audio/broadcast/BroadcastConfigurationEditor.java @@ -19,24 +19,22 @@ package audio.broadcast; import alias.AliasModel; -import audio.broadcast.broadcastify.BroadcastifyConfiguration; -import audio.broadcast.broadcastify.BroadcastifyConfigurationEditor; import gui.editor.DocumentListenerEditor; -import settings.SettingsManager; +import icon.IconManager; import javax.swing.*; public abstract class BroadcastConfigurationEditor extends DocumentListenerEditor { - protected SettingsManager mSettingsManager; + protected IconManager mIconManager; protected BroadcastModel mBroadcastModel; protected AliasModel mAliasModel; - public BroadcastConfigurationEditor(BroadcastModel broadcastModel, AliasModel aliasModel, SettingsManager settingsManager) + public BroadcastConfigurationEditor(BroadcastModel broadcastModel, AliasModel aliasModel, IconManager iconManager) { mBroadcastModel = broadcastModel; mAliasModel = aliasModel; - mSettingsManager = settingsManager; + mIconManager = iconManager; } /** diff --git a/src/audio/broadcast/BroadcastFactory.java b/src/audio/broadcast/BroadcastFactory.java index 3fc95768..745be778 100644 --- a/src/audio/broadcast/BroadcastFactory.java +++ b/src/audio/broadcast/BroadcastFactory.java @@ -40,6 +40,7 @@ import audio.convert.MP3SilenceGenerator; import controller.ThreadPoolManager; import gui.editor.Editor; import gui.editor.EmptyEditor; +import icon.IconManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import record.AudioRecorder; @@ -155,26 +156,26 @@ public class BroadcastFactory public static Editor getEditor(BroadcastConfiguration configuration, BroadcastModel broadcastModel, AliasModel aliasModel, - SettingsManager settingsManager) + IconManager iconManager) { Editor editor; switch (configuration.getBroadcastServerType()) { case BROADCASTIFY: - editor = new BroadcastifyConfigurationEditor(broadcastModel, aliasModel, settingsManager); + editor = new BroadcastifyConfigurationEditor(broadcastModel, aliasModel, iconManager); break; case ICECAST_TCP: - editor = new IcecastTCPConfigurationEditor(broadcastModel, aliasModel, settingsManager); + editor = new IcecastTCPConfigurationEditor(broadcastModel, aliasModel, iconManager); break; case ICECAST_HTTP: - editor = new IcecastHTTPConfigurationEditor(broadcastModel, aliasModel, settingsManager); + editor = new IcecastHTTPConfigurationEditor(broadcastModel, aliasModel, iconManager); break; case SHOUTCAST_V1: - editor = new ShoutcastV1ConfigurationEditor(broadcastModel, aliasModel, settingsManager); + editor = new ShoutcastV1ConfigurationEditor(broadcastModel, aliasModel, iconManager); break; case SHOUTCAST_V2: - editor = new ShoutcastV2ConfigurationEditor(broadcastModel, aliasModel, settingsManager); + editor = new ShoutcastV2ConfigurationEditor(broadcastModel, aliasModel, iconManager); break; default: editor = new EmptyEditor(); diff --git a/src/audio/broadcast/BroadcastModel.java b/src/audio/broadcast/BroadcastModel.java index 703c350c..911eaf39 100644 --- a/src/audio/broadcast/BroadcastModel.java +++ b/src/audio/broadcast/BroadcastModel.java @@ -22,12 +22,12 @@ import alias.id.broadcast.BroadcastChannel; import audio.AudioPacket; import audio.metadata.AudioMetadata; import controller.ThreadPoolManager; +import icon.IconManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import properties.SystemProperties; import sample.Broadcaster; import sample.Listener; -import settings.SettingsManager; import javax.swing.*; import javax.swing.table.AbstractTableModel; @@ -67,17 +67,17 @@ public class BroadcastModel extends AbstractTableModel implements Listener