mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
Adds AliasModel, AliasController tab with new AliasEditor
This commit is contained in:
@@ -41,6 +41,11 @@ public class Alias
|
||||
{
|
||||
}
|
||||
|
||||
public Alias( String name )
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return getName();
|
||||
|
||||
30
src/alias/AliasActionListener.java
Normal file
30
src/alias/AliasActionListener.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
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 );
|
||||
}
|
||||
36
src/alias/AliasConfigurationEditor.java
Normal file
36
src/alias/AliasConfigurationEditor.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
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();
|
||||
}
|
||||
287
src/alias/AliasController.java
Normal file
287
src/alias/AliasController.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<AliasEvent>
|
||||
{
|
||||
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<MapIcon> 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<MapIcon>( 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Alias> mAliases = new ArrayList<>();
|
||||
private List<TableModelListener> 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();
|
||||
}
|
||||
|
||||
|
||||
232
src/alias/AliasNameEditor.java
Normal file
232
src/alias/AliasNameEditor.java
Normal file
@@ -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<String> EMPTY_MODEL = new DefaultComboBoxModel<>();
|
||||
|
||||
private JComboBox<String> mListCombo = new JComboBox<>( EMPTY_MODEL );
|
||||
private JComboBox<String> mGroupCombo = new JComboBox<>( EMPTY_MODEL );
|
||||
private JTextField mName;
|
||||
|
||||
private JLabel mLabelMapColor;
|
||||
private JButton mButtonColor;
|
||||
private JComboBox<MapIcon> 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<MapIcon>( 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<String> listNames = mAliasModel.getListNames();
|
||||
|
||||
if( listNames.isEmpty() )
|
||||
{
|
||||
mListCombo.setModel( EMPTY_MODEL );
|
||||
}
|
||||
else
|
||||
{
|
||||
mListCombo.setModel( new DefaultComboBoxModel<String>(
|
||||
listNames.toArray( new String[ listNames.size() ] ) ) );;
|
||||
}
|
||||
|
||||
mListCombo.setSelectedItem( mAlias.getList() );
|
||||
|
||||
List<String> groupNames = mAliasModel.getGroupNames( mAlias.getList() );
|
||||
|
||||
if( groupNames.isEmpty() )
|
||||
{
|
||||
mGroupCombo.setModel( EMPTY_MODEL );
|
||||
}
|
||||
else
|
||||
{
|
||||
mGroupCombo.setModel( new DefaultComboBoxModel<String>(
|
||||
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" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user