📄 periodictablepanel.java
字号:
panel.add( createButton("Th")); panel.add(createButton("Pa")); panel.add(createButton("U")); panel.add(createButton("Np")); panel.add(createButton("Pu")); panel.add(createButton("Am")); panel.add(createButton("Cm")); panel.add(createButton("Bk")); panel.add(createButton("Cf")); panel.add(createButton("Es")); panel.add(createButton("Fm")); panel.add(createButton("Md")); panel.add(createButton("No")); panel.add(createButton("Lr")); //End panel.setVisible(true); return panel; } /** * create button. Difine the color of the font and background * *@param elementS String of the element *@return button JButton */ private JButton createButton(String elementS) { PeriodicTableElement element = factory.configure(new PeriodicTableElement(elementS)); String colorFS = "000000"; Color colorF = new Color(0,0,0); String colorPh = element.getPhase(); if(colorPh.equals("Solid")){ colorFS = "000000"; colorF = new Color(0,0,0); } else if(colorPh.equals("Gas")){ colorFS = "CC0033"; colorF = new Color(200,0,0); } else if(colorPh.equals("Liquid")){ colorFS = "3300CC"; colorF = new Color(0,0,200); } else if(colorPh.equals("Synthetic")){ colorFS = "FFCC00"; colorF = new Color(235,208,6); } Color colorB = null; String serie = element.getChemicalSerie(); if(serie.equals("Noble Gasses")) colorB = new Color(255,153,255); else if(serie.equals("Halogens")) colorB = new Color(255,153,153); else if(serie.equals("Nonmetals")) colorB = new Color(255,152,90); else if(serie.equals("Metalloids")) colorB = new Color(255,80,80); else if(serie.equals("Metals")) colorB = new Color(255,50,0); else if(serie.equals("Alkali Earth Metals")) colorB = new Color(102,150,255); else if(serie.equals("Alkali Metals")) colorB = new Color(130,130,255); else if(serie.equals("Transition metals")) colorB = new Color(255,255,110); else if(serie.equals("Lanthanides")) colorB = new Color(255,255,150); else if(serie.equals("Actinides")) colorB = new Color(255,255,200); JButton button = new ElementButton(element, new ElementButtonAction(), getTextButton(element,colorFS), colorF); button.setBackground(colorB); return button; } /** * Sets the selectedElement attribute of the PeriodicTablePanel object * *@param selectedElement The new selectedElement value */ public void setSelectedElement(PeriodicTableElement selectedElement) { this.selectedElement = selectedElement; } /** * Gets the selectedElement attribute of the PeriodicTablePanel object * *@return The selectedElement value */ public Element getSelectedElement() { return PeriodicTableElement.configure(selectedElement); } /** * Adds a change listener to the list of listeners * *@param listener The listener added to the list */ public void addCDKChangeListener(ICDKChangeListener listener) { listeners.add(listener); } /** * Removes a change listener from the list of listeners * *@param listener The listener removed from the list */ public void removeCDKChangeListener(ICDKChangeListener listener) { listeners.remove(listener); } /** * Notifies registered listeners of certain changes that have occurred in this * model. */ public void fireChange() { EventObject event = new EventObject(this); for (int i = 0; i < listeners.size(); i++) { ((ICDKChangeListener) listeners.get(i)).stateChanged(event); } } /** * get the format which the text will be introduce into the button * * @param element The PeriodicTableElement * @return the String to show */ public String getTextButton(PeriodicTableElement element, String color){ String buttonString = null; switch (controlViewerButton) { case 0: buttonString ="<html><p><u><FONT SIZE=-2>"+element.getAtomicNumber()+"</FONT></u></p><p><font COLOR="+color+">" +element.getSymbol()+"<font></p></html>";break; case 1: buttonString = element.getSymbol();break; default: buttonString = element.getSymbol();break; } return buttonString; } /** * Description of the Class * *@author steinbeck *@cdk.created February 10, 2004 */ public class ElementButtonAction extends AbstractAction { private static final long serialVersionUID = 6176240749900870566L; public void actionPerformed(ActionEvent e) { ElementButton button = (ElementButton) e.getSource(); setSelectedElement(button.getElement()); layeredPane.remove(panel); panel = CreateLabelProperties(button.getElement()); layeredPane.add(panel, new Integer(1)); layeredPane.repaint(); fireChange(); } } /** * This action fragment a molecule which is on the frame JChemPaint * */ class BackAction extends AbstractAction { private static final long serialVersionUID = -8708581865777449553L; public void actionPerformed(ActionEvent e) { layeredPane.remove(panel); panel = CreateLabelProperties(null); layeredPane.add(panel, new Integer(1)); layeredPane.repaint(); } } class ElementButton extends JButton { private static final long serialVersionUID = 1504183423628680664L; private PeriodicTableElement element; /** * Constructor for the ElementButton object * *@param element Description of the Parameter */ public ElementButton(PeriodicTableElement element) { super("H"); this.element = factory.configure(element); } /** * Constructor for the ElementButton object * * @param element Description of the Parameter * @param e Description of the Parameter * @param color Description of the Parameter * @param controlViewer Description of the Parameter */ public ElementButton( PeriodicTableElement element, ElementButtonAction e,String buttonString, Color color) { super(buttonString); if(controlViewerButton == JCP){ setForeground(color); } this.element = element; setFont(new Font("Times-Roman",Font.BOLD, 15)); setBorder( new BevelBorder(BevelBorder.RAISED) ); setToolTipText(element.getName()); addActionListener(e); } /** * Gets the element attribute of the ElementButton object * *@return The element value */ public PeriodicTableElement getElement() { return this.element; } } /** * create the Label * *@param element PeriodicTableElement *@return pan JPanel */ private JPanel CreateLabelProperties(PeriodicTableElement element) { JPanel pan = new JPanel(); pan.setLayout(new BorderLayout()); Color color = new Color(255,255,255); Point origin = new Point(90, 20); JLabel label; if(element != null){ if(controlViewerButton == PeriodicTablePanel.APPLICATION) { label = new JLabel("<html><PRE> <FONT SIZE=+2>" +element.getSymbol()+"</FONT>" +": At.No "+element.getAtomicNumber() +", Group "+element.getGroup()+", Period " + element.getPeriod()+"</PRE></html>"); pan.add(label,BorderLayout.NORTH); label = new JLabel("<html><PRE><FONT SIZE=-2>" +" CAS id: "+element.getCASid()+"<br>" +" Name: "+element.getName()+"<br>" +" Serie: "+element.getChemicalSerie()+"<br>" +" State: "+element.getPhase()+"<br>" +" Appar: XXXX<br>" +" Mp: 0.0000<br>" +" Bp: 0.0000<br>" +" Conduc: 0.0000<br>" +" Densit: 0.0000<br>" +" VaporH: 0.0000<br>" +" XXXX: 0.0000<br>" +" XXXX: 0.0000<br>" +"</FONT></PRE></html>"); label.setMinimumSize(new Dimension(145,150)); pan.add(label,BorderLayout.WEST); label = new JLabel("<html><PRE><FONT SIZE=-2>" +" At. Weight: 0.000000<br>" +" At. Radius: 0.0000<br>" +" Cov Radius: 0.0000<br>" +" VW Radius: 0.0000<br>" +" Io Radius: 0.0000<br>" +" e config: 1s1<br>" +" Valency e: 1s1<br>" +" Electro: 0.0<br>" +" Oxid: 1<br>" +" IP: 0.0000<br>" +" Crist: XXXXXX<br>" +" XXXX: 0.0000<br>" +"</FONT></PRE></html>"); label.setMinimumSize(new Dimension(145,150)); pan.add(label,BorderLayout.EAST); } } else { label = new JLabel("<html></head><br><br>" +"<p><FONT><pre> PERIODIC TABLE<pre></FONT></p>" +"<p><PRE> of elements</PRE></p><br><br><br><br>" +"<FONT SIZE=-2>D.I. Mendeleev(1834-1907)</FONT></html>"); label.setOpaque(true); label.setBackground(color); pan.add(label,BorderLayout.EAST); URL url = this.getClass().getResource( "/org/openscience/cdk/applications/swing/periodicTable_Mendeleev.jpg"); if(url!=null) { ImageIcon image = new ImageIcon(url); label = new JLabel(image,JLabel.CENTER); pan.add(label,BorderLayout.WEST); } } pan.setBackground(color); pan.setForeground(Color.black); pan.setBorder(BorderFactory.createLineBorder(Color.black)); pan.setBounds(origin.x, origin.y, 295, 210); return pan; } /** * set the form to do a button {html or normal) * * @param controlViewer */ public void setControlViewer(int controlViewer){ this.controlViewerButton = controlViewer; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -