getinfotext.java

来自「The ElectricTM VLSI Design System is an 」· Java 代码 · 共 974 行 · 第 1/2 页

JAVA
974
字号
	public static class EditInPlaceListener implements MouseMotionListener, MouseListener, MouseWheelListener, KeyListener	{		private CachedTextInfo cti;		private EditWindow wnd;		private EventListener oldListener;		private JTextComponent tc;		private EMenuBar.Instance mb;		private UndoManager undo;		public EditInPlaceListener(CachedTextInfo cti, EditWindow wnd, Font theFont, int lowX, int lowY)		{			this.cti = cti;			this.wnd = wnd;			// make the field bigger			if (cti.isMultiLineCapable() || (cti.var != null && cti.var.getLength() > 1))			{				EIPEditorPane ep = new EIPEditorPane(cti.initialText);				tc = ep;			} else			{				EIPTextField tf = new EIPTextField(cti.initialText);				tf.addActionListener(new ActionListener()				{					public void actionPerformed(ActionEvent evt) { closeEditInPlace(); }				});				tc = tf;			}			Document doc = tc.getDocument();			// Listen for undo and redo events			undo = new UndoManager();			doc.addUndoableEditListener(new UndoableEditListener()			{				public void undoableEditHappened(UndoableEditEvent evt) { undo.addEdit(evt.getEdit()); }			});			tc.addKeyListener(this);			tc.setSize(figureSize());			tc.setLocation(lowX, lowY);			tc.setBorder(new EmptyBorder(0,0,0,0));			if (theFont != null) tc.setFont(theFont);			tc.selectAll();			wnd.addInPlaceTextObject(this);			tc.setVisible(true);			tc.repaint();			oldListener = WindowFrame.getListener();			WindowFrame.setListener(this);			TopLevel top = TopLevel.getCurrentJFrame();			mb = top.getTheMenuBar();			mb.setIgnoreTextEditKeys(true);		}		/**		 * Method to return the JTextComponent associated with this listener.		 * @return the  JTextComponent associated with this listener.		 */		public JTextComponent getTextComponent() { return tc; }		/**		 * Method to undo the last change to the in-place edit session.		 */		public void undo()		{			try			{				if (undo.canUndo()) undo.undo();			} catch (CannotUndoException e) {}		}		/**		 * Method to redo the last change to the in-place edit session.		 */		public void redo()		{			try			{				if (undo.canRedo()) undo.redo();			} catch (CannotUndoException e) {}		}		/**		 * Method to determine the size of the in-place edit.		 * @return the size of the in-place edit.		 */		private Dimension figureSize()		{			Font theFont = wnd.getFont(cti.td);			double size = EditWindow.getDefaultFontSize();			if (cti.td != null) size = cti.td.getTrueSize(wnd);			if (size <= 0) size = 1;			size = theFont.getSize();			String[] textArray = tc.getText().split("\\n", -1);			double totalHeight = 0;			double totalWidth = 0;			for (int i=0; i<textArray.length; i++)			{				String str = textArray[i];				GlyphVector gv = wnd.getGlyphs(str, theFont);				Rectangle2D glyphBounds = gv.getLogicalBounds();				totalHeight += size;				if (glyphBounds.getWidth() > totalWidth) totalWidth = glyphBounds.getWidth();			}			if (textArray.length > 1) totalHeight *= 2;			return new Dimension((int)totalWidth+5, (int)totalHeight+5);		}		public void closeEditInPlace()		{			// gather the current text and store it on the owner			String currentText = tc.getText();			if (!currentText.equals(cti.initialText))			{				String[] textArray = currentText.split("\\n");				ArrayList<String> textList = new ArrayList<String>();				for (int i=0; i<textArray.length; i++)				{					String str = textArray[i];					if (Simulation.getPreserveVerilogFormating() && // Pref set					   cti.td.getPos() == TextDescriptor.Position.RIGHT && // Left justified text					   (cti.varKey == Verilog.VERILOG_PARAMETER_KEY || 						cti.varKey == Verilog.VERILOG_CODE_KEY ||						cti.varKey == Verilog.VERILOG_EXTERNAL_CODE_KEY ||						cti.varKey == Verilog.VERILOG_DECLARATION_KEY)) {						textList.add(str);					} else					{						str = str.trim();						if (str.equals("")) continue;						textList.add(str);					}				}				textArray = new String[textList.size()];				for (int i=0; i<textList.size(); i++)				{					String str = textList.get(i);					textArray[i] = str;				}				if (textArray.length > 0)				{					// generate job to change text					new ChangeText(cti.owner, cti.varKey, textArray);				}			}			// close the in-place text editor			tc.removeKeyListener(this);			WindowFrame.setListener(oldListener);			wnd.removeInPlaceTextObject(this);			wnd.repaint();			wnd.requestFocus();			mb.setIgnoreTextEditKeys(false);		} 		// the MouseListener events		public void mouseEntered(MouseEvent evt) {}		public void mouseExited(MouseEvent evt) {}		public void mousePressed(MouseEvent evt) { closeEditInPlace(); }		public void mouseReleased(MouseEvent evt) {}		public void mouseClicked(MouseEvent evt) {}		// the MouseMotionListener events		public void mouseMoved(MouseEvent evt) {}		public void mouseDragged(MouseEvent evt) {}		// the MouseWheelListener events		public void mouseWheelMoved(MouseWheelEvent evt) {}		// the KeyListener events		public void keyPressed(KeyEvent evt) {}		public void keyReleased(KeyEvent evt)		{			int chr = evt.getKeyCode();			if (chr == KeyEvent.VK_ESCAPE)			{				tc.setText(cti.initialText);				closeEditInPlace();				return;			}						tc.setSize(figureSize());		}		public void keyTyped(KeyEvent evt) {}	}	private static class ChangeText extends Job {		private ElectricObject owner;		private Variable.Key key;		private String[] newText;		private ChangeText(ElectricObject owner, Variable.Key key, String[] newText) {			super("Modify Text", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.owner = owner;			this.key = key;			this.newText = newText;			startJob();		}		public boolean doIt() throws JobException		{			if (key == null) return false;			if (key == Export.EXPORT_NAME)			{				Export pp = (Export)owner;				pp.rename(newText[0]);			} else if (key == NodeInst.NODE_NAME)			{				((NodeInst)owner).setName(newText[0]);			} else if (key == ArcInst.ARC_NAME)			{				((ArcInst)owner).setName(newText[0]);			} else if (owner instanceof Cell && owner.isParam(key))			{				Cell.CellGroup cellGroup = ((Cell)owner).getCellGroup();				if (newText.length > 1)				{					cellGroup.updateParam((Variable.AttrKey)key, newText);				} else				{					// change variable text					cellGroup.updateParamText((Variable.AttrKey)key, newText[0]);				}			} else			{				if (newText.length > 1)				{					owner.updateVar(key, newText);				} else				{					// change variable text					owner.updateVarText(key, newText[0]);				}			}			return true;		}	}	/**	 * This method is called from within the constructor to	 * initialize the form.	 */	private void initComponents()	{		GridBagConstraints gridBagConstraints;		cancel = new JButton();		ok = new JButton();		header = new JLabel();		apply = new JButton();		evaluation = new JLabel();		theText = new JTextField();		textPanel = new TextInfoPanel(false, false);		attrPanel = new TextAttributesPanel(false);		multiLine = new JCheckBox();		getContentPane().setLayout(new GridBagLayout());		getRootPane().setDefaultButton(ok);		setTitle("Text Properties");		setName("");		addWindowListener(new WindowAdapter() {			public void windowClosing(WindowEvent evt) { closeDialog(evt); }		});		header.setText("");		gridBagConstraints = new GridBagConstraints();		gridBagConstraints.gridx = 0;		gridBagConstraints.gridy = 0;		gridBagConstraints.gridwidth = 2;		gridBagConstraints.weightx = 1.0;		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;		gridBagConstraints.anchor = GridBagConstraints.WEST;		gridBagConstraints.insets = new Insets(4, 4, 4, 4);		getContentPane().add(header, gridBagConstraints);		changeTextComponent("", false);		multiLine.setText("Multi-Line Text");		gridBagConstraints = new GridBagConstraints();		gridBagConstraints.gridx = 2;		gridBagConstraints.gridy = 0;		gridBagConstraints.gridwidth = 1;		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;		gridBagConstraints.insets = new Insets(4, 4, 4, 4);		gridBagConstraints.anchor = GridBagConstraints.EAST;		getContentPane().add(multiLine, gridBagConstraints);		multiLine.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent e) { multiLineStateChanged(); }		});		evaluation.setText(" ");		gridBagConstraints = new GridBagConstraints();		gridBagConstraints.gridx = 0;		gridBagConstraints.gridy = 2;		gridBagConstraints.gridwidth = 3;		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;		gridBagConstraints.insets = new Insets(2, 4, 2, 4);		getContentPane().add(evaluation, gridBagConstraints);		gridBagConstraints = new GridBagConstraints();		gridBagConstraints.gridx = 0;		gridBagConstraints.gridy = 3;		gridBagConstraints.gridwidth = 3;		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;		gridBagConstraints.insets = new Insets(2, 4, 2, 4);		getContentPane().add(textPanel, gridBagConstraints);		gridBagConstraints = new GridBagConstraints();		gridBagConstraints.gridx = 0;		gridBagConstraints.gridy = 4;		gridBagConstraints.gridwidth = 3;		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;		gridBagConstraints.insets = new Insets(2, 4, 2, 4);		getContentPane().add(attrPanel, gridBagConstraints);		cancel.setText("Cancel");		cancel.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent evt) { cancelActionPerformed(evt); }		});		gridBagConstraints = new GridBagConstraints();		gridBagConstraints.gridx = 0;		gridBagConstraints.gridy = 5;		gridBagConstraints.weightx = 0.1;		gridBagConstraints.insets = new Insets(4, 4, 4, 4);		getContentPane().add(cancel, gridBagConstraints);		apply.setText("Apply");		apply.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent evt) { applyActionPerformed(evt); }		});		gridBagConstraints = new GridBagConstraints();		gridBagConstraints.gridx = 1;		gridBagConstraints.gridy = 5;		gridBagConstraints.weightx = 0.1;		gridBagConstraints.insets = new Insets(4, 4, 4, 4);		getContentPane().add(apply, gridBagConstraints);		ok.setText("OK");		ok.addActionListener(new ActionListener() {			public void actionPerformed(ActionEvent evt) { okActionPerformed(evt); }		});		gridBagConstraints = new GridBagConstraints();		gridBagConstraints.gridx = 2;		gridBagConstraints.gridy = 5;		gridBagConstraints.weightx = 0.1;		gridBagConstraints.insets = new Insets(4, 4, 4, 4);		getContentPane().add(ok, gridBagConstraints);		pack();	}	private void multiLineStateChanged() {		// set text box type		changeTextComponent(theText.getText(), multiLine.isSelected());	}	private void changeTextComponent(String currentText, boolean multipleLines) {		if (cti == null || cti.shownText == null) return;		getContentPane().remove(theText);		if (currentText == null) currentText = "";		if (multipleLines) {			// multiline text, change to text area			theText = new JTextArea();			String[] text = currentText.split("\\n");			int size = 1;			if (text.length > size) size = text.length;			((JTextArea)theText).setRows(size);			((JTextArea)theText).setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));			// add listener to increase the number of rows if needed			theText.addKeyListener(new KeyListener() {				public void keyPressed(KeyEvent e) {}				public void keyTyped(KeyEvent e) {}				public void keyReleased(KeyEvent e) {					JTextArea area = (JTextArea)theText;					area.setRows(area.getLineCount());					pack();					ensureProperSize();				}			});		} else {			theText = new JTextField();			if (currentText.matches(".*?\\n.*")) {				currentText = currentText.substring(0, currentText.indexOf('\n'));			}		}		theText.setText(currentText);		GridBagConstraints gridBagConstraints = new GridBagConstraints();		gridBagConstraints.gridx = 0;		gridBagConstraints.gridy = 1;		gridBagConstraints.gridwidth = 3;		gridBagConstraints.fill = GridBagConstraints.BOTH;		gridBagConstraints.weightx = 1.0;		gridBagConstraints.weighty = 1.0;		gridBagConstraints.insets = new Insets(4, 4, 4, 4);		getContentPane().add(theText, gridBagConstraints);		pack();	}	private void applyActionPerformed(ActionEvent evt)	{		if (cti.shownText == null) return;		// tell sub-panels to update if they have changed		textPanel.applyChanges(true);		attrPanel.applyChanges();		boolean changed = false;		// see if text changed		String currentText = theText.getText();		if (!currentText.equals(cti.initialText)) changed = true;		if (changed)		{			String[] textArray = currentText.split("\\n");			ArrayList<String> textList = new ArrayList<String>();			for (int i=0; i<textArray.length; i++) {				String str = textArray[i];				if (Simulation.getPreserveVerilogFormating() && // Pref set					cti.td.getPos() == TextDescriptor.Position.RIGHT && // Left justified text					(cti.varKey == Verilog.VERILOG_PARAMETER_KEY || 				 	cti.varKey == Verilog.VERILOG_CODE_KEY ||				 	cti.varKey == Verilog.VERILOG_EXTERNAL_CODE_KEY ||				 	cti.varKey == Verilog.VERILOG_DECLARATION_KEY))				{				 	textList.add(str);				} else				{					str = str.trim();					if (str.equals("")) continue;					textList.add(str);				}			}			textArray = new String[textList.size()];			for (int i=0; i<textList.size(); i++) {				String str = textList.get(i);				textArray[i] = str;			}			if (textArray.length > 0) {				// generate job to change text				new ChangeText(cti.owner, cti.varKey, textArray);				cti.initialText = currentText;			}		}	}	private void okActionPerformed(ActionEvent evt) {		applyActionPerformed(evt);		closeDialog(null);	}	private void cancelActionPerformed(ActionEvent evt) {		closeDialog(null);	}	/**	 * Closes the dialog	 */	private void closeDialog(WindowEvent evt) {		super.closeDialog();	}	private JButton apply;	private JButton cancel;	private JLabel evaluation;	private JLabel header;	private JButton ok;	private JTextComponent theText;	private TextInfoPanel textPanel;	private TextAttributesPanel attrPanel;	private JCheckBox multiLine;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?