mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-27 23:18:02 -04:00
added lazy loading of tool tip texts from the circuits
This commit is contained in:
parent
4799a81e01
commit
16ceaeb06d
@ -482,7 +482,7 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the filename
|
* 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
|
* @return the filename
|
||||||
*/
|
*/
|
||||||
|
@ -9,6 +9,8 @@ import de.neemann.digital.draw.shapes.ShapeFactory;
|
|||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
import de.neemann.gui.IconCreator;
|
import de.neemann.gui.IconCreator;
|
||||||
import de.neemann.gui.LineBreaker;
|
import de.neemann.gui.LineBreaker;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -21,6 +23,7 @@ import java.util.Iterator;
|
|||||||
* Created by hneemann on 25.03.17.
|
* Created by hneemann on 25.03.17.
|
||||||
*/
|
*/
|
||||||
public class LibraryNode implements Iterable<LibraryNode> {
|
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 static final Icon ICON_NOT_UNIQUE = IconCreator.create("testFailed.png");
|
||||||
|
|
||||||
private final ArrayList<LibraryNode> children;
|
private final ArrayList<LibraryNode> children;
|
||||||
@ -325,6 +328,7 @@ public class LibraryNode implements Iterable<LibraryNode> {
|
|||||||
if (description == null) {
|
if (description == null) {
|
||||||
if (toolTipText == null) {
|
if (toolTipText == null) {
|
||||||
try {
|
try {
|
||||||
|
LOGGER.debug("load tooltip from "+file);
|
||||||
Circuit c = Circuit.loadCircuit(file, null);
|
Circuit c = Circuit.loadCircuit(file, null);
|
||||||
toolTipText = c.getAttributes().get(Keys.DESCRIPTION);
|
toolTipText = c.getAttributes().get(Keys.DESCRIPTION);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -90,4 +90,25 @@ public final class InsertAction extends ToolTipAction {
|
|||||||
public LibraryNode getNode() {
|
public LibraryNode getNode() {
|
||||||
return node;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,9 +83,7 @@ public class LibrarySelector implements LibraryListener {
|
|||||||
|
|
||||||
private void addComponents(JMenu parts, LibraryNode node) {
|
private void addComponents(JMenu parts, LibraryNode node) {
|
||||||
if (node.isLeaf()) {
|
if (node.isLeaf()) {
|
||||||
parts.add(new InsertAction(node, insertHistory, circuitComponent, shapeFactory)
|
parts.add(new InsertAction(node, insertHistory, circuitComponent, shapeFactory).createJMenuItem());
|
||||||
.setToolTip(node.getToolTipText())
|
|
||||||
.createJMenuItem());
|
|
||||||
} else {
|
} else {
|
||||||
JMenu subMenu = new JMenu(node.getName());
|
JMenu subMenu = new JMenu(node.getName());
|
||||||
for (LibraryNode child : node)
|
for (LibraryNode child : node)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user