20 package net.sf.gridarta.maincontrol;
22 import java.awt.BorderLayout;
23 import java.awt.Container;
25 import java.io.IOException;
26 import java.util.List;
27 import java.util.MissingResourceException;
28 import java.util.ResourceBundle;
29 import java.util.prefs.Preferences;
30 import javax.swing.Action;
31 import javax.swing.ImageIcon;
32 import javax.swing.JFrame;
33 import javax.swing.JMenu;
34 import javax.swing.JMenuBar;
212 import net.
sf.japi.swing.action.ActionBuilder;
213 import net.
sf.japi.swing.action.ActionBuilderFactory;
214 import net.
sf.japi.swing.tod.TipOfTheDayManager;
215 import net.
sf.japi.util.ThrowableHandler;
216 import org.apache.log4j.Category;
217 import org.apache.log4j.Logger;
218 import org.jetbrains.annotations.NotNull;
231 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
325 final String spellFile = editorFactory.getSpellFile();
354 final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory =
new GameObjectAttributesDialogFactory<>(
projectModel.
getArchetypeTypeSet(),
mainViewFrame, treasureListTree,
projectModel.
getFaceObjectProviders(),
projectModel.
getAnimationObjects(),
projectModel.
getProjectSettings(), editorFactory.getMapFileFilter(), editorFactory.getScriptFileFilter(),
projectModel.
getFaceObjects(),
projectModel.
getGameObjectSpells(),
projectModel.
getNumberSpells(), editorFactory.getUndefinedSpellIndex(),
projectModel.
getTreasureTree(), noFaceSquareIcon, unknownSquareIcon, textAreaDefaults,
projectModel.
getMapManager());
358 final ScriptArchEditor<G, A, R> scriptArchEditor =
new ScriptArchEditor<>(scriptedEventFactory, editorFactory.getScriptExtension(), editorFactory.getScriptName(), scriptArchUtils, editorFactory.getScriptFileFilter(),
projectModel.
getProjectSettings(),
projectModel.
getMapManager(),
projectModel.
getPathManager(),
scriptEditControl);
359 final ScriptArchDataUtils<G, A, R> scriptArchDataUtils = editorFactory.newScriptArchDataUtils(scriptArchUtils, scriptedEventFactory, scriptedEventEditor);
377 final ArchetypeChooserView<G, A, R> archetypeChooserView =
new ArchetypeChooserView<>(editorFactory.isCreateDirectionPane(),
projectModel.
getArchetypeChooserModel(),
projectModel.
getFaceObjectProviders(), displayGameObjectNamesAction, displayArchetypeNamesAction, displayIconsOnlyAction, displayModeGameObjectNames, displayModeArchetypeNames, displayModeIconsOnly);
381 fileControl =
new DefaultFileControl<>(
projectModel.
getProjectSettings(), volatileSettings, mapImageCache,
projectModel.
getMapManager(),
mapViewsManager,
mainViewFrame,
GuiFileFilters.
MAP_FILE_FILTER, editorFactory.getScriptFileFilter(),
newMapDialogFactory,
scriptExtension,
scriptEditControl,
projectModel.
getPathManager());
383 final PickmapChooserControl<G, A, R> pickmapChooserControl =
new PickmapChooserControl<>(pickmapChooserModel, pickmapSettings,
newMapDialogFactory, mapFolderTree,
projectModel.
getMapManager(),
mainViewFrame,
mapViewsManager,
fileControl, pickmapChooserView);
388 final MapActions<G, A, R> mapActions =
new MapActions<>(
mainViewFrame,
projectModel.
getMapManager(), mapViewManager, exitMatcher,
GuiFileFilters.
MAP_FILE_FILTER, selectedSquareModel, editorFactory.isAllowRandomMapParameters(), mapPropertiesDialogFactory, mapViewSettings,
mapViewsManager, enterMap,
projectModel.
getProjectSettings());
397 final ToolPalette<G, A, R> toolPalette =
new ToolPalette<>(mapViewSettings, selectedSquareModel, objectChooser, pickmapSettings, floorMatcher, wallMatcher, monsterMatcher, insertionModeSet);
415 editorActionManager.
createAction(
"prevWindow",
"Map,Window", mapDesktop);
416 editorActionManager.
createAction(
"nextWindow",
"Map,Window", mapDesktop);
417 editorActionManager.
createAction(
"addNewPickmap",
"Pickmap", pickmapChooserControl);
418 editorActionManager.
createAction(
"openPickmapMap",
"Pickmap", pickmapChooserControl);
419 editorActionManager.
createAction(
"deletePickmap",
"Pickmap", pickmapChooserControl);
420 editorActionManager.
createAction(
"savePickmap",
"Pickmap", pickmapChooserControl);
421 editorActionManager.
createAction(
"revertPickmap",
"Pickmap", pickmapChooserControl);
423 editorActionManager.
createAction(
"mapCreateView",
"Map,Window", mapActions);
424 editorActionManager.
createAction(
"mapProperties",
"Map", mapActions);
426 editorActionManager.
createAction(
"shrinkMapSize",
"Map", mapActions);
427 editorActionManager.
createAction(
"enterExit",
"Map Navigation", mapActions);
428 editorActionManager.
createAction(
"nextExit",
"Map Navigation", mapActions);
429 editorActionManager.
createAction(
"prevExit",
"Map Navigation", mapActions);
430 editorActionManager.
createAction(
"deleteUnknownObjects",
"Map Navigation", mapActions);
431 editorActionManager.
createAction(
"enterNorthMap",
"Map Navigation", mapActions);
432 editorActionManager.
createAction(
"enterEastMap",
"Map Navigation", mapActions);
433 editorActionManager.
createAction(
"enterSouthMap",
"Map Navigation", mapActions);
434 editorActionManager.
createAction(
"enterWestMap",
"Map Navigation", mapActions);
435 editorActionManager.
createAction(
"enterNorthEastMap",
"Map Navigation", mapActions);
436 editorActionManager.
createAction(
"enterSouthEastMap",
"Map Navigation", mapActions);
437 editorActionManager.
createAction(
"enterSouthWestMap",
"Map Navigation", mapActions);
438 editorActionManager.
createAction(
"enterNorthWestMap",
"Map Navigation", mapActions);
439 editorActionManager.
createAction(
"enterUpMap",
"Map Navigation", mapActions);
440 editorActionManager.
createAction(
"enterDownMap",
"Map Navigation", mapActions);
441 editorActionManager.
createAction(
"createTileNorth",
"Map/Create Tile", mapActions);
442 editorActionManager.
createAction(
"createTileEast",
"Map/Create Tile", mapActions);
443 editorActionManager.
createAction(
"createTileSouth",
"Map/Create Tile", mapActions);
444 editorActionManager.
createAction(
"createTileWest",
"Map/Create Tile", mapActions);
445 editorActionManager.
createAction(
"createTileNorthEast",
"Map/Create Tile", mapActions);
446 editorActionManager.
createAction(
"createTileSouthEast",
"Map/Create Tile", mapActions);
447 editorActionManager.
createAction(
"createTileSouthWest",
"Map/Create Tile", mapActions);
448 editorActionManager.
createAction(
"createTileNorthWest",
"Map/Create Tile", mapActions);
449 editorActionManager.
createAction(
"createTileUp",
"Map/Create Tile", mapActions);
450 editorActionManager.
createAction(
"createTileDown",
"Map/Create Tile", mapActions);
456 editorActionManager.
createToggleAction(
"tileStretching",
"Map Navigation", mapActions);
462 editorActionManager.
createAction(
"undo",
"Undo", undoControl);
463 editorActionManager.
createAction(
"redo",
"Undo", undoControl);
466 editorActionManager.
createAction(
"createPickmapFolder",
"Pickmap", mapFolderTreeActions);
467 editorActionManager.
createAction(
"deletePickmapFolder",
"Pickmap", mapFolderTreeActions);
468 editorActionManager.
createAction(
"resetView",
"Map", viewActions);
469 editorActionManager.
createAction(
"saveMap",
"Map", mapFileActions);
470 editorActionManager.
createAction(
"saveMapAs",
"Map", mapFileActions);
471 editorActionManager.
createAction(
"createImage",
"Map,Image", mapFileActions);
472 editorActionManager.
createAction(
"reloadMap",
"Map", mapFileActions);
473 editorActionManager.
createAction(
"closeMap",
"Map", mapFileActions);
474 editorActionManager.
createAction(
"clear",
"Copy Buffer", mainActions);
475 editorActionManager.
createAction(
"cut",
"Copy Buffer", mainActions);
476 editorActionManager.
createAction(
"copy",
"Copy Buffer", mainActions);
477 editorActionManager.
createAction(
"paste",
"Copy Buffer", mainActions);
478 editorActionManager.
createAction(
"pasteTiled",
"Copy Buffer", mainActions);
479 editorActionManager.
createAction(
"shiftNorth",
"Map/Shift", mainActions);
480 editorActionManager.
createAction(
"shiftNorthEast",
"Map/Shift", mainActions);
481 editorActionManager.
createAction(
"shiftEast",
"Map/Shift", mainActions);
482 editorActionManager.
createAction(
"shiftSouthEast",
"Map/Shift", mainActions);
483 editorActionManager.
createAction(
"shiftSouth",
"Map/Shift", mainActions);
484 editorActionManager.
createAction(
"shiftSouthWest",
"Map/Shift", mainActions);
485 editorActionManager.
createAction(
"shiftWest",
"Map/Shift", mainActions);
486 editorActionManager.
createAction(
"shiftNorthWest",
"Map/Shift", mainActions);
487 editorActionManager.
createAction(
"find",
"Map", mainActions);
488 editorActionManager.
createAction(
"findNext",
"Map", mainActions);
489 editorActionManager.
createAction(
"findPrev",
"Map", mainActions);
490 editorActionManager.
createAction(
"replace",
"Map", mainActions);
491 editorActionManager.
createAction(
"fillAuto",
"Map/Fill", mainActions);
492 editorActionManager.
createAction(
"fillAbove",
"Map/Fill", mainActions);
493 editorActionManager.
createAction(
"fillBelow",
"Map/Fill", mainActions);
494 editorActionManager.
createAction(
"randFillAuto",
"Map/Fill", mainActions);
495 editorActionManager.
createAction(
"randFillAbove",
"Map/Fill", mainActions);
496 editorActionManager.
createAction(
"randFillBelow",
"Map/Fill", mainActions);
497 editorActionManager.
createAction(
"floodFill",
"Map/Fill", mainActions);
498 editorActionManager.
createAction(
"massChange",
"Map", mainActions);
499 editorActionManager.
createAction(
"selectAll",
"Map/Selection", mainActions);
500 editorActionManager.
createAction(
"invertSelection",
"Map/Selection", mainActions);
501 editorActionManager.
createAction(
"expandEmptySelection",
"Map/Selection", mainActions);
502 editorActionManager.
createAction(
"tileStretchingSet",
"Map,Tile Stretching", mainActions);
503 editorActionManager.
createAction(
"tileStretchingClear",
"Map,Tile Stretching", mainActions);
504 editorActionManager.
createAction(
"tileStretchingIncrease",
"Map,Tile Stretching", mainActions);
505 editorActionManager.
createAction(
"tileStretchingDecrease",
"Map,Tile Stretching", mainActions);
525 editorActionManager.
createAction(
"moveCursorNorth",
"Map Cursor,Map/Selection", mapCursorActions);
526 editorActionManager.
createAction(
"moveCursorEast",
"Map Cursor,Map/Selection", mapCursorActions);
527 editorActionManager.
createAction(
"moveCursorSouth",
"Map Cursor,Map/Selection", mapCursorActions);
528 editorActionManager.
createAction(
"moveCursorWest",
"Map Cursor,Map/Selection", mapCursorActions);
529 editorActionManager.
createAction(
"moveCursorNorthEast",
"Map Cursor,Map/Selection", mapCursorActions);
530 editorActionManager.
createAction(
"moveCursorSouthEast",
"Map Cursor,Map/Selection", mapCursorActions);
531 editorActionManager.
createAction(
"moveCursorSouthWest",
"Map Cursor,Map/Selection", mapCursorActions);
532 editorActionManager.
createAction(
"moveCursorNorthWest",
"Map Cursor,Map/Selection", mapCursorActions);
553 editorActionManager.
createAction(
"exitCopy",
"Exit Connector", exitConnectorController);
554 editorActionManager.
createAction(
"exitPaste",
"Exit Connector", exitConnectorController);
555 editorActionManager.
createAction(
"exitConnect",
"Exit Connector", exitConnectorController);
557 final JMenuBar menuBar =
ACTION_BUILDER.createMenuBar(
true,
"main");
562 final String compassIconName = editorFactory.getCompassIconName();
563 final ImageIcon compassIcon = compassIconName ==
null ? null : resourceIcons.getResourceIcon(compassIconName);
564 mainView.
addTab(
new Tab(
"selectedSquare",
new SelectedSquareView<>(selectedSquareModel, gameObjectAttributesDialogFactory, objectChooser, mapViewManager, mapViewSettings, compassIcon,
projectModel.
getFaceObjectProviders(), unknownSquareIcon, moveSquareUpAction, moveSquareDownAction, moveSquareTopAction, moveSquareBottomAction, moveSquareEnvAction, moveSquareInvAction),
Location.RIGHT,
false, 1,
true));
568 if (windowMenu ==
null) {
569 LOG.warn(
"'main' menu bar does not define 'window' menu.");
574 final JMenu pickmapFoldersMenu =
MenuUtils.
getMenu(menuBar,
"pickmapFolders");
575 if (pickmapFoldersMenu ==
null) {
576 LOG.warn(
"'main' menu bar does not define 'pickmapFolders' menu.");
582 if (viewMenu ==
null) {
583 LOG.warn(
"'main' menu bar does not define 'view' menu.");
588 if (pluginsMenu ==
null) {
589 LOG.warn(
"'main' menu bar does not define 'plugins' menu.");
598 gameObjectAttributesControl.
addTab(textEditorTab);
611 if (recentMenu ==
null) {
612 LOG.warn(
"'main' menu bar does not define 'recent' menu.");
614 recentMapMenuManager.
setMenu(recentMenu);
618 if (bookmarksMenu ==
null) {
619 LOG.warn(
"'main' menu bar does not define 'bookmarks' menu.");
621 bookmarksMapMenuManager.
setMenu(bookmarksMenu);
625 if (analyzeMenu ==
null) {
626 LOG.warn(
"'main' menu bar does not define 'analyze' menu.");
637 if (!pickmapChooserModel.
isEmpty()) {
650 delayedMapModelListenerManager.
start();
660 return ResourceBundle.getBundle(
"build").getString(
"build.number");
661 }
catch (
final MissingResourceException ignored) {
662 return "unknown version";
671 private void openFile(@NotNull
final File file)
throws IOException {
672 final boolean isScriptFile = file.getName().toLowerCase().endsWith(
scriptExtension);
679 }
else if (!file.exists()) {
694 for (
int i =
files.size() - 1; i >= 0; i--) {
695 final File file =
files.get(i);
698 }
catch (
final IOException ex) {
713 public void run(@NotNull
final List<File> args) {