📄 admingui.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: AdminGui.java,v 1.3 2003/11/09 16:23:56 per_nyfelt Exp $package org.ozoneDB.adminGui.main;import org.ozoneDB.adminGui.feature.FeatureBar;import org.ozoneDB.adminGui.feature.Feature;import org.ozoneDB.adminGui.feature.FeaturePanel;import org.ozoneDB.adminGui.feature.data.DataPanel;import org.ozoneDB.adminGui.feature.server.ServerPanel;import org.ozoneDB.adminGui.feature.account.AccountPanel;import org.ozoneDB.adminGui.res.Settings;import org.ozoneDB.adminGui.res.Images;import org.ozoneDB.adminGui.res.OzoneTheme;import org.ozoneDB.adminGui.widget.MessageBox;import org.ozoneDB.ExternalDatabase;import org.ozoneDB.core.admin.Admin;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.ArrayList;import java.util.Set;import java.util.HashSet;import javax.swing.*;import javax.swing.plaf.metal.MetalLookAndFeel;/** * @author Per Nyfelt */public class AdminGui extends JFrame { private JMenuBar menuBar; private Action connectAction; private Action disonnectAction; public int ID_THRESHOLD = 99; private JSplitPane centerSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); private HeaderPanel headerPanel = new HeaderPanel(""); private FeatureBar featureBar; private JPanel cardPanel; private Feature feature; private StatusBar statusBar; private ExternalDatabase db; private Set features; private static AdminGui instance; private AdminGui() { super(); initialize(); } public static AdminGui instance() { if (instance == null) { instance = new AdminGui(); } return instance; } public ExternalDatabase getDb() { return db; } public Admin getAdmin() { try { return getDb().admin(); } catch (Exception e) { MessageBox.showError("Failed to get Admin from database: ", e.toString()); return null; } } private void initialize() { this.features = new HashSet(); setTitle(Settings.TITLE); this.setSize(Settings.ADMIN_GUI_WIDTH, Settings.ADMIN_GUI_HEIGHT); this.setIconImage(new ImageIcon(getClass().getResource(Images.IMAGE_LOGO)).getImage()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { exit(); } }); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); layoutFrame(); createMenus(); setCursor(Cursor.getDefaultCursor()); setExtendedState(JFrame.MAXIMIZED_BOTH); setVisible(true); } public void setFeature(Feature feature) { this.feature = feature; headerPanel.setHeader(feature); String featureName = feature.getName(); if (!features.contains(featureName)) { System.out.println("adding feature " + featureName + " to cards"); features.add(feature.getName()); FeaturePanel featurePanel = feature.getPanel(); cardPanel.add(featurePanel, featureName); featurePanel.activateFeature(); } CardLayout layout = (CardLayout) cardPanel.getLayout(); System.out.println("showing feature " + featureName); layout.show(cardPanel, featureName); cardPanel.validate(); } public Feature getFeature() { return this.feature; } /** * |------------------------------------------------|| * | ||-----------------------------------------|| * | || HeaderPanel || * | ||-----------------------------------------|| * | F || || * | e || || * | a || || * | t || || * | u || FeaturePanel || * | r || || * | e || || * | B || || * | a || || * | r || || * | ||------------centerSplitPane--------------|| * |-------------------------------------------------| * | StatusBar | * |-------------------------------------------------| */ private void layoutFrame() { Container cp = getContentPane(); statusBar = new StatusBar("Ozone Server Administration"); featureBar = new FeatureBar(createFeatures()); cardPanel = new JPanel(new CardLayout()); cardPanel.add(new LogoPanel(), "logo"); //Vertical splitter that divides HeaderPanel and FeaturePanel centerSplitPane.setTopComponent(headerPanel); centerSplitPane.setBottomComponent(cardPanel); centerSplitPane.setOneTouchExpandable(false); //centerSplitPane.setDividerLocation(.20); centerSplitPane.setDividerSize(3); centerSplitPane.setEnabled(false); centerSplitPane.setBackground(Settings.COLOR_COBALT); cp.add(featureBar, BorderLayout.WEST); cp.add(centerSplitPane, BorderLayout.CENTER); cp.add(statusBar, BorderLayout.SOUTH); } private void createMenus() { menuBar = new JMenuBar(); setJMenuBar(menuBar); createFileMenu(); } private void createFileMenu() { JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); fileMenu.add(connectAction = new ConnectAction()); fileMenu.add(disonnectAction = new DisconnectAction()); fileMenu.add(new ExitAction()); showDisconnected(); } private class ConnectAction extends AbstractAction { public ConnectAction() { super("Connect"); } public void actionPerformed(ActionEvent e) { System.out.println("connect action called"); connect(); } } private void connect() { ConnectionDialog connDialog = new ConnectionDialog(AdminGui.instance(), "Connect"); connDialog.setVisible(true); if (connDialog.isDbChanged()) { db = connDialog.getDb(); headerPanel.setConnected(connDialog.getUrl()); disonnectAction.setEnabled(true); connectAction.setEnabled(false); featureBar.enableFeatures(); } } private class DisconnectAction extends AbstractAction { public DisconnectAction() { super("Disconnect"); } public void actionPerformed(ActionEvent e) { System.out.println("disconnect action called"); try { if (db != null && db.isOpen()) { db.close(); db = null; showDisconnected(); } } catch (Exception e1) { MessageBox.showError("Error closing db", e1.toString()); e1.printStackTrace(); } } } public void showDisconnected() { headerPanel.setDisConnected(); disonnectAction.setEnabled(false); connectAction.setEnabled(true); featureBar.disableFeatures(); } private class ExitAction extends AbstractAction { public ExitAction() { super("Exit"); } public void actionPerformed(ActionEvent e) { exit(); } } private void exit() { try { if (db != null && db.isOpen()) { db.close(); } } catch (Exception e1) { e1.printStackTrace(); } System.exit(0); } private java.util.List createFeatures() { java.util.List features = new ArrayList(); features.add(new Feature(Settings.FEATURE_ACCOUNTS, Images.FEATURES_ACCOUNTS, AccountPanel.class)); features.add(new Feature(Settings.FEATURE_SERVER, Images.FEATURES_SERVER, ServerPanel.class)); features.add(new Feature(Settings.FEATURE_DATA, Images.FEATURES_DATA, DataPanel.class)); return features; } private void run() { System.out.println("Starting AdminGui ...."); this.connect(); } public static void main(String args[]) { MetalLookAndFeel.setCurrentTheme(new OzoneTheme()); AdminGui gui = AdminGui.instance(); gui.run(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -