mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
wip: finished alias, alias ID and alias action editing framework.
This commit is contained in:
29
src/gui/editor/DocumentListenerEditor.java
Normal file
29
src/gui/editor/DocumentListenerEditor.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package gui.editor;
|
||||
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
public abstract class DocumentListenerEditor<T> extends Editor<T>
|
||||
implements DocumentListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public DocumentListenerEditor()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertUpdate( DocumentEvent e )
|
||||
{
|
||||
setModified( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate( DocumentEvent e )
|
||||
{
|
||||
setModified( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate( DocumentEvent e ) { }
|
||||
}
|
||||
94
src/gui/editor/Editor.java
Normal file
94
src/gui/editor/Editor.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package gui.editor;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import alias.id.AliasIdentifierEditor;
|
||||
|
||||
/**
|
||||
* Generic editor with change detection, save and reset functions.
|
||||
*/
|
||||
public abstract class Editor<T> extends JPanel
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final static Logger mLog = LoggerFactory.getLogger( Editor.class );
|
||||
|
||||
protected T mItem;
|
||||
protected boolean mModified = false;
|
||||
|
||||
public Editor()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the object to be edited
|
||||
*/
|
||||
public void setItem( T item )
|
||||
{
|
||||
if( isModified() )
|
||||
{
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
Editor.this,
|
||||
"This item has changed. Do you want to save these changes?",
|
||||
"Save Changes?",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE );
|
||||
|
||||
if( option == JOptionPane.YES_OPTION )
|
||||
{
|
||||
save();
|
||||
}
|
||||
|
||||
setModified( false );
|
||||
}
|
||||
|
||||
mItem = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current editing item
|
||||
*/
|
||||
public T getItem()
|
||||
{
|
||||
return mItem;
|
||||
}
|
||||
|
||||
public boolean hasItem()
|
||||
{
|
||||
return mItem != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the contents modified flag
|
||||
*/
|
||||
public void setModified( boolean modified )
|
||||
{
|
||||
mModified = modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this editor contents have been modified
|
||||
*/
|
||||
public boolean isModified()
|
||||
{
|
||||
return mModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the contents of the editor
|
||||
*/
|
||||
public abstract void save();
|
||||
|
||||
/**
|
||||
* Reset the contents of the editor without saving any changes
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
mModified = false;
|
||||
setItem( mItem );
|
||||
}
|
||||
}
|
||||
26
src/gui/editor/EmptyEditor.java
Normal file
26
src/gui/editor/EmptyEditor.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package gui.editor;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
public class EmptyEditor<T> extends Editor<T>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public EmptyEditor()
|
||||
{
|
||||
setLayout( new MigLayout( "", "[center]", "[grow]" ) );
|
||||
add( new JLabel( "Please select an item" ), "wrap" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user