From e6e2109814828ab6fefbdc0d4521e4bd889aed3e Mon Sep 17 00:00:00 2001 From: goddard Date: Sun, 16 Aug 2020 20:11:56 -0400 Subject: [PATCH 01/25] mass convert mosv1 mostly working Still a few interface related problems need to be fixed, but functionality for mass conversion is done. --- .gitignore | 2 + .../infinity/gui/ProgressCellRenderer.java | 44 + .../infinity/gui/converter/ConvertToMos.java | 968 +++++++++++------- .../infinity/gui/converter/MassConvert.java | 8 + 4 files changed, 635 insertions(+), 387 deletions(-) create mode 100644 src/org/infinity/gui/ProgressCellRenderer.java create mode 100644 src/org/infinity/gui/converter/MassConvert.java diff --git a/.gitignore b/.gitignore index a1397ff1c..322468b26 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ NearInfinity.jar /bin /build /.settings +.idea +NearInfinity.iml diff --git a/src/org/infinity/gui/ProgressCellRenderer.java b/src/org/infinity/gui/ProgressCellRenderer.java new file mode 100644 index 000000000..48c5a7ec5 --- /dev/null +++ b/src/org/infinity/gui/ProgressCellRenderer.java @@ -0,0 +1,44 @@ +package org.infinity.gui; + +import javax.swing.*; +import javax.swing.table.TableCellRenderer; +import java.awt.*; + +public class ProgressCellRenderer extends JProgressBar implements TableCellRenderer { + + /** + * Creates a JProgressBar with the range 0,100. + */ + public ProgressCellRenderer(){ + super(0, 100); + setValue(0); + setString("0%"); + setStringPainted(true); + } + + public Component getTableCellRendererComponent( + JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + + //value is a percentage e.g. 95% + final String sValue = value.toString(); + int index = sValue.indexOf('%'); + if (index != -1) { + int p = 0; + try{ + p = Integer.parseInt(sValue.substring(0, index)); + } + catch(NumberFormatException e) { + System.out.println("Number Format Exception"); + } + + this.setValue(p); + this.setString(sValue); + } + return this; + } +} \ No newline at end of file diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index cc0777f62..cf1eb64b5 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -14,42 +14,33 @@ import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.KeyEvent; +import java.awt.event.*; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.io.File; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Vector; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import javax.imageio.ImageIO; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSpinner; -import javax.swing.JTabbedPane; -import javax.swing.JTextField; -import javax.swing.ProgressMonitor; -import javax.swing.SpinnerNumberModel; -import javax.swing.SwingWorker; +import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; import org.infinity.gui.ChildFrame; +import org.infinity.gui.ProgressCellRenderer; import org.infinity.gui.ViewerUtil; import org.infinity.gui.WindowBlocker; import org.infinity.icon.Icons; @@ -63,188 +54,25 @@ import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; -public class ConvertToMos extends ChildFrame - implements ActionListener, PropertyChangeListener, ChangeListener, FocusListener -{ +public class ConvertToMos extends ChildFrame implements ActionListener, PropertyChangeListener, ChangeListener, FocusListener { private static String currentDir = Profile.getGameRoot().toString(); private JTabbedPane tabPane; - private JTextField tfInputV1, tfOutputV1, tfInputV2, tfOutputV2; + private JTable tfInputTableV1; + private JTable tfOutputTableV1; + private JTextField tfOutputV1, tfInputV2, tfOutputV2; private JButton bInputV1, bOutputV1, bInputV2, bOutputV2, bCompressionHelp; private JButton bConvert, bCancel; private JSpinner sPvrzIndex; private JLabel lPvrzInfo; private JComboBox cbCompression; private JCheckBox cbCompress, cbCloseOnExit; - private SwingWorker, Void> workerConvert; - private WindowBlocker blocker; +// private Task workerConvert; - /** - * Converts an image into a MOS V1 resource. - * @param parent This parameter is needed for the progress monitor only. - * @param img The source image to convert into a MOS resource. - * @param mosFileName The name of the resulting MOS file. - * @param compressed If {@code true}, converts into a compressed BAMC file. - * @param result Returns more specific information about the conversion process. Data placed in the - * first item indicates success, data in the second item indicates failure. - * @param showProgress Specify whether to show a progress monitor (needs a valid 'parent' parameter). - * @return {@code true} if the conversion finished successfully, {@code false} otherwise. - */ - public static boolean convertV1(Component parent, BufferedImage img, String mosFileName, - boolean compressed, List result, boolean showProgress) - { - // checking parameters - if (result == null) { - return false; - } - if (img == null) { - result.add(null); - result.add("No source image specified."); - return false; - } - if (mosFileName == null || mosFileName.isEmpty()) { - result.add(null); - result.add("No output filename specified."); - return false; - } - - // preparing MOS V1 header - int width = img.getWidth(); - int height = img.getHeight(); - int cols = (width + 63) / 64; - int rows = (height + 63) / 64; - int tileCount = cols * rows; - int palOfs = 24; - int tableOfs = palOfs + tileCount*1024; - int dataOfs = tableOfs + tileCount*4; - byte[] dst = new byte[dataOfs + width*height]; - System.arraycopy("MOS V1 ".getBytes(), 0, dst, 0, 8); - DynamicArray.putShort(dst, 8, (short)width); - DynamicArray.putShort(dst, 10, (short)height); - DynamicArray.putShort(dst, 12, (short)cols); - DynamicArray.putShort(dst, 14, (short)rows); - DynamicArray.putInt(dst, 16, 64); - DynamicArray.putInt(dst, 20, palOfs); - - ProgressMonitor progress = null; - try { - String note = "Converting tile %d / %d"; - int progressIndex = 0, progressMax = tileCount; - if (showProgress) { - progress = new ProgressMonitor(parent, "Converting MOS...", - String.format(note, progressIndex, progressMax), 0, progressMax); - progress.setMillisToDecideToPopup(250); - progress.setMillisToPopup(500); - } - - // creating list of tiles as int[] arrays - List tileList = new ArrayList(cols*rows); - for (int y = 0; y < rows; y++) { - for (int x = 0; x < cols; x++) { - int tileX = x * 64; - int tileY = y * 64; - int tileW = (tileX + 64 < width) ? 64 : (width - tileX); - int tileH = (tileY + 64 < height) ? 64 : (height - tileY); - int[] rgbArray = new int[tileW*tileH]; - img.getRGB(tileX, tileY, tileW, tileH, rgbArray, 0, tileW); - tileList.add(rgbArray); - } - } - - // applying color reduction to each tile - int[] palette = new int[255]; - byte[] tilePalette = new byte[1024]; - byte[] tileData = new byte[64*64]; - int curPalOfs = palOfs, curTableOfs = tableOfs, curDataOfs = dataOfs; - IntegerHashMap colorCache = new IntegerHashMap(1536); // caching RGBColor -> index - for (int tileIdx = 0; tileIdx < tileList.size(); tileIdx++) { - colorCache.clear(); - if (showProgress) { - if (progress.isCanceled()) { - dst = null; - result.add(null); - result.add("Conversion has been cancelled."); - return false; - } - progressIndex++; - if ((progressIndex % 10) == 0) { - progress.setProgress(progressIndex); - progress.setNote(String.format(note, progressIndex, progressMax)); - } - } - - int[] pixels = tileList.get(tileIdx); - if (ColorConvert.medianCut(pixels, 255, palette, true)) { - // filling palette - // first palette entry denotes transparency - tilePalette[0] = tilePalette[2] = tilePalette[3] = 0; tilePalette[1] = (byte)255; - for (int i = 1; i < 256; i++) { - tilePalette[(i << 2) + 0] = (byte)(palette[i - 1] & 0xff); - tilePalette[(i << 2) + 1] = (byte)((palette[i - 1] >>> 8) & 0xff); - tilePalette[(i << 2) + 2] = (byte)((palette[i - 1] >>> 16) & 0xff); - tilePalette[(i << 2) + 3] = 0; - colorCache.put(palette[i - 1], (byte)(i - 1)); - } - // filling pixel data - for (int i = 0; i < pixels.length; i++) { - if ((pixels[i] & 0xff000000) == 0) { - tileData[i] = 0; - } else { - Byte palIndex = colorCache.get(pixels[i]); - if (palIndex != null) { - tileData[i] = (byte)(palIndex + 1); - } else { - byte color = (byte)ColorConvert.nearestColorRGB(pixels[i], palette, true); - tileData[i] = (byte)(color + 1); - colorCache.put(pixels[i], color); - } - } - } - } else { - // error handling - dst = null; - result.add(null); - result.add(String.format("Error processing tile #%d. Conversion cancelled.", tileIdx)); - return false; - } - - System.arraycopy(tilePalette, 0, dst, curPalOfs, 1024); - curPalOfs += 1024; - DynamicArray.putInt(dst, curTableOfs, curDataOfs - dataOfs); - curTableOfs += 4; - System.arraycopy(tileData, 0, dst, curDataOfs, pixels.length); - curDataOfs += pixels.length; - } - tileList.clear(); tileList = null; - tileData = null; tilePalette = null; /*hclPalette = null;*/ palette = null; - - // optionally compressing to MOSC V1 - if (compressed) { - dst = Compressor.compress(dst, "MOSC", "V1 "); - } - - // writing MOS file to disk - Path mosFile = FileManager.resolve(mosFileName); - try (OutputStream os = StreamUtils.getOutputStream(mosFile, true)) { - os.write(dst); - } catch (Exception e) { - e.printStackTrace(); - result.add(null); - result.add("Error writing TIS file to disk."); - return false; - } - } finally { - // some cleaning up - if (showProgress) { - progress.close(); - progress = null; - } - } - - // generating conversion summary - result.add("Conversion finished successfully."); - return true; - } + private DefaultTableModel inputTableModel; + private DefaultTableModel outputTableModel; + private JScrollPane spInputScroll; + private JScrollPane spOutputScroll; /** * Converts an image into a MOS V2 resource. @@ -328,8 +156,8 @@ public static boolean convertV2(Component parent, BufferedImage img, String mosF // register page entry MosEntry entry = new MosEntry(pvrzIndex + pageIdx, - new Point(rectMatch.x, rectMatch.y), - w, h, new Point(x, y)); + new Point(rectMatch.x, rectMatch.y), + w, h, new Point(x, y)); entryList.add(entry); // advance scanning @@ -346,8 +174,8 @@ public static boolean convertV2(Component parent, BufferedImage img, String mosF if (pvrzIndex + pageList.size() > 100000) { result.add(null); result.add(String.format("One or more PVRZ indices exceed the max. possible value of 99999.\n" + - "Please choose a start index smaller than or equal to %d.", - 100000 - pageList.size())); + "Please choose a start index smaller than or equal to %d.", + 100000 - pageList.size())); return false; } @@ -386,7 +214,7 @@ public static boolean convertV2(Component parent, BufferedImage img, String mosF // generating PVRZ files if (!createPvrzPages(mosFile.getParent(), img, dxtType, pageList, entryList, - result, progress)) { + result, progress)) { return false; } } finally { @@ -407,11 +235,11 @@ public static boolean convertV2(Component parent, BufferedImage img, String mosF private static FileNameExtensionFilter[] getInputFilters() { FileNameExtensionFilter[] filters = new FileNameExtensionFilter[] { - new FileNameExtensionFilter("Graphics files (*.bmp, *.png, *,jpg, *.jpeg)", - "bam", "bmp", "png", "jpg", "jpeg"), - new FileNameExtensionFilter("BMP files (*.bmp)", "bmp"), - new FileNameExtensionFilter("PNG files (*.png)", "png"), - new FileNameExtensionFilter("JPEG files (*.jpg, *.jpeg)", "jpg", "jpeg") + new FileNameExtensionFilter("Graphics files (*.bmp, *.png, *,jpg, *.jpeg)", + "bam", "bmp", "png", "jpg", "jpeg"), + new FileNameExtensionFilter("BMP files (*.bmp)", "bmp"), + new FileNameExtensionFilter("PNG files (*.png)", "png"), + new FileNameExtensionFilter("JPEG files (*.jpg, *.jpeg)", "jpg", "jpeg") }; return filters; } @@ -514,7 +342,12 @@ private static boolean createPvrzPages(Path path, BufferedImage img, DxtEncoder. public ConvertToMos() { super("Convert to MOS", true); - init(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + init(); + } + }); } //--------------------- Begin Class ChildFrame --------------------- @@ -527,6 +360,253 @@ protected boolean windowClosing(boolean forced) throws Exception } //--------------------- End Class ChildFrame --------------------- +class TaskPropertyChange implements PropertyChangeListener { + public int fileCount = 0; + public void setFileCount(int fileCount) { + this.fileCount = fileCount; + } + + @Override + public void propertyChange(PropertyChangeEvent event) { + if ("progress" == event.getPropertyName()) { + Integer progressIndex = (Integer) event.getNewValue(); + tfOutputTableV1.setValueAt(progressIndex +"%", fileCount, 1); + } + } +} + + class Task extends SwingWorker, Integer> { + public String inputPath; + public String getInputPath() { + return inputPath; + } + + public void setInputPath(String inputPath) { + this.inputPath = inputPath; + } + + public Integer fileCount; + public Integer getFileCount() { + return fileCount; + } + + public void setFileCount(Integer fileCount) { + this.fileCount = fileCount; + } + + public Integer progressIndex; + public Integer getProgressIndex() { + return progressIndex; + } + + /** + * Converts an image into a MOS V1 resource. + * @param parent This parameter is needed for the progress monitor only. + * @param img The source image to convert into a MOS resource. + * @param mosFileName The name of the resulting MOS file. + * @param compressed If {@code true}, converts into a compressed BAMC file. + * @param result Returns more specific information about the conversion process. Data placed in the + * first item indicates success, data in the second item indicates failure. + * @return {@code true} if the conversion finished successfully, {@code false} otherwise. + */ + public boolean convertV1(BufferedImage img, String mosFileName, boolean compressed, List result) + { + // checking parameters + if (result == null) { + return false; + } + if (img == null) { + result.add(null); + result.add("No source image specified."); + return false; + } + if (mosFileName == null || mosFileName.isEmpty()) { + result.add(null); + result.add("No output filename specified."); + return false; + } + + // preparing MOS V1 header + int width = img.getWidth(); + int height = img.getHeight(); + int cols = (width + 63) / 64; + int rows = (height + 63) / 64; + int tileCount = cols * rows; + int palOfs = 24; + int tableOfs = palOfs + tileCount*1024; + int dataOfs = tableOfs + tileCount*4; + byte[] dst = new byte[dataOfs + width*height]; + System.arraycopy("MOS V1 ".getBytes(), 0, dst, 0, 8); + DynamicArray.putShort(dst, 8, (short)width); + DynamicArray.putShort(dst, 10, (short)height); + DynamicArray.putShort(dst, 12, (short)cols); + DynamicArray.putShort(dst, 14, (short)rows); + DynamicArray.putInt(dst, 16, 64); + DynamicArray.putInt(dst, 20, palOfs); + + try { + String note = "Converting tile %d / %d"; + double progressIndexPer = 0, progressMaxPer = 0; + int progressIndex = 0, progressMax = tileCount; + + // creating list of tiles as int[] arrays + List tileList = new ArrayList(cols*rows); + for (int y = 0; y < rows; y++) { + for (int x = 0; x < cols; x++) { + int tileX = x * 64; + int tileY = y * 64; + int tileW = (tileX + 64 < width) ? 64 : (width - tileX); + int tileH = (tileY + 64 < height) ? 64 : (height - tileY); + int[] rgbArray = new int[tileW*tileH]; + img.getRGB(tileX, tileY, tileW, tileH, rgbArray, 0, tileW); + tileList.add(rgbArray); + } + } + + // applying color reduction to each tile + int[] palette = new int[255]; + byte[] tilePalette = new byte[1024]; + byte[] tileData = new byte[64*64]; + int curPalOfs = palOfs, curTableOfs = tableOfs, curDataOfs = dataOfs; + IntegerHashMap colorCache = new IntegerHashMap(1536); // caching RGBColor -> index + for (int tileIdx = 0; tileIdx < tileList.size(); tileIdx++) { + colorCache.clear(); + + progressIndex++; + progressIndexPer = progressIndex; + progressMaxPer = progressMax; + double percentage = Math.round((progressIndexPer / progressMaxPer) * 100); + System.out.println(progressIndex + " " + percentage); + setProgress((int)percentage); + + int[] pixels = tileList.get(tileIdx); + if (ColorConvert.medianCut(pixels, 255, palette, true)) { + // filling palette + // first palette entry denotes transparency + tilePalette[0] = tilePalette[2] = tilePalette[3] = 0; tilePalette[1] = (byte)255; + for (int i = 1; i < 256; i++) { + tilePalette[(i << 2) + 0] = (byte)(palette[i - 1] & 0xff); + tilePalette[(i << 2) + 1] = (byte)((palette[i - 1] >>> 8) & 0xff); + tilePalette[(i << 2) + 2] = (byte)((palette[i - 1] >>> 16) & 0xff); + tilePalette[(i << 2) + 3] = 0; + colorCache.put(palette[i - 1], (byte)(i - 1)); + } + // filling pixel data + for (int i = 0; i < pixels.length; i++) { + if ((pixels[i] & 0xff000000) == 0) { + tileData[i] = 0; + } else { + Byte palIndex = colorCache.get(pixels[i]); + if (palIndex != null) { + tileData[i] = (byte)(palIndex + 1); + } else { + byte color = (byte)ColorConvert.nearestColorRGB(pixels[i], palette, true); + tileData[i] = (byte)(color + 1); + colorCache.put(pixels[i], color); + } + } + } + } else { + // error handling + dst = null; + result.add(null); + result.add(String.format("Error processing tile #%d. Conversion cancelled.", tileIdx)); + return false; + } + + System.arraycopy(tilePalette, 0, dst, curPalOfs, 1024); + curPalOfs += 1024; + DynamicArray.putInt(dst, curTableOfs, curDataOfs - dataOfs); + curTableOfs += 4; + System.arraycopy(tileData, 0, dst, curDataOfs, pixels.length); + curDataOfs += pixels.length; + } + tileList.clear(); tileList = null; + tileData = null; tilePalette = null; /*hclPalette = null;*/ palette = null; + + // optionally compressing to MOSC V1 + if (compressed) { + dst = Compressor.compress(dst, "MOSC", "V1 "); + } + + // writing MOS file to disk + Path mosFile = FileManager.resolve(mosFileName); + try (OutputStream os = StreamUtils.getOutputStream(mosFile, true)) { + os.write(dst); + } catch (Exception e) { + e.printStackTrace(); + result.add(null); + result.add("Error writing TIS file to disk."); + return false; + } + } finally { + + } + + // generating conversion summary + result.add("Conversion finished successfully."); + return true; + } + + @Override + protected void process(java.util.List c) { + int lastValue = c.get(c.size()-1); +// outputTableModel.setValueAt(c, fileCount, 1); +// outputTableModel.setValueAt(lastValue, fileCount, 1); +// tfOutputTableV1.setModel(outputTableModel); +// tfOutputTableV1.getModel().setValueAt(lastValue, fileCount, 1); //currentTask +// tfOutputTableV1.updateUI(); + + +// tfOutputTableV1.setValueAt(lastValue, fileCount, 1); //currentTask + System.out.println("Process C Value " + lastValue); + } + + public void setProgressIndex(Integer progressIndex) { + setProgress(this.progressIndex); + this.progressIndex = progressIndex; +// Double percentage = ((double)this.progressIndex / (double)this.progressMax) * 100; +// System.out.println("Progress " + this.progressIndex + " Total Tiles " + this.progressMax + " File Index " + fileCount + " Percentage " + Math.round(percentage)); +// DefaultTableModel df = (DefaultTableModel)tfOutputTableV1.getModel(); +// tfOutputTableV1.getModel().setValueAt(Math.round(percentage), fileCount, 1); //currentTask +// tfOutputTableV1.setValueAt(Math.round(percentage) + "%", fileCount, 1); //currentTask +// outputTableModel.setValueAt(Math.round(percentage), fileCount, 1); +// df.fireTableCellUpdated(fileCount, 1); +// tfOutputTableV1.setModel(df); +// publish(((int) Math.round(percentage))); +// tfOutputTableV1 +// tfOutputTableV1.getModel().fireTableCellUpdated(); +// tfOutputTableV1.updateUI(); //fireTableChanged + } + + public Integer progressMax; + public Integer getProgressMax() { + return progressMax; + } + + public void setProgressMax(Integer progressMax) { + this.progressMax = progressMax; + } + + public Task(String inputPath, Integer fileCount) { + this.inputPath = inputPath; + this.fileCount = fileCount; + + this.progressIndex = 0; + this.progressMax = 100; + } + + @Override + public List doInBackground() { + return convert(this); + } + + @Override + protected void done() { + super.done(); + setProgress(100); + } + } //--------------------- Begin Interface ActionListener --------------------- @@ -534,71 +614,68 @@ protected boolean windowClosing(boolean forced) throws Exception public void actionPerformed(ActionEvent event) { if (event.getSource() == bConvert) { - if (workerConvert == null) { final String msg = "MOS output file already exists. Overwrite?"; - Path file = null; - do { - if (tabPane.getSelectedIndex() == 0 && !tfOutputV1.getText().isEmpty()) { - file = FileManager.resolve(tfOutputV1.getText()); - } else if (tabPane.getSelectedIndex() == 1 & !tfOutputV2.getText().isEmpty()) { - file = FileManager.resolve(tfOutputV2.getText()); - } - if (file != null) { - if (!Files.exists(file) || - JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, msg, "Question", - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE)) { + //loop over each file being converted + int fileCount = 0; + for (String inputPath : this.getTableInputPaths()) { + Path file = null; + if (tabPane.getSelectedIndex() == 0 && !inputPath.isEmpty()) { + file = FileManager.resolve(getTableOutputNames().get(fileCount)); + } else if (tabPane.getSelectedIndex() == 1 & !tfOutputV2.getText().isEmpty()) { + file = FileManager.resolve(tfOutputV2.getText()); + } + + if (file != null) { + if (!Files.exists(file) || JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, msg, "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)) { + file = null; + Task workerConvert = new Task(inputPath, fileCount); + TaskPropertyChange taskPropertyChange = new TaskPropertyChange(); + taskPropertyChange.setFileCount(fileCount); + workerConvert.addPropertyChangeListener(taskPropertyChange); + workerConvert.execute(); + } file = null; - workerConvert = new SwingWorker, Void>() { - @Override - public List doInBackground() - { - return convert(); - } - }; - workerConvert.addPropertyChangeListener(this); - blocker = new WindowBlocker(this); - blocker.setBlocked(true); - workerConvert.execute(); } - file = null; - } - } while (file != null); - } + fileCount++; + } + } else if (event.getSource() == bCancel) { hideWindow(); + } else if (event.getSource() == tfInputTableV1) { + } else if (event.getSource() == bInputV1 || event.getSource() == bInputV2) { - String fileName = tfInputV1.getText().isEmpty() ? currentDir : tfInputV1.getText(); - Path file = FileManager.resolve(fileName).toAbsolutePath(); - if ((fileName = getImageFileName(file)) != null) { - file = FileManager.resolve(fileName).toAbsolutePath(); - currentDir = file.getParent().toString(); - tfInputV1.setText(fileName); - tfInputV2.setText(fileName); - if (tfOutputV1.getText().isEmpty()) { - fileName = StreamUtils.replaceFileExtension(fileName, "MOS"); - tfOutputV1.setText(fileName); - tfOutputV2.setText(fileName); + String fileName = currentDir; + + File[] filePaths = getImageFileName(); + if (filePaths != null) { + for(File fileSelected : filePaths) { + System.out.println(fileSelected.getName()); + inputTableModel.addRow(new Object[] { fileSelected.getAbsolutePath()}); + + fileName = StreamUtils.replaceFileExtension(fileSelected.getName(), "MOS"); + outputTableModel.addRow(new Object[] { fileName, 0 }); + bConvert.setEnabled(isReady()); } - bConvert.setEnabled(isReady()); } + } else if (event.getSource() == bOutputV1 || event.getSource() == bOutputV2) { String fileName = tfOutputV1.getText().isEmpty() ? currentDir : tfOutputV1.getText(); Path file = FileManager.resolve(fileName).toAbsolutePath(); - if ((fileName = getMosFileName(file)) != null) { + if ((fileName = getMosOutputDirectory(file)) != null) { file = FileManager.resolve(fileName).toAbsolutePath(); currentDir = file.getParent().toString(); tfOutputV1.setText(fileName); tfOutputV2.setText(fileName); } + bConvert.setEnabled(isReady()); } else if (event.getSource() == bCompressionHelp) { final String helpMsg = - "\"DXT1\" provides the highest compression ratio. It supports only 1 bit alpha\n" + - "(i.e. either no or full transparency) and is the preferred type for TIS or MOS resources.\n\n" + - "\"DXT5\" provides an average compression ratio. It features interpolated\n" + - "alpha transitions and is the preferred type for BAM resources.\n\n" + - "\"Auto\" selects the most appropriate compression type based on the input data."; + "\"DXT1\" provides the highest compression ratio. It supports only 1 bit alpha\n" + + "(i.e. either no or full transparency) and is the preferred type for TIS or MOS resources.\n\n" + + "\"DXT5\" provides an average compression ratio. It features interpolated\n" + + "alpha transitions and is the preferred type for BAM resources.\n\n" + + "\"Auto\" selects the most appropriate compression type based on the input data."; JOptionPane.showMessageDialog(this, helpMsg, "About Compression Types", JOptionPane.INFORMATION_MESSAGE); } } @@ -610,47 +687,56 @@ public List doInBackground() @Override public void propertyChange(PropertyChangeEvent event) { - if (event.getSource() == workerConvert) { - if ("state".equals(event.getPropertyName()) && - SwingWorker.StateValue.DONE == event.getNewValue()) { - if (blocker != null) { - blocker.setBlocked(false); - blocker = null; - } - List sl = null; - try { - sl = workerConvert.get(); - } catch (Exception e) { - e.printStackTrace(); - } - workerConvert = null; - - boolean isError = false; - String s = null; - if (sl != null && !sl.isEmpty()) { - if (sl.get(0) != null) { - s = sl.get(0); - } else if (sl.size() > 1 && sl.get(1) != null) { - s = sl.get(1); - isError = true; - } - } - if (s != null) { - if (isError) { - JOptionPane.showMessageDialog(this, s, "Error", JOptionPane.ERROR_MESSAGE); - } else { - JOptionPane.showMessageDialog(this, s, "Information", JOptionPane.INFORMATION_MESSAGE); - if (cbCloseOnExit.isSelected()) { - hideWindow(); - } else { - clear(); - } - } - } else { - JOptionPane.showMessageDialog(this, "Unknown error!", "Error", JOptionPane.ERROR_MESSAGE); - } - } + System.out.println("Event Name : " + event.getPropertyName()); + + if ("progress" == event.getPropertyName()) { + Integer progressIndex = (Integer) event.getNewValue(); +// tfOutputTableV1.setValueAt((progressIndex / progressMax), fileCount, 1); +// tfOutputTableV1.set +// tfOutputTableV1.getModel().notifyAll(); +// tfOutputTableV1.notifyAll(); } + +// if (event.getSource() == workerConvert) { +// if ("state".equals(event.getPropertyName()) && SwingWorker.StateValue.DONE == event.getNewValue()) { +//// if (blocker != null) { +//// blocker.setBlocked(false); +//// blocker = null; +//// } +// List sl = null; +// try { +// sl = workerConvert.get(); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// workerConvert = null; +// +// boolean isError = false; +// String s = null; +// if (sl != null && !sl.isEmpty()) { +// if (sl.get(0) != null) { +// s = sl.get(0); +// } else if (sl.size() > 1 && sl.get(1) != null) { +// s = sl.get(1); +// isError = true; +// } +// } +// if (s != null) { +// if (isError) { +// JOptionPane.showMessageDialog(this, s, "Error", JOptionPane.ERROR_MESSAGE); +// } else { +// JOptionPane.showMessageDialog(this, s, "Information", JOptionPane.INFORMATION_MESSAGE); +// if (cbCloseOnExit.isSelected()) { +// hideWindow(); +// } else { +// clear(); +// } +// } +// } else { +// JOptionPane.showMessageDialog(this, "Unknown error!", "Error", JOptionPane.ERROR_MESSAGE); +// } +// } +// } } //--------------------- End Interface PropertyChangeListener --------------------- @@ -678,13 +764,14 @@ public void focusGained(FocusEvent event) @Override public void focusLost(FocusEvent event) { - if (event.getSource() == tfInputV1) { - tfInputV2.setText(tfInputV1.getText()); - bConvert.setEnabled(isReady()); - } else if (event.getSource() == tfInputV2) { - tfInputV1.setText(tfInputV2.getText()); - bConvert.setEnabled(isReady()); - } else if (event.getSource() == tfOutputV1) { +// if (event.getSource() == tfInputV1) { +// tfInputV2.setText(tfInputV1.getText()); +// bConvert.setEnabled(isReady()); +// } else if (event.getSource() == tfInputV2) { +// tfInputV1.setText(tfInputV2.getText()); +// bConvert.setEnabled(isReady()); + + if (event.getSource() == tfOutputV1) { tfOutputV2.setText(tfOutputV1.getText()); bConvert.setEnabled(isReady()); } else if (event.getSource() == tfOutputV2) { @@ -693,6 +780,29 @@ public void focusLost(FocusEvent event) } } +// private class ProgressBarModel extends AbstractTableModel { +// +// @Override +// public int getRowCount() { +// return 0; +// } +// +// @Override +// public int getColumnCount() { +// return 2; +// } +// +// @Override +// public Object getValueAt(int row, int col) { +// return String.valueOf(row) + ", " + String.valueOf(col); +// } +// +// @Override +// public void setValueAt(Object aValue, int row, int col) { +// // update internal model and notify listeners +// fireTableCellUpdated(row, col); +// } +// } //--------------------- End Interface FocusListener --------------------- private void init() @@ -701,36 +811,73 @@ private void init() GridBagConstraints c = new GridBagConstraints(); // setting up input/output section (Legacy V1) - JPanel pFilesV1 = new JPanel(new GridBagLayout()); - pFilesV1.setBorder(BorderFactory.createTitledBorder("Input & Output ")); - JLabel lInputV1 = new JLabel("Input file:"); - JLabel lOutputV1 = new JLabel("Output file:"); - tfInputV1 = new JTextField(); - tfInputV1.addFocusListener(this); + JPanel pFilesOutputV1 = new JPanel(new GridBagLayout()); + pFilesOutputV1.setBorder(BorderFactory.createTitledBorder("Output Files")); + + JPanel pFilesInputV1 = new JPanel(new GridBagLayout()); + pFilesInputV1.setBorder(BorderFactory.createTitledBorder("Input Files")); + + //output directory choice will defualt to source directory maybe? tfOutputV1 = new JTextField(); + tfOutputV1.setText("D:\\bg-mos-convert"); tfOutputV1.addFocusListener(this); - bInputV1 = new JButton("..."); + + //input table settings + inputTableModel = new DefaultTableModel(0, 0); + inputTableModel.addColumn("Input"); + tfInputTableV1 = new JTable(inputTableModel) { + public boolean isCellEditable(int rowIndex, int colIndex) { + return false; + } + }; + tfInputTableV1.setModel(inputTableModel); + tfInputTableV1.setPreferredScrollableViewportSize(new Dimension(500,200)); +// tfInputTableV1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + spInputScroll = new JScrollPane(tfInputTableV1); + + //output table settings + outputTableModel = new DefaultTableModel(0, 0); + outputTableModel.addColumn("Output"); + outputTableModel.addColumn("Progress"); + tfOutputTableV1 = new JTable(outputTableModel); + tfOutputTableV1.setModel(outputTableModel); + TableColumn tfOutputTableProgressCol = tfOutputTableV1.getColumnModel().getColumn(1); + tfOutputTableProgressCol.setCellRenderer(new ProgressCellRenderer()); + tfOutputTableV1.setPreferredScrollableViewportSize(new Dimension(500,200)); +// tfOutputTableV1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + spOutputScroll = new JScrollPane(tfOutputTableV1); + + bInputV1 = new JButton("Select Input"); bInputV1.addActionListener(this); - bOutputV1 = new JButton("..."); + + bOutputV1 = new JButton("Change Output Directory"); bOutputV1.addActionListener(this); - c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(0, 4, 0, 0), 0, 0); - pFilesV1.add(lInputV1, c); - c = ViewerUtil.setGBC(c, 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0); - pFilesV1.add(tfInputV1, c); - c = ViewerUtil.setGBC(c, 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(0, 4, 0, 4), 0, 0); - pFilesV1.add(bInputV1, c); - c = ViewerUtil.setGBC(c, 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(0, 4, 4, 0), 0, 0); - pFilesV1.add(lOutputV1, c); - c = ViewerUtil.setGBC(c, 1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(0, 8, 4, 0), 0, 0); - pFilesV1.add(tfOutputV1, c); - c = ViewerUtil.setGBC(c, 2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(0, 4, 4, 4), 0, 0); - pFilesV1.add(bOutputV1, c); + + //input file frame start + c = ViewerUtil.setGBC(c, 4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, + GridBagConstraints.HORIZONTAL, new Insets(0, 4, 0, 4), 0, 0); + pFilesInputV1.add(bInputV1, c); + + c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, + GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0); +// spInputScroll.add(tfInputTableV1, c); + pFilesInputV1.add(spInputScroll, c); + //input file frame end + + //out file frame start + c = ViewerUtil.setGBC(c, 4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, + GridBagConstraints.HORIZONTAL, new Insets(0, 4, 0, 4), 0, 0); + pFilesOutputV1.add(bOutputV1, c); + + c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, + GridBagConstraints.HORIZONTAL, new Insets(0, 8, 4, 0), 0, 0); + pFilesOutputV1.add(tfOutputV1, c); + + c = ViewerUtil.setGBC(c, 0, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, + GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0); +// spOutputScroll.add(tfOutputTableV1, c); + pFilesOutputV1.add(spOutputScroll, c); + //out file frame end // setting up input/output section (PVRZ-based V2) JPanel pFilesV2 = new JPanel(new GridBagLayout()); @@ -746,22 +893,22 @@ private void init() bOutputV2 = new JButton("..."); bOutputV2.addActionListener(this); c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0); + GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0); pFilesV2.add(lInputV2, c); c = ViewerUtil.setGBC(c, 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0); + GridBagConstraints.HORIZONTAL, new Insets(0, 8, 0, 0), 0, 0); pFilesV2.add(tfInputV2, c); c = ViewerUtil.setGBC(c, 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 4, 0, 4), 0, 0); + GridBagConstraints.NONE, new Insets(0, 4, 0, 4), 0, 0); pFilesV2.add(bInputV2, c); c = ViewerUtil.setGBC(c, 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 4, 4, 0), 0, 0); + GridBagConstraints.NONE, new Insets(0, 4, 4, 0), 0, 0); pFilesV2.add(lOutputV2, c); c = ViewerUtil.setGBC(c, 1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(0, 8, 4, 0), 0, 0); + GridBagConstraints.HORIZONTAL, new Insets(0, 8, 4, 0), 0, 0); pFilesV2.add(tfOutputV2, c); c = ViewerUtil.setGBC(c, 2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 4, 4, 4), 0, 0); + GridBagConstraints.NONE, new Insets(0, 4, 4, 4), 0, 0); pFilesV2.add(bOutputV2, c); // setting up options section (legacy V1) @@ -769,13 +916,13 @@ private void init() pOptionsV1.setBorder(BorderFactory.createTitledBorder("Options ")); cbCompress = new JCheckBox("Compressed (MOSC)", false); c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(4, 0, 0, 0), 0, 0); + GridBagConstraints.NONE, new Insets(4, 0, 0, 0), 0, 0); pOptionsV1.add(cbCompress, c); c = ViewerUtil.setGBC(c, 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(4, 0, 0, 0), 0, 0); + GridBagConstraints.HORIZONTAL, new Insets(4, 0, 0, 0), 0, 0); pOptionsV1.add(new JPanel(), c); c = ViewerUtil.setGBC(c, 0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.FIRST_LINE_START, - GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0); + GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0); pOptionsV1.add(new JPanel(), c); // setting up options section (PVRZ-based V2) @@ -792,26 +939,26 @@ private void init() bCompressionHelp.setToolTipText("About compression types"); bCompressionHelp.addActionListener(this); bCompressionHelp.setMargin(new Insets(bCompressionHelp.getInsets().top, 4, - bCompressionHelp.getInsets().bottom, 4)); + bCompressionHelp.getInsets().bottom, 4)); lPvrzInfo = new JLabel(pvrzInfoString(sPvrzIndex.getValue())); c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0); + GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0); pOptionsV2.add(lPvrzIndex, c); c = ViewerUtil.setGBC(c, 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0); + GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0); pOptionsV2.add(sPvrzIndex, c); c = ViewerUtil.setGBC(c, 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 16, 0, 0), 0, 0); + GridBagConstraints.NONE, new Insets(0, 16, 0, 0), 0, 0); pOptionsV2.add(lCompression, c); c = ViewerUtil.setGBC(c, 3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0); + GridBagConstraints.NONE, new Insets(0, 8, 0, 0), 0, 0); pOptionsV2.add(cbCompression, c); c = ViewerUtil.setGBC(c, 4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 4, 0, 4), 0, 0); + GridBagConstraints.NONE, new Insets(0, 4, 0, 4), 0, 0); pOptionsV2.add(bCompressionHelp, c); c = ViewerUtil.setGBC(c, 0, 1, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0); + GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0); pOptionsV2.add(lPvrzInfo, c); // setting up tabbed pane @@ -819,20 +966,28 @@ private void init() JPanel pTabV1 = new JPanel(new GridBagLayout()); c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(4, 4, 2, 4), 0, 0); - pTabV1.add(pFilesV1, c); + GridBagConstraints.HORIZONTAL, new Insets(4, 4, 2, 4), 0, 0); + +// pTabV1.add(spInputScroll, c); + pTabV1.add(pFilesInputV1, c); c = ViewerUtil.setGBC(c, 0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, - GridBagConstraints.BOTH, new Insets(2, 4, 4, 4), 0, 0); + GridBagConstraints.BOTH, new Insets(2, 4, 4, 4), 0, 0); + +// pTabV1.add(spOutputScroll, c); + pTabV1.add(pFilesOutputV1, c); + c = ViewerUtil.setGBC(c, 0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, + GridBagConstraints.BOTH, new Insets(2, 4, 4, 4), 0, 0); + pTabV1.add(pOptionsV1, c); tabPane.addTab("Legacy (V1)", pTabV1); tabPane.setMnemonicAt(0, KeyEvent.VK_1); JPanel pTabV2 = new JPanel(new GridBagLayout()); c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(4, 4, 2, 4), 0, 0); + GridBagConstraints.HORIZONTAL, new Insets(4, 4, 2, 4), 0, 0); pTabV2.add(pFilesV2, c); c = ViewerUtil.setGBC(c, 0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(2, 4, 4, 4), 0, 0); + GridBagConstraints.HORIZONTAL, new Insets(2, 4, 4, 4), 0, 0); pTabV2.add(pOptionsV2, c); tabPane.addTab("PVRZ-based (V2)", pTabV2); tabPane.setMnemonicAt(1, KeyEvent.VK_2); @@ -852,28 +1007,28 @@ private void init() JPanel pButtons = new JPanel(new GridBagLayout()); c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); + GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); pButtons.add(cbCloseOnExit, c); c = ViewerUtil.setGBC(c, 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); + GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); pButtons.add(new JPanel(), c); c = ViewerUtil.setGBC(c, 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, - GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); + GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); pButtons.add(bConvert, c); c = ViewerUtil.setGBC(c, 3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, - GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0); + GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0); pButtons.add(bCancel, c); // putting all together setLayout(new GridBagLayout()); c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(8, 8, 0, 8), 0, 0); + GridBagConstraints.HORIZONTAL, new Insets(8, 8, 0, 8), 0, 0); add(tabPane, c); c = ViewerUtil.setGBC(c, 0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(8, 8, 0, 8), 0, 0); + GridBagConstraints.HORIZONTAL, new Insets(8, 8, 0, 8), 0, 0); add(pButtons, c); c = ViewerUtil.setGBC(c, 0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.FIRST_LINE_START, - GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0); + GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0); add(new JPanel(), c); // finalizing dialog initialization @@ -893,7 +1048,6 @@ private void hideWindow() // resetting dialog state private void clear() { - tfInputV1.setText(""); tfInputV2.setText(""); tfOutputV1.setText(""); tfOutputV2.setText(""); @@ -903,12 +1057,15 @@ private void clear() // got enough data to start conversion? private boolean isReady() { - boolean ret = false; - if (!tfInputV1.getText().isEmpty() && !tfOutputV1.getText().isEmpty()) { - Path file = FileManager.resolve(tfInputV1.getText()); - ret = Files.isRegularFile(file); + if (tfInputTableV1.getRowCount() > 0 && !tfOutputV1.getText().isEmpty()) { + for(String outPutTableFiles : getTableInputPaths()) { + Path file = FileManager.resolve(outPutTableFiles); + if(!Files.isRegularFile(file)) { + return false; + } + } } - return ret; + return true; } private int getPvrzIndex(Object o) @@ -933,12 +1090,14 @@ private String pvrzInfoString(Object o) return String.format("Resulting in MOS%04d.PVRZ, MOS%04d.PVRZ, ...", index, index+1); } - private String getImageFileName(Path path) + private File[] getImageFileName() { - JFileChooser fc = new JFileChooser(path.toFile()); - fc.setDialogTitle("Select input graphics file"); + JFileChooser fc = new JFileChooser(); + + fc.setDialogTitle("Select input graphics files"); fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); + fc.setMultiSelectionEnabled(true); FileNameExtensionFilter[] filters = getInputFilters(); for (final FileNameExtensionFilter filter: filters) { fc.addChoosableFileFilter(filter); @@ -946,21 +1105,23 @@ private String getImageFileName(Path path) fc.setFileFilter(filters[0]); int ret = fc.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { - return fc.getSelectedFile().toString(); + File[] filePaths = fc.getSelectedFiles(); + for(File fileSelected : filePaths) { + System.out.println(fileSelected.getName()); + } + return filePaths; } else { return null; } } - private String getMosFileName(Path path) + private String getMosOutputDirectory(Path path) { JFileChooser fc = new JFileChooser(path.toFile()); - fc.setDialogTitle("Specify output filename"); + fc.setDialogTitle("Specify output directory"); fc.setDialogType(JFileChooser.SAVE_DIALOG); - fc.setFileSelectionMode(JFileChooser.FILES_ONLY); - FileNameExtensionFilter filter = new FileNameExtensionFilter("MOS files (*.mos)", "mos"); - fc.addChoosableFileFilter(filter); - fc.setFileFilter(filter); + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int ret = fc.showSaveDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { return fc.getSelectedFile().toString(); @@ -969,15 +1130,41 @@ private String getMosFileName(Path path) } } - private List convert() + private ArrayList getTableInputPaths() { + ArrayList list = new ArrayList<>(); + if(tfInputTableV1.getModel().getRowCount() > 0) { + for (int i = 0; i < tfInputTableV1.getModel().getRowCount(); i++) { + list.add(tfInputTableV1.getModel().getValueAt(i, 0).toString()); + } + + return list; + } else { + return null; + } + } + + private ArrayList getTableOutputNames() { + ArrayList list = new ArrayList<>(); + if(tfOutputTableV1.getModel().getRowCount() > 0) { + for (int i = 0; i < tfOutputTableV1.getModel().getRowCount(); i++) { + list.add(tfOutputTableV1.getModel().getValueAt(i, 0).toString()); + } + + return list; + } else { + return null; + } + } + + private List convert(Task workerTask) { List result = new Vector(2); - // validating input file - Path inFile = FileManager.resolve(tfInputV1.getText()); + // validating input files + Path inFile = FileManager.resolve(workerTask.getInputPath()); if (!Files.isRegularFile(inFile)) { result.add(null); - result.add(String.format("Input file \"%s\" does not exist.", tfInputV1.getText())); + result.add(String.format("Input file \"%s\" does not exist.", workerTask.getInputPath())); return result; } @@ -1016,7 +1203,14 @@ private List convert() // converting if (tabPane.getSelectedIndex() == 0) { - convertV1(this, srcImage, tfOutputV1.getText(), isMOSC, result, true); + //default to current directory + String mosFilePath = currentDir + File.separator + getTableOutputNames().get(workerTask.getFileCount()); + if(!tfOutputV1.getText().isEmpty()) { + mosFilePath = tfOutputV1.getText() + File.separator + getTableOutputNames().get(workerTask.getFileCount()); + } + + workerTask.convertV1(srcImage, mosFilePath, isMOSC, result); + //String.valueOf((workerTask.fileCount+1)), workerTask.progressIndex, workerTask.progressMax //tfOutputV1.getText() } else if (tabPane.getSelectedIndex() == 1) { convertV2(this, srcImage, tfOutputV2.getText(), dxtType, pvrzIndex, result, true); } else { @@ -1030,20 +1224,20 @@ private List convert() //-------------------------- INNER CLASSES -------------------------- - private static class MosEntry - { - public int page; - public int width, height; - public Point srcLocation; - public Point dstLocation; - - public MosEntry(int page, Point srcLocation, int width, int height, Point dstLocation) - { - this.page = page; - this.srcLocation = srcLocation; - this.width = width; - this.height = height; - this.dstLocation = dstLocation; - } - } -} + private static class MosEntry + { + public int page; + public int width, height; + public Point srcLocation; + public Point dstLocation; + + public MosEntry(int page, Point srcLocation, int width, int height, Point dstLocation) + { + this.page = page; + this.srcLocation = srcLocation; + this.width = width; + this.height = height; + this.dstLocation = dstLocation; + } + } +} \ No newline at end of file diff --git a/src/org/infinity/gui/converter/MassConvert.java b/src/org/infinity/gui/converter/MassConvert.java new file mode 100644 index 000000000..46455baa0 --- /dev/null +++ b/src/org/infinity/gui/converter/MassConvert.java @@ -0,0 +1,8 @@ +package org.infinity.gui.converter; + +import javax.swing.*; + +//place holder +public final class MassConvert extends JPanel { +//might be nice to have an integrated interface to convert anything? +} From 94c6d2c2d3c4351c65975cddb9e27ce4326b2053 Mon Sep 17 00:00:00 2001 From: goddard Date: Wed, 19 Aug 2020 22:25:13 -0400 Subject: [PATCH 02/25] Working version, but still has bugs Mass convert for MOS v1 works well, but some bugs still exist. MOS v2 still needs to be tested. --- .../infinity/gui/converter/ConvertToMos.java | 408 +++++++----------- 1 file changed, 144 insertions(+), 264 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index cf1eb64b5..0cbe40476 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -67,170 +67,12 @@ public class ConvertToMos extends ChildFrame implements ActionListener, Property private JLabel lPvrzInfo; private JComboBox cbCompression; private JCheckBox cbCompress, cbCloseOnExit; -// private Task workerConvert; private DefaultTableModel inputTableModel; private DefaultTableModel outputTableModel; private JScrollPane spInputScroll; private JScrollPane spOutputScroll; - /** - * Converts an image into a MOS V2 resource. - * @param parent This parameter is needed for the progress monitor only. - * @param img The source image to convert into a MOS resource. - * @param mosFileName The name of the resulting MOS file. - * @param dxtType The desired compression type. - * @param pvrzIndex The starting index for PVRZ files. - * @param result Returns more specific information about the conversion process. Data placed in the - * first item indicates success, data in the second item indicates failure. - * @param showProgress Specify whether to show a progress monitor (needs a valid 'parent' parameter). - * @return {@code true} if the conversion finished successfully, {@code false} otherwise. - */ - public static boolean convertV2(Component parent, BufferedImage img, String mosFileName, - DxtEncoder.DxtType dxtType, int pvrzIndex, - List result, boolean showProgress) - { - // checking parameters - if (result == null) { - return false; - } - if (img == null) { - result.add(null); - result.add("No source image specified."); - return false; - } - if (mosFileName == null || mosFileName.isEmpty()) { - result.add(null); - result.add("No output filename specified."); - return false; - } - if (pvrzIndex < 0 || pvrzIndex > 99999) { - result.add(null); - result.add("PVRZ index is out of range [0..99999]."); - return false; - } - - // preparing variables - ProgressMonitor progress = null; - int width = img.getWidth(); - int height = img.getHeight(); - List pageList = new ArrayList(); - List entryList = new ArrayList(); - - try { - if (showProgress) { - // preparing progress meter - progress = new ProgressMonitor(parent, "Converting MOS...", "Preparing data", 0, 5); - progress.setMillisToDecideToPopup(0); - progress.setMillisToPopup(0); - progress.setProgress(0); - } - - // processing tiles - final int pageDim = 1024; - final BinPack2D.HeuristicRules binPackRule = BinPack2D.HeuristicRules.BOTTOM_LEFT_RULE; - - int x = 0, y = 0, pOfs = 0; - while (pOfs < width*height) { - int w = Math.min(pageDim, width - x); - int h = Math.min(pageDim, height - y); - Dimension space = new Dimension((w+3) & ~3, (h+3) & ~3); - int pageIdx = -1; - Rectangle rectMatch = null; - for (int i = 0; i < pageList.size(); i++) { - BinPack2D packer = pageList.get(i); - rectMatch = packer.insert(space.width, space.height, binPackRule); - if (rectMatch.height > 0) { - pageIdx = i; - break; - } - } - - // create new page? - if (pageIdx < 0) { - BinPack2D packer = new BinPack2D(pageDim, pageDim); - pageList.add(packer); - pageIdx = pageList.size() - 1; - rectMatch = packer.insert(space.width, space.height, binPackRule); - } - - // register page entry - MosEntry entry = new MosEntry(pvrzIndex + pageIdx, - new Point(rectMatch.x, rectMatch.y), - w, h, new Point(x, y)); - entryList.add(entry); - - // advance scanning - if (x + pageDim >= width) { - x = 0; - y += pageDim; - } else { - x += pageDim; - } - pOfs = y*width + x; - } - - // check PVRZ index again - if (pvrzIndex + pageList.size() > 100000) { - result.add(null); - result.add(String.format("One or more PVRZ indices exceed the max. possible value of 99999.\n" + - "Please choose a start index smaller than or equal to %d.", - 100000 - pageList.size())); - return false; - } - - byte[] dst = new byte[24 + entryList.size()*28]; // header + tiles - int dstOfs = 0; - - // writing MOS header and data - System.arraycopy("MOS V2 ".getBytes(), 0, dst, 0, 8); - DynamicArray.putInt(dst, 8, width); - DynamicArray.putInt(dst, 12, height); - DynamicArray.putInt(dst, 16, entryList.size()); - DynamicArray.putInt(dst, 20, 24); - dstOfs += 24; - for (int i = 0; i < entryList.size(); i++, dstOfs += 28) { - MosEntry entry = entryList.get(i); - DynamicArray.putInt(dst, dstOfs, entry.page); - DynamicArray.putInt(dst, dstOfs + 4, entry.srcLocation.x); - DynamicArray.putInt(dst, dstOfs + 8, entry.srcLocation.y); - DynamicArray.putInt(dst, dstOfs + 12, entry.width); - DynamicArray.putInt(dst, dstOfs + 16, entry.height); - DynamicArray.putInt(dst, dstOfs + 20, entry.dstLocation.x); - DynamicArray.putInt(dst, dstOfs + 24, entry.dstLocation.y); - } - - // writing MOS file to disk - Path mosFile = FileManager.resolve(mosFileName); - try (OutputStream os = StreamUtils.getOutputStream(mosFile, true)) { - os.write(dst); - } catch (Exception e) { - e.printStackTrace(); - result.add(null); - result.add("Error writing MOS file to disk."); - return false; - } - dst = null; - - // generating PVRZ files - if (!createPvrzPages(mosFile.getParent(), img, dxtType, pageList, entryList, - result, progress)) { - return false; - } - } finally { - // some cleaning up - img.flush(); - if (progress != null) { - progress.close(); - progress = null; - } - } - - // generating conversion summary - result.add("Conversion finished successfully."); - return true; - } - // Returns a list of supported graphics file formats private static FileNameExtensionFilter[] getInputFilters() { @@ -401,7 +243,6 @@ public Integer getProgressIndex() { /** * Converts an image into a MOS V1 resource. - * @param parent This parameter is needed for the progress monitor only. * @param img The source image to convert into a MOS resource. * @param mosFileName The name of the resulting MOS file. * @param compressed If {@code true}, converts into a compressed BAMC file. @@ -548,35 +389,156 @@ public boolean convertV1(BufferedImage img, String mosFileName, boolean compress return true; } - @Override - protected void process(java.util.List c) { - int lastValue = c.get(c.size()-1); -// outputTableModel.setValueAt(c, fileCount, 1); -// outputTableModel.setValueAt(lastValue, fileCount, 1); -// tfOutputTableV1.setModel(outputTableModel); -// tfOutputTableV1.getModel().setValueAt(lastValue, fileCount, 1); //currentTask -// tfOutputTableV1.updateUI(); + /** + * Converts an image into a MOS V2 resource. + * @param img The source image to convert into a MOS resource. + * @param mosFileName The name of the resulting MOS file. + * @param dxtType The desired compression type. + * @param pvrzIndex The starting index for PVRZ files. + * @param result Returns more specific information about the conversion process. Data placed in the + * first item indicates success, data in the second item indicates failure. + * @return {@code true} if the conversion finished successfully, {@code false} otherwise. + */ + public boolean convertV2(BufferedImage img, String mosFileName, DxtEncoder.DxtType dxtType, int pvrzIndex, List result) { + // checking parameters + if (result == null) { + return false; + } + if (img == null) { + result.add(null); + result.add("No source image specified."); + return false; + } + + if (mosFileName == null || mosFileName.isEmpty()) { + result.add(null); + result.add("No output filename specified."); + return false; + } + + if (pvrzIndex < 0 || pvrzIndex > 99999) { + result.add(null); + result.add("PVRZ index is out of range [0..99999]."); + return false; + } + + // preparing variables + ProgressMonitor progress = null; + int width = img.getWidth(); + int height = img.getHeight(); + List pageList = new ArrayList(); + List entryList = new ArrayList(); + + try { + // processing tiles + final int pageDim = 1024; + final BinPack2D.HeuristicRules binPackRule = BinPack2D.HeuristicRules.BOTTOM_LEFT_RULE; + + int x = 0, y = 0, pOfs = 0; + while (pOfs < width*height) { + int w = Math.min(pageDim, width - x); + int h = Math.min(pageDim, height - y); + Dimension space = new Dimension((w+3) & ~3, (h+3) & ~3); + int pageIdx = -1; + Rectangle rectMatch = null; + for (int i = 0; i < pageList.size(); i++) { + BinPack2D packer = pageList.get(i); + rectMatch = packer.insert(space.width, space.height, binPackRule); + if (rectMatch.height > 0) { + pageIdx = i; + break; + } + } + + // create new page? + if (pageIdx < 0) { + BinPack2D packer = new BinPack2D(pageDim, pageDim); + pageList.add(packer); + pageIdx = pageList.size() - 1; + rectMatch = packer.insert(space.width, space.height, binPackRule); + } + + // register page entry + MosEntry entry = new MosEntry(pvrzIndex + pageIdx, + new Point(rectMatch.x, rectMatch.y), + w, h, new Point(x, y)); + entryList.add(entry); -// tfOutputTableV1.setValueAt(lastValue, fileCount, 1); //currentTask - System.out.println("Process C Value " + lastValue); + // advance scanning + if (x + pageDim >= width) { + x = 0; + y += pageDim; + } else { + x += pageDim; + } + pOfs = y*width + x; + } + + // check PVRZ index again + if (pvrzIndex + pageList.size() > 100000) { + result.add(null); + result.add(String.format("One or more PVRZ indices exceed the max. possible value of 99999.\n" + + "Please choose a start index smaller than or equal to %d.", + 100000 - pageList.size())); + return false; + } + + byte[] dst = new byte[24 + entryList.size()*28]; // header + tiles + int dstOfs = 0; + + // writing MOS header and data + System.arraycopy("MOS V2 ".getBytes(), 0, dst, 0, 8); + DynamicArray.putInt(dst, 8, width); + DynamicArray.putInt(dst, 12, height); + DynamicArray.putInt(dst, 16, entryList.size()); + DynamicArray.putInt(dst, 20, 24); + dstOfs += 24; + for (int i = 0; i < entryList.size(); i++, dstOfs += 28) { + MosEntry entry = entryList.get(i); + DynamicArray.putInt(dst, dstOfs, entry.page); + DynamicArray.putInt(dst, dstOfs + 4, entry.srcLocation.x); + DynamicArray.putInt(dst, dstOfs + 8, entry.srcLocation.y); + DynamicArray.putInt(dst, dstOfs + 12, entry.width); + DynamicArray.putInt(dst, dstOfs + 16, entry.height); + DynamicArray.putInt(dst, dstOfs + 20, entry.dstLocation.x); + DynamicArray.putInt(dst, dstOfs + 24, entry.dstLocation.y); + } + + // writing MOS file to disk + Path mosFile = FileManager.resolve(mosFileName); + try (OutputStream os = StreamUtils.getOutputStream(mosFile, true)) { + os.write(dst); + } catch (Exception e) { + e.printStackTrace(); + result.add(null); + result.add("Error writing MOS file to disk."); + return false; + } + dst = null; + + // generating PVRZ files + if (!createPvrzPages(mosFile.getParent(), img, dxtType, pageList, entryList, + result, progress)) { + return false; + } + } finally { + // some cleaning up + img.flush(); + if (progress != null) { + progress.close(); + progress = null; + } + } + + // generating conversion summary + result.add("Conversion finished successfully."); + return true; } public void setProgressIndex(Integer progressIndex) { setProgress(this.progressIndex); this.progressIndex = progressIndex; -// Double percentage = ((double)this.progressIndex / (double)this.progressMax) * 100; -// System.out.println("Progress " + this.progressIndex + " Total Tiles " + this.progressMax + " File Index " + fileCount + " Percentage " + Math.round(percentage)); -// DefaultTableModel df = (DefaultTableModel)tfOutputTableV1.getModel(); -// tfOutputTableV1.getModel().setValueAt(Math.round(percentage), fileCount, 1); //currentTask -// tfOutputTableV1.setValueAt(Math.round(percentage) + "%", fileCount, 1); //currentTask -// outputTableModel.setValueAt(Math.round(percentage), fileCount, 1); -// df.fireTableCellUpdated(fileCount, 1); -// tfOutputTableV1.setModel(df); -// publish(((int) Math.round(percentage))); -// tfOutputTableV1 -// tfOutputTableV1.getModel().fireTableCellUpdated(); -// tfOutputTableV1.updateUI(); //fireTableChanged } public Integer progressMax; @@ -687,56 +649,7 @@ public void actionPerformed(ActionEvent event) @Override public void propertyChange(PropertyChangeEvent event) { - System.out.println("Event Name : " + event.getPropertyName()); - if ("progress" == event.getPropertyName()) { - Integer progressIndex = (Integer) event.getNewValue(); -// tfOutputTableV1.setValueAt((progressIndex / progressMax), fileCount, 1); -// tfOutputTableV1.set -// tfOutputTableV1.getModel().notifyAll(); -// tfOutputTableV1.notifyAll(); - } - -// if (event.getSource() == workerConvert) { -// if ("state".equals(event.getPropertyName()) && SwingWorker.StateValue.DONE == event.getNewValue()) { -//// if (blocker != null) { -//// blocker.setBlocked(false); -//// blocker = null; -//// } -// List sl = null; -// try { -// sl = workerConvert.get(); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// workerConvert = null; -// -// boolean isError = false; -// String s = null; -// if (sl != null && !sl.isEmpty()) { -// if (sl.get(0) != null) { -// s = sl.get(0); -// } else if (sl.size() > 1 && sl.get(1) != null) { -// s = sl.get(1); -// isError = true; -// } -// } -// if (s != null) { -// if (isError) { -// JOptionPane.showMessageDialog(this, s, "Error", JOptionPane.ERROR_MESSAGE); -// } else { -// JOptionPane.showMessageDialog(this, s, "Information", JOptionPane.INFORMATION_MESSAGE); -// if (cbCloseOnExit.isSelected()) { -// hideWindow(); -// } else { -// clear(); -// } -// } -// } else { -// JOptionPane.showMessageDialog(this, "Unknown error!", "Error", JOptionPane.ERROR_MESSAGE); -// } -// } -// } } //--------------------- End Interface PropertyChangeListener --------------------- @@ -764,13 +677,6 @@ public void focusGained(FocusEvent event) @Override public void focusLost(FocusEvent event) { -// if (event.getSource() == tfInputV1) { -// tfInputV2.setText(tfInputV1.getText()); -// bConvert.setEnabled(isReady()); -// } else if (event.getSource() == tfInputV2) { -// tfInputV1.setText(tfInputV2.getText()); -// bConvert.setEnabled(isReady()); - if (event.getSource() == tfOutputV1) { tfOutputV2.setText(tfOutputV1.getText()); bConvert.setEnabled(isReady()); @@ -780,29 +686,6 @@ public void focusLost(FocusEvent event) } } -// private class ProgressBarModel extends AbstractTableModel { -// -// @Override -// public int getRowCount() { -// return 0; -// } -// -// @Override -// public int getColumnCount() { -// return 2; -// } -// -// @Override -// public Object getValueAt(int row, int col) { -// return String.valueOf(row) + ", " + String.valueOf(col); -// } -// -// @Override -// public void setValueAt(Object aValue, int row, int col) { -// // update internal model and notify listeners -// fireTableCellUpdated(row, col); -// } -// } //--------------------- End Interface FocusListener --------------------- private void init() @@ -1210,9 +1093,8 @@ private List convert(Task workerTask) } workerTask.convertV1(srcImage, mosFilePath, isMOSC, result); - //String.valueOf((workerTask.fileCount+1)), workerTask.progressIndex, workerTask.progressMax //tfOutputV1.getText() } else if (tabPane.getSelectedIndex() == 1) { - convertV2(this, srcImage, tfOutputV2.getText(), dxtType, pvrzIndex, result, true); + workerTask.convertV2(srcImage, tfOutputV2.getText(), dxtType, pvrzIndex, result); } else { result.add(null); result.add("No MOS type specified!"); @@ -1220,8 +1102,6 @@ private List convert(Task workerTask) return result; } - - //-------------------------- INNER CLASSES -------------------------- private static class MosEntry From 580502f7a3393db628f8f592c53a6ce341d32086 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Thu, 1 Jul 2021 21:16:55 -0400 Subject: [PATCH 03/25] remove checkbox --- src/org/infinity/gui/converter/ConvertToMos.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 0cbe40476..f56189f48 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -889,9 +889,9 @@ public boolean isCellEditable(int rowIndex, int colIndex) { bCancel.setMargin(new Insets(i.top + 2, i.left, i.bottom + 2, i.right)); JPanel pButtons = new JPanel(new GridBagLayout()); - c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); - pButtons.add(cbCloseOnExit, c); +// c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, +// GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); +// pButtons.add(cbCloseOnExit, c); c = ViewerUtil.setGBC(c, 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); pButtons.add(new JPanel(), c); From aafb62803beb1b03663b9f162a1d5906e79be5c1 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:00:14 -0400 Subject: [PATCH 04/25] fixed imports and newline at end of file --- src/org/infinity/gui/ProgressCellRenderer.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/org/infinity/gui/ProgressCellRenderer.java b/src/org/infinity/gui/ProgressCellRenderer.java index 48c5a7ec5..5ec9a316a 100644 --- a/src/org/infinity/gui/ProgressCellRenderer.java +++ b/src/org/infinity/gui/ProgressCellRenderer.java @@ -1,8 +1,9 @@ package org.infinity.gui; -import javax.swing.*; +import javax.swing.JProgressBar; +import javax.swing.JTable; import javax.swing.table.TableCellRenderer; -import java.awt.*; +import java.awt.Component; public class ProgressCellRenderer extends JProgressBar implements TableCellRenderer { @@ -41,4 +42,4 @@ public Component getTableCellRendererComponent( } return this; } -} \ No newline at end of file +} From 89fca90035ec9f9b448dfed1d93ad84c230b3a20 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:03:35 -0400 Subject: [PATCH 05/25] copy paste header from other files --- src/org/infinity/gui/ProgressCellRenderer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/org/infinity/gui/ProgressCellRenderer.java b/src/org/infinity/gui/ProgressCellRenderer.java index 5ec9a316a..a21f04e58 100644 --- a/src/org/infinity/gui/ProgressCellRenderer.java +++ b/src/org/infinity/gui/ProgressCellRenderer.java @@ -1,3 +1,7 @@ +// Near Infinity - An Infinity Engine Browser and Editor +// Copyright (C) 2001 - 2005 Jon Olav Hauglid +// See LICENSE.txt for license information + package org.infinity.gui; import javax.swing.JProgressBar; From 9044e2dd06c6fd91b1c25b967b46a5a8f59b523c Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:04:24 -0400 Subject: [PATCH 06/25] used format for code so it is all the same --- src/org/infinity/gui/ProgressCellRenderer.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/org/infinity/gui/ProgressCellRenderer.java b/src/org/infinity/gui/ProgressCellRenderer.java index a21f04e58..9228d9a0b 100644 --- a/src/org/infinity/gui/ProgressCellRenderer.java +++ b/src/org/infinity/gui/ProgressCellRenderer.java @@ -14,7 +14,7 @@ public class ProgressCellRenderer extends JProgressBar implements TableCellRende /** * Creates a JProgressBar with the range 0,100. */ - public ProgressCellRenderer(){ + public ProgressCellRenderer() { super(0, 100); setValue(0); setString("0%"); @@ -34,10 +34,9 @@ public Component getTableCellRendererComponent( int index = sValue.indexOf('%'); if (index != -1) { int p = 0; - try{ + try { p = Integer.parseInt(sValue.substring(0, index)); - } - catch(NumberFormatException e) { + } catch (NumberFormatException e) { System.out.println("Number Format Exception"); } From e1f5b090678f3bfd2014115106312d980763763a Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:20:49 -0400 Subject: [PATCH 07/25] added logger --- src/org/infinity/gui/ProgressCellRenderer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/org/infinity/gui/ProgressCellRenderer.java b/src/org/infinity/gui/ProgressCellRenderer.java index 9228d9a0b..560f68c45 100644 --- a/src/org/infinity/gui/ProgressCellRenderer.java +++ b/src/org/infinity/gui/ProgressCellRenderer.java @@ -8,6 +8,8 @@ import javax.swing.JTable; import javax.swing.table.TableCellRenderer; import java.awt.Component; +import java.util.logging.Level; +import java.util.logging.Logger; public class ProgressCellRenderer extends JProgressBar implements TableCellRenderer { @@ -37,7 +39,7 @@ public Component getTableCellRendererComponent( try { p = Integer.parseInt(sValue.substring(0, index)); } catch (NumberFormatException e) { - System.out.println("Number Format Exception"); + Logger.getLogger(String.valueOf(ProgressCellRenderer.class)).log(Level.WARNING, "Number Format Exception : " + e.getMessage()); } this.setValue(p); From 625dd0115bd4bce0c81c3619f198fee01b655033 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:28:03 -0400 Subject: [PATCH 08/25] fixed more imports --- .../infinity/gui/converter/ConvertToMos.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index f56189f48..cf71613d7 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -31,9 +31,26 @@ import java.util.concurrent.Executors; import javax.imageio.ImageIO; -import javax.swing.*; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.JButton; +import javax.swing.JTabbedPane; +import javax.swing.JSpinner; +import javax.swing.JLabel; +import javax.swing.JComboBox; +import javax.swing.JCheckBox; +import javax.swing.JScrollPane; +import javax.swing.SwingWorker; +import javax.swing.ProgressMonitor; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.BorderFactory; +import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.swing.JFileChooser; +import javax.swing.SpinnerNumberModel; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableModel; From f73159b1c18d23ab87ccfc7c10a73c46158a3990 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:31:28 -0400 Subject: [PATCH 09/25] added javadoc block --- src/org/infinity/gui/converter/ConvertToMos.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index cf71613d7..23f12f864 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -71,6 +71,9 @@ import org.infinity.util.io.FileManager; import org.infinity.util.io.StreamUtils; +/** + * Class converts images to MOS type v1 and v2. v1 has the ability to convert multiple files at once. + */ public class ConvertToMos extends ChildFrame implements ActionListener, PropertyChangeListener, ChangeListener, FocusListener { private static String currentDir = Profile.getGameRoot().toString(); From 22685ba01e54eb3f47fafa2b580ae746e14ed645 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:37:44 -0400 Subject: [PATCH 10/25] added comment and split variables to own line and use equal function --- src/org/infinity/gui/converter/ConvertToMos.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 23f12f864..47a8aa9b0 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -80,7 +80,10 @@ public class ConvertToMos extends ChildFrame implements ActionListener, Property private JTabbedPane tabPane; private JTable tfInputTableV1; private JTable tfOutputTableV1; - private JTextField tfOutputV1, tfInputV2, tfOutputV2; + // location where output will be saved + private JTextField tfOutputV1; + private JTextField tfInputV2; + private JTextField tfOutputV2; private JButton bInputV1, bOutputV1, bInputV2, bOutputV2, bCompressionHelp; private JButton bConvert, bCancel; private JSpinner sPvrzIndex; @@ -230,7 +233,7 @@ public void setFileCount(int fileCount) { @Override public void propertyChange(PropertyChangeEvent event) { - if ("progress" == event.getPropertyName()) { + if ("progress".equals(event.getPropertyName())) { Integer progressIndex = (Integer) event.getNewValue(); tfOutputTableV1.setValueAt(progressIndex +"%", fileCount, 1); } @@ -722,7 +725,7 @@ private void init() //output directory choice will defualt to source directory maybe? tfOutputV1 = new JTextField(); - tfOutputV1.setText("D:\\bg-mos-convert"); + tfOutputV1.setText(""); tfOutputV1.addFocusListener(this); //input table settings From dc89796c3ea73cc6d8ee637ff013305150b922ee Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:43:06 -0400 Subject: [PATCH 11/25] fix errors to logs and wrong file type --- src/org/infinity/gui/converter/ConvertToMos.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 47a8aa9b0..fd9a299ed 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -29,6 +29,8 @@ import java.util.Vector; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.JTabbedPane; @@ -340,7 +342,7 @@ public boolean convertV1(BufferedImage img, String mosFileName, boolean compress progressIndexPer = progressIndex; progressMaxPer = progressMax; double percentage = Math.round((progressIndexPer / progressMaxPer) * 100); - System.out.println(progressIndex + " " + percentage); + Logger.getLogger(this.getClass().getName()).log(Level.INFO, progressIndex + " " + percentage); setProgress((int)percentage); int[] pixels = tileList.get(tileIdx); @@ -398,9 +400,9 @@ public boolean convertV1(BufferedImage img, String mosFileName, boolean compress try (OutputStream os = StreamUtils.getOutputStream(mosFile, true)) { os.write(dst); } catch (Exception e) { - e.printStackTrace(); + Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error writing file to disk : " + e.getMessage()); result.add(null); - result.add("Error writing TIS file to disk."); + result.add("Error writing MOS file to disk."); return false; } } finally { From 353130c5e50f12a65ac08c26a480a0eb1c9df281 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:44:14 -0400 Subject: [PATCH 12/25] move property to top of class --- src/org/infinity/gui/converter/ConvertToMos.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index fd9a299ed..8534ff5ac 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -244,6 +244,9 @@ public void propertyChange(PropertyChangeEvent event) { class Task extends SwingWorker, Integer> { public String inputPath; + public Integer fileCount; + public Integer progressIndex; + public String getInputPath() { return inputPath; } @@ -252,7 +255,6 @@ public void setInputPath(String inputPath) { this.inputPath = inputPath; } - public Integer fileCount; public Integer getFileCount() { return fileCount; } @@ -261,7 +263,7 @@ public void setFileCount(Integer fileCount) { this.fileCount = fileCount; } - public Integer progressIndex; + public Integer getProgressIndex() { return progressIndex; } From 3830798879306450de34363e264cd444033f31c8 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:45:23 -0400 Subject: [PATCH 13/25] move int to own line --- src/org/infinity/gui/converter/ConvertToMos.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 8534ff5ac..691a5718a 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -335,7 +335,9 @@ public boolean convertV1(BufferedImage img, String mosFileName, boolean compress int[] palette = new int[255]; byte[] tilePalette = new byte[1024]; byte[] tileData = new byte[64*64]; - int curPalOfs = palOfs, curTableOfs = tableOfs, curDataOfs = dataOfs; + int curPalOfs = palOfs; + int curTableOfs = tableOfs; + int curDataOfs = dataOfs; IntegerHashMap colorCache = new IntegerHashMap(1536); // caching RGBColor -> index for (int tileIdx = 0; tileIdx < tileList.size(); tileIdx++) { colorCache.clear(); @@ -425,7 +427,7 @@ public boolean convertV1(BufferedImage img, String mosFileName, boolean compress * @param result Returns more specific information about the conversion process. Data placed in the * first item indicates success, data in the second item indicates failure. * @return {@code true} if the conversion finished successfully, {@code false} otherwise. - */ + */int curPalOfs = palOfs, curTableOfs = tableOfs, curDataOfs = dataOfs; public boolean convertV2(BufferedImage img, String mosFileName, DxtEncoder.DxtType dxtType, int pvrzIndex, List result) { // checking parameters if (result == null) { From 1c59c47e2e8c7911bd24c3dab9bee9e77f842441 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:49:31 -0400 Subject: [PATCH 14/25] added catch instead of finally to log error --- src/org/infinity/gui/converter/ConvertToMos.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 691a5718a..e30ea5bec 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -409,8 +409,8 @@ public boolean convertV1(BufferedImage img, String mosFileName, boolean compress result.add("Error writing MOS file to disk."); return false; } - } finally { - + } catch (Exception e) { + Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Unable to convert tile" + e.getMessage()); } // generating conversion summary @@ -427,7 +427,7 @@ public boolean convertV1(BufferedImage img, String mosFileName, boolean compress * @param result Returns more specific information about the conversion process. Data placed in the * first item indicates success, data in the second item indicates failure. * @return {@code true} if the conversion finished successfully, {@code false} otherwise. - */int curPalOfs = palOfs, curTableOfs = tableOfs, curDataOfs = dataOfs; + */ public boolean convertV2(BufferedImage img, String mosFileName, DxtEncoder.DxtType dxtType, int pvrzIndex, List result) { // checking parameters if (result == null) { From ead4b64cf4683819bf8d37f98435f3006b177076 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:52:13 -0400 Subject: [PATCH 15/25] added log and removed redundent progress assignment to null --- src/org/infinity/gui/converter/ConvertToMos.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index e30ea5bec..1049e3b1d 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -539,7 +539,7 @@ public boolean convertV2(BufferedImage img, String mosFileName, DxtEncoder.DxtTy try (OutputStream os = StreamUtils.getOutputStream(mosFile, true)) { os.write(dst); } catch (Exception e) { - e.printStackTrace(); + Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Unable to save MOS to disk : " + e.getMessage()); result.add(null); result.add("Error writing MOS file to disk."); return false; @@ -556,7 +556,6 @@ public boolean convertV2(BufferedImage img, String mosFileName, DxtEncoder.DxtTy img.flush(); if (progress != null) { progress.close(); - progress = null; } } From 60a492149c423f1cadb352dca423a683ae6d9b8f Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:54:16 -0400 Subject: [PATCH 16/25] added log for selecting file --- src/org/infinity/gui/converter/ConvertToMos.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 1049e3b1d..e3062fa4c 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -638,7 +638,7 @@ public void actionPerformed(ActionEvent event) File[] filePaths = getImageFileName(); if (filePaths != null) { - for(File fileSelected : filePaths) { + for (File fileSelected : filePaths) { System.out.println(fileSelected.getName()); inputTableModel.addRow(new Object[] { fileSelected.getAbsolutePath()}); @@ -1018,7 +1018,7 @@ private File[] getImageFileName() if (ret == JFileChooser.APPROVE_OPTION) { File[] filePaths = fc.getSelectedFiles(); for(File fileSelected : filePaths) { - System.out.println(fileSelected.getName()); + Logger.getLogger(this.getClass().getName()).log(Level.INFO, "File Selected : " + fileSelected.getName()); } return filePaths; } else { From f5df564f09f1fcba5bb932b440a159eaf35929b8 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:56:03 -0400 Subject: [PATCH 17/25] removed white space --- src/org/infinity/gui/converter/ConvertToMos.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index e3062fa4c..27c4cec4c 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -661,11 +661,11 @@ public void actionPerformed(ActionEvent event) bConvert.setEnabled(isReady()); } else if (event.getSource() == bCompressionHelp) { final String helpMsg = - "\"DXT1\" provides the highest compression ratio. It supports only 1 bit alpha\n" + - "(i.e. either no or full transparency) and is the preferred type for TIS or MOS resources.\n\n" + - "\"DXT5\" provides an average compression ratio. It features interpolated\n" + - "alpha transitions and is the preferred type for BAM resources.\n\n" + - "\"Auto\" selects the most appropriate compression type based on the input data."; + "\"DXT1\" provides the highest compression ratio. It supports only 1 bit alpha\n" + + "(i.e. either no or full transparency) and is the preferred type for TIS or MOS resources.\n\n" + + "\"DXT5\" provides an average compression ratio. It features interpolated\n" + + "alpha transitions and is the preferred type for BAM resources.\n\n" + + "\"Auto\" selects the most appropriate compression type based on the input data."; JOptionPane.showMessageDialog(this, helpMsg, "About Compression Types", JOptionPane.INFORMATION_MESSAGE); } } From 2bc5022729df564f91d55bb275c00f6ee4d83c6c Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:57:10 -0400 Subject: [PATCH 18/25] added comment for required method even if unused --- src/org/infinity/gui/converter/ConvertToMos.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 27c4cec4c..400c84c8b 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -677,7 +677,7 @@ public void actionPerformed(ActionEvent event) @Override public void propertyChange(PropertyChangeEvent event) { - + // required method for class } //--------------------- End Interface PropertyChangeListener --------------------- From c1a182e091ca0a767e1576c31b9a369e326de7b3 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:58:05 -0400 Subject: [PATCH 19/25] fixed typo --- src/org/infinity/gui/converter/ConvertToMos.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 400c84c8b..1ecf8b18e 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -728,7 +728,7 @@ private void init() JPanel pFilesInputV1 = new JPanel(new GridBagLayout()); pFilesInputV1.setBorder(BorderFactory.createTitledBorder("Input Files")); - //output directory choice will defualt to source directory maybe? + // Output directory choice will default to source directory maybe? tfOutputV1 = new JTextField(); tfOutputV1.setText(""); tfOutputV1.addFocusListener(this); From e02c8f516984f6b3b50d967db4bcdcbf7c754cb9 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 22:59:47 -0400 Subject: [PATCH 20/25] removed commented code --- src/org/infinity/gui/converter/ConvertToMos.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 1ecf8b18e..663d4ca0b 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -743,7 +743,6 @@ public boolean isCellEditable(int rowIndex, int colIndex) { }; tfInputTableV1.setModel(inputTableModel); tfInputTableV1.setPreferredScrollableViewportSize(new Dimension(500,200)); -// tfInputTableV1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); spInputScroll = new JScrollPane(tfInputTableV1); //output table settings @@ -755,7 +754,6 @@ public boolean isCellEditable(int rowIndex, int colIndex) { TableColumn tfOutputTableProgressCol = tfOutputTableV1.getColumnModel().getColumn(1); tfOutputTableProgressCol.setCellRenderer(new ProgressCellRenderer()); tfOutputTableV1.setPreferredScrollableViewportSize(new Dimension(500,200)); -// tfOutputTableV1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); spOutputScroll = new JScrollPane(tfOutputTableV1); bInputV1 = new JButton("Select Input"); From 6bca6635c6a4a669ed6e556eaaad207af9acd38e Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 23:01:34 -0400 Subject: [PATCH 21/25] removed unused code --- src/org/infinity/gui/converter/ConvertToMos.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 663d4ca0b..20dec5f0d 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -915,9 +915,6 @@ public boolean isCellEditable(int rowIndex, int colIndex) { bCancel.setMargin(new Insets(i.top + 2, i.left, i.bottom + 2, i.right)); JPanel pButtons = new JPanel(new GridBagLayout()); -// c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, -// GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); -// pButtons.add(cbCloseOnExit, c); c = ViewerUtil.setGBC(c, 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); pButtons.add(new JPanel(), c); From 78b74e7f700e3d17acc492ef963c52fc175681b4 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Sat, 3 Jul 2021 23:05:45 -0400 Subject: [PATCH 22/25] changed to final for count --- src/org/infinity/gui/converter/ConvertToMos.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 20dec5f0d..b44da59bf 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -639,7 +639,7 @@ public void actionPerformed(ActionEvent event) File[] filePaths = getImageFileName(); if (filePaths != null) { for (File fileSelected : filePaths) { - System.out.println(fileSelected.getName()); + Logger.getLogger(this.getClass().getName()).log(Level.INFO, "File Selected : " + fileSelected.getName()); inputTableModel.addRow(new Object[] { fileSelected.getAbsolutePath()}); fileName = StreamUtils.replaceFileExtension(fileSelected.getName(), "MOS"); @@ -964,9 +964,9 @@ private void clear() private boolean isReady() { if (tfInputTableV1.getRowCount() > 0 && !tfOutputV1.getText().isEmpty()) { - for(String outPutTableFiles : getTableInputPaths()) { + for (String outPutTableFiles : getTableInputPaths()) { Path file = FileManager.resolve(outPutTableFiles); - if(!Files.isRegularFile(file)) { + if (!Files.isRegularFile(file)) { return false; } } @@ -1050,8 +1050,9 @@ private ArrayList getTableInputPaths() { } private ArrayList getTableOutputNames() { - ArrayList list = new ArrayList<>(); - if(tfOutputTableV1.getModel().getRowCount() > 0) { + final int count = tfOutputTableV1.getModel().getRowCount(); + if (count > 0) { + final ArrayList list = new ArrayList<>(count); for (int i = 0; i < tfOutputTableV1.getModel().getRowCount(); i++) { list.add(tfOutputTableV1.getModel().getValueAt(i, 0).toString()); } From 36981221e06c432a6b00bde8bf041e07a238a3f7 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Tue, 6 Jul 2021 19:06:51 -0400 Subject: [PATCH 23/25] fixed old function used --- src/org/infinity/gui/converter/ConvertToMos.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index b44da59bf..334ee15e2 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -370,7 +370,7 @@ public boolean convertV1(BufferedImage img, String mosFileName, boolean compress if (palIndex != null) { tileData[i] = (byte)(palIndex + 1); } else { - byte color = (byte)ColorConvert.nearestColorRGB(pixels[i], palette, true); + byte color = (byte)ColorConvert.getNearestColor(pixels[i], palette, 0.0, null); tileData[i] = (byte)(color + 1); colorCache.put(pixels[i], color); } @@ -939,7 +939,7 @@ public boolean isCellEditable(int rowIndex, int colIndex) { // finalizing dialog initialization pack(); - setMinimumSize(getPreferredSize()); + setMinimumSize(new Dimension(250, 400)); //getPreferredSize() setLocationRelativeTo(getParent()); setVisible(true); } From 0075e22ec84587e6058946652ca9c25235456084 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Wed, 7 Jul 2021 12:52:34 -0400 Subject: [PATCH 24/25] fixed spacing issue with v2 and shrink bug --- src/org/infinity/gui/converter/ConvertToMos.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index 334ee15e2..e95740def 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -872,7 +872,6 @@ public boolean isCellEditable(int rowIndex, int colIndex) { // setting up tabbed pane tabPane = new JTabbedPane(JTabbedPane.TOP); - JPanel pTabV1 = new JPanel(new GridBagLayout()); c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 2, 4), 0, 0); @@ -893,11 +892,17 @@ public boolean isCellEditable(int rowIndex, int colIndex) { JPanel pTabV2 = new JPanel(new GridBagLayout()); c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, - GridBagConstraints.HORIZONTAL, new Insets(4, 4, 2, 4), 0, 0); + GridBagConstraints.HORIZONTAL, new Insets(0, 4, 2, 4), 0, 0); pTabV2.add(pFilesV2, c); - c = ViewerUtil.setGBC(c, 0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, + c = ViewerUtil.setGBC(c, 0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 4, 4, 4), 0, 0); pTabV2.add(pOptionsV2, c); + + JPanel spacePanel = new JPanel(new GridBagLayout()); + c = ViewerUtil.setGBC(c, 0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, + GridBagConstraints.HORIZONTAL, new Insets(2, 4, 4, 4), 0, 0); + + pTabV2.add(spacePanel, c); tabPane.addTab("PVRZ-based (V2)", pTabV2); tabPane.setMnemonicAt(1, KeyEvent.VK_2); tabPane.setSelectedIndex(0); @@ -939,7 +944,7 @@ public boolean isCellEditable(int rowIndex, int colIndex) { // finalizing dialog initialization pack(); - setMinimumSize(new Dimension(250, 400)); //getPreferredSize() + setMinimumSize(new Dimension(1000, 800)); //getPreferredSize() setLocationRelativeTo(getParent()); setVisible(true); } From 4c8e5e9d8dd36a6a232ddb8760e62078af709745 Mon Sep 17 00:00:00 2001 From: Ryein Goddard Date: Thu, 8 Jul 2021 20:06:59 -0400 Subject: [PATCH 25/25] window now fresh after closed and reopened dialog opens in root and saves last location --- .../infinity/gui/converter/ConvertToMos.java | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/src/org/infinity/gui/converter/ConvertToMos.java b/src/org/infinity/gui/converter/ConvertToMos.java index e95740def..f8dff3633 100644 --- a/src/org/infinity/gui/converter/ConvertToMos.java +++ b/src/org/infinity/gui/converter/ConvertToMos.java @@ -79,6 +79,8 @@ public class ConvertToMos extends ChildFrame implements ActionListener, PropertyChangeListener, ChangeListener, FocusListener { private static String currentDir = Profile.getGameRoot().toString(); + private int fileDoneCount = 0; + private JTabbedPane tabPane; private JTable tfInputTableV1; private JTable tfOutputTableV1; @@ -209,12 +211,7 @@ private static boolean createPvrzPages(Path path, BufferedImage img, DxtEncoder. public ConvertToMos() { super("Convert to MOS", true); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - init(); - } - }); + init(); } //--------------------- Begin Class ChildFrame --------------------- @@ -238,6 +235,21 @@ public void propertyChange(PropertyChangeEvent event) { if ("progress".equals(event.getPropertyName())) { Integer progressIndex = (Integer) event.getNewValue(); tfOutputTableV1.setValueAt(progressIndex +"%", fileCount, 1); + +// System.out.println(fileCount); + if(progressIndex == 100) { + fileDoneCount++; + Logger.getLogger(this.getClass().getName()).log(Level.INFO, "--- File Done Count --- " + fileDoneCount); + + if(fileDoneCount == tfOutputTableV1.getRowCount()) { + fileDoneCount = 0; + Logger.getLogger(this.getClass().getName()).log(Level.INFO, "--- All files converted --- "); + + if(cbCloseOnExit.isSelected()) { + hideWindow(); + } + } + } } } } @@ -415,6 +427,7 @@ public boolean convertV1(BufferedImage img, String mosFileName, boolean compress // generating conversion summary result.add("Conversion finished successfully."); + return true; } @@ -920,6 +933,10 @@ public boolean isCellEditable(int rowIndex, int colIndex) { bCancel.setMargin(new Insets(i.top + 2, i.left, i.bottom + 2, i.right)); JPanel pButtons = new JPanel(new GridBagLayout()); + c = ViewerUtil.setGBC(c, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, + GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); + pButtons.add(cbCloseOnExit, c); + c = ViewerUtil.setGBC(c, 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); pButtons.add(new JPanel(), c); @@ -954,11 +971,31 @@ private void hideWindow() { clear(); setVisible(false); + this.dispose(); + this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); } // resetting dialog state private void clear() { + tfInputTableV1.clearSelection(); + tfOutputTableV1.clearSelection(); + + while(tfInputTableV1.getRowCount() > 0) + { + ((DefaultTableModel) tfInputTableV1.getModel()).removeRow(0); + } + + while(tfOutputTableV1.getRowCount() > 0) + { + ((DefaultTableModel) tfOutputTableV1.getModel()).removeRow(0); + } + + inputTableModel.setRowCount(0); + inputTableModel.setNumRows(0); + outputTableModel.setRowCount(0); + outputTableModel.setNumRows(0); + tfInputV2.setText(""); tfOutputV1.setText(""); tfOutputV2.setText(""); @@ -1003,7 +1040,8 @@ private String pvrzInfoString(Object o) private File[] getImageFileName() { - JFileChooser fc = new JFileChooser(); + Path file = FileManager.resolve(currentDir); + JFileChooser fc = new JFileChooser(file.toFile()); fc.setDialogTitle("Select input graphics files"); fc.setDialogType(JFileChooser.OPEN_DIALOG); @@ -1016,6 +1054,7 @@ private File[] getImageFileName() fc.setFileFilter(filters[0]); int ret = fc.showOpenDialog(this); if (ret == JFileChooser.APPROVE_OPTION) { + currentDir = fc.getSelectedFiles()[0].toPath().getParent().toString(); File[] filePaths = fc.getSelectedFiles(); for(File fileSelected : filePaths) { Logger.getLogger(this.getClass().getName()).log(Level.INFO, "File Selected : " + fileSelected.getName());