[menya] 1 new revision pushed by dpsen...@gmail.com on 2009-08-11 16:25 GMT

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 11, 2009, 12:26:30 PM8/11/09
to menya...@googlegroups.com
Revision: d04b88be0a
Author: dominik
Date: Mon Aug 10 01:12:34 2009
Log: * editable layers introduced
* curve layer is a editable layer
* pdf layer is not (hence only data holder)
* found strange behaviour: we need a pdf layer to be able to write to pdf!?
* another strange behaviour: when loading from pdf, the layers are likely
well initialized but contain no data; all data is stored to the lowest pdf
layer (so it says acroread)
http://code.google.com/p/menya/source/detail?r=d04b88be0a

Added:
/src/main/java/menya/core/document/IEditableLayer.java
/src/main/java/menya/core/document/layers/AEditableLayer.java
Modified:
/docs/CHANGELOG
/log4j-configuration.xml
/src/main/java/menya/core/document/ILayer.java
/src/main/java/menya/core/document/IPage.java
/src/main/java/menya/core/document/layers/ALayer.java
/src/main/java/menya/core/document/layers/CurveLayer.java
/src/main/java/menya/core/document/layers/PDFLayer.java
/src/main/java/menya/core/model/Document.java
/src/main/java/menya/core/model/Page.java
/src/main/java/menya/gui/GUI.java
/src/main/java/menya/gui/SketchPane.java

=======================================
--- /dev/null
+++ /src/main/java/menya/core/document/IEditableLayer.java Mon Aug 10
01:12:34 2009
@@ -0,0 +1,36 @@
+/*
+ * This file is part of Menya.
+ *
+ * Menya is free software: you can redistribute it and/or modify it under
the
+ * terms of the GNU General Public License as published by the Free
Software
+ * Foundation, either version 3 of the License, or (at your option) any
later
+ * version.
+ *
+ * Menya is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
+ *
+ * You should have received a copy of the GNU General Public License along
with
+ * Menya. If not, see <http://www.gnu.org/licenses/>.
+ */
+package menya.core.document;
+
+import menya.core.model.Curve;
+
+/**
+ * This interface marks editable layers and adds methods that take care of
that
+ * functionality.
+ *
+ * @author dominik
+ *
+ */
+public interface IEditableLayer extends ILayer {
+
+ /**
+ * Adds a new curve to the layer.
+ *
+ * @param curve
+ * the curve to add.
+ */
+ public void addCurve(final Curve curve);
+}
=======================================
--- /dev/null
+++ /src/main/java/menya/core/document/layers/AEditableLayer.java Mon Aug
10 01:12:34 2009
@@ -0,0 +1,105 @@
+/*
+ * This file is part of Menya.
+ *
+ * Menya is free software: you can redistribute it and/or modify it under
the
+ * terms of the GNU General Public License as published by the Free
Software
+ * Foundation, either version 3 of the License, or (at your option) any
later
+ * version.
+ *
+ * Menya is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
+ *
+ * You should have received a copy of the GNU General Public License along
with
+ * Menya. If not, see <http://www.gnu.org/licenses/>.
+ */
+package menya.core.document.layers;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import menya.core.document.IEditableLayer;
+import menya.core.document.IPage;
+import menya.core.model.Curve;
+import menya.core.model.GraphicalData;
+import menya.core.model.tools.StandardPen;
+
+import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
+
+/**
+ * @author dominik
+ *
+ */
+public abstract class AEditableLayer extends ALayer implements
IEditableLayer,
+ Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3212596772643865807L;
+
+ /**
+ * Logger for this class.
+ */
+ private static final Logger LOGGER = Logger.getLogger(AEditableLayer.class
+ .toString());
+
+ private List<Curve> curves;
+
+ private transient boolean hasChanged;
+
+ public AEditableLayer() {
+ // this is a editable layer, hence add a pen
+ addPen(new StandardPen());
+ }
+
+ private List<Curve> getCurves() {
+ if (curves == null) {
+ curves = new ArrayList<Curve>();
+ }
+ return curves;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public final IEditableLayer castEditableLayer() {
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ public void addCurve(final Curve curve) {
+ LOGGER.info("adding curve");
+ this.hasChanged = true;
+ getCurves().add(curve);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ public Iterable<GraphicalData> getGraphicalData() {
+ final Iterable<Curve> i = getCurves();
+ final Iterable d = i;
+ this.hasChanged = false;
+ if (d == null) {
+ LOGGER.warning("getGraphicalData() will return null");
+ }
+ return d;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean hasChanged() {
+ return this.hasChanged;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void toPdf(final PDPageContentStream contentStream, final IPage
page)
+ throws IOException {
+ for (final Curve curve : getCurves()) {
+ curve.toPdf(contentStream, page);
+ }
+ }
+}
=======================================
--- /docs/CHANGELOG Wed Aug 5 16:40:33 2009
+++ /docs/CHANGELOG Mon Aug 10 01:12:34 2009
@@ -1,4 +1,6 @@
Version 0.1.1
* added working tool class structure (a general way to describe pens)
+ * moved pens into layers
+ * introduced "editable" layers
Version 0.1.0
* a lots of tests and sandbox coding
=======================================
--- /log4j-configuration.xml Tue Aug 4 04:41:14 2009
+++ /log4j-configuration.xml Mon Aug 10 01:12:34 2009
@@ -4,8 +4,11 @@
<param name="RemoteHost" value="localhost"/>
<param name="Port" value="4445"/>
</appender>
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ </appender>
<root>
<priority value="ALL"/>
<appender-ref ref="socket"/>
+ <appender-ref ref="console"/>
</root>
</log4j:configuration>
=======================================
--- /src/main/java/menya/core/document/ILayer.java Sun Aug 9 01:45:08 2009
+++ /src/main/java/menya/core/document/ILayer.java Mon Aug 10 01:12:34 2009
@@ -42,7 +42,7 @@
*
* @return A Set of graphical data.
*/
- Iterable<GraphicalData> getGraphicalData();
+ public Iterable<GraphicalData> getGraphicalData();

/**
* Simple check if this layer has changed since {@link
#getGraphicalData()}
@@ -133,4 +133,15 @@
* @param pen
*/
public void removePen(IWorkingTool pen);
-}
+
+ /**
+ * is a method to retrieve a editable layer if the method
+ * {@link #isEditable()} returns true. This method is quite useful as
+ * dangerous casting is no longer needed. But be aware, if
+ * {@link #isEditable()} does return false, this method should return null
+ * as it is not possible to get a valid editable layer.
+ *
+ * @return
+ */
+ public IEditableLayer castEditableLayer();
+}
=======================================
--- /src/main/java/menya/core/document/IPage.java Sun Aug 9 01:45:08 2009
+++ /src/main/java/menya/core/document/IPage.java Mon Aug 10 01:12:34 2009
@@ -22,7 +22,6 @@
import java.util.Deque;
import java.util.List;

-import menya.core.document.layers.CurveLayer;
import menya.core.model.IWorkingTool;

/**
@@ -37,7 +36,7 @@
/**
* @return the size of the page in Point.
*/
- Dimension2D getPageSize();
+ public Dimension2D getPageSize();

/**
* retrieves the background layer of this page. Basically would it be the
@@ -46,34 +45,73 @@
*
* @return the background of this document or null if no layers are
present.
*/
- ILayer getBackground();
+ public ILayer getBackground();

/**
* retrieves all layers of this document.
*
* @return the document layers as stack
*/
- Deque<ILayer> getLayers();
+ public Deque<ILayer> getLayers();

/**
- * Retrieves an active curve layer. This method never returns null - if no
- * curve layer is present, a new one must be created.
+ * Retrieves the currently active layer. It is not guaranteed that the
layer
+ * returned by this method is actually a editable layer.
*
- * @return the active curve layer.
+ * @return the active layer.
*/
- CurveLayer getActiveLayer();
+ public ILayer getActiveLayer();

/**
+ * sets the currently active layer. If the layer passed as argument is
not a
+ * valid layer for this page, a {@link IllegalArgumentException} will be
+ * thrown.
+ *
+ * @param layer
+ * @throws IllegalArgumentException
+ */
+ public void setActiveLayer(ILayer layer) throws IllegalArgumentException;
+
+ /**
+ * retrieves the default pen for the currently active layer. This
represents
+ * a convenience method that is deprecated. Please note that this method
may
+ * be removed in future versions. Access the pens through the layers!
+ *
* @return
*/
+ @Deprecated
public IWorkingTool getDefaultPen();

+ /**
+ * retrieves the currently active pen for the currently active layer. This
+ * represents a convenience method that is deprecated. Please note that
this
+ * method may be removed in future versions. Access the pens through the
+ * layers!
+ *
+ * @return
+ */
+ @Deprecated
public IWorkingTool getActivePen();

+ /**
+ * sets the currently active pen for the currently active layer. This
+ * represents a convenience method that is deprecated. Please note that
this
+ * method may be removed in future versions. Access the pens through the
+ * layers!
+ *
+ * @param pen
+ * @throws IllegalArgumentException
+ */
+ @Deprecated
public void setActivePen(IWorkingTool pen) throws
IllegalArgumentException;

/**
+ * retrieves all pens of each layer on this page. This represents a
+ * convenience method that is deprecated. Please note that this method may
+ * be removed in future versions. Access the pens through the layers!
+ *
* @return
*/
+ @Deprecated
public List<IWorkingTool> getAllPens();
}
=======================================
--- /src/main/java/menya/core/document/layers/ALayer.java Sun Aug 9
01:45:08 2009
+++ /src/main/java/menya/core/document/layers/ALayer.java Mon Aug 10
01:12:34 2009
@@ -22,6 +22,7 @@
import java.util.LinkedList;
import java.util.List;

+import menya.core.document.IEditableLayer;
import menya.core.document.ILayer;
import menya.core.model.IWorkingTool;

@@ -35,6 +36,16 @@

private List<IWorkingTool> pens = new LinkedList<IWorkingTool>();
private IWorkingTool activePen;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see menya.core.document.ILayer#castEditableLayer()
+ */
+ @Override
+ public IEditableLayer castEditableLayer() {
+ return null;
+ }

/**
* {@inheritDoc}
@@ -65,7 +76,7 @@
*/
@Override
public final boolean isEditable() {
- return getAllPens().size() > 0;
+ return getAllPens().size() > 0 && castEditableLayer() != null;
}

/**
=======================================
--- /src/main/java/menya/core/document/layers/CurveLayer.java Sun Aug 9
01:45:08 2009
+++ /src/main/java/menya/core/document/layers/CurveLayer.java Mon Aug 10
01:12:34 2009
@@ -18,17 +18,9 @@

package menya.core.document.layers;

-import java.io.IOException;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import menya.core.document.IPage;
-import menya.core.model.Curve;
-import menya.core.model.GraphicalData;
-import menya.core.model.tools.StandardPen;
-
-import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
+
+import menya.core.document.IEditableLayer;

/**
* Represents a layer with curves drawn.
@@ -36,54 +28,8 @@
* @author Max
* @version $Revision$
*/
-public class CurveLayer extends ALayer implements Serializable {
+public class CurveLayer extends AEditableLayer implements IEditableLayer,
+ Serializable {

private static final long serialVersionUID = 1L;
-
- private final List<Curve> curves = new ArrayList<Curve>();
-
- private transient boolean hasChanged;
-
- /**
- * Default constructor.
- */
- public CurveLayer() {
- // this is a editable layer, hence add a pen
- addPen(new StandardPen());
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- public Iterable<GraphicalData> getGraphicalData() {
- final Iterable<Curve> i = this.curves;
- final Iterable d = i;
- this.hasChanged = false;
- return d;
- }
-
- /**
- * Adds a new curve to the layer.
- *
- * @param curve
- * the curve to add.
- */
- public void addCurve(final Curve curve) {
- this.hasChanged = true;
- this.curves.add(curve);
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean hasChanged() {
- return this.hasChanged;
- }
-
- /** {@inheritDoc} */
- @Override
- public void toPdf(final PDPageContentStream contentStream, final IPage
page)
- throws IOException {
- for (final Curve curve : this.curves) {
- curve.toPdf(contentStream, page);
- }
- }
-}
+}
=======================================
--- /src/main/java/menya/core/document/layers/PDFLayer.java Sun Aug 9
01:45:08 2009
+++ /src/main/java/menya/core/document/layers/PDFLayer.java Mon Aug 10
01:12:34 2009
@@ -25,7 +25,6 @@

import menya.core.document.IPage;
import menya.core.model.GraphicalData;
-import menya.core.model.tools.StandardPen;

import org.apache.pdfbox.pdfviewer.PageDrawer;
import org.apache.pdfbox.pdmodel.PDPage;
@@ -64,9 +63,6 @@
this.drawer = pgdrawer;
this.page = pdpage;
this.dimension = pageDimension;
-
- // FIXME is this correct for all pdf layers?
- addPen(new StandardPen());
}

private class PDFGraphics implements GraphicalData {
@@ -79,6 +75,7 @@
@Override
public void draw(final Graphics2D g2d) {
try {
+ LOGGER.info("draw pdf to graphics2d");
PDFLayer.this.drawer.drawPage(g2d, PDFLayer.this.page,
PDFLayer.this.dimension);
} catch (final IOException io) {
=======================================
--- /src/main/java/menya/core/model/Document.java Sun Aug 9 01:45:08 2009
+++ /src/main/java/menya/core/model/Document.java Mon Aug 10 01:12:34 2009
@@ -36,6 +36,7 @@
import menya.core.document.IDocument;
import menya.core.document.ILayer;
import menya.core.document.IPage;
+import menya.core.document.layers.CurveLayer;
import menya.core.document.layers.PDFLayer;

import org.apache.pdfbox.cos.COSArray;
@@ -156,6 +157,7 @@
*/
private void addEmptyPage() {
final Page p = new Page();
+
if (this.pdfDocument != null) {
final Dimension2D pgDimension = p.getPageSize();
final Dimension pageDimension = new Dimension((int) pgDimension
@@ -166,6 +168,11 @@
pageDimension);
p.addLayer(pdfLayer);
}
+
+ // now we add a curve layer so that we can draw on it
+ ILayer curveLayer = new CurveLayer();
+ p.addLayer(curveLayer);
+ p.setActiveLayer(curveLayer);
this.pages.add(p);
}

@@ -288,6 +295,8 @@
int i = 0;
COSBase cb = privateDict.getDictionaryObject(Document
.getLayerName(i));
+
+ boolean gotEditableOne = false;
while (cb instanceof COSString) {
final COSString cs = (COSString) cb;
final byte[] buf = cs.getBytes();
@@ -295,9 +304,17 @@
final ObjectInputStream ois = new ObjectInputStream(bis);
final ILayer layer = (ILayer) ois.readObject();
menyaPage.addLayer(layer);
+ if (layer.isEditable()) {
+ menyaPage.setActiveLayer(layer);
+ gotEditableOne = true;
+ }
i++;
cb = privateDict.getDictionaryObject(Document.getLayerName(i));
}
+
+ if (!gotEditableOne) {
+ menyaPage.addLayer(new CurveLayer());
+ }
} catch (final ClassNotFoundException e) {
throw new IOException("Failed to read embedded Menya Layer", e);
}
=======================================
--- /src/main/java/menya/core/model/Page.java Sun Aug 9 01:45:08 2009
+++ /src/main/java/menya/core/model/Page.java Mon Aug 10 01:12:34 2009
@@ -21,11 +21,11 @@
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
+import java.util.logging.Logger;

import menya.core.Constants;
import menya.core.document.ILayer;
import menya.core.document.IPage;
-import menya.core.document.layers.CurveLayer;

/**
* Default Implementation of a Document.
@@ -35,6 +35,9 @@
*/
public class Page implements IPage {

+ private static final Logger LOGGER = Logger
+ .getLogger(Page.class.toString());
+
/**
*
*/
@@ -52,6 +55,8 @@
(int) (Page.A4_WIDTH * Constants.CM_TO_PT),
(int) (Page.A4_HEIGHT * Constants.CM_TO_PT));

+ private ILayer activeLayer;
+
/**
* Default Constructor.
*/
@@ -66,20 +71,31 @@

/** {@inheritDoc} */
public Deque<ILayer> getLayers() {
+ // TODO alter this to use some sort of unmodifiable Deque
return this.layers.clone();
}

- /** {@inheritDoc} */
- public CurveLayer getActiveLayer() {
- final ILayer top = this.layers.peekLast();
- if (top instanceof CurveLayer) {
- return (CurveLayer) top;
+ public void setActiveLayer(ILayer layer) throws IllegalArgumentException {
+ if (layers.contains(layer)) {
+ activeLayer = layer;
} else {
- final CurveLayer c = new CurveLayer();
- this.layers.add(c);
- return c;
+ throw new IllegalArgumentException(
+ "The layer specified is not part of this document.");
}
}
+
+ /** {@inheritDoc} */
+ public ILayer getActiveLayer() {
+ if (activeLayer == null) {
+ setActiveLayer(layers.peekLast());
+ }
+ return activeLayer;
+ /*
+ * final ILayer top = this.layers.peekLast(); if (top instanceof
+ * CurveLayer) { return (CurveLayer) top; } else { final CurveLayer c =
+ * new CurveLayer(); this.layers.add(c); return c; }
+ */
+ }

/** {@inheritDoc} */
public Dimension2D getPageSize() {
@@ -103,6 +119,7 @@
* the new layer.
*/
public void addLayer(final ILayer layer) {
+ LOGGER.info("addLayer(" + layer + ")");
this.layers.add(layer);
}

=======================================
--- /src/main/java/menya/gui/GUI.java Wed Aug 5 15:01:06 2009
+++ /src/main/java/menya/gui/GUI.java Mon Aug 10 01:12:34 2009
@@ -38,119 +38,120 @@
*/
public final class GUI {

- /**
- * Set to true if we're running under Mac OS X.
- */
- public static final boolean OSX = GUI.isOSX();
-
- /**
- * Logger for this class.
- */
- private static final Logger LOGGER =
Logger.getLogger(GUI.class.toString());
-
- /**
+ /**
+ * Set to true if we're running under Mac OS X.
+ */
+ public static final boolean OSX = GUI.isOSX();
+
+ /**
+ * Logger for this class.
+ */
+ private static final Logger LOGGER =
Logger.getLogger(GUI.class.toString());
+
+ /**
*
*/
- private static final String BASEDIR = "basedir";
-
- /**
+ private static final String BASEDIR = "basedir";
+
+ /**
*
*/
- private static final String JAVA_LIBRARY_PATH = "java.library.path";
-
- /**
- * is the empty private constructor.
- */
- private GUI() {
- // Empty on purpose.
- }
-
- /**
- * retrieves if we are running on OSX.
- *
- * @return true if OSX, false otherwise
- */
- private static boolean isOSX() {
- //$NON-NLS-1$
- return System.getProperty("mrj.version") != null;
- }
-
- /**
- * is the main entry point of the application.
- *
- * @param args
- * arguments to pass
- */
- public static void main(final String[] args) {
- // TODO parse arguments
- // TODO create menya core class (respecting switches/flags passed)
- // TODO load file if wanted by argument
-
- GUI.setLibraryPath();
-
- if (GUI.OSX) {
- //$NON-NLS-1$ //$NON-NLS-2$
- System.setProperty("apple.laf.useScreenMenuBar", "true");
- }
-
- try {
-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (final ClassNotFoundException e) {
- GUI.LOGGER.log(Level.FINE, e.getMessage(), e);
- } catch (final InstantiationException e) {
- GUI.LOGGER.log(Level.FINE, e.getMessage(), e);
- } catch (final IllegalAccessException e) {
- GUI.LOGGER.log(Level.FINE, e.getMessage(), e);
- } catch (final UnsupportedLookAndFeelException e) {
- GUI.LOGGER.log(Level.FINE, e.getMessage(), e);
- }
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- final MainFrame mainFrame = new MainFrame();
- mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- mainFrame.setVisible(true);
- }
- });
- }
-
- /**
- * Sets java.library.path if basedir is set.
- * <p>
- * This methods employs a terrible hack: java.library.path is only
checked
- * when the internal sys_paths variable is null, e.g. once at startup.
In
- * this case, it is reset to null to force re-evaluation of the system
- * variable.
- */
- private static void setLibraryPath() {
- final String oldPath = System.getProperty(GUI.JAVA_LIBRARY_PATH);
- final String basedir = System.getProperty(GUI.BASEDIR);
- if (basedir != null) {
- final StringBuilder newPath = new
StringBuilder(basedir).append(
- File.separatorChar).append("jni");
- if (oldPath != null) {
- newPath.append(File.pathSeparatorChar).append(oldPath);
- }
- try {
- final Class<?> clazz = ClassLoader.class;
- final Field field = clazz.getDeclaredField("sys_paths");
- final boolean accessible = field.isAccessible();
- if (!accessible) {
- field.setAccessible(true);
- }
- field.set(clazz, null);
- field.setAccessible(accessible);
- // CHECKSTYLE:OFF In this case a catch-all is needed due to
- // unpredictable reflection errors!
- } catch (final Throwable e) {
- // CHECKSTYLE:ON
- GUI.LOGGER
- .log(
- Level.INFO,
- "Failed to employ library hack, pen
functionality may be inacessible.",
- e);
- }
-
- System.setProperty(GUI.JAVA_LIBRARY_PATH, newPath.toString());
- }
- }
-}
+ private static final String JAVA_LIBRARY_PATH = "java.library.path";
+
+ /**
+ * is the empty private constructor.
+ */
+ private GUI() {
+ // Empty on purpose.
+ }
+
+ /**
+ * retrieves if we are running on OSX.
+ *
+ * @return true if OSX, false otherwise
+ */
+ private static boolean isOSX() {
+ //$NON-NLS-1$
+ return System.getProperty("mrj.version") != null;
+ }
+
+ /**
+ * is the main entry point of the application.
+ *
+ * @param args
+ * arguments to pass
+ */
+ public static void main(final String[] args) {
+
+ // TODO parse arguments
+ // TODO create menya core class (respecting switches/flags passed)
+ // TODO load file if wanted by argument
+
+ GUI.setLibraryPath();
+
+ if (GUI.OSX) {
+ //$NON-NLS-1$ //$NON-NLS-2$
+ System.setProperty("apple.laf.useScreenMenuBar", "true");
+ }
+
+ try {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ } catch (final ClassNotFoundException e) {
+ GUI.LOGGER.log(Level.FINE, e.getMessage(), e);
+ } catch (final InstantiationException e) {
+ GUI.LOGGER.log(Level.FINE, e.getMessage(), e);
+ } catch (final IllegalAccessException e) {
+ GUI.LOGGER.log(Level.FINE, e.getMessage(), e);
+ } catch (final UnsupportedLookAndFeelException e) {
+ GUI.LOGGER.log(Level.FINE, e.getMessage(), e);
+ }
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ final MainFrame mainFrame = new MainFrame();
+ mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ mainFrame.setVisible(true);
+ }
+ });
+ }
+
+ /**
+ * Sets java.library.path if basedir is set.
+ * <p>
+ * This methods employs a terrible hack: java.library.path is only checked
+ * when the internal sys_paths variable is null, e.g. once at startup. In
+ * this case, it is reset to null to force re-evaluation of the system
+ * variable.
+ */
+ private static void setLibraryPath() {
+ final String oldPath = System.getProperty(GUI.JAVA_LIBRARY_PATH);
+ final String basedir = System.getProperty(GUI.BASEDIR);
+ if (basedir != null) {
+ final StringBuilder newPath = new StringBuilder(basedir).append(
+ File.separatorChar).append("jni");
+ if (oldPath != null) {
+ newPath.append(File.pathSeparatorChar).append(oldPath);
+ }
+ try {
+ final Class<?> clazz = ClassLoader.class;
+ final Field field = clazz.getDeclaredField("sys_paths");
+ final boolean accessible = field.isAccessible();
+ if (!accessible) {
+ field.setAccessible(true);
+ }
+ field.set(clazz, null);
+ field.setAccessible(accessible);
+ // CHECKSTYLE:OFF In this case a catch-all is needed due to
+ // unpredictable reflection errors!
+ } catch (final Throwable e) {
+ // CHECKSTYLE:ON
+ GUI.LOGGER
+ .log(
+ Level.INFO,
+ "Failed to employ library hack, pen functionality may be
inacessible.",
+ e);
+ }
+
+ System.setProperty(GUI.JAVA_LIBRARY_PATH, newPath.toString());
+ }
+ }
+}
=======================================
--- /src/main/java/menya/gui/SketchPane.java Sun Aug 9 01:45:08 2009
+++ /src/main/java/menya/gui/SketchPane.java Mon Aug 10 01:12:34 2009
@@ -38,7 +38,6 @@
import jpen.event.PenAdapter;
import menya.core.document.ILayer;
import menya.core.document.IPage;
-import menya.core.document.layers.CurveLayer;
import menya.core.model.Curve;
import menya.core.model.GraphicalData;
import menya.core.model.Point;
@@ -66,8 +65,6 @@

private final IPage currentPage;

- private final CurveLayer activeLayer;
-
private Curve currentCurve;

private BufferedImage cachedImage;
@@ -80,7 +77,6 @@
*/
public SketchPane(final IPage page) {
this.currentPage = page;
- this.activeLayer = page.getActiveLayer();
// this.addMouseListener(this);
// this.addMouseMotionListener(this);

@@ -189,7 +185,10 @@
}
this.currentCurve.add(p);
// TODO: Smooth Path
- this.activeLayer.addCurve(this.currentCurve);
+ if (currentPage.getActiveLayer().isEditable()) {
+ currentPage.getActiveLayer().castEditableLayer().addCurve(
+ this.currentCurve);
+ }
this.currentCurve = null;
// TODO: Maybe erase path that was drawn during drag.
this.repaint();
@@ -206,15 +205,17 @@
final float posy = pen.getLevelValue(Type.Y);
final float pressure;
if (PKind.Type.STYLUS.equals(pen.getKind().getType())) {
- pressure = currentPage.getActivePen().applyPressureFunction(
- pen.getLevelValue(Type.PRESSURE));
+ pressure = currentPage
+ .getActiveLayer()
+ .getActivePen()
+ .applyPressureFunction(pen.getLevelValue(Type.PRESSURE));
} else {
- pressure = currentPage.getActivePen().applyPressureFunction(
- SketchPane.DEFAULT_PRESSURE);
+ pressure = currentPage.getActiveLayer().getActivePen()
+ .applyPressureFunction(SketchPane.DEFAULT_PRESSURE);
}
// TODO: Improve!
return new Point(posx, posy, pressure
- * currentPage.getActivePen().getMaxWidth());
+ * currentPage.getActiveLayer().getActivePen().getMaxWidth());
} else {
// XXX possible source for a nullpointerexception
LOGGER

Reply all
Reply to author
Forward
0 new messages