mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
added image component
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
<map>
|
<map>
|
||||||
<entry>
|
<entry>
|
||||||
<string>lastPath</string>
|
<string>metric</string>
|
||||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
<boolean>true</boolean>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>zoom</string>
|
<string>zoom</string>
|
||||||
<double>1.0</double>
|
<double>1.0</double>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>metric</string>
|
<string>lastPath</string>
|
||||||
<boolean>true</boolean>
|
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<string>default.org.diylc.components.misc.Label:Color</string>
|
<string>default.org.diylc.components.misc.Label:Color</string>
|
||||||
|
|||||||
Binary file not shown.
+3
-2
@@ -492,8 +492,9 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
|
public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
|
||||||
// FIXME: map
|
boolean result = canvasGraphics.drawImage(img, x, y, observer);
|
||||||
return canvasGraphics.drawImage(img, x, y, observer);
|
appendShape(new Rectangle2D.Double(x, y, img.getWidth(observer), img.getHeight(observer)));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-1
@@ -709,7 +709,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
controlPoints[index] = null;
|
controlPoints[index] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(Arrays.deepToString(controlPoints));
|
|
||||||
for (int i = 0; i < controlPoints.length - 1; i++) {
|
for (int i = 0; i < controlPoints.length - 1; i++) {
|
||||||
for (int j = i + 1; j < controlPoints.length; j++) {
|
for (int j = i + 1; j < controlPoints.length; j++) {
|
||||||
if (controlPoints[i] != null && controlPoints[j] != null
|
if (controlPoints[i] != null && controlPoints[j] != null
|
||||||
|
|||||||
+5
@@ -3,6 +3,7 @@ package org.diylc.swing.gui.editor;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@@ -26,6 +27,10 @@ public class FieldEditorFactory {
|
|||||||
MeasureEditor editor = new MeasureEditor(property);
|
MeasureEditor editor = new MeasureEditor(property);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
if (ImageIcon.class.isAssignableFrom(property.getType())) {
|
||||||
|
ImageEditor editor = new ImageEditor(property);
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
if (property.getType().isEnum()) {
|
if (property.getType().isEnum()) {
|
||||||
EnumEditor editor = new EnumEditor(property);
|
EnumEditor editor = new EnumEditor(property);
|
||||||
return editor;
|
return editor;
|
||||||
|
|||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package org.diylc.swing.gui.editor;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
|
||||||
|
import org.diylc.common.PropertyWrapper;
|
||||||
|
import org.diylc.swing.gui.DialogFactory;
|
||||||
|
import org.diylc.swing.plugins.file.FileFilterEnum;
|
||||||
|
|
||||||
|
public class ImageEditor extends JButton {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public ImageEditor(final PropertyWrapper property) {
|
||||||
|
super("Click to load file");
|
||||||
|
addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent e) {
|
||||||
|
File file = DialogFactory.getInstance().showOpenDialog(
|
||||||
|
FileFilterEnum.IMAGES.getFilter(), null,
|
||||||
|
FileFilterEnum.IMAGES.getExtensions()[0], null);
|
||||||
|
if (file != null) {
|
||||||
|
ImageIcon image = new ImageIcon(file.getAbsolutePath());
|
||||||
|
property.setValue(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBackground(Color bg) {
|
||||||
|
if (bg.getRed() < 127 || bg.getBlue() < 127 || bg.getGreen() < 127) {
|
||||||
|
setForeground(Color.white);
|
||||||
|
} else {
|
||||||
|
setForeground(Color.black);
|
||||||
|
}
|
||||||
|
super.setBackground(bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-2
@@ -4,11 +4,12 @@ import java.io.File;
|
|||||||
|
|
||||||
import javax.swing.filechooser.FileFilter;
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
enum FileFilterEnum {
|
public enum FileFilterEnum {
|
||||||
|
|
||||||
PNG("PNG Images (*.png)", "png"), PDF("PDF Files (*.pdf)", "pdf"), DIY(
|
PNG("PNG Images (*.png)", "png"), PDF("PDF Files (*.pdf)", "pdf"), DIY(
|
||||||
"DIY Project Files (*.diy)", "diy"), EXCEL("Excel Workbooks (*.xls)", "xls"), CSV(
|
"DIY Project Files (*.diy)", "diy"), EXCEL("Excel Workbooks (*.xls)", "xls"), CSV(
|
||||||
"Comma Separated Files (*.csv)", "csv"), HTML("HTML Files (*.html)", "html");
|
"Comma Separated Files (*.csv)", "csv"), HTML("HTML Files (*.html)", "html"), IMAGES(
|
||||||
|
"Image Files (*.png, *.jpg, *.gif)", "png", "jpg", "gif");
|
||||||
|
|
||||||
FileFilter filter;
|
FileFilter filter;
|
||||||
String[] extensions;
|
String[] extensions;
|
||||||
|
|||||||
@@ -11,19 +11,23 @@
|
|||||||
<changes>
|
<changes>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>Copy/paste between two instances of the application</description>
|
<description>Copy/paste between two instances of the
|
||||||
|
application</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>Parsing numerical values in countries that use comma as decimal separator</description>
|
<description>Parsing numerical values in countries that use
|
||||||
|
comma as decimal separator</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>Dragging sticky points affects selectability of objects</description>
|
<description>Dragging sticky points affects selectability
|
||||||
|
of objects</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>Click is sometimes not registered while adding a new component</description>
|
<description>Click is sometimes not registered while adding a
|
||||||
|
new component</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
@@ -31,7 +35,8 @@
|
|||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Allow shape control points of curves to overlap</description>
|
<description>Allow shape control points of curves to overlap
|
||||||
|
</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
@@ -39,18 +44,29 @@
|
|||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Added transparency to the potentiometer</description>
|
<description>Added transparency to the potentiometer
|
||||||
|
</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Reduced number of layers</description>
|
<description>Reduced number of layers</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
|
<com.diyfever.gui.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Import from v1 files can now read label and
|
||||||
|
electrolytic capacitor components and trace/pad colors</description>
|
||||||
|
</com.diyfever.gui.update.Change>
|
||||||
<com.diyfever.gui.update.Change>
|
<com.diyfever.gui.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Added Label component</description>
|
<description>Added label component</description>
|
||||||
|
</com.diyfever.gui.update.Change>
|
||||||
|
<com.diyfever.gui.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Added image component</description>
|
||||||
</com.diyfever.gui.update.Change>
|
</com.diyfever.gui.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
|
<url>http://code.google.com/p/diy-layout-creator/downloads/list
|
||||||
|
</url>
|
||||||
</com.diyfever.gui.update.Version>
|
</com.diyfever.gui.update.Version>
|
||||||
</a>
|
</a>
|
||||||
</java.util.Arrays_-ArrayList>
|
</java.util.Arrays_-ArrayList>
|
||||||
+112
@@ -0,0 +1,112 @@
|
|||||||
|
package org.diylc.components.misc;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
|
import org.diylc.components.AbstractComponent;
|
||||||
|
import org.diylc.core.ComponentState;
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
import org.diylc.core.IDrawingObserver;
|
||||||
|
import org.diylc.core.Project;
|
||||||
|
import org.diylc.core.VisibilityPolicy;
|
||||||
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
|
|
||||||
|
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc", description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.TEXT, stretchable = false)
|
||||||
|
public class Image extends AbstractComponent<Void> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
public static String DEFAULT_TEXT = "Double click to edit text";
|
||||||
|
private static ImageIcon ICON;
|
||||||
|
private static byte DEFAULT_SCALE = 50;
|
||||||
|
|
||||||
|
static {
|
||||||
|
String name = "image.png";
|
||||||
|
java.net.URL imgURL = Image.class.getResource(name);
|
||||||
|
if (imgURL != null) {
|
||||||
|
ICON = new ImageIcon(imgURL, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Point point = new Point(0, 0);
|
||||||
|
private ImageIcon image = ICON;
|
||||||
|
private byte scale = 50;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||||
|
IDrawingObserver drawingObserver) {
|
||||||
|
double s = 1d * scale / DEFAULT_SCALE;
|
||||||
|
g2d.scale(s, s);
|
||||||
|
g2d.drawImage(image.getImage(), (int) (point.x / s), (int) (point.y / s), null);
|
||||||
|
if (componentState == ComponentState.SELECTED) {
|
||||||
|
g2d.setColor(SELECTION_COLOR);
|
||||||
|
g2d.drawRect((int) (point.x / s), (int) (point.y / s), image.getIconWidth(), image
|
||||||
|
.getIconHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
|
g2d.drawImage(ICON.getImage(), point.x, point.y, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getControlPointCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Point getControlPoint(int index) {
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isControlPointSticky(int index) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||||
|
return VisibilityPolicy.NEVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setControlPoint(Point point, int index) {
|
||||||
|
this.point.setLocation(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(defaultable = false)
|
||||||
|
public ImageIcon getImage() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImage(ImageIcon image) {
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(defaultable = false)
|
||||||
|
public byte getScale() {
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScale(byte scale) {
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return super.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@Override
|
||||||
|
public Void getValue() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValue(Void value) {
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Reference in New Issue
Block a user