mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
* Stores minimal main application window location and size/layout settings to allow application to be restored to the same size/location on restart. * Adds column width monitor to all tables in application that stores the column width settings in the user preferences so that on restarting the application the table column widths are restored to the previous widths.
141 lines
4.9 KiB
Java
141 lines
4.9 KiB
Java
/*
|
|
* ******************************************************************************
|
|
* sdrtrunk
|
|
* Copyright (C) 2014-2019 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 io.github.dsheirer.audio.broadcast;
|
|
|
|
import io.github.dsheirer.preference.UserPreferences;
|
|
import io.github.dsheirer.preference.swing.JTableColumnWidthMonitor;
|
|
import net.miginfocom.swing.MigLayout;
|
|
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JTable;
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.table.DefaultTableCellRenderer;
|
|
import java.awt.Color;
|
|
import java.awt.Component;
|
|
|
|
public class BroadcastStatusPanel extends JPanel
|
|
{
|
|
private JTable mTable;
|
|
private JTableColumnWidthMonitor mColumnWidthMonitor;
|
|
private JScrollPane mScrollPane;
|
|
private BroadcastModel mBroadcastModel;
|
|
private UserPreferences mUserPreferences;
|
|
private String mPreferenceKey;
|
|
|
|
public BroadcastStatusPanel(BroadcastModel broadcastModel, UserPreferences userPreferences, String preferenceKey)
|
|
{
|
|
mBroadcastModel = broadcastModel;
|
|
mUserPreferences = userPreferences;
|
|
mPreferenceKey = preferenceKey;
|
|
|
|
init();
|
|
}
|
|
|
|
public JTable getTable()
|
|
{
|
|
return mTable;
|
|
}
|
|
|
|
private void init()
|
|
{
|
|
setLayout(new MigLayout("insets 0 0 0 0 ", "[grow,fill]", "[grow,fill]"));
|
|
|
|
mTable = new JTable(mBroadcastModel);
|
|
|
|
DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)mTable.getDefaultRenderer(String.class);
|
|
renderer.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
|
mTable.getColumnModel().getColumn(BroadcastModel.COLUMN_BROADCASTER_STATUS).setCellRenderer(new StatusCellRenderer());
|
|
mColumnWidthMonitor = new JTableColumnWidthMonitor(mUserPreferences, mTable, mPreferenceKey);
|
|
|
|
mScrollPane = new JScrollPane(mTable);
|
|
|
|
add(mScrollPane);
|
|
}
|
|
|
|
/**
|
|
* Custom cell renderer for the broadcast state column.
|
|
*/
|
|
public class StatusCellRenderer extends DefaultTableCellRenderer
|
|
{
|
|
public StatusCellRenderer()
|
|
{
|
|
setOpaque(true);
|
|
setHorizontalAlignment(SwingConstants.CENTER);
|
|
}
|
|
|
|
@Override
|
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
|
boolean hasFocus, int row, int column)
|
|
{
|
|
JLabel component = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
|
|
|
if(isSelected)
|
|
{
|
|
setBackground(table.getSelectionBackground());
|
|
setForeground(table.getSelectionForeground());
|
|
}
|
|
else
|
|
{
|
|
if(value instanceof BroadcastState)
|
|
{
|
|
BroadcastState state = (BroadcastState)value;
|
|
|
|
if(state == BroadcastState.CONNECTED)
|
|
{
|
|
setBackground(Color.GREEN);
|
|
setForeground(table.getForeground());
|
|
}
|
|
else if(state == BroadcastState.DISABLED)
|
|
{
|
|
setBackground(table.getBackground());
|
|
setForeground(Color.LIGHT_GRAY);
|
|
}
|
|
else if(state == BroadcastState.INVALID_SETTINGS ||
|
|
state == BroadcastState.NETWORK_UNAVAILABLE)
|
|
{
|
|
setBackground(Color.YELLOW);
|
|
setForeground(table.getForeground());
|
|
}
|
|
else if(state.isErrorState())
|
|
{
|
|
setBackground(Color.RED);
|
|
setForeground(table.getForeground());
|
|
}
|
|
else
|
|
{
|
|
setBackground(table.getBackground());
|
|
setForeground(table.getForeground());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
setForeground(table.getForeground());
|
|
setBackground(table.getBackground());
|
|
}
|
|
}
|
|
|
|
return this;
|
|
}
|
|
}
|
|
}
|