pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1684918 - in /pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools: ./ pdfdebugger/colorpane/
Date Thu, 11 Jun 2015 15:26:58 GMT
Author: tilman
Date: Thu Jun 11 15:26:58 2015
New Revision: 1684918

URL: http://svn.apache.org/r1684918
Log:
PDFBOX-2530: show DeviceN colorspace in pane, as done by Khyrul Bashar in GSoC2015

Added:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSDeviceN.java
  (with props)
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/ColorBarCellRenderer.java
  (with props)
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNColorant.java
  (with props)
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNTableModel.java
  (with props)
Modified:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java?rev=1684918&r1=1684917&r2=1684918&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFDebugger.java Thu Jun 11 15:26:58
2015
@@ -60,6 +60,7 @@ import java.io.IOException;
 import java.util.HashSet;
 import java.util.Set;
 import javax.swing.filechooser.FileFilter;
+import org.apache.pdfbox.tools.pdfdebugger.colorpane.CSDeviceN;
 import org.apache.pdfbox.tools.pdfdebugger.colorpane.CSSeparation;
 import org.apache.pdfbox.tools.util.FileOpenSaveDialog;
 import org.apache.pdfbox.tools.pdfdebugger.ui.Tree;
@@ -330,7 +331,7 @@ public class PDFDebugger extends javax.s
      * For now only Separation Color space is shown.
      * @param csNode the special color space containing node.
      */
-    //TODO implement DeviceN and Indexed color spaces related features
+    //TODO implement Indexed color spaces related features
     private void showColorPane(Object csNode)
     {
         if (csNode instanceof MapEntry)
@@ -353,6 +354,10 @@ public class PDFDebugger extends javax.s
                 {
                     jSplitPane1.setRightComponent(new CSSeparation(array).getPanel());
                 }
+                else if (csName.equals(COSName.DEVICEN))
+                {
+                    jSplitPane1.setRightComponent(new CSDeviceN(array).getPanel());
+                }
                 else
                 {
                     if (!jSplitPane1.getRightComponent().equals(jScrollPane2))
@@ -571,9 +576,9 @@ public class PDFDebugger extends javax.s
     {
         System.err.println(
                 "usage: java -jar pdfbox-app-x.y.z.jar PDFDebugger [OPTIONS] <input-file>\n"
+
-                "  -password <password>      Password to decrypt the document\n" +
-                "  <input-file>              The PDF document to be loaded\n"
-                );
+                        "  -password <password>      Password to decrypt the document\n"
+
+                        "  <input-file>              The PDF document to be loaded\n"
+        );
     }
 
     // Variables declaration - do not modify//GEN-BEGIN:variables

Added: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSDeviceN.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSDeviceN.java?rev=1684918&view=auto
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSDeviceN.java
(added)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSDeviceN.java
Thu Jun 11 15:26:58 2015
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.tools.pdfdebugger.colorpane;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.util.Arrays;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import java.io.IOException;
+
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN;
+
+
+/**
+ *@author  Khyrul Bashar.
+ */
+
+/**
+ * A class that provides the necessary UI and functionalities to show the DeviceN color space.
+ */
+public class CSDeviceN
+{
+    private PDDeviceN deviceN;
+    private JScrollPane panel;
+
+    /**
+     * Constructor
+     * @param array COSArray instance that holds DeviceN color space
+     */
+    public CSDeviceN(COSArray array)
+    {
+        try
+        {
+            deviceN = new PDDeviceN(array);
+            DeviceNColorant[] colorants = getColorantData();
+            initUI(colorants);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * Parses the colorant data from the array and return.
+     * @return
+     */
+    private DeviceNColorant[] getColorantData()
+    {
+        int componentCount = deviceN.getNumberOfComponents();
+        DeviceNColorant[] colorants = new DeviceNColorant[componentCount];
+        for (int i=0; i<componentCount; i++)
+        {
+            DeviceNColorant colorant = new DeviceNColorant();
+
+            colorant.setName(deviceN.getColorantNames().get(i));
+            float[] maximum = new float[componentCount];
+            Arrays.fill(maximum, 0);
+            float[] minimum = new float[componentCount];
+            Arrays.fill(minimum,1);
+            maximum[i] = 1;
+            minimum[i] = 0;
+            try
+            {
+                colorant.setMaximum(getColorObj(deviceN.toRGB(maximum)));
+                colorant.setMinimum(getColorObj(deviceN.toRGB(minimum)));
+            }
+            catch (IOException e)
+            {
+                throw new RuntimeException();
+            }
+            colorants[i] = colorant;
+        }
+        return colorants;
+    }
+
+    private void initUI(DeviceNColorant[] colorants)
+    {
+        DeviceNTableModel tableModel = new DeviceNTableModel(colorants);
+        JTable table = new JTable(tableModel);
+        table.setDefaultRenderer(Color.class, new ColorBarCellRenderer());
+        table.setRowHeight(60);
+        panel = new JScrollPane();
+        panel.setPreferredSize(new Dimension(300, 500));
+        panel.setViewportView(table);
+    }
+
+    /**
+     * return the main panel that hold all the UI elements.
+     * @return JPanel instance
+     */
+    public Component getPanel()
+    {
+        return panel;
+    }
+
+    private Color getColorObj(float[] rgbValues)
+    {
+        return new Color(rgbValues[0], rgbValues[1], rgbValues[2]);
+    }
+}

Propchange: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/CSDeviceN.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/ColorBarCellRenderer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/ColorBarCellRenderer.java?rev=1684918&view=auto
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/ColorBarCellRenderer.java
(added)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/ColorBarCellRenderer.java
Thu Jun 11 15:26:58 2015
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.tools.pdfdebugger.colorpane;
+
+import java.awt.Color;
+import java.awt.Component;
+import javax.swing.JLabel;
+import javax.swing.JTable;
+import javax.swing.table.TableCellRenderer;
+
+/**
+ * @author Khyrul Bashar.
+ */
+
+/**
+ * ColorBarCellRenderer class that says how to render color bar columns
+ */
+public class ColorBarCellRenderer implements TableCellRenderer
+{
+    @Override
+    public Component getTableCellRendererComponent(
+            JTable jTable, Object o, boolean b, boolean b2, int i, int i2)
+    {
+        JLabel colorBar = new JLabel();
+        colorBar.setOpaque(true);
+        colorBar.setBackground((Color) o);
+        return colorBar;
+    }
+}

Propchange: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/ColorBarCellRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNColorant.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNColorant.java?rev=1684918&view=auto
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNColorant.java
(added)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNColorant.java
Thu Jun 11 15:26:58 2015
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.tools.pdfdebugger.colorpane;
+
+import java.awt.Color;
+
+/**
+ * @author Khyrul Bashar.
+ */
+public class DeviceNColorant
+{
+    private String name;
+    private Color maximum;
+    private Color minimum;
+
+    /**
+     * Constructor
+     */
+    public DeviceNColorant()
+    {
+    }
+
+    /**
+     * Constructor
+     * @param colorantName String instance
+     * @param maxi maximum color
+     * @param mini minimum color
+     */
+    public DeviceNColorant(String colorantName, Color maxi, Color mini)
+    {
+        name = colorantName;
+        maximum = maxi;
+        minimum = mini;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public Color getMaximum()
+    {
+        return maximum;
+    }
+
+    public void setMaximum(Color maximum)
+    {
+        this.maximum = maximum;
+    }
+
+    public Color getMinimum()
+    {
+        return minimum;
+    }
+
+    public void setMinimum(Color minimum)
+    {
+        this.minimum = minimum;
+    }
+}

Propchange: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNColorant.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNTableModel.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNTableModel.java?rev=1684918&view=auto
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNTableModel.java
(added)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNTableModel.java
Thu Jun 11 15:26:58 2015
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.tools.pdfdebugger.colorpane;
+
+import java.awt.Color;
+import javax.swing.table.AbstractTableModel;
+
+/**
+ * @author Khyrul Bashar.
+ */
+
+/**
+ * This the table model for showing DeviceN color space which extends AbstractTableModel.
+ */
+public class DeviceNTableModel extends AbstractTableModel
+{
+    private final String[] columnNames = new String[]{"Colorant", "Maximum", "Minimum"};
+    private final DeviceNColorant[] data;
+
+    /**
+     * Constructor
+     * @param colorants
+     */
+    public DeviceNTableModel(DeviceNColorant[] colorants)
+    {
+        data = colorants;
+    }
+
+    @Override
+    public int getRowCount()
+    {
+        return data.length;
+    }
+
+    @Override
+    public int getColumnCount()
+    {
+        return columnNames.length;
+    }
+
+    @Override
+    public Object getValueAt(int row, int column)
+    {
+        switch (column)
+        {
+            case 0:
+                return data[row].getName();
+            case 1:
+                return data[row].getMaximum();
+            case 2:
+                return data[row].getMinimum();
+            default:
+                return null;
+        }
+    }
+
+    @Override
+    public String getColumnName(int column)
+    {
+        return columnNames[column];
+    }
+
+    @Override
+    public Class<?> getColumnClass(int columnIndex)
+    {
+        switch (columnIndex)
+        {
+            case 0:
+                return String.class;
+            case 1:
+            case 2:
+                return Color.class;
+            default:
+                return null;
+        }
+    }
+}
\ No newline at end of file

Propchange: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/colorpane/DeviceNTableModel.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message