Search in sources :

Example 1 with GUIPlugin

use of com.ramussoft.gui.common.GUIPlugin in project ramus by Vitaliy-Yakovchuk.

the class Runner method openInNewWindows.

@SuppressWarnings("unchecked")
public void openInNewWindows(final Engine engine, AccessRules rules) {
    List<GUIPlugin> list = new ArrayList<GUIPlugin>();
    initAdditionalGUIPlugins(list, engine, rules);
    list.add(new UndoRedoPlugin(engine));
    final AbstractGUIPluginFactory factory = createGUIPluginFactory(engine, rules, list);
    final JFrame frame = factory.getMainFrame();
    List<JFrame> frames = (List<JFrame>) engine.getPluginProperty(CORE, "AdditionalWindows");
    if (frames == null) {
        frames = new ArrayList<JFrame>();
        engine.setPluginProperty(CORE, "AdditionalWindows", frames);
    }
    frames.add(frame);
    final JFrame mainFrame = (JFrame) engine.getPluginProperty(CORE, "MainFrame");
    frame.setTitle("[" + mainFrame.getTitle() + "]");
    final PropertyChangeListener titleListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            frame.setTitle("[" + (String) evt.getNewValue() + "]");
        }
    };
    factory.getFramework().addCloseMainFrameListener(new CloseMainFrameAdapter() {

        @Override
        public void afterClosed() {
            mainFrame.removePropertyChangeListener("title", titleListener);
            List<JFrame> list = (List<JFrame>) engine.getPluginProperty(CORE, "AdditionalWindows");
            list.remove(frame);
        }
    });
    mainFrame.addPropertyChangeListener("title", titleListener);
    beforeMainFrameShow(frame);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            frame.setVisible(true);
            postShowVisibaleMainFrame(engine, factory.getFramework());
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ArrayList(java.util.ArrayList) UndoRedoPlugin(com.ramussoft.gui.common.UndoRedoPlugin) CloseMainFrameAdapter(com.ramussoft.gui.common.event.CloseMainFrameAdapter) JFrame(javax.swing.JFrame) List(java.util.List) ArrayList(java.util.ArrayList) GUIPlugin(com.ramussoft.gui.common.GUIPlugin) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory)

Example 2 with GUIPlugin

use of com.ramussoft.gui.common.GUIPlugin in project ramus by Vitaliy-Yakovchuk.

the class Client method run.

public void run(final String[] args) {
    final SplashScreen screen = new SplashScreen() {

        /**
         */
        private static final long serialVersionUID = -4641958771849938048L;

        @Override
        protected String getImageName() {
            for (String s : args) if (s.equals("-season"))
                return "/com/ramussoft/season/about.png";
            return "/com/ramussoft/gui/about.png";
        }
    };
    if (Metadata.CLIENT) {
        Metadata.REGISTERED_FOR = ClientConnection.getName();
        Metadata.DEMO_REGISTERED = ClientConnection.getName() != null;
    }
    screen.setLocationRelativeTo(null);
    boolean hide = false;
    for (String s : args) if ("--hide-splash".equals(s))
        hide = true;
    if (!hide)
        screen.setVisible(true);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            List<PluginProvider> suits = new ArrayList<PluginProvider>();
            suits.add(new SimpleAttributePluginSuit());
            initAdditionalPluginSuits(suits);
            PluginFactory factory = createPluginFactory(suits);
            PersistentFactory persistentFactory = new PersistentFactory(null, factory.getAttributePlugins(), null);
            persistentFactory.reinit();
            Engine engine = getEngine(factory, persistentFactory);
            AccessRules rules = getAccessRules();
            e = engine;
            e.setPluginProperty("Core", "PluginList", factory.getPlugins());
            e.setPluginProperty("Core", "PluginFactory", factory);
            LightClient.staticEngine = e;
            LightClient.staticAccessRules = rules;
            List<GUIPlugin> list = new ArrayList<GUIPlugin>();
            QualifierPluginSuit.addPlugins(list, e, rules);
            initAdditionalGuiPlugins(list);
            User me = getMe();
            List<Group> groups = me.getGroups();
            String[] grps = new String[groups.size()];
            for (int i = 0; i < grps.length; i++) grps[i] = groups.get(i).getName();
            AbstractGUIPluginFactory factory1;
            String ws = Options.getString("WindowsControl", "simple");
            if (ws.equals("simple"))
                factory1 = new SimleGUIPluginFactory(list, e, rules, getType(), grps, loadPlugins);
            else
                factory1 = new GUIPluginFactory(list, e, rules, getType(), grps, loadPlugins);
            framework = factory1.getFramework();
            framework.addCloseMainFrameListener(new CloseMainFrameAdapter() {

                @Override
                public void afterClosed() {
                    Client.this.close();
                }
            });
            final JFrame frame = factory1.getMainFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            String title = getTitle();
            frame.setTitle(title);
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    frame.setVisible(true);
                    screen.setVisible(false);
                }
            });
        }
    });
    t.start();
    Thread thread = new Thread("Icons-buffer-cleaner") {

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(20000);
                    IconFactory.clearIconsBuffer(LightClient.staticEngine);
                    IconFactory.clearQualifierIconsBuffer(LightClient.staticEngine);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    thread.setDaemon(true);
    thread.setPriority(Thread.MIN_PRIORITY);
    thread.start();
}
Also used : PersistentFactory(com.ramussoft.core.persistent.PersistentFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) User(com.ramussoft.net.common.User) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) GUIPluginFactory(com.ramussoft.gui.core.GUIPluginFactory) PluginProvider(com.ramussoft.common.PluginProvider) CloseMainFrameAdapter(com.ramussoft.gui.common.event.CloseMainFrameAdapter) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) JFrame(javax.swing.JFrame) SplashScreen(com.ramussoft.gui.common.SplashScreen) AccessRules(com.ramussoft.common.AccessRules) ArrayList(java.util.ArrayList) List(java.util.List) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) GUIPluginFactory(com.ramussoft.gui.core.GUIPluginFactory) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) GUIPlugin(com.ramussoft.gui.common.GUIPlugin) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory)

Example 3 with GUIPlugin

use of com.ramussoft.gui.common.GUIPlugin in project ramus by Vitaliy-Yakovchuk.

the class AboutDialog method createGUIPluginListComponent.

private Component createGUIPluginListComponent() {
    JScrollPane pane = new JScrollPane();
    Object[][] data = new Object[guiPlugins.size()][];
    for (int i = 0; i < guiPlugins.size(); i++) {
        GUIPlugin plugin = guiPlugins.get(i);
        String name = plugin.getName();
        if (plugin instanceof com.ramussoft.gui.common.AttributePlugin)
            name = "Attribute." + name + "." + ((com.ramussoft.gui.common.AttributePlugin) plugin).getAttributeType().getTypeName();
        data[i] = new Object[] { name };
    }
    Arrays.sort(data, new Comparator<Object[]>() {

        @SuppressWarnings("unchecked")
        @Override
        public int compare(Object[] o1, Object[] o2) {
            return ((Comparable<String>) o1[0]).compareTo((String) o2[0]);
        }
    });
    DefaultTableModel model = new DefaultTableModel(data, new Object[] { GlobalResourcesManager.getString("Plugin.Name") }) {

        /**
         */
        private static final long serialVersionUID = 4893341040484525590L;

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    pane.setViewportView(new JTable(model));
    return pane;
}
Also used : JScrollPane(javax.swing.JScrollPane) AttributePlugin(com.ramussoft.common.attribute.AttributePlugin) DefaultTableModel(javax.swing.table.DefaultTableModel) JTable(javax.swing.JTable) GUIPlugin(com.ramussoft.gui.common.GUIPlugin)

Example 4 with GUIPlugin

use of com.ramussoft.gui.common.GUIPlugin in project ramus by Vitaliy-Yakovchuk.

the class Runner method openInNewWindows.

@SuppressWarnings("unchecked")
public JFrame openInNewWindows(final Engine engine, final AccessRules rules, final File file, final boolean recovered) {
    List<GUIPlugin> list = new ArrayList<GUIPlugin>();
    FilePlugin filePlugin = new FilePlugin((FileIEngineImpl) engine.getDeligate(), engine, rules, file, this);
    list.add(filePlugin);
    list.add(new UndoRedoPlugin(engine));
    initAdditionalGUIPlugins(list, engine, rules);
    final AbstractGUIPluginFactory factory = createGUIPluginFactory(engine, rules, list);
    final JFrame frame = factory.getMainFrame();
    engine.setPluginProperty(CORE, "MainFrame", frame);
    String title = getApplicationTitle();
    if (file != null)
        title += " - " + file.getName();
    frame.setTitle(title);
    factory.getFramework().addCloseMainFrameListener(new CloseMainFrameAdapter() {

        @Override
        public void afterClosed() {
            List<JFrame> list = (List<JFrame>) engine.getPluginProperty(CORE, "AdditionalWindows");
            if (list != null) {
                JFrame[] frames = list.toArray(new JFrame[list.size()]);
                for (JFrame frame : frames) {
                    frame.setVisible(false);
                    frame.dispose();
                }
            }
            FileIEngineImpl impl = (FileIEngineImpl) engine.getDeligate();
            try {
                impl.getTemplate().getConnection().close();
                if (engine instanceof Journaled)
                    ((Journaled) engine).close();
                impl.close();
                impl.clear();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });
    Object changed = engine.getPluginProperty(CORE, "Changed");
    if (changed != null)
        filePlugin.changed();
    InputStream is = engine.getInputStream("/user/gui/session.binary");
    if (is != null) {
        try {
            ObjectInputStream ois = new ObjectInputStream(is);
            try {
                final List<ActionEvent> session = (List<ActionEvent>) ois.readObject();
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        for (ActionEvent e : session) if (e != null)
                            factory.getFramework().propertyChanged(e);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                is.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    beforeMainFrameShow(frame);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            frame.setVisible(true);
            if (recovered) {
                factory.getFramework().propertyChanged("FileRecovered");
            } else
                factory.getFramework().propertyChanged("FileOpened", file);
            postShowVisibaleMainFrame(engine, factory.getFramework());
        }
    });
    return frame;
}
Also used : FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ZipException(java.util.zip.ZipException) FileMinimumVersionException(com.ramussoft.core.impl.FileMinimumVersionException) IOException(java.io.IOException) UndoRedoPlugin(com.ramussoft.gui.common.UndoRedoPlugin) Journaled(com.ramussoft.common.journal.Journaled) CloseMainFrameAdapter(com.ramussoft.gui.common.event.CloseMainFrameAdapter) JFrame(javax.swing.JFrame) List(java.util.List) ArrayList(java.util.ArrayList) GUIPlugin(com.ramussoft.gui.common.GUIPlugin) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) ObjectInputStream(java.io.ObjectInputStream)

Example 5 with GUIPlugin

use of com.ramussoft.gui.common.GUIPlugin in project ramus by Vitaliy-Yakovchuk.

the class StatusMessageFormat method format.

private static String format(String pluginAnswer, GUIFramework framework, String pluginName) {
    GUIPlugin plugin = framework.findPlugin(pluginName);
    String[] keys = findKeys(pluginAnswer);
    for (String key : keys) {
        String k = "\\{" + key + "\\}";
        String v;
        if (plugin == null) {
            v = GlobalResourcesManager.getString(key);
            if (v == null)
                v = key;
        } else
            v = plugin.getString(key);
        pluginAnswer = pluginAnswer.replaceAll(k, v);
    }
    return pluginAnswer;
}
Also used : GUIPlugin(com.ramussoft.gui.common.GUIPlugin)

Aggregations

GUIPlugin (com.ramussoft.gui.common.GUIPlugin)6 ArrayList (java.util.ArrayList)4 AbstractGUIPluginFactory (com.ramussoft.gui.common.AbstractGUIPluginFactory)3 CloseMainFrameAdapter (com.ramussoft.gui.common.event.CloseMainFrameAdapter)3 List (java.util.List)3 JFrame (javax.swing.JFrame)3 UndoRedoPlugin (com.ramussoft.gui.common.UndoRedoPlugin)2 AccessRules (com.ramussoft.common.AccessRules)1 Engine (com.ramussoft.common.Engine)1 PluginFactory (com.ramussoft.common.PluginFactory)1 PluginProvider (com.ramussoft.common.PluginProvider)1 AttributePlugin (com.ramussoft.common.attribute.AttributePlugin)1 Journaled (com.ramussoft.common.journal.Journaled)1 SimpleAttributePluginSuit (com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)1 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)1 FileMinimumVersionException (com.ramussoft.core.impl.FileMinimumVersionException)1 PersistentFactory (com.ramussoft.core.persistent.PersistentFactory)1 SplashScreen (com.ramussoft.gui.common.SplashScreen)1 ActionEvent (com.ramussoft.gui.common.event.ActionEvent)1 GUIPluginFactory (com.ramussoft.gui.core.GUIPluginFactory)1