added lazy loading of tool tip texts from the circuits

This commit is contained in:
hneemann 2017-05-16 08:39:22 +02:00
parent 4799a81e01
commit 16ceaeb06d
4 changed files with 27 additions and 4 deletions

View File

@ -482,7 +482,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
/**
* Returns the filename
* the retuned file is opened if the user wants to modify the element
* The returned file is opened if the user wants to modify the element
*
* @return the filename
*/

View File

@ -9,6 +9,8 @@ import de.neemann.digital.draw.shapes.ShapeFactory;
import de.neemann.digital.lang.Lang;
import de.neemann.gui.IconCreator;
import de.neemann.gui.LineBreaker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.io.File;
@ -21,6 +23,7 @@ import java.util.Iterator;
* Created by hneemann on 25.03.17.
*/
public class LibraryNode implements Iterable<LibraryNode> {
private static final Logger LOGGER = LoggerFactory.getLogger(LibraryNode.class);
private static final Icon ICON_NOT_UNIQUE = IconCreator.create("testFailed.png");
private final ArrayList<LibraryNode> children;
@ -325,6 +328,7 @@ public class LibraryNode implements Iterable<LibraryNode> {
if (description == null) {
if (toolTipText == null) {
try {
LOGGER.debug("load tooltip from "+file);
Circuit c = Circuit.loadCircuit(file, null);
toolTipText = c.getAttributes().get(Keys.DESCRIPTION);
} catch (Exception e) {

View File

@ -90,4 +90,25 @@ public final class InsertAction extends ToolTipAction {
public LibraryNode getNode() {
return node;
}
/**
* Implements a lazy loading of the tooltips.
* Avoids the reading of all tooltips from the lib files if menu is created.
* This code ensures, that the tooltips are onli loaded from the file if the text is shown to the user.
*
* @return the JMenuItem created
*/
@Override
public JMenuItem createJMenuItem() {
JMenuItem i = new JMenuItem(node.getTranslatedName(), getIcon()) {
@Override
public String getToolTipText() {
return node.getToolTipText();
}
};
i.addActionListener(InsertAction.this);
ToolTipManager.sharedInstance().registerComponent(i);
return i;
}
}

View File

@ -83,9 +83,7 @@ public class LibrarySelector implements LibraryListener {
private void addComponents(JMenu parts, LibraryNode node) {
if (node.isLeaf()) {
parts.add(new InsertAction(node, insertHistory, circuitComponent, shapeFactory)
.setToolTip(node.getToolTipText())
.createJMenuItem());
parts.add(new InsertAction(node, insertHistory, circuitComponent, shapeFactory).createJMenuItem());
} else {
JMenu subMenu = new JMenu(node.getName());
for (LibraryNode child : node)