-
Notifications
You must be signed in to change notification settings - Fork 36
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 #22 from nccgroup/zehuan-dev
Export, import and clear tabs
- Loading branch information
Showing
6 changed files
with
139 additions
and
34 deletions.
There are no files selected for viewing
Binary file not shown.
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,82 @@ | ||
package trust.nccgroup.decoderimproved; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
|
||
public class ConfigPanel extends JPanel { | ||
JButton exportButton; | ||
JButton loadButton; | ||
JToggleButton clearButton; | ||
|
||
public ConfigPanel(ExtensionRoot extensionRoot) { | ||
this.setLayout(new FlowLayout(FlowLayout.LEFT)); | ||
exportButton = new JButton("Export all tabs to file"); | ||
loadButton = new JButton("Load tabs from file"); | ||
String clearButtonText = "Clear all tabs on exit"; | ||
clearButton = new JToggleButton(clearButtonText); | ||
|
||
this.add(exportButton); | ||
this.add(loadButton); | ||
this.add(clearButton); | ||
|
||
// Listeners | ||
exportButton.addActionListener((e) -> { | ||
try { | ||
JFileChooser fileChooser = new JFileChooser(); | ||
fileChooser.setDialogTitle("Save all data to..."); | ||
// Grab focus to save file dialog | ||
fileChooser.addHierarchyListener((_event) -> { | ||
grabFocus(); | ||
}); | ||
if (fileChooser.showSaveDialog(extensionRoot.multiDecoderTab) == JFileChooser.APPROVE_OPTION) { | ||
FileOutputStream fileOutputStream = new FileOutputStream(fileChooser.getSelectedFile()); | ||
// Get state and write to file | ||
fileOutputStream.write(extensionRoot.multiDecoderTab.getState().getBytes()); | ||
fileOutputStream.close(); | ||
} | ||
} catch (Exception ee) { | ||
Logger.printErrorFromException(ee); | ||
} | ||
}); | ||
|
||
loadButton.addActionListener((e) -> { | ||
try { | ||
JFileChooser fileChooser = new JFileChooser(); | ||
fileChooser.setDialogTitle("Load data from..."); | ||
// Grab focus to load file dialog | ||
fileChooser.addHierarchyListener((_event) -> { | ||
grabFocus(); | ||
}); | ||
if (fileChooser.showOpenDialog(extensionRoot.multiDecoderTab) == JFileChooser.APPROVE_OPTION) { | ||
// Read file content | ||
File selectedFile = fileChooser.getSelectedFile(); | ||
FileInputStream fileInputStream = new FileInputStream(selectedFile); | ||
byte[] fileContent = new byte[(int) selectedFile.length()]; | ||
fileInputStream.read(fileContent); | ||
fileInputStream.close(); | ||
extensionRoot.multiDecoderTab.setState(new String(fileContent), false); | ||
} | ||
} catch (Exception ee) { | ||
Logger.printErrorFromException(ee); | ||
JOptionPane.showMessageDialog(extensionRoot.multiDecoderTab, ee.getClass().getName() + ", please check extension errors for details", "Error loading file", JOptionPane.ERROR_MESSAGE); | ||
} | ||
}); | ||
|
||
clearButton.addItemListener((e) -> { | ||
try { | ||
if (clearButton.isSelected()) { | ||
extensionRoot.setClearState(); | ||
clearButton.setText("ALL TABS will be CLEARED on exit"); | ||
} else { | ||
extensionRoot.setSaveFullState(); | ||
clearButton.setText(clearButtonText); | ||
} | ||
} catch (Exception ee) { | ||
Logger.printErrorFromException(ee); | ||
} | ||
}); | ||
} | ||
} |
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
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