-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from jpage4500/feature/10-25
- new feature to save device logs to file; option to hide toolbar buttons
- Loading branch information
Showing
24 changed files
with
781 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/jpage4500/devicemanager/data/SaveLogEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.jpage4500.devicemanager.data; | ||
|
||
import java.io.File; | ||
|
||
public class SaveLogEntry { | ||
public Device device; | ||
public long numLines; | ||
public long size; | ||
public File saveFile; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/com/jpage4500/devicemanager/table/SaveLogsTableModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.jpage4500.devicemanager.table; | ||
|
||
import com.jpage4500.devicemanager.data.SaveLogEntry; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.swing.table.AbstractTableModel; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SaveLogsTableModel extends AbstractTableModel { | ||
private static final Logger log = LoggerFactory.getLogger(SaveLogsTableModel.class); | ||
|
||
private final List<SaveLogEntry> entryList; | ||
|
||
public enum Columns { | ||
NAME("Name"), | ||
SERIAL("Serial"), | ||
SIZE("Size"), | ||
; | ||
String desc; | ||
|
||
Columns(String desc) { | ||
this.desc = desc; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return desc; | ||
} | ||
} | ||
|
||
public SaveLogsTableModel() { | ||
entryList = new ArrayList<>(); | ||
} | ||
|
||
public void setEntryList(List<SaveLogEntry> entryList) { | ||
this.entryList.clear(); | ||
this.entryList.addAll(entryList); | ||
|
||
fireTableDataChanged(); | ||
} | ||
|
||
public List<SaveLogEntry> getEntryList() { | ||
return entryList; | ||
} | ||
|
||
public void notifyEntryUpdated(SaveLogEntry entry) { | ||
int index = entryList.indexOf(entry); | ||
if (index >= 0) { | ||
fireTableRowsUpdated(index, index); | ||
} | ||
} | ||
|
||
public int getColumnCount() { | ||
return Columns.values().length; | ||
} | ||
|
||
@Override | ||
public Class<?> getColumnClass(int columnIndex) { | ||
return SaveLogEntry.class; | ||
} | ||
|
||
public String getColumnName(int i) { | ||
Columns[] columns = Columns.values(); | ||
Columns colType = columns[i]; | ||
return colType.toString(); | ||
} | ||
|
||
public int getRowCount() { | ||
return entryList.size(); | ||
} | ||
|
||
public Object getValueAt(int row, int col) { | ||
if (row >= entryList.size()) return null; | ||
else if (col >= getColumnCount()) return null; | ||
|
||
return entryList.get(row); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/java/com/jpage4500/devicemanager/table/utils/SaveLogsCellRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.jpage4500.devicemanager.table.utils; | ||
|
||
import com.jpage4500.devicemanager.data.SaveLogEntry; | ||
import com.jpage4500.devicemanager.table.SaveLogsTableModel; | ||
import com.jpage4500.devicemanager.utils.Colors; | ||
import com.jpage4500.devicemanager.utils.FileUtils; | ||
import com.jpage4500.devicemanager.utils.UiUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.swing.*; | ||
import javax.swing.table.TableCellRenderer; | ||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
|
||
public class SaveLogsCellRenderer extends JLabel implements TableCellRenderer { | ||
private static final Logger log = LoggerFactory.getLogger(SaveLogsCellRenderer.class); | ||
|
||
private final Icon statusOfflineIcon; | ||
private final Icon statusOnlineIcon; | ||
private final Icon statusBusyIcon; | ||
private final Icon statusNotReadyIcon; | ||
|
||
public SaveLogsCellRenderer() { | ||
setOpaque(true); | ||
|
||
UiUtils.setEmptyBorder(this, 10, 10); | ||
|
||
BufferedImage image = UiUtils.getImage("device_status.png", UiUtils.IMG_SIZE_ICON, UiUtils.IMG_SIZE_ICON); | ||
|
||
BufferedImage offlineImage = UiUtils.replaceColor(image, Color.GRAY); | ||
statusOfflineIcon = new ImageIcon(offlineImage); | ||
|
||
BufferedImage onlineImage = UiUtils.replaceColor(image, Colors.COLOR_ONLINE); | ||
statusOnlineIcon = new ImageIcon(onlineImage); | ||
|
||
BufferedImage busyImage = UiUtils.replaceColor(image, Colors.COLOR_BUSY); | ||
statusBusyIcon = new ImageIcon(busyImage); | ||
|
||
BufferedImage notReadyImage = UiUtils.replaceColor(image, Colors.COLOR_NOT_READY); | ||
statusNotReadyIcon = new ImageIcon(notReadyImage); | ||
} | ||
|
||
public Component getTableCellRendererComponent(JTable table, Object object, boolean isSelected, boolean hasFocus, int row, int column) { | ||
SaveLogEntry entry = (SaveLogEntry) object; | ||
// convert table column to model column | ||
column = table.convertColumnIndexToModel(column); | ||
|
||
SaveLogsTableModel.Columns col = SaveLogsTableModel.Columns.values()[column]; | ||
Icon icon = null; | ||
String text = null; | ||
int align = SwingConstants.LEFT; | ||
switch (col) { | ||
case NAME: | ||
text = entry.device.nickname; | ||
if (entry.device.isBusy()) { | ||
icon = statusBusyIcon; | ||
} else if (entry.device.isOnline) { | ||
if (!entry.device.isBooted) icon = statusNotReadyIcon; | ||
else icon = statusOnlineIcon; | ||
} else { | ||
icon = statusOfflineIcon; | ||
} | ||
break; | ||
case SERIAL: | ||
text = entry.device.serial; | ||
break; | ||
case SIZE: | ||
// right-align size column | ||
align = SwingConstants.RIGHT; | ||
if (entry.size > 0) { | ||
text = FileUtils.bytesToDisplayString(entry.size); | ||
} else { | ||
text = "-"; | ||
} | ||
break; | ||
} | ||
|
||
boolean isTableFocused = table.hasFocus(); | ||
Color textColor = isSelected && isTableFocused ? Color.WHITE : Color.BLACK; | ||
Color backgroundColor = isSelected ? table.getSelectionBackground() : table.getBackground(); | ||
|
||
setForeground(textColor); | ||
setBackground(backgroundColor); | ||
|
||
setIcon(icon); | ||
setText(text); | ||
setHorizontalAlignment(align); | ||
|
||
return this; | ||
} | ||
} |
Oops, something went wrong.