📄 macroplugin.java
字号:
}
while(id<0);
// 2 - We get the selected macro...
String macro;
if(id>MAX_MACROS-1 || macrosFields[id]==null)
macro = "#macro not found#";
else if(macrosFound[id])
macro = "#macro used twice#";
else {
macro = macrosFields[id].getText();
macrosFound[id]= true;
}
// 3 - Replace the macro call by the macro's text.
StringBuffer buf = new StringBuffer(text.substring(0,pos));
buf.append(macro);
if(pos2+1<text.length())
buf.append(text.substring(pos2+1,text.length()));
text = buf.toString();
}
while(true);
}
/*------------------------------------------------------------------------------------*/
/** To add a new macros to our list.
* @param macro text of the macro
*/
protected void addMacro( String macro ) {
int index=0;
while( index<MAX_MACROS && macrosFields[index]!=null )
index++;
if(index==MAX_MACROS) {
JOptionPane.showMessageDialog( null, "Maximum number of Macros reached !","Warning", JOptionPane.WARNING_MESSAGE);
return;
}
macrosPanel[index] = new JPanel( new BorderLayout() );
macrosRadios[index]= new ARadioButton(""+index);
macrosFields[index] = new ATextField(macro,12);
macrosPanel[index].add(macrosRadios[index],BorderLayout.WEST);
macrosPanel[index].add(macrosFields[index],BorderLayout.EAST);
centerPanel.add(macrosPanel[index]);
macrosGroup.add(macrosRadios[index]);
macrosRadios[index].setSelected(true);
centerPanel.validate();
}
/*------------------------------------------------------------------------------------*/
/** To remove a new macros to our list.
* @param index index of the macros to remove
*/
protected void removeMacro( int index ) {
if(index<0) return;
// we remove the panel & other components
centerPanel.remove(macrosPanel[index]);
macrosGroup.remove(macrosRadios[index]);
macrosPanel[index] = null;
macrosRadios[index]= null;
macrosFields[index] = null;
// we shift the eventual macros that are on the right
int i;
for( i=index; i<MAX_MACROS-1 && macrosPanel[i+1]!=null; i++ ) {
macrosPanel[i] = macrosPanel[i+1];
macrosRadios[i] = macrosRadios[i+1];
macrosFields[i] = macrosFields[i+1];
macrosRadios[i].setText(""+i);
}
if(macrosFields[i]!=null) {
// we remove the copy of the last element of the list
macrosPanel[i] = null;
macrosRadios[i]= null;
macrosFields[i] = null;
}
// we validate & repaint...
centerPanel.validate();
centerPanel.repaint();
if(macrosRadios[index]!=null)
macrosRadios[index].setSelected(true);
else if(index-1>=0 && macrosRadios[index-1]!=null)
macrosRadios[index-1].setSelected(true);
else if(macrosRadios[0]!=null)
macrosRadios[0].setSelected(true);
}
/*------------------------------------------------------------------------------------*/
/** To get our macros list.
* @return all the macros
*/
protected String[] getMacros() {
int nb=0;
while( nb<MAX_MACROS && macrosFields[nb]!=null )
nb++;
String list[] = new String[nb];
for( int i=0; i<nb; i ++ )
list[i] = macrosFields[i].getText();
return list;
}
/*------------------------------------------------------------------------------------*/
/** To get a macro from our list.
* @param index inde of the macro to get
*/
protected String getMacro(int index) {
if( index<0 || index>=MAX_MACROS || macrosFields[index]==null )
return "Macro not found !! ("+index+")";
return macrosFields[index].getText();
}
/*------------------------------------------------------------------------------------*/
/** To get the selected index in the macro list.
* @return the first selected index, -1 if none
*/
protected int getSelectedIndex() {
for( int i=0; i<MAX_MACROS && macrosPanel[i]!=null; i++ )
if( macrosRadios[i].isSelected() )
return i;
return -1; // none selected !!! should never happen
}
/*------------------------------------------------------------------------------------*/
/** Returns the name of the plug-in that will be displayed in the JPlayerPanel.
* @return a short name for the plug-in
*/
public String getPlugInName() {
return "Macro";
}
/*------------------------------------------------------------------------------------*/
/** Returns the name of the plug-in's author.
* @return author name.
*/
public String getPlugInAuthor() {
return "Wotlas Team (Aldiss & Fred)";
}
/*------------------------------------------------------------------------------------*/
/** Returns the tool tip text that will be displayed in the JPlayerPanel.
* @return a short tool tip text
*/
public String getToolTipText() {
return "To create HTML macros";
}
/*------------------------------------------------------------------------------------*/
/** Eventual index in the list of JPlayerPanels
* @return -1 if the plug-in has to be added at the end of the plug-in list,
* otherwise a positive integer for a precise location.
*/
public int getPlugInIndex() {
return -1;
}
/*------------------------------------------------------------------------------------*/
/** Tells if this plug-in is a system plug-in that represents some base
* wotlas feature.
* @return true means system plug-in, false means user plug-in
*/
public boolean isSystemPlugIn() {
return true;
}
/*------------------------------------------------------------------------------------*/
/** Persistence class containing all the macros.
*/
public static class MacrosList {
private String macros[];
public MacrosList() {
}
public String[] getMacros() {
return macros;
}
public void setMacros(String[] macros) {
this.macros = macros;
}
}
/*------------------------------------------------------------------------------------*/
/** To load the Macro config file. If the file is not found we return an empty list.
* @return the loaded macros list, an empty array if no config file was found
*/
public String[] load() {
ResourceManager rManager = ClientDirector.getResourceManager();
String fileName = rManager.getExternalMacrosDir()
+MACROS_PREFIX
+ClientDirector.getDataManager().getMyPlayer().getPrimaryKey()
+MACROS_SUFFIX;
if( new File(fileName).exists() ) {
MacrosList list = (MacrosList) rManager.loadObject(fileName);
if(list!=null)
return list.getMacros();
}
Debug.signal( Debug.NOTICE, null, "No macros config found..." );
String listStr[] = new String[1];
listStr[0] = "";
return listStr;
}
/*------------------------------------------------------------------------------------*/
/** To load the Macro config file. If the file is not found we return an empty list.
* @param macros macros list to save
* @return true if the save succeeded, false otherwise
*/
public boolean save(String[] macros) {
ResourceManager rManager = ClientDirector.getResourceManager();
MacrosList list = new MacrosList();
list.setMacros(macros);
if( rManager.saveObject(list, rManager.getExternalMacrosDir()
+MACROS_PREFIX
+ClientDirector.getDataManager().getMyPlayer().getPrimaryKey()
+MACROS_SUFFIX ) )
return true;
Debug.signal( Debug.ERROR, this, "Failed to save macros.");
return false;
}
/*------------------------------------------------------------------------------------*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -