use of java.awt.event.WindowAdapter in project gephi by gephi.
the class DataLaboratoryHelper method executeManipulator.
/**
* Prepares the dialog UI of a manipulator if it has one and executes the manipulator in a separate
* Thread when the dialog is accepted or directly if there is no UI.
* @param m Manipulator to execute
*/
public void executeManipulator(final Manipulator m) {
if (m.canExecute()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final ManipulatorUI ui = m.getUI();
//Show a dialog for the manipulator UI if it provides one. If not, execute the manipulator directly:
if (ui != null) {
final JButton okButton = new JButton(NbBundle.getMessage(DataLaboratoryHelper.class, "DataLaboratoryHelper.ui.okButton.text"));
DialogControls dialogControls = new DialogControlsImpl(okButton);
ui.setup(m, dialogControls);
JPanel settingsPanel = ui.getSettingsPanel();
DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(DataLaboratoryHelper.class, "SettingsPanel.title", ui.getDisplayName()), ui.isModal(), new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(okButton)) {
ui.unSetup();
executeManipulatorInOtherThread(m);
} else {
ui.unSetup();
}
}
});
dd.setOptions(new Object[] { okButton, DialogDescriptor.CANCEL_OPTION });
//All options close
dd.setClosingOptions(null);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
ui.unSetup();
}
});
dialog.setVisible(true);
} else {
executeManipulatorInOtherThread(m);
}
}
});
}
}
use of java.awt.event.WindowAdapter in project jmonkeyengine by jMonkeyEngine.
the class JoglDisplay method applySettings.
protected void applySettings(AppSettings settings) {
final boolean isDisplayModeModified;
final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
// Get the current display mode
final DisplayMode previousDisplayMode = gd.getDisplayMode();
// Handle full screen mode if requested.
if (settings.isFullscreen()) {
frame.setUndecorated(true);
// Check if the full-screen mode is supported by the OS
boolean isFullScreenSupported = gd.isFullScreenSupported();
if (isFullScreenSupported) {
gd.setFullScreenWindow(frame);
// Check if display mode changes are supported by the OS
if (gd.isDisplayChangeSupported()) {
// Get all available display modes
final DisplayMode[] displayModes = gd.getDisplayModes();
DisplayMode multiBitsDepthSupportedDisplayMode = null;
DisplayMode refreshRateUnknownDisplayMode = null;
DisplayMode multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode = null;
DisplayMode matchingDisplayMode = null;
DisplayMode currentDisplayMode;
// that matches exactly with your parameters
for (int i = 0; i < displayModes.length && matchingDisplayMode == null; i++) {
currentDisplayMode = displayModes[i];
if (currentDisplayMode.getWidth() == settings.getWidth() && currentDisplayMode.getHeight() == settings.getHeight()) {
if (currentDisplayMode.getBitDepth() == settings.getBitsPerPixel()) {
if (currentDisplayMode.getRefreshRate() == settings.getFrequency()) {
matchingDisplayMode = currentDisplayMode;
} else if (currentDisplayMode.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN) {
refreshRateUnknownDisplayMode = currentDisplayMode;
}
} else if (currentDisplayMode.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) {
if (currentDisplayMode.getRefreshRate() == settings.getFrequency()) {
multiBitsDepthSupportedDisplayMode = currentDisplayMode;
} else if (currentDisplayMode.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN) {
multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode = currentDisplayMode;
}
}
}
}
DisplayMode nextDisplayMode = null;
if (matchingDisplayMode != null) {
nextDisplayMode = matchingDisplayMode;
} else if (multiBitsDepthSupportedDisplayMode != null) {
nextDisplayMode = multiBitsDepthSupportedDisplayMode;
} else if (refreshRateUnknownDisplayMode != null) {
nextDisplayMode = refreshRateUnknownDisplayMode;
} else if (multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode != null) {
nextDisplayMode = multiBitsDepthSupportedAndRefreshRateUnknownDisplayMode;
} else {
isFullScreenSupported = false;
}
// with the input parameters, use it
if (nextDisplayMode != null) {
gd.setDisplayMode(nextDisplayMode);
isDisplayModeModified = true;
} else {
isDisplayModeModified = false;
}
} else {
isDisplayModeModified = false;
// Resize the canvas if the display mode cannot be changed
// and the screen size is not equal to the canvas size
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
if (screenSize.width != settings.getWidth() || screenSize.height != settings.getHeight()) {
canvas.setSize(screenSize);
}
}
} else {
isDisplayModeModified = false;
}
// Software windowed full-screen mode
if (!isFullScreenSupported) {
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// Resize the canvas
canvas.setSize(screenSize);
// Resize the frame so that it occupies the whole screen
frame.setSize(screenSize);
// Set its location at the top left corner
frame.setLocation(0, 0);
}
} else // Otherwise, center the window on the screen.
{
isDisplayModeModified = false;
frame.pack();
int x, y;
x = (Toolkit.getDefaultToolkit().getScreenSize().width - settings.getWidth()) / 2;
y = (Toolkit.getDefaultToolkit().getScreenSize().height - settings.getHeight()) / 2;
frame.setLocation(x, y);
}
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) {
// If required, restore the previous display mode
if (isDisplayModeModified) {
gd.setDisplayMode(previousDisplayMode);
}
// If required, get back to the windowed mode
if (gd.getFullScreenWindow() == frame) {
gd.setFullScreenWindow(null);
}
windowCloseRequest.set(true);
}
@Override
public void windowActivated(WindowEvent evt) {
active.set(true);
}
@Override
public void windowDeactivated(WindowEvent evt) {
active.set(false);
}
});
logger.log(Level.FINE, "Selected display mode: {0}x{1}x{2} @{3}", new Object[] { gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight(), gd.getDisplayMode().getBitDepth(), gd.getDisplayMode().getRefreshRate() });
}
use of java.awt.event.WindowAdapter in project groovy-core by groovy.
the class Main method doTreeAction.
public static void doTreeAction(String f, AST t, String[] tokenNames) {
if (t == null)
return;
if (showTree) {
CommonAST.setVerboseStringConversion(true, tokenNames);
ASTFactory factory = new ASTFactory();
AST r = factory.create(0, "AST ROOT");
r.setFirstChild(t);
final ASTFrame frame = new ASTFrame("Groovy AST", r);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// hide the Frame
frame.setVisible(false);
frame.dispose();
System.exit(0);
}
});
if (verbose)
System.out.println(t.toStringList());
}
/*if ( xml ) {
((CommonAST)t).setVerboseStringConversion(true, tokenNames);
ASTFactory factory = new ASTFactory();
AST r = factory.create(0,"AST ROOT");
r.setFirstChild(t);
XStream xstream = new XStream();
xstream.alias("ast", CommonAST.class);
try {
xstream.toXML(r,new FileWriter(f + ".xml"));
System.out.println("Written AST to " + f + ".xml");
} catch (Exception e) {
System.out.println("couldn't write to " + f + ".xml");
e.printStackTrace();
}
//if (verbose) System.out.println(t.toStringList());
}*/
/*@todo
GroovyTreeParser tparse = new GroovyTreeParser();
try {
tparse.compilationUnit(t);
if (verbose) System.out.println("successful walk of result AST for "+f);
}
catch (RecognitionException e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
@todo*/
}
use of java.awt.event.WindowAdapter in project gradle by gradle.
the class Application method setupUI.
private void setupUI() {
frame = new JFrame("Gradle");
JPanel mainPanel = new JPanel(new BorderLayout());
frame.getContentPane().add(mainPanel);
mainPanel.add(singlePaneUIInstance.getComponent());
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
singlePaneUIInstance.aboutToShow();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
close();
}
});
frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
frame.setLocationByPlatform(true);
}
use of java.awt.event.WindowAdapter in project gradle by gradle.
the class ProjectAndTaskFilterDialog method setupUI.
private void setupUI() {
mainPanel = new JPanel(new BorderLayout());
dialog.getContentPane().add(mainPanel);
mainPanel.add(createOptionsPanel(), BorderLayout.NORTH);
mainPanel.add(createCenterPanel(), BorderLayout.CENTER);
mainPanel.add(createOkCancelPanel(), BorderLayout.SOUTH);
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
close(false);
}
});
dialog.setSize(600, 750);
dialog.setLocationRelativeTo(dialog.getParent());
}
Aggregations