mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
better measurement
This commit is contained in:
Binary file not shown.
+11
@@ -32,4 +32,15 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closest odd number, i.e. x when x is odd, or x + 1 when x is
|
||||
* even.
|
||||
*
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
protected int getClosestOdd(int x) {
|
||||
return (x / 2) * 2 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -18,7 +18,9 @@ public class Size extends AbstractMeasure<SizeUnit> {
|
||||
|
||||
public int convertToPixels() {
|
||||
double factor = getUnit().getFactor() / SizeUnit.in.getFactor();
|
||||
return (int) Math.round(factor * Constants.PIXELS_PER_INCH * getValue());
|
||||
int grids = (int) (factor * getValue() * Constants.GRIDS_PER_INCH);
|
||||
double remainder = (factor * getValue() * Constants.GRIDS_PER_INCH) - grids;
|
||||
return (int) Math.round(Constants.GRID * (grids + remainder));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.util.Map;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
+7
-1
@@ -3,11 +3,16 @@ package org.diylc.gui.editor;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.measures.AbstractMeasure;
|
||||
|
||||
public class FieldEditorFactory {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(FieldEditorFactory.class);
|
||||
|
||||
public static Component createFieldEditor(PropertyWrapper property) {
|
||||
if (property.getType().equals(String.class)) {
|
||||
StringEditor editor = new StringEditor(property);
|
||||
@@ -30,6 +35,7 @@ public class FieldEditorFactory {
|
||||
ByteEditor byteEditor = new ByteEditor(property);
|
||||
return byteEditor;
|
||||
}
|
||||
return null;
|
||||
LOG.error("Unrecognized parameter type: " + property.getType().getName());
|
||||
return new JLabel("Unrecognized");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -12,8 +12,9 @@ import org.diylc.core.measures.SizeUnit;
|
||||
public class Constants {
|
||||
|
||||
public static final int PIXELS_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution();
|
||||
public static Size GRID_SIZE = new Size(0.1d, SizeUnit.in);
|
||||
public static final int GRID = GRID_SIZE.convertToPixels();
|
||||
public static int GRIDS_PER_INCH = 10;
|
||||
public static Size GRID_SIZE = new Size(1d / GRIDS_PER_INCH, SizeUnit.in);
|
||||
public static final int GRID = 10;
|
||||
|
||||
public static Color CANVAS_COLOR = Color.white;
|
||||
public static Color GRID_COLOR = new Color(240, 240, 240);
|
||||
|
||||
Reference in New Issue
Block a user