- private void addTagBar(List<SearchableTag> tags,
- final SearchableTag selected) {
- tags.add(0, null);
-
- final int comboIndex = combos.size();
-
- final JComboBox combo = new JComboBox(
- tags.toArray(new SearchableTag[] {}));
- combo.setSelectedItem(selected);
-
- final ListCellRenderer basic = combo.getRenderer();
-
- combo.setRenderer(new ListCellRenderer() {
- @Override
- public Component getListCellRendererComponent(JList list,
- Object value, int index, boolean isSelected,
- boolean cellHasFocus) {
-
- Object displayValue = value;
- if (value instanceof SearchableTag) {
- displayValue = ((SearchableTag) value).getName();
- } else {
- displayValue = "Select a tag...";
- cellHasFocus = false;
- isSelected = false;
- }
-
- Component rep = basic.getListCellRendererComponent(list,
- displayValue, index, isSelected, cellHasFocus);
-
- if (value == null) {
- rep.setForeground(Color.GRAY);
- }
-
- return rep;
- }
- });
-
- combo.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- final SearchableTag tag = (SearchableTag) combo
- .getSelectedItem();
- if (tag != null) {
- while (comboIndex + 1 < combos.size()) {
- JComboBox combo = combos.remove(comboIndex + 1);
- tagBars.remove(combo);
- }
-
- addTagBar(tag, new Runnable() {
- @Override
- public void run() {
- // TODO: slow ui
- SearchableTag tag = ((SearchableTag) combo
- .getSelectedItem());
- if (tag != null && tag.isLeaf()) {
- BasicSearchable searchable = BasicSearchable
- .getSearchable(supportType);
- List<MetaData> metas = new ArrayList<MetaData>();
- try {
- metas = searchable.search(tag, 1);
- search(metas, 1,
- searchable.searchPages(tag), 0);
- } catch (IOException e) {
- error(e);
- }
- }
-
- setWaitingScreen(false);
- }
- });
- }
- }
- });
-
- combos.add(combo);
- tagBars.add(combo);
- }
-
- // async, add children of tag, NULL = base tags
- private void addTagBar(final SearchableTag tag, final Runnable inUi) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- BasicSearchable searchable = BasicSearchable
- .getSearchable(supportType);
-
- List<SearchableTag> children = new ArrayList<SearchableTag>();
- if (tag == null) {
- try {
- List<SearchableTag> baseTags = searchable.getTags();
- children = baseTags;
- } catch (IOException e) {
- error(e);
- }
- } else {
- try {
- searchable.fillTag(tag);
- } catch (IOException e) {
- error(e);
- }
-
- if (!tag.isLeaf()) {
- children = tag.getChildren();
- } else {
- children = null;
- }
- }
-
- final List<SearchableTag> fchildren = children;
- inUi(new Runnable() {
- @Override
- public void run() {
- if (fchildren != null) {
- addTagBar(fchildren, tag);
- }
-
- if (inUi != null) {
- inUi.run();
- }
- }
- });
- }
- }).start();
- }
-