public void actionPerformed(ActionEvent arg0) { JFrame f = gfFrame; ClassBrowser classBrowser = gfFrame.getClassBrowser(); GPackage pkg = null; try { pkg = classBrowser.getProject().getDefaultPackage(); } catch (ProjectNotOpenException e) { e.printStackTrace(); return; } catch (RemoteException e) { e.printStackTrace(); return; } NewClassDialog dialog = new NewClassDialog(f, pkg); dialog.setVisible(true); if (!dialog.okPressed()) { return; } String className = dialog.getClassName(); // GClass gClass = superclass.createSubclass(className); try { File dir = pkg.getProject().getDir(); File newJavaFile = new File(dir, className + ".java"); GreenfootUtil.createSkeleton( className, null, newJavaFile, NormalClassRole.getInstance().getTemplateFileName()); GClass newClass = pkg.newClass(className); ClassView classView = new ClassView(classBrowser, newClass); classBrowser.addClass(classView); } catch (RemoteException re) { re.printStackTrace(); } catch (IOException ioe) { // TODO definitely should report an error condition via dialog ioe.printStackTrace(); } catch (ProjectNotOpenException pnoe) { pnoe.printStackTrace(); } }
/** * If it is a new actor, that has not been added to the world yet, the dragging is handled here. */ public boolean drag(Object o, Point p) { Insets insets = getInsets(); Point p2 = new Point(p.x - insets.left, p.y - insets.top); if (o instanceof Actor && ActorVisitor.getWorld((Actor) o) == null) { if (!getVisibleRect().contains(p)) { return false; } if (o != dragActor) { // It is the first time we are dragging this actor. Create the drag image. dragActor = (Actor) o; dragImage = GreenfootUtil.createDragShadow(ActorVisitor.getDragImage(dragActor).getAwtImage()); } dragLocation = p2; repaint(); return true; } else if (dropTargetListener != null) { return dropTargetListener.drag(o, p2); } else { return false; } }