Merge pull request #464 from Bl3nd/master
Exception with finding and opening an already opened resource
This commit is contained in:
commit
d5558a4b25
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
|
* @since 09/26/2011
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Workspace extends TranslatedVisibleComponent
|
public class Workspace extends TranslatedVisibleComponent {
|
||||||
{
|
|
||||||
public final DraggableTabbedPane tabs;
|
public final DraggableTabbedPane tabs;
|
||||||
public final JPanel buttonPanel;
|
public final JPanel buttonPanel;
|
||||||
public final JButton refreshClass;
|
public final JButton refreshClass;
|
||||||
public final Set<String> openedTabs = new HashSet<>();
|
public final Set<String> openedTabs = new HashSet<>();
|
||||||
|
|
||||||
public Workspace()
|
public Workspace() {
|
||||||
{
|
|
||||||
super("Workspace", TranslatedComponents.WORK_SPACE);
|
super("Workspace", TranslatedComponents.WORK_SPACE);
|
||||||
|
|
||||||
this.tabs = new DraggableTabbedPane();
|
this.tabs = new DraggableTabbedPane();
|
||||||
|
@ -80,8 +79,7 @@ public class Workspace extends TranslatedVisibleComponent
|
||||||
TabExitButton tabExitButton = (TabExitButton) ((JPopupMenu) ((JMenuItem) e.getSource()).getParent()).getInvoker();
|
TabExitButton tabExitButton = (TabExitButton) ((JPopupMenu) ((JMenuItem) e.getSource()).getParent()).getInvoker();
|
||||||
final int index = tabExitButton.getTabIndex();
|
final int index = tabExitButton.getTabIndex();
|
||||||
|
|
||||||
while (true)
|
while (true) {
|
||||||
{
|
|
||||||
if (tabs.getTabCount() <= 1)
|
if (tabs.getTabCount() <= 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -92,36 +90,34 @@ public class Workspace extends TranslatedVisibleComponent
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tabs.addMouseListener(new MouseListener()
|
tabs.addMouseListener(new MouseListener() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) { }
|
public void mouseClicked(MouseEvent e) {
|
||||||
@Override
|
}
|
||||||
public void mouseEntered(MouseEvent arg0) { }
|
|
||||||
@Override
|
|
||||||
public void mouseExited(MouseEvent arg0) { }
|
|
||||||
|
|
||||||
@Override
|
@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)
|
if (BLOCK_TAB_MENU)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (e.getButton() == 3)
|
if (e.getButton() == 3) {
|
||||||
{
|
|
||||||
Rectangle bounds = new Rectangle(1, 1, e.getX(), e.getY());
|
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);
|
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);
|
popUp.setVisible(true);
|
||||||
closeAllTabs.setText(TranslatedStrings.CLOSE_TAB + ": " + ((TabbedPane) c).tabName);
|
closeAllTabs.setText(TranslatedStrings.CLOSE_TAB + ": " + ((TabbedPane) c).tabName);
|
||||||
closeTab.setText(TranslatedStrings.CLOSE_TAB + ": " + ((TabbedPane) c).tabName);
|
closeTab.setText(TranslatedStrings.CLOSE_TAB + ": " + ((TabbedPane) c).tabName);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
popUp.setVisible(false);
|
popUp.setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +125,8 @@ public class Workspace extends TranslatedVisibleComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) { }
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
popUp.add(closeAllTabs);
|
popUp.add(closeAllTabs);
|
||||||
|
@ -163,24 +160,20 @@ public class Workspace extends TranslatedVisibleComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
//load class resources
|
//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));
|
addResource(container, name, new ClassViewer(container, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Load file resources
|
//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));
|
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
|
// Warn user and prevent 'nothing' from opening if no Decompiler is selected
|
||||||
if (BytecodeViewer.viewer.viewPane1.getSelectedDecompiler() == Decompiler.NONE &&
|
if (BytecodeViewer.viewer.viewPane1.getSelectedDecompiler() == Decompiler.NONE &&
|
||||||
BytecodeViewer.viewer.viewPane2.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());
|
BytecodeViewer.showMessage(TranslatedStrings.SUGGESTED_FIX_NO_DECOMPILER_WARNING.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -191,21 +184,17 @@ public class Workspace extends TranslatedVisibleComponent
|
||||||
final String workingName = container.getWorkingName(name);
|
final String workingName = container.getWorkingName(name);
|
||||||
|
|
||||||
//create a new tab if the resource isn't opened currently
|
//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);
|
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
|
//TODO openedTabs could be changed to a HashMap<String, Integer> for faster lookups
|
||||||
|
|
||||||
//search through each tab
|
//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
|
//find the matching resource and open it
|
||||||
ResourceViewer tab = ((TabbedPane)tabs.getTabComponentAt(i)).resource;
|
ResourceViewer tab = (ResourceViewer) tabs.getComponentAt(i);
|
||||||
if(tab.resource.workingName.equals(workingName))
|
if (tab.resource.workingName.equals(workingName)) {
|
||||||
{
|
|
||||||
tabs.setSelectedIndex(i);
|
tabs.setSelectedIndex(i);
|
||||||
break;
|
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
|
//start processing the resource to be viewed
|
||||||
if (resourceView instanceof ClassViewer)
|
if (resourceView instanceof ClassViewer)
|
||||||
resourceView.refresh(null);
|
resourceView.refresh(null);
|
||||||
|
@ -250,8 +238,7 @@ public class Workspace extends TranslatedVisibleComponent
|
||||||
return tabs.getComponents();
|
return tabs.getComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetWorkspace()
|
public void resetWorkspace() {
|
||||||
{
|
|
||||||
tabs.removeAll();
|
tabs.removeAll();
|
||||||
tabs.updateUI();
|
tabs.updateUI();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue