{ for (myjava.gui.syntax.Painter painter : myjava.gui.syntax.Painter.getPainters()) { painterComboBox.addItem(painter); EntryListPanel panel = new EntryListPanel(painter); listPanelSet.add(panel); centerPanel.add(panel, painter.getName()); } componentSet.addAll(Arrays.asList(matchBracket, painterComboBox, centerPanel)); }
public SyntaxTab() { super(new BorderLayout(), "Syntax highlighting"); /* * upper checkboxes */ JPanel upper = new JPanel(new GridLayout(2, 1, 0, 0)); upper.setOpaque(false); upper.add(MyPanel.wrap(highlightSyntax)); upper.add(MyPanel.wrap(matchBracket)); highlightSyntax.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { SyntaxTab.this.updateComponentStatus(); } }); this.add(upper, BorderLayout.PAGE_START); /* * upper panel (painters) */ painterComboBox.setSelectedItem(myjava.gui.syntax.Painter.getCurrentInstance()); painterComboBox.setFont(f13); if (isMetal) painterComboBox.setBackground(Color.WHITE); painterComboBox.addItemListener(this.painterChangeListener); JButton addPainter = new MyButton("+") { { if (isMetal) { this.setPreferredSize(new Dimension(28, 28)); } } @Override public void actionPerformed(ActionEvent ev) { String name; do { name = JOptionPane.showInputDialog( SyntaxTab.this, "Enter a name:", "Name", JOptionPane.QUESTION_MESSAGE); } while (!myjava.gui.syntax.Painter.isValidPrompt(name, SyntaxTab.this)); if ((name != null) && (!name.isEmpty())) { // name is valid, neither cancelled nor pressed enter directly myjava.gui.syntax.Painter newPainter = ((myjava.gui.syntax.Painter) (painterComboBox.getSelectedItem())) .newInstance(name); addPainter(newPainter); System.out.println("now set, should call listener"); painterComboBox.setSelectedItem(newPainter); // auto-call ItemListener(s) } } }; JButton removePainter = new MyButton("-") { { if (isMetal) { this.setPreferredSize(new Dimension(28, 28)); } } @Override public void actionPerformed(ActionEvent ev) { myjava.gui.syntax.Painter painter = (myjava.gui.syntax.Painter) (painterComboBox.getSelectedItem()); if (painter.equals(myjava.gui.syntax.Painter.getDefaultInstance())) { JOptionPane.showMessageDialog( SyntaxTab.this, "The default painter cannot be removed.", "Error", JOptionPane.ERROR_MESSAGE); } else { int option = JOptionPane.showConfirmDialog( SyntaxTab.this, "Remove painter \"" + painter.getName() + "\"?", "Confirm", JOptionPane.YES_NO_OPTION); if (option == JOptionPane.YES_OPTION) { // remove "painter" removedPainters.add(painter); painterComboBox.removeItemListener(painterChangeListener); painterComboBox.setSelectedItem(myjava.gui.syntax.Painter.getDefaultInstance()); painterComboBox.removeItem(painter); for (Iterator<EntryListPanel> it = listPanelSet.iterator(); it.hasNext(); ) { EntryListPanel panel = it.next(); if (panel.getPainter().getName().equals(painter.getName())) { System.out.println("removing, then break"); it.remove(); centerPanel.remove(panel); break; } } painterComboBox.addItemListener(painterChangeListener); cardLayout.show( centerPanel, myjava.gui.syntax.Painter.getDefaultInstance().getName()); } } } }; // lower part JPanel center = new JPanel(new BorderLayout()); JLabel selectLabel = new MyLabel("Selected painter:"); center.add( MyPanel.wrap(MyPanel.CENTER, selectLabel, painterComboBox, addPainter, removePainter), BorderLayout.PAGE_START); componentSet.addAll(Arrays.asList(selectLabel, addPainter, removePainter)); center.add(centerPanel, BorderLayout.CENTER); this.add(center, BorderLayout.CENTER); cardLayout.show(centerPanel, myjava.gui.syntax.Painter.getCurrentInstance().getName()); }
/** * Linear forward search algorithm * * @param p * @param algorithm * @param targetVars * @param _computeAll * @return */ private boolean linearForwardSearch( PlanningContext context, EvaluationAlgorithm algorithm, boolean _computeAll) { /* * while iterating through hashset, items cant be removed from/added to * that set. Theyre collected into these sets and added/removedall * together after iteration is finished */ Set<Var> newVars = new LinkedHashSet<Var>(); Set<Var> relOutputs = new LinkedHashSet<Var>(); Set<Var> removableVars = new LinkedHashSet<Var>(); boolean changed = true; if (isLinearLoggingOn()) logger.debug( "------Starting linear planning with (sub)goals: " + context.getRemainingGoals() + "--------"); if (isLinearLoggingOn()) logger.debug("Algorithm " + algorithm); int counter = 1; while ((!_computeAll && changed && !context.getRemainingGoals().isEmpty()) || (changed && _computeAll)) { if (isLinearLoggingOn()) logger.debug("----Iteration " + counter + " ----"); counter++; changed = false; // iterate through all knownvars if (isLinearLoggingOn()) logger.debug("Known:" + context.getKnownVars()); for (Var var : context.getKnownVars()) { if (isLinearLoggingOn()) logger.debug("Current Known: " + var); // Check the relations of all components for (Rel rel : var.getRels()) { if (isLinearLoggingOn()) logger.debug("And its rel: " + rel); if (context.isAvailableRel(rel)) { context.removeUnknownInput(rel, var); if (isLinearLoggingOn()) logger.debug("problem contains it " + rel); removableVars.add(var); if (context.isRelReadyToUse(rel) && rel.getType() != RelType.TYPE_METHOD_WITH_SUBTASK) { if (isLinearLoggingOn()) logger.debug("rel is ready to be used " + rel); boolean relIsNeeded = false; if (isLinearLoggingOn()) logger.debug("its outputs " + rel.getOutputs()); for (Var relVar : rel.getOutputs()) { if (!context.getFoundVars().contains(relVar)) { relIsNeeded = true; } } if (rel.getOutputs().isEmpty()) { relIsNeeded = true; } if (isLinearLoggingOn()) logger.debug("relIsNeeded " + relIsNeeded); if (relIsNeeded) { if (isLinearLoggingOn()) logger.debug("needed rel: " + rel); if (!rel.getOutputs().isEmpty()) { relOutputs.clear(); unfoldVarsToSet(rel.getOutputs(), relOutputs); newVars.addAll(relOutputs); context.getFoundVars().addAll(relOutputs); } algorithm.addRel(rel); if (isLinearLoggingOn()) logger.debug("algorithm " + algorithm); } context.removeRel(rel); changed = true; } } } } // remove targets if they have already been found for (Iterator<Var> targetIter = context.getRemainingGoals().iterator(); targetIter.hasNext(); ) { Var targetVar = targetIter.next(); if (context.getFoundVars().contains(targetVar)) { targetIter.remove(); } } if (isLinearLoggingOn()) logger.debug("foundvars " + context.getFoundVars()); context.getKnownVars().addAll(newVars); context.getKnownVars().removeAll(removableVars); newVars.clear(); } if (isLinearLoggingOn()) logger.debug("algorithm " + algorithm); if (!_computeAll) { Optimizer.optimize(context, algorithm); if (isLinearLoggingOn()) logger.debug("optimized algorithm " + algorithm); } if (isLinearLoggingOn()) logger.debug("\n---!!!Finished linear planning!!!---\n"); return context.getRemainingGoals().isEmpty() || context.getFoundVars().containsAll(context.getAllGoals()); }