📄 gpbarfactory.java
字号:
return toolbar;
}
String[] toolKeys = tokenize(key, toolKey);
for (int i = 0; i < toolKeys.length; i++) {
if (toolKeys[i].equals("-")) {
toolbar.add(Box.createHorizontalStrut(5));
} else {
Component[] comps = createTool(toolKeys[i]);
for (int j = 0; j < comps.length; j++) {
toolbar.add(comps[j]);
}
}
}
toolbar.add(Box.createHorizontalGlue());
return toolbar;
}
/**
* Hook through which every toolbar item is created.
*/
protected Component[] createTool(String key) {
return createToolbarButton(key);
}
/**
* Create a button to go inside of the toolbar. By default this
* will load an image resource. The image filename is relative to
* the classpath (including the '.' directory if its a part of the
* classpath), and may either be in a JAR file or a separate file.
*
* @param key The key in the resource file to serve as the basis
* of lookups.
*/
protected Component[] createToolbarButton(String key) {
Action a = graphpad.getCurrentActionMap().get(key);
if (a instanceof AbstractActionDefault) {
return ((AbstractActionDefault) a).getToolComponents();
} else {
JButton item = new JButton();
item.setAction(a);
fillToolbarButton(item, key, "");
return new Component[] { item };
}
}
/** returns the action for the cmd key.
* The method inspects the action map at the graph pad
* to get the correct action.
*/
protected Action getAction(String cmd) {
Action a = null;
if (cmd != null) {
a = graphpad.getCurrentActionMap().get(cmd);
}
if (a != null)
return a;
else {
// Check for Plugin
String className = Translator.getString(cmd + "Plugin");
System.out.println("cmd=" + cmd + " className=" + className);
if (className != null) {
try {
final GPPlugin plugin =
(GPPlugin) getClass()
.getClassLoader()
.loadClass(className)
.newInstance();
if (plugin != null) {
Action action = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
plugin.execute(graphpad);
}
};
graphpad.getActionMap().put(cmd, action);
return action;
} else {
System.err.println(
"Can't find plugin Class: " + className);
}
} catch (Exception e) {
// ignore
}
}
}
return null;
}
/** fills the abstract button with values from
* the properties files.
*
*/
public static AbstractButton fillMenuButton(
AbstractButton button,
String key,
String actionCommand) {
button.putClientProperty(
LocaleChangeAdapter.DONT_SET_TOOL_TIP_TEXT,
new Boolean(true));
return fillAbstractButton(button, key, actionCommand);
}
/** fills the abstract button with values from
* the properties files.
*
*/
public static AbstractButton fillToolbarButton(
AbstractButton button,
String key,
String actionCommand) {
button.putClientProperty(
LocaleChangeAdapter.DONT_SET_MNEMONIC,
new Boolean(true));
button.putClientProperty(
LocaleChangeAdapter.SET_TEXT_IF_ICON_NOT_AVAILABLE,
new Boolean(true));
return fillAbstractButton(button, key, actionCommand);
}
/**
* The method fills the AbstractButton with
* the localized label, the image, the accelerator
* and the mnemonic.
*
*/
public static AbstractButton fillAbstractButton(
AbstractButton button,
String key,
String actionCommand) {
String label = null;
String tooltip = null;
ImageIcon icon = null;
if (key != null) {
button.setName(key);
//LocaleChangeAdapter.updateComponent(button);
/*
icon = ImageLoader.getImageIcon(
Translator.getString(key + SUFFIX_IMAGE));
if (icon != null) {
button.setHorizontalTextPosition(JButton.RIGHT);
button.setIcon(icon);
}
label = Translator.getString(key + SUFFIX_LABEL);
if (label != null)
button.setText(label);
tooltip = Translator.getString(key + SUFFIX_TOOL_TIP_TEXT);
if (tooltip==null)
tooltip = label;
if (tooltip!= null && (button instanceof JButton || button instanceof JToggleButton))
button.setToolTipText(tooltip);
if (icon != null && !setText)
button.setText(null);
// important that buttons in toolbars do not get
// mnemonics or accelerators as they compete with
// their menuitem counterparts
if (button instanceof JMenuItem){
String accel = Translator.getString(key + SUFFIX_ACCELERATOR);
if (accel != null && accel.length() > 0) {
KeyStroke keyStroke = KeyStroke.getKeyStroke(accel);
((JMenuItem) button).setAccelerator(keyStroke);
}
String mnemonic = Translator.getString(key + SUFFIX_MNEMONIC);
if (mnemonic != null && mnemonic.length() > 0)
button.setMnemonic(mnemonic.toCharArray()[0]);
}
*/
}
/*
if (icon == null && label == null)
button.setText(key);
*/
button.setActionCommand(actionCommand);
return button;
}
/** Tokenizes the value for the key and integrates
* bar entries.
*
*
*
* @see #integrateBarEntries(String, String[])
*/
protected String[] tokenize(String key, String value) {
String[] values = Utilities.tokenize(value);
values = integrateBarEntries(key, values);
return values;
}
/** Integrates bar entries, if available, for the key.
* If the position is out of the array the method
* ignores the bar entry.
*
* @param key Current key for the values
* @param values The tokenized values for the key.
* @see #addBarEntry
*
*/
protected String[] integrateBarEntries(String key, String[] values) {
Enumeration enum;
// get the bar entries for the key
Vector vector4BarKey = (Vector) barEntries.get(key);
// if there is no bar entry return
if (vector4BarKey == null || vector4BarKey.size() == 0)
return values;
// build a mutable list with the old values
Vector listValues = new Vector();
for (int i = 0; i < values.length; i++) {
listValues.add(values[i]);
}
// insert the bar entries
enum = vector4BarKey.elements();
while (enum.hasMoreElements()) {
GPBarEntry barEntry = (GPBarEntry) enum.nextElement();
try {
listValues.insertElementAt(
barEntry.getBarValue(),
barEntry.getPos());
} catch (Exception ex) {
System.err.println(
"Error while integrating Bar Entry" + barEntry);
System.err.println(ex.getMessage());
}
}
// build the new array with the old values and the
// bar entries
String[] newValues = new String[listValues.size()];
for (int i = 0; i < listValues.size(); i++) {
newValues[i] = (String) listValues.get(i);
}
return newValues;
}
/** Here you can add your own bar entries.
*
*/
public static void addBarEntry(GPBarEntry entry) {
Vector vector4BarKey = (Vector) barEntries.get(entry.getBarKey());
if (vector4BarKey == null) {
vector4BarKey = new Vector();
barEntries.put(entry.getBarKey(), vector4BarKey);
}
vector4BarKey.add(entry);
}
/** Here you can remove your own bar entries.
*/
public static void removeBarEntry(GPBarEntry entry) {
Vector vector4BarKey = (Vector) barEntries.get(entry.getBarKey());
if (vector4BarKey == null) {
return;
}
vector4BarKey.remove(entry);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -