Ejemplo n.º 1
0
public class XmlTreeModel implements TreeModel {
  static Logger T = Logger.getLogger(XmlTreeModel.class);
  private Element _root;

  public XmlTreeModel(Document doc) {
    _root = doc.getRootElement();
  }

  @Override
  public Object getRoot() {
    return _root;
  }

  @Override
  public Object getChild(Object parent, int index) {
    Element el = (Element) parent;
    List children = el.getChildren();
    return children.get(index);
  }

  @Override
  public int getChildCount(Object parent) {
    Element el = (Element) parent;
    List children = el.getChildren();
    return children.size();
  }

  @Override
  public boolean isLeaf(Object parent) {
    Element el = (Element) parent;
    List children = el.getChildren();
    return children.size() == 0;
  }

  @Override
  public int getIndexOfChild(Object parent, Object child) {
    Element el = (Element) parent;
    List children = el.getChildren();
    return children.indexOf(child);
  }

  @Override
  public void valueForPathChanged(TreePath path, Object newValue) {
    // only needed if you edit/change tree nodes in Jtree itself which we
    // don't do/support
  }

  EventListenerList _listener = new EventListenerList();

  @Override
  public void addTreeModelListener(TreeModelListener l) {
    _listener.add(TreeModelListener.class, l);
  }

  @Override
  public void removeTreeModelListener(TreeModelListener l) {
    _listener.remove(TreeModelListener.class, l);
  }
}
Ejemplo n.º 2
0
public class TextAreaDef extends XulTag implements NComponentFactory {

  public static final XulTagFactory FACTORY =
      new XulTagFactory() {
        public XulTag createXulTag(Element element) {
          return new TextAreaDef(element);
        }
      };

  static Logger T = Logger.getLogger(TextAreaDef.class);

  public TextAreaDef(Element element) {
    super(element);
  }

  public NComponent createNComponent(JComponentResolver resolver, XulContext ctx) {
    return new XTextArea(this, ctx);
  }
}
Ejemplo n.º 3
0
 public void onButtonEntered(AbstractButton button) {
   T.debug("onButtonEntered()");
 }
Ejemplo n.º 4
0
public class HintPublisher {
  static Logger T = Logger.getLogger(HintPublisher.class);

  private static HintPublisher _publisher;
  private MouseListener _buttonMouseListener;
  private MenuItemListener _menuItemListener;

  private MenuListener _menuListener;

  private JLabel _subscriber;

  private HintPublisher() {}

  public static HintPublisher getHintPublisher() {
    if (_publisher == null) _publisher = new HintPublisher();

    return _publisher;
  }

  public void addButton(AbstractButton button) {
    if (_buttonMouseListener == null) {
      _buttonMouseListener =
          new MouseListener() {
            public void mouseClicked(MouseEvent ev) {}

            public void mouseEntered(MouseEvent ev) {
              onButtonEntered((AbstractButton) ev.getSource());
            }

            public void mouseExited(MouseEvent ev) {
              onButtonExited((AbstractButton) ev.getSource());
            }

            public void mousePressed(MouseEvent ev) {}

            public void mouseReleased(MouseEvent ev) {}
          };
    }

    button.addMouseListener(_buttonMouseListener);
  }

  public void addMenu(JMenu menu) {
    if (_menuListener == null) {
      _menuListener =
          new MenuListener() {
            public void menuCanceled(MenuEvent ev) {
              onMenuCanceled((JMenu) ev.getSource());
            }

            public void menuDeselected(MenuEvent ev) {
              onMenuDeselected((JMenu) ev.getSource());
            }

            public void menuSelected(MenuEvent ev) {
              onMenuSelected((JMenu) ev.getSource());
            }
          };
    }

    menu.addMenuListener(_menuListener);
  }

  public void addMenuItem(MenuItemSource mi) {
    if (_menuItemListener == null) {
      _menuItemListener =
          new MenuItemListener() {

            public void menuItemDeselected(MenuItemEvent ev) {
              onMenuItemDeselected((JMenuItem) ev.getSource());
            }

            public void menuItemSelected(MenuItemEvent ev) {
              onMenuItemSelected((JMenuItem) ev.getSource());
            }
          };
    }

    mi.addMenuItemListener(_menuItemListener);
  }

  public void onButtonEntered(AbstractButton button) {
    T.debug("onButtonEntered()");
  }

  public void onButtonExited(AbstractButton button) {
    T.debug("onButtonExited()");
  }

  public void onMenuCanceled(JMenu menu) {
    T.debug("onMenuCanceled()");
  }

  public void onMenuDeselected(JMenu menu) {
    T.debug("onMenuDeselected()");
  }

  public void onMenuItemDeselected(JMenuItem mi) {
    publish(" ");
    T.debug("onMenuItemDeselected()");
  }

  public void onMenuItemSelected(JMenuItem mi) {
    publish("text: " + mi.getText() + ", tooltip: " + mi.getToolTipText());
    T.debug("onMenuItemSelected()");
  }

  public void onMenuSelected(JMenu menu) {
    T.debug("onMenuSelected()");
  }

  public void subscribe(JLabel subscriber) {
    // todo: use interface to allow many subscribers
    _subscriber = subscriber;
  }

  private void publish(String msg) {
    if (_subscriber != null) _subscriber.setText(msg);
  }
}
Ejemplo n.º 5
0
 public void onMenuSelected(JMenu menu) {
   T.debug("onMenuSelected()");
 }
Ejemplo n.º 6
0
 public void onMenuItemSelected(JMenuItem mi) {
   publish("text: " + mi.getText() + ", tooltip: " + mi.getToolTipText());
   T.debug("onMenuItemSelected()");
 }
Ejemplo n.º 7
0
 public void onMenuItemDeselected(JMenuItem mi) {
   publish(" ");
   T.debug("onMenuItemDeselected()");
 }
Ejemplo n.º 8
0
 public void onMenuCanceled(JMenu menu) {
   T.debug("onMenuCanceled()");
 }