use of org.jivesoftware.MainWindow in project Spark by igniterealtime.
the class LayoutPlugin method initialize.
public void initialize() {
final MainWindow mainWindow = SparkManager.getMainWindow();
SparkManager.getMainWindow().addMainWindowListener(new MainWindowListener() {
public void shutdown() {
LayoutSettingsManager.getLayoutSettings().setMainWindowBounds(mainWindow.getBounds());
if (mainWindow.isDocked()) {
LayoutSettingsManager.getLayoutSettings().setSplitPaneDividerLocation(mainWindow.getSplitPane().getDividerLocation());
} else {
LayoutSettingsManager.getLayoutSettings().setSplitPaneDividerLocation(-1);
}
LayoutSettingsManager.saveLayoutSettings();
}
public void mainWindowActivated() {
}
public void mainWindowDeactivated() {
}
});
}
use of org.jivesoftware.MainWindow in project Spark by igniterealtime.
the class ApplePlugin method initialize.
@SuppressWarnings("deprecation")
public void initialize() {
_props = new AppleProperties();
ApplePreference pref = new ApplePreference(_props);
SparkManager.getPreferenceManager().addPreference(pref);
_applebounce = new AppleBounce(_props);
_appledock = new AppleDock();
SparkManager.getNativeManager().addNativeHandler(this);
handleIdle();
// // register an application listener to show the about box
_application = Application.getApplication();
_application.setEnabledPreferencesMenu(true);
_application.addPreferencesMenuItem();
_application.addApplicationListener(new ApplicationAdapter() {
public void handlePreferences(ApplicationEvent applicationEvent) {
SparkManager.getPreferenceManager().showPreferences();
}
public void handleReOpenApplication(ApplicationEvent event) {
MainWindow mainWindow = SparkManager.getMainWindow();
if (!mainWindow.isVisible()) {
mainWindow.setState(Frame.NORMAL);
mainWindow.setVisible(true);
}
if (SparkManager.getChatManager().getChatContainer().getTotalNumberOfUnreadMessages() > 0) {
final ChatFrame frame = SparkManager.getChatManager().getChatContainer().getChatFrame();
frame.setState(Frame.NORMAL);
frame.setVisible(true);
frame.toFront();
}
}
public void handleQuit(ApplicationEvent applicationEvent) {
SparkManager.getMainWindow().shutdown();
}
});
}
use of org.jivesoftware.MainWindow in project Spark by igniterealtime.
the class MessageDialog method showAlert.
/**
* Display an alert dialog.
*
* @param message the message to display.
* @param header the header/title of the dialog.
* @param title the title to display.
* @param icon the icon for the alert dialog.
*/
public static void showAlert(final String message, final String header, final String title, final Icon icon) {
EventQueue.invokeLater(() -> {
JTextPane textPane;
final JOptionPane pane;
final JDialog dlg;
TitlePanel titlePanel;
textPane = new JTextPane();
textPane.setFont(new Font("Dialog", Font.PLAIN, 12));
textPane.setEditable(false);
textPane.setText(message);
textPane.setBackground(Color.white);
// Create the title panel for this dialog
titlePanel = new TitlePanel(header, null, icon, true);
// Construct main panel w/ layout.
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(titlePanel, BorderLayout.NORTH);
// The user should only be able to close this dialog.
Object[] options = { Res.getString("close") };
pane = new JOptionPane(new JScrollPane(textPane), JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
mainPanel.add(pane, BorderLayout.CENTER);
MainWindow mainWindow = SparkManager.getMainWindow();
dlg = new JDialog(mainWindow, title, false);
dlg.pack();
dlg.setSize(300, 300);
dlg.setContentPane(mainPanel);
dlg.setLocationRelativeTo(SparkManager.getMainWindow());
PropertyChangeListener changeListener = e -> {
String value = (String) pane.getValue();
if (Res.getString("close").equals(value)) {
dlg.setVisible(false);
}
};
pane.addPropertyChangeListener(changeListener);
dlg.setVisible(true);
dlg.toFront();
dlg.requestFocus();
});
}
use of org.jivesoftware.MainWindow in project Spark by igniterealtime.
the class SparkTransferManager method sendScreenshot.
public void sendScreenshot(final ChatRoomButton button, final ChatRoom room) {
button.setEnabled(false);
final MainWindow mainWindow = SparkManager.getMainWindow();
final ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
final boolean mainWindowVisible = mainWindow.isVisible();
final boolean chatFrameVisible = chatFrame.isVisible();
if (mainWindowVisible) {
mainWindow.setVisible(false);
}
if (chatFrameVisible) {
chatFrame.setVisible(false);
}
final SwingWorker worker = new SwingWorker() {
public Object construct() {
try {
Thread.sleep(1000);
Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
return robot.createScreenCapture(area);
} catch (Throwable e) {
Log.error(e);
if (mainWindowVisible) {
mainWindow.setVisible(true);
}
if (chatFrameVisible) {
chatFrame.setVisible(true);
}
}
return null;
}
public void finished() {
bufferedImage = (BufferedImage) get();
if (bufferedImage == null) {
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(null, Res.getString("title.error"), "Unable to process screenshot.", JOptionPane.ERROR_MESSAGE);
return;
}
final Frame frame = new Frame();
frame.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
selectionPanel.setImage(bufferedImage);
selectionPanel.validate();
selectionPanel.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
Rectangle clip = selectionPanel.getClip();
BufferedImage newImage = null;
try {
newImage = bufferedImage.getSubimage((int) clip.getX(), (int) clip.getY(), (int) clip.getWidth(), (int) clip.getHeight());
} catch (Exception e1) {
// Nothing to do
}
if (newImage != null) {
sendImage(newImage, room);
bufferedImage = null;
selectionPanel.clear();
}
frame.dispose();
frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if (mainWindowVisible) {
mainWindow.setVisible(true);
}
if (chatFrameVisible) {
chatFrame.setVisible(true);
}
selectionPanel.removeMouseListener(this);
}
});
frame.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
frame.dispose();
frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if (mainWindowVisible) {
mainWindow.setVisible(true);
}
if (chatFrameVisible) {
chatFrame.setVisible(true);
}
}
}
});
frame.setSize(bufferedImage.getWidth(null), bufferedImage.getHeight());
frame.add(selectionPanel);
frame.setUndecorated(true);
// Determine if full-screen mode is supported directly
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
if (gs.isFullScreenSupported()) {
gs.setFullScreenWindow(frame);
} else {
// Full-screen mode will be simulated
frame.setVisible(true);
}
button.setEnabled(true);
}
};
worker.start();
}
use of org.jivesoftware.MainWindow in project Spark by igniterealtime.
the class ChatContainer method blinkFrameIfNecessary.
public void blinkFrameIfNecessary(final JFrame frame) {
final MainWindow mainWindow = SparkManager.getMainWindow();
if (mainWindow.isFocusOwner()) {
frame.setVisible(true);
} else {
// Set to new tab.
if (Spark.isWindows()) {
frame.setState(Frame.ICONIFIED);
SparkManager.getNativeManager().flashWindow(frame);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {
SparkManager.getNativeManager().stopFlashing(frame);
}
});
}
}
}
Aggregations