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
@@ -1,13 +1,15 @@
package org.diylc;
import java.io.IOException;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Properties;
import javax.swing.UIManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.diylc.gui.MainFrame;
import org.diylc.presenter.Presenter;
import com.diyfever.gui.miscutils.PropertyInjector;
@@ -16,6 +18,8 @@ import com.diyfever.gui.miscutils.PropertyInjector;
* @author Branislav Stojkovic
*/
public class DIYLCStarter {
private static final Logger LOG = Logger.getLogger(Presenter.class);
/**
* @param args
@@ -26,25 +30,23 @@ public class DIYLCStarter {
try {
properties.load(url.openStream());
PropertyConfigurator.configure(properties);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
LOG.error("Could not initialize log4j configuration", e);
}
url = DIYLCStarter.class.getResource("config.properties");
url = DIYLCStarter.class.getResource("/config.properties");
properties = new Properties();
try {
properties.load(url.openStream());
properties.load(new FileInputStream("config.properties"));
PropertyInjector.injectProperties(properties);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
LOG.error("Could not read config.properties file", e);
}
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e) {
LOG.error("Could not set Look&Feel", e);
}
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>Getters for properties editable by users should be annotated with
* {@link EditableProperty}.</li>
* <li>Component configuration should be declared using
* <code>public static</code> fields so they can be set through config file.</li>
* <li>Component configuration should be stored int <code>public static</code>
* fields so they can be set through config file.</li>
* </ul>
*
* @author Branislav Stojkovic
@@ -42,8 +42,9 @@ public interface IDIYComponent<T> extends Serializable {
*
* @param g2d
* @param componentState
* @param project
*/
void draw(Graphics2D g2d, ComponentState componentState);
void draw(Graphics2D g2d, ComponentState componentState, Project project);
/**
* Draws icon representation of the component.
@@ -16,9 +16,9 @@ public class SelectionTransferable implements Transferable {
"Component Selection");
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();
this.selection = selection;
this.startPoint = startPoint;
@@ -52,6 +52,7 @@ public class ComponentProcessor {
* @param clazz
* @return
*/
@SuppressWarnings("unchecked")
public List<PropertyWrapper> extractProperties(Class<? extends IDIYComponent> clazz) {
if (propertyCache.containsKey(clazz)) {
return cloner.deepClone(propertyCache.get(clazz));
@@ -95,6 +96,7 @@ public class ComponentProcessor {
* @param clazz
* @return
*/
@SuppressWarnings("unchecked")
public List<ControlPointWrapper> extractControlPoints(Class<? extends IDIYComponent> clazz) {
if (controlPointCache.containsKey(clazz)) {
return cloner.deepClone(controlPointCache.get(clazz));
@@ -313,7 +313,7 @@ public class Presenter implements IPlugInPort {
g2dWrapper.setComposite(alphaComposite);
}
// Draw the component through the g2dWrapper.
component.draw(g2dWrapper, state);
component.draw(g2dWrapper, state, currentProject);
// Restore the composite if needed.
if (state == ComponentState.DRAGGING) {
g2dWrapper.setComposite(mainComposite);
@@ -328,7 +328,7 @@ public class Presenter implements IPlugInPort {
try {
controlPoint.readFrom(component);
if (shouldShowControlPoint(controlPoint, component)) {
g2d.setColor(Color.blue);
g2d.setColor(Constants.CONTROL_POINT_COLOR);
g2d.setStroke(new BasicStroke(2));
g2d.drawOval(controlPoint.getValue().x - 2,
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 Color CANVAS_COLOR = Color.white;
public static final Color GRID_COLOR = new Color(240, 240, 240);
public static Color CANVAS_COLOR = Color.white;
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);