mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
switchable sticky points
added themes fixed ruler precision improved board rendering
This commit is contained in:
+17
-2
@@ -11,6 +11,7 @@ import java.util.Set;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.swing.plugins.edit.ComponentTransferable;
|
||||
|
||||
import com.diyfever.gui.simplemq.IMessageListener;
|
||||
@@ -30,9 +31,11 @@ import com.diyfever.gui.update.VersionNumber;
|
||||
* @see EventType
|
||||
*/
|
||||
public interface IPlugInPort {
|
||||
|
||||
|
||||
public static final String ANTI_ALIASING_KEY = "antiAliasing";
|
||||
public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender";
|
||||
public static final String EXPORT_GRID_KEY = "exportGrid";
|
||||
public static final String STICKY_POINTS_KEY = "stickyPoints";
|
||||
|
||||
/**
|
||||
* Returns size of the canvas that takes project dimensions into account as
|
||||
@@ -330,9 +333,21 @@ public interface IPlugInPort {
|
||||
* Brings each of the selected components one step to front.
|
||||
*/
|
||||
void bringSelectionToFront();
|
||||
|
||||
|
||||
/**
|
||||
* Causes the display to refresh.
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
/**
|
||||
* @return currently selected theme.
|
||||
*/
|
||||
Theme getSelectedTheme();
|
||||
|
||||
/**
|
||||
* Changes the current theme.
|
||||
*
|
||||
* @param theme
|
||||
*/
|
||||
void setSelectedTheme(Theme theme);
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
public static Color SELECTION_COLOR = Color.red;
|
||||
public static Color LABEL_COLOR = Color.black;
|
||||
public static Color LABEL_COLOR_SELECTED = Color.red;
|
||||
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 12);
|
||||
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 14);
|
||||
|
||||
@EditableProperty(defaultable = false)
|
||||
@Override
|
||||
|
||||
+1
@@ -39,6 +39,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
* @param curve
|
||||
* @param g2d
|
||||
* @param componentState
|
||||
* @param theme
|
||||
*/
|
||||
protected abstract void drawCurve(CubicCurve2D curve, Graphics2D g2d,
|
||||
ComponentState componentState);
|
||||
|
||||
+20
-12
@@ -69,12 +69,14 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
return;
|
||||
}
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness()));
|
||||
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState));
|
||||
Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState);
|
||||
g2d.setColor(leadColor);
|
||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||
if (shouldShadeLeads()) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness() - 2));
|
||||
g2d.setColor(getLeadColor(componentState));
|
||||
leadColor = getLeadColor(componentState);
|
||||
g2d.setColor(leadColor);
|
||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||
}
|
||||
return;
|
||||
@@ -94,19 +96,23 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
if (bodyColor != null) {
|
||||
g2d.setColor(bodyColor);
|
||||
g2d.fill(shape);
|
||||
if (bodyColor != null) {
|
||||
g2d.setColor(bodyColor);
|
||||
g2d.fill(shape);
|
||||
}
|
||||
}
|
||||
decorateComponentBody(g2d);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
|
||||
Color finalBorderColor = componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
|
||||
g2d.setColor(finalBorderColor);
|
||||
g2d.draw(shape);
|
||||
// Draw label.
|
||||
g2d.setFont(LABEL_FONT);
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : labelColor);
|
||||
Color finalLabelFont = componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : labelColor;
|
||||
g2d.setColor(finalLabelFont);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
String label = display == Display.NAME ? getName() : getValue().toString();
|
||||
// Adjust label angle if needed to make sure that it's readable.
|
||||
@@ -123,8 +129,9 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
int leadThickness = getClosestOdd(getLeadThickness());
|
||||
double leadLength = (distance - shapeRect.width) / 2 - leadThickness / 2;
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState));
|
||||
Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState);
|
||||
g2d.setColor(leadColor);
|
||||
int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
|
||||
int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength);
|
||||
g2d.drawLine(points[0].x, points[0].y, endX, endY);
|
||||
@@ -133,7 +140,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
g2d.drawLine(points[1].x, points[1].y, endX, endY);
|
||||
if (shouldShadeLeads()) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(getLeadColor(componentState));
|
||||
leadColor = getLeadColor(componentState);
|
||||
g2d.setColor(leadColor);
|
||||
g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta)
|
||||
* leadLength), (int) (points[0].y + Math.sin(theta) * leadLength));
|
||||
g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta - Math.PI)
|
||||
|
||||
@@ -23,6 +23,7 @@ public interface IView {
|
||||
public static final int OK_OPTION = 0;
|
||||
|
||||
public static final String CHECK_BOX_MENU_ITEM = "org.diylc.checkBoxMenuItem";
|
||||
public static final String RADIO_BUTTON_GROUP_KEY = "org.diylc.radioButtonGroup";
|
||||
|
||||
void showMessage(String message, String title, int messageType);
|
||||
|
||||
|
||||
@@ -12,17 +12,17 @@ public class Theme implements Serializable {
|
||||
private Color gridColor;
|
||||
private Color componentBodyColor;
|
||||
private Color componentBorderColor;
|
||||
private Color componentLabelColor;
|
||||
private Color labelColor;
|
||||
|
||||
public Theme(String name, Color bgColor, Color gridColor, Color componentBodyColor,
|
||||
Color componentBorderColor, Color componentLabelColor) {
|
||||
Color componentBorderColor, Color labelColor) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.bgColor = bgColor;
|
||||
this.gridColor = gridColor;
|
||||
this.componentBodyColor = componentBodyColor;
|
||||
this.componentBorderColor = componentBorderColor;
|
||||
this.componentLabelColor = componentLabelColor;
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -45,8 +45,8 @@ public class Theme implements Serializable {
|
||||
return componentBorderColor;
|
||||
}
|
||||
|
||||
public Color getComponentLabelColor() {
|
||||
return componentLabelColor;
|
||||
public Color getLabelColor() {
|
||||
return labelColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,7 +59,7 @@ public class Theme implements Serializable {
|
||||
result = prime * result
|
||||
+ ((componentBorderColor == null) ? 0 : componentBorderColor.hashCode());
|
||||
result = prime * result
|
||||
+ ((componentLabelColor == null) ? 0 : componentLabelColor.hashCode());
|
||||
+ ((labelColor == null) ? 0 : labelColor.hashCode());
|
||||
result = prime * result + ((gridColor == null) ? 0 : gridColor.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
@@ -89,10 +89,10 @@ public class Theme implements Serializable {
|
||||
return false;
|
||||
} else if (!componentBorderColor.equals(other.componentBorderColor))
|
||||
return false;
|
||||
if (componentLabelColor == null) {
|
||||
if (other.componentLabelColor != null)
|
||||
if (labelColor == null) {
|
||||
if (other.labelColor != null)
|
||||
return false;
|
||||
} else if (!componentLabelColor.equals(other.componentLabelColor))
|
||||
} else if (!labelColor.equals(other.labelColor))
|
||||
return false;
|
||||
if (gridColor == null) {
|
||||
if (other.gridColor != null)
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@ public enum IconLoader {
|
||||
"faq.png"), Component("component.png"), Plugin("plugin.png"), Manual("manual.png"), Donate(
|
||||
"donate.png"), Bug("bug.png"), IconLarge("icon_large.png"), IconMedium(
|
||||
"icon_medium.png"), IconSmall("icon_small.png"), DocumentEdit("document_edit.png"), EditComponent(
|
||||
"edit_component.png"), Size("size.png"), Front("front.png"), Back("back.png");
|
||||
"edit_component.png"), Size("size.png"), Front("front.png"), Back("back.png"), Pens(
|
||||
"pens.png");
|
||||
|
||||
protected String name;
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 922 B |
+39
-20
@@ -26,6 +26,7 @@ import org.diylc.common.ObjectCache;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@@ -44,14 +45,17 @@ public class DrawingManager {
|
||||
|
||||
public static int CONTROL_POINT_SIZE = 7;
|
||||
|
||||
public static final String ANTIALIASING_KEY = "anti-aliasing";
|
||||
public static final String ZOOM_KEY = "zoom";
|
||||
public static final String THEME_KEY = "theme";
|
||||
public static boolean DEBUG_COMPONENT_AREAS = false;
|
||||
|
||||
public static Color GRID_COLOR = new Color(240, 240, 240);
|
||||
public static Color CONTROL_POINT_COLOR = Color.black;
|
||||
public static Color SELECTED_CONTROL_POINT_COLOR = Color.green;
|
||||
|
||||
private Theme theme = new Theme("White Realistic", Constants.CANVAS_COLOR, GRID_COLOR, null,
|
||||
null, null);
|
||||
|
||||
// Keeps Area object of each drawn component.
|
||||
private Map<IDIYComponent<?>, Area> componentAreaMap;
|
||||
// Maps components to the last state they are drawn in. Also, used to
|
||||
@@ -72,6 +76,10 @@ public class DrawingManager {
|
||||
this.messageDispatcher = messageDispatcher;
|
||||
componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
|
||||
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(THEME_KEY, null);
|
||||
if (theme != null) {
|
||||
this.theme = theme;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,12 +153,11 @@ public class DrawingManager {
|
||||
// AffineTransform initialTx = g2d.getTransform();
|
||||
Dimension d = getCanvasDimensions(project, zoom, true);
|
||||
|
||||
g2dWrapper.setColor(Constants.CANVAS_COLOR);
|
||||
g2dWrapper.setColor(theme.getBgColor());
|
||||
g2dWrapper.fillRect(0, 0, d.width, d.height);
|
||||
g2d.clip(new Rectangle(new Point(0, 0), d));
|
||||
|
||||
GridType gridType = (GridType) ConfigurationManager.getInstance().readObject(
|
||||
ANTIALIASING_KEY, GridType.LINES);
|
||||
GridType gridType = GridType.LINES;
|
||||
if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) {
|
||||
double zoomStep = project.getGridSpacing().convertToPixels() * zoom;
|
||||
if (gridType == GridType.CROSSHAIR) {
|
||||
@@ -162,7 +169,7 @@ public class DrawingManager {
|
||||
10f, new float[] { 1f, (float) zoomStep - 1 }, 0f));
|
||||
}
|
||||
|
||||
g2dWrapper.setColor(GRID_COLOR);
|
||||
g2dWrapper.setColor(theme.getGridColor());
|
||||
for (double i = zoomStep; i < d.width; i += zoomStep) {
|
||||
g2dWrapper.drawLine((int) i, 0, (int) i, d.height - 1);
|
||||
}
|
||||
@@ -224,22 +231,24 @@ public class DrawingManager {
|
||||
// Draw control points.
|
||||
if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
|
||||
// Draw unselected points first to make sure they are below.
|
||||
for (IDIYComponent<?> component : project.getComponents()) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
VisibilityPolicy visibilityPolicy = component
|
||||
.getControlPointVisibilityPolicy(i);
|
||||
if ((groupedComponents.contains(component)
|
||||
&& (visibilityPolicy == VisibilityPolicy.ALWAYS || (selectedComponents
|
||||
.contains(component) && visibilityPolicy == VisibilityPolicy.WHEN_SELECTED)) || (!groupedComponents
|
||||
.contains(component)
|
||||
&& !selectedComponents.contains(component) && component
|
||||
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) {
|
||||
g2dWrapper.setColor(CONTROL_POINT_COLOR);
|
||||
if (dragInProgress) {
|
||||
for (IDIYComponent<?> component : project.getComponents()) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
VisibilityPolicy visibilityPolicy = component
|
||||
.getControlPointVisibilityPolicy(i);
|
||||
if ((groupedComponents.contains(component)
|
||||
&& (visibilityPolicy == VisibilityPolicy.ALWAYS || (selectedComponents
|
||||
.contains(component) && visibilityPolicy == VisibilityPolicy.WHEN_SELECTED)) || (!groupedComponents
|
||||
.contains(component)
|
||||
&& !selectedComponents.contains(component) && component
|
||||
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) {
|
||||
g2dWrapper.setColor(CONTROL_POINT_COLOR);
|
||||
|
||||
Point controlPoint = component.getControlPoint(i);
|
||||
int pointSize = CONTROL_POINT_SIZE - 2;
|
||||
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y
|
||||
- pointSize / 2, pointSize, pointSize);
|
||||
Point controlPoint = component.getControlPoint(i);
|
||||
int pointSize = CONTROL_POINT_SIZE - 2;
|
||||
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y
|
||||
- pointSize / 2, pointSize, pointSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,4 +382,14 @@ public class DrawingManager {
|
||||
messageDispatcher.dispatchMessage(EventType.ZOOM_CHANGED, zoomLevel);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
|
||||
public Theme getTheme() {
|
||||
return theme;
|
||||
}
|
||||
|
||||
public void setTheme(Theme theme) {
|
||||
this.theme = theme;
|
||||
ConfigurationManager.getInstance().writeValue(THEME_KEY, theme);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
}
|
||||
|
||||
+34
-8
@@ -30,6 +30,7 @@ import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.swing.plugins.edit.ComponentTransferable;
|
||||
import org.diylc.utils.Constants;
|
||||
@@ -594,7 +595,12 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
// Expand control points to include all stuck components.
|
||||
if (!ctrlDown) {
|
||||
boolean sticky = ConfigurationManager.getInstance().readBoolean(
|
||||
IPlugInPort.STICKY_POINTS_KEY, true);
|
||||
if (ctrlDown) {
|
||||
sticky = !sticky;
|
||||
}
|
||||
if (sticky) {
|
||||
includeStuckComponents(controlPointMap);
|
||||
}
|
||||
}
|
||||
@@ -691,8 +697,9 @@ public class Presenter implements IPlugInPort {
|
||||
int actualDy = 0;
|
||||
|
||||
// For each component, do a simulation of the move to see if any of
|
||||
// them will
|
||||
// overlap.
|
||||
// them will overlap or go out of bounds.
|
||||
int width = (int) currentProject.getWidth().convertToPixels();
|
||||
int height = (int) currentProject.getHeight().convertToPixels();
|
||||
boolean isFirst = true;
|
||||
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
|
||||
IDIYComponent<?> component = entry.getKey();
|
||||
@@ -715,8 +722,15 @@ public class Presenter implements IPlugInPort {
|
||||
// Nothing to move.
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
controlPoints[index].translate(actualDx, actualDy);
|
||||
}
|
||||
// else {
|
||||
controlPoints[index].translate(actualDx, actualDy);
|
||||
if (controlPoints[index].x < 0 || controlPoints[index].y < 0
|
||||
|| controlPoints[index].x > width
|
||||
|| controlPoints[index].y > height) {
|
||||
// At least one control point went out of bounds.
|
||||
return true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
// For control points that may overlap, just write null,
|
||||
@@ -730,7 +744,7 @@ public class Presenter implements IPlugInPort {
|
||||
for (int j = i + 1; j < controlPoints.length; j++) {
|
||||
if (controlPoints[i] != null && controlPoints[j] != null
|
||||
&& controlPoints[i].equals(controlPoints[j])) {
|
||||
LOG.error("Control points collision detected, cannot make this move.");
|
||||
LOG.warn("Control points collision detected, cannot make this move.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -977,12 +991,22 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Theme getSelectedTheme() {
|
||||
return drawingManager.getTheme();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedTheme(Theme theme) {
|
||||
drawingManager.setTheme(theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the selection with the specified {@link ComponentTransferable}.
|
||||
* Also, updates control point map with all components that are stuck to the
|
||||
@@ -1000,7 +1024,9 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
controlPointMap.put(component, indices);
|
||||
}
|
||||
includeStuckComponents(controlPointMap);
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.STICKY_POINTS_KEY, true)) {
|
||||
includeStuckComponents(controlPointMap);
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents,
|
||||
controlPointMap.keySet());
|
||||
}
|
||||
|
||||
+29
@@ -17,6 +17,7 @@ import org.diylc.common.ITask;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.swing.gui.DialogFactory;
|
||||
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
||||
@@ -141,6 +142,10 @@ public class ActionFactory {
|
||||
boolean defaultValue) {
|
||||
return new ConfigAction(plugInPort, title, configKey, defaultValue);
|
||||
}
|
||||
|
||||
public ThemeAction createThemeAction(IPlugInPort plugInPort, Theme theme) {
|
||||
return new ThemeAction(plugInPort, theme);
|
||||
}
|
||||
|
||||
// File menu actions.
|
||||
|
||||
@@ -825,4 +830,28 @@ public class ActionFactory {
|
||||
plugInPort.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ThemeAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
private Theme theme;
|
||||
|
||||
public ThemeAction(IPlugInPort plugInPort, Theme theme) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
this.theme = theme;
|
||||
putValue(AbstractAction.NAME, theme.getName());
|
||||
putValue(IView.RADIO_BUTTON_GROUP_KEY, "theme");
|
||||
putValue(AbstractAction.SELECTED_KEY, plugInPort.getSelectedTheme().getName().equals(
|
||||
theme.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOG.info(getValue(AbstractAction.NAME) + " triggered");
|
||||
plugInPort.setSelectedTheme(theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -15,6 +15,7 @@ import java.util.Map;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JComponent;
|
||||
@@ -23,6 +24,7 @@ import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButtonMenuItem;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.Timer;
|
||||
@@ -62,6 +64,7 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
|
||||
private JMenuBar mainMenuBar;
|
||||
private Map<String, JMenu> menuMap;
|
||||
private Map<String, ButtonGroup> buttonGroupMap;
|
||||
|
||||
private CanvasPlugin canvasPlugin;
|
||||
|
||||
@@ -71,6 +74,7 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
setPreferredSize(new Dimension(800, 600));
|
||||
createBasePanels();
|
||||
menuMap = new HashMap<String, JMenu>();
|
||||
buttonGroupMap = new HashMap<String, ButtonGroup>();
|
||||
setIconImages(Arrays.asList(IconLoader.IconSmall.getImage(), IconLoader.IconMedium
|
||||
.getImage(), IconLoader.IconLarge.getImage()));
|
||||
DialogFactory.getInstance().initialize(this);
|
||||
@@ -239,8 +243,20 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
menu.addSeparator();
|
||||
} else {
|
||||
Boolean isCheckBox = (Boolean) action.getValue(IView.CHECK_BOX_MENU_ITEM);
|
||||
String groupName = (String) action.getValue(IView.RADIO_BUTTON_GROUP_KEY);
|
||||
if (isCheckBox != null && isCheckBox) {
|
||||
menu.add(new JCheckBoxMenuItem(action));
|
||||
} else if (groupName != null) {
|
||||
ButtonGroup group;
|
||||
if (buttonGroupMap.containsKey(groupName)) {
|
||||
group = buttonGroupMap.get(groupName);
|
||||
} else {
|
||||
group = new ButtonGroup();
|
||||
buttonGroupMap.put(groupName, group);
|
||||
}
|
||||
JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
|
||||
group.add(item);
|
||||
menu.add(item);
|
||||
} else {
|
||||
menu.add(action);
|
||||
}
|
||||
|
||||
+2
-2
@@ -112,7 +112,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
private RulerScrollPane getScrollPane() {
|
||||
if (scrollPane == null) {
|
||||
scrollPane = new RulerScrollPane(getCanvasPanel(), new ProjectDrawingProvider(
|
||||
plugInPort, true), (int) new Size(1d, SizeUnit.cm).convertToPixels(), (int) new Size(1d,
|
||||
plugInPort, true), new Size(1d, SizeUnit.cm).convertToPixels(), new Size(1d,
|
||||
SizeUnit.in).convertToPixels());
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY,
|
||||
true);
|
||||
@@ -271,7 +271,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
(int) (visibleRect.y * zoomFactor), visibleRect.width, visibleRect.height);
|
||||
canvasPanel.scrollRectToVisible(visibleRect);
|
||||
canvasPanel.revalidate();
|
||||
|
||||
|
||||
zoomLevel = (Double) params[0];
|
||||
break;
|
||||
case REPAINT:
|
||||
|
||||
+34
@@ -1,13 +1,22 @@
|
||||
package org.diylc.swing.plugins.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.swing.ActionFactory;
|
||||
import org.diylc.swing.ISwingUI;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.xml.DomDriver;
|
||||
|
||||
/**
|
||||
* Controls configuration menu.
|
||||
*
|
||||
@@ -15,7 +24,10 @@ import org.diylc.swing.ISwingUI;
|
||||
*/
|
||||
public class ConfigPlugin implements IPlugIn {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ConfigPlugin.class);
|
||||
|
||||
private static final String CONFIG_MENU = "Config";
|
||||
private static final String THEME_MENU = "Theme";
|
||||
|
||||
private ISwingUI swingUI;
|
||||
|
||||
@@ -30,6 +42,28 @@ public class ConfigPlugin implements IPlugIn {
|
||||
"Anti-Aliasing", IPlugInPort.ANTI_ALIASING_KEY, true), CONFIG_MENU);
|
||||
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
|
||||
"Hi-Quality Rendering", IPlugInPort.HI_QUALITY_RENDER_KEY, false), CONFIG_MENU);
|
||||
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
|
||||
"Sticky Points", IPlugInPort.STICKY_POINTS_KEY, true), CONFIG_MENU);
|
||||
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
|
||||
"Export Grid", IPlugInPort.EXPORT_GRID_KEY, false), CONFIG_MENU);
|
||||
File themeDir = new File("themes");
|
||||
if (themeDir.exists()) {
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
swingUI.injectSubmenu(THEME_MENU, IconLoader.Pens.getIcon(), CONFIG_MENU);
|
||||
for (File file : themeDir.listFiles()) {
|
||||
if (file.getName().toLowerCase().endsWith(".xml")) {
|
||||
try {
|
||||
InputStream in = new FileInputStream(file);
|
||||
Theme theme = (Theme) xStream.fromXML(in);
|
||||
LOG.debug("Found theme: " + theme.getName());
|
||||
swingUI.injectMenuAction(ActionFactory.getInstance().createThemeAction(
|
||||
plugInPort, theme), THEME_MENU);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not load theme file " + file.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
@@ -9,6 +9,7 @@ import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
|
||||
import com.diyfever.gui.IDrawingProvider;
|
||||
import com.diyfever.gui.miscutils.ConfigurationManager;
|
||||
|
||||
/**
|
||||
* {@link IDrawingProvider} implementation that uses {@link IPlugInPort} to draw
|
||||
@@ -33,6 +34,9 @@ public class ProjectDrawingProvider implements IDrawingProvider {
|
||||
if (useZoom) {
|
||||
options.add(DrawOption.ZOOM);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXPORT_GRID_KEY, false)) {
|
||||
options.add(DrawOption.GRID);
|
||||
}
|
||||
plugInPort.draw((Graphics2D) g, options, null);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import java.awt.Toolkit;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final int PIXELS_PER_INCH = 150;
|
||||
public static final int PIXELS_PER_INCH = 200;
|
||||
public static final double PIXEL_SIZE = 1d * PIXELS_PER_INCH
|
||||
/ Toolkit.getDefaultToolkit().getScreenResolution();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user