subbutton.java
来自「一个简单的visio程序。」· Java 代码 · 共 265 行
JAVA
265 行
package webide.views.prop;
import java.awt.Color;
import java.awt.Frame;
import java.beans.PropertyEditor;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import Editor.*;
import hc.util.MsgBox;
import webide.itools.Util;
import webide.itools.NewFileDialog;
public class SubButton extends java.awt.Canvas
implements MouseListener, MouseMotionListener, KeyListener
{
/*--- Private Data Members ----------------------------------------------------------------*/
private webide.views.prop.PropPanel proppanel;
private PropertyEditor editor;
private java.awt.Frame frame;
public java.awt.Dialog Pd = null;
public NewFileDialog Fd = null;
private int buttonadd = 2;
private String Type = "";
/* Constructor */
public SubButton(webide.views.prop.PropPanel proppanel, PropertyEditor pe)
{
this.frame = new java.awt.Frame();
this.proppanel = proppanel;
this.editor = pe;
setBackground(java.awt.Color.lightGray);
setForeground(java.awt.Color.black);
addMouseListener(this);
addMouseMotionListener(this);
this.editor.addPropertyChangeListener(new PropAdaptor(webide.MainConsole.getCurrentFocus(), editor));
if(editor instanceof FontEditor || editor instanceof Editor.FontEditor
|| editor instanceof InsetsEditor )
{
if(editor instanceof InsetsEditor)
Pd = new PropFontDialog(frame, editor, frame.getLocation().x + 50 , frame.getLocation().y + 200);
else
Pd = new PropFontDialog(frame, editor, frame.getLocation().x - 30, frame.getLocation().y + 50);
}
else if(editor instanceof Editor.PictureEditor)
{
Fd = null;
}
else
{
Pd = new PropDialog(frame, editor, frame.getLocation().x - 30, frame.getLocation().y + 50);
}
}
/*-----------------------------------------------------------------------------------------*/
/*--- Paint Method ------------------------------------------------------------------------*/
public void update(java.awt.Graphics g)
{
paint(g);
}
public void paint(java.awt.Graphics g)
{
draw(g);
}
public void draw(java.awt.Graphics g)
{
int odd = 0;
for(int i = 0 ; i < 3; i++)
{
g.setColor(Color.black);
g.fillRect(buttonadd+1+odd, getSize().height-(buttonadd+4),2,2);
odd = odd + 3;
}
drawupbutton();
}
/*-----------------------------------------------------------------------------------------*/
/*--- Private Method ----------------------------------------------------------------------*/
private void drawButton(java.awt.Graphics g,Color c1,Color c2,Color c3,Color c4,int x, int y, int width, int height)
{
g.setColor(c1);
g.drawLine(x,y,x+width,y);
g.drawLine(x,y,x,y+height);
g.setColor(c2);
g.drawLine(x+1,y+1,x+width-1,y+1);
g.drawLine(x+1,y+1,x+1,y+height-1);
g.setColor(c3);
g.drawLine(x+width-1,y+height-1,x+1,y+height-1);
g.drawLine(x+width-1,y+height-1,x+width-1,y+1);
g.setColor(c4);
g.drawLine(x+width,y+height,x,y+height);
g.drawLine(x+width,y+height,x+width,y);
}
private void drawupbutton()
{
java.awt.Graphics g = getGraphics();
if(g != null)
drawButton(g, Color.lightGray, Color.white, Color.gray, Color.black, 0,0,getSize().width-1,getSize().height-1);
g.dispose();
}
private void drawdownbutton()
{
java.awt.Graphics g = getGraphics();
if(g != null)
drawButton(g, Color.black, Color.gray, new Color(224,224,224), Color.white, 0,0,getSize().width-1,getSize().height-1);
g.dispose();
}
public void setText(String text)
{
//empty;
}
public void newPropertyDialog()
{
if( !Pd.isVisible())
{
Pd.setVisible(true);
}
}
public String getFileName()
{
String fname,dname;
webide.MainConsole mM = webide.MainConsole.getMainConsole();
if(editor.getClass().getName().toLowerCase().endsWith("pictureeditor"))
{
Fd = new NewFileDialog(mM);
}
else if (editor.getClass().getName().toLowerCase().endsWith("toolboxbitmapeditor"))
{
Fd = new NewFileDialog(mM);
}
else if (editor.getClass().getName().toLowerCase().endsWith("paletteeditor"))
{
Fd = new NewFileDialog(mM);
}
else if (editor.getClass().getName().toLowerCase().endsWith("mouseiconeditor"))
{
Fd = new NewFileDialog(mM);
}
else
{
Fd = new NewFileDialog(mM);
}
Fd.display();
fname = Fd.getFile();
return fname;
}
/*--- Event -------------------------------------------------------------------------------*/
/*--- Mouse Listener ----------------------------------------------------------------------*/
public void mouseClicked(MouseEvent e)
{
int clickCount = e.getClickCount();
if ( clickCount > 0 && clickCount < 2 )
{
if(editor instanceof Editor.PictureEditor)
{
if(Fd != null) return;
String fileName = getFileName();
if (fileName != null)
{
try
{
editor.setAsText(fileName);
}
catch(Exception ex)
{
String msg = "Invalid property value";
MsgBox.MessageBox(new Frame(), "Instant Basic",msg, MsgBox.OK, 1);
}
}
Fd = null;
}
else
newPropertyDialog();
}
}
public void mousePressed(MouseEvent e)
{
drawdownbutton();
}
public void mouseReleased(MouseEvent e)
{
drawupbutton();
}
public void mouseExited(MouseEvent e)
{
drawupbutton();
}
public void mouseEntered(MouseEvent e)
{
}
/*-----------------------------------------------------------------------------------------*/
/*--- Mouse Motion Listener ---------------------------------------------------------------*/
public void mouseMoved(MouseEvent e)
{
}
private boolean isInButton = false;
public void mouseDragged(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
if(x > 0 && x < getSize().width && y > 0 && y < getSize().height)
{
if(!isInButton)
drawdownbutton() ;
isInButton = true;
}
else
{
if(isInButton)
drawupbutton() ;
isInButton = false;
}
}
/*-----------------------------------------------------------------------------------------*/
/*--- Key Listener ------------------------------------------------------------------------*/
public void keyTyped(KeyEvent event)
{
}
public void keyReleased(KeyEvent event)
{
}
public void keyPressed(KeyEvent event)
{
if(editor instanceof Editor.PictureEditor)
{
webide.Wrapper wrap = webide.MainConsole.getCurrentFocus();
int code = event.getKeyCode();
if(code == KeyEvent.VK_DELETE)
{
editor.setAsText(null);
try
{
wrap.wasModified(editor);
this.proppanel.Repaint();
}
catch(Exception e)
{
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?