Skip to content

Commit

Permalink
ehx/text can now be opened empty for notes
Browse files Browse the repository at this point in the history
  • Loading branch information
judovana committed Nov 9, 2022
1 parent 6d52020 commit db077cf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class FeatureFullHex extends JPanel {
private final LinesProvider hex;

public FeatureFullHex(final File f, final JTabbedPane parent, LinesProvider impl) throws IOException {
this.setName(f.getName());
this.setLayout(new BorderLayout());
JPanel tool = new JPanel();
tool.setLayout(new GridLayout(1, 6));
Expand Down Expand Up @@ -66,8 +65,15 @@ private List<LinesProvider> toLines(JTabbedPane parent) {
tool.add(close);
this.add(tool, BorderLayout.NORTH);
hex = impl;
hex.setFile(f);
hex.open(f);
if (f != null) {
this.setName(f.getName());
hex.setFile(f);
hex.open(f);
} else {
File ff = StandaloneHex.getNext();
this.setName(ff.getName());
hex.setFile(ff);
}
this.add(hex.asComponent(), BorderLayout.CENTER);
save.addActionListener(new ActionListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.io.File;
import java.io.IOException;
Expand All @@ -22,6 +23,7 @@

public class StandaloneHex extends JFrame {

private static int counter = 0;
File lastOpened = new File(System.getProperty("user.dir"));

public StandaloneHex(List<String> files) throws HeadlessException, IOException {
Expand All @@ -34,14 +36,23 @@ public StandaloneHex(List<String> files) throws HeadlessException, IOException {
JPanel wrapper = new FeatureFullHex(new File(s), tp, new HexWithControls(null));
tp.add(wrapper);
}
JPanel topButtons = new JPanel(new GridLayout(1, 2));
JButton openHex = new JButton("Open file (hex)");
openHex.setFont(openHex.getFont().deriveFont(Font.BOLD));
JButton exit = new JButton("exit");
JButton openEmptyHex = new JButton("Open empty hex");
topButtons.add(openEmptyHex, BorderLayout.WEST);
topButtons.add(openHex, BorderLayout.EAST);
JPanel lowButtons = new JPanel(new GridLayout(1, 2));
JButton openText = new JButton("Open file (text)... just because we can, it do not mean it is good idea");
JButton openEmptyText = new JButton("Open empty text");
openEmptyText.setFont(openEmptyText.getFont().deriveFont(Font.BOLD));
lowButtons.add(openEmptyText, BorderLayout.WEST);
lowButtons.add(openText, BorderLayout.EAST);
final JButton exit = new JButton("exit");
final JPanel plus = new JPanel(new BorderLayout());
plus.add(openHex, BorderLayout.NORTH);
plus.add(topButtons, BorderLayout.NORTH);
plus.add(exit, BorderLayout.CENTER);
plus.add(openText, BorderLayout.SOUTH);
plus.add(lowButtons, BorderLayout.SOUTH);
plus.setName("+");
tp.add(plus);
this.add(tp);
Expand All @@ -53,6 +64,19 @@ public StandaloneHex(List<String> files) throws HeadlessException, IOException {
openText.addActionListener(a -> {
addMainPanel(tp, openHex, plus, new TextWithControls(null));
});

openEmptyHex.addActionListener(a -> {
addEmptyMainPanel(tp, openHex, plus, new HexWithControls(null));
});

openEmptyText.addActionListener(a -> {
addEmptyMainPanel(tp, openHex, plus, new TextWithControls(null));
});
}

public static File getNext() {
counter++;
return new File(System.getProperty("user.home") + File.separator + "file" + counter);
}

private void addMainPanel(JTabbedPane tp, JButton openHex, JPanel plus, final LinesProvider lp) {
Expand All @@ -71,10 +95,24 @@ private void addMainPanel(JTabbedPane tp, JButton openHex, JPanel plus, final Li
}

private void movePlus(JTabbedPane tp, JPanel plus, File nwf, JComponent ffh) {
final int i = tp.getSelectedIndex();
tp.remove(plus);
tp.add(ffh);
tp.add(plus);
lastOpened = nwf;
if (nwf != null) {
lastOpened = nwf;
}
tp.setSelectedIndex(i);
}

private void addEmptyMainPanel(JTabbedPane tp, JButton openHex, JPanel plus, final LinesProvider lp) {
try {
FeatureFullHex ffh = new FeatureFullHex(null, tp, lp);
movePlus(tp, plus, null, ffh);
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(openHex, ex.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jrd.backend.data.MetadataProperties;
import org.jrd.backend.data.VmInfo;
import org.jrd.frontend.frame.about.AboutView;
import org.jrd.frontend.frame.hex.StandaloneHex;
import org.jrd.frontend.frame.license.LicenseView;
import org.jrd.frontend.frame.main.decompilerview.BytecodeDecompilerView;
import org.jrd.frontend.frame.main.decompilerview.DecompilationController;
Expand Down Expand Up @@ -48,6 +49,7 @@
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -97,6 +99,7 @@ public class MainFrameView {
private JMenuBar menuBar;
private JMenu jMenuConnect;
private JMenuItem jMenuItemNewConnection;
private JMenuItem openEditor;
private JMenu jMenuConfig;
private JMenuItem jMenuSettings;
private JMenuItem jMenuPluginEditor;
Expand Down Expand Up @@ -422,6 +425,17 @@ public void windowClosing(WindowEvent e) {
newConnectionDialogListener.actionPerformed(actionEvent);
});
jMenuConnect.add(jMenuItemNewConnection);
openEditor = new JMenuItem("Open Hex/Text notes");
openEditor.addActionListener(a -> {
StandaloneHex hexview = null;
try {
hexview = new StandaloneHex(new ArrayList<>());
hexview.setVisible(true);
} catch (IOException ex) {
Logger.getLogger().log(ex);
}
});
jMenuConnect.add(openEditor);
// jMenuConnect end

jMenuConfig = new JMenu("Configure");
Expand Down

0 comments on commit db077cf

Please sign in to comment.