JPanel createCustomPanel() { Box p = new Box(BoxLayout.PAGE_AXIS); // left operand sink leftSink = new PartSink(PartType.EXPRESSION_PART); leftSink.addCombineListener( new CombineListener() { public void combined() { WorkspaceObject c = leftSink.getContainedPart(); Object o = c.getPart(); Expression exp = (Expression) o; op.setLeftOperand(exp); } public void split() { op.setLeftOperand(null); } }); p.add(leftSink); JLabel eqLab = new JLabel("<html><b>÷</b></html>"); p.add(eqLab); // right operand sink rightSink = new PartSink(PartType.EXPRESSION_PART); rightSink.addCombineListener( new CombineListener() { public void combined() { WorkspaceObject c = rightSink.getContainedPart(); Object o = c.getPart(); Expression exp = (Expression) o; op.setRightOperand(exp); } public void split() { op.setRightOperand(null); } }); p.add(rightSink); JPanel retPanel = new JPanel(); retPanel.setLayout(new BorderLayout()); retPanel.add(p, BorderLayout.CENTER); return retPanel; }
JPanel createCustomPanel() { JPanel p = new JPanel(); p.setLayout(new GridLayout(1, 1)); sink = new PartSink(PartType.EXPRESSION_PART); sink.addCombineListener( new CombineListener() { public void combined() { WorkspaceObject c = sink.getContainedPart(); Object o = c.getPart(); // we know this is an expression because of our sink restriction Expression exp = (Expression) o; randInt.setMax(exp); } public void split() { randInt.setMax(null); } }); sink.setToolTipText("Maximum possible value of the random number"); p.add(sink); return p; }