mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
ant to gradle. Removes linux and windows application launch scripts and produces an executable jar with all resources included.
156 lines
5.2 KiB
Java
156 lines
5.2 KiB
Java
/*******************************************************************************
|
|
* 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 <http://www.gnu.org/licenses/>
|
|
*
|
|
******************************************************************************/
|
|
package io.github.dsheirer.icon;
|
|
|
|
import net.miginfocom.swing.MigLayout;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.event.ListSelectionEvent;
|
|
import javax.swing.event.ListSelectionListener;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
|
|
public class IconEditor extends JFrame implements ActionListener
|
|
{
|
|
private static final long serialVersionUID = 1L;
|
|
private static final Logger mLog = LoggerFactory.getLogger(IconEditor.class);
|
|
private static final String ADD = "Add";
|
|
private static final String DEFAULT = "Set Default";
|
|
private static final String DELETE = "Delete";
|
|
|
|
private JButton mAddButton;
|
|
private JButton mDeleteButton;
|
|
private JButton mDefaultButton;
|
|
private JTable mIconTable;
|
|
private IconManager mIconManager;
|
|
|
|
public IconEditor(IconManager model)
|
|
{
|
|
mIconManager = model;
|
|
|
|
init();
|
|
}
|
|
|
|
private void init()
|
|
{
|
|
setTitle("Icon Manager");
|
|
setSize(400, 400);
|
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
setLayout(new MigLayout("", "[grow,fill]", "[grow,fill]"));
|
|
|
|
/**
|
|
* Editor Panel
|
|
*/
|
|
JPanel editorPanel = new JPanel();
|
|
editorPanel.setLayout(new MigLayout("insets 1 1 1 1", "[grow,fill][grow,fill][grow,fill]", "[grow,fill][]"));
|
|
|
|
mIconTable = new JTable(mIconManager.getModel());
|
|
IconTableCellRenderer renderer = new IconTableCellRenderer(mIconManager);
|
|
mIconTable.getColumnModel().getColumn(IconTableModel.COLUMN_IMAGE_ICON).setCellRenderer(renderer);
|
|
mIconTable.setAutoCreateRowSorter(true);
|
|
mIconTable.getRowSorter().toggleSortOrder(IconTableModel.COLUMN_ICON_NAME);
|
|
mIconTable.setRowHeight(36);
|
|
mIconTable.getSelectionModel().addListSelectionListener(new ListSelectionListener()
|
|
{
|
|
@Override
|
|
public void valueChanged(ListSelectionEvent e)
|
|
{
|
|
checkButtons();
|
|
}
|
|
});
|
|
editorPanel.add(new JScrollPane(mIconTable), "span");
|
|
|
|
mAddButton = new JButton(ADD);
|
|
mAddButton.addActionListener(this);
|
|
editorPanel.add(mAddButton);
|
|
|
|
mDeleteButton = new JButton(DELETE);
|
|
mDeleteButton.addActionListener(this);
|
|
mDeleteButton.setEnabled(false);
|
|
editorPanel.add(mDeleteButton);
|
|
|
|
mDefaultButton = new JButton(DEFAULT);
|
|
mDefaultButton.addActionListener(this);
|
|
mDefaultButton.setEnabled(false);
|
|
editorPanel.add(mDefaultButton, "wrap");
|
|
|
|
add(editorPanel);
|
|
}
|
|
|
|
private void checkButtons()
|
|
{
|
|
io.github.dsheirer.icon.Icon selected = getSelectedIcon();
|
|
|
|
mDefaultButton.setEnabled(selected != null && selected != mIconManager.getModel().getDefaultIcon());
|
|
mDeleteButton.setEnabled(selected != null && selected != mIconManager.getModel().getDefaultIcon());
|
|
}
|
|
|
|
private io.github.dsheirer.icon.Icon getSelectedIcon()
|
|
{
|
|
int selectedViewRow = mIconTable.getSelectedRow();
|
|
|
|
if(selectedViewRow >= 0)
|
|
{
|
|
int selectedModelRow = mIconTable.convertRowIndexToModel(mIconTable.getSelectedRow());
|
|
|
|
if(selectedModelRow >= 0)
|
|
{
|
|
return mIconManager.getModel().get(selectedModelRow);
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
{
|
|
io.github.dsheirer.icon.Icon selected = getSelectedIcon();
|
|
|
|
switch(e.getActionCommand())
|
|
{
|
|
case ADD:
|
|
IconSelector iconSelector = new IconSelector(this, mIconManager.getModel());
|
|
iconSelector.setVisible(true);
|
|
break;
|
|
case DELETE:
|
|
if(selected != null)
|
|
{
|
|
int choice = JOptionPane.showConfirmDialog(IconEditor.this,
|
|
"Are you sure you want to delete this icon?", "Delete Icon?", JOptionPane.YES_NO_OPTION);
|
|
|
|
if(choice == JOptionPane.YES_OPTION)
|
|
{
|
|
mIconManager.getModel().remove(selected);
|
|
}
|
|
}
|
|
break;
|
|
case DEFAULT:
|
|
if(selected != null)
|
|
{
|
|
mIconManager.getModel().setDefaultIcon(selected);
|
|
}
|
|
break;
|
|
}
|
|
|
|
checkButtons();
|
|
}
|
|
}
|