/** * Construct a new instance * * @param term the term containing the descriptor and possibly the visualization mode * @param parent the figure in which this figure is placed * @throws TermVisualizationException if visualization of the term has failed, e.g., if the query * failed. * @throws TermInstantiationException if a visualization object could not be instantiated */ public VisualTerm(Compound term, TermContext parent) throws TermVisualizationException, TermInstantiationException { context = parent; // Register this object with the content context.registerTermFigure(path, this); try { // The first argument is the descriptor, containing the path and additional information descriptor = (Compound) term.arg(1); if (!descriptor.name().equals("::")) System.err.println("Bad descriptor: " + descriptor.name()); path = ((Compound) descriptor.arg(1)).arg(1); if (term.arity() > 1) { projType = (Compound) term.arg(2); } else { projType = Compound.createCompound("cpi#default"); } // Set up the GUI setLayoutManager(new FlowLayout()); setRequestFocusEnabled(true); // Create the child figures contentFigure = createContentFigure(descriptor); add(contentFigure); unreg = Notifier.instance() .register( new Compound("::", path, Compound.createCompound("cpi#path")), new Runnable() { @Override public void run() { try { updateFigure(); } catch (TermVisualizationException e) { e.printStackTrace(); } catch (TermInstantiationException e) { e.printStackTrace(); } } }); } catch (TermVisualizationException e) { e.printStackTrace(); Label label = new Label("<<<" + e.getMessage() + ">>>"); label.setForegroundColor(new Color(context.getTextEditor().getDisplay(), 255, 0, 0)); add(label); } catch (ClassCastException e) { e.printStackTrace(); Label label = new Label("<<<" + e.getMessage() + ">>>"); label.setForegroundColor(new Color(context.getTextEditor().getDisplay(), 128, 128, 0)); add(label); } pathOwner.put(path, this); }
public void registerTermFigure(Object termID, TermFigure figure) { context.registerTermFigure(termID, figure); }