?? attributedisplay.java
字號(hào):
package com.ca.directory.jxplorer.viewer;
import javax.swing.*;
import java.lang.reflect.*;
import java.awt.*;
import java.awt.print.*;
import java.util.*;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.io.*;
import com.ca.directory.jxplorer.*;
import com.ca.commons.cbutil.*;
import com.ca.commons.naming.*;
import javax.naming.directory.*;
import javax.naming.NamingException;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
/**
* <p>AttributeDisplay holds a variety of display and editing
* classes, as well as a simple toolbar to allow switching
* between these. The main one is an HTML template displaying
* class, but there are (will be) also attribute editing and
* template editing classes...</p>
*
* <p>Note that this class is *not* thread safe.</p>
*/
public class AttributeDisplay extends JTabbedPane
implements DataSink, Printable
{
/**
* The HTML editor is always in position 1 (if present)
*/
public static final int HTMLRENDERER = 1;
/**
* The Table editor is always in position 2 (if present)
*/
public static final int EDITOR = 2;
/**
* The scroll pane that holds the main view object
*/
protected JScrollPane viewHolder;
/**
* The main view panel. This is what holds the various editors.
*/
protected JPanel view;
//protected JToolBar toolBar;
/**
* the source of directory data for all editors
*/
protected DataSource dataSource;
/**
* the currently viewed entry (may be null)
*/
protected DXEntry entry = null;
/**
* This is updated every time the user tabs to a new
* editor, or a different editor is loaded.
*/
protected PluggableEditor currentEditor;
/**
* The default html editor, that is usually available, and which
* displays html template files
*/
protected HTMLTemplateDisplay templateDisplay;
/**
* The default table editor, that is usually available, and displays
* entry data as a grid of strings. Binary data may be edited using
* special 'attribute editors'.
*/
protected TableAttributeEditor tableDisplay;
/**
* A convenience link to schema.
*/
//XXX? protected DirContext schemaInfo; // used to discover schema
/**
* A convenience link to the global JX properties list.
*/
protected Properties myProperties;
/**
* The printing preferences used to print the currently visible entry editor.
*/
private Properties printprefs = new Properties();
/**
* A hashtable of all the editors that have ever been used to display an
* entry in the current JX session. When an entry is loaded, these are
* checked first to determine whether an editor already exists, and if it
* does, it is re-used.
*/
protected Hashtable editors = new Hashtable();
/**
* a list containing the currently displayed editors
*/
protected Vector activeEditors = new Vector(8);
/**
* the parent frame displaying this object
*/
protected JFrame owner;
protected String oldOCSig = null; // a concatenation of the last used object classes.
/** A local copy of the JX component, to pass on to pluggable editors */
private JMenuBar registerMenu = null;
/** A local copy of the JX component, to pass on to pluggable editors */
private JToolBar registerButtons = null;
/** A local copy of the JX component, to pass on to pluggable editors */
private JTree registerTree = null;
/** A local copy of the JX component, to pass on to pluggable editors */
private JPopupMenu registerTreeMenu = null;
/** A local copy of the JX component, to pass on to pluggable editors */
private JFrame registerJX = null;
/**
* A local copy of the special class loader used to load the plugable
* editors.
*/
protected ClassLoader myLoader = null; // the class loader used for reading pluggable editors from zip/jar files.
/**
* A local copy of the special resource loader used to load the plugable
* editors and their associated resource files.
*/
protected CBResourceLoader resourceLoader = null; // the resource loader used for reading HTML templates from zip/jar files.
/**
* All Plugins must have this package prefix. Usually it is com.ca.directory.jxplorer.viewer,
* but it <i>can</i> be reset in the configuration.
*/
public static String PACKAGEPREFIX = "com.ca.directory.jxplorer.viewer.";
public static void setPackagePrefix(String prefix) { PACKAGEPREFIX = prefix; }
public static String getPackagePrefix() { return PACKAGEPREFIX; }
// Do we need an alternative 'BASESPREFIX' variable for when PACKAGEPREFIX is changed?
// public static String BASEPREFIX = "com.ca.directory.jxplorer.viewer.";
/**
* A utility constant - this is used in the editor hashtable to indicate
* that no pluggable editor has been found, and that there is no need
* to use the resource loader to look again.
*/
protected static final String NONE = "none";
/**
* A temporary copy of a component that is to be printed, used by the
* print thread mechanism to pass an editor image around.
*/
private Component printComponent = null;
/**
* Every time a tab is added or deleted, or a new tab is selected, a
* change event is triggered. Sometimes we'd like to ignore these
* while we're getting our tabs sorted out (i.e. when we're adding
* and deleting large numbers of tabs) and this flags that such
* changes should be ignored.
*
*/
protected boolean ignoreChangeEvents = false;
private static Logger log = Logger.getLogger(AttributeDisplay.class.getName());
/**
* The constructor for AttributeDisplay requires information
* about default file directories and urls. These are passed
* in via a Properties object, that should contain values for
* 'dir.templates', 'dir.htmldocs', and 'dir.local'.
* @param props list of defaults for file and url locations.
* @param owner the parent frame, used for gui sanity and L&F propogation
* @param resourceLoader the resource loader used to load HTML templates from zip/jar files
*/
public AttributeDisplay(Properties props, JFrame owner, CBResourceLoader resourceLoader)
{
super();
myProperties = props;
if (myProperties.containsKey("plugins.package"))
{
setPackagePrefix(myProperties.getProperty("plugins.package"));
log.fine("SETTING PLUGIN PREFIX TO: " + PACKAGEPREFIX);
}
else
log.fine("PLUGIN PREFIX UNCHANGED: " + PACKAGEPREFIX);
this.resourceLoader = resourceLoader;
this.owner = owner;
initHTMLEditor();
initTableEditor();
addEditor(templateDisplay);
/**
* This change listener is *intended* to listen for user initiated tab
* changes, rather than programmatic changes to the editor tabs (which
* are expected to look after themselves)
*/
addChangeListener( new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
if (ignoreChangeEvents) // sometimes when we're messing around we can fire heaps of
return; // change events - and there's no point paying attention to 'em.
int index = getSelectedIndex();
if (index >= 0 && activeEditors.size() > index && activeEditors.get(index) != null)
{
setCurrentEditor((PluggableEditor)activeEditors.get(index));
}
else // should never happen (ROTFL)
{
log.warning("internal error - unable to find editor # " + index + " in Attribute Display");
}
}
});
}
/**
* This specifies the class loader used to load plugin editors.
* (This may not be known when an AttributeDisplay object is first
* created, at which time only the default system class loader is used).
*/
public void registerClassLoader(ClassLoader loader)
{
myLoader = loader;
if (tableDisplay == null)
initTableEditor();
tableDisplay.registerClassLoader(loader);
}
/**
* delay initialising the html editor until we need it, or it is loaded by
* a background thread.
*/
protected synchronized void initHTMLEditor()
{
if (templateDisplay != null) return;
templateDisplay = new HTMLTemplateDisplay(this, myProperties, resourceLoader);
/*
* HTML editor is placed in the hashtable associated with the object
* class "top". Since *all* directory entries must have object class
* "top", this is the equivalent of saying the editor may be used for
* all object classes.
*/
//editors.put("top", templateDisplay);
// Set the html editor to be the current default editor.
currentEditor = templateDisplay;
}
/**
* delay initialising the table editor until we need it, or it is loaded by
* a background thread.
*/
protected synchronized void initTableEditor()
{
if (tableDisplay != null) return;
tableDisplay = new TableAttributeEditor(owner);
/*
* HTML editor is placed in the hashtable associated with the object
* class "top". Since *all* directory entries must have object class
* "top", this is the equivalent of saying the editor may be used for
* all object classes.
*/
//editors.put("top", tableDisplay); // can be used for all entries
}
/**
* The method @print@ must be implemented for @Printable@ interface.
*
*/
//(Magic Irina Spell...!)
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException
{
//Component printMe = getPrintComponent();
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.black); //set default foreground color to black
//for faster printing, turn off double buffering
//RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
Dimension d = printComponent.getSize(); //get size of document
double panelWidth = d.width; //width in pixels
double panelHeight = d.height; //height in pixels
double pageHeight = pf.getImageableHeight(); //height of printer page
double pageWidth = pf.getImageableWidth(); //width of printer page
double scale = pageWidth/panelWidth;
int totalNumPages = (int)Math.ceil(scale * panelHeight / pageHeight);
//make sure we don't print empty pages
if(pageIndex >= totalNumPages)
{
return Printable.NO_SUCH_PAGE;
}
//shift Graphic to line up with beginning of print-imageable region
g2.translate(pf.getImageableX(), pf.getImageableY());
//shift Graphic to line up with beginning of next page to print
g2.translate(0f, -pageIndex*pageHeight);
//scale the page so the width fits...
g2.scale(scale, scale);
// PRINT IT!
printComponent.paint(g2);
return Printable.PAGE_EXISTS;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -