Made XML Sandbox non-modal, using a glass pane
This commit is contained in:
parent
376299dddd
commit
c88ecf0bc8
4 changed files with 137 additions and 16 deletions
55
src/main/java/net/vhati/modmanager/ui/InertPanel.java
Normal file
55
src/main/java/net/vhati/modmanager/ui/InertPanel.java
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
package net.vhati.modmanager.ui;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Cursor;
|
||||||
|
import java.awt.KeyEventDispatcher;
|
||||||
|
import java.awt.KeyboardFocusManager;
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A panel that consumes all mouse/keyboard events, for use as a glass pane.
|
||||||
|
*/
|
||||||
|
public class InertPanel extends JPanel {
|
||||||
|
|
||||||
|
private KeyEventDispatcher nullDispatcher;
|
||||||
|
|
||||||
|
|
||||||
|
public InertPanel() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
nullDispatcher = new KeyEventDispatcher() {
|
||||||
|
@Override
|
||||||
|
public boolean dispatchKeyEvent( KeyEvent e ) {
|
||||||
|
return InertPanel.this == ( (JFrame)SwingUtilities.getWindowAncestor( (Component)e.getSource() ) ).getGlassPane();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed( MouseEvent e ) {e.consume();}
|
||||||
|
@Override
|
||||||
|
public void mouseReleased( MouseEvent e ) {e.consume();}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setCursor(Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ));
|
||||||
|
this.setOpaque( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVisible( boolean b ) {
|
||||||
|
super.setVisible( b );
|
||||||
|
if ( b ) {
|
||||||
|
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher( nullDispatcher );
|
||||||
|
} else {
|
||||||
|
KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher( nullDispatcher );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,6 +72,7 @@ import net.vhati.modmanager.core.Report.ReportFormatter;
|
||||||
import net.vhati.modmanager.json.GrognakCatalogFetcher;
|
import net.vhati.modmanager.json.GrognakCatalogFetcher;
|
||||||
import net.vhati.modmanager.json.JacksonGrognakCatalogReader;
|
import net.vhati.modmanager.json.JacksonGrognakCatalogReader;
|
||||||
import net.vhati.modmanager.ui.ChecklistTableModel;
|
import net.vhati.modmanager.ui.ChecklistTableModel;
|
||||||
|
import net.vhati.modmanager.ui.InertPanel;
|
||||||
import net.vhati.modmanager.ui.ModInfoArea;
|
import net.vhati.modmanager.ui.ModInfoArea;
|
||||||
import net.vhati.modmanager.ui.ModPatchDialog;
|
import net.vhati.modmanager.ui.ModPatchDialog;
|
||||||
import net.vhati.modmanager.ui.ModXMLSandbox;
|
import net.vhati.modmanager.ui.ModXMLSandbox;
|
||||||
|
@ -83,7 +84,7 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
public class ManagerFrame extends JFrame implements ActionListener, HashObserver, Statusbar {
|
public class ManagerFrame extends JFrame implements ActionListener, HashObserver, Nerfable, Statusbar {
|
||||||
|
|
||||||
private static final Logger log = LogManager.getLogger(ManagerFrame.class);
|
private static final Logger log = LogManager.getLogger(ManagerFrame.class);
|
||||||
|
|
||||||
|
@ -100,6 +101,8 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver
|
||||||
private String appURL;
|
private String appURL;
|
||||||
private String appAuthor;
|
private String appAuthor;
|
||||||
|
|
||||||
|
private NerfListener nerfListener = new NerfListener( this );
|
||||||
|
|
||||||
private HashMap<File,String> modFileHashes = new HashMap<File,String>();
|
private HashMap<File,String> modFileHashes = new HashMap<File,String>();
|
||||||
private ModDB modDB = new ModDB();
|
private ModDB modDB = new ModDB();
|
||||||
|
|
||||||
|
@ -319,6 +322,8 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver
|
||||||
menubar.add( helpMenu );
|
menubar.add( helpMenu );
|
||||||
this.setJMenuBar( menubar );
|
this.setJMenuBar( menubar );
|
||||||
|
|
||||||
|
this.setGlassPane( new InertPanel() );
|
||||||
|
|
||||||
this.setContentPane( contentPane );
|
this.setContentPane( contentPane );
|
||||||
this.pack();
|
this.pack();
|
||||||
this.setMinimumSize( new Dimension( 300, modActionsPanel.getPreferredSize().height+90 ) );
|
this.setMinimumSize( new Dimension( 300, modActionsPanel.getPreferredSize().height+90 ) );
|
||||||
|
@ -691,8 +696,11 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver
|
||||||
File datsDir = new File( config.getProperty( "ftl_dats_path" ) );
|
File datsDir = new File( config.getProperty( "ftl_dats_path" ) );
|
||||||
File dataDatFile = new File( datsDir, "data.dat" );
|
File dataDatFile = new File( datsDir, "data.dat" );
|
||||||
|
|
||||||
ModXMLSandbox sandboxDlg = new ModXMLSandbox( this, dataDatFile );
|
ModXMLSandbox sandboxFrame = new ModXMLSandbox( dataDatFile );
|
||||||
sandboxDlg.setVisible( true );
|
sandboxFrame.addWindowListener( nerfListener );
|
||||||
|
sandboxFrame.setSize( 800, 600 );
|
||||||
|
sandboxFrame.setLocationRelativeTo( null );
|
||||||
|
sandboxFrame.setVisible( true );
|
||||||
}
|
}
|
||||||
else if ( source == exitMenuItem ) {
|
else if ( source == exitMenuItem ) {
|
||||||
setStatusText( "" );
|
setStatusText( "" );
|
||||||
|
@ -752,6 +760,37 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNerfed( boolean b ) {
|
||||||
|
Component glassPane = this.getGlassPane();
|
||||||
|
if (b) {
|
||||||
|
glassPane.setVisible(true);
|
||||||
|
glassPane.requestFocusInWindow();
|
||||||
|
} else {
|
||||||
|
glassPane.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static class NerfListener extends WindowAdapter {
|
||||||
|
private Nerfable nerfObj;
|
||||||
|
|
||||||
|
public NerfListener( Nerfable nerfObj ) {
|
||||||
|
this.nerfObj = nerfObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowOpened( WindowEvent e ) {
|
||||||
|
nerfObj.setNerfed( true );
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void windowClosing( WindowEvent e ) {
|
||||||
|
nerfObj.setNerfed( false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static class ModFileFilter implements FileFilter {
|
private static class ModFileFilter implements FileFilter {
|
||||||
boolean allowZip;
|
boolean allowZip;
|
||||||
|
|
|
@ -28,9 +28,9 @@ import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JDialog;
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JSplitPane;
|
import javax.swing.JSplitPane;
|
||||||
|
@ -65,7 +65,10 @@ import org.jdom2.Document;
|
||||||
import org.jdom2.input.JDOMParseException;
|
import org.jdom2.input.JDOMParseException;
|
||||||
|
|
||||||
|
|
||||||
public class ModXMLSandbox extends JDialog implements ActionListener {
|
/**
|
||||||
|
* A basic text editor to test XML modding.
|
||||||
|
*/
|
||||||
|
public class ModXMLSandbox extends JFrame implements ActionListener {
|
||||||
|
|
||||||
private UndoManager undoManager = new UndoManager();
|
private UndoManager undoManager = new UndoManager();
|
||||||
private Document mainDoc = null;
|
private Document mainDoc = null;
|
||||||
|
@ -76,6 +79,7 @@ public class ModXMLSandbox extends JDialog implements ActionListener {
|
||||||
private JScrollPane mainScroll;
|
private JScrollPane mainScroll;
|
||||||
private JScrollPane appendScroll;
|
private JScrollPane appendScroll;
|
||||||
private JScrollPane resultScroll;
|
private JScrollPane resultScroll;
|
||||||
|
private JSplitPane splitPane;
|
||||||
private JScrollPane messageScroll;
|
private JScrollPane messageScroll;
|
||||||
|
|
||||||
private JTextArea mainArea;
|
private JTextArea mainArea;
|
||||||
|
@ -88,8 +92,8 @@ public class ModXMLSandbox extends JDialog implements ActionListener {
|
||||||
private JLabel statusLbl;
|
private JLabel statusLbl;
|
||||||
|
|
||||||
|
|
||||||
public ModXMLSandbox( Frame owner, File dataDatFile ) {
|
public ModXMLSandbox( File dataDatFile ) {
|
||||||
super( owner, "Mod XML Sandbox", true );
|
super( "Mod XML Sandbox" );
|
||||||
|
|
||||||
this.dataDatFile = dataDatFile;
|
this.dataDatFile = dataDatFile;
|
||||||
|
|
||||||
|
@ -145,7 +149,7 @@ public class ModXMLSandbox extends JDialog implements ActionListener {
|
||||||
topPanel.add( areasPane, BorderLayout.CENTER );
|
topPanel.add( areasPane, BorderLayout.CENTER );
|
||||||
topPanel.add( ctrlPanel, BorderLayout.SOUTH );
|
topPanel.add( ctrlPanel, BorderLayout.SOUTH );
|
||||||
|
|
||||||
final JSplitPane splitPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
|
splitPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
|
||||||
splitPane.setTopComponent( topPanel );
|
splitPane.setTopComponent( topPanel );
|
||||||
splitPane.setBottomComponent( messageArea );
|
splitPane.setBottomComponent( messageArea );
|
||||||
|
|
||||||
|
@ -272,9 +276,15 @@ public class ModXMLSandbox extends JDialog implements ActionListener {
|
||||||
resultArea.addAncestorListener( new FocusAncestorListener( resultArea ) );
|
resultArea.addAncestorListener( new FocusAncestorListener( resultArea ) );
|
||||||
|
|
||||||
this.pack();
|
this.pack();
|
||||||
this.setSize( 800, 600 );
|
}
|
||||||
this.setLocationRelativeTo( null );
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVisible( boolean b ) {
|
||||||
|
super.setVisible( b );
|
||||||
|
|
||||||
|
if ( b ) {
|
||||||
|
// Splitpane has to be realized before the divider can be moved.
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -282,6 +292,7 @@ public class ModXMLSandbox extends JDialog implements ActionListener {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
16
src/main/java/net/vhati/modmanager/ui/Nerfable.java
Normal file
16
src/main/java/net/vhati/modmanager/ui/Nerfable.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package net.vhati.modmanager.ui;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* An interface to en/disable user interaction.
|
||||||
|
* It was written with JFrames and glass panes in mind.
|
||||||
|
*/
|
||||||
|
public interface Nerfable {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Either nerf or restore user interaction.
|
||||||
|
*
|
||||||
|
* @param b the nerfed state
|
||||||
|
*/
|
||||||
|
public void setNerfed( boolean b );
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue