{ 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)); }
static SortedSet<TypeColorEntry> fromPainter(myjava.gui.syntax.Painter painter) { Token.Type[] types = Token.Type.values(); SortedSet<TypeColorEntry> entries = new TreeSet<>(); for (Token.Type type : types) { entries.add(new TypeColorEntry(type, painter.fromType(type))); } return entries; }
private void addPainter(myjava.gui.syntax.Painter painter) { EntryListPanel newPanel = new EntryListPanel(painter); listPanelSet.add(newPanel); centerPanel.add(newPanel, painter.getName()); painterComboBox.removeItemListener(painterChangeListener); painterComboBox.removeAllItems(); for (EntryListPanel p : listPanelSet) { painterComboBox.addItem(p.getPainter()); } removedPainters.remove(painter); painterComboBox.addItemListener(painterChangeListener); }
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()); }
@Override public void onExit() { // save all painters for (EntryListPanel panel : listPanelSet) { myjava.gui.syntax.Painter painter = panel.getPainter(); if (!painter.equals(myjava.gui.syntax.Painter.getDefaultInstance())) { myjava.gui.syntax.Painter.add(painter); setConfig("painter.userDefined." + painter.getName(), painter.toWritableString()); } if (painter.equals(painterComboBox.getSelectedItem())) { // selected painter setConfig("syntax.selectedPainter", painter.getName()); myjava.gui.syntax.Painter.setCurrentInstance(painter); } } // remove "removed painters" for (myjava.gui.syntax.Painter removed : removedPainters) { removeConfig0("painter.userDefined." + removed.getName()); myjava.gui.syntax.Painter.remove(removed); } // highlight? boolean _highlightSyntax = highlightSyntax.isSelected(); boolean _matchBracket = matchBracket.isSelected(); MyUmbrellaLayerUI.setHighlightingStatus(_highlightSyntax, _matchBracket); setConfig("syntax.highlight", _highlightSyntax + ""); setConfig("syntax.matchBrackets", _matchBracket + ""); }