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);
}
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);
}
Aggregations