📄 mainframe.java
字号:
public void mouseClicked(MouseEvent e) {
if(e.getButton() == e.BUTTON1) {
MainFrame.this.setVisible(true);
MainFrame.this.setState(Frame.NORMAL);
}
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
};
ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainFrame.this.setVisible(false);
MainFrame.this.dispose();
}
};
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "JStock - Stock Market Software", popup);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
};
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
trayIcon.addMouseListener(mouseListener);
try {
tray.add(trayIcon);
} catch (AWTException e) {
trayIcon = null;
JOptionPane.showMessageDialog(MainFrame.this, "TrayIcon could not be added.", "System Tray Not Supported", JOptionPane.WARNING_MESSAGE);
}
} else {
// System Tray is not supported
trayIcon = null;
JOptionPane.showMessageDialog(MainFrame.this, "System tray is not supported. You may not get stock alert notify.", "System Tray Not Supported", JOptionPane.WARNING_MESSAGE);
}
}
private void initTableHeaderToolTips() {
JTableHeader header = jTable1.getTableHeader();
ColumnHeaderToolTips tips = new ColumnHeaderToolTips();
header.addMouseMotionListener(tips);
}
private void updateBuyerSellerInformation(Stock stock) {
if(stock == null) {
jLabel24.setText("");
jLabel33.setText("");
jLabel19.setText("");
jLabel32.setText("");
jLabel35.setText("");
jLabel37.setText("");
jLabel25.setText("");
jLabel34.setText("");
jLabel26.setText("");
jLabel29.setText("");
jLabel30.setText("");
jLabel38.setText("");
return;
}
final double openPrice = stock.getOpenPrice();
jLabel24.setText("" + stock.getThirdBuyPrice()); jLabel24.setForeground(Utils.getColor(stock.getThirdBuyPrice(), openPrice));
jLabel33.setText("" + stock.getSecondBuyPrice()); jLabel33.setForeground(Utils.getColor(stock.getSecondBuyPrice(), openPrice));
jLabel19.setText("" + stock.getBuyPrice()); jLabel19.setForeground(Utils.getColor(stock.getBuyPrice(), openPrice));
jLabel32.setText("" + stock.getSellPrice()); jLabel32.setForeground(Utils.getColor(stock.getSellPrice(), openPrice));
jLabel35.setText("" + stock.getSecondSellPrice()); jLabel35.setForeground(Utils.getColor(stock.getSecondSellPrice(), openPrice));
jLabel37.setText("" + stock.getThirdSellPrice()); jLabel37.setForeground(Utils.getColor(stock.getThirdSellPrice(), openPrice));
jLabel25.setText("" + stock.getThirdBuyQuantity());
jLabel34.setText("" + stock.getSecondBuyQuantity());
jLabel26.setText("" + stock.getBuyQuantity());
jLabel29.setText("" + stock.getSellQuantity());
jLabel30.setText("" + stock.getSecondSellQuantity());
jLabel38.setText("" + stock.getThirdSellQuantity());
}
private void changeCountry(Country country) {
if(country == null) return;
if(jStockOptions.getCountry() == country) return;
saveRealTimeStocks();
this.portfolioManagementJPanel.savePortfolio();
jStockOptions.setCountry(country);
MainFrame.this.statusBar.setCountryIcon(country.getIcon(), country.toString());
initStockCodeAndSymbolDatabase(true);
initMarketThread();
initMarketJPanel();
initStockHistoryMonitor();
initOthersStockHistoryMonitor();
// Initialize real time monitor must come before initialize real time
// stocks.
initRealTimeStockMonitor();
initRealTimeStocks();
this.portfolioManagementJPanel.initPortfolio();
this.indicatorScannerJPanel.stop();
this.indicatorScannerJPanel.clear();
this.chatJPanel.stopChatServiceManager();
if (jStockOptions.isChatEnabled())
{
this.chatJPanel.startChatServiceManager();
}
for (Enumeration<AbstractButton> e = this.buttonGroup2.getElements() ; e.hasMoreElements() ;) {
AbstractButton button = e.nextElement();
javax.swing.JRadioButtonMenuItem m = (javax.swing.JRadioButtonMenuItem)button;
if(m.getText().equals(country.toString())) {
m.setSelected(true);
break;
}
}
}
private MouseAdapter getMyJXStatusBarCountryLabelMouseAdapter() {
return new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2) {
CountryJDialog countryJDialog = new CountryJDialog(MainFrame.this, true);
countryJDialog.setLocationRelativeTo(MainFrame.this);
countryJDialog.setCountry(jStockOptions.getCountry());
countryJDialog.setVisible(true);
final Country country = countryJDialog.getCountry();
changeCountry(country);
}
}
};
}
private MouseAdapter getMyJXStatusBarImageLabelMouseAdapter() {
return new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 2) {
// Make sure no same task is running.
if(stockCodeAndSymbolDatabaseTask != null) {
if(stockCodeAndSymbolDatabaseTask.isDone() == true) {
final int result = JOptionPane.showConfirmDialog(MainFrame.this, "Perform reconnecting to stock server may take several minutes to several hours (depending on your network connection).\nAre you sure you want to do so?", "Reconnecting to stock server", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(result == JOptionPane.YES_OPTION)
{
initStockCodeAndSymbolDatabase(false);
}
}
else {
final int result = JOptionPane.showConfirmDialog(MainFrame.this, "Do you want to cancel from connecting to stock server?", "Cancel connecting to stock server", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(result == JOptionPane.YES_OPTION)
{
synchronized(stockCodeAndSymbolDatabaseTask)
{
stockCodeAndSymbolDatabaseTask._stop();
stockCodeAndSymbolDatabaseTask = null;
}
statusBar.setMainMessage("Network error");
statusBar.setImageIcon(getImageIcon("/images/16x16/network-error.png"), "Double cliked to try again");
statusBar.setProgressBar(false);
}
}
}
else {
initStockCodeAndSymbolDatabase(true);
}
}
}
};
}
private KeyAdapter getjComboBox1EditorComponentKeyAdapter() {
return new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if(KeyEvent.VK_ENTER == e.getKeyCode()) {
String stock = MainFrame.this.jComboBox1.getEditor().getItem().toString();
if(stock.length() > 0) {
Code code = stockCodeAndSymbolDatabase.searchStockCode(stock);
Symbol symbol = null;
if(code != null) {
symbol = stockCodeAndSymbolDatabase.codeToSymbol(code);
// First add the empty stock, so that the user will not have wrong perspective that
// our system is slow.
addStockToTable(Utils.getEmptyStock(code, symbol));
realTimeStockMonitor.addStockCode(code);
}
else {
symbol = stockCodeAndSymbolDatabase.searchStockSymbol(stock);
if(symbol != null) {
code = stockCodeAndSymbolDatabase.symbolToCode(symbol);
addStockToTable(Utils.getEmptyStock(code, symbol));
realTimeStockMonitor.addStockCode(stockCodeAndSymbolDatabase.symbolToCode(symbol));
}
}
} // if(stock.length() > 0)
else {
final String lastEnteredString = ((AutoCompleteJComboBox)MainFrame.this.jComboBox1).getLastEnteredString();
if(lastEnteredString.length() < 1) {
return;
}
if(MainFrame.this.stockCodeAndSymbolDatabaseTask != null)
{
if(MainFrame.this.stockCodeAndSymbolDatabaseTask.isDone() == false)
{
JOptionPane.showMessageDialog(MainFrame.this, lastEnteredString + " is not found in database\nPlease wait till database finished downloaded.", "Database downloading in progress", JOptionPane.INFORMATION_MESSAGE);
return;
}
}
JOptionPane.showMessageDialog(MainFrame.this, lastEnteredString + " is not found in database.\nYou may either add \"" + lastEnteredString + "\" manually through \"Database\" menu,\n" +
"or you may get the latest database from stock server, by double click on " +
"bottom right network icon.", "Database outdated", JOptionPane.INFORMATION_MESSAGE);
//final int result = JOptionPane.showConfirmDialog(MainFrame.this, lastEnteredString + " is not found in database\nDo you want to perform reconnecting to stock server?\nThis may take several minutes to several hours. (depending on your network connection)", "Database outdated", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
//if(result == JOptionPane.YES_OPTION)
//{
// initStockCodeAndSymbolDatabase(false);
//}
}
} // if(KeyEvent.VK_ENTER == e.getKeyCode())
} /* public void keyReleased(KeyEvent e) */
};
}
public StockCodeAndSymbolDatabase getStockCodeAndSymbolDatabase() {
return stockCodeAndSymbolDatabase;
}
public java.util.List<StockServerFactory> getStockServerFactory() {
return getStockServerFactory(MainFrame.jStockOptions.getCountry());
}
private java.util.List<StockServerFactory> getStockServerFactory(Country country) {
return Factories.INSTANCE.getStockServerFactories(country);
}
public java.util.List<Stock> getStocks() {
StockTableModel tableModel = (StockTableModel)jTable1.getModel();
return tableModel.getStocks();
}
// Should we synchronized the jTable1, or post the job at GUI event dispatch
// queue?
public void addStockToTable(final Stock stock) {
assert(java.awt.EventQueue.isDispatchThread());
StockTableModel tableModel = (StockTableModel)jTable1.getModel();
tableModel.addStock(stock);
}
// Only will return true if the selected stock is the one and only one.
private boolean isStockBeingSelected(final Stock stock) {
int[] rows = MainFrame.this.jTable1.getSelectedRows();
if(rows.length == 1) {
int row = rows[0];
StockTableModel tableModel = (StockTableModel)jTable1.getModel();
int modelIndex = jTable1.convertRowIndexToModel(row);
if(stock.getCode().equals(tableModel.getStock(modelIndex).getCode()))
{
return true;
}
}
return false;
}
priv
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -