[izpack-changes] r179 - in izpack-frontend/trunk/src: izpack/frontend/controller/filters izpack/frontend/model/shortcut izpack/frontend/view/components izpack/frontend/view/renderers izpack/frontend/view/stages/configure/panels/shortcut izpack/frontend/view/win32 native res/i18n utils
gumbo at BerliOS
gumbo at berlios.de
Sat Jan 7 08:54:22 CET 2006
Author: gumbo
Date: 2006-01-07 08:54:21 +0100 (Sat, 07 Jan 2006)
New Revision: 179
Added:
izpack-frontend/trunk/src/izpack/frontend/controller/filters/IcoLibFilter.java
izpack-frontend/trunk/src/izpack/frontend/view/renderers/IconRenderer.java
izpack-frontend/trunk/src/izpack/frontend/view/win32/IconChooser.java
izpack-frontend/trunk/src/izpack/frontend/view/win32/NativeIconException.java
izpack-frontend/trunk/src/native/IconFileLoader.cpp
izpack-frontend/trunk/src/native/IconFileLoader.h
izpack-frontend/trunk/src/native/IconFileStructs.h
Modified:
izpack-frontend/trunk/src/izpack/frontend/model/shortcut/Shortcut.java
izpack-frontend/trunk/src/izpack/frontend/view/components/JFileChooserIconPreview.java
izpack-frontend/trunk/src/izpack/frontend/view/renderers/LabelRenderer.java
izpack-frontend/trunk/src/izpack/frontend/view/stages/configure/panels/shortcut/ShortcutView.java
izpack-frontend/trunk/src/izpack/frontend/view/win32/NativeIconAccessor.java
izpack-frontend/trunk/src/native/ErrorCheck.cpp
izpack-frontend/trunk/src/native/Icon.h
izpack-frontend/trunk/src/native/IconLoader.vcproj
izpack-frontend/trunk/src/native/IconSet.cpp
izpack-frontend/trunk/src/native/IconSet.h
izpack-frontend/trunk/src/native/JNIInterface.cpp
izpack-frontend/trunk/src/native/izpack_frontend_view_win32_NativeIconAccessor.h
izpack-frontend/trunk/src/res/i18n/LangResources_en.properties
izpack-frontend/trunk/src/utils/UI.java
Log:
Integrated icon loader into the shortcut dialog
Added: izpack-frontend/trunk/src/izpack/frontend/controller/filters/IcoLibFilter.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/controller/filters/IcoLibFilter.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/izpack/frontend/controller/filters/IcoLibFilter.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -0,0 +1,56 @@
+/*
+ * Created on Jan 5, 2006
+ *
+ * $Id: DLLFilter.java Feb 8, 2004 izpack-frontend
+ * Copyright (C) 2005 Andy Gombos
+ *
+ * File : DLLFilter.java
+ * Description : TODO Add description
+ * Author's email : gumbo at users.berlios.de
+ *
+ * Licensed 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 izpack.frontend.controller.filters;
+
+import izpack.frontend.view.IzPackFrame;
+
+import java.io.File;
+
+import javax.swing.filechooser.FileFilter;
+
+public class IcoLibFilter extends FileFilter
+{
+
+ /* (non-Javadoc)
+ * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
+ */
+ public boolean accept(File f)
+ {
+ String name = f.getName().toLowerCase();
+
+ return f.isDirectory() ||
+ name.endsWith("dll") ||
+ name.endsWith("exe") ||
+ name.endsWith("ico");
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.filechooser.FileFilter#getDescription()
+ */
+ public String getDescription()
+ {
+ return IzPackFrame.getInstance().langResources().getText("UI.FileFilters.IcoLib.Desc");
+ }
+
+}
Modified: izpack-frontend/trunk/src/izpack/frontend/model/shortcut/Shortcut.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/model/shortcut/Shortcut.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/izpack/frontend/model/shortcut/Shortcut.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -31,7 +31,7 @@
Document doc;
try
{
- doc = XML.createDocument("unix_shortcutSpec.xml");
+ doc = XML.createDocument("shortcutSpec.xml");
initFromXML(doc.getElementsByTagName("shortcut").item(0));
}
@@ -75,6 +75,17 @@
iconFile = getOptionalAttribute(attributes, "iconFile");
+ try
+ {
+ iconIndex = Integer.parseInt(getOptionalAttribute(attributes, "iconIndex"));
+ }
+ catch (NumberFormatException nfe)
+ {
+ //Catch so the program doesn't crash for a bad input file
+ //TODO maybe tell user
+ iconIndex = 0;
+ }
+
String initialStateStr = getOptionalAttribute(attributes, "initialState");
for (INITIAL_STATE state : INITIAL_STATE.values())
{
@@ -137,7 +148,8 @@
private String description;
// Main functionality on Windows
- private String iconFile;
+ private String iconFile;
+ private int iconIndex;
private INITIAL_STATE initialState;
private boolean programGroup;
private boolean desktop;
@@ -355,4 +367,16 @@
firePropertyChange("modelledOS", null, modelledOS);
}
+
+ public int getIconIndex()
+ {
+ return iconIndex;
+ }
+
+ public void setIconIndex(int iconIndex)
+ {
+ this.iconIndex = iconIndex;
+
+ firePropertyChange("iconIndex", null, iconIndex);
+ }
}
Modified: izpack-frontend/trunk/src/izpack/frontend/view/components/JFileChooserIconPreview.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/view/components/JFileChooserIconPreview.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/izpack/frontend/view/components/JFileChooserIconPreview.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -14,6 +14,10 @@
package izpack.frontend.view.components;
+import izpack.frontend.view.renderers.IconRenderer;
+import izpack.frontend.view.win32.NativeIconAccessor;
+import izpack.frontend.view.win32.NativeIconException;
+
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
@@ -26,30 +30,44 @@
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
+import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
+import javax.swing.JList;
import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.SwingConstants;
public class JFileChooserIconPreview extends JPanel implements
PropertyChangeListener
{
- private JLabel label;
- private int maxImgWidth;
+ private JComponent iconDisplay = new JPanel();
+ private int maxImgWidth = 64;
public JFileChooserIconPreview()
- {
+ {
+ JLabel label;
+
setLayout(new BorderLayout(5, 5));
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- add(new JLabel("Preview:"), BorderLayout.NORTH);
- label = new JLabel();
- label.setBackground(Color.WHITE);
- label.setOpaque(true);
- label.setPreferredSize(new Dimension(72, 72));
+ add(label = new JLabel("Preview:"), BorderLayout.NORTH);
+
+ label.setHorizontalAlignment(SwingConstants.CENTER);
+
+ add(iconDisplay, BorderLayout.CENTER);
+ }
+
+ private void configurePreview(JComponent preview)
+ {
+ preview.setBackground(Color.WHITE);
+ preview.setOpaque(true);
+ //preview.setPreferredSize(new Dimension(72, 144));
+ preview.setBorder(BorderFactory.createEtchedBorder());
+
maxImgWidth = 64;
- label.setBorder(BorderFactory.createEtchedBorder());
- add(label, BorderLayout.CENTER);
}
public void propertyChange(PropertyChangeEvent evt)
@@ -61,36 +79,113 @@
File newFile = (File) evt.getNewValue();
if (newFile != null)
{
- String path = newFile.getAbsolutePath();
-
- // TODO other icon types here
- if (path.endsWith(".ico") || path.endsWith(".png"))
+ String filename = newFile.getAbsolutePath().toLowerCase();
+
+ String internalFmtNames[] = ImageIO.getReaderFormatNames();
+
+ for (String fmt : internalFmtNames)
{
- try
+ //If the internal Java stuff can read our image
+ if (filename.endsWith(fmt))
{
- BufferedImage img = ImageIO.read(newFile);
- float width = img.getWidth();
- float height = img.getHeight();
- float scale = height / width;
- width = maxImgWidth;
- height = (width * scale); // height should be scaled
- // from new width
- icon = new ImageIcon(img.getScaledInstance(Math.max(1,
- (int) width),
- Math.max(1, (int) height),
- Image.SCALE_SMOOTH));
+ iconDisplay.removeAll();
+ iconDisplay.add(previewJavaIcon(newFile));
}
- catch (IOException e)
- {
- // couldn't read image.
- }
}
+
+ //If the file is a set of Windows Icons
+ if (filename.endsWith("dll") || filename.endsWith("exe") || filename.endsWith("ico"))
+ {
+ iconDisplay.removeAll();
+ iconDisplay.add(previewWindowsIcon(filename));
+ }
+
+ configurePreview((JComponent) iconDisplay.getComponent(0));
}
-
- label.setIcon(icon);
+
+ this.validate();
+ this.invalidate();
this.repaint();
-
}
}
+ private JComponent previewJavaIcon(File file)
+ {
+
+ try
+ {
+ BufferedImage img = ImageIO.read(file);
+
+ //TODO only scale when oversized
+ float width = img.getWidth();
+ float height = img.getHeight();
+ float scale = height / width;
+ width = maxImgWidth;
+ height = (width * scale); // height should be scaled
+ // from new width
+ Icon icon = new ImageIcon(img.getScaledInstance(Math.max(1,
+ (int) width),
+ Math.max(1, (int) height),
+ Image.SCALE_FAST));
+
+ JLabel label = new JLabel(icon);
+
+ return label;
+ }
+ catch (IOException e)
+ {
+ // couldn't read image.
+ }
+
+ return new JLabel("");
+ }
+
+ public JComponent previewWindowsIcon(String filename)
+ {
+ try
+ {
+ NativeIconAccessor ni = new NativeIconAccessor(filename);
+
+ int numIcons = ni.getNumIcons() > 25 ? 25 : ni.getNumIcons();
+
+ JScrollPane scroller = new JScrollPane();
+ JList displayer = new JList();
+
+ scroller.setViewportView(displayer);
+ scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ scroller.setPreferredSize(new Dimension(92, 174));
+
+ displayer.setCellRenderer(new IconRenderer());
+ displayer.setModel(new DefaultListModel());
+
+ DefaultListModel model = (DefaultListModel) displayer.getModel();
+
+ for (int i = 0; i < numIcons; i++)
+ {
+ BufferedImage icon = ni.getIcon(i);
+
+ //Scale if the image is more than maxImgWidth pixels wide
+ if (icon.getWidth() > maxImgWidth)
+ {
+ float ratio = ( (float) maxImgWidth ) / icon.getWidth();
+ int height = (int) (icon.getHeight() * ratio);
+
+ model.addElement(new ImageIcon(
+ icon.getScaledInstance(maxImgWidth, height, BufferedImage.SCALE_FAST)
+ ));
+ }
+ else
+ model.addElement(new ImageIcon(icon));
+ }
+
+ ni.destroy();
+
+ return scroller;
+ }
+ catch (NativeIconException nie)
+ {
+ //No icons in the file
+ return new JLabel("<html>No icons<br>in file");
+ }
+ }
}
Added: izpack-frontend/trunk/src/izpack/frontend/view/renderers/IconRenderer.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/view/renderers/IconRenderer.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/izpack/frontend/view/renderers/IconRenderer.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -0,0 +1,52 @@
+package izpack.frontend.view.renderers;
+import java.awt.Component;
+
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.Icon;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.border.Border;
+import javax.swing.border.SoftBevelBorder;
+/*
+ * Created on Nov 18, 2004
+ *
+ * $Id: LabelRenderer.java Feb 8, 2004 izpack-frontend
+ * Copyright (C) 2005 Andy Gombos
+ *
+ * File : LabelRenderer.java
+ * Description : TODO Add description
+ * Author's email : gumbo at users.berlios.de
+ *
+ * Licensed 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.
+ */
+
+
+/**
+ * @author Andy Gombos
+ */
+public class IconRenderer extends DefaultListCellRenderer
+{
+
+ /* (non-Javadoc)
+ * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
+ */
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
+ {
+ Icon icon = (Icon) value;
+
+ return new JLabel(icon);
+ }
+
+ Border unselected = new SoftBevelBorder(SoftBevelBorder.RAISED);
+ Border selected = new SoftBevelBorder(SoftBevelBorder.LOWERED);
+}
Modified: izpack-frontend/trunk/src/izpack/frontend/view/renderers/LabelRenderer.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/view/renderers/LabelRenderer.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/izpack/frontend/view/renderers/LabelRenderer.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -2,6 +2,7 @@
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
+import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.border.Border;
@@ -40,7 +41,7 @@
* @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
*/
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
- {
+ {
JComponent c = (JComponent) value;
if (isSelected)
c.setBorder(selected);
Modified: izpack-frontend/trunk/src/izpack/frontend/view/stages/configure/panels/shortcut/ShortcutView.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/view/stages/configure/panels/shortcut/ShortcutView.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/izpack/frontend/view/stages/configure/panels/shortcut/ShortcutView.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -23,9 +23,11 @@
package izpack.frontend.view.stages.configure.panels.shortcut;
+import izpack.frontend.controller.filters.IcoLibFilter;
import izpack.frontend.controller.filters.IconFilter;
import izpack.frontend.model.shortcut.Shortcut;
import izpack.frontend.view.components.JFileChooserIconPreview;
+import izpack.frontend.view.win32.IconChooser;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
@@ -43,17 +45,15 @@
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
+import javax.swing.filechooser.FileFilter;
import utils.UI;
-import com.jgoodies.binding.adapter.BasicComponentFactory;
import com.jgoodies.binding.adapter.Bindings;
import com.jgoodies.binding.beans.BeanAdapter;
-import com.jgoodies.binding.beans.PropertyAdapter;
import com.jgoodies.binding.beans.PropertyConnector;
import com.jgoodies.binding.list.SelectionInList;
import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.debug.FormDebugPanel;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import com.jgoodies.forms.layout.FormLayout;
@@ -242,21 +242,48 @@
// TODO Make code not a copy-and-paste from the javalobby article
public void actionPerformed(ActionEvent e)
{
- JFileChooser chooser = new JFileChooser();
+ JFileChooser chooser = new JFileChooser();
+ FileFilter iconFilter = new IcoLibFilter();
+
JFileChooserIconPreview previewPane = new JFileChooserIconPreview();
chooser.setAccessory(previewPane);
chooser.addPropertyChangeListener(previewPane);
- chooser.setFileFilter(new IconFilter());
+ chooser.addChoosableFileFilter(iconFilter);
+ chooser.addChoosableFileFilter(new IconFilter());
if (chooser.showDialog(UI.getApplicationFrame(), "Load icon") == JFileChooser.APPROVE_OPTION)
{
- iconPreviewer = new ImageIcon(chooser.getSelectedFile()
+ //If this is an icon inside a Windows resource, display the chooser
+ if ( iconFilter.accept(chooser.getSelectedFile()) )
+ {
+ IconChooser icoChooser = new IconChooser(chooser.getSelectedFile()
+ .getAbsolutePath());
+ icoChooser.setVisible(true);
+
+ int iconIndex = icoChooser.getSelectedIconIndex();
+
+
+ //-1 means cancel was pressed
+ if (iconIndex != -1)
+ {
+ model.setIconIndex(iconIndex);
+ }
+
+ iconPreviewer = new ImageIcon(icoChooser.getIconImage());
+ }
+ else
+ {
+ //Just a normal image
+ iconPreviewer = new ImageIcon(chooser.getSelectedFile()
.getAbsolutePath());
+ }
+
+ //Add the icon to the preview
+ iconPreview.setIcon(iconPreviewer);
+
icon.setText(chooser.getSelectedFile().getAbsolutePath());
- iconPreview.setIcon(iconPreviewer);
-
validate();
}
}
Added: izpack-frontend/trunk/src/izpack/frontend/view/win32/IconChooser.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/view/win32/IconChooser.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/izpack/frontend/view/win32/IconChooser.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -0,0 +1,244 @@
+/*
+ * Created on Jan 5, 2006 $Id: IconChooser.java Feb 8, 2004 izpack-frontend
+ * Copyright (C) 2005 Andy Gombos File : IconChooser.java Description : TODO Add
+ * description Author's email : gumbo at users.berlios.de Licensed 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 izpack.frontend.view.win32;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.image.BufferedImage;
+import java.util.EventObject;
+
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.DefaultListSelectionModel;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.event.CellEditorListener;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.TableCellEditor;
+
+import utils.UI;
+
+public class IconChooser extends JDialog
+{
+ public IconChooser(String filename)
+ {
+ try
+ {
+ ni = new NativeIconAccessor(filename);
+ }
+ catch (NativeIconException nie)
+ {
+ UI.showError(nie.getMessage(), "Error loading icons");
+
+ return;
+ }
+
+ //Confiugure the table
+ JTable table = new JTable((int) Math.ceil(ni.getNumIcons() / 4.0), 4);
+
+ table.setDefaultRenderer(Object.class, new Renderer());
+ table.setDefaultEditor(Object.class, new SelectingEditor(this));
+
+ table.setShowGrid(false);
+ table.setTableHeader(null);
+ table.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
+ table.setCellSelectionEnabled(true);
+
+ //Add the icons to the table
+ int numIcon = 0;
+
+ for (int y = 0; y < table.getRowCount(); y++)
+ {
+ int maxIconHeight = 0;
+
+ for (int x = 0; x < 4; x++)
+ {
+ if (numIcon < ni.getNumIcons())
+ {
+ Data d = new Data();
+ d.image = ni.getIcon(numIcon);
+ d.index = numIcon;
+
+ table.getModel().setValueAt(d, y, x);
+
+ if (d.image.getHeight() > maxIconHeight)
+ maxIconHeight = d.image.getHeight();
+
+ numIcon++;
+ }
+ }
+
+ table.setRowHeight(y, maxIconHeight + rendererAddHeight);
+ }
+
+ //Try to free up all our intermediate objects
+ Runtime.getRuntime().gc();
+
+ JScrollPane scroll = new JScrollPane(table);
+
+ setLayout(new BorderLayout());
+ getContentPane().add(scroll, BorderLayout.CENTER);
+
+ //Add the information label and the cancel button
+ JPanel infoPanel = new JPanel();
+ JButton cancel;
+
+ infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.X_AXIS));
+
+ infoPanel.add(Box.createHorizontalGlue());
+ infoPanel.add(new JLabel("Double click to select an icon"));
+ infoPanel.add(Box.createHorizontalGlue());
+ infoPanel.add(cancel = new JButton("Cancel"));
+
+ cancel.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ selectedIconIndex = -1;
+ dispose();
+ }
+ });
+
+ getContentPane().add(infoPanel, BorderLayout.SOUTH);
+
+ setModal(true);
+ pack();
+ }
+
+ public int getSelectedIconIndex()
+ {
+ return selectedIconIndex;
+ }
+
+ public BufferedImage getIconImage()
+ {
+ return ni.getIcon(selectedIconIndex);
+ }
+
+ public class Renderer extends DefaultTableCellRenderer
+ {
+ @Override
+ public Component getTableCellRendererComponent(JTable table,
+ Object value, boolean isSelected, boolean hasFocus,
+ int row, int column)
+ {
+ if (value != null)
+ {
+ Data data = (Data) value;
+
+ JPanel panel = new JPanel();
+ JLabel label = new JLabel(new ImageIcon(data.image));
+
+ panel.setLayout(new BorderLayout());
+ panel.setSize(data.image.getWidth(), data.image.getHeight()
+ + rendererAddHeight);
+
+ if (isSelected)
+ panel.setBackground(table.getSelectionBackground());
+ else
+ panel.setBackground(table.getBackground());
+
+ panel.add(label);
+
+ return panel;
+ }
+ else
+ return new JLabel("");
+ }
+ }
+
+ /**
+ * Uses the editing framework to provide a double-click selection behavior
+ *
+ * @author Andy Gombos
+ */
+ public class SelectingEditor implements TableCellEditor
+ {
+ public SelectingEditor(JDialog dialog)
+ {
+ this.dialog = dialog;
+ }
+
+ public Object getCellEditorValue()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isCellEditable(EventObject anEvent)
+ {
+ if (anEvent instanceof MouseEvent)
+ {
+ return ((MouseEvent) anEvent).getClickCount() >= 2;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public boolean shouldSelectCell(EventObject anEvent)
+ {
+ return true;
+ }
+
+ public boolean stopCellEditing()
+ {
+ return true;
+ }
+
+ public void cancelCellEditing()
+ {
+ }
+
+ public void addCellEditorListener(CellEditorListener l)
+ {
+ }
+
+ public void removeCellEditorListener(CellEditorListener l)
+ {
+ }
+
+ public Component getTableCellEditorComponent(JTable table,
+ Object value, boolean isSelected, int row, int column)
+ {
+ //Don't edit, store the cell and close the dialog
+
+ selectedIconIndex = ((Data) value).index;
+ dialog.dispose();
+
+ return new JPanel();
+ }
+
+ private JDialog dialog;
+ }
+
+ public class Data
+ {
+ BufferedImage image;
+ int index;
+ }
+
+ private NativeIconAccessor ni = null;
+ private int rendererAddHeight = 6;
+ private int selectedIconIndex;
+}
Modified: izpack-frontend/trunk/src/izpack/frontend/view/win32/NativeIconAccessor.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/view/win32/NativeIconAccessor.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/izpack/frontend/view/win32/NativeIconAccessor.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -1,6 +1,7 @@
package izpack.frontend.view.win32;
import java.awt.image.BufferedImage;
+import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -29,34 +30,52 @@
public class NativeIconAccessor
{
- public NativeIconAccessor(String filename)
+ public NativeIconAccessor(String filename) throws NativeIconException
{
- boolean successful = initializeIconSet(filename);
+ if (! new File(filename).exists())
+ {
+ throw new NativeIconException("Specified file \"" + filename + "\" does not exist" );
+ }
+ initializeIconSet(filename);
+
NativeIcon ni = getNativeBuffers();
iconBuf = ni.icon;
maskBuf = ni.mask;
+ //Calculate the size of the buffers. a UINT is 4 bytes, and icons
+ bufWidth = ni.width;
+ bufHeight = ni.height;
+
instances.add(this);
}
- public BufferedImage getIcon(int index)
+ public BufferedImage getIcon(int index) throws NativeIconException
{
- getNativeIcon(index);
+ //Check for invalid indexes
+ if (index > getNumIcons())
+ throw new NativeIconException("Icon index is greater than the number of icons in the file");
+ int dimensions[] = getNativeIcon(index);
+
iconBuf.clear();
maskBuf.clear();
// Copy buffer to BufferedImage BufferedImage bi = new
- BufferedImage bi = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
+ BufferedImage bi = new BufferedImage(dimensions[0], dimensions[1], BufferedImage.TYPE_INT_ARGB);
- for (int y = 31; y >= 0; y--)
+ for (int y = bufHeight - 1; y >= 0 ; y--)
{
- for (int x = 0; x < 32; x++)
- {
+ for (int x = 0; x < bufWidth; x++)
+ {
int colorVal = createARGB(iconBuf.getInt(), maskBuf.getInt());
- bi.setRGB(x, y, colorVal);
+ //If the value isn't in the image, don't draw it
+ //VERY inefficient
+ if (x < dimensions[0] && y < dimensions[1])
+ {
+ bi.setRGB(x, y, colorVal);
+ }
}
}
@@ -95,16 +114,24 @@
}
}
- private native boolean initializeIconSet(String filename);
+ public void destroy()
+ {
+ destroyIconSet();
+ instances.remove(this);
+ }
+
+ private native void initializeIconSet(String filename) throws NativeIconException;
private native NativeIcon getNativeBuffers();
public native int getNumIcons();
private native void destroyIconSet();
- private native void getNativeIcon(int index);
+ private native int[] getNativeIcon(int index) throws NativeIconException;
private ByteBuffer iconBuf;
private ByteBuffer maskBuf;
+ private int bufWidth, bufHeight;
+
static
{
System.loadLibrary("IconLoader");
Added: izpack-frontend/trunk/src/izpack/frontend/view/win32/NativeIconException.java
===================================================================
--- izpack-frontend/trunk/src/izpack/frontend/view/win32/NativeIconException.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/izpack/frontend/view/win32/NativeIconException.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -0,0 +1,45 @@
+/*
+ * Created on Jan 5, 2006
+ *
+ * $Id: NativeIconException.java Feb 8, 2004 izpack-frontend
+ * Copyright (C) 2005 Andy Gombos
+ *
+ * File : NativeIconException.java
+ * Description : TODO Add description
+ * Author's email : gumbo at users.berlios.de
+ *
+ * Licensed 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 izpack.frontend.view.win32;
+
+/**
+ * Thrown when something occurs in the native code that causes the icons to fail in reading
+ *
+ * A runtime exception because it may be advantageous to have the automatic error subsystem handle
+ * everything in some cases
+ *
+ * @author Andy Gombos
+ */
+public class NativeIconException extends RuntimeException
+{
+ public NativeIconException()
+ {
+ super();
+ }
+
+ public NativeIconException(String message)
+ {
+ super(message);
+ }
+}
Modified: izpack-frontend/trunk/src/native/ErrorCheck.cpp
===================================================================
--- izpack-frontend/trunk/src/native/ErrorCheck.cpp 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/ErrorCheck.cpp 2006-01-07 07:54:21 UTC (rev 179)
@@ -1,12 +1,34 @@
#include "ErrorCheck.h"
//Make sure the result != 0, if not, throw an exception so there's no messy ifs
-//Use error code
+
void checkResult(BOOL result, char *errorMessage)
{
if (!result)
{
- cout << errorMessage << " Code: " << GetLastError() << endl;
- throw string(errorMessage);
+ LPVOID msgBuf;
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR) &msgBuf,
+ 0,
+ NULL
+ );
+
+ if (errorMessage == NULL)
+ errorMessage = &"";
+
+ string userErrorMessage(errorMessage);
+ string sysErrorMessage((LPTSTR) msgBuf);
+
+ LocalFree(msgBuf);
+
+ string message(userErrorMessage + ": " + sysErrorMessage);
+
+ throw message;
}
}
Modified: izpack-frontend/trunk/src/native/Icon.h
===================================================================
--- izpack-frontend/trunk/src/native/Icon.h 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/Icon.h 2006-01-07 07:54:21 UTC (rev 179)
@@ -5,7 +5,7 @@
class Icon
{
public:
- Icon(HICON tIcon);
+ Icon(HICON tIcon);
HICON getIcon() { return icon; }
int getWidth() { return width; }
Added: izpack-frontend/trunk/src/native/IconFileLoader.cpp
===================================================================
--- izpack-frontend/trunk/src/native/IconFileLoader.cpp 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/IconFileLoader.cpp 2006-01-07 07:54:21 UTC (rev 179)
@@ -0,0 +1,81 @@
+#include "iconfileloader.h"
+#include "IconFileStructs.h"
+#include "ErrorCheck.h"
+
+#include <vector>
+
+IconFileLoader::IconFileLoader(const char *filename)
+: icons()
+{
+ iconFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+ checkResult(iconFile != INVALID_HANDLE_VALUE, "File does not exist");
+
+ ICONDIR iconDirectory;
+ DWORD bytesRead = 0;
+
+
+
+ //Read reserved word
+ BOOL result = ReadFile(iconFile, &iconDirectory.idReserved, sizeof(WORD), &bytesRead, NULL);
+ checkResult(result, "Unable to read header from file");
+
+ //Read resource type
+ result = ReadFile(iconFile, &iconDirectory.idType, sizeof(WORD), &bytesRead, NULL);
+ checkResult(result, "Unable to read header from file");
+
+ if (iconDirectory.idType != 1)
+ throw string("Not an icon file");
+
+ //Read number of icons in file
+ result = ReadFile(iconFile, &iconDirectory.idCount, sizeof(WORD), &bytesRead, NULL);
+ checkResult(result, "Unable to read header from file");
+
+ numIcons = iconDirectory.idCount;
+
+ //Read each icon entry
+ for (int i = 0; i < iconDirectory.idCount; i++)
+ {
+ ICONDIRENTRY icon;
+
+ result = ReadFile(iconFile, &icon, sizeof(ICONDIRENTRY), &bytesRead, NULL);
+
+ checkResult(result, "Unable to read icon directory from file");
+
+ icons.push_back(icon);
+ }
+}
+
+IconFileLoader::~IconFileLoader(void)
+{
+ CloseHandle(iconFile);
+}
+
+int IconFileLoader::getNumIcons()
+{
+ return numIcons;
+}
+
+HICON IconFileLoader::getIcon(int index)
+{
+ return createIconFromFile(icons[index]);
+}
+
+HICON IconFileLoader::createIconFromFile(ICONDIRENTRY icon)
+{
+ DWORD bytesRead;
+
+ byte *iconImage = new byte[icon.dwBytesInRes];
+
+ SetFilePointer(iconFile, icon.dwImageOffset, NULL, FILE_BEGIN);
+
+ BOOL result = ReadFile(iconFile, iconImage, icon.dwBytesInRes, &bytesRead, NULL);
+ checkResult(result, "Unable to load icon data");
+
+ HICON iconHandle = CreateIconFromResourceEx(iconImage, icon.dwBytesInRes, TRUE, 0x00030000, icon.bWidth, icon.bHeight, LR_DEFAULTCOLOR);
+ checkResult(iconHandle != NULL, "Failed to create icon from data");
+
+ delete iconImage;
+
+ return iconHandle;
+}
\ No newline at end of file
Added: izpack-frontend/trunk/src/native/IconFileLoader.h
===================================================================
--- izpack-frontend/trunk/src/native/IconFileLoader.h 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/IconFileLoader.h 2006-01-07 07:54:21 UTC (rev 179)
@@ -0,0 +1,31 @@
+#pragma once
+#include <windows.h>
+#include <string>
+
+#include <fstream>
+#include <iostream>
+
+#include <vector>
+
+#include "IconFileStructs.h"
+
+using namespace std;
+
+class IconFileLoader
+{
+public:
+ IconFileLoader(const char *filename);
+ ~IconFileLoader(void);
+
+ int getNumIcons();
+
+ HICON getIcon(int index);
+
+private:
+ vector<ICONDIRENTRY> icons;
+ HANDLE iconFile;
+
+ int numIcons;
+
+ HICON createIconFromFile(ICONDIRENTRY icon);
+};
Added: izpack-frontend/trunk/src/native/IconFileStructs.h
===================================================================
--- izpack-frontend/trunk/src/native/IconFileStructs.h 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/IconFileStructs.h 2006-01-07 07:54:21 UTC (rev 179)
@@ -0,0 +1,30 @@
+#pragma once
+#include <windows.h>
+
+typedef struct
+{
+ BYTE bWidth; // Width, in pixels, of the image
+ BYTE bHeight; // Height, in pixels, of the image
+ BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
+ BYTE bReserved; // Reserved ( must be 0)
+ WORD wPlanes; // Color Planes
+ WORD wBitCount; // Bits per pixel
+ DWORD dwBytesInRes; // How many bytes in this resource?
+ DWORD dwImageOffset; // Where in the file is this image?
+} ICONDIRENTRY, *LPICONDIRENTRY;
+
+typedef struct
+{
+ WORD idReserved; // Reserved (must be 0)
+ WORD idType; // Resource Type (1 for icons)
+ WORD idCount; // How many images?
+ ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em)
+} ICONDIR, *LPICONDIR;
+
+typedef struct
+{
+ BITMAPINFOHEADER icHeader; // DIB header
+ RGBQUAD icColors[1]; // Color table
+ BYTE icXOR[1]; // DIB bits for XOR mask
+ BYTE icAND[1]; // DIB bits for AND mask
+} ICONIMAGE, *LPICONIMAGE;
Modified: izpack-frontend/trunk/src/native/IconLoader.vcproj
===================================================================
--- izpack-frontend/trunk/src/native/IconLoader.vcproj 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/IconLoader.vcproj 2006-01-07 07:54:21 UTC (rev 179)
@@ -56,28 +56,31 @@
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
- ConfigurationType="1"
- CharacterSet="2">
+ ConfigurationType="2"
+ CharacterSet="2"
+ WholeProgramOptimization="TRUE">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="H:\jdk1.5\include\win32;H:\jdk1.5\include\"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="0"
- WarningLevel="3"
+ WarningLevel="4"
Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="3"/>
+ DebugInformationFormat="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
- OutputFile="$(OutDir)/IconLoader.exe"
+ OutputFile="H:/eclipse/workspace/izpackfrontend/$(ProjectName).dll"
LinkIncremental="1"
- GenerateDebugInformation="TRUE"
+ IgnoreAllDefaultLibraries="FALSE"
+ GenerateDebugInformation="FALSE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
@@ -104,12 +107,20 @@
ConfigurationType="2">
<Tool
Name="VCCLCompilerTool"
- AdditionalIncludeDirectories="H:\jdk1.5\include\win32;H:\jdk1.5\include\"/>
+ OptimizeForProcessor="0"
+ AdditionalIncludeDirectories="H:\jdk1.5\include\win32;H:\jdk1.5\include\"
+ EnableFunctionLevelLinking="TRUE"
+ WarningLevel="4"
+ DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
- OutputFile="H:/eclipse/workspace/izpackfrontend/$(ProjectName).dll"/>
+ OutputFile="H:/eclipse/workspace/izpackfrontend/$(ProjectName).dll"
+ GenerateDebugInformation="TRUE"
+ GenerateMapFile="TRUE"
+ MapExports="TRUE"
+ MapLines="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
@@ -137,6 +148,9 @@
RelativePath="Icon.cpp">
</File>
<File
+ RelativePath="IconFileLoader.cpp">
+ </File>
+ <File
RelativePath="IconSet.cpp">
</File>
<File
@@ -144,6 +158,12 @@
</File>
<File
RelativePath="starter.cpp">
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="TRUE">
+ <Tool
+ Name="VCCLCompilerTool"/>
+ </FileConfiguration>
</File>
</Filter>
<Filter
@@ -156,6 +176,12 @@
RelativePath="Icon.h">
</File>
<File
+ RelativePath="IconFileLoader.h">
+ </File>
+ <File
+ RelativePath="IconFileStructs.h">
+ </File>
+ <File
RelativePath="IconSet.h">
</File>
<File
Modified: izpack-frontend/trunk/src/native/IconSet.cpp
===================================================================
--- izpack-frontend/trunk/src/native/IconSet.cpp 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/IconSet.cpp 2006-01-07 07:54:21 UTC (rev 179)
@@ -2,43 +2,101 @@
#include <iostream>
#include <vector>
#include <fstream>
-#include "3dshade.h"
+#include "IconFileLoader.h"
+
+#include <string.h>
+
using namespace std;
//Load icons into *icons from the filename file, or throw an exception if there's an error
-IconSet::IconSet(string filename)
+IconSet::IconSet(const char *filename)
{
- numIcons = ExtractIconEx(filename.c_str(), -1, NULL, NULL, 1);
+ if (filename == NULL)
+ throw string("Filename is invalid");
+
+ char *lowerFilename = strlwr( strdup(filename) );
+ //If not a .ICO file
+ if (strstr(lowerFilename, "ico") == NULL)
+ {
+ createIconsEXEDLL(filename);
+ }
+ else
+ {
+ createIconsICO(filename);
+ }
+
+ if (numIcons <= 0)
+ throw string("No icons in file");
+
+ //Determine the largest our canvas needs to be
+ getIconDimensions();
+
+ createMemBuffers();
+}
+
+//Free all of our buffers, release the DIB and DC
+void IconSet::destroy()
+{
+ SelectObject(iconContext, oldObjIcon);
+ SelectObject(maskContext, oldObjMask);
+
+ DeleteObject(iconBitmap);
+ DeleteObject(maskBitmap);
+
+ DeleteDC(iconContext);
+ DeleteDC(maskContext);
+
+ //Delete the icon resources
+ vector<Icon>::const_iterator start = icons.begin();
+ vector<Icon>::const_iterator end = icons.end();
+
+ width = height = 0;
+
+ while (start != end)
+ {
+ Icon icon = *start;
+ DestroyIcon( icon.getIcon() );
+
+ start++;
+ }
+
+ pixels = NULL;
+ mask = NULL;
+}
+
+void IconSet::createIconsEXEDLL(const char *filename)
+{
+ numIcons = ExtractIconEx(filename, -1, NULL, NULL, 1);
+
//Make icon store height and width
icons = vector<Icon>();
HICON *tmpIcons = new HICON[numIcons];
//Load the large icons into an array
- numIcons = ExtractIconEx(filename.c_str(), 0, tmpIcons, NULL, numIcons);
+ numIcons = ExtractIconEx(filename, 0, tmpIcons, NULL, numIcons);
for (int i = 0; i < numIcons; i++)
{
- icons.push_back(Icon(tmpIcons[i]));
+ icons.push_back(Icon(tmpIcons[i]));
}
-
- getIconDimensions();
- delete tmpIcons;
-
- createMemBuffers();
+ if (numIcons > 0)
+ delete tmpIcons;
}
-//Free all of our buffers, release the DIB and DC
-void IconSet::destroy()
+void IconSet::createIconsICO(const char *filename)
{
- DeleteObject(iconBitmap);
+ IconFileLoader iconLoader(filename);
- SelectObject(iconContext, oldObjIcon);
+ numIcons = iconLoader.getNumIcons();
- DeleteDC(iconContext);
+ for (int i = 0; i < numIcons; i++)
+ {
+ icons.push_back(Icon(iconLoader.getIcon(i)));
+ }
}
//Loop through all the icons, and figure out the maximum width and height
@@ -47,7 +105,7 @@
vector<Icon>::const_iterator start = icons.begin();
vector<Icon>::const_iterator end = icons.end();
- width = height = 0;
+ width = height = 0;
while (start != end)
{
@@ -63,22 +121,32 @@
}
}
-void IconSet::getIcon(int index)
+int* IconSet::getIcon(int index)
{
+ if (index < 0 || index > numIcons)
+ throw string("Icon index not in range");
+
BOOL result;
//Clear the DC
memset(pixels, 0x0, width * height * sizeof(UINT));
memset(mask, 0x0, width * height * sizeof(UINT));
+ Icon icon = icons[index];
+
//Paint the icon onto the DC
- result = DrawIconEx(iconContext, 0, 0, icons[index].getIcon(), 0, 0, 0, NULL, DI_NORMAL);
+ result = DrawIconEx(iconContext, 0, 0, icon.getIcon(), icon.getWidth(), icon.getHeight(), 0, NULL, DI_NORMAL);
checkResult(result, "Failed to draw icon into memory");
//Paint the icon onto the DC
- result = DrawIconEx(maskContext, 0, 0, icons[index].getIcon(), 0, 0, 0, NULL, DI_MASK);
+ result = DrawIconEx(maskContext, 0, 0, icon.getIcon(), icon.getWidth(), icon.getHeight(), 0, NULL, DI_MASK);
checkResult(result, "Failed to draw icon alpha mask into memory");
//pixels and mask now contain the data
+ int *dimensions = new int[2];
+ dimensions[0] = icon.getWidth();
+ dimensions[1] = icon.getHeight();
+
+ return dimensions;
}
//Create a memory DC of the screen and a DIB for painting
Modified: izpack-frontend/trunk/src/native/IconSet.h
===================================================================
--- izpack-frontend/trunk/src/native/IconSet.h 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/IconSet.h 2006-01-07 07:54:21 UTC (rev 179)
@@ -11,9 +11,9 @@
class IconSet
{
public:
- IconSet(string filename);
+ IconSet(const char *filename);
- void getIcon(int index);
+ int* getIcon(int index);
UINT* getIconPixels()
{
@@ -30,12 +30,12 @@
return numIcons;
}
- int getWidth()
+ int getMaxWidth()
{
return width;
}
- int getHeight()
+ int getMaxHeight()
{
return height;
}
@@ -47,6 +47,9 @@
void fillBitmapHeader(BITMAP *bitmap, BITMAPINFOHEADER *header);
void getIconDimensions();
+ void createIconsEXEDLL(const char *filename);
+ void createIconsICO(const char *filename);
+
int width, height;
int numIcons;
Modified: izpack-frontend/trunk/src/native/JNIInterface.cpp
===================================================================
--- izpack-frontend/trunk/src/native/JNIInterface.cpp 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/JNIInterface.cpp 2006-01-07 07:54:21 UTC (rev 179)
@@ -5,7 +5,7 @@
using namespace std;
IconSet *icons;
-jclass clazz;
+jclass clazz, expClazz;
jmethodID constructor;
/*
@@ -13,19 +13,25 @@
* Method: initializeIconSet
* Signature: (Ljava/lang/String;)Z
*/
-JNIEXPORT jboolean JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_initializeIconSet(JNIEnv *env, jobject obj, jstring sfilename)
-{
- const char *filename = env->GetStringUTFChars(sfilename, false);
+JNIEXPORT void JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_initializeIconSet(JNIEnv *env, jobject obj, jstring sfilename)
+{
+ const char *filename = env->GetStringUTFChars(sfilename, NULL);
- icons = new IconSet(string(filename));
+ clazz = env->FindClass("izpack/frontend/view/win32/NativeIcon");
+ expClazz = env->FindClass("izpack/frontend/view/win32/NativeIconException");
- clazz = env->FindClass("izpack/frontend/view/win32/NativeIcon");
+ constructor = env->GetMethodID(clazz, "<init>", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;II)V");
- constructor = env->GetMethodID(clazz, "<init>", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)V");
+ try
+ {
+ icons = new IconSet(filename);
+ }
+ catch (string message)
+ {
+ env->ThrowNew(expClazz, message.c_str());
+ }
env->ReleaseStringUTFChars(sfilename, filename);
-
- return 0;
}
/*
@@ -34,7 +40,7 @@
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_destroyIconSet(JNIEnv *, jobject)
-{
+{
icons->destroy();
delete icons;
}
@@ -55,21 +61,55 @@
* Signature: ()LNativeIcon;
*/
JNIEXPORT jobject JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_getNativeBuffers(JNIEnv *env, jobject obj)
-{
- jobject iconBuffer = env->NewDirectByteBuffer(icons->getIconPixels(), icons->getWidth() * icons->getHeight() * sizeof(UINT));
- jobject maskBuffer = env->NewDirectByteBuffer(icons->getMaskPixels(), icons->getWidth() * icons->getHeight() * sizeof(UINT));
+{
+ jobject iconBuffer = env->NewDirectByteBuffer(icons->getIconPixels(), icons->getMaxWidth() * icons->getMaxHeight() * sizeof(UINT));
+ jobject maskBuffer = env->NewDirectByteBuffer(icons->getMaskPixels(), icons->getMaxWidth() * icons->getMaxHeight() * sizeof(UINT));
- jobject nativeIcon = env->NewObject(clazz, constructor, iconBuffer, maskBuffer);
+ if (iconBuffer != NULL && maskBuffer != NULL)
+ {
+ //The references go "bad" or something
+ clazz = env->FindClass("izpack/frontend/view/win32/NativeIcon");
+ constructor = env->GetMethodID(clazz, "<init>", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;II)V");
- return nativeIcon;
+ jobject nativeIcon = env->NewObject(clazz, constructor, iconBuffer, maskBuffer, icons->getMaxWidth(), icons->getMaxHeight());
+
+ if (nativeIcon != NULL)
+ return nativeIcon;
+ else
+ env->ThrowNew(expClazz, "Unable to create native icon");
+ }
+ else
+ {
+ env->ThrowNew(expClazz, "Unable to allocate NIO buffers");
+ }
+
+ return NULL;
}
/*
* Class: izpack_frontend_view_win32_NativeIconAccessor
* Method: getNativeIcon
- * Signature: (I)V
+ * Signature: (I)[I
*/
-JNIEXPORT void JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_getNativeIcon(JNIEnv *env, jobject obj, jint index)
+JNIEXPORT jintArray JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_getNativeIcon(JNIEnv *env, jobject obj, jint index)
{
- icons->getIcon(index);
+ int *dimensions = NULL;
+
+ try
+ {
+ dimensions = icons->getIcon(index);
+ }
+ catch (string message)
+ {
+ //I think this makes the native code return here
+ //Nothing is initialized yet
+ env->ThrowNew(expClazz, message.c_str());
+ }
+
+ jintArray javaDimensions = env->NewIntArray(2);
+ env->SetIntArrayRegion(javaDimensions, 0, 2, (const jint*) dimensions);
+
+ delete dimensions;
+
+ return javaDimensions;
}
Modified: izpack-frontend/trunk/src/native/izpack_frontend_view_win32_NativeIconAccessor.h
===================================================================
--- izpack-frontend/trunk/src/native/izpack_frontend_view_win32_NativeIconAccessor.h 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/native/izpack_frontend_view_win32_NativeIconAccessor.h 2006-01-07 07:54:21 UTC (rev 179)
@@ -12,7 +12,7 @@
* Method: initializeIconSet
* Signature: (Ljava/lang/String;)Z
*/
-JNIEXPORT jboolean JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_initializeIconSet
+JNIEXPORT void JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_initializeIconSet
(JNIEnv *, jobject, jstring);
/*
@@ -42,9 +42,9 @@
/*
* Class: izpack_frontend_view_win32_NativeIconAccessor
* Method: getNativeIcon
- * Signature: (I)V
+ * Signature: (I)[I
*/
-JNIEXPORT void JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_getNativeIcon
+JNIEXPORT jintArray JNICALL Java_izpack_frontend_view_win32_NativeIconAccessor_getNativeIcon
(JNIEnv *, jobject, jint);
#ifdef __cplusplus
Modified: izpack-frontend/trunk/src/res/i18n/LangResources_en.properties
===================================================================
--- izpack-frontend/trunk/src/res/i18n/LangResources_en.properties 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/res/i18n/LangResources_en.properties 2006-01-07 07:54:21 UTC (rev 179)
@@ -38,6 +38,7 @@
UI.FileFilters.Icon =
UI.FileFilters.Icon.Desc = Image files (JPG, PNG, GIF)
UI.FileFilters.Image.Desc = Image files (JPG, PNG, GIF)
+UI.FileFilters.IcoLib.Desc = Windows Icon Sets (DLL, EXE, ICO)
UI.FileFilters.Jar.Desc = JAR Files (JAR)
UI.FileFilters.Text.Desc = Text Files (TXT, INI, CONF)
UI.FileFilters.XML.Desc = XML Files (XML, XSL)
Modified: izpack-frontend/trunk/src/utils/UI.java
===================================================================
--- izpack-frontend/trunk/src/utils/UI.java 2005-12-13 17:25:33 UTC (rev 178)
+++ izpack-frontend/trunk/src/utils/UI.java 2006-01-07 07:54:21 UTC (rev 179)
@@ -74,7 +74,6 @@
public static void showError(String message, String title)
{
- System.out.println(UI.getApplicationFrame());
JOptionPane.showMessageDialog(UI.getApplicationFrame(), message, title, JOptionPane.ERROR_MESSAGE);
}
More information about the izpack-changes
mailing list