mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 17:04:42 -04:00
refactoring of wide shape flag handling
This commit is contained in:
parent
1351d8b4ce
commit
4e0b61fc3b
@ -286,25 +286,34 @@ public class LibraryNode implements Iterable<LibraryNode> {
|
||||
*/
|
||||
public Icon getIconOrNull(ShapeFactory shapeFactory) {
|
||||
if (unique) {
|
||||
if (icon == null && description != null) {
|
||||
final VisualElement visualElement = new VisualElement(description.getName()).setShapeFactory(shapeFactory);
|
||||
|
||||
// set the wide shape option to the element
|
||||
try {
|
||||
if (Settings.getInstance().get(Keys.SETTINGS_USE_WIDE_SHAPES)
|
||||
&& getDescription().hasAttribute(Keys.WIDE_SHAPE))
|
||||
visualElement.setAttribute(Keys.WIDE_SHAPE, true);
|
||||
} catch (IOException e1) {
|
||||
// do nothing on error
|
||||
}
|
||||
|
||||
icon = visualElement.createIcon(75);
|
||||
}
|
||||
if (icon == null && description != null)
|
||||
icon = setWideShapeFlagTo(
|
||||
new VisualElement(description.getName())
|
||||
.setShapeFactory(shapeFactory)
|
||||
).createIcon(75);
|
||||
return icon;
|
||||
} else
|
||||
return ICON_NOT_UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the wide shape flag to this element if necessary
|
||||
*
|
||||
* @param visualElement the visual element
|
||||
* @return the given visual element
|
||||
*/
|
||||
public VisualElement setWideShapeFlagTo(VisualElement visualElement) {
|
||||
// set the wide shape option to the element
|
||||
try {
|
||||
if (Settings.getInstance().get(Keys.SETTINGS_USE_WIDE_SHAPES)
|
||||
&& getDescription().hasAttribute(Keys.WIDE_SHAPE))
|
||||
visualElement.setAttribute(Keys.WIDE_SHAPE, true);
|
||||
} catch (IOException e1) {
|
||||
// do nothing on error
|
||||
}
|
||||
return visualElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given child.
|
||||
*
|
||||
@ -342,7 +351,7 @@ public class LibraryNode implements Iterable<LibraryNode> {
|
||||
path.add(0, n);
|
||||
n = n.parent;
|
||||
}
|
||||
return path.toArray(new Object[path.size()]);
|
||||
return path.toArray(new Object[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
package de.neemann.digital.gui;
|
||||
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
import de.neemann.digital.draw.graphics.Vector;
|
||||
import de.neemann.digital.draw.library.LibraryNode;
|
||||
@ -49,7 +48,7 @@ public final class InsertAction extends ToolTipAction {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (node.isUnique()) {
|
||||
VisualElement visualElement = new VisualElement(node.getName()).setPos(new Vector(10, 10)).setShapeFactory(shapeFactory);
|
||||
VisualElement visualElement = node.setWideShapeFlagTo(new VisualElement(node.getName()).setPos(new Vector(10, 10)).setShapeFactory(shapeFactory));
|
||||
if (getIcon() == null) {
|
||||
try {
|
||||
node.getDescription();
|
||||
@ -59,15 +58,6 @@ public final class InsertAction extends ToolTipAction {
|
||||
}
|
||||
}
|
||||
|
||||
// set the wide shape option to the new element
|
||||
try {
|
||||
if (Settings.getInstance().get(Keys.SETTINGS_USE_WIDE_SHAPES)
|
||||
&& node.getDescription().hasAttribute(Keys.WIDE_SHAPE))
|
||||
visualElement.setAttribute(Keys.WIDE_SHAPE, true);
|
||||
} catch (IOException e1) {
|
||||
// do nothing on error
|
||||
}
|
||||
|
||||
if (visualElement.getShape() instanceof MissingShape)
|
||||
return;
|
||||
|
||||
|
@ -6,13 +6,11 @@
|
||||
package de.neemann.digital.gui.components.tree;
|
||||
|
||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
import de.neemann.digital.draw.library.LibraryNode;
|
||||
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||
import de.neemann.digital.gui.InsertAction;
|
||||
import de.neemann.digital.gui.InsertHistory;
|
||||
import de.neemann.digital.gui.Settings;
|
||||
import de.neemann.digital.gui.components.CircuitComponent;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
import de.neemann.gui.ErrorMessage;
|
||||
@ -53,17 +51,7 @@ public class SelectTree extends JTree {
|
||||
if (node.isLeaf() && node.isUnique()) {
|
||||
try {
|
||||
ElementTypeDescription d = node.getDescription();
|
||||
final VisualElement element = new VisualElement(d.getName()).setShapeFactory(shapeFactory);
|
||||
|
||||
// set the wide shape option to the new element
|
||||
try {
|
||||
if (Settings.getInstance().get(Keys.SETTINGS_USE_WIDE_SHAPES)
|
||||
&& node.getDescription().hasAttribute(Keys.WIDE_SHAPE))
|
||||
element.setAttribute(Keys.WIDE_SHAPE, true);
|
||||
} catch (IOException e1) {
|
||||
// do nothing on error
|
||||
}
|
||||
|
||||
final VisualElement element = node.setWideShapeFlagTo(new VisualElement(d.getName()).setShapeFactory(shapeFactory));
|
||||
component.setPartToInsert(element);
|
||||
insertHistory.add(new InsertAction(node, insertHistory, component, shapeFactory));
|
||||
} catch (IOException e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user