From 5b288e80c80089d4aa448a58e72d2e3547c9871f Mon Sep 17 00:00:00 2001 From: goldbattle Date: Sun, 28 Jul 2013 23:23:38 -0400 Subject: [PATCH] Added Highlighting Cells -Cell is red if needs to be updated -Cell is yellow if it is installed --- .../soartex/texture_patcher/Listeners.java | 33 +++++++++++- .../soartex/texture_patcher/TableRender.java | 53 +++++++++++++++++++ .../texture_patcher/Texture_Patcher.java | 2 +- 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/net/soartex/texture_patcher/TableRender.java diff --git a/src/net/soartex/texture_patcher/Listeners.java b/src/net/soartex/texture_patcher/Listeners.java index 59818d2..4234207 100644 --- a/src/net/soartex/texture_patcher/Listeners.java +++ b/src/net/soartex/texture_patcher/Listeners.java @@ -1,5 +1,6 @@ package net.soartex.texture_patcher; +import java.awt.Color; import java.awt.Desktop; import java.awt.Frame; import java.awt.GridBagConstraints; @@ -286,6 +287,13 @@ protected BrowseListener (final Texture_Patcher t_p) { t_p.prefsnode.put("path", file.getAbsolutePath()); t_p.prefsnode.put("lastDir", file.getParent()); + + // Clear cell highlighting + try { + TableRender tableRender = new TableRender(new ArrayList(), new ArrayList(), Color.red, Color.yellow); + t_p.table.getColumnModel().getColumn(1).setCellRenderer(tableRender); + t_p.table.updateUI(); + } catch (Exception e2){} } catch (final Exception e1) { @@ -657,6 +665,10 @@ protected void checkUpdate () throws IOException, ParseException { if (modslist.exists()) { final ArrayList updates = new ArrayList(); + + final ArrayList rows1 = new ArrayList(); + + final ArrayList rows2 = new ArrayList(); final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(modslist))); @@ -664,6 +676,8 @@ protected void checkUpdate () throws IOException, ParseException { while ((readline = in.readLine()) != null) { + int counter = 0; + for (final Object[] row : t_p.tableData) { if (readline.split(",")[0].equals(row[1])) { @@ -682,10 +696,20 @@ protected void checkUpdate () throws IOException, ParseException { final long newdate = ((Date) row[5]).getTime(); - if (olddate < newdate) updates.add((String) row[1]); + // Add if it needs to be updated + if (olddate < newdate) { + updates.add((String) row[1]); + rows1.add(counter); + } + // Add to generic list of what is installed + else { + rows2.add(counter); + } } + counter++; + } } @@ -705,6 +729,13 @@ protected void checkUpdate () throws IOException, ParseException { } } + + // Display highlighting boxes + try { + TableRender tableRender = new TableRender(rows1, rows2, Color.red, Color.yellow); + t_p.table.getColumnModel().getColumn(1).setCellRenderer(tableRender); + t_p.table.updateUI(); + } catch (Exception e2){} } else { diff --git a/src/net/soartex/texture_patcher/TableRender.java b/src/net/soartex/texture_patcher/TableRender.java new file mode 100644 index 0000000..c2ce63b --- /dev/null +++ b/src/net/soartex/texture_patcher/TableRender.java @@ -0,0 +1,53 @@ +package net.soartex.texture_patcher; + +import java.awt.Color; +import java.awt.Component; +import java.util.ArrayList; + +import javax.swing.BorderFactory; +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +/** + * Texture_Patcher Cell Coloring + * + * @author GoldBattle + * @version 1.3 + * + */ +final class TableRender extends DefaultTableCellRenderer{ + + private static final long serialVersionUID = 1L; + private ArrayList rows1; + private ArrayList rows2; + private Color color1; + private Color color2; + + public TableRender(ArrayList rows1, ArrayList rows2, Color color1, Color color2){ + this.rows1=rows1; + this.rows2=rows2; + this.color1=color1; + this.color2=color2; + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + // Act as normal + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + // Add custom behavior 1 + for(int i: rows1){ + if(row == i) { + // this will customize that kind of border that will be use to highlight a row + setBorder(BorderFactory.createMatteBorder(1, 2, 1, 2, color1)); + } + } + // Add custom behavior 2 + for(int i: rows2){ + if(row == i) { + // this will customize that kind of border that will be use to highlight a row + setBorder(BorderFactory.createMatteBorder(1, 2, 1, 2, color2)); + } + } + return this; + } +} \ No newline at end of file diff --git a/src/net/soartex/texture_patcher/Texture_Patcher.java b/src/net/soartex/texture_patcher/Texture_Patcher.java index cc8898d..94b954a 100644 --- a/src/net/soartex/texture_patcher/Texture_Patcher.java +++ b/src/net/soartex/texture_patcher/Texture_Patcher.java @@ -230,7 +230,7 @@ else if (!debug) { // Used for testing. if (debug) readLine = "http://soartex.net/texture-patcher/data/config.json"; - if (debug) readLine2 = "http://soartex.net/texture-patcher/data/branches_dev.json"; + if (debug) readLine2 = "http://soartex.net/texture-patcher/data/branches.json"; // If the second config line for branches is not there. Return normal branch if (readLine2==null || readLine2.equals("")) {