added project to component.draw

better logging
This commit is contained in:
bancika
2011-01-05 01:00:16 +00:00
parent dd50ccf785
commit 8db24c2588
11 changed files with 34 additions and 24 deletions
@@ -0,0 +1,2 @@
#org.diylc.utils.Constants.CANVAS_COLOR=#005D96
#org.diylc.utils.Constants.GRID_COLOR=#FFFFFF
@@ -10,6 +10,7 @@ import java.awt.Shape;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy; import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ControlPoint; import org.diylc.core.annotations.ControlPoint;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -76,7 +77,7 @@ public abstract class AbstractLeadedDIYComponent<T> implements IDIYComponent<T>
protected abstract Color getBorderColor(); protected abstract Color getBorderColor();
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState) { public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
g2d.setColor(LEAD_COLOR); g2d.setColor(LEAD_COLOR);
g2d.setStroke(new BasicStroke(1)); g2d.setStroke(new BasicStroke(1));
double distance = point1.distance(point2); double distance = point1.distance(point2);
@@ -8,6 +8,7 @@ import java.awt.geom.Rectangle2D;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy; import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.ControlPoint; import org.diylc.core.annotations.ControlPoint;
@@ -66,7 +67,7 @@ public class DIL_IC implements IDIYComponent<String> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState) { public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
int width = ((int) (Math.abs(point1.x - point2.x) / Constants.GRID)); int width = ((int) (Math.abs(point1.x - point2.x) / Constants.GRID));
if (width % 2 == 1) { if (width % 2 == 1) {
width--; width--;
@@ -6,6 +6,7 @@ import java.awt.Point;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy; import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.ControlPoint; import org.diylc.core.annotations.ControlPoint;
@@ -110,7 +111,7 @@ public class MockDIYComponent implements IDIYComponent {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState) { public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker()); g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50); g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
} }
@@ -1,13 +1,15 @@
package org.diylc; package org.diylc;
import java.io.IOException; import java.io.FileInputStream;
import java.net.URL; import java.net.URL;
import java.util.Properties; import java.util.Properties;
import javax.swing.UIManager; import javax.swing.UIManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import org.diylc.gui.MainFrame; import org.diylc.gui.MainFrame;
import org.diylc.presenter.Presenter;
import com.diyfever.gui.miscutils.PropertyInjector; import com.diyfever.gui.miscutils.PropertyInjector;
@@ -16,6 +18,8 @@ import com.diyfever.gui.miscutils.PropertyInjector;
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
public class DIYLCStarter { public class DIYLCStarter {
private static final Logger LOG = Logger.getLogger(Presenter.class);
/** /**
* @param args * @param args
@@ -26,25 +30,23 @@ public class DIYLCStarter {
try { try {
properties.load(url.openStream()); properties.load(url.openStream());
PropertyConfigurator.configure(properties); PropertyConfigurator.configure(properties);
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); LOG.error("Could not initialize log4j configuration", e);
} }
url = DIYLCStarter.class.getResource("config.properties"); url = DIYLCStarter.class.getResource("/config.properties");
properties = new Properties(); properties = new Properties();
try { try {
properties.load(url.openStream()); properties.load(new FileInputStream("config.properties"));
PropertyInjector.injectProperties(properties); PropertyInjector.injectProperties(properties);
} catch (IOException e) { } catch (Exception e) {
// TODO Auto-generated catch block LOG.error("Could not read config.properties file", e);
e.printStackTrace();
} }
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e1) { } catch (Exception e) {
// TODO Auto-generated catch block LOG.error("Could not set Look&Feel", e);
e1.printStackTrace();
} }
MainFrame mainFrame = new MainFrame(); MainFrame mainFrame = new MainFrame();
@@ -19,8 +19,8 @@ import org.diylc.core.annotations.EditableProperty;
* <li>Control point getters need to be annotated with {@link ControlPoint}.</li> * <li>Control point getters need to be annotated with {@link ControlPoint}.</li>
* <li>Getters for properties editable by users should be annotated with * <li>Getters for properties editable by users should be annotated with
* {@link EditableProperty}.</li> * {@link EditableProperty}.</li>
* <li>Component configuration should be declared using * <li>Component configuration should be stored int <code>public static</code>
* <code>public static</code> fields so they can be set through config file.</li> * fields so they can be set through config file.</li>
* </ul> * </ul>
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
@@ -42,8 +42,9 @@ public interface IDIYComponent<T> extends Serializable {
* *
* @param g2d * @param g2d
* @param componentState * @param componentState
* @param project
*/ */
void draw(Graphics2D g2d, ComponentState componentState); void draw(Graphics2D g2d, ComponentState componentState, Project project);
/** /**
* Draws icon representation of the component. * Draws icon representation of the component.
@@ -16,9 +16,9 @@ public class SelectionTransferable implements Transferable {
"Component Selection"); "Component Selection");
private Point startPoint; private Point startPoint;
private List<IDIYComponent> selection; private List<IDIYComponent<?>> selection;
public SelectionTransferable(List<IDIYComponent> selection, Point startPoint) { public SelectionTransferable(List<IDIYComponent<?>> selection, Point startPoint) {
super(); super();
this.selection = selection; this.selection = selection;
this.startPoint = startPoint; this.startPoint = startPoint;
@@ -52,6 +52,7 @@ public class ComponentProcessor {
* @param clazz * @param clazz
* @return * @return
*/ */
@SuppressWarnings("unchecked")
public List<PropertyWrapper> extractProperties(Class<? extends IDIYComponent> clazz) { public List<PropertyWrapper> extractProperties(Class<? extends IDIYComponent> clazz) {
if (propertyCache.containsKey(clazz)) { if (propertyCache.containsKey(clazz)) {
return cloner.deepClone(propertyCache.get(clazz)); return cloner.deepClone(propertyCache.get(clazz));
@@ -95,6 +96,7 @@ public class ComponentProcessor {
* @param clazz * @param clazz
* @return * @return
*/ */
@SuppressWarnings("unchecked")
public List<ControlPointWrapper> extractControlPoints(Class<? extends IDIYComponent> clazz) { public List<ControlPointWrapper> extractControlPoints(Class<? extends IDIYComponent> clazz) {
if (controlPointCache.containsKey(clazz)) { if (controlPointCache.containsKey(clazz)) {
return cloner.deepClone(controlPointCache.get(clazz)); return cloner.deepClone(controlPointCache.get(clazz));
@@ -313,7 +313,7 @@ public class Presenter implements IPlugInPort {
g2dWrapper.setComposite(alphaComposite); g2dWrapper.setComposite(alphaComposite);
} }
// Draw the component through the g2dWrapper. // Draw the component through the g2dWrapper.
component.draw(g2dWrapper, state); component.draw(g2dWrapper, state, currentProject);
// Restore the composite if needed. // Restore the composite if needed.
if (state == ComponentState.DRAGGING) { if (state == ComponentState.DRAGGING) {
g2dWrapper.setComposite(mainComposite); g2dWrapper.setComposite(mainComposite);
@@ -328,7 +328,7 @@ public class Presenter implements IPlugInPort {
try { try {
controlPoint.readFrom(component); controlPoint.readFrom(component);
if (shouldShowControlPoint(controlPoint, component)) { if (shouldShowControlPoint(controlPoint, component)) {
g2d.setColor(Color.blue); g2d.setColor(Constants.CONTROL_POINT_COLOR);
g2d.setStroke(new BasicStroke(2)); g2d.setStroke(new BasicStroke(2));
g2d.drawOval(controlPoint.getValue().x - 2, g2d.drawOval(controlPoint.getValue().x - 2,
controlPoint.getValue().y - 2, 4, 4); controlPoint.getValue().y - 2, 4, 4);
@@ -10,8 +10,9 @@ public class Constants {
public static final float GRID = Toolkit.getDefaultToolkit().getScreenResolution() / 10f; public static final float GRID = Toolkit.getDefaultToolkit().getScreenResolution() / 10f;
public static final Color CANVAS_COLOR = Color.white; public static Color CANVAS_COLOR = Color.white;
public static final Color GRID_COLOR = new Color(240, 240, 240); public static Color GRID_COLOR = new Color(240, 240, 240);
public static Color CONTROL_POINT_COLOR = Color.blue;
public static Font LABEL_FONT = new Font("Tahoma", Font.BOLD, 11); public static Font LABEL_FONT = new Font("Tahoma", Font.BOLD, 11);