📄 infopanelfordrawable.java
字号:
/* * (C) 2001 by Argonne National Laboratory * See COPYRIGHT in top-level directory. *//* * @author Anthony Chan */package viewer.timelines;import java.text.NumberFormat;import java.text.DecimalFormat;import java.awt.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.tree.TreeNode;import java.util.Map;import java.util.Iterator;import base.drawable.Coord;import base.drawable.Topology;import base.drawable.Drawable;import base.drawable.Primitive;import base.drawable.Composite;import base.drawable.Shadow;import base.drawable.Category;import base.drawable.CategoryWeight;import base.topology.PreviewState;import viewer.common.Const;import viewer.common.Routines;import viewer.common.Parameters;import viewer.legends.CategoryLabel;import viewer.zoomable.TimeFormat;import viewer.zoomable.SearchPanel;import viewer.zoomable.YaxisTreeNode;public class InfoPanelForDrawable extends SearchPanel // SearchPanel is JPanel{ private static final Component STRUT = Box.createHorizontalStrut( 10 ); private static final Component GLUE = Box.createHorizontalGlue(); private static final String FORMAT = Const.INFOBOX_TIME_FORMAT; private static DecimalFormat fmt = null; private static TimeFormat tfmt = null; private static Border Normal_Border = null; private static Border Shadow_Border = null; private Drawable drawable; public InfoPanelForDrawable( final Map map_line2treenodes, final String[] y_colnames, final Drawable dobj ) { super(); super.setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) ); /* Define DecialFormat for the displayed time */ if ( fmt == null ) { fmt = (DecimalFormat) NumberFormat.getInstance(); fmt.applyPattern( FORMAT ); } if ( tfmt == null ) tfmt = new TimeFormat(); if ( Normal_Border == null ) { /* Normal_Border = BorderFactory.createCompoundBorder( BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder() ); */ Normal_Border = BorderFactory.createEtchedBorder(); } if ( Shadow_Border == null ) { Shadow_Border = BorderFactory.createTitledBorder( Normal_Border, " Preview State ", TitledBorder.LEFT, TitledBorder.TOP, Const.FONT, Color.magenta ); } drawable = dobj; // Set the CategoryLabel Icon Dimension panel_max_size; Category type = null; CategoryLabel label_type = null; JPanel top_panel = new JPanel(); top_panel.setLayout( new BoxLayout( top_panel, BoxLayout.X_AXIS ) ); if ( drawable instanceof Shadow && ( (Shadow) drawable ).getSelectedSubCategory() != null ) { type = ( (Shadow) drawable ).getSelectedSubCategory(); label_type = new CategoryLabel( type ); ( (Shadow) drawable ).clearSelectedSubCategory(); top_panel.setBorder( Shadow_Border ); } else { type = drawable.getCategory(); label_type = new CategoryLabel( type ); top_panel.setBorder( Normal_Border ); } top_panel.add( STRUT ); top_panel.add( label_type ); top_panel.add( GLUE ); top_panel.setAlignmentX( Component.LEFT_ALIGNMENT ); panel_max_size = top_panel.getPreferredSize(); panel_max_size.width = Short.MAX_VALUE; top_panel.setMaximumSize( panel_max_size ); super.add( top_panel ); // Determine the text of the drawable TextAreaBuffer textbuf; int num_cols, num_rows; textbuf = new TextAreaBuffer( map_line2treenodes, y_colnames ); if ( drawable instanceof Shadow ) textbuf.setShadowText( (Shadow) drawable, type ); else if ( drawable instanceof Composite ) textbuf.setCompositeText( (Composite) drawable ); else textbuf.setPrimitiveText( (Primitive) drawable ); textbuf.finalized(); num_cols = textbuf.getColumnCount(); num_rows = textbuf.getRowCount(); // Set the TextArea JTextArea text_area; int adj_num_cols; text_area = new JTextArea( textbuf.toString() ); adj_num_cols = Routines.getAdjNumOfTextColumns( text_area, num_cols ); num_cols = (int) Math.ceil( adj_num_cols * 85.0d / 100.0d ); text_area.setColumns( num_cols ); text_area.setRows( num_rows ); text_area.setEditable( false ); text_area.setLineWrap( true ); JScrollPane scroller = new JScrollPane( text_area ); scroller.setAlignmentX( Component.LEFT_ALIGNMENT ); super.add( scroller ); } // The following function is for Seach and Scan facility of the viewport. public Drawable getSearchedDrawable() { return drawable; } private class TextAreaBuffer { private Map map_line2treenodes; private String[] y_colnames; private StringBuffer strbuf; private String strbuf2str; private int num_cols; private int num_rows; public TextAreaBuffer( final Map in_map_line2treenodes, final String[] in_y_colnames ) { map_line2treenodes = in_map_line2treenodes; y_colnames = in_y_colnames; strbuf = new StringBuffer(); strbuf2str = null; // Initialize num_cols and num_rows. num_cols = 0; num_rows = 0; } // this.finalized() needs to be called before // getColumnCount()/getRowCount()/toString() public void finalized() { int num_lines; strbuf2str = strbuf.toString(); num_lines = this.getNumOfLines(); if ( num_lines <= 3 ) num_rows = 3; else num_rows = 4; } public int getColumnCount() { return num_cols; } public int getRowCount() { return num_rows; } public String toString() { return strbuf2str; } private int getNumOfLines() { int num_lines; int str_length; int ipos; if ( strbuf2str != null ) { num_lines = 1; ipos = 0; str_length = strbuf2str.length(); while ( ipos >= 0 && ipos < str_length ) { ipos = strbuf2str.indexOf( '\n', ipos ); if ( ipos >= 0 ) { num_lines++; ipos++; } } return num_lines; } else return -1; } private void setCoordsText( final Coord[] coords,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -