Skip to content

Commit

Permalink
Added Highlighting Cells
Browse files Browse the repository at this point in the history
-Cell is red if needs to be updated
-Cell is yellow if it is installed
  • Loading branch information
goldbattle committed Jul 29, 2013
1 parent b91be5c commit 5b288e8
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/net/soartex/texture_patcher/Listeners.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Integer>(), new ArrayList<Integer>(), Color.red, Color.yellow);
t_p.table.getColumnModel().getColumn(1).setCellRenderer(tableRender);
t_p.table.updateUI();
} catch (Exception e2){}

} catch (final Exception e1) {

Expand Down Expand Up @@ -657,13 +665,19 @@ protected void checkUpdate () throws IOException, ParseException {
if (modslist.exists()) {

final ArrayList<String> updates = new ArrayList<String>();

final ArrayList<Integer> rows1 = new ArrayList<Integer>();

final ArrayList<Integer> rows2 = new ArrayList<Integer>();

final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(modslist)));

String readline;

while ((readline = in.readLine()) != null) {

int counter = 0;

for (final Object[] row : t_p.tableData) {

if (readline.split(",")[0].equals(row[1])) {
Expand All @@ -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++;

}

}
Expand All @@ -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 {

Expand Down
53 changes: 53 additions & 0 deletions src/net/soartex/texture_patcher/TableRender.java
Original file line number Diff line number Diff line change
@@ -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<Integer> rows1;
private ArrayList<Integer> rows2;
private Color color1;
private Color color2;

public TableRender(ArrayList<Integer> rows1, ArrayList<Integer> 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;
}
}
2 changes: 1 addition & 1 deletion src/net/soartex/texture_patcher/Texture_Patcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("")) {
Expand Down

0 comments on commit 5b288e8

Please sign in to comment.