Author: dandre
Date: Thu Oct 10 00:50:44 2013
New Revision: 4605
Log:
* Add detailed entity view as tooltip in tree view
Added:
trunk/AncestrisCore/core/src/ancestris/view/BpToolTip.java
- copied, changed from r4599,
/trunk/AncestrisCore/modules.views.entity/src/genj/entity/EntityView.java
Modified:
trunk/AncestrisCore/modules.views.tree/src/genj/tree/TreeView.java
Copied: trunk/AncestrisCore/core/src/ancestris/view/BpToolTip.java (from r4599,
/trunk/AncestrisCore/modules.views.entity/src/genj/entity/EntityView.java)
==============================================================================
--- /trunk/AncestrisCore/modules.views.entity/src/genj/entity/EntityView.java
(original)
+++ trunk/AncestrisCore/core/src/ancestris/view/BpToolTip.java Thu Oct 10
00:50:44 2013
@@ -1,173 +1,94 @@
-/**
- * GenJ - GenealogyJ
- *
- * Copyright (C) 1997 - 2002 Nils Meier <[email protected]>
+/*
+ * Ancestris - http://www.ancestris.org
*
- * This piece of code is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * Copyright 2013 Ancestris
*
- * This code is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Author: Daniel Andre ([email protected]).
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
-package genj.entity;
+package ancestris.view;
-import ancestris.core.actions.AncestrisActionProvider;
-import ancestris.gedcom.PropertyNode;
-import genj.gedcom.Context;
import genj.gedcom.Entity;
import genj.gedcom.Gedcom;
-import genj.gedcom.GedcomListener;
-import genj.gedcom.GedcomListenerAdapter;
-import genj.gedcom.Property;
import genj.renderer.Blueprint;
import genj.renderer.BlueprintManager;
import genj.renderer.BlueprintRenderer;
-import genj.renderer.ChooseBlueprintAction;
import genj.renderer.RenderOptions;
import genj.util.Registry;
import genj.util.Resources;
-import genj.view.View;
+import java.awt.BasicStroke;
import java.awt.Color;
+import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
-import java.util.ArrayList;
+import java.awt.Shape;
+import java.awt.geom.RoundRectangle2D;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import javax.swing.Action;
-import org.openide.nodes.Node;
-import spin.Spin;
+import javax.swing.JComponent;
+import javax.swing.JToolTip;
/**
* A rendering component showing the currently selected entity
* via html
*/
-public class EntityView extends View implements AncestrisActionProvider {
+public class BpToolTip extends JToolTip {
/** language resources we use */
- /* package */ final static Resources resources =
Resources.get(EntityView.class);
+ /* package */ final static Resources resources =
Resources.get(BpToolTip.class);
/** a dummy blueprint */
private final static Blueprint BLUEPRINT_SELECT = new
Blueprint(resources.getString("html.select"));
/** a registry we keep */
- private final static Registry REGISTRY = Registry.get(EntityView.class);
+ private final static Registry REGISTRY = Registry.get(BpToolTip.class);
/** the renderer we're using */
private BlueprintRenderer renderer = null;
- /** our current context */
- /* package */ Context context = new Context();
/** the blueprints we're using */
private Map<String, Blueprint> type2blueprint = new HashMap<String,
Blueprint>();
/** whether we do antialiasing */
private boolean isAntialiasing = true;
- private transient GedcomListener callback = new GedcomListenerAdapter() {
-
- @Override
- public void gedcomEntityDeleted(Gedcom gedcom, Entity entity) {
- if (context.getEntity() == entity) {
- setContext(new Context(context.getGedcom()));
- }
- }
-
- @Override
- public void gedcomPropertyChanged(Gedcom gedcom, Property property) {
- if (context.getEntity() == property.getEntity()) {
- repaint();
- }
- }
-
- @Override
- public void gedcomPropertyAdded(Gedcom gedcom, Property property, int
pos, Property added) {
- gedcomPropertyChanged(gedcom, property);
- }
-
- @Override
- public void gedcomPropertyDeleted(Gedcom gedcom, Property property,
int pos, Property removed) {
- gedcomPropertyChanged(gedcom, property);
- }
- };
+ private Entity entity;
/**
* Constructor
*/
- public EntityView() {
+ public BpToolTip() {
+ super();
+ this.setOpaque(false);
// grab data from registry
BlueprintManager bpm = BlueprintManager.getInstance();
for (int t = 0; t < Gedcom.ENTITIES.length; t++) {
String tag = Gedcom.ENTITIES[t];
- type2blueprint.put(tag, bpm.getBlueprint(tag,
REGISTRY.get("blueprint." + tag, "")));
+ type2blueprint.put(tag, bpm.getBlueprint(tag,
""));//REGISTRY.get("blueprint." + tag, "")));
}
isAntialiasing = REGISTRY.get("antial", false);
// done
}
+ private static BpToolTip instance;
- @Override
- public List<Action> getActions(boolean hasFocus, Node[] nodes) {
- if (!hasFocus) {
- return new ArrayList<Action>();
- }
- List<Action> actions = new ArrayList<Action>();
- if (nodes.length == 1) {
- if (nodes[0] instanceof PropertyNode) {
- PropertyNode node = (PropertyNode) nodes[0];
- Entity entity = node.getProperty().getEntity();
- actions.add(new ChooseBlueprintAction(entity,
getBlueprint(entity.getTag())) {
-
- @Override
- protected void commit(Entity recipient, Blueprint
blueprint) {
- type2blueprint.put(blueprint.getTag(), blueprint);
- setContext(context);
- REGISTRY.put("blueprint." + blueprint.getTag(),
blueprint.getName());
- }
- });
- }
+ public static BpToolTip getdefault() {
+ if (instance == null) {
+ instance = new BpToolTip();
}
- return actions;
+ return instance;
}
- /**
- * our context setter
- */
- @Override
- public void setContext(Context newContext) {
-
- // disconnect from old
- if (context.getGedcom() != null) {
- context.getGedcom().removeGedcomListener((GedcomListener)
Spin.over(callback));
- }
- renderer = null;
-
- // keep new
- context = newContext;
-
- // hook-up
- if (context.getGedcom() != null) {
- context.getGedcom().addGedcomListener((GedcomListener)
Spin.over(callback));
-
- // resolve blueprint & renderer
- Entity e = context.getEntity();
- Blueprint blueprint;
- if (e == null) {
- blueprint = BLUEPRINT_SELECT;
- } else {
- blueprint = getBlueprint(e.getTag());
- }
- renderer = new BlueprintRenderer(blueprint);
-
+ public void setEntity(Entity entity) {
+ this.entity = entity;
+ Blueprint blueprint;
+ if (entity == null) {
+ blueprint = BLUEPRINT_SELECT;
+ } else {
+ blueprint = getBlueprint(entity.getTag());
}
-
- repaint();
+ renderer = new BlueprintRenderer(blueprint);
}
/**
@@ -175,36 +96,51 @@
*/
@Override
public Dimension getPreferredSize() {
- return new Dimension(256, 160);
+ return new Dimension(256, 256);
}
-// // store settings in registry
-// for (int t=0;t<Gedcom.ENTITIES.length;t++) {
-// String tag = Gedcom.ENTITIES[t];
-// registry.put("blueprint."+tag, getBlueprint(tag).getName());
-// }
-// registry.put("antial", isAntialiasing );
- /**
- * @see javax.swing.JComponent#paintComponent(Graphics)
- */
@Override
- protected void paintComponent(Graphics g) {
+ public void paintComponent(Graphics g) {
- Rectangle bounds = getBounds();
- g.setColor(Color.white);
- g.fillRect(0, 0, bounds.width, bounds.height);
- g.setColor(Color.black);
- g.setFont(RenderOptions.getInstance().getDefaultFont());
+ // set the parent to not be opaque
+ Component parent = this.getParent();
+ if (parent != null) {
+ if (parent instanceof JComponent) {
+ JComponent jparent = (JComponent) parent;
+ if (jparent.isOpaque()) {
+ jparent.setOpaque(false);
+ }
+ }
+ }
- if (context == null || renderer == null) {
+ if (entity == null || renderer == null) {
return;
}
-
- ((Graphics2D) g).setRenderingHint(
- RenderingHints.KEY_ANTIALIASING,
+// create a round rectangle
+ Shape round = new RoundRectangle2D.Float(4, 4,
+ this.getWidth() - 1 - 8,
+ this.getHeight() - 1 - 8,
+ 15, 15);
+
+
+// draw the white background
+ Graphics2D g2 = (Graphics2D) g;
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ g2.setColor(Color.WHITE);
+ g2.fill(round);
+
+// draw the gray border
+ g2.setColor(new Color(0, 0, 0));
+ g2.setStroke(new BasicStroke(2));
+ g2.draw(round);
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
isAntialiasing ? RenderingHints.VALUE_ANTIALIAS_ON :
RenderingHints.VALUE_ANTIALIAS_OFF);
- renderer.render(g, context.getEntity(), new Rectangle(0, 0,
bounds.width, bounds.height));
+// draw the blueprint
+ g2.setColor(Color.BLACK);
+ g.setFont(RenderOptions.getInstance().getDefaultFont());
+ renderer.render(g, entity, new Rectangle(4, 4, getWidth() - 9,
getHeight() - 9));
}
/**
@@ -213,7 +149,7 @@
private Blueprint getBlueprint(String tag) {
Blueprint result = type2blueprint.get(tag);
if (result == null) {
- result = BlueprintManager.getInstance().getBlueprint(tag, "");
+ result = BlueprintManager.getInstance().getBlueprint(tag,
"complete");
type2blueprint.put(tag, result);
}
return result;
@@ -233,4 +169,4 @@
public boolean isAntialiasing() {
return isAntialiasing;
}
-} //EntityView
+}
Modified: trunk/AncestrisCore/modules.views.tree/src/genj/tree/TreeView.java
==============================================================================
--- trunk/AncestrisCore/modules.views.tree/src/genj/tree/TreeView.java
(original)
+++ trunk/AncestrisCore/modules.views.tree/src/genj/tree/TreeView.java Thu Oct
10 00:50:44 2013
@@ -29,6 +29,7 @@
import ancestris.gedcom.GedcomDirectory;
import ancestris.gedcom.GedcomDirectory.ContextNotFoundException;
import ancestris.util.swing.DialogManager;
+import ancestris.view.BpToolTip;
import ancestris.view.ExplorerHelper;
import ancestris.view.SelectionActionEvent;
import ancestris.view.SelectionDispatcher;
@@ -72,6 +73,7 @@
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
+import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
@@ -93,6 +95,7 @@
import javax.swing.JScrollPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
+import javax.swing.JToolTip;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
@@ -147,6 +150,8 @@
// Lookup listener for action callback
private Lookup.Result<SelectionActionEvent> result;
+ private BpToolTip tt = new BpToolTip();
+
/**
* Constructor
*/
@@ -902,6 +907,7 @@
super.addNotify();
// listen to model events
model.addListener(this);
+ setToolTipText("");
}
@Override
@@ -909,8 +915,26 @@
model.removeListener(this);
// cont
super.removeNotify();
+ setToolTipText(null);
+ }
+
+ @Override
+ public JToolTip createToolTip() {
+ tt.setEntity(getEntityAt(TreeView.this.getMousePosition()));
+ tt.setComponent(this);
+ return tt;
}
+ // Change TT to fire a createTooltip call
+ @Override
+ public String getToolTipText(MouseEvent event) {
+ Point pos = TreeView.this.getMousePosition();
+ if (pos == null) return "";
+ Entity entity = getEntityAt(pos);
+ if (entity == null) return "";
+ return entity.getId();
+ }
+
/**
* @param e
*/
---------------------------------------------------------------------
Site Web Ancestris : http://www.ancestris.org
<*> Pour vous desinscrire de cette liste, envoyez un mail a :
[email protected]
<*> Pour obtenir de l'aide sur les commandes de la liste :
[email protected]
Pour obtenir tous les messages lies a ce fil de discussion, cliquez sur le
lien ci-dessous, cela ouvrira votre logiciel de messagerie. Il vous suffira
d'envoyer le message :
[email protected]