mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
reorg loadline
This commit is contained in:
@@ -42,6 +42,7 @@ G-D-S MOSFET
|
|||||||
G-S-D JFET
|
G-S-D JFET
|
||||||
G-S-D MOSFET
|
G-S-D MOSFET
|
||||||
Lin
|
Lin
|
||||||
|
Loadline Editor
|
||||||
Log
|
Log
|
||||||
NPN
|
NPN
|
||||||
Nand
|
Nand
|
||||||
|
|||||||
@@ -21,35 +21,37 @@
|
|||||||
*/
|
*/
|
||||||
package org.diylc.swing.gui.editor;
|
package org.diylc.swing.gui.editor;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.io.File;
|
||||||
import java.awt.event.MouseEvent;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JColorChooser;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.components.misc.LoadlineEntity;
|
import org.diylc.components.misc.LoadlineEntity;
|
||||||
import org.diylc.swingframework.ButtonDialog;
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
|
import org.diylc.swing.loadline.LoadlineEditorFrame;
|
||||||
|
import org.diylc.swing.plugins.file.FileFilterEnum;
|
||||||
|
|
||||||
|
import com.thoughtworks.xstream.XStream;
|
||||||
|
|
||||||
public class LoadlineEditor extends JButton {
|
public class LoadlineEditor extends JButton {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(LoadlineEditor.class);
|
||||||
|
|
||||||
private static final String title = "Click to edit";
|
private static final String title = " (click to load from a file)";
|
||||||
|
|
||||||
private PropertyWrapper property;
|
|
||||||
|
|
||||||
public LoadlineEditor(final PropertyWrapper property) {
|
public LoadlineEditor(final PropertyWrapper property) {
|
||||||
super();
|
super();
|
||||||
this.property = property;
|
|
||||||
|
|
||||||
LoadlineEntity loadline = (LoadlineEntity) property.getValue();
|
LoadlineEntity loadline = (LoadlineEntity) property.getValue();
|
||||||
|
|
||||||
@@ -64,13 +66,25 @@ public class LoadlineEditor extends JButton {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
LoadlineEditorDialog dialog = new LoadlineEditorDialog(null, "Edit Loadline", loadline);
|
final File file = DialogFactory.getInstance().showOpenDialog(FileFilterEnum.CRV.getFilter(), null,
|
||||||
dialog.setVisible(true);
|
FileFilterEnum.CRV.getExtensions()[0], null);
|
||||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption()))
|
if (file != null) {
|
||||||
{
|
try {
|
||||||
property.setChanged(true);
|
XStream xStream = LoadlineEditorFrame.loadlineXStream();
|
||||||
// property.setValue(newColor);
|
|
||||||
}
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
Reader reader = new InputStreamReader(fis, "UTF-8");
|
||||||
|
LoadlineEntity loadline = (LoadlineEntity) xStream.fromXML(reader);
|
||||||
|
fis.close();
|
||||||
|
property.setValue(loadline);
|
||||||
|
property.setChanged(true);
|
||||||
|
|
||||||
|
String name = (loadline == null ? "<empty>" : loadline.getName()) + " ";
|
||||||
|
setText(property.isUnique() ? (name + title ): ("(multi value) " + title));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.error("Error loading loadline file", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+63
-27
@@ -1,4 +1,4 @@
|
|||||||
package org.diylc.swing.gui.editor;
|
package org.diylc.swing.loadline;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
@@ -28,6 +28,7 @@ import javax.swing.JComponent;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
@@ -59,6 +60,7 @@ import org.diylc.images.IconLoader;
|
|||||||
import org.diylc.lang.LangUtil;
|
import org.diylc.lang.LangUtil;
|
||||||
import org.diylc.presenter.Presenter;
|
import org.diylc.presenter.Presenter;
|
||||||
import org.diylc.swing.gui.DialogFactory;
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
|
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
||||||
import org.diylc.swing.plugins.canvas.CanvasPanel;
|
import org.diylc.swing.plugins.canvas.CanvasPanel;
|
||||||
import org.diylc.swing.plugins.file.FileFilterEnum;
|
import org.diylc.swing.plugins.file.FileFilterEnum;
|
||||||
import org.diylc.swingframework.ButtonDialog;
|
import org.diylc.swingframework.ButtonDialog;
|
||||||
@@ -67,11 +69,11 @@ import org.diylc.swingframework.DoubleTextField;
|
|||||||
import com.thoughtworks.xstream.XStream;
|
import com.thoughtworks.xstream.XStream;
|
||||||
import com.thoughtworks.xstream.io.xml.DomDriver;
|
import com.thoughtworks.xstream.io.xml.DomDriver;
|
||||||
|
|
||||||
public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
public class LoadlineEditorFrame extends JFrame implements IView {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(LoadlineEditorDialog.class);
|
private static final Logger LOG = Logger.getLogger(LoadlineEditorFrame.class);
|
||||||
|
|
||||||
private static final String AXIS_LABEL = "AXIS_LABEL";
|
private static final String AXIS_LABEL = "AXIS_LABEL";
|
||||||
private static final String CURVE = "CURVE";
|
private static final String CURVE = "CURVE";
|
||||||
@@ -84,6 +86,7 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
private Presenter plugInPort;
|
private Presenter plugInPort;
|
||||||
private IConfigurationManager configManager;
|
private IConfigurationManager configManager;
|
||||||
|
|
||||||
|
private JTextField nameEditor;
|
||||||
private DoubleTextField vEditor;
|
private DoubleTextField vEditor;
|
||||||
private DoubleTextField iEditor;
|
private DoubleTextField iEditor;
|
||||||
private DoubleTextField dEditor;
|
private DoubleTextField dEditor;
|
||||||
@@ -92,8 +95,8 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
private int xIncrement;
|
private int xIncrement;
|
||||||
private int yIncrement;
|
private int yIncrement;
|
||||||
|
|
||||||
public LoadlineEditorDialog(JFrame owner, String title, LoadlineEntity loadline) {
|
public LoadlineEditorFrame() {
|
||||||
super(owner, title, new String[] {ButtonDialog.OK, ButtonDialog.CANCEL});
|
super("Loadline Editor");
|
||||||
|
|
||||||
if (loadline == null) {
|
if (loadline == null) {
|
||||||
loadline = new LoadlineEntity();
|
loadline = new LoadlineEntity();
|
||||||
@@ -113,7 +116,6 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
this.loadline = loadline;
|
|
||||||
this.plugInPort = new Presenter(this, configManager);
|
this.plugInPort = new Presenter(this, configManager);
|
||||||
this.plugInPort.installPlugin(new IPlugIn() {
|
this.plugInPort.installPlugin(new IPlugIn() {
|
||||||
|
|
||||||
@@ -138,19 +140,21 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
});
|
});
|
||||||
|
|
||||||
loadProject();
|
loadProject();
|
||||||
|
|
||||||
layoutGui();
|
setContentPane(getMainComponent());
|
||||||
|
pack();
|
||||||
|
setLocationRelativeTo(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadProject() {
|
private void loadProject() {
|
||||||
getvEditor().setValue(loadline.getMaxVoltage());
|
getvEditor().setValue(loadline.getMaxVoltage());
|
||||||
getiEditor().setValue(loadline.getMaxCurrent());
|
getiEditor().setValue(loadline.getMaxCurrent());
|
||||||
getdEditor().setValue(loadline.getMaxDissipation());
|
getdEditor().setValue(loadline.getMaxDissipation());
|
||||||
|
getNameEditor().setText(loadline.getName());
|
||||||
loadlineToProject();
|
loadlineToProject();
|
||||||
updateAxis();
|
updateAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JComponent getMainComponent() {
|
protected JComponent getMainComponent() {
|
||||||
if (panel == null) {
|
if (panel == null) {
|
||||||
panel = new JPanel();
|
panel = new JPanel();
|
||||||
@@ -209,22 +213,36 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
}
|
}
|
||||||
return canvasPanel;
|
return canvasPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JTextField getNameEditor() {
|
||||||
|
if (nameEditor == null) {
|
||||||
|
nameEditor = new JTextField();
|
||||||
|
nameEditor.setColumns(12);
|
||||||
|
}
|
||||||
|
return nameEditor;
|
||||||
|
}
|
||||||
|
|
||||||
public DoubleTextField getvEditor() {
|
public DoubleTextField getvEditor() {
|
||||||
if (vEditor == null)
|
if (vEditor == null) {
|
||||||
vEditor = new DoubleTextField();
|
vEditor = new DoubleTextField();
|
||||||
|
vEditor.setColumns(8);
|
||||||
|
}
|
||||||
return vEditor;
|
return vEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleTextField getiEditor() {
|
public DoubleTextField getiEditor() {
|
||||||
if (iEditor == null)
|
if (iEditor == null) {
|
||||||
iEditor = new DoubleTextField();
|
iEditor = new DoubleTextField();
|
||||||
|
iEditor.setColumns(8);
|
||||||
|
}
|
||||||
return iEditor;
|
return iEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleTextField getdEditor() {
|
public DoubleTextField getdEditor() {
|
||||||
if (dEditor == null)
|
if (dEditor == null) {
|
||||||
dEditor = new DoubleTextField();
|
dEditor = new DoubleTextField();
|
||||||
|
dEditor.setColumns(8);
|
||||||
|
}
|
||||||
return dEditor;
|
return dEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,17 +250,16 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
if (controlPanel == null) {
|
if (controlPanel == null) {
|
||||||
controlPanel = new JPanel();
|
controlPanel = new JPanel();
|
||||||
|
|
||||||
|
controlPanel.add(new JLabel("Name: "));
|
||||||
|
controlPanel.add(getNameEditor());
|
||||||
|
|
||||||
controlPanel.add(new JLabel("Max Voltage (V): "));
|
controlPanel.add(new JLabel("Max Voltage (V): "));
|
||||||
vEditor.setColumns(8);
|
|
||||||
controlPanel.add(getvEditor());
|
controlPanel.add(getvEditor());
|
||||||
|
|
||||||
controlPanel.add(new JLabel("Max Current (mA): "));
|
controlPanel.add(new JLabel("Max Current (mA): "));
|
||||||
iEditor.setColumns(8);
|
|
||||||
controlPanel.add(getiEditor());
|
controlPanel.add(getiEditor());
|
||||||
|
|
||||||
controlPanel.add(new JLabel("Max Dissipation (W): "));
|
controlPanel.add(new JLabel("Max Dissipation (W): "));
|
||||||
dEditor.setColumns(8);
|
|
||||||
controlPanel.add(getdEditor());
|
controlPanel.add(getdEditor());
|
||||||
|
|
||||||
JButton updateButton = new JButton(new UpdateValuesAction());
|
JButton updateButton = new JButton(new UpdateValuesAction());
|
||||||
@@ -443,6 +460,7 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
Project project = plugInPort.getCurrentProject();
|
Project project = plugInPort.getCurrentProject();
|
||||||
double spacing = project.getGridSpacing().convertToPixels();
|
double spacing = project.getGridSpacing().convertToPixels();
|
||||||
|
|
||||||
|
loadline.setName(getNameEditor().getText());
|
||||||
int centerX = (int) (spacing * 3);
|
int centerX = (int) (spacing * 3);
|
||||||
int centerY = (int) (project.getHeight().convertToPixels() - spacing * 3);
|
int centerY = (int) (project.getHeight().convertToPixels() - spacing * 3);
|
||||||
double v = loadline.getMaxVoltage();
|
double v = loadline.getMaxVoltage();
|
||||||
@@ -470,6 +488,15 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
}
|
}
|
||||||
loadline.setLines(lines);
|
loadline.setLines(lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static XStream loadlineXStream() {
|
||||||
|
XStream xStream = new XStream(new DomDriver("UTF-8"));
|
||||||
|
xStream.autodetectAnnotations(true);
|
||||||
|
xStream.alias("point", Point2D.Double.class);
|
||||||
|
xStream.alias("curve", org.diylc.components.misc.LoadlineEntity.Line.class);
|
||||||
|
xStream.alias("loadline", org.diylc.components.misc.LoadlineEntity.class);
|
||||||
|
return xStream;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showMessage(String message, String title, int messageType) {
|
public void showMessage(String message, String title, int messageType) {
|
||||||
@@ -519,15 +546,11 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
applyToLoadline();
|
applyToLoadline();
|
||||||
|
|
||||||
final File file = DialogFactory.getInstance().showSaveDialog(LoadlineEditorDialog.this,
|
final File file = DialogFactory.getInstance().showSaveDialog(LoadlineEditorFrame.this,
|
||||||
FileFilterEnum.CRV.getFilter(), null, FileFilterEnum.CRV.getExtensions()[0], null);
|
FileFilterEnum.CRV.getFilter(), null, FileFilterEnum.CRV.getExtensions()[0], null);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
XStream xStream = new XStream(new DomDriver("UTF-8"));
|
XStream xStream = loadlineXStream();
|
||||||
xStream.autodetectAnnotations(true);
|
|
||||||
xStream.alias("point", Point2D.Double.class);
|
|
||||||
xStream.alias("curve", org.diylc.components.misc.LoadlineEntity.Line.class);
|
|
||||||
xStream.alias("loadline", org.diylc.components.misc.LoadlineEntity.class);
|
|
||||||
|
|
||||||
FileOutputStream fos;
|
FileOutputStream fos;
|
||||||
fos = new FileOutputStream(file);
|
fos = new FileOutputStream(file);
|
||||||
@@ -557,6 +580,7 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
loadline = new LoadlineEntity();
|
loadline = new LoadlineEntity();
|
||||||
loadline.setMaxVoltage(300);
|
loadline.setMaxVoltage(300);
|
||||||
loadline.setMaxCurrent(5);
|
loadline.setMaxCurrent(5);
|
||||||
|
loadline.setName("New");
|
||||||
loadline.setLines(new ArrayList<LoadlineEntity.Line>());
|
loadline.setLines(new ArrayList<LoadlineEntity.Line>());
|
||||||
|
|
||||||
loadProject();
|
loadProject();
|
||||||
@@ -579,11 +603,7 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
FileFilterEnum.CRV.getExtensions()[0], null);
|
FileFilterEnum.CRV.getExtensions()[0], null);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
XStream xStream = new XStream(new DomDriver("UTF-8"));
|
XStream xStream = loadlineXStream();
|
||||||
xStream.autodetectAnnotations(true);
|
|
||||||
xStream.alias("point", Point2D.Double.class);
|
|
||||||
xStream.alias("curve", org.diylc.components.misc.LoadlineEntity.Line.class);
|
|
||||||
xStream.alias("loadline", org.diylc.components.misc.LoadlineEntity.class);
|
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
Reader reader = new InputStreamReader(fis, "UTF-8");
|
Reader reader = new InputStreamReader(fis, "UTF-8");
|
||||||
@@ -674,4 +694,20 @@ public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class LoadlineEditorAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public LoadlineEditorAction() {
|
||||||
|
super();
|
||||||
|
putValue(Action.NAME, "Loadline Editor");
|
||||||
|
// putValue(Action.SMALL_ICON, IconLoader.Delete.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
new LoadlineEditorFrame().setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,8 @@ import org.diylc.core.ExpansionMode;
|
|||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
import org.diylc.images.IconLoader;
|
import org.diylc.images.IconLoader;
|
||||||
import org.diylc.swing.ActionFactory;
|
import org.diylc.swing.ActionFactory;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
|
import org.diylc.swing.loadline.LoadlineEditorFrame;
|
||||||
|
|
||||||
public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
||||||
|
|
||||||
@@ -321,7 +322,8 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
swingUI.injectMenuAction(null, EDIT_TITLE);
|
swingUI.injectMenuAction(null, EDIT_TITLE);
|
||||||
swingUI.injectMenuAction(getFlexibleLeadsAction(), EDIT_TITLE);
|
swingUI.injectMenuAction(getFlexibleLeadsAction(), EDIT_TITLE);
|
||||||
swingUI.injectMenuAction(null, EDIT_TITLE);
|
swingUI.injectMenuAction(null, EDIT_TITLE);
|
||||||
swingUI.injectMenuAction(actionFactory.createEditProjectAction(plugInPort), EDIT_TITLE);
|
swingUI.injectMenuAction(actionFactory.createEditProjectAction(plugInPort), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(new LoadlineEditorFrame.LoadlineEditorAction(), EDIT_TITLE);
|
||||||
|
|
||||||
refreshActions();
|
refreshActions();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user