use of com.wave.hextractor.object.FileDrop in project hextractor by sewave.
the class HexViewer method addAllListeners.
/**
* Adds all the program listeners.
*/
private void addAllListeners() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
closeApp();
}
});
asciiTextArea.addCaretListener(e -> refreshSelection());
asciiTextArea.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
doPop(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
doPop(e);
}
}
private void doPop(MouseEvent e) {
asciiTextArea.setCaretPosition(e.getX() / 8 + e.getY() / 18 * visibleColumns);
PopUpOffsetEntry menu = new PopUpOffsetEntry(getCaretEntry());
menu.show(e.getComponent(), e.getX(), e.getY());
}
});
/* (non-Javadoc)
* @see java.awt.event.AdjustmentListener#adjustmentValueChanged(java.awt.event.AdjustmentEvent)
*/
vsb.addAdjustmentListener(evt -> {
Adjustable source = evt.getAdjustable();
if (evt.getValueIsAdjusting()) {
return;
}
int orient = source.getOrientation();
if (orient == Adjustable.VERTICAL) {
int type = evt.getAdjustmentType();
int value = evt.getValue();
switch(type) {
case AdjustmentEvent.UNIT_INCREMENT:
offset += visibleColumns;
break;
case AdjustmentEvent.UNIT_DECREMENT:
offset -= visibleColumns;
break;
case AdjustmentEvent.BLOCK_INCREMENT:
offset += getOffsetBlock();
break;
case AdjustmentEvent.BLOCK_DECREMENT:
offset -= getOffsetBlock();
break;
case AdjustmentEvent.TRACK:
offset = value;
break;
default:
break;
}
asciiTextArea.setText(Utils.getTextArea(offset, getViewSize(), fileBytes, hexTable));
hexTextArea.setText(Utils.getHexAreaFixedWidth(offset, getViewSize(), fileBytes, visibleColumns));
asciiTextArea.setCaretPosition(asciiTextArea.getText().length());
}
});
vsb.getModel().addChangeListener(e -> {
offset = vsb.getValue();
refreshAll();
});
// Drop on new project, batch creation
new FileDrop(newPrjWin, files -> {
if (files != null) {
if (files.length > 1) {
newPrjWin.setCursor(new Cursor(Cursor.WAIT_CURSOR));
disableProjectWindow();
newPrjWin.repaint();
for (File file : files) {
try {
ProjectUtils.createProject(file);
} catch (Exception e) {
Utils.logException(e);
}
}
newPrjWin.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
newPrjWin.setVisible(false);
JOptionPane.showMessageDialog(asciiTextArea.getParent(), rb.getString(KeyConstants.KEY_NEW_PRJ_GENERATING_MSG), rb.getString(KeyConstants.KEY_NEW_PRJ_GENERATING_MSG), JOptionPane.INFORMATION_MESSAGE);
} else {
for (File file : files) {
newPrjWinFileInput.setText(file.getName());
projectFile = file;
selectProjectFileType(projectFile);
newPrjWinNameInput.setText(ProjectUtils.getProjectName(projectFile.getName()));
}
}
}
});
newPrjWinFileInput.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
cleanFile();
}
@Override
public void removeUpdate(DocumentEvent e) {
cleanFile();
}
@Override
public void insertUpdate(DocumentEvent e) {
cleanFile();
}
void cleanFile() {
projectFile = null;
}
});
searchResults.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
@SuppressWarnings("unchecked") JList<TableSearchResult> list = (JList<TableSearchResult>) evt.getSource();
TableSearchResult tsr = list.getSelectedValue();
if (evt.getClickCount() == 1 && tsr != null) {
if (SwingUtilities.isLeftMouseButton(evt)) {
offset = tsr.getOffset();
asciiTextArea.setCaretPosition(0);
hexTextArea.setCaretPosition(0);
refreshAll();
}
if (SwingUtilities.isRightMouseButton(evt)) {
int selectedOption = JOptionPane.showConfirmDialog(null, rb.getString(KeyConstants.KEY_SEARCH_RESULT_TABLE), rb.getString(KeyConstants.KEY_SEARCH_RESULT_TABLE_TITLE), JOptionPane.YES_NO_OPTION);
if (selectedOption == JOptionPane.YES_OPTION) {
offset = tsr.getOffset();
hexTable = tsr.getHexTable();
refreshAll();
}
}
}
}
});
new FileDrop(this, files -> {
if (files != null && files.length > 0) {
requestFocus();
requestFocusInWindow();
for (File file : files) {
if (file.getAbsolutePath().endsWith(EXTENSION_TABLE)) {
reloadTableFile(file);
} else {
if (file.getAbsolutePath().endsWith(EXTENSION_OFFSET)) {
reloadOffsetsFile(file);
} else {
if (file.getAbsolutePath().endsWith(EXTENSION_EXTRACTION)) {
reloadExtAsOffsetsFile(file);
} else {
reloadHexFile(file);
}
}
}
}
}
});
addMouseWheelListener(e -> {
if (e.getWheelRotation() < 0) {
if (offset > visibleColumns) {
offset -= visibleColumns;
}
} else {
if (offset < fileBytes.length - getViewSize()) {
offset += visibleColumns;
}
}
refreshAll();
});
addListenerForKeys();
}
Aggregations