📄 xbrowserlayout.java
字号:
exit();
}
public void propertyChange(PropertyChangeEvent evt)
{
String prop_name = evt.getPropertyName();
Object new_value = evt.getNewValue();
if( prop_name.equals("ActiveLNF") || prop_name.equals("ActiveTheme") )
updateLookAndFeel();
else if( prop_name.equals("ActiveDocumentContainer") )
setActiveDocumentContainer( (XDocumentContainerObject)new_value );
else if( prop_name.equals("ContainerTabPlacement") )
getDocumentContainer().setContainerTabPlacement( ((Integer)new_value).intValue() );
else if( prop_name.equals("NavigationToolBar") )
{
boolean state = ((Boolean)new_value).booleanValue();
mnuNavigationToolBar.setState(state);
pnlNorth.remove(tlbNavigation);
if( state==true )
pnlNorth.add(tlbNavigation, BorderLayout.NORTH);
validate();
}
else if( prop_name.equals("PersonalToolBar") )
{
boolean state = ((Boolean)new_value).booleanValue();
mnuPersonalToolBar.setState(state);
pnlNorth.remove(tlbPersonal);
if( state==true )
pnlNorth.add(tlbPersonal, BorderLayout.SOUTH);
validate();
}
else if( prop_name.equals("LocationToolBar") )
{
boolean state = ((Boolean)new_value).booleanValue();
mnuLocationToolBar.setState(state);
pnlNorth.remove(pnlLocationBar);
if( state==true )
pnlNorth.add(pnlLocationBar, BorderLayout.CENTER);
validate();
}
else if( prop_name.equals("StatusBar") )
{
boolean state = ((Boolean)new_value).booleanValue();
mnuStatusBar.setState(state);
getContentPane().remove(statusBar);
if( state==true )
getContentPane().add(statusBar, BorderLayout.SOUTH);
validate();
}
else if( prop_name.equals("SideBar") )
{
boolean state = ((Boolean)new_value).booleanValue();
mnuSideBar.setState(state);
pnlCenter.removeAll();
if( state==true )
{
spltMain.setRightComponent(pnlDocumentContainer);
spltMain.setLeftComponent(pluginBar);
spltMain.setDividerLocation(200);
pnlCenter.add(spltMain, BorderLayout.CENTER);
}
else
pnlCenter.add(pnlDocumentContainer, BorderLayout.CENTER);
validate();
}
else if( prop_name.equals("HomeURL") )
homeAction.putValue(Action.SHORT_DESCRIPTION,new_value.toString());
}
///////////////// XIBrowser Interface /////////////////////
public XDocument openInActiveDocument(XBookmark bookmark)
{
return showInActiveDocument( bookmark.getHRef() );
}
public XDocument openInNewDocument(XBookmark bookmark)
{
return showInNewDocument( bookmark.getHRef() );
}
public XDocument openInActiveDocument(XHistoryData history_data)
{
return showInActiveDocument( history_data.getLocation() );
}
public XDocument openInNewDocument(XHistoryData history_data)
{
return showInNewDocument( history_data.getLocation() );
}
public XDocument showInNewDocument(String url)
{
getDocumentContainer().createNewDocument();
return showInActiveDocument(url);
}
public XDocument showInActiveDocument(String url)
{
XDocument doc = getActiveDocument();
if( doc==null )
doc = getDocumentContainer().createNewDocument();
doc.showURL(url);
return doc;
}
public XDocumentContainer getDocumentContainer()
{
return documentContainer;
}
public void addDocumentContainerListener(XDocumentContainerListener doc_container_listener)
{
XAbstractDocumentContainer.addDocumentContainerListener(doc_container_listener);
}
public void removeDocumentContainerListener(XDocumentContainerListener doc_container_listener)
{
XAbstractDocumentContainer.removeDocumentContainerListener(doc_container_listener);
}
public void showPopupMenu(Component invoker, String hyper_link, int x, int y)
{
JPopupMenu popup = (hyper_link==null) ? rightPopup : hyperLinkPopup;
hyperLink = hyper_link;
popup.show(invoker,x,y);
}
public void showPopupMenu(Component invoker, int x, int y)
{
showPopupMenu(invoker, null, x, y);
}
///////////////// XIBrowser Interface /////////////////////
///////////////// XDocumentListener Interface /////////////////////
public void documentLoadingStarted(XDocument doc)
{
updateTitle();
cmbURL.setCurrentURL(doc.getRenderer().getPageCompletePath());
mnuBackwardHistory.update();
mnuForwardHistory.update();
updateComponents();
}
public void documentLoadingFinished(XDocument doc)
{
XHistoryData distory_data = XRepository.getHistoryManager().createNewHistoryData(doc.getRenderer().getPageCompletePath(), doc.getRenderer().getPageTitle());
XRepository.getHistoryManager().updateHistoryData(distory_data);
updateTitle();
mnuBackwardHistory.update();
mnuForwardHistory.update();
updateComponents();
}
public void pageAddedToDocumentHistory(XDocument doc, String url)
{
XHistoryData history_data = XRepository.getHistoryManager().createNewHistoryData(doc.getPageCompletePath(), doc.getPageTitle());
XRepository.getHistoryManager().addHistoryData(history_data);
if( doc==getActiveDocument() )
cmbURL.addURL(url);
}
///////////////// XDocumentListener Interface /////////////////////
///////////////// XDocumentContainerListener Interface /////////////////////
public void documentActivated(XDocument doc)
{
activeDocumentChanged(doc);
cmbURL.loadURLs(doc.getRenderer().getURLList(), doc.getRenderer().getCurrentURL());
}
public void documentAdded(XDocument doc)
{
doc.addDocumentListener(this);
activeDocumentChanged(doc);
}
public void documentClosed(XDocument doc)
{
doc.removeDocumentListener(this);
cmbURL.removeAllURLs();
activeDocumentChanged(null);
}
///////////////// XDocumentContainerListener Interface /////////////////////
private void buildActions()
{
backAction = new BackAction();
forwardAction = new ForwardAction();
reloadAction = new ReloadAction();
homeAction = new HomeAction();
stopAction = new StopAction();
findAction = new FindAction();
newPageAction = new NewPageAction();
printAction = new PrintAction();
printPreviewAction = new PrintPreviewAction();
copyAction = new CopyAction();
cutAction = new CutAction();
pasteAction = new PasteAction();
selectAllAction = new SelectAllAction();
saveAsAction = new SaveAsAction();
findAgainAction = new FindAgainAction();
refreshAction = new RefreshAction();
pageSourceAction = new PageSourceAction();
pagePropertiesAction = new PagePropertiesAction();
setAsHomeAction = new SetAsHomeAction();
optionsAction = new OptionsAction();
closeAllAction = new CloseAllAction();
closeAction = new CloseAction();
tileCascadeAction = new TileCascadeAction();
tileHorizontalAction = new TileHorizontalAction();
tileVerticalAction = new TileVerticalAction();
minimizeAllAction = new MinimizeAllAction();
restoreAllAction = new RestoreAllAction();
openInSameWindowAction = new OpenInSameWindowAction();
openInNewWindowAction = new OpenInNewWindowAction();
addToBookmarksAction = new AddToBookmarksAction();
historyAction = new HistoryAction();
}
private void updateComponents()
{
boolean have_doc = ( getActiveDocument()!=null );
backAction.setEnabled(have_doc && getActiveRenderer().hasBackwardHistory());
forwardAction.setEnabled(have_doc && getActiveRenderer().hasForwardHistory());
reloadAction.setEnabled(have_doc);
if( have_doc )
{
backAction.putValue(Action.SHORT_DESCRIPTION, getActiveRenderer().getPreviousPagePath());
forwardAction.putValue(Action.SHORT_DESCRIPTION, getActiveRenderer().getNextPagePath());
reloadAction.putValue(Action.SHORT_DESCRIPTION, getActiveRenderer().getCurrentURL());
}
else
{
backAction.putValue(Action.SHORT_DESCRIPTION, null);
forwardAction.putValue(Action.SHORT_DESCRIPTION, null);
reloadAction.putValue(Action.SHORT_DESCRIPTION, null);
}
pageSourceAction.setEnabled(have_doc && getActiveRenderer().hasSource());
pagePropertiesAction.setEnabled(have_doc);
closeAllAction.setEnabled(getDocumentContainer()!=null && getDocumentContainer().hasDocument());
stopAction.setEnabled(have_doc);
findAction.setEnabled(have_doc);
findAgainAction.setEnabled(have_doc);
printAction.setEnabled(have_doc);
printPreviewAction.setEnabled(have_doc);
saveAsAction.setEnabled(have_doc);
refreshAction.setEnabled(have_doc);
setAsHomeAction.setEnabled(have_doc);
closeAction.setEnabled(have_doc);
updateTilings();
}
private void updateTilings()
{
boolean tiling_condition = getDocumentContainer()!=null &&
getDocumentContainer().hasDocument() &&
XRepository.getConfiguration().getActiveDocumentContainer().supportsTiling();
tileCascadeAction.setEnabled(tiling_condition);
tileHorizontalAction.setEnabled(tiling_condition);
tileVerticalAction.setEnabled(tiling_condition);
minimizeAllAction.setEnabled(tiling_condition);
restoreAllAction.setEnabled(tiling_condition);
}
protected void updateLookAndFeel()
{
super.updateLookAndFeel();
SwingUtilities.updateComponentTreeUI(rightPopup);
SwingUtilities.updateComponentTreeUI(hyperLinkPopup);
SwingUtilities.updateComponentTreeUI(comboBoxPopup);
SwingUtilities.updateComponentTreeUI(mnuBookmarkQuickFile);
SwingUtilities.updateComponentTreeUI(tlbNavigation);
SwingUtilities.updateComponentTreeUI(tlbPersonal);
SwingUtilities.updateComponentTreeUI(pnlLocationBar);
SwingUtilities.updateComponentTreeUI(statusBar);
SwingUtilities.updateComponentTreeUI(spltMain);
SwingUtilities.updateComponentTreeUI(pluginBar);
}
protected void doEscapeCloseSupport()
{
}
private void updateTitle()
{
if( getActiveDocument()!=null )
super.setTitle( XProjectConstants.PRODUCT_NAME+" - "+getActiveDocument().getPageTitle() );
else
super.setTitle( XProjectConstants.PRODUCT_NAME );
}
private void setActiveDocumentContainer(XDocumentContainerObject doc_container)
{
XDocumentContainer old_doc_container = documentContainer;
if( old_doc_container!=null )
pnlDocumentContainer.remove(old_doc_container.getComponent());
try
{
documentContainer = doc_container.buildDocumentContainer();
}
catch( Exception e )
{
XRepository.getLogger().error(this, "Error on instantiating the Document Container!");
XRepository.getLogger().error(this, e);
}
documentContainer.setContainerTabPlacement(XRepository.getConfiguration().getContainerTabPlacement());
pnlDocumentContainer.add(documentContainer.getComponent(), BorderLayout.CENTER);
pnlDocumentContainer.validate();
updateTilings();
if( old_doc_container!=null )
old_doc_container.moveDocumentsTo(documentContainer);
}
private void showInActiveDocument(File file)
{
String str = "";
try
{
str = file.toURL().toString();
}
catch( Exception e )
{
str = file.toString();
}
showInActiveDocument(str);
}
private XDocument getActiveDocument()
{
if( getDocumentContainer()==null )
return null;
else
return getDocumentContainer().getActiveDocument();
}
private XRenderer getActiveRenderer()
{
return getActiveDocument().getRenderer();
}
private void activeDocumentChanged(XDocument doc)
{
mnuBackwardHistory.setDocument(doc);
mnuForwardHistory.setDocument(doc);
updateTitle();
updateComponents();
}
private void exit()
{
XRepository.getConfiguration().removePropertyChangeListener(this);
XRepository.getPluginManager().destroyAllPlugins();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -