minor refactorings on the groupEdit function

This commit is contained in:
hneemann 2017-09-12 10:37:22 +02:00
parent 60c9898d4f
commit 427abf0859
10 changed files with 4959 additions and 154 deletions

File diff suppressed because it is too large Load Diff

View File

@ -48,10 +48,11 @@ public final class Keys {
/**
* The size of a LED
*/
public static final Key.KeyInteger SIZE
public static final Key<Integer> SIZE
= new Key.KeyInteger("Size", 1)
.setComboBoxValues(new Integer[]{1, 2, 3, 4, 5})
.setMin(1);
.setMin(1)
.setGroupEditAllowed(true);
/**
* The value of constants

View File

@ -33,7 +33,7 @@ public class AttributeDialog extends JDialog {
private final ElementAttributes originalAttributes;
private final ElementAttributes modifiedAttributes;
private final JPanel buttonPanel;
private final GBC constrains;
private final ConstrainsBuilder constrains;
private HashMap<Key, JCheckBox> checkBoxes;
private JComponent topMostTextComponent;
private VisualElement visualElement;
@ -86,7 +86,7 @@ public class AttributeDialog extends JDialog {
editors = new ArrayList<>();
topMostTextComponent = null;
constrains = new GBC().inset(3).fill();
constrains = new ConstrainsBuilder().inset(3).fill();
for (Key key : list) {
Editor e = EditorFactory.INSTANCE.create(key, modifiedAttributes.get(key));
editors.add(new EditorHolder(e, key));

View File

@ -1001,7 +1001,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
}
}
if (keyList.size()>0) {
if (keyList.size() > 0) {
AttributeDialog ad = new AttributeDialog(this, null, keyList, attr, true);
for (Map.Entry<Key, Boolean> u : useKeyMap.entrySet())
ad.getCheckBoxes().get(u.getKey()).setSelected(u.getValue());

View File

@ -0,0 +1,142 @@
package de.neemann.digital.gui.components;
import java.awt.*;
/**
* More simple to use GridBagConstrains
*/
public class ConstrainsBuilder extends GridBagConstraints {
/**
* Creates a new instance.
* Position is set to (0,0)
*/
public ConstrainsBuilder() {
gridx = 0;
gridy = 0;
}
private ConstrainsBuilder(ConstrainsBuilder original) {
gridx = original.gridx;
gridy = original.gridy;
gridwidth = original.gridwidth;
gridheight = original.gridheight;
weightx = original.weightx;
weighty = original.weighty;
ipadx = original.ipadx;
ipady = original.ipady;
fill = original.fill;
insets = original.insets;
}
/**
* Sets the position
*
* @param x x position
* @param y y position
* @return the new created ConstrainsBuilder instance
*/
public ConstrainsBuilder pos(int x, int y) {
ConstrainsBuilder c = new ConstrainsBuilder(this);
c.gridx = x;
c.gridy = y;
return c;
}
/**
* Sets the position
*
* @param x x position
* @return the new created ConstrainsBuilder instance
*/
public ConstrainsBuilder x(int x) {
ConstrainsBuilder c = new ConstrainsBuilder(this);
c.gridx = x;
return c;
}
/**
* Sets the width
*
* @param x width
* @return the new created ConstrainsBuilder instance
*/
public ConstrainsBuilder width(int x) {
ConstrainsBuilder c = new ConstrainsBuilder(this);
c.gridwidth = x;
return c;
}
/**
* Sets a dynamic height
*
* @return the new created ConstrainsBuilder instance
*/
public ConstrainsBuilder dynamicHeight() {
ConstrainsBuilder c = new ConstrainsBuilder(this);
c.weighty = 1;
return c;
}
/**
* Sets a dynamic width
*
* @return the new created ConstrainsBuilder instance
*/
public ConstrainsBuilder dynamicWidth() {
ConstrainsBuilder c = new ConstrainsBuilder(this);
c.weightx = 1;
return c;
}
/**
* Sets the padding
*
* @param x x padding
* @param y y padding
* @return the new created ConstrainsBuilder instance
*/
public ConstrainsBuilder pad(int x, int y) {
ConstrainsBuilder c = new ConstrainsBuilder(this);
c.ipadx = x;
c.ipady = y;
return c;
}
/**
* Sets the fill attribute to BOTH
*
* @return the new created ConstrainsBuilder instance
*/
public ConstrainsBuilder fill() {
ConstrainsBuilder c = new ConstrainsBuilder(this);
c.fill = GridBagConstraints.BOTH;
return c;
}
/**
* Sets insets to a border of width b
*
* @param b border width
* @return the new created ConstrainsBuilder instance
*/
public ConstrainsBuilder inset(int b) {
ConstrainsBuilder c = new ConstrainsBuilder(this);
c.insets = new Insets(b, b, b, b);
return c;
}
/**
* Increases the row.
* Does not create a new instance!
*
* @return this for chained calls
*/
public ConstrainsBuilder nextRow() {
gridx = 0;
gridy++;
return this;
}
}

View File

@ -25,5 +25,5 @@ public interface Editor<T> {
* @param dialog the containing dialog
* @param constrains the constrains used to place the components in the panel
*/
void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes, AttributeDialog dialog, GBC constrains);
void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes, AttributeDialog dialog, ConstrainsBuilder constrains);
}

View File

@ -97,7 +97,7 @@ public final class EditorFactory {
private boolean labelAtTop = false;
@Override
public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes, AttributeDialog attributeDialog, GBC constrains) {
public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes, AttributeDialog attributeDialog, ConstrainsBuilder constrains) {
this.attributeDialog = attributeDialog;
JLabel label = new JLabel(key.getName() + ": ");
final String description = new LineBreaker().toHTML().breakLines(key.getDescription());
@ -256,7 +256,7 @@ public final class EditorFactory {
}
@Override
public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes, AttributeDialog attributeDialog, GBC constrains) {
public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes, AttributeDialog attributeDialog, ConstrainsBuilder constrains) {
panel.add(bool, constrains.width(2));
}
}

View File

@ -1,144 +0,0 @@
package de.neemann.digital.gui.components;
import java.awt.*;
/**
* More simple to use GridBagConstrains
*/
public class GBC extends GridBagConstraints {
/**
* Creates a new instance.
* Position is set to (0,0)
*/
public GBC() {
gridx = 0;
gridy = 0;
}
private GBC copy() {
GBC n = new GBC();
n.gridx = gridx;
n.gridy = gridy;
n.gridwidth = gridwidth;
n.gridheight = gridheight;
n.weightx = weightx;
n.weighty = weighty;
n.ipadx = ipadx;
n.ipady = ipady;
n.fill = fill;
n.insets = insets;
return n;
}
/**
* Sets the position
*
* @param x x position
* @param y y position
* @return the new created GBC instance
*/
public GBC pos(int x, int y) {
GBC c = copy();
c.gridx = x;
c.gridy = y;
return c;
}
/**
* Sets the position
*
* @param x x position
* @return the new created GBC instance
*/
public GBC x(int x) {
GBC c = copy();
c.gridx = x;
return c;
}
/**
* Sets the width
*
* @param x width
* @return the new created GBC instance
*/
public GBC width(int x) {
GBC c = copy();
c.gridwidth = x;
return c;
}
/**
* Sets a dynamic height
*
* @return the new created GBC instance
*/
public GBC dynamicHeight() {
GBC c = copy();
c.weighty = 1;
return c;
}
/**
* Sets a dynamic width
*
* @return the new created GBC instance
*/
public GBC dynamicWidth() {
GBC c = copy();
c.weightx = 1;
return c;
}
/**
* Sets the padding
*
* @param x x padding
* @param y y padding
* @return the new created GBC instance
*/
public GBC pad(int x, int y) {
GBC c = copy();
c.ipadx = x;
c.ipady = y;
return c;
}
/**
* Sets the fill attribute to BOTH
*
* @return the new created GBC instance
*/
public GBC fill() {
GBC c = copy();
c.fill = GridBagConstraints.BOTH;
return c;
}
/**
* Sets insets to a border of width b
*
* @param b border width
* @return the new created GBC instance
*/
public GBC inset(int b) {
GBC c = copy();
c.insets = new Insets(b, b, b, b);
return c;
}
/**
* Increases the row.
* Does not create a new instance
*
* @return this for chained calls
*/
public GBC nextRow() {
gridx = 0;
gridy++;
return this;
}
}

View File

@ -90,7 +90,7 @@ public final class SingleValueDialog extends JDialog implements ModelStateObserv
});
JPanel panel = new JPanel(new GridBagLayout());
GBC constr = new GBC().inset(3).fill();
ConstrainsBuilder constr = new ConstrainsBuilder().inset(3).fill();
panel.add(formatComboBox, constr);
panel.add(textField, constr.dynamicWidth().x(1));
constr.nextRow();

View File

@ -1015,7 +1015,7 @@ eine &lt;a href=&quot;https://github.com/hneemann/Digital/issues/new?labels=enha
<string name="msg_modelHasErrors">Es kann nur eine fehlerfreie Schaltung exportiert werden!</string>
<string name="msg_noKVMapAvailable">Keine KV-Tafel verfügbar!</string>
<string name="msg_dataNotUpdatedAnymore">Daten werden nicht mehr aktualisiert!</string>
<string name="msg_modifyThisAttribute">Diesen Wert setzen</string>
<string name="msg_modifyThisAttribute">Diesen Wert verändern.</string>
<string name="ok">Ok</string>
<string name="rot_0"></string>