📄 gumviewer.java
字号:
* x,y:起始点坐标
* str:文字
* g2d:画笔
* angle:旋转角度
*****************************************************************/
private void drawRotateString(int x,int y,String str,Graphics2D g2d,double angle)
{
FontRenderContext frc = new FontRenderContext(null, true, false); TextLayout tl = new TextLayout(str, g2d.getFont(), frc); AffineTransform Tx = new AffineTransform(); Tx.translate(x, y); Tx.rotate(angle*Math.PI/180,0,0);
Shape textshape = tl.getOutline(Tx); GeneralPath path = new GeneralPath(textshape); g2d.fill(path);
g2d.draw(path);
}
/******************************************************************
* main() 主方法
******************************************************************/
public static void main(String s[]) {
GumViewer gumViewer = new GumViewer("GumViewer");
gumViewer.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
//gumViewer.pack();
//gumViewer.setVisible(true);
java.awt.Dimension dPoint = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
gumViewer.setBounds(0,0,dPoint.width ,dPoint.height-30);
gumViewer.show();
intro.myintro.start();
}
/*****************************************************************
* addButtons()方法 添加所有的按钮
* 无返回值
*****************************************************************/
private void addButtons() {
//add toolbar
btn_zoomout = new JButton("缩小地图", LoadImageIcon("zoomout.gif"));
btn_zoomout.setVerticalTextPosition(AbstractButton.BOTTOM);
btn_zoomout.setHorizontalTextPosition(AbstractButton.CENTER);
btn_zoomout.setToolTipText("将地图缩小");
btn_zoomout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(Picture.img!=null&&selected.length>0 && width>120){
width/=1.2;
height/=1.2;
Rectangle myrect=Picture.getVisibleRect();
int x1=0;
int y1=0;
if(myrect.width<width*1.2){
x1=(int)(myrect.x/1.2-myrect.width*0.1);
x1=(x1+Picture.getVisibleRect().width<width)?x1:width-Picture.getVisibleRect().width;
x1=x1>0?x1:0;
}
if(myrect.height<height*1.2){
y1=(int)(myrect.y/1.2-myrect.height*0.1);
y1=(y1+Picture.getVisibleRect().height<height)?y1:height-Picture.getVisibleRect().height;
y1=y1>0?y1:0;
}
Picture.setTag(false);
Picture.setPosition(x1,y1);
ReDrawMap();
Picture.setTag(true);
myrect.x=x1;myrect.y=y1;
Picture.scrollRectToVisible(myrect);
Picture.repaint();
}
}
});
ToolBar.add(btn_zoomout);
btn_zoomin = new JButton("放大地图",LoadImageIcon("zoomin.gif"));
btn_zoomin.setVerticalTextPosition(AbstractButton.BOTTOM);
btn_zoomin.setHorizontalTextPosition(AbstractButton.CENTER);
btn_zoomin.setToolTipText("将地图放大");
btn_zoomin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(Picture.img!=null&&selected.length>0){
width*=1.2;
height*=1.2;
Rectangle myrect=Picture.getVisibleRect();
int x1=0;
int y1=0;
if(myrect.width*1.2<width){
x1=(int)(myrect.x*1.2+myrect.width*0.1);
x1=(x1+Picture.getVisibleRect().width<width)?x1:width-Picture.getVisibleRect().width;
}
if(myrect.height*1.2<height){
y1=(int)(myrect.y*1.2+myrect.height*0.1);
y1=(y1+Picture.getVisibleRect().height<height)?y1:height-Picture.getVisibleRect().height;
}
Picture.setTag(false);
Picture.setPosition(x1,y1);
ReDrawMap();
Picture.setTag(true);
myrect.x=x1;myrect.y=y1;
Picture.scrollRectToVisible(myrect);
Picture.repaint();
}
}
});
ToolBar.add(btn_zoomin);
btn_show = new JButton("显示地图",LoadImageIcon("show.gif"));
btn_show.setVerticalTextPosition(AbstractButton.BOTTOM);
btn_show.setHorizontalTextPosition(AbstractButton.CENTER);
btn_show.setToolTipText("显示地图");
btn_show.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
selected=FileList.getSelectedIndices();
if(selected.length>0)
{
if(width==-1)
width=1000;
ShowMap();
}
}
});
ToolBar.add(btn_show );
btn_open = new JButton("打开文件",LoadImageIcon("open.gif"));
btn_open.setVerticalTextPosition(AbstractButton.BOTTOM);
btn_open.setHorizontalTextPosition(AbstractButton.CENTER);
btn_open.setToolTipText("打开Gum格式文件");
btn_open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openFile();
}
});
ToolBar.add(btn_open);
ImageIcon temp=LoadImageIcon("1002.gif");
cur_drag1=Toolkit.getDefaultToolkit().createCustomCursor(temp.getImage(),new Point(temp.getIconWidth()/2,temp.getIconHeight()/2),"1");
temp=LoadImageIcon("1001.gif");
cur_drag2=Toolkit.getDefaultToolkit().createCustomCursor(temp.getImage(),new Point(temp.getIconWidth()/2,temp.getIconHeight()/2),"2");
temp=LoadImageIcon("normal.gif");
cur_normal=Toolkit.getDefaultToolkit().createCustomCursor(temp.getImage(),new Point(0,0),"normal");
btn_drag = new JButton(" 拖动 ",LoadImageIcon("1002.gif"));
col_default=btn_drag.getBackground();
btn_drag.setVerticalTextPosition(AbstractButton.BOTTOM);
btn_drag.setHorizontalTextPosition(AbstractButton.CENTER);
btn_drag.setToolTipText("按住鼠标左键拖动地图");
isDragged=false;
btn_drag.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
isSelected=false;
btn_selected.setBackground(col_default);
if(isDragged)
{
Picture.setCursor(cur_normal);
btn_drag.setBackground(col_default);
isDragged=false;
}
else
{
Picture.setCursor(cur_drag1);
btn_drag.setBackground(new Color(172,172,255));
isDragged=true;
}
}
});
ToolBar.add(btn_drag);
btn_selected= new JButton("选择放大",LoadImageIcon("select.gif"));
btn_selected.setVerticalTextPosition(AbstractButton.BOTTOM);
btn_selected.setHorizontalTextPosition(AbstractButton.CENTER);
btn_selected.setToolTipText("将选中的区域放大");
isSelected=false;
btn_selected.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
isDragged=false;
btn_drag.setBackground(col_default);
if(isSelected)
{
Picture.setCursor(cur_normal);
btn_selected.setBackground(col_default);
isSelected=false;
}
else
{
Picture.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
btn_selected.setBackground(new Color(172,172,255));
isSelected=true;
}
}
});
ToolBar.add(btn_selected);
ToolBar.addSeparator();
JButton btn_setting= new JButton("功能设置",LoadImageIcon("setting.gif"));
btn_setting.setVerticalTextPosition(AbstractButton.BOTTOM);
btn_setting.setHorizontalTextPosition(AbstractButton.CENTER);
btn_setting.setToolTipText("功能及参数设置");
btn_setting.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showSetting();
}
});
ToolBar.add(btn_setting);
JButton btn_about= new JButton("关于程序",LoadImageIcon("about.gif"));
btn_about.setVerticalTextPosition(AbstractButton.BOTTOM);
btn_about.setHorizontalTextPosition(AbstractButton.CENTER);
btn_about.setToolTipText("关于本程序");
btn_about.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mainPanel.showAbout();
}
});
ToolBar.add(btn_about);
//add toolbar end
//add leftBar
btn_top = new JButton(LoadImageIcon("top.gif"));
btn_top.setToolTipText("将选中文件在绘画序列中移到最上");
btn_top.setBorderPainted(false);
btn_top.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int[] Selected=FileList.getSelectedIndices();
for(int i=0;i<Selected.length;i++)
{
String tempStr=(String)FileNames.elementAt(Selected[i]);
String tempFul=(String)FileFullNames.elementAt(Selected[i]);
map tempMap=(map)Maps.elementAt(Selected[i]);
for(int j=Selected[i];j>i;j--)
{
FileNames.setElementAt(FileNames.elementAt(j-1),j);
FileFullNames.setElementAt(FileFullNames.elementAt(j-1),j);
Maps.setElementAt(Maps.elementAt(j-1),j);
}
FileNames.setElementAt(tempStr,i);
FileFullNames.setElementAt(tempFul,i);
Maps.setElementAt(tempMap,i);
Selected[i]=i;
}
FileList.setSelectedIndices(Selected);
FileList.updateUI();
}
});
LeftBar.add(btn_top);
btn_up = new JButton(LoadImageIcon("up.gif"));
btn_up.setToolTipText("将选中文件在绘画序列中向上移一格");
btn_up.setBorderPainted(false);
btn_up.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int[] Selected=FileList.getSelectedIndices();
for(int i=0;i<Selected.length;i++)
{
if(Selected[i]>i)
{
String tempStr=(String)FileNames.elementAt(Selected[i]);
FileNames.setElementAt(FileNames.elementAt(Selected[i]-1),Selected[i]);
FileNames.setElementAt(tempStr,Selected[i]-1);
String tempFul=(String)FileFullNames.elementAt(Selected[i]);
FileFullNames.setElementAt(FileFullNames.elementAt(Selected[i]-1),Selected[i]);
FileFullNames.setElementAt(tempFul,Selected[i]-1);
map tempMap=(map)Maps.elementAt(Selected[i]);
Maps.setElementAt(Maps.elementAt(Selected[i]-1),Selected[i]);
Maps.setElementAt(tempMap,Selected[i]-1);
Selected[i]--;
}
}
FileList.setSelectedIndices(Selected);
FileList.updateUI();
}
});
LeftBar.add(btn_up);
btn_down = new JButton(LoadImageIcon("down.gif"));
btn_down.setToolTipText("将选中文件在绘画序列中向下移一格");
btn_down.setBorderPainted(false);
btn_down.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int[] Selected=FileList.getSelectedIndices();
for(int i=Selected.length-1;i>=0;i--)
{
if(Selected[i]<FileNames.size()-Selected.length+i)
{
String tempStr=(String)FileNames.elementAt(Selected[i]);
FileNames.setElementAt(FileNames.elementAt(Selected[i]+1),Selected[i]);
FileNames.setElementAt(tempStr,Selected[i]+1);
String tempFul=(String)FileFullNames.elementAt(Selected[i]);
FileFullNames.setElementAt(FileFullNames.elementAt(Selected[i]+1),Selected[i]);
FileFullNames.setElementAt(tempFul,Selected[i]+1);
map tempMap=(map)Maps.elementAt(Selected[i]);
Maps.setElementAt(Maps.elementAt(Selected[i]+1),Selected[i]);
Maps.setElementAt(tempMap,Selected[i]+1);
Selected[i]++;
}
}
FileList.setSelectedIndices(Selected);
FileList.updateUI();
}
});
LeftBar.add(btn_down);
btn_buttom = new JButton(LoadImageIcon("buttom.gif"));
btn_buttom.setToolTipText("将选中文件在绘画序列中移到最下");
btn_buttom.setBorderPainted(false);
btn_buttom.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int[] Selected=FileList.getSelectedIndices();
for(int i=Selected.length-1;i>=0;i--)
{
String tempStr=(String)FileNames.elementAt(Selected[i]);
String tempFul=(String)FileFullNames.elementAt(Selected[i]);
map tempMap=(map)Maps.elementAt(Selected[i]);
for(int j=Selected[i];j<FileNames.size()-Selected.length+i;j++)
{
FileNames.setElementAt(FileNames.elementAt(j+1),j);
FileFullNames.setElementAt(FileFullNames.elementAt(j+1),j);
Maps.setElementAt(Maps.elementAt(j+1),j);
}
FileNames.setElementAt(tempStr,FileNames.size()-Selected.length+i);
FileFullNames.setElementAt(tempFul,FileNames.size()-Selected.length+i);
Maps.setElementAt(tempMap,FileNames.size()-Selected.length+i);
Selected[i]=FileNames.size()-Selected.length+i;
}
FileList.setSelectedIndices(Selected);
FileList.updateUI();
}
});
LeftBar.add(btn_buttom);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -