// This is used both when loading a model and when the user is making // new widgets in the UI. For most widget types, the same type string // is used in both places. - ST 3/17/04 public Widget makeWidget(String type, boolean loading) { type = "DUMMY " + type.toUpperCase(); Widget fromRegistry = org.nlogo.window.WidgetRegistry.apply(type); if (fromRegistry != null) { return fromRegistry; } else if (type.equals("DUMMY SLIDER")) { return new org.nlogo.window.DummySliderWidget(); } else if (type.equals("DUMMY CHOOSER") || // current name type.equals("DUMMY CHOICE")) // old name, used in old models { return new org.nlogo.window.DummyChooserWidget( new org.nlogo.nvm.DefaultCompilerServices(workspace.compiler())); } else if (type.equals("DUMMY BUTTON")) { return new org.nlogo.window.DummyButtonWidget(); } else if (type.equals("DUMMY PLOT")) { // note that plots on the HubNet client must have the name of a plot // on the server, thus, feed the dummy plot widget the names of // the current plots so the user can select one. We override // this method in InterfacePanel since regular plots are handled // differently ev 1/25/07 String[] names = workspace.plotManager().getPlotNames(); if (names.length > 0) { return DummyPlotWidget.apply(names[0], workspace.plotManager()); } else { return DummyPlotWidget.apply("plot 1", workspace.plotManager()); } } else if (type.equals("DUMMY MONITOR")) { return new org.nlogo.window.DummyMonitorWidget(); } else if (type.equals("DUMMY INPUT") || // in the GUI, it's "Input Box" type.equals("DUMMY INPUTBOX")) // in saved models, it's "INPUTBOX" { java.awt.Font font = new java.awt.Font(org.nlogo.awt.Fonts.platformMonospacedFont(), java.awt.Font.PLAIN, 12); return new org.nlogo.window.DummyInputBoxWidget( new org.nlogo.window.CodeEditor( 1, 20, font, false, null, new EditorColorizer(workspace), I18N.guiJ().fn()), new org.nlogo.window.CodeEditor( 5, 20, font, true, null, new EditorColorizer(workspace), I18N.guiJ().fn()), this, new org.nlogo.nvm.DefaultCompilerServices(workspace.compiler())); } else if (type.equals("DUMMY OUTPUT")) // currently in saved models only - ST 3/17/04 { return new org.nlogo.window.OutputWidget(); } else if (type.equals("DUMMY CC-WINDOW")) // definitely in saved models only { // in current NetLogo versions, the command center goes in // a JSplitPane instead of in the InterfacePanel, so we ignore // the entry in the model - ST 7/13/04, 3/14/06 return null; } else if (type.equals("DUMMY GRAPHICS-WINDOW") || type.equals("DUMMY VIEW") || type.equals("VIEW")) { view = new org.nlogo.window.DummyViewWidget(workspace.world); return view; } else { throw new IllegalStateException("unknown widget type: " + type); } }
// this is bordering on comical its so confusing. // this method runs for the hubnet client editor. // im not yet sure if it runs anywhere else. // that seems like bugs waiting to happen. JC - 12/20/10 protected void doPopup(java.awt.event.MouseEvent e) { javax.swing.JPopupMenu menu = new javax.swing.JPopupMenu(); menu.add( new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.button"), "BUTTON", e.getX(), e.getY())); menu.add( new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.slider"), "SLIDER", e.getX(), e.getY())); menu.add( new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.switch"), "SWITCH", e.getX(), e.getY())); menu.add( new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.chooser"), "CHOOSER", e.getX(), e.getY())); menu.add( new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.input"), "INPUT", e.getX(), e.getY())); menu.add( new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.monitor"), "MONITOR", e.getX(), e.getY())); WidgetCreationMenuItem plot = new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.plot"), "PLOT", e.getX(), e.getY()); // if there are no plots in this model, then you can't have a plot in a hubnet client. if (workspace.plotManager().plots().size() == 0) { plot.setEnabled(false); } menu.add(plot); menu.add( new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.note"), "NOTE", e.getX(), e.getY())); menu.show(this, e.getX(), e.getY()); }
public boolean canAddWidget(String widget) { if (widget.equals(I18N.guiJ().get("tabs.run.widgets.view"))) { return !hasView(); } else if (widget.equals(I18N.guiJ().get("tabs.run.widgets.plot"))) { // you can't add a plot to the client interface unless // there are plots in the server interface so enable the // plot button accordingly ev 1/25/07 return workspace.plotManager().getPlotNames().length > 0; } return true; }