Search in sources :

Example 1 with CFocusListener

use of bibliothek.gui.dock.common.event.CFocusListener in project jsoar by soartech.

the class JSoarDebugger method initialize.

/**
 * Initialize the debugger
 *
 * @param parentFrame The parent frame of the debugger
 * @param proxy A non-null, <b>initialized</b> agent proxy
 */
private void initialize(final JXFrame parentFrame, ThreadedAgent proxy) {
    logger.info("Initializing debugger for agent '" + proxy + "'");
    final float scaleUpFactor = 4.0f / 3.0f;
    final float scaleDownFactor = .75f;
    parentFrame.addMouseWheelListener(e -> {
        if (e.isControlDown()) {
            float scaleFactor = 1.0f;
            if (e.getWheelRotation() < 0) {
                scaleFactor = scaleUpFactor;
            } else if (e.getWheelRotation() > 0) {
                scaleFactor = scaleDownFactor;
            }
            fontScale = fontScale * scaleFactor;
            setFontScale(scaleFactor, parentFrame.getComponents());
            SwingTools.setFontScale(scaleFactor);
            parentFrame.repaint();
        }
    });
    parentFrame.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.isControlDown()) {
                float scaleFactor = 1.0f;
                if (e.getKeyCode() == KeyEvent.VK_PLUS || e.getKeyCode() == KeyEvent.VK_EQUALS) {
                    scaleFactor = scaleUpFactor;
                } else if (e.getKeyCode() == KeyEvent.VK_MINUS) {
                    scaleFactor = scaleDownFactor;
                } else {
                    super.keyPressed(e);
                }
                fontScale = fontScale * scaleFactor;
                setFontScale(scaleFactor, parentFrame.getComponents());
                SwingTools.setFontScale(scaleFactor);
                parentFrame.repaint();
            } else {
                super.keyPressed(e);
            }
        }
    });
    this.frame = parentFrame;
    this.frame.setTitle("JSoar Debugger - " + proxy.getName());
    this.agent = proxy;
    proxy.getInterpreter().addCommand("load-plugin", loadPluginCommand);
    proxy.getInterpreter().addCommand("edit-production", new EditProductionCommand(agent.getAgent()));
    agent.getAgent().getRhsFunctions().registerHandler(new AcceptRhsFunction());
    this.docking = new CControl(this.frame);
    this.docking.setTheme(ThemeMap.KEY_ECLIPSE_THEME);
    // Track selection to active view
    this.docking.addFocusListener(new CFocusListener() {

        @Override
        public void focusLost(CDockable dockable) {
        }

        @Override
        public void focusGained(final CDockable newDockable) {
            SelectionProvider provider = Adaptables.adapt(newDockable, SelectionProvider.class);
            if (provider != null) {
                selectionManager.setSelectionProvider(provider);
            }
            // HACK: For some reason the WM tree briefly gets focus which messes this
            // up when using a hotkey to switch to the trace view. So invoke later
            // after everything settles down.
            SwingUtilities.invokeLater(() -> {
                if (newDockable instanceof AbstractAdaptableView) {
                    ((AbstractAdaptableView) newDockable).activate();
                }
            });
        }
    });
    this.add(docking.getContentArea(), BorderLayout.CENTER);
    initActions();
    this.add(status = new StatusBar(proxy), BorderLayout.SOUTH);
    factory = new StopCommandViewFactory(this);
    factory.setDefaultLocation(docking.getDefaultLocation());
    docking.addMultipleDockableFactory("stop-command-factory", factory);
    initViews();
    initMenuBar();
    initToolbar();
    // Track the agent name in the title bar
    saveListener(proxy.getProperties().addListener(SoarProperties.NAME, new PropertyListener<String>() {

        @Override
        public void propertyChanged(PropertyChangeEvent<String> event) {
            frame.setTitle("JSoar Debugger - " + event.getNewValue());
        }
    }));
    // Track agent's running state
    saveListener(proxy.getProperties().addListener(SoarProperties.IS_RUNNING, new PropertyListener<Boolean>() {

        @Override
        public void propertyChanged(PropertyChangeEvent<Boolean> event) {
            updateActionsAndStatus();
        }
    }));
    // Update after init-soar
    proxy.getEvents().addListener(AfterInitSoarEvent.class, saveListener(event -> {
        proxy.getPrinter().flush();
        newUpdateCompleter(true).finish(null);
    }));
    // Update when the agent stops running
    proxy.getEvents().addListener(StopEvent.class, saveListener(event -> {
        proxy.getPrinter().flush();
        newUpdateCompleter(false).finish(null);
    }));
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            final Preferences winPrefs = getWindowPrefs();
            final Rectangle r = frame.getBounds();
            if (frame.getExtendedState() == JFrame.NORMAL) {
                winPrefs.putInt("x", r.x);
                winPrefs.putInt("y", r.y);
                winPrefs.putInt("width", r.width);
                winPrefs.putInt("height", r.height);
            }
            exit();
        }
    });
    final Preferences winPrefs = getWindowPrefs();
    if (winPrefs.get("x", null) != null) {
        frame.setBounds(winPrefs.getInt("x", 0), winPrefs.getInt("y", 0), winPrefs.getInt("width", 1200), winPrefs.getInt("height", 1024));
    } else {
        frame.setSize(1200, 1024);
        // center
        frame.setLocationRelativeTo(null);
    }
    readDefaultLayout();
    update(false);
}
Also used : StopCommandViewFactory(org.jsoar.debugger.stopcommand.StopCommandViewFactory) RunAction(org.jsoar.debugger.actions.RunAction) AfterInitSoarEvent(org.jsoar.kernel.events.AfterInitSoarEvent) SoarEventListener(org.jsoar.util.events.SoarEventListener) CloseAction(org.jsoar.kernel.DebuggerProvider.CloseAction) LoggerFactory(org.slf4j.LoggerFactory) UrlAction(org.jsoar.debugger.actions.UrlAction) PropertyProvider(org.jsoar.util.properties.PropertyProvider) DebuggerProvider(org.jsoar.kernel.DebuggerProvider) StopEvent(org.jsoar.kernel.events.StopEvent) ActionManager(org.jsoar.debugger.actions.ActionManager) CThemeMenuPiece(bibliothek.gui.dock.common.menu.CThemeMenuPiece) SoarEvent(org.jsoar.util.events.SoarEvent) Map(java.util.Map) GarbageCollectorAction(org.jsoar.debugger.actions.GarbageCollectorAction) MatchesProductionAction(org.jsoar.debugger.actions.MatchesProductionAction) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) EnumSet(java.util.EnumSet) StopAction(org.jsoar.debugger.actions.StopAction) JMenuBar(javax.swing.JMenuBar) CompletionHandler(org.jsoar.runtime.CompletionHandler) PropertyKey(org.jsoar.util.properties.PropertyKey) JToolBar(javax.swing.JToolBar) StepAction(org.jsoar.debugger.actions.StepAction) SoarCommand(org.jsoar.util.commands.SoarCommand) SoarException(org.jsoar.kernel.SoarException) SoarCommandInterpreter(org.jsoar.util.commands.SoarCommandInterpreter) JMenu(javax.swing.JMenu) XIO(bibliothek.util.xml.XIO) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) Component(java.awt.Component) WindowEvent(java.awt.event.WindowEvent) ThreadedAgentDetachedEvent(org.jsoar.runtime.ThreadedAgentDetachedEvent) EditProductionAction(org.jsoar.debugger.actions.EditProductionAction) List(java.util.List) SelectionManager(org.jsoar.debugger.selection.SelectionManager) SwingTools(org.jsoar.debugger.util.SwingTools) AbstractAction(javax.swing.AbstractAction) RestoreLayoutAction(org.jsoar.debugger.actions.RestoreLayoutAction) SoarCommands(org.jsoar.util.commands.SoarCommands) PropertyChangeEvent(org.jsoar.util.properties.PropertyChangeEvent) JPanel(javax.swing.JPanel) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) StopCommandViewFactory(org.jsoar.debugger.stopcommand.StopCommandViewFactory) SourceFileAction(org.jsoar.debugger.actions.SourceFileAction) Rectangle(java.awt.Rectangle) SelectionProvider(org.jsoar.debugger.selection.SelectionProvider) CControl(bibliothek.gui.dock.common.CControl) Prefs(org.jsoar.debugger.util.Prefs) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) BackingStoreException(java.util.prefs.BackingStoreException) InitSoarAction(org.jsoar.debugger.actions.InitSoarAction) JXFrame(org.jdesktop.swingx.JXFrame) KeyAdapter(java.awt.event.KeyAdapter) CDockable(bibliothek.gui.dock.common.intern.CDockable) ArrayList(java.util.ArrayList) XElement(bibliothek.util.xml.XElement) PrefsFactory(org.jsoar.debugger.util.PrefsFactory) ExciseProductionAction(org.jsoar.debugger.actions.ExciseProductionAction) SwingUtilities(javax.swing.SwingUtilities) ResourceBundle(java.util.ResourceBundle) Adaptables(org.jsoar.util.adaptables.Adaptables) ExitAction(org.jsoar.debugger.actions.ExitAction) Agent(org.jsoar.kernel.Agent) SeparatingMenuPiece(bibliothek.gui.dock.support.menu.SeparatingMenuPiece) Container(java.awt.Container) AboutAction(org.jsoar.debugger.actions.AboutAction) MultipleCDockable(bibliothek.gui.dock.common.MultipleCDockable) ThemeMap(bibliothek.gui.dock.common.theme.ThemeMap) SubmenuPiece(bibliothek.gui.dock.facile.menu.SubmenuPiece) SoarProperties(org.jsoar.kernel.SoarProperties) PropertyListenerHandle(org.jsoar.util.properties.PropertyListenerHandle) PropertyListener(org.jsoar.util.properties.PropertyListener) Logger(org.slf4j.Logger) StopCommandAction(org.jsoar.debugger.stopcommand.StopCommandAction) Adaptable(org.jsoar.util.adaptables.Adaptable) IOException(java.io.IOException) CLayoutChoiceMenuPiece(bibliothek.gui.dock.common.menu.CLayoutChoiceMenuPiece) SetBreakpointAction(org.jsoar.debugger.actions.SetBreakpointAction) JOptionPane(javax.swing.JOptionPane) CFocusListener(bibliothek.gui.dock.common.event.CFocusListener) ActionEvent(java.awt.event.ActionEvent) Preferences(java.util.prefs.Preferences) RootMenuPiece(bibliothek.gui.dock.facile.menu.RootMenuPiece) ThreadedAgent(org.jsoar.runtime.ThreadedAgent) Collections(java.util.Collections) InputStream(java.io.InputStream) StopCommandView(org.jsoar.debugger.stopcommand.StopCommandView) RunType(org.jsoar.kernel.RunType) PropertyChangeEvent(org.jsoar.util.properties.PropertyChangeEvent) CControl(bibliothek.gui.dock.common.CControl) PropertyListener(org.jsoar.util.properties.PropertyListener) KeyAdapter(java.awt.event.KeyAdapter) Rectangle(java.awt.Rectangle) WindowAdapter(java.awt.event.WindowAdapter) KeyEvent(java.awt.event.KeyEvent) CFocusListener(bibliothek.gui.dock.common.event.CFocusListener) WindowEvent(java.awt.event.WindowEvent) SelectionProvider(org.jsoar.debugger.selection.SelectionProvider) Preferences(java.util.prefs.Preferences) CDockable(bibliothek.gui.dock.common.intern.CDockable) MultipleCDockable(bibliothek.gui.dock.common.MultipleCDockable)

Example 2 with CFocusListener

use of bibliothek.gui.dock.common.event.CFocusListener in project ramus by Vitaliy-Yakovchuk.

the class GUIPluginFactory method initContent.

@SuppressWarnings("deprecation")
private void initContent() {
    control = new CControl(plugableFrame, false);
    // control.setTheme(control.getThemes().getFactory(2).create());
    control.addControlListener(new CControlListener() {

        @Override
        public void added(CControl control, CDockable dockable) {
        }

        @Override
        public void closed(CControl control, CDockable dockable) {
            Boolean b = recHash.get(Thread.currentThread());
            if (b != null)
                return;
            recHash.put(Thread.currentThread(), true);
            List<TabView> list = new ArrayList<TabView>();
            for (Entry<TabView, TabDockable> e : tabDockables.entrySet()) {
                if (e.getValue().equals(dockable)) {
                    TabView view = e.getKey();
                    list.add(view);
                }
            }
            for (TabView view : list) view.close();
            recHash.remove(Thread.currentThread());
        }

        @Override
        public void opened(CControl control, CDockable dockable) {
        }

        @Override
        public void removed(CControl control, CDockable dockable) {
        }
    });
    control.addFocusListener(new CFocusListener() {

        @Override
        public void focusGained(CDockable dockable) {
            List<View> list = new ArrayList<View>();
            for (Entry<TabView, TabDockable> e : tabDockables.entrySet()) {
                if (e.getValue().equals(dockable)) {
                    TabView view = e.getKey();
                    list.add(view);
                }
            }
            if (dockable instanceof DefaultSingleCDockable) {
                list.add(findUniqueView(((DefaultSingleCDockable) dockable).getUniqueId()));
            }
            for (View view : list) {
                lastActiveView = view;
                view.focusGained();
                plugableFrame.setViewActions(view.getGlobalActions());
                if ((!(view instanceof UniqueView)) && (view instanceof TabView)) {
                    if (currentWorkspace != null)
                        workspaceViews.put(currentWorkspace, view);
                }
            }
        }

        @Override
        public void focusLost(CDockable dockable) {
            List<View> list = new ArrayList<View>();
            for (Entry<TabView, TabDockable> e : tabDockables.entrySet()) {
                if (e.getValue().equals(dockable)) {
                    TabView view = e.getKey();
                    list.add(view);
                }
            }
            if (dockable instanceof DefaultSingleCDockable) {
                list.add(findUniqueView(((DefaultSingleCDockable) dockable).getUniqueId()));
            }
            for (View view : list) view.focusLost();
            plugableFrame.setViewActions(new String[] {});
        }
    });
    // control.setTheme(ThemeMap.KEY_ECLIPSE_THEME);
    contentArea = control.getContentArea();
    plugableFrame.add(contentArea, BorderLayout.CENTER);
    for (UniqueView view : uniqueViews) {
        String id = view.getId();
        final DefaultSingleCDockable dockable = new DefaultSingleCDockable(id, findPluginForViewId(id).getString(id), view.createComponent());
        dockable.setCloseable(true);
        initActions(view.getId(), view, dockable);
        control.addDockable(dockable);
        uniqueDockables.add(dockable);
        framework.addActionListener(id, new ActionListener() {

            @Override
            public void onAction(ActionEvent event) {
                dockable.setVisible(true);
            }
        });
        if (currentWorkspace.equals(view.getDefaultWorkspace()))
            dockable.setVisible(true);
    }
    for (TabbedView view : tabbedViews) {
        String id = view.getId();
        if (getWorkingArea(id) != null)
            continue;
        CWorkingArea area = control.createWorkingArea(id);
        uniqueWorkingAreas.add(area);
        // area.setTitleShown(false);
        // if (currentWorkspace.equals(view.getDefaultWorkspace()))
        area.setVisible(true);
        TabbedFactory factory = new TabbedFactory();
        factories.put(id, factory);
        control.addMultipleDockableFactory(id, factory);
    // dockable.setWorkingArea(area);
    // dockable1.setWorkingArea(area);
    // control.add(dockable1);
    // control.add(dockable);
    // dockable.setLocation(CLocation.base().)
    }
    framework.setMainFrame(plugableFrame);
}
Also used : CControl(bibliothek.gui.dock.common.CControl) TabView(com.ramussoft.gui.common.TabView) ActionEvent(com.ramussoft.gui.common.event.ActionEvent) UniqueView(com.ramussoft.gui.common.UniqueView) TabView(com.ramussoft.gui.common.TabView) TabbedView(com.ramussoft.gui.common.TabbedView) View(com.ramussoft.gui.common.View) CWorkingArea(bibliothek.gui.dock.common.CWorkingArea) TabbedView(com.ramussoft.gui.common.TabbedView) Entry(java.util.Map.Entry) UniqueView(com.ramussoft.gui.common.UniqueView) CFocusListener(bibliothek.gui.dock.common.event.CFocusListener) ActionListener(com.ramussoft.gui.common.event.ActionListener) List(java.util.List) ArrayList(java.util.ArrayList) CControlListener(bibliothek.gui.dock.common.event.CControlListener) DefaultSingleCDockable(bibliothek.gui.dock.common.DefaultSingleCDockable) SingleCDockable(bibliothek.gui.dock.common.SingleCDockable) CDockable(bibliothek.gui.dock.common.intern.CDockable) DefaultSingleCDockable(bibliothek.gui.dock.common.DefaultSingleCDockable) DefaultCDockable(bibliothek.gui.dock.common.intern.DefaultCDockable)

Aggregations

CControl (bibliothek.gui.dock.common.CControl)2 CFocusListener (bibliothek.gui.dock.common.event.CFocusListener)2 CDockable (bibliothek.gui.dock.common.intern.CDockable)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CWorkingArea (bibliothek.gui.dock.common.CWorkingArea)1 DefaultSingleCDockable (bibliothek.gui.dock.common.DefaultSingleCDockable)1 MultipleCDockable (bibliothek.gui.dock.common.MultipleCDockable)1 SingleCDockable (bibliothek.gui.dock.common.SingleCDockable)1 CControlListener (bibliothek.gui.dock.common.event.CControlListener)1 DefaultCDockable (bibliothek.gui.dock.common.intern.DefaultCDockable)1 CLayoutChoiceMenuPiece (bibliothek.gui.dock.common.menu.CLayoutChoiceMenuPiece)1 CThemeMenuPiece (bibliothek.gui.dock.common.menu.CThemeMenuPiece)1 ThemeMap (bibliothek.gui.dock.common.theme.ThemeMap)1 RootMenuPiece (bibliothek.gui.dock.facile.menu.RootMenuPiece)1 SubmenuPiece (bibliothek.gui.dock.facile.menu.SubmenuPiece)1 SeparatingMenuPiece (bibliothek.gui.dock.support.menu.SeparatingMenuPiece)1 XElement (bibliothek.util.xml.XElement)1 XIO (bibliothek.util.xml.XIO)1 TabView (com.ramussoft.gui.common.TabView)1