tweak colors

This commit is contained in:
bancika
2011-01-13 18:50:27 +00:00
parent 7afeb48407
commit f3ed8d1a7c
12 changed files with 92 additions and 59 deletions
@@ -6,14 +6,14 @@
<unit class="org.diylc.core.measures.ResistanceUnit">K</unit> <unit class="org.diylc.core.measures.ResistanceUnit">K</unit>
</org.diylc.core.measures.Resistance> </org.diylc.core.measures.Resistance>
</entry> </entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
<entry> <entry>
<string>metric</string> <string>metric</string>
<boolean>true</boolean> <boolean>true</boolean>
</entry> </entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
<entry> <entry>
<string>default.org.diylc.components.semiconductors.DIL_IC:Value</string> <string>default.org.diylc.components.semiconductors.DIL_IC:Value</string>
<string>LM366</string> <string>LM366</string>
@@ -0,0 +1,8 @@
package org.diylc.common;
import org.diylc.core.IDIYComponent;
public interface IComponentFiler {
boolean testComponent(IDIYComponent<?> component);
}
@@ -83,11 +83,15 @@ public interface IPlugInPort {
Map<String, List<ComponentType>> getComponentTypes(); Map<String, List<ComponentType>> getComponentTypes();
/** /**
* Draws project on the provided {@link Graphics2D}. * Draws project on the provided {@link Graphics2D}. If the provided filter
* is not null, it will be used to filter the components that are shown.
* *
* @param g2d * @param g2d
* @param drawOptions
* specific drawing options
* @param filter
*/ */
void draw(Graphics2D g2d, Set<DrawOption> drawProperties); void draw(Graphics2D g2d, Set<DrawOption> drawOptions, IComponentFiler filter);
/** /**
* Injects a custom GUI panels provided by the plug-in and desired position * Injects a custom GUI panels provided by the plug-in and desired position
@@ -71,16 +71,14 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
(points[0].y + points[1].y - shapeRect.height) / 2); (points[0].y + points[1].y - shapeRect.height) / 2);
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2); g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
// Draw body. // Draw body.
if (componentState != ComponentState.DRAGGING) { Composite oldComposite = g2d.getComposite();
Composite oldComposite = g2d.getComposite(); if (alpha < MAX_ALPHA) {
if (alpha < MAX_ALPHA) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
}
g2d.setColor(bodyColor);
g2d.fill(shape);
g2d.setComposite(oldComposite);
} }
g2d.setColor(bodyColor);
g2d.fill(shape);
g2d.setComposite(oldComposite);
g2d.setStroke(new BasicStroke(1)); g2d.setStroke(new BasicStroke(1));
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor); || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
@@ -107,7 +107,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
bufferImage = createImage(getWidth(), getHeight()); bufferImage = createImage(getWidth(), getHeight());
} }
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics(); Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
plugInPort.draw(g2d, drawOptions); plugInPort.draw(g2d, drawOptions, null);
} }
@Override @Override
@@ -119,7 +119,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
createBufferImage(); createBufferImage();
} else { } else {
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics(); Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
plugInPort.draw(g2d, drawOptions); plugInPort.draw(g2d, drawOptions, null);
} }
if (USE_HARDWARE_ACCELLERATION) { if (USE_HARDWARE_ACCELLERATION) {
VolatileImage volatileImage = (VolatileImage) bufferImage; VolatileImage volatileImage = (VolatileImage) bufferImage;
@@ -139,7 +139,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
} while (volatileImage == null || volatileImage.contentsLost()); } while (volatileImage == null || volatileImage.contentsLost());
} else { } else {
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics(); Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
plugInPort.draw(g2d, drawOptions); plugInPort.draw(g2d, drawOptions, null);
g.drawImage(bufferImage, 0, 0, this); g.drawImage(bufferImage, 0, 0, this);
bufferImage.flush(); bufferImage.flush();
} }
@@ -6,6 +6,7 @@ import java.awt.Graphics2D;
import java.util.EnumSet; import java.util.EnumSet;
import org.diylc.common.DrawOption; import org.diylc.common.DrawOption;
import org.diylc.common.IComponentFiler;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import com.diyfever.gui.IDrawingProvider; import com.diyfever.gui.IDrawingProvider;
@@ -18,7 +19,7 @@ import com.diyfever.gui.IDrawingProvider;
*/ */
public class ProjectDrawingProvider implements IDrawingProvider { public class ProjectDrawingProvider implements IDrawingProvider {
IPlugInPort plugInPort; private IPlugInPort plugInPort;
public ProjectDrawingProvider(IPlugInPort plugInPort) { public ProjectDrawingProvider(IPlugInPort plugInPort) {
super(); super();
@@ -27,7 +28,12 @@ public class ProjectDrawingProvider implements IDrawingProvider {
@Override @Override
public void draw(Graphics g) { public void draw(Graphics g) {
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING)); plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING), null);
}
public void draw(Graphics g, IComponentFiler filter) {
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING),
filter);
} }
@Override @Override
@@ -132,14 +132,14 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
zoomRatio = rect.getHeight() / d.getHeight(); zoomRatio = rect.getHeight() / d.getHeight();
} }
// d.setSize(d.getWidth() * zoomRatio, d.getHeight() * zoomRatio); // d.setSize(d.getWidth() * zoomRatio, d.getHeight() * zoomRatio);
int x = (int) (rect.getWidth() - d.getWidth() * zoomRatio) / 2; // int x = (int) (rect.getWidth() - d.getWidth() * zoomRatio) / 2;
int y = (int) (rect.getHeight() - d.getHeight() * zoomRatio) / 2; // int y = (int) (rect.getHeight() - d.getHeight() * zoomRatio) / 2;
// System.out.println(x + "," + y); // System.out.println(x + "," + y);
g2d.translate(x, y); // g2d.translate(x, y);
g2d.scale(zoomRatio, zoomRatio); g2d.scale(zoomRatio, zoomRatio);
presenter.draw(g2d, EnumSet.noneOf(DrawOption.class)); presenter.draw(g2d, EnumSet.noneOf(DrawOption.class), null);
g2d.setColor(Color.black); g2d.setColor(Color.black);
g2d.drawRect(0, 0, d.width - (int) (1 / zoomRatio), d.height - (int) (1 / zoomRatio)); g2d.drawRect(0, 0, d.width - (int) (1 / zoomRatio), d.height - (int) (1 / zoomRatio));
@@ -0,0 +1,23 @@
package org.diylc.presenter;
import org.diylc.common.ComponentType;
import org.diylc.common.IComponentFiler;
import org.diylc.core.IDIYComponent;
public class ComponentZOrderFiler implements IComponentFiler {
private int zOrder;
public ComponentZOrderFiler(int zOrder) {
super();
this.zOrder = zOrder;
}
@SuppressWarnings("unchecked")
@Override
public boolean testComponent(IDIYComponent<?> component) {
ComponentType componentType = ComponentProcessor.getInstance().createComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component.getClass());
return Math.round(componentType.getZOrder()) == zOrder;
}
}
@@ -8,7 +8,6 @@ import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@@ -31,6 +30,7 @@ import org.diylc.common.ComponentSelection;
import org.diylc.common.ComponentType; import org.diylc.common.ComponentType;
import org.diylc.common.DrawOption; import org.diylc.common.DrawOption;
import org.diylc.common.EventType; import org.diylc.common.EventType;
import org.diylc.common.IComponentFiler;
import org.diylc.common.IPlugIn; import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.PropertyWrapper; import org.diylc.common.PropertyWrapper;
@@ -215,7 +215,7 @@ public class Presenter implements IPlugInPort {
} }
@Override @Override
public void draw(Graphics2D g2d, Set<DrawOption> drawOptions) { public void draw(Graphics2D g2d, Set<DrawOption> drawOptions, IComponentFiler filter) {
if (currentProject == null) { if (currentProject == null) {
return; return;
} }
@@ -227,7 +227,7 @@ public class Presenter implements IPlugInPort {
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
} }
AffineTransform initialTx = g2d.getTransform(); // AffineTransform initialTx = g2d.getTransform();
Dimension d = getCanvasDimensions(drawOptions.contains(DrawOption.ZOOM)); Dimension d = getCanvasDimensions(drawOptions.contains(DrawOption.ZOOM));
g2dWrapper.setColor(Constants.CANVAS_COLOR); g2dWrapper.setColor(Constants.CANVAS_COLOR);
@@ -259,6 +259,10 @@ public class Presenter implements IPlugInPort {
componentAreaMap.clear(); componentAreaMap.clear();
if (components != null) { if (components != null) {
for (IDIYComponent<?> component : components) { for (IDIYComponent<?> component : components) {
// Do not draw the component if it's filtered out.
if (filter != null && !filter.testComponent(component)) {
continue;
}
g2dWrapper.startedDrawingComponent(); g2dWrapper.startedDrawingComponent();
ComponentState state = ComponentState.NORMAL; ComponentState state = ComponentState.NORMAL;
if (drawOptions.contains(DrawOption.SELECTION) if (drawOptions.contains(DrawOption.SELECTION)
@@ -299,10 +303,10 @@ public class Presenter implements IPlugInPort {
// Go back to the original transformation and zoom in to draw the // Go back to the original transformation and zoom in to draw the
// selection rectangle and other similar elements. // selection rectangle and other similar elements.
g2d.setTransform(initialTx); // g2d.setTransform(initialTx);
if ((drawOptions.contains(DrawOption.ZOOM)) && (Math.abs(1.0 - zoomLevel) > 1e-4)) { // if ((drawOptions.contains(DrawOption.ZOOM)) && (Math.abs(1.0 - zoomLevel) > 1e-4)) {
g2d.scale(zoomLevel, zoomLevel); // g2d.scale(zoomLevel, zoomLevel);
} // }
// At the end draw selection rectangle if needed. // At the end draw selection rectangle if needed.
if (drawOptions.contains(DrawOption.SELECTION) && (selectionRect != null)) { if (drawOptions.contains(DrawOption.SELECTION) && (selectionRect != null)) {
@@ -157,16 +157,14 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
Shape body = getBody(); Shape body = getBody();
// Draw body if available. // Draw body if available.
if (body != null) { if (body != null) {
if (componentState != ComponentState.DRAGGING) { Composite oldComposite = g2d.getComposite();
Composite oldComposite = g2d.getComposite(); if (alpha < MAX_ALPHA) {
if (alpha < MAX_ALPHA) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
}
g2d.setColor(BODY_COLOR);
g2d.fill(body);
g2d.setComposite(oldComposite);
} }
g2d.setColor(BODY_COLOR);
g2d.fill(body);
g2d.setComposite(oldComposite);
g2d.setStroke(new BasicStroke()); g2d.setStroke(new BasicStroke());
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR); || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
@@ -177,11 +175,9 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
int lugWidth = getClosestOdd(LUG_WIDTH.convertToPixels()); int lugWidth = getClosestOdd(LUG_WIDTH.convertToPixels());
int lugHeight = getClosestOdd(LUG_HEIGHT.convertToPixels()); int lugHeight = getClosestOdd(LUG_HEIGHT.convertToPixels());
for (Point p : controlPoints) { for (Point p : controlPoints) {
if (componentState != ComponentState.DRAGGING) { g2d.setColor(CIRCLE_COLOR);
g2d.setColor(CIRCLE_COLOR); g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter,
g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter, circleDiameter);
circleDiameter);
}
g2d.setColor(LUG_COLOR); g2d.setColor(LUG_COLOR);
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight); g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
} }
@@ -218,27 +218,21 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
g2d.setColor(PIN_BORDER_COLOR); g2d.setColor(PIN_BORDER_COLOR);
g2d.drawRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize); g2d.drawRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
} }
if (componentState != ComponentState.DRAGGING) { Composite oldComposite = g2d.getComposite();
Composite oldComposite = g2d.getComposite(); if (alpha < MAX_ALPHA) {
if (alpha < MAX_ALPHA) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
}
g2d.setColor(BODY_COLOR);
g2d.fill(getBody());
g2d.setComposite(oldComposite);
} }
g2d.setColor(BODY_COLOR);
g2d.fill(getBody());
g2d.setComposite(oldComposite);
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR); || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
g2d.setStroke(new BasicStroke()); g2d.setStroke(new BasicStroke());
g2d.draw(getBody()); g2d.draw(getBody());
// Draw label. // Draw label.
g2d.setFont(Constants.LABEL_FONT); g2d.setFont(Constants.LABEL_FONT);
if (componentState == ComponentState.DRAGGING) { g2d.setColor(LABEL_COLOR);
g2d.setColor(BORDER_COLOR);
} else {
g2d.setColor(LABEL_COLOR);
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d); Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) (rect.getHeight()); int textHeight = (int) (rect.getHeight());