private int findPos(DefaultListModel lm, String item) { for (int i = 0; i < lm.size(); i++) { String s = (String) lm.get(i); if (item.compareToIgnoreCase(s) < 0) { // item precedes s return i; } } return lm.size(); }
private void applyChanges() { boolean changedFieldSet = false; // Watch if we need to rebuild entry editors // First remove the mappings for fields that have been deleted. // If these were re-added, they will be added below, so it doesn't // cause any harm to remove them here. for (Iterator<String> i = removedFields.iterator(); i.hasNext(); ) { String fieldName = i.next(); metaData.remove(Globals.SELECTOR_META_PREFIX + fieldName); changedFieldSet = true; } // Cycle through all fields that we have created listmodels for: loop: for (Iterator<String> i = wordListModels.keySet().iterator(); i.hasNext(); ) { // For each field name, store the values: String fieldName = i.next(); if ((fieldName == null) || FIELD_FIRST_LINE.equals(fieldName)) continue loop; DefaultListModel lm = wordListModels.get(fieldName); int start = 0; // Avoid storing the <new word> marker if it is there: if (lm.size() > 0) while ((start < lm.size()) && (lm.get(start)).equals(WORD_FIRSTLINE_TEXT)) start++; Vector<String> data = metaData.getData(Globals.SELECTOR_META_PREFIX + fieldName); boolean newField = false; if (data == null) { newField = true; data = new Vector<String>(); changedFieldSet = true; } else data.clear(); for (int wrd = start; wrd < lm.size(); wrd++) { String word = (String) lm.get(wrd); data.add(word); } if (newField) metaData.putData(Globals.SELECTOR_META_PREFIX + fieldName, data); } // System.out.println("TODO: remove metadata for removed selector field."); panel.markNonUndoableBaseChanged(); // Update all selectors in the current BasePanel. if (changedFieldSet) { panel.rebuildAllEntryEditors(); } else { panel.updateAllContentSelectors(); } panel.addContentSelectorValuesToAutoCompleters(); }
/** List results by alphabetical name */ private void listByProgramName() { int nresult = datasets.size(); String res[] = new String[nresult]; for (int i = 0; i < nresult; i++) res[i] = (String) datasets.getElementAt(i); Arrays.sort(res); datasets.removeAllElements(); for (int i = 0; i < nresult; i++) datasets.addElement(res[i]); }
public List<BufferedImage> getExamples() { List<BufferedImage> list = new ArrayList<BufferedImage>(); for (int i = 0; i < model.size(); i++) { Example example = (Example) model.get(i); list.add(example.getBufferedImage()); } return list; }
public SaveDialog(Frame parent) { super(parent, true); this.setLayout(new BorderLayout()); // gather unsaved tab Set<Tab> unsaved = new LinkedHashSet<>(); for (Tab tab : MainPanel.getAllTab()) { if (!tab.isSaved()) { unsaved.add(tab); } } if (unsaved.isEmpty()) { // close directly this.setTitle("Confirm close"); // upper labels JPanel labels = new JPanel(new FlowLayout(FlowLayout.LEFT, 11, 7)); labels.add(iconLabel); labels.add(new MyLabel(" Do you really want to close RefluxEdit?")); // buttons JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7)); buttons.add( new MyButton("YES") { { SaveDialog.this.getRootPane().setDefaultButton(this); this.setFocusPainted(true); } @Override public void actionPerformed(ActionEvent ev) { close = true; SaveDialog.this.setVisible(false); } }); buttons.add( new MyButton("NO") { { this.setFocusPainted(true); } @Override public void actionPerformed(ActionEvent ev) { close = false; SaveDialog.this.setVisible(false); } }); buttons.setBorder(new EmptyBorder(0, 0, 5, 0)); // this.add(labels, BorderLayout.CENTER); this.add(buttons, BorderLayout.PAGE_END); } else { // ask save changes this.setTitle("Unsaved changes"); // upper components: icon and list JPanel upper = new JPanel(new GridBagLayout()); JPanel listPane = new JPanel(new BorderLayout()); final DefaultListModel<Tab> listModel = new DefaultListModel<>(); final JList<Tab> tabList = new JList<>(listModel); tabList.setFont(f13); tabList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); tabList.setCellRenderer( new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) (super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus)); if (value instanceof Tab) { String text = ((Tab) value).getTabLabel().getText(); label.setText(text.substring(1)); // remove "*" } return label; } }); for (Tab tab : unsaved) { listModel.addElement(tab); } tabList.getSelectionModel().setSelectionInterval(0, listModel.size() - 1); JScrollPane scrollPane = new JScrollPane(tabList); scrollPane.setPreferredSize(new Dimension(350, 170)); listPane.add(new MyLabel("The following tabs are unsaved:"), BorderLayout.PAGE_START); listPane.add(scrollPane, BorderLayout.CENTER); // setup upper GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 0; c.weighty = 1; c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.FIRST_LINE_START; upper.add(iconLabel, c); // c.gridx = 1; c.weightx = 1; c.fill = GridBagConstraints.BOTH; upper.add(listPane, c); // lower components: buttons JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7)); buttons.add( new MyButton("Save") { { this.setFocusPainted(true); this.setToolTipText("Save selected tab(s)"); SaveDialog.this.getRootPane().setDefaultButton(this); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { for (Tab tab : tabList.getSelectedValuesList()) { if (tab.getFile() != null) { try { tab.save(); MainPanel.close(tab); listModel.removeElement(tab); } catch (Exception ex) { exception(ex); break; } } else { File file = FileChooser.showPreferredFileDialog( RefluxEdit.getInstance(), FileChooser.SAVE, new String[0]); if (file != null) { try { tab.save(file, false); MainPanel.close(tab); listModel.removeElement(tab); } catch (Exception ex) { exception(ex); break; } } } } if (listModel.size() == 0) { RefluxEdit.getInstance().close(); } } }); buttons.add( new MyButton("Discard") { { this.setFocusPainted(true); this.setToolTipText("Discard selected tab(s)"); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { for (Tab tab : tabList.getSelectedValuesList()) { MainPanel.close(tab); listModel.removeElement(tab); } if (listModel.size() == 0) { RefluxEdit.getInstance().close(); } } }); buttons.add( new MyButton("Close") { { this.setFocusPainted(true); this.setToolTipText("Close RefluxEdit"); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { SaveDialog.this.close = true; SaveDialog.this.setVisible(false); } }); buttons.add( new MyButton("Cancel") { { this.setFocusPainted(true); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { SaveDialog.this.close = false; SaveDialog.this.setVisible(false); } }); this.add(upper, BorderLayout.CENTER); this.add(buttons, BorderLayout.PAGE_END); } }
private void newWordAction() { if ((wordListModel.size() == 0) || !wordListModel.get(0).equals(WORD_FIRSTLINE_TEXT)) wordListModel.add(0, WORD_FIRSTLINE_TEXT); wordList.setSelectedIndex(0); wPane.getVerticalScrollBar().setValue(0); }