Search in sources :

Example 1 with MainWindow

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() {
        }
    });
}
Also used : MainWindow(org.jivesoftware.MainWindow) MainWindowListener(org.jivesoftware.MainWindowListener)

Example 2 with MainWindow

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();
        }
    });
}
Also used : ChatFrame(org.jivesoftware.spark.ui.ChatFrame) MainWindow(org.jivesoftware.MainWindow) ApplicationEvent(com.apple.eawt.ApplicationEvent) ApplicationAdapter(com.apple.eawt.ApplicationAdapter)

Example 3 with MainWindow

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();
    });
}
Also used : java.awt(java.awt) PrintWriter(java.io.PrintWriter) Arrays(java.util.Arrays) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) SparkRes(org.jivesoftware.resource.SparkRes) SparkManager(org.jivesoftware.spark.SparkManager) StringWriter(java.io.StringWriter) Res(org.jivesoftware.resource.Res) Writer(java.io.Writer) MainWindow(org.jivesoftware.MainWindow) javax.swing(javax.swing) PropertyChangeListener(java.beans.PropertyChangeListener) MainWindow(org.jivesoftware.MainWindow)

Example 4 with MainWindow

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();
}
Also used : Frame(java.awt.Frame) ChatFrame(org.jivesoftware.spark.ui.ChatFrame) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) Rectangle(java.awt.Rectangle) MouseAdapter(java.awt.event.MouseAdapter) Cursor(java.awt.Cursor) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) URISyntaxException(java.net.URISyntaxException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) AWTException(java.awt.AWTException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) KeyEvent(java.awt.event.KeyEvent) GraphicsDevice(java.awt.GraphicsDevice) ChatFrame(org.jivesoftware.spark.ui.ChatFrame) MainWindow(org.jivesoftware.MainWindow) SwingWorker(org.jivesoftware.spark.util.SwingWorker)

Example 5 with MainWindow

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);
                }
            });
        }
    }
}
Also used : MainWindow(org.jivesoftware.MainWindow)

Aggregations

MainWindow (org.jivesoftware.MainWindow)5 ChatFrame (org.jivesoftware.spark.ui.ChatFrame)2 ApplicationAdapter (com.apple.eawt.ApplicationAdapter)1 ApplicationEvent (com.apple.eawt.ApplicationEvent)1 java.awt (java.awt)1 AWTException (java.awt.AWTException)1 Cursor (java.awt.Cursor)1 Frame (java.awt.Frame)1 GraphicsDevice (java.awt.GraphicsDevice)1 GraphicsEnvironment (java.awt.GraphicsEnvironment)1 Rectangle (java.awt.Rectangle)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 BufferedImage (java.awt.image.BufferedImage)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1