Skip to content

Commit c932596

Browse files
committed
Removed last version of dnd. Added dnd support from weisJ theme. Also, I fixed a problem not being able to scroll when a class is open and switching themes. Not sure if it was happening to just me or not.
1 parent e6cdd92 commit c932596

2 files changed

Lines changed: 75 additions & 85 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public class MainViewerGUI extends JFrame
116116
public final SearchBoxPane searchBoxPane = new SearchBoxPane();
117117
public JSplitPane splitPane1;
118118
public JSplitPane splitPane2;
119-
119+
120120
//the root menu bar
121121
public final JMenuBar rootMenu = new JMenuBar();
122122

@@ -351,16 +351,20 @@ public MainViewerGUI()
351351
searchBoxPane.setPreferredSize(new Dimension(200, 50));
352352
searchBoxPane.setMinimumSize(new Dimension(200, 50));
353353
searchBoxPane.setMaximumSize(new Dimension(200, 2147483647));
354-
354+
355+
workPane.setPreferredSize(new Dimension(1500, 1000));
356+
355357
splitPane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, resourcePane, searchBoxPane);
356358
splitPane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitPane1, workPane);
359+
357360
getContentPane().add(splitPane2);
358361
splitPane2.setResizeWeight(0.05);
359362
splitPane1.setResizeWeight(0.5);
360363

361364
uiComponents.add(resourcePane);
362365
uiComponents.add(searchBoxPane);
363366
uiComponents.add(workPane);
367+
// uiComponents.add(hierarchy);
364368

365369
viewPane1.setDefault();
366370
viewPane2.setDefault();

src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java

Lines changed: 69 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.awt.Font;
66
import java.awt.event.InputEvent;
77
import java.awt.event.KeyEvent;
8+
import java.awt.event.MouseWheelEvent;
89
import java.awt.event.MouseWheelListener;
910
import javax.swing.JButton;
1011
import javax.swing.JCheckBox;
@@ -13,6 +14,7 @@
1314
import javax.swing.JTextField;
1415
import javax.swing.SwingUtilities;
1516
import javax.swing.text.BadLocationException;
17+
1618
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
1719
import org.fife.ui.rtextarea.RTextScrollPane;
1820
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
@@ -50,9 +52,9 @@
5052
* @author Konloch
5153
* @since 6/25/2021
5254
*/
53-
public class SearchableRSyntaxTextArea extends RSyntaxTextArea
54-
{
55-
private final RTextScrollPane scrollPane = new RTextScrollPane(this);
55+
public class SearchableRSyntaxTextArea extends RSyntaxTextArea {
56+
57+
private RTextScrollPane scrollPane = new RTextScrollPane(this);
5658
private final JPanel searchPanel = new JPanel(new BorderLayout());
5759
private final JTextField searchInput = new JTextField();
5860
private final JCheckBox caseSensitiveSearch = new TranslatedJCheckBox("Match case", TranslatedComponents.MATCH_CASE);
@@ -62,30 +64,26 @@ public class SearchableRSyntaxTextArea extends RSyntaxTextArea
6264
private final Color blackScrollBackground = new Color(0x232323);
6365
private final Color blackScrollForeground = new Color(0x575859);
6466
private Runnable onCtrlS;
65-
66-
public SearchableRSyntaxTextArea()
67-
{
68-
if(Configuration.lafTheme == LAFTheme.HIGH_CONTRAST_DARK)
69-
{
67+
68+
public SearchableRSyntaxTextArea() {
69+
if (Configuration.lafTheme == LAFTheme.HIGH_CONTRAST_DARK) {
7070
//this fixes the white border on the jScrollBar panes
7171
scrollPane.getHorizontalScrollBar().setBackground(blackScrollBackground);
7272
scrollPane.getHorizontalScrollBar().setForeground(blackScrollForeground);
7373
scrollPane.getVerticalScrollBar().setBackground(blackScrollBackground);
7474
scrollPane.getVerticalScrollBar().setForeground(blackScrollForeground);
75-
}
76-
else if(Configuration.lafTheme.isDark())
77-
{
75+
} else if (Configuration.lafTheme.isDark()) {
7876
//this fixes the white border on the jScrollBar panes
7977
scrollPane.getHorizontalScrollBar().setBackground(darkScrollBackground);
8078
scrollPane.getHorizontalScrollBar().setForeground(darkScrollForeground);
8179
scrollPane.getVerticalScrollBar().setBackground(darkScrollBackground);
8280
scrollPane.getVerticalScrollBar().setForeground(darkScrollForeground);
8381
}
84-
82+
8583
setAntiAliasingEnabled(true);
86-
84+
8785
scrollPane.setColumnHeaderView(searchPanel);
88-
86+
8987
JButton searchNext = new JButton();
9088
JButton searchPrev = new JButton();
9189
JPanel buttonPane = new JPanel(new BorderLayout());
@@ -96,133 +94,121 @@ else if(Configuration.lafTheme.isDark())
9694
searchPanel.add(buttonPane, BorderLayout.WEST);
9795
searchPanel.add(searchInput, BorderLayout.CENTER);
9896
searchPanel.add(caseSensitiveSearch, BorderLayout.EAST);
99-
97+
10098
searchNext.addActionListener(arg0 -> search(searchInput.getText(), true, caseSensitiveSearch.isSelected()));
10199
searchPrev.addActionListener(arg0 -> search(searchInput.getText(), false, caseSensitiveSearch.isSelected()));
102-
100+
103101
searchInput.addKeyListener(new ReleaseKeyListener(keyEvent ->
104102
{
105103
if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER)
106104
search(searchInput.getText(), true, caseSensitiveSearch.isSelected());
107105
}));
108-
106+
109107
addKeyListener(new PressKeyListener(keyEvent ->
110108
{
111109
if ((keyEvent.getKeyCode() == KeyEvent.VK_F) && ((keyEvent.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0))
112110
searchInput.requestFocus();
113-
114-
if (onCtrlS != null && (keyEvent.getKeyCode() == KeyEvent.VK_S) && ((keyEvent.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0))
115-
{
111+
112+
if (onCtrlS != null && (keyEvent.getKeyCode() == KeyEvent.VK_S) && ((keyEvent.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0)) {
116113
onCtrlS.run();
117114
return;
118115
}
119-
116+
120117
GlobalHotKeys.keyPressed(keyEvent);
121118
}));
122-
119+
123120
final Font newFont = getFont().deriveFont((float) BytecodeViewer.viewer.getFontSize());
124-
121+
125122
//set number-bar font
126123
setFont(newFont);
127-
128-
SwingUtilities.invokeLater(()-> {
124+
125+
SwingUtilities.invokeLater(() -> {
129126
//attach CTRL + Mouse Wheel Zoom
130127
attachCtrlMouseWheelZoom();
131-
128+
132129
//set text font
133130
setFont(newFont);
134131
});
135-
132+
136133
}
137-
138-
public void search(String search, boolean forwardSearchDirection, boolean caseSensitiveSearch)
139-
{
134+
135+
public void search(String search, boolean forwardSearchDirection, boolean caseSensitiveSearch) {
140136
JTextAreaUtils.search(this, search, forwardSearchDirection, caseSensitiveSearch);
141137
}
142-
143-
public void highlight(String pattern, boolean caseSensitiveSearch)
144-
{
138+
139+
public void highlight(String pattern, boolean caseSensitiveSearch) {
145140
JTextAreaUtils.highlight(this, pattern, caseSensitiveSearch);
146141
}
147-
148-
public void attachCtrlMouseWheelZoom()
149-
{
150-
//get the existing scroll event
151-
MouseWheelListener ogListener = scrollPane.getMouseWheelListeners().length > 0 ?
152-
scrollPane.getMouseWheelListeners()[0] : null;
153-
154-
//remove the existing event
155-
if(ogListener != null)
156-
scrollPane.removeMouseWheelListener(ogListener);
157-
158-
//add a new event
159-
scrollPane.addMouseWheelListener(e ->
160-
{
161-
if (getText().isEmpty())
162-
return;
163-
164-
if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0)
165-
{
142+
143+
public void attachCtrlMouseWheelZoom() {
144+
scrollPane.addMouseWheelListener(e -> {
145+
if (getText().isEmpty()) return;
146+
if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) {
166147
Font font = getFont();
167148
int size = font.getSize();
168-
169-
if (e.getWheelRotation() > 0) //Up
149+
if (e.getWheelRotation() > 0)
170150
setFont(new Font(font.getName(), font.getStyle(), --size >= 2 ? --size : 2));
171-
else //Down
151+
else
172152
setFont(new Font(font.getName(), font.getStyle(), ++size));
173-
153+
174154
e.consume();
175155
}
176-
else if(ogListener != null)
177-
{
178-
ogListener.mouseWheelMoved(e);
179-
}
180156
});
157+
158+
scrollPane = new RTextScrollPane() {
159+
@Override
160+
protected void processMouseWheelEvent(MouseWheelEvent event) {
161+
if (!isWheelScrollingEnabled()) {
162+
if (getParent() != null) {
163+
getParent().dispatchEvent(SwingUtilities.convertMouseEvent(this, event, getParent()));
164+
return;
165+
}
166+
}
167+
168+
super.processMouseWheelEvent(event);
169+
}
170+
};
171+
172+
scrollPane.setWheelScrollingEnabled(false);
181173
}
182-
174+
183175
public String getLineText(int line) {
184176
try {
185177
if (line < getLineCount()) {
186178
int start = getLineStartOffset(line);
187179
int end = getLineEndOffset(line);
188180
return getText(start, end - start).trim();
189181
}
190-
} catch (BadLocationException ignored) { }
182+
} catch (BadLocationException ignored) {
183+
}
191184
return "";
192185
}
193-
194-
public void setOnCtrlS(Runnable onCtrlS)
195-
{
186+
187+
public void setOnCtrlS(Runnable onCtrlS) {
196188
this.onCtrlS = onCtrlS;
197189
}
198-
199-
public RTextScrollPane getScrollPane()
200-
{
190+
191+
public RTextScrollPane getScrollPane() {
201192
return scrollPane;
202193
}
203-
204-
public JPanel getSearchPanel()
205-
{
194+
195+
public JPanel getSearchPanel() {
206196
return searchPanel;
207197
}
208-
209-
public JTextField getSearchInput()
210-
{
198+
199+
public JTextField getSearchInput() {
211200
return searchInput;
212201
}
213-
214-
public JCheckBox getCaseSensitiveSearch()
215-
{
202+
203+
public JCheckBox getCaseSensitiveSearch() {
216204
return caseSensitiveSearch;
217205
}
218-
219-
public JLabel getTitleHeader()
220-
{
206+
207+
public JLabel getTitleHeader() {
221208
return titleHeader;
222209
}
223-
224-
public Runnable getOnCtrlS()
225-
{
210+
211+
public Runnable getOnCtrlS() {
226212
return onCtrlS;
227213
}
228214
}

0 commit comments

Comments
 (0)