Skip to content

Commit dbf624f

Browse files
committed
first commit
1 parent 4cc5381 commit dbf624f

File tree

142 files changed

+14493
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+14493
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
target/
2+
pom.xml.tag
3+
pom.xml.releaseBackup
4+
pom.xml.versionsBackup
5+
pom.xml.next
6+
release.properties
7+
dependency-reduced-pom.xml
8+
buildNumber.properties
9+
.mvn/timing.properties
10+
11+
.idea/
12+
*.iml
13+
14+
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
15+
!/.mvn/wrapper/maven-wrapper.jar

README.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
<p align="center">
3+
<a target="_blank" href="docs/images/JHexViewer-without-theme.png">
4+
<img width="400" src="docs/images/JHexViewer-without-theme.png" alt="without theme">
5+
</a>
6+
<a target="_blank" href="docs/images/JHexViewer-custom-theme.png">
7+
<img width="400" src="docs/images/JHexViewer-custom-theme.png" alt="custom dark theme">
8+
</a>
9+
</P>
10+
11+
12+
# What it is
13+
14+
JHexViewer is a basic hex viewer Swing component, which can be used to create more complex hex viewers based on it.
15+
16+
A lot of effort was put into making it customizable and easy to extend, instead of forcing you to stay with a fixed implementation. Nearly everything can be changed e.g. rendering of the content, Swing UI, layout of the rows etc.
17+
18+
It wasn't the goal to create a feature rich hex viewer as there are many existing tools out there. Instead I tried to focus on the core of a small hex viewer which builds the foundation for an easy to customize hex viewer.
19+
20+
**Main goals were:**
21+
22+
- to make it easy to customize and extend
23+
- content is drawn using the Java 2D API to make it as customizable as possible
24+
- complete exchangeable Swing UI
25+
- write code that can be easily modified
26+
27+
28+
# Features
29+
30+
- Instant opening regardless of file-size
31+
- currently only the first 50MB are displayed
32+
- Drag'n'Drop to load files
33+
- Context menus
34+
- Styleable row layout
35+
- padding and spacing between bytes
36+
- byte grouping
37+
- display 1, 2, 4, 8 or 16 bytes as columns
38+
- Styleable row rendering
39+
- use alternating background colors
40+
- render certain bytes in different colors to highlight them
41+
- Styleable highlighter
42+
- use different highlighters to mark ranges of bytes
43+
- overwrite the selection highlighter
44+
- Custom themes
45+
- Custom Swing UI
46+
- Many entry points to overwrite certain functionalities
47+
- painting of the areas (JHexViewer#setPaintRowsDelegate)
48+
- the caret (JHexViewer#setCaret)
49+
- the highlighter (JHexViewer#setHighlighter)
50+
- the scroll behavior (JHexViewer#setScrollableDelegate)
51+
- the row template factory (JHexViewer#.setRowTemplateFactory)
52+
- formatting of the displayed bytes or offset addresses (JHexViewer#setOffsetFormatter)
53+
- ...
54+
55+
56+
# Controls
57+
Files can be loaded by **drag and drop**.
58+
59+
- Action keys
60+
- caret actions
61+
- to move the caret (`arrow keys`)
62+
- to start/expand a selection (`mouse` and `arrow keys`)
63+
- font actions
64+
- increase font size (`crtl + '+'`)
65+
- decrease font size (`crtl + '-'`)
66+
- switch focus between areas (`tab`)
67+
68+
# Dependencies
69+
There are no third party dependencies used in the project.
70+
71+
# Build the project
72+
Requires Maven and Java 8 or higher to build.
73+
74+
To build the maven project, run one of the following mvn commands from the command line. The command should be executed in the directory which contains the relevant `pom.xml` file.
75+
76+
Compile and run:
77+
```
78+
mvn -q compile exec:java
79+
```
80+
81+
Compile and create executable jar file:
82+
```
83+
mvn -q compile assembly:single
84+
```
30.4 KB
Loading
28.5 KB
Loading

pom.xml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>cms.rendner.hexviewer</groupId>
8+
<artifactId>JHexViewer</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.codehaus.mojo</groupId>
21+
<artifactId>exec-maven-plugin</artifactId>
22+
<version>1.6.0</version>
23+
<configuration>
24+
<mainClass>Main</mainClass>
25+
</configuration>
26+
</plugin>
27+
<plugin>
28+
<groupId>org.apache.maven.plugins</groupId>
29+
<artifactId>maven-assembly-plugin</artifactId>
30+
<version>3.1.1</version>
31+
<configuration>
32+
<archive>
33+
<manifest>
34+
<mainClass>Main</mainClass>
35+
</manifest>
36+
</archive>
37+
<descriptorRefs>
38+
<descriptorRef>jar-with-dependencies</descriptorRef>
39+
</descriptorRefs>
40+
<finalName>${project.artifactId}</finalName>
41+
<appendAssemblyId>false</appendAssemblyId>
42+
</configuration>
43+
<executions>
44+
<execution>
45+
<phase>package</phase>
46+
<goals>
47+
<goal>single</goal>
48+
</goals>
49+
</execution>
50+
</executions>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
</project>

src/main/java/Main.java

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import cms.rendner.hexviewer.core.model.row.template.configuration.values.EMValue;
2+
import cms.rendner.hexviewer.core.JHexViewer;
3+
import cms.rendner.hexviewer.core.view.highlight.IHighlighter;
4+
import example.DataModelFactory;
5+
import example.ExampleContextMenuFactory;
6+
import example.themes.ThemeFactory;
7+
8+
import javax.swing.*;
9+
import java.beans.PropertyChangeEvent;
10+
import java.beans.PropertyChangeListener;
11+
12+
/**
13+
* @author rendner
14+
*/
15+
public class Main
16+
{
17+
public static void main(String[] args)
18+
{
19+
SwingUtilities.invokeLater(new Runnable()
20+
{
21+
public void run()
22+
{
23+
displayJFrame();
24+
}
25+
});
26+
}
27+
28+
static void displayJFrame()
29+
{
30+
final Main main = new Main();
31+
32+
try
33+
{
34+
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
35+
}
36+
catch (Exception e)
37+
{
38+
e.printStackTrace();
39+
}
40+
41+
final JFrame frame = new JFrame("JHexViewer");
42+
43+
final JComponent content = main.createHexViewer();
44+
content.addPropertyChangeListener(new PropertyChangeListener()
45+
{
46+
@Override
47+
public void propertyChange(final PropertyChangeEvent event)
48+
{
49+
if(event.getPropertyName().equals(JHexViewer.PROPERTY_DATA_MODEL))
50+
{
51+
frame.pack();
52+
}
53+
}
54+
});
55+
56+
frame.getContentPane().add(content);
57+
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
58+
frame.pack();
59+
frame.setVisible(true);
60+
}
61+
62+
private JComponent createHexViewer()
63+
{
64+
final JHexViewer hexViewer = new JHexViewer();
65+
hexViewer.setShowOffsetCaretIndicator(true);
66+
hexViewer.setDataModel(DataModelFactory.createRandomDataModel());
67+
hexViewer.setPreferredVisibleRowCount(23);
68+
hexViewer.setContextMenuFactory(new ExampleContextMenuFactory());
69+
70+
ThemeFactory.applyRandomTheme(hexViewer);
71+
72+
hexViewer.getRowTemplateConfiguration()
73+
.setBytesPerGroup(2)
74+
.setSpaceBetweenGroups(new EMValue(1))
75+
.setBytesPerRow(16)
76+
.commit();
77+
78+
final IHighlighter highlighter = hexViewer.getHighlighter();
79+
if (highlighter != null)
80+
{
81+
highlighter.setPaintSelectionBehindHighlights(false);
82+
}
83+
84+
return hexViewer;
85+
}
86+
}

0 commit comments

Comments
 (0)