📄 recdefbuttons.java
字号:
if ( getOrientation() == SwingConstants.HORIZONTAL ) { Ncolumn = (int) ( 0.4 + (double) ( getSize().width - 50 ) / max_btn_dim.width ); if ( Ncolumn < 1 ) Ncolumn = 1; } else Ncolumn = 1; Nrow = 0; int Nrow_total = 0; // Setup Arrows Panels with Ncolumn computed if ( state_btns.size() > 0 ) { // Initialize the State sections of the panel Nbtn = state_btns.size() + ( state_btns.size() > 1 ? 1 : 0 ); Nrow = ( Nbtn / Ncolumn ) + ( Nbtn % Ncolumn > 0 ? 1 : 0 ); if ( Nrow > 1 ) states_gridlayout.setColumns( Ncolumn ); else states_gridlayout.setColumns( Nbtn ); states_panel.invalidate(); } Nrow_total += Nrow; Nrow = 0; // Setup Arrows Panels with Ncolumn computed if ( arrow_btns.size() > 0 ) { // Initialize the Arrow sections of the panel Nbtn = arrow_btns.size() + ( arrow_btns.size() > 1 ? 1 : 0 ); Nrow = ( Nbtn / Ncolumn ) + ( Nbtn % Ncolumn > 0 ? 1 : 0 ); if ( Nrow > 1 ) arrows_gridlayout.setColumns( Ncolumn ); else arrows_gridlayout.setColumns( Nbtn ); arrows_panel.invalidate(); } Nrow_total += Nrow; validate(); SetAllBtnPanelsSize();/* // Determine the preferred size based on the getOrientation() Dimension pref_size; if ( Ncolumn > 1 ) { if ( Nrow_total > 3 ) pref_size = new Dimension( scrollpane.getSize().width, (int) (3.5*max_btn_dim.height) ); else pref_size = new Dimension( scrollpane.getSize().width, (int) (Nrow_total*max_btn_dim.height) ); } else pref_size = new Dimension( max_btn_dim.width + 15, scrollpane.getSize().height ); // main_panel.setPreferredSize( perf_size ) cannot be called, it // seems to set the main_panel to a fixed size, this renders the // arrows_panel disappear from the scroll_pane. // scrollpane.setPreferredSize( perf_size ) can be called. // this.setPreferredSize( pref_size ) activates a call to propertyChange() scrollpane.setPreferredSize( pref_size );*/ // setPreferredSize( getSize() ); } // Endof SetInternalLayout() // For PropertyChangeListener public void propertyChange( PropertyChangeEvent evt ) {/* System.out.println( "\n\n" + "propertyChange(): Size = " + getSize() + "\n" + "propertyChange(): PerferredSize = " + getPreferredSize()+ "\n" + "propertyChange(): MinimumSize = " + getMinimumSize() + "\n" + "propertyChange(): MaximumSize = " + getMaximumSize() + "\n" + "propertyChange(): Orientation = " + getOrientation() ); System.out.println( "propertyChange(): evt = " + evt );*//* SetInternalLayout();*/ // Determine the preferred size based on the getOrientation() Dimension parent_size, pref_size, min_size, max_size; parent_size = parent.getSize(); if ( getOrientation() == SwingConstants.HORIZONTAL ) { if ( getSize().width > parent_size.width ) pref_size = new Dimension( getSize().width, (int) (3.5*max_btn_dim.height) ); else pref_size = new Dimension( parent_size.width, (int) (3.5*max_btn_dim.height) ); max_size = new Dimension( parent_size.width, parent_size.height / 4 ); } else { if ( getPreferredSize().height > parent_size.height ) pref_size = new Dimension( max_btn_dim.width + 15, getPreferredSize().height ); else pref_size = new Dimension( max_btn_dim.width + 15, parent_size.height ); max_size = new Dimension( parent_size.width / 4, parent_size.height ); } // setSize( perf_size ) does NOT work, it seems value set by setSize() // will be modified by the values in setPreferredSize later on setMaximumSize( max_size ); setPreferredSize( pref_size ); }// For ComponentChangeListener public void componentResized( ComponentEvent evt ) {/* System.out.println( "\n\n" + "componentResized(): Size = " + getSize() + "\n" + "componentResized(): PerferredSize = " + getPreferredSize()+ "\n" + "componentResized(): MinimumSize = " + getMinimumSize() + "\n" + "componentResized(): MaximumSize = " + getMaximumSize() + "\n" + "componentResized(): Orientation = " + getOrientation() ); System.out.println( "componentResized(): evt = " + evt );*/ SetInternalLayout(); } public void componentHidden( ComponentEvent evt ) {;} public void componentMoved( ComponentEvent evt ) {;} public void componentShown( ComponentEvent evt ) {;} private void SetRecDefsEnabled( Vector rec_defs, boolean val ) { Enumeration defs = rec_defs.elements(); while ( defs.hasMoreElements() ) { RecDef def = (RecDef) defs.nextElement(); if ( def.stateVector.size() > 0 ) def.checkbox.setSelected( val ); } } /** * causes the histogram frame to be displayed for the given state name */ private void getStateHistogram( String name ) { waitCursor(); parent.waitCursor(); parent.canvas.waitCursor(); parent.init_win.waitCursor(); RecDef def = getRecDef( name ); if ( def != null ) hists.addElement( new Histwin( def, parent ) ); else new ErrorDialog(this, "Record Definition " + name + " does not exist"); parent.init_win.normalCursor(); parent.canvas.normalCursor(); parent.normalCursor(); normalCursor(); } /** * This function returns the RecDef associated with the given name string. */ private RecDef getRecDef( String name ) { RecDef def; def = parent.stateDefs.GetRecDef( name ); if ( def == null ) def = parent.arrowDefs.GetRecDef( name ); return def; } /** * The function prints out key to jumpshot data. */ int print (Graphics g, int x, int y, int width, int height) { Font f = g.getFont (); FontMetrics fm = getToolkit ().getFontMetrics (f); int charW = fm.stringWidth (" "), charH = fm.getHeight (); int hgap1 = charW, hgap2 = 2 * charW, vgap = fm.getAscent (); int rectW = 30, rectH = charH; //Dimensions of state rectangles int xcord = x, ycord = y; Enumeration enum = parent.stateDefs.elements (); while (enum.hasMoreElements ()) { RecDef s = (RecDef)enum.nextElement (); if (s.stateVector.size () > 0) { int strW = fm.stringWidth (s.description); if ((xcord + rectW + hgap1 + strW) > (width + x)) { xcord = x; ycord += (charH + vgap); } g.setColor (s.color); g.fillRect (xcord, ycord, rectW, rectH); g.setColor (Color.black); g.drawRect (xcord, ycord, rectW - 1, rectH - 1); g.drawString( s.description, xcord + rectW + hgap1, ycord + rectH - fm.getDescent () - 1); xcord += (rectW + hgap1 + strW + hgap2); } } return (ycord - y + (2 * charH)); } /** * sets the cursor to the WAIT_CURSOR type */ void waitCursor () {setCursor (new Cursor (Cursor.WAIT_CURSOR));} /** * sets the cursor to the cursor associated with this frame */ void normalCursor () {setCursor (new Cursor (Cursor.DEFAULT_CURSOR));} public void actionPerformed( ActionEvent evt ) { String command = evt.getActionCommand(); if ( command.equals( "Change Orientation" ) ) { if ( getOrientation() == SwingConstants.HORIZONTAL ) setOrientation( SwingConstants.VERTICAL ); else setOrientation( SwingConstants.HORIZONTAL ); } else getStateHistogram( command ); } public void itemStateChanged( ItemEvent ievt ) { Object obj = ievt.getItemSelectable(); if ( obj == all_states_chkbox ) SetRecDefsEnabled( parent.stateDefs, all_states_chkbox.isSelected() ); if ( obj == all_arrows_chkbox ) SetRecDefsEnabled( parent.arrowDefs, all_arrows_chkbox.isSelected() ); parent.canvas.Refresh(); } private void killHists() { if ( hists.size() > 0 ) { Enumeration enum = hists.elements(); while ( enum.hasMoreElements() ) { Histwin h = (Histwin) enum.nextElement(); if ( h != null ) { h.kill (); h = null; } } hists.removeAllElements (); } } void kill() { killHists(); removeAll(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -