public boolean existLibrary(StorableResource parent, String libraryName) { for (int i = 0, j = parent.getChildCount(); i < j; i++) { StorableResource node = (StorableResource) parent.getChildAt(i); if (node.getName().equals(libraryName)) { return true; } } return false; }
private boolean hasLibrary(TreePath[] paths) { for (TreePath path : paths) { StorableResource r = (StorableResource) path.getLastPathComponent(); if (r.isLibrary()) { return true; } } return false; }
private boolean importFile(File[] files, Tile tile) { for (File f : files) { if (f.isDirectory()) { StorableResource library = new LibraryResource(f.getName()); manager.addResourceChild(library); importFile(f.listFiles(), tile); manager.setCurrentNode(library.getParentResource()); } else { if (!imageFilter.accept(f)) { continue; } Tile newTile = TileFactory.createDefaultTile(tile); newTile.setImage(ImageUtils.readImage(f)); StorableResource resource = new DefaultResource(newTile); resource.setName(getNameFromFile(f)); manager.createResourceID(resource); manager.addResourceChild(resource); } } return true; }
private void cellValueChanged(DefaultCellEditor e) { TreePath path = managerTree.getSelectionPath(); StorableResource r = (StorableResource) path.getLastPathComponent(); r.setName(e.getCellEditorValue().toString()); }
private void handlePopupMenu(MouseEvent e) { Point p = e.getPoint(); JPopupMenu menu = new JPopupMenu(); final StorableResource child = manager.getCurrentNode(); final Application app = view.getApplication(); final TreePath[] paths = managerTree.getSelectionPaths(); final StorableResource[] selectedResources = new StorableResource[paths.length]; for (int i = 0; i < paths.length; i++) { selectedResources[i] = (StorableResource) paths[i].getLastPathComponent(); } Action editAction = new AbsAction("edit") { @Override public void actionPerformed(ActionEvent e) { Storable sp = child.getSource(); if (sp instanceof DefaultTile) { Tile t = TileFactory.createCandidateTile((Tile) sp); BufferedImage image = t.getImage(); Map map = MapFactory.getDefaultMap(); map.setName(child.getName()); map.setTileStep(t.getTileWidth(), t.getTileHeight()); map.setLogicalSize(1, 1); map.setSize(image.getWidth(), image.getHeight()); map.addLayer(new DefaultLayer(), 0); map.addTile(new int[][] {{0, 0}}, new Tile[] {t}); EditorView editorView = EditorViewFactory.getTileEditorView(map, t, manager); view.getEditor().add(editorView); firePropertyChange(SELECTION_CHANGED_PROPERTY, null, map); return; } if (sp instanceof CustomTile) { final Application app = view.getApplication(); app.setEnable(false); final AppDialog dialog = new NewCustomTileDialog(app, manager, (CustomTile) sp); dialog.showDialog( new AppDialogListener() { @Override public void optionSelection(DialogEvent evt) { dialog.dispose(); // other option app.setFoucs(); app.setEnable(true); } }); } } }; editAction.setEnabled(!child.isLibrary()); menu.add(editAction); Action edgeAction = new AbsAction("edge") { @Override public void actionPerformed(ActionEvent e) { final AppDialog dialog = new MapTypeDialog(app); app.setEnable(false); dialog.showDialog( new AppDialogListener() { @Override public void optionSelection(DialogEvent evt) { if (evt.getName().equals(AppDialog.COMFIRM_OPTION)) { Storable sp = child.getSource(); if (sp instanceof DefaultTile) { Tile t = (Tile) sp; Map map = (Map) evt.getData(); map.setName(sp.getName()); map.setLogicalSize( 3, 3); // TODO change the size in case the dimension of the tile not (1,1) map.addLayer(new DefaultLayer(), 0); map.addTile(new int[][] {{1, 1}}, new Tile[] {t}); EdgeEditorView editorView = EditorViewFactory.getEdgeEditorView( map, child.getParentResource(), manager); Editor editor = view.getEditor(); editor.add(editorView); firePropertyChange(SELECTION_CHANGED_PROPERTY, null, map); } } managerTree.validate(); managerTree.repaint(); dialog.dispose(); app.setEnable(true); } }); app.setEnable(true); } }; edgeAction.setEnabled(paths.length == 1 && !hasLibrary(paths)); menu.add(edgeAction); Action deleteAction = new AbsAction("delete") { @Override public void actionPerformed(ActionEvent e) { if (AppOptionPanel.showConfirmDeleteDialog( LibraryPanel.this, paths.length == 1 ? paths[0].getLastPathComponent().toString() : paths.length + "")) { for (TreePath path : paths) { manager.setCurrentNode((StorableResource) path.getLastPathComponent()); manager.removeResource((StorableResource) path.getLastPathComponent()); } } } }; deleteAction.setEnabled(child.getParentResource() != null); menu.add(deleteAction); Action propertyAction = new PropertyAction(app, selectedResources); propertyAction.setEnabled(child != null); menu.add(propertyAction); menu.show(managerTree, p.x, p.y); }