// 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); } }
private boolean checkWithUser() { return (!workspace.jobManager.anyPrimaryJobs()) || org.nlogo.swing.OptionDialog.show( this, I18N.guiJ().get("common.messages.warning"), "Changing the size will halt and clear the world.", new String[] {"Change Size", I18N.guiJ().get("common.buttons.cancel")}) == 0; }
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; }
private void checkWithUserBeforeOpening2DModelin3D() throws UserCancelException { String[] options = { I18N.guiJ().get("common.buttons.continue"), I18N.guiJ().get("common.buttons.cancel") }; String message = "You are attempting to open a 2D model in " + org.nlogo.api.Version.version() + ". " + "You might need to make changes before it will work in 3D."; if (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options) != 0) { throw new UserCancelException(); } }
private boolean userWantsToSaveFirst() throws UserCancelException { String[] options = { I18N.guiJ().get("common.buttons.save"), "Discard", I18N.guiJ().get("common.buttons.cancel") }; String message = "Do you want to save the changes you made to this model?"; switch (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options)) { case 0: return true; case 1: return false; default: throw new UserCancelException(); } }
// 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()); }
// 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); } }
@Override void action() throws UserCancelException, java.io.IOException { final String importPath = org.nlogo.swing.FileDialog.show( FileMenu.this, "Import HubNet Client Interface", java.awt.FileDialog.LOAD, null); final java.io.IOException[] exception = new java.io.IOException[] {null}; final int choice = org.nlogo.swing.OptionDialog.show( app.workspace().getFrame(), "Import HubNet Client", "Which section would you like to import from?", new String[] { "Interface Tab", "HubNet client", I18N.guiJ().get("common.buttons.cancel") }); if (choice != 2) { org.nlogo.swing.ModalProgressTask.apply( org.nlogo.awt.Hierarchy.getFrame(FileMenu.this), "Importing Drawing...", new Runnable() { public void run() { try { app.workspace().getHubNetManager().importClientInterface(importPath, choice == 1); } catch (java.io.IOException ex) { exception[0] = ex; } } }); if (exception[0] != null) { throw exception[0]; } } }
private void checkWithUserBeforeSavingModelFromOldVersion() throws UserCancelException { if (!org.nlogo.api.Version.compatibleVersion(savedVersion)) { String[] options = { I18N.guiJ().get("common.buttons.save"), I18N.guiJ().get("common.buttons.cancel") }; String message = "This model was made with " + savedVersion + ". " + "If you save it in " + org.nlogo.api.Version.version() + " it may not work in the old version anymore."; if (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options) != 0) { throw new UserCancelException(); } savedVersion = org.nlogo.api.Version.version(); } }
private void checkWithUserBeforeOpening3DModelin2D(String version) throws UserCancelException { String[] options = { I18N.guiJ().get("common.buttons.continue"), I18N.guiJ().get("common.buttons.cancel") }; String message = "You are attempting to open a model that was created" + " in a 3D version of NetLogo. (This is " + org.nlogo.api.Version.version() + "; " + "the model was created in " + version + ".) " + "NetLogo can try to open the model, but it may " + "or may not work."; if (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options) != 0) { throw new UserCancelException(); } }
public FileMenu(App app, ModelSaver modelSaver, AppletSaver appletSaver) { super(I18N.guiJ().get("menu.file")); this.app = app; this.modelSaver = modelSaver; this.appletSaver = appletSaver; addMenuItem('N', new NewAction()); addMenuItem('O', new OpenAction()); addMenuItem('M', new ModelsLibraryAction()); addSeparator(); addMenuItem('S', new SaveAction()); addMenuItem(new SaveAsAction()); addMenuItem(new SaveAppletAction()); addSeparator(); addMenuItem(I18N.guiJ().get("menu.file.print"), 'P', app.tabs().printAction()); addSeparator(); org.nlogo.swing.Menu exportMenu = new org.nlogo.swing.Menu(I18N.guiJ().get("menu.file.export")); exportMenu.addMenuItem(new ExportWorldAction()); exportMenu.addMenuItem(new ExportPlotAction()); exportMenu.addMenuItem(new ExportAllPlotsAction()); exportMenu.addMenuItem(new ExportGraphicsAction()); exportMenu.addMenuItem(new ExportInterfaceAction()); exportMenu.addMenuItem(new ExportOutputAction()); add(exportMenu); addSeparator(); org.nlogo.swing.Menu importMenu = new org.nlogo.swing.Menu(I18N.guiJ().get("menu.file.import")); importMenu.addMenuItem(new ImportWorldAction()); importMenu.addMenuItem(new ImportPatchColorsAction()); importMenu.addMenuItem(new ImportPatchColorsRGBAction()); if (!org.nlogo.api.Version.is3D()) { importMenu.addMenuItem(new ImportDrawingAction()); } importMenu.addMenuItem(new ImportClientAction()); add(importMenu); if (!System.getProperty("os.name").startsWith("Mac")) { addSeparator(); addMenuItem('Q', new QuitAction()); } // initialize here, unless there's a big problem early on in the // initial load process it'll get initialize properly below // maybe this fixes Nigel Gilbert's bug. maybe. ev 1/30/07 savedVersion = org.nlogo.api.Version.version(); }
@Override public java.awt.Dimension getMinimumSize() { java.awt.Dimension d = super.getMinimumSize(); java.awt.FontMetrics fontMetrics = getFontMetrics(getFont()); if (!labelsBelow) { d.width = StrictMath.max( d.width, fontMetrics.stringWidth(I18N.guiJ().get("tabs.run.speedslider.normalspeed"))); } else { d.width = StrictMath.max( d.width, fontMetrics.stringWidth( " " + I18N.guiJ().get("tabs.run.speedslider.faster")) + 10); } return d; }
public void addOriginConfigurations() { originConfigurations.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.center"), new boolean[] {false, true, false, true}, new boolean[] {false, false, false, false})); originConfigurations.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.corner"), new boolean[] {true, true, true, true}, new boolean[] {false, false, false, false})); originConfigurations.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.edge"), new boolean[] {true, true, true, true}, new boolean[] {false, false, false, false})); originConfigurations.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.custom"), new boolean[] {true, true, true, true}, new boolean[] {false, false, false, false})); }
public void addCornerChoices() { cornerChoices.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.corner.bottomLeft"), new boolean[] {false, true, false, true}, new boolean[] {true, false, true, false})); cornerChoices.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.corner.topLeft"), new boolean[] {false, true, true, false}, new boolean[] {true, false, false, true})); cornerChoices.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.corner.topRight"), new boolean[] {true, false, true, false}, new boolean[] {false, true, false, true})); cornerChoices.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.corner.bottomRight"), new boolean[] {true, false, false, true}, new boolean[] {false, true, true, false})); }
public void actionPerformed(java.awt.event.ActionEvent e) { try { action(); } catch (UserCancelException ex) { org.nlogo.util.Exceptions.ignore(ex); } catch (java.io.IOException ex) { javax.swing.JOptionPane.showMessageDialog( FileMenu.this, ex.getMessage(), I18N.guiJ().get("common.messages.error"), javax.swing.JOptionPane.ERROR_MESSAGE); } }
public void addEdgeChoices() { edgeChoices.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.edge.bottom"), new boolean[] {true, true, false, true}, new boolean[] {false, false, true, false})); edgeChoices.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.edge.top"), new boolean[] {true, true, true, false}, new boolean[] {false, false, false, true})); edgeChoices.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.edge.right"), new boolean[] {true, false, true, true}, new boolean[] {false, true, false, false})); edgeChoices.add( new OriginConfiguration( I18N.guiJ().get("edit.viewSettings.origin.location.edge.left"), new boolean[] {false, true, true, true}, new boolean[] {true, false, false, false})); }
// this is called whenever a workspace is about to be destroyed public void offerSave() throws UserCancelException { // check if we have an open movie if (app.workspace().movieEncoder != null) { String[] options = { I18N.guiJ().get("common.buttons.ok"), I18N.guiJ().get("common.buttons.cancel") }; String message = "There is a movie in progress. " + "Are you sure you want to exit this model? " + "You will lose the contents of your movie."; if (org.nlogo.swing.OptionDialog.show(this, "NetLogo", message, options) == 1) { throw new UserCancelException(); } app.workspace().movieEncoder.cancel(); app.workspace().movieEncoder = null; } if (app.dirtyMonitor().dirty() && userWantsToSaveFirst()) { save(); } }
@Override protected void doPopup(final java.awt.event.MouseEvent e) { JPopupMenu menu = new JPopupMenu(); // add all the widgets 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())); menu.add( new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.plot"), "PLOT", e.getX(), e.getY())); WidgetCreationMenuItem outputItem = new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.output"), "OUTPUT", e.getX(), e.getY()); if (getOutputWidget() != null) { outputItem.setEnabled(false); } menu.add(outputItem); menu.add( new WidgetCreationMenuItem( I18N.guiJ().get("tabs.run.widgets.note"), "NOTE", e.getX(), e.getY())); // add extra stuff menu.add(new javax.swing.JPopupMenu.Separator()); menu.add(exportItem()); menu.show(this, e.getX(), e.getY()); }
void enableLabels(int value) { if (value == 0) { if (labelsBelow) { normal.setText(" " + I18N.guiJ().get("tabs.run.speedslider.normalspeed")); } else { normal.setText(I18N.guiJ().get("tabs.run.speedslider.normalspeed")); } } else if (value < 0) { if (labelsBelow) { normal.setText( I18N.guiJ().get("tabs.run.speedslider.slower") + " "); } else { normal.setText(I18N.guiJ().get("tabs.run.speedslider.slower")); } } else { if (labelsBelow) { normal.setText( " " + I18N.guiJ().get("tabs.run.speedslider.faster")); } else { normal.setText(I18N.guiJ().get("tabs.run.speedslider.faster")); } } }
ImportPatchColorsRGBAction() { super(I18N.guiJ().get("menu.file.import.patchColorsRGB")); }
private void notifyUserNotValidFile() throws UserCancelException { String[] options = {I18N.guiJ().get("common.buttons.ok")}; org.nlogo.swing.OptionDialog.show( this, "NetLogo", "The file is not a valid NetLogo model file.", options); throw new UserCancelException(); }
ExportGraphicsAction() { super(I18N.guiJ().get("menu.file.export.view")); }
ExportInterfaceAction() { super(I18N.guiJ().get("menu.file.export.interface")); }
ExportOutputAction() { super(I18N.guiJ().get("menu.file.export.output")); }
ExportPlotAction() { super(I18N.guiJ().get("menu.file.export.plot")); }
QuitAction() { super(I18N.guiJ().get("menu.file.quit")); }
ExportAllPlotsAction() { super(I18N.guiJ().get("menu.file.export.allPlots")); }
ImportClientAction() { super(I18N.guiJ().get("menu.file.import.hubNetClientInterface")); }
ImportDrawingAction() { super(I18N.guiJ().get("menu.file.import.drawing")); }
ImportWorldAction() { super(I18N.guiJ().get("menu.file.import.world")); }