Fixed exception when clicking a class that's already open.
This commit is contained in:
parent
ae6911658c
commit
aa9b4bacf4
1 changed files with 154 additions and 167 deletions
|
@ -50,15 +50,14 @@ import static the.bytecode.club.bytecodeviewer.Constants.BLOCK_TAB_MENU;
|
|||
* @since 09/26/2011
|
||||
*/
|
||||
|
||||
public class Workspace extends TranslatedVisibleComponent
|
||||
{
|
||||
public class Workspace extends TranslatedVisibleComponent {
|
||||
|
||||
public final DraggableTabbedPane tabs;
|
||||
public final JPanel buttonPanel;
|
||||
public final JButton refreshClass;
|
||||
public final Set<String> openedTabs = new HashSet<>();
|
||||
|
||||
public Workspace()
|
||||
{
|
||||
public Workspace() {
|
||||
super("Workspace", TranslatedComponents.WORK_SPACE);
|
||||
|
||||
this.tabs = new DraggableTabbedPane();
|
||||
|
@ -80,8 +79,7 @@ public class Workspace extends TranslatedVisibleComponent
|
|||
TabExitButton tabExitButton = (TabExitButton) ((JPopupMenu) ((JMenuItem) e.getSource()).getParent()).getInvoker();
|
||||
final int index = tabExitButton.getTabIndex();
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
if (tabs.getTabCount() <= 1)
|
||||
return;
|
||||
|
||||
|
@ -92,36 +90,34 @@ public class Workspace extends TranslatedVisibleComponent
|
|||
}
|
||||
});
|
||||
|
||||
tabs.addMouseListener(new MouseListener()
|
||||
{
|
||||
tabs.addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) { }
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) { }
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) { }
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (BLOCK_TAB_MENU)
|
||||
return;
|
||||
|
||||
if (e.getButton() == 3)
|
||||
{
|
||||
if (e.getButton() == 3) {
|
||||
Rectangle bounds = new Rectangle(1, 1, e.getX(), e.getY());
|
||||
|
||||
for (int i = 0; i < BytecodeViewer.viewer.workPane.tabs.getTabCount(); i++)
|
||||
{
|
||||
for (int i = 0; i < BytecodeViewer.viewer.workPane.tabs.getTabCount(); i++) {
|
||||
Component c = BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(i);
|
||||
if (c != null && bounds.intersects(c.getBounds()))
|
||||
{
|
||||
if (c != null && bounds.intersects(c.getBounds())) {
|
||||
popUp.setVisible(true);
|
||||
closeAllTabs.setText(TranslatedStrings.CLOSE_TAB + ": " + ((TabbedPane) c).tabName);
|
||||
closeTab.setText(TranslatedStrings.CLOSE_TAB + ": " + ((TabbedPane) c).tabName);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
popUp.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +125,8 @@ public class Workspace extends TranslatedVisibleComponent
|
|||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) { }
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
popUp.add(closeAllTabs);
|
||||
|
@ -163,24 +160,20 @@ public class Workspace extends TranslatedVisibleComponent
|
|||
}
|
||||
|
||||
//load class resources
|
||||
public void addClassResource(final ResourceContainer container, final String name)
|
||||
{
|
||||
public void addClassResource(final ResourceContainer container, final String name) {
|
||||
addResource(container, name, new ClassViewer(container, name));
|
||||
}
|
||||
|
||||
//Load file resources
|
||||
public void addFileResource(final ResourceContainer container, final String name)
|
||||
{
|
||||
public void addFileResource(final ResourceContainer container, final String name) {
|
||||
addResource(container, name, new FileViewer(container, name));
|
||||
}
|
||||
|
||||
private void addResource(final ResourceContainer container, final String name, final ResourceViewer resourceView)
|
||||
{
|
||||
private void addResource(final ResourceContainer container, final String name, final ResourceViewer resourceView) {
|
||||
// Warn user and prevent 'nothing' from opening if no Decompiler is selected
|
||||
if (BytecodeViewer.viewer.viewPane1.getSelectedDecompiler() == Decompiler.NONE &&
|
||||
BytecodeViewer.viewer.viewPane2.getSelectedDecompiler() == Decompiler.NONE &&
|
||||
BytecodeViewer.viewer.viewPane3.getSelectedDecompiler() == Decompiler.NONE)
|
||||
{
|
||||
BytecodeViewer.viewer.viewPane3.getSelectedDecompiler() == Decompiler.NONE) {
|
||||
BytecodeViewer.showMessage(TranslatedStrings.SUGGESTED_FIX_NO_DECOMPILER_WARNING.toString());
|
||||
return;
|
||||
}
|
||||
|
@ -191,21 +184,17 @@ public class Workspace extends TranslatedVisibleComponent
|
|||
final String workingName = container.getWorkingName(name);
|
||||
|
||||
//create a new tab if the resource isn't opened currently
|
||||
if (!openedTabs.contains(workingName))
|
||||
{
|
||||
if (!openedTabs.contains(workingName)) {
|
||||
addResourceToTab(resourceView, workingName, container.name, name);
|
||||
}
|
||||
else //if the resource is already opened select this tab as the active one
|
||||
} else //if the resource is already opened select this tab as the active one
|
||||
{
|
||||
//TODO openedTabs could be changed to a HashMap<String, Integer> for faster lookups
|
||||
|
||||
//search through each tab
|
||||
for(int i = 0; i < tabs.getTabCount(); i++)
|
||||
{
|
||||
for (int i = 0; i < tabs.getTabCount(); i++) {
|
||||
//find the matching resource and open it
|
||||
ResourceViewer tab = ((TabbedPane)tabs.getTabComponentAt(i)).resource;
|
||||
if(tab.resource.workingName.equals(workingName))
|
||||
{
|
||||
ResourceViewer tab = (ResourceViewer) tabs.getComponentAt(i);
|
||||
if (tab.resource.workingName.equals(workingName)) {
|
||||
tabs.setSelectedIndex(i);
|
||||
break;
|
||||
}
|
||||
|
@ -213,8 +202,7 @@ public class Workspace extends TranslatedVisibleComponent
|
|||
}
|
||||
}
|
||||
|
||||
public void addResourceToTab(ResourceViewer resourceView, String workingName, String containerName, String name)
|
||||
{
|
||||
public void addResourceToTab(ResourceViewer resourceView, String workingName, String containerName, String name) {
|
||||
//start processing the resource to be viewed
|
||||
if (resourceView instanceof ClassViewer)
|
||||
resourceView.refresh(null);
|
||||
|
@ -250,8 +238,7 @@ public class Workspace extends TranslatedVisibleComponent
|
|||
return tabs.getComponents();
|
||||
}
|
||||
|
||||
public void resetWorkspace()
|
||||
{
|
||||
public void resetWorkspace() {
|
||||
tabs.removeAll();
|
||||
tabs.updateUI();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue