Esempio n. 1
0
 // 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);
   }
 }
Esempio n. 2
0
 // 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
 @Override
 public Widget makeWidget(String type, boolean loading) {
   type = type.toUpperCase();
   Widget fromRegistry = org.nlogo.window.WidgetRegistry.apply(type);
   if (fromRegistry != null) {
     return fromRegistry;
   } else if (type.equalsIgnoreCase("SLIDER")) {
     return new org.nlogo.window.SliderWidget(workspace.world.auxRNG) {
       @Override
       public int sourceOffset() {
         return org.nlogo.workspace.Evaluator.sourceOffset(org.nlogo.agent.Observer.class, false);
       }
     };
   } else if (type.equals("CHOOSER")
       || // current name
       type.equals("CHOICE")) // old name, used in old models
   {
     return new org.nlogo.window.ChooserWidget(workspace);
   } else if (type.equals("BUTTON")) {
     return new org.nlogo.window.ButtonWidget(workspace.world.mainRNG);
   } else if (type.equals("PLOT")) {
     return org.nlogo.window.PlotWidget.apply(workspace.plotManager());
   } else if (type.equals("MONITOR")) {
     return new org.nlogo.window.MonitorWidget(workspace.world.auxRNG);
   } else if (type.equals("INPUT")
       || // in the GUI, it's "Input Box"
       type.equals("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.InputBoxWidget(
         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()),
         workspace,
         this);
   } else if (type.equals("OUTPUT")) // currently in saved models only - ST 3/17/04
   {
     return new org.nlogo.window.OutputWidget();
   } else if (type.equals("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 {
     throw new IllegalStateException("unknown widget type: " + type);
   }
 }