added grid type

renamed few classes
This commit is contained in:
bancika
2011-01-19 19:38:36 +00:00
parent 69ef633af3
commit 55f7d2e057
12 changed files with 90 additions and 26 deletions
@@ -1,4 +1,12 @@
<map>
<entry>
<string>metric</string>
<boolean>false</boolean>
</entry>
<entry>
<string>zoom</string>
<double>1.0</double>
</entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
@@ -0,0 +1,6 @@
package org.diylc.common;
public enum GridType {
LINES, CROSSHAIR, DOT, NONE;
}
@@ -172,6 +172,8 @@ public interface IPlugInPort {
* @param parentMenuName
*/
void injectSubmenu(String name, Icon icon, String parentMenuName);
Double[] getAvailableZoomLevels();
/**
* Returns current zoom level where <code>zoomLevel = 1.0d</code> means
@@ -30,9 +30,9 @@ import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.images.IconLoader;
import org.diylc.plugins.canvas.CanvasPlugin;
import org.diylc.plugins.clipboard.ClipboardManager;
import org.diylc.plugins.file.FileManager;
import org.diylc.plugins.help.HelpManager;
import org.diylc.plugins.clipboard.EditMenuPlugin;
import org.diylc.plugins.file.FileMenuPlugin;
import org.diylc.plugins.help.HelpMenuPlugin;
import org.diylc.plugins.statusbar.StatusBar;
import org.diylc.plugins.toolbox.ToolBox;
import org.diylc.presenter.Presenter;
@@ -67,10 +67,10 @@ public class MainFrame extends JFrame implements IView {
this.presenter = new Presenter(this);
presenter.installPlugin(new ToolBox());
presenter.installPlugin(new FileManager());
presenter.installPlugin(new ClipboardManager());
presenter.installPlugin(new FileMenuPlugin());
presenter.installPlugin(new EditMenuPlugin());
// presenter.installPlugin(new OnlineManager());
presenter.installPlugin(new HelpManager());
presenter.installPlugin(new HelpMenuPlugin());
presenter.installPlugin(new StatusBar());
canvasPlugin = new CanvasPlugin();
@@ -3,6 +3,8 @@ package org.diylc.plugins.canvas;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.util.EnumSet;
import javax.swing.SwingConstants;
@@ -35,7 +37,6 @@ public class CanvasPlugin implements IPlugIn {
@Override
public void connect(IPlugInPort plugInPort) {
this.plugInPort = plugInPort;
canvasPanel = new CanvasPanel(plugInPort);
try {
plugInPort.injectGUIComponent(getScrollPane(), SwingConstants.CENTER);
} catch (BadPositionException e) {
@@ -43,14 +44,22 @@ public class CanvasPlugin implements IPlugIn {
}
}
public CanvasPanel getCanvasPanel() {
if (canvasPanel == null) {
canvasPanel = new CanvasPanel(plugInPort);
}
return canvasPanel;
}
private RulerScrollPane getScrollPane() {
if (scrollPane == null) {
scrollPane = new RulerScrollPane(canvasPanel, new ProjectDrawingProvider(plugInPort),
new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d, SizeUnit.in)
.convertToPixels());
boolean metric = ConfigurationManager.getInstance().readBoolean(
Presenter.METRIC_KEY, true);
scrollPane = new RulerScrollPane(getCanvasPanel(), new ProjectDrawingProvider(
plugInPort), new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d,
SizeUnit.in).convertToPixels());
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY,
true);
scrollPane.setMetric(metric);
scrollPane.setWheelScrollingEnabled(false);
scrollPane.addUnitListener(new IRulerListener() {
@Override
@@ -58,6 +67,29 @@ public class CanvasPlugin implements IPlugIn {
plugInPort.setMetric(isMetric);
}
});
scrollPane.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
double d = plugInPort.getZoomLevel();
Double[] availableZoomLevels = plugInPort.getAvailableZoomLevels();
if (e.getWheelRotation() > 0) {
int i = availableZoomLevels.length - 1;
while (i > 0 && availableZoomLevels[i] >= d) {
i--;
}
plugInPort.setZoomLevel(availableZoomLevels[i]);
} else {
int i = 0;
while (i < availableZoomLevels.length - 1 && availableZoomLevels[i] <= d) {
i++;
}
plugInPort.setZoomLevel(availableZoomLevels[i]);
}
System.out.println(e);
e.consume();
}
});
}
return scrollPane;
}
@@ -31,9 +31,9 @@ import com.diyfever.gui.undo.IUndoListener;
import com.diyfever.gui.undo.UndoHandler;
import com.rits.cloning.Cloner;
public class ClipboardManager implements IPlugIn, ClipboardOwner {
public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
private static final Logger LOG = Logger.getLogger(ClipboardManager.class);
private static final Logger LOG = Logger.getLogger(EditMenuPlugin.class);
private static final String EDIT_TITLE = "Edit";
private IPlugInPort plugInPort;
@@ -47,7 +47,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
private UndoHandler<Project> undoHandler;
public ClipboardManager() {
public EditMenuPlugin() {
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
cloner = new Cloner();
undoHandler = new UndoHandler<Project>(new IUndoListener<Project>() {
@@ -152,7 +152,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
public void actionPerformed(ActionEvent e) {
LOG.info("Copy triggered");
clipboard.setContents(cloner.deepClone(plugInPort.getSelectedComponents()),
ClipboardManager.this);
EditMenuPlugin.this);
}
}
@@ -21,7 +21,7 @@ import com.diyfever.gui.export.DrawingExporter;
*
* @author Branislav Stojkovic
*/
public class FileManager implements IPlugIn {
public class FileMenuPlugin implements IPlugIn {
private static final String FILE_TITLE = "File";
private static final String TRACE_MASK_TITLE = "Trace Mask";
@@ -20,7 +20,7 @@ import com.diyfever.gui.miscutils.Utils;
*
* @author Branislav Stojkovic
*/
public class HelpManager implements IPlugIn {
public class HelpMenuPlugin implements IPlugIn {
private static final String HELP_TITLE = "Help";
@@ -71,8 +71,7 @@ public class StatusBar extends JPanel implements IPlugIn {
private JComboBox getZoomBox() {
if (zoomBox == null) {
zoomBox = new JComboBox(new Double[] { 0.25d, 0.3333d, 0.5d, 0.6667d, 0.75d, 1d, 1.25d,
1.5d, 2d });
zoomBox = new JComboBox(plugInPort.getAvailableZoomLevels());
zoomBox.setSelectedItem(plugInPort.getZoomLevel());
zoomBox.setFocusable(false);
zoomBox.setRenderer(new PercentageListCellRenderer());
@@ -134,6 +134,11 @@ public class Presenter implements IPlugInPort {
// IPlugInPort
@Override
public Double[] getAvailableZoomLevels() {
return new Double[] { 0.25d, 0.3333d, 0.5d, 0.6667d, 0.75d, 1d, 1.25d, 1.5d, 2d };
}
@Override
public double getZoomLevel() {
return zoomLevel;
@@ -142,6 +147,9 @@ public class Presenter implements IPlugInPort {
@Override
public void setZoomLevel(double zoomLevel) {
LOG.info(String.format("setZoomLevel(%s)", zoomLevel));
if (this.zoomLevel == zoomLevel) {
return;
}
this.zoomLevel = zoomLevel;
ConfigurationManager.getInstance().writeValue(ZOOM_KEY, zoomLevel);
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
@@ -18,6 +18,7 @@ import java.util.Set;
import org.diylc.common.ComponentSelection;
import org.diylc.common.DrawOption;
import org.diylc.common.GridType;
import org.diylc.common.IComponentFiler;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
@@ -45,9 +46,6 @@ public class ProjectPainter {
// determine which components are invalidated when they are not in the map.
private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap;
public boolean antiAliasing = ConfigurationManager.getInstance().readBoolean(ANTIALIASING_KEY,
true);
public ProjectPainter() {
super();
componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
@@ -63,7 +61,8 @@ public class ProjectPainter {
}
G2DWrapper g2dWrapper = new G2DWrapper(g2d);
if (drawOptions.contains(DrawOption.ANTIALIASING) && antiAliasing) {
if (drawOptions.contains(DrawOption.ANTIALIASING)
&& ConfigurationManager.getInstance().readBoolean(ANTIALIASING_KEY, true)) {
g2d
.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
@@ -76,8 +75,18 @@ public class ProjectPainter {
g2dWrapper.fillRect(0, 0, d.width, d.height);
g2d.setClip(new Rectangle(new Point(0, 0), d));
if (drawOptions.contains(DrawOption.GRID)) {
GridType gridType = (GridType) ConfigurationManager.getInstance().readObject(
ANTIALIASING_KEY, GridType.LINES);
if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) {
double zoomStep = project.getGridSpacing().convertToPixels() * zoomLevel;
if (gridType == GridType.CROSSHAIR) {
g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
10f, new float[] { (float) zoomStep / 2, (float) zoomStep / 2 },
(float) zoomStep / 4));
} else if (gridType == GridType.DOT) {
g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
10f, new float[] { 1f, (float) zoomStep - 1 }, 0f));
}
g2dWrapper.setColor(Constants.GRID_COLOR);
for (double i = zoomStep; i < d.width; i += zoomStep) {
@@ -18,5 +18,5 @@ public class Constants {
public static final Stroke BASIC_STROKE = new BasicStroke();
public static final Stroke DASHED_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER, 2.0f, new float[] { 2.0f }, 0.0f);
BasicStroke.JOIN_MITER, 10f, new float[] { 2.0f }, 0.0f);
}