mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Loadline work
This commit is contained in:
@@ -48,6 +48,7 @@ import javax.swing.KeyStroke;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigListener;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.BuildingBlockPackage;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
@@ -421,7 +422,7 @@ public class ActionFactory {
|
||||
Set<PropertyWrapper> defaultedProperties) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}, InMemoryConfigurationManager.getInstance());
|
||||
putValue(AbstractAction.NAME, "Import");
|
||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I,
|
||||
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
||||
|
||||
@@ -59,6 +59,8 @@ import javax.swing.event.MenuListener;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.BadPositionException;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
@@ -117,11 +119,13 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
buttonGroupMap = new HashMap<String, ButtonGroup>();
|
||||
setIconImages(Arrays.asList(IconLoader.IconSmall.getImage(), IconLoader.IconMedium.getImage(),
|
||||
IconLoader.IconLarge.getImage()));
|
||||
DialogFactory.getInstance().initialize(this);
|
||||
DialogFactory.getInstance().initialize(this);
|
||||
|
||||
IConfigurationManager configManager = ConfigurationManager.getInstance();
|
||||
|
||||
this.presenter = new Presenter(this);
|
||||
this.presenter = new Presenter(this, configManager);
|
||||
|
||||
canvasPlugin = new CanvasPlugin(this);
|
||||
canvasPlugin = new CanvasPlugin(this, configManager);
|
||||
|
||||
presenter.installPlugin(new ToolBox(this));
|
||||
presenter.installPlugin(new FileMenuPlugin(this));
|
||||
|
||||
@@ -54,7 +54,8 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
@@ -112,7 +113,7 @@ public class TemplateDialog extends JDialog {
|
||||
public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}, InMemoryConfigurationManager.getInstance());
|
||||
// this.presenter.installPlugin(new IPlugIn() {
|
||||
//
|
||||
// @Override
|
||||
|
||||
@@ -29,6 +29,7 @@ import javax.swing.JLabel;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.components.misc.LoadlineEntity;
|
||||
import org.diylc.core.annotations.DynamicList;
|
||||
import org.diylc.core.annotations.MultiLineText;
|
||||
import org.diylc.core.measures.AbstractMeasure;
|
||||
@@ -99,6 +100,10 @@ public class FieldEditorFactory {
|
||||
if (Integer.class.isAssignableFrom(property.getType()) || int.class.isAssignableFrom(property.getType())) {
|
||||
IntEditor editor = new IntEditor(property);
|
||||
return editor;
|
||||
}
|
||||
if (LoadlineEntity.class.isAssignableFrom(property.getType())) {
|
||||
LoadlineEditor editor = new LoadlineEditor(property);
|
||||
return editor;
|
||||
}
|
||||
LOG.error("Unrecognized parameter type: " + property.getType().getName());
|
||||
return new JLabel("Unrecognized");
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.components.misc.LoadlineEntity;
|
||||
import org.diylc.swingframework.ButtonDialog;
|
||||
|
||||
public class LoadlineEditor extends JButton {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String title = "Click to edit";
|
||||
|
||||
private PropertyWrapper property;
|
||||
|
||||
public LoadlineEditor(final PropertyWrapper property) {
|
||||
super();
|
||||
this.property = property;
|
||||
|
||||
LoadlineEntity loadline = (LoadlineEntity) property.getValue();
|
||||
|
||||
String name = (loadline == null ? "<empty>" : loadline.getName()) + " ";
|
||||
|
||||
setText(property.isUnique() ? (name + title ): ("(multi value) " + title));
|
||||
setOpaque(true);
|
||||
setHorizontalAlignment(SwingConstants.CENTER);
|
||||
setBorder(BorderFactory.createEtchedBorder());
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
LoadlineEditorDialog dialog = new LoadlineEditorDialog(null, "Edit Loadline", loadline);
|
||||
dialog.setVisible(true);
|
||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption()))
|
||||
{
|
||||
property.setChanged(true);
|
||||
// property.setValue(newColor);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (property.isReadOnly()) {
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.Utils;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractCurvedComponent.PointCount;
|
||||
import org.diylc.components.connectivity.CurvedTrace;
|
||||
import org.diylc.components.connectivity.Dot;
|
||||
import org.diylc.components.connectivity.Line;
|
||||
import org.diylc.components.misc.Label;
|
||||
import org.diylc.components.misc.LoadlineEntity;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.measures.Current;
|
||||
import org.diylc.core.measures.CurrentUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.core.measures.Voltage;
|
||||
import org.diylc.core.measures.VoltageUnit;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.plugins.canvas.CanvasPanel;
|
||||
import org.diylc.swingframework.ButtonDialog;
|
||||
import org.diylc.swingframework.DoubleTextField;
|
||||
|
||||
public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final String AXIS_LABEL = "AXIS_LABEL";
|
||||
private LoadlineEntity loadline;
|
||||
private JPanel panel;
|
||||
private JPanel toolbar;
|
||||
private JPanel controlPanel;
|
||||
private CanvasPanel canvasPanel;
|
||||
private Presenter plugInPort;
|
||||
private IConfigurationManager configManager;
|
||||
|
||||
private static int[] INCREMENTS = new int[] {100, 50, 20, 10, 5, 1};
|
||||
private int xIncrement;
|
||||
private int yIncrement;
|
||||
|
||||
public LoadlineEditorDialog(JFrame owner, String title, LoadlineEntity loadline) {
|
||||
super(owner, title, new String[] {ButtonDialog.OK, ButtonDialog.CANCEL});
|
||||
|
||||
if (loadline == null) {
|
||||
loadline = new LoadlineEntity();
|
||||
loadline.setMaxVoltage(new Voltage(300d, VoltageUnit.V));
|
||||
loadline.setMaxCurrent(new Current(5d, CurrentUnit.mA));
|
||||
}
|
||||
|
||||
configManager = new InMemoryConfigurationManager(new HashMap<String, Object>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put(IPlugInPort.LOCKED_ALPHA, false);
|
||||
put(IPlugInPort.EXTRA_SPACE_KEY, false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.loadline = loadline;
|
||||
this.plugInPort = new Presenter(this, configManager);
|
||||
this.plugInPort.installPlugin(new IPlugIn() {
|
||||
|
||||
@Override
|
||||
public void processMessage(EventType type, Object... params) {
|
||||
switch (type) {
|
||||
case REPAINT:
|
||||
getCanvasPanel().repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return EnumSet.of(EventType.REPAINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {}
|
||||
});
|
||||
initializeProject();
|
||||
updateAxis();
|
||||
|
||||
layoutGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent getMainComponent() {
|
||||
if (panel == null) {
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.add(getToolbar(), BorderLayout.NORTH);
|
||||
panel.add(getCanvasPanel(), BorderLayout.CENTER);
|
||||
panel.add(getControlPanel(), BorderLayout.SOUTH);
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
public JPanel getToolbar() {
|
||||
if (toolbar == null) {
|
||||
toolbar = new JPanel();
|
||||
toolbar.add(new JButton(new LoadAction()));
|
||||
toolbar.add(new JButton(new SaveAction()));
|
||||
toolbar.add(new JButton(new LoadImageAction()));
|
||||
toolbar.add(new JButton(new AddCurveAction()));
|
||||
}
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
public CanvasPanel getCanvasPanel() {
|
||||
if (canvasPanel == null) {
|
||||
// create canvas panel that doesn't render locked components in lower alpha
|
||||
canvasPanel = new CanvasPanel(plugInPort, configManager);
|
||||
canvasPanel.setPreferredSize(plugInPort.getCanvasDimensions(true, false));
|
||||
|
||||
canvasPanel.addMouseMotionListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
||||
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
|
||||
e.isShiftDown(), e.isAltDown());
|
||||
}
|
||||
});
|
||||
}
|
||||
return canvasPanel;
|
||||
}
|
||||
|
||||
public JPanel getControlPanel() {
|
||||
if (controlPanel == null) {
|
||||
controlPanel = new JPanel();
|
||||
|
||||
|
||||
controlPanel.add(new JLabel("Max Voltage (V): "));
|
||||
JTextField vEditor = new DoubleTextField();
|
||||
vEditor.setColumns(8);
|
||||
controlPanel.add(vEditor);
|
||||
|
||||
controlPanel.add(new JLabel("Max Current (mA): "));
|
||||
JTextField iEditor = new DoubleTextField();
|
||||
iEditor.setColumns(8);
|
||||
controlPanel.add(iEditor);
|
||||
|
||||
controlPanel.add(new JLabel("Max Dissipation (W): "));
|
||||
JTextField dEditor = new DoubleTextField();
|
||||
dEditor.setColumns(8);
|
||||
controlPanel.add(dEditor);
|
||||
|
||||
JButton updateButton = new JButton("Update");
|
||||
controlPanel.add(updateButton);
|
||||
|
||||
}
|
||||
return controlPanel;
|
||||
}
|
||||
|
||||
|
||||
private void initializeProject() {
|
||||
Project project = new Project();
|
||||
project.setWidth(new Size(5d, SizeUnit.in));
|
||||
project.setHeight(new Size(3d, SizeUnit.in));
|
||||
project.setGridSpacing(new Size(0.05d, SizeUnit.in));
|
||||
|
||||
double spacing = project.getGridSpacing().convertToPixels();
|
||||
|
||||
int centerX = (int) (spacing * 3);
|
||||
int centerY = (int) (project.getHeight().convertToPixels() - spacing * 3);
|
||||
|
||||
// setup coordinate system
|
||||
Line y = new Line();
|
||||
y.setControlPoint(new Point(centerX, (int) (spacing * 2)), 0);
|
||||
y.setControlPoint(new Point(centerX, centerY), 1);
|
||||
y.setArrowStart(true);
|
||||
y.setThickness(new Size(2d, SizeUnit.px));
|
||||
project.getComponents().add(y);
|
||||
project.getLockedComponents().add(y);
|
||||
|
||||
Label yLabel = new Label();
|
||||
yLabel.setValue("I(ma)");
|
||||
yLabel.setControlPoint(new Point((int) (centerX + spacing), (int) (spacing * 5)), 0);
|
||||
yLabel.setHorizontalAlignment(HorizontalAlignment.LEFT);
|
||||
yLabel.setVerticalAlignment(VerticalAlignment.TOP);
|
||||
yLabel.setBold(true);
|
||||
project.getComponents().add(yLabel);
|
||||
project.getLockedComponents().add(yLabel);
|
||||
|
||||
Line x = new Line();
|
||||
x.setControlPoint(new Point(centerX, centerY), 0);
|
||||
x.setControlPoint(
|
||||
new Point((int) (project.getWidth().convertToPixels() - spacing * 2), centerY), 1);
|
||||
x.setArrowEnd(true);
|
||||
x.setThickness(new Size(2d, SizeUnit.px));
|
||||
project.getComponents().add(x);
|
||||
project.getLockedComponents().add(x);
|
||||
|
||||
Label xLabel = new Label();
|
||||
xLabel.setValue("U(V)");
|
||||
xLabel.setControlPoint(new Point((int) (project.getWidth().convertToPixels() - spacing * 4),
|
||||
(int) (centerY - spacing)), 0);
|
||||
xLabel.setHorizontalAlignment(HorizontalAlignment.RIGHT);
|
||||
xLabel.setVerticalAlignment(VerticalAlignment.TOP);
|
||||
xLabel.setBold(true);
|
||||
project.getComponents().add(xLabel);
|
||||
project.getLockedComponents().add(xLabel);
|
||||
|
||||
Dot dot = new Dot();
|
||||
dot.setControlPoint(new Point(centerX, centerY), 0);
|
||||
project.getComponents().add(dot);
|
||||
project.getLockedComponents().add(dot);
|
||||
|
||||
plugInPort.loadProject(project, true, "n/a");
|
||||
}
|
||||
|
||||
private void updateAxis() {
|
||||
int v = loadline.getMaxVoltage().getValue().intValue();
|
||||
int i = loadline.getMaxCurrent().getValue().intValue();
|
||||
|
||||
for (int j = 0; j < INCREMENTS.length; j++) {
|
||||
int increment = INCREMENTS[j];
|
||||
if (v % increment == 0 && v / increment >= 5) {
|
||||
xIncrement = increment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < INCREMENTS.length; j++) {
|
||||
int increment = INCREMENTS[j];
|
||||
if (i % increment == 0 && i / increment >= 5) {
|
||||
yIncrement = increment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// delete old axis components
|
||||
plugInPort.selectMatching(AXIS_LABEL);
|
||||
plugInPort.deleteSelectedComponents();
|
||||
|
||||
Project project = plugInPort.getCurrentProject();
|
||||
|
||||
double spacing = project.getGridSpacing().convertToPixels();
|
||||
int centerX = (int) (spacing * 3);
|
||||
int centerY = (int) (project.getHeight().convertToPixels() - spacing * 3);
|
||||
int maxX = (int) (project.getWidth().convertToPixels() - spacing * 4);
|
||||
int maxY = (int) (spacing * 5);
|
||||
|
||||
for (int j = xIncrement; j <= v; j += xIncrement) {
|
||||
Line tick = new Line();
|
||||
tick.setName(AXIS_LABEL);
|
||||
double offset = 1.0 * (maxX - centerX) * (1.0 * j / v);
|
||||
tick.setControlPoint(new Point((int) (centerX + offset), centerY), 0);
|
||||
tick.setControlPoint(new Point((int) (centerX + offset), (int) (centerY + spacing / 2)), 1);
|
||||
tick.setThickness(new Size(1d, SizeUnit.px));
|
||||
project.getComponents().add(tick);
|
||||
project.getLockedComponents().add(tick);
|
||||
|
||||
Label xLabel = new Label();
|
||||
xLabel.setValue(String.valueOf(j));
|
||||
xLabel.setControlPoint(new Point((int) (centerX + offset), (int) (centerY + spacing / 2 + 1)),
|
||||
0);
|
||||
xLabel.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
xLabel.setVerticalAlignment(VerticalAlignment.BOTTOM);
|
||||
// xLabel.setFontSize((int) (xLabel.getFontSize() * 0.8));
|
||||
project.getComponents().add(xLabel);
|
||||
project.getLockedComponents().add(xLabel);
|
||||
}
|
||||
|
||||
for (int j = yIncrement; j <= i; j += yIncrement) {
|
||||
Line tick = new Line();
|
||||
tick.setName(AXIS_LABEL);
|
||||
double offset = 1.0 * (maxY - centerY) * (1.0 * j / i);
|
||||
tick.setControlPoint(new Point(centerX, (int) (centerY + offset)), 0);
|
||||
tick.setControlPoint(new Point((int) (centerX - spacing / 2), (int) (centerY + offset)), 1);
|
||||
tick.setThickness(new Size(1d, SizeUnit.px));
|
||||
project.getComponents().add(tick);
|
||||
project.getLockedComponents().add(tick);
|
||||
|
||||
Label yLabel = new Label();
|
||||
yLabel.setValue(String.valueOf(j));
|
||||
yLabel.setControlPoint(new Point((int) (centerX - spacing / 2 - 1), (int) (centerY + offset)),
|
||||
0);
|
||||
yLabel.setHorizontalAlignment(HorizontalAlignment.RIGHT);
|
||||
yLabel.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
// yLabel.setFontSize((int) (yLabel.getFontSize() * 0.8));
|
||||
project.getComponents().add(yLabel);
|
||||
project.getLockedComponents().add(yLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void addCurve() {
|
||||
Project project = plugInPort.getCurrentProject();
|
||||
double spacing = project.getGridSpacing().convertToPixels();
|
||||
|
||||
int centerX = (int) (spacing * 3);
|
||||
int centerY = (int) (project.getHeight().convertToPixels() - spacing * 3);
|
||||
|
||||
CurvedTrace t = new CurvedTrace();
|
||||
t.setPointCount(PointCount.FOUR);
|
||||
t.setControlPoint(new Point(centerX, centerY), 0);
|
||||
t.setControlPoint(new Point((int) (centerX + 30 * spacing), (int) (centerY - 10 * spacing)), 1);
|
||||
t.setControlPoint(new Point((int) (centerX + 50 * spacing), (int) (centerY - 20 * spacing)), 2);
|
||||
t.setControlPoint(new Point((int) (centerX + 70 * spacing), (int) (centerY - 50 * spacing)), 3);
|
||||
t.setThickness(new Size(2d, SizeUnit.px));
|
||||
t.setLeadColor(Color.blue);
|
||||
project.getComponents().add(t);
|
||||
|
||||
plugInPort.loadProject(plugInPort.getCurrentProject(), false, "n/a");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(String message, String title, int messageType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int showConfirmDialog(String message, String title, int optionType, int messageType) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean editProperties(List<PropertyWrapper> properties,
|
||||
Set<PropertyWrapper> defaultedProperties) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String showInputDialog(String message, String title) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File promptFileSave() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
class SaveAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SaveAction() {
|
||||
super();
|
||||
putValue(Action.NAME, "Save To File");
|
||||
putValue(Action.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {}
|
||||
}
|
||||
|
||||
class LoadAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public LoadAction() {
|
||||
super();
|
||||
putValue(Action.NAME, "Load From File");
|
||||
putValue(Action.SMALL_ICON, IconLoader.FolderOut.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {}
|
||||
}
|
||||
|
||||
class AddCurveAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public AddCurveAction() {
|
||||
super();
|
||||
putValue(Action.NAME, "Add a Curve");
|
||||
// putValue(Action.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
addCurve();
|
||||
}
|
||||
}
|
||||
|
||||
class LoadImageAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public LoadImageAction() {
|
||||
super();
|
||||
putValue(Action.NAME, "Insert Image");
|
||||
putValue(Action.SMALL_ICON, IconLoader.Image.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,23 @@
|
||||
/*
|
||||
*
|
||||
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
*
|
||||
* This file is part of DIYLC.
|
||||
*
|
||||
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
@@ -52,164 +49,175 @@ import javax.swing.KeyStroke;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IBlockProcessor.InvalidBlockException;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.swing.plugins.tree.TreePanel;
|
||||
|
||||
/**
|
||||
* GUI class used to draw onto.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* GUI class used to draw onto.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CanvasPlugin.class);
|
||||
|
||||
public static boolean RENDER_VISIBLE_RECT_ONLY = true;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
|
||||
private Image bufferImage;
|
||||
private GraphicsConfiguration screenGraphicsConfiguration;
|
||||
|
||||
public boolean useHardwareAcceleration = ConfigurationManager.getInstance().readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
|
||||
// static final EnumSet<DrawOption> DRAW_OPTIONS =
|
||||
// EnumSet.of(DrawOption.GRID,
|
||||
// DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
|
||||
// static final EnumSet<DrawOption> DRAW_OPTIONS_ANTI_ALIASING =
|
||||
// EnumSet.of(DrawOption.GRID,
|
||||
// DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
|
||||
// DrawOption.CONTROL_POINTS);
|
||||
|
||||
private HashMap<String, ComponentType> componentTypeCache;
|
||||
|
||||
public CanvasPanel(IPlugInPort plugInPort) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
setFocusable(true);
|
||||
initializeListeners();
|
||||
initializeDnD();
|
||||
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
|
||||
screenGraphicsConfiguration = devices[0].getDefaultConfiguration();
|
||||
|
||||
initializeActions();
|
||||
}
|
||||
|
||||
public void invalidateCache() {
|
||||
bufferImage = null;
|
||||
}
|
||||
|
||||
public HashMap<String, ComponentType> getComponentTypeCache() {
|
||||
if (componentTypeCache == null) {
|
||||
componentTypeCache = new HashMap<String, ComponentType>();
|
||||
for (Entry<String, List<ComponentType>> entry : this.plugInPort.getComponentTypes().entrySet()) {
|
||||
for (ComponentType type : entry.getValue())
|
||||
componentTypeCache.put(type.getInstanceClass().getCanonicalName(), type);
|
||||
}
|
||||
}
|
||||
return componentTypeCache;
|
||||
}
|
||||
|
||||
private void initializeDnD() {
|
||||
// Initialize drag source recognizer.
|
||||
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
|
||||
DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK, new CanvasGestureListener(plugInPort));
|
||||
// Initialize drop target.
|
||||
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new CanvasTargetListener(plugInPort), true);
|
||||
}
|
||||
|
||||
private void initializeActions() {
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_QUOTE, 0), "repeatLast");
|
||||
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "clearSlot");
|
||||
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
final int x = i;
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1 + i - 1, 0),
|
||||
"functionKey" + i);
|
||||
getActionMap().put("functionKey" + i, new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
functionKeyPressed(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getActionMap().put("clearSlot", new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(null, null, false);
|
||||
}
|
||||
});
|
||||
|
||||
getActionMap().put("repeatLast", new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<String> recent =
|
||||
(List<String>) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY, null);
|
||||
if (recent != null && !recent.isEmpty()) {
|
||||
String clazz = recent.get(0);
|
||||
Map<String, List<ComponentType>> componentTypes = CanvasPanel.this.plugInPort.getComponentTypes();
|
||||
for (Map.Entry<String, List<ComponentType>> entry : componentTypes.entrySet()) {
|
||||
for (ComponentType type : entry.getValue()) {
|
||||
if (type.getInstanceClass().getCanonicalName().equals(clazz)) {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(type, null, false);
|
||||
// hack: fake mouse movement to repaint
|
||||
CanvasPanel.this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void functionKeyPressed(int i) {
|
||||
HashMap<String, String> shortcutMap =
|
||||
(HashMap<String, String>) ConfigurationManager.getInstance().readObject(TreePanel.COMPONENT_SHORTCUT_KEY, null);
|
||||
if (shortcutMap == null)
|
||||
return;
|
||||
String typeName = shortcutMap.get("F" + i);
|
||||
if (typeName == null)
|
||||
return;
|
||||
if (typeName.startsWith("block:")) {
|
||||
String blockName = typeName.substring(6);
|
||||
try {
|
||||
plugInPort.loadBlock(blockName);
|
||||
} catch (InvalidBlockException e) {
|
||||
LOG.error("Could not find block assigned to shortcut: " + blockName);
|
||||
}
|
||||
} else {
|
||||
ComponentType type = getComponentTypeCache().get(typeName);
|
||||
if (type == null) {
|
||||
LOG.error("Could not find type: " + typeName);
|
||||
return;
|
||||
}
|
||||
this.plugInPort.setNewComponentTypeSlot(type, null, false);
|
||||
}
|
||||
|
||||
// hack: fake mouse movement to repaint
|
||||
this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
}
|
||||
|
||||
|
||||
public static boolean RENDER_VISIBLE_RECT_ONLY = true;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
|
||||
private Image bufferImage;
|
||||
private GraphicsConfiguration screenGraphicsConfiguration;
|
||||
|
||||
public boolean useHardwareAcceleration;
|
||||
|
||||
// static final EnumSet<DrawOption> DRAW_OPTIONS =
|
||||
// EnumSet.of(DrawOption.GRID,
|
||||
// DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
|
||||
// static final EnumSet<DrawOption> DRAW_OPTIONS_ANTI_ALIASING =
|
||||
// EnumSet.of(DrawOption.GRID,
|
||||
// DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
|
||||
// DrawOption.CONTROL_POINTS);
|
||||
|
||||
private HashMap<String, ComponentType> componentTypeCache;
|
||||
|
||||
private IConfigurationManager configManager;
|
||||
|
||||
public CanvasPanel(IPlugInPort plugInPort, IConfigurationManager configManager) {
|
||||
this.plugInPort = plugInPort;
|
||||
this.configManager = configManager;
|
||||
|
||||
this.useHardwareAcceleration =
|
||||
configManager.readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
setFocusable(true);
|
||||
initializeListeners();
|
||||
initializeDnD();
|
||||
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
|
||||
screenGraphicsConfiguration = devices[0].getDefaultConfiguration();
|
||||
|
||||
initializeActions();
|
||||
}
|
||||
|
||||
public void invalidateCache() {
|
||||
bufferImage = null;
|
||||
}
|
||||
|
||||
public HashMap<String, ComponentType> getComponentTypeCache() {
|
||||
if (componentTypeCache == null) {
|
||||
componentTypeCache = new HashMap<String, ComponentType>();
|
||||
for (Entry<String, List<ComponentType>> entry : this.plugInPort.getComponentTypes()
|
||||
.entrySet()) {
|
||||
for (ComponentType type : entry.getValue())
|
||||
componentTypeCache.put(type.getInstanceClass().getCanonicalName(), type);
|
||||
}
|
||||
}
|
||||
return componentTypeCache;
|
||||
}
|
||||
|
||||
private void initializeDnD() {
|
||||
// Initialize drag source recognizer.
|
||||
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
|
||||
DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK,
|
||||
new CanvasGestureListener(plugInPort));
|
||||
// Initialize drop target.
|
||||
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new CanvasTargetListener(plugInPort),
|
||||
true);
|
||||
}
|
||||
|
||||
private void initializeActions() {
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_QUOTE, 0), "repeatLast");
|
||||
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "clearSlot");
|
||||
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
final int x = i;
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_F1 + i - 1, 0), "functionKey" + i);
|
||||
getActionMap().put("functionKey" + i, new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
functionKeyPressed(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getActionMap().put("clearSlot", new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(null, null, false);
|
||||
}
|
||||
});
|
||||
|
||||
getActionMap().put("repeatLast", new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<String> recent = (List<String>) configManager
|
||||
.readObject(IPlugInPort.RECENT_COMPONENTS_KEY, null);
|
||||
if (recent != null && !recent.isEmpty()) {
|
||||
String clazz = recent.get(0);
|
||||
Map<String, List<ComponentType>> componentTypes =
|
||||
CanvasPanel.this.plugInPort.getComponentTypes();
|
||||
for (Map.Entry<String, List<ComponentType>> entry : componentTypes.entrySet()) {
|
||||
for (ComponentType type : entry.getValue()) {
|
||||
if (type.getInstanceClass().getCanonicalName().equals(clazz)) {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(type, null, false);
|
||||
// hack: fake mouse movement to repaint
|
||||
CanvasPanel.this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void functionKeyPressed(int i) {
|
||||
HashMap<String, String> shortcutMap = (HashMap<String, String>) configManager.readObject(TreePanel.COMPONENT_SHORTCUT_KEY, null);
|
||||
if (shortcutMap == null)
|
||||
return;
|
||||
String typeName = shortcutMap.get("F" + i);
|
||||
if (typeName == null)
|
||||
return;
|
||||
if (typeName.startsWith("block:")) {
|
||||
String blockName = typeName.substring(6);
|
||||
try {
|
||||
plugInPort.loadBlock(blockName);
|
||||
} catch (InvalidBlockException e) {
|
||||
LOG.error("Could not find block assigned to shortcut: " + blockName);
|
||||
}
|
||||
} else {
|
||||
ComponentType type = getComponentTypeCache().get(typeName);
|
||||
if (type == null) {
|
||||
LOG.error("Could not find type: " + typeName);
|
||||
return;
|
||||
}
|
||||
this.plugInPort.setNewComponentTypeSlot(type, null, false);
|
||||
}
|
||||
|
||||
// hack: fake mouse movement to repaint
|
||||
this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
}
|
||||
|
||||
protected void createBufferImage() {
|
||||
int imageWidth;
|
||||
int imageHeight;
|
||||
@@ -221,126 +229,135 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
imageWidth = getWidth();
|
||||
imageHeight = getHeight();
|
||||
}
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(imageWidth, imageHeight);
|
||||
((VolatileImage) bufferImage).validate(screenGraphicsConfiguration);
|
||||
} else {
|
||||
bufferImage = createImage(imageWidth, imageHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
if (plugInPort == null) {
|
||||
return;
|
||||
}
|
||||
if (bufferImage == null) {
|
||||
createBufferImage();
|
||||
}
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
bufferImage =
|
||||
screenGraphicsConfiguration.createCompatibleVolatileImage(imageWidth, imageHeight);
|
||||
((VolatileImage) bufferImage).validate(screenGraphicsConfiguration);
|
||||
} else {
|
||||
bufferImage = createImage(imageWidth, imageHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
if (plugInPort == null) {
|
||||
return;
|
||||
}
|
||||
if (bufferImage == null) {
|
||||
createBufferImage();
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||
|
||||
|
||||
Rectangle visibleRect = getVisibleRect();
|
||||
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
if (RENDER_VISIBLE_RECT_ONLY) {
|
||||
|
||||
if (RENDER_VISIBLE_RECT_ONLY) {
|
||||
x = visibleRect.x;
|
||||
y = visibleRect.y;
|
||||
g2d.translate(-x, -y);
|
||||
} else {
|
||||
} else {
|
||||
g2d.setClip(visibleRect);
|
||||
}
|
||||
|
||||
Set<DrawOption> drawOptions = EnumSet.of(DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.ANTI_ALIASING_KEY, true)) {
|
||||
drawOptions.add(DrawOption.ANTIALIASING);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
|
||||
drawOptions.add(DrawOption.OUTLINE_MODE);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_GRID_KEY, true)) {
|
||||
drawOptions.add(DrawOption.GRID);
|
||||
|
||||
|
||||
Set<DrawOption> drawOptions = EnumSet.of(DrawOption.SELECTION, DrawOption.ZOOM,
|
||||
DrawOption.CONTROL_POINTS);
|
||||
|
||||
if (configManager.readBoolean(IPlugInPort.ANTI_ALIASING_KEY, true)) {
|
||||
drawOptions.add(DrawOption.ANTIALIASING);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true)) {
|
||||
if (configManager.readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
|
||||
drawOptions.add(DrawOption.OUTLINE_MODE);
|
||||
}
|
||||
if (configManager.readBoolean(IPlugInPort.SHOW_GRID_KEY, true)) {
|
||||
drawOptions.add(DrawOption.GRID);
|
||||
}
|
||||
if (configManager.readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true)) {
|
||||
drawOptions.add(DrawOption.EXTRA_SPACE);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.CACHING_ENABLED_KEY, true)) {
|
||||
if (configManager.readBoolean(IPlugInPort.CACHING_ENABLED_KEY, true)) {
|
||||
drawOptions.add(DrawOption.ENABLE_CACHING);
|
||||
}
|
||||
|
||||
}
|
||||
if (configManager.readBoolean(IPlugInPort.LOCKED_ALPHA, true)) {
|
||||
drawOptions.add(DrawOption.LOCKED_ALPHA);
|
||||
}
|
||||
|
||||
plugInPort.draw(g2d, drawOptions, null, null, visibleRect);
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
||||
do {
|
||||
try {
|
||||
if (volatileImage.contentsLost()) {
|
||||
createBufferImage();
|
||||
}
|
||||
// int validation =
|
||||
// volatileImage.validate(screenGraphicsConfiguration);
|
||||
// if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
// createBufferImage();
|
||||
// }
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
} catch (NullPointerException e) {
|
||||
createBufferImage();
|
||||
}
|
||||
} while (volatileImage == null || volatileImage.contentsLost());
|
||||
} else {
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
// bufferImage.flush();
|
||||
}
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
private void initializeListeners() {
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
invalidateCache();
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
// addKeyListener(new KeyAdapter() {
|
||||
//
|
||||
// @Override
|
||||
// public void keyPressed(KeyEvent e) {
|
||||
// if (e.getKeyCode() == KeyEvent.VK_DELETE) {
|
||||
// plugInPort.deleteSelectedComponents();
|
||||
// }
|
||||
// // plugInPort.mouseMoved(getMousePosition(), e.isControlDown(),
|
||||
// // e.isShiftDown(), e
|
||||
// // .isAltDown());
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
// Autoscroll
|
||||
|
||||
private int autoScrollSize = 64;
|
||||
|
||||
@Override
|
||||
public void autoscroll(Point cursorLocn) {
|
||||
scrollRectToVisible(new Rectangle(cursorLocn.x - autoScrollSize, cursorLocn.y - autoScrollSize, autoScrollSize * 2, autoScrollSize * 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getAutoscrollInsets() {
|
||||
Rectangle rect = getVisibleRect();
|
||||
return new Insets(rect.y - autoScrollSize, rect.x - autoScrollSize, rect.y + rect.height + autoScrollSize, rect.x + rect.width + autoScrollSize);
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
||||
do {
|
||||
try {
|
||||
if (volatileImage.contentsLost()) {
|
||||
createBufferImage();
|
||||
}
|
||||
// int validation =
|
||||
// volatileImage.validate(screenGraphicsConfiguration);
|
||||
// if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
// createBufferImage();
|
||||
// }
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
} catch (NullPointerException e) {
|
||||
createBufferImage();
|
||||
}
|
||||
} while (volatileImage == null || volatileImage.contentsLost());
|
||||
} else {
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
// bufferImage.flush();
|
||||
}
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
private void initializeListeners() {
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
invalidateCache();
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
// addKeyListener(new KeyAdapter() {
|
||||
//
|
||||
// @Override
|
||||
// public void keyPressed(KeyEvent e) {
|
||||
// if (e.getKeyCode() == KeyEvent.VK_DELETE) {
|
||||
// plugInPort.deleteSelectedComponents();
|
||||
// }
|
||||
// // plugInPort.mouseMoved(getMousePosition(), e.isControlDown(),
|
||||
// // e.isShiftDown(), e
|
||||
// // .isAltDown());
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
// Autoscroll
|
||||
|
||||
private int autoScrollSize = 64;
|
||||
|
||||
@Override
|
||||
public void autoscroll(Point cursorLocn) {
|
||||
scrollRectToVisible(new Rectangle(cursorLocn.x - autoScrollSize, cursorLocn.y - autoScrollSize,
|
||||
autoScrollSize * 2, autoScrollSize * 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getAutoscrollInsets() {
|
||||
Rectangle rect = getVisibleRect();
|
||||
return new Insets(rect.y - autoScrollSize, rect.x - autoScrollSize,
|
||||
rect.y + rect.height + autoScrollSize, rect.x + rect.width + autoScrollSize);
|
||||
}
|
||||
|
||||
public void setUseHardwareAcceleration(boolean useHardwareAcceleration) {
|
||||
this.useHardwareAcceleration = useHardwareAcceleration;
|
||||
bufferImage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import javax.swing.SwingUtilities;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigListener;
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.Utils;
|
||||
import org.diylc.common.BadPositionException;
|
||||
import org.diylc.common.EventType;
|
||||
@@ -115,8 +116,11 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private double zoomLevel = 1;
|
||||
|
||||
public CanvasPlugin(ISwingUI swingUI) {
|
||||
private IConfigurationManager configManager;
|
||||
|
||||
public CanvasPlugin(ISwingUI swingUI, IConfigurationManager configManager) {
|
||||
this.swingUI = swingUI;
|
||||
this.configManager = configManager;
|
||||
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
}
|
||||
|
||||
@@ -145,7 +149,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
|
||||
getScrollPane().setRulerVisible(
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true));
|
||||
configManager.readBoolean(IPlugInPort.SHOW_RULERS_KEY, true));
|
||||
|
||||
// revalidate canvas on scrolling when we render visible rect only
|
||||
if (CanvasPanel.RENDER_VISIBLE_RECT_ONLY) {
|
||||
@@ -168,7 +172,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
});
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.SHOW_RULERS_KEY,
|
||||
configManager.addConfigListener(IPlugInPort.SHOW_RULERS_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -178,7 +182,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.HARDWARE_ACCELERATION,
|
||||
configManager.addConfigListener(IPlugInPort.HARDWARE_ACCELERATION,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -188,7 +192,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.METRIC_KEY,
|
||||
configManager.addConfigListener(IPlugInPort.METRIC_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -197,7 +201,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.EXTRA_SPACE_KEY,
|
||||
configManager.addConfigListener(IPlugInPort.EXTRA_SPACE_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -214,7 +218,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RULER_IN_SUBDIVISION_KEY,
|
||||
configManager.addConfigListener(IPlugInPort.RULER_IN_SUBDIVISION_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -225,7 +229,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA,
|
||||
configManager.addConfigListener(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -239,7 +243,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
public CanvasPanel getCanvasPanel() {
|
||||
if (canvasPanel == null) {
|
||||
canvasPanel = new CanvasPanel(plugInPort);
|
||||
canvasPanel = new CanvasPanel(plugInPort, configManager);
|
||||
canvasPanel.addMouseListener(new MouseAdapter() {
|
||||
|
||||
private MouseEvent pressedEvent;
|
||||
@@ -336,7 +340,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private RulerScrollPane getScrollPane() {
|
||||
if (scrollPane == null) {
|
||||
String subdivision = ConfigurationManager.getInstance().readString(
|
||||
String subdivision = configManager.readString(
|
||||
IPlugInPort.RULER_IN_SUBDIVISION_KEY, IPlugInPort.RULER_IN_SUBDIVISION_DEFAULT);
|
||||
|
||||
scrollPane = new RulerScrollPane(getCanvasPanel(),
|
||||
@@ -345,10 +349,10 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
IPlugInPort.RULER_IN_SUBDIVISION_10.equalsIgnoreCase(subdivision)
|
||||
? InchSubdivision.BASE_10
|
||||
: InchSubdivision.BASE_2);
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(IPlugInPort.METRIC_KEY, true);
|
||||
boolean metric = configManager.readBoolean(IPlugInPort.METRIC_KEY, true);
|
||||
|
||||
boolean useHardwareAcceleration =
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
configManager.readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
scrollPane.setUseHardwareAcceleration(useHardwareAcceleration);
|
||||
scrollPane.setMetric(metric);
|
||||
scrollPane.setWheelScrollingEnabled(true);
|
||||
@@ -374,7 +378,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
|
||||
|
||||
boolean wheelZoom =
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
|
||||
configManager.readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
|
||||
|
||||
if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) {
|
||||
|
||||
@@ -817,7 +821,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true))
|
||||
if (configManager.readBoolean(IPlugInPort.SHOW_RULERS_KEY, true))
|
||||
scrollPane.setSelectionRectangle(plugInPort.getSelectionBounds(true));
|
||||
}
|
||||
});
|
||||
@@ -838,7 +842,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private void refreshSize() {
|
||||
Dimension d = plugInPort.getCanvasDimensions(true,
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true));
|
||||
configManager.readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true));
|
||||
canvasPanel.setSize(d);
|
||||
canvasPanel.setPreferredSize(d);
|
||||
getScrollPane().setZoomLevel(plugInPort.getZoomLevel());
|
||||
|
||||
@@ -31,7 +31,8 @@ import java.util.ListIterator;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.AbstractAction;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
@@ -80,7 +81,7 @@ public class CloudPlugIn implements IPlugIn {
|
||||
super();
|
||||
|
||||
this.swingUI = swingUI;
|
||||
this.thumbnailPresenter = new Presenter(new DummyView());
|
||||
this.thumbnailPresenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||
|
||||
swingUI.injectMenuAction(getLibraryAction(), ONLINE_TITLE);
|
||||
swingUI.injectMenuAction(null, ONLINE_TITLE);
|
||||
|
||||
+3
-2
@@ -54,7 +54,8 @@ import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ITask;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
@@ -402,7 +403,7 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
+ project.getName()
|
||||
+ "\" with a new file?\nThis opperation is irreversible. Once replaced, the old version of the project cannot be restored.",
|
||||
"Replace Project", IView.YES_NO_OPTION, IView.QUESTION_MESSAGE) == IView.YES_OPTION) {
|
||||
final Presenter thumbnailPresenter = new Presenter(new DummyView());
|
||||
final Presenter thumbnailPresenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||
final File file =
|
||||
DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(), null,
|
||||
FileFilterEnum.DIY.getExtensions()[0], null, cloudUI.getOwnerFrame());
|
||||
|
||||
@@ -35,8 +35,9 @@ import java.util.EnumSet;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.core.Project;
|
||||
@@ -68,7 +69,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
||||
super();
|
||||
|
||||
setPreferredSize(new Dimension(140, 128));
|
||||
presenter = new Presenter(new DummyView());
|
||||
presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||
xStream = new XStream(new DomDriver());
|
||||
|
||||
emptyProject = new Project();
|
||||
|
||||
@@ -28,7 +28,8 @@ import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.diylc.DIYLCStarter;
|
||||
import org.diylc.DIYLCStarter;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.gui.DummyView;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class BatchConverter {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
Presenter presenter = new Presenter(new DummyView());
|
||||
Presenter presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||
for (File file : matchingFiles) {
|
||||
if (file.getName() != "" && file.getName() != "." && file.getName() != ".." && !file.isDirectory())
|
||||
presenter.loadProjectFromFile(file.getAbsolutePath());
|
||||
|
||||
Reference in New Issue
Block a user