📄 userinterfacemain.java
字号:
content.fullRepaint(); } }// Object[] listeners;// synchronized (UserInterfaceMain.class) {// listeners = undoRedoListenerList.getListenerList();// }// // Process the listeners last to first, notifying those that are interested in this event// for (int i = listeners.length-2; i>=0; i-=2) {// if (listeners[i] == PropertyChangeListener.class)// ((PropertyChangeListener)listeners[i+1]).propertyChange(e);// } } private static class PropertyChangeRun implements Runnable { private PropertyChangeEvent e; private PropertyChangeRun(PropertyChangeEvent e) { this.e = e; } public void run() { firePropertyChange(e); } } /** Add a DatabaseChangeListener. It will be notified when * state of the database changes. * @param l the listener */ public static synchronized void addDatabaseChangeListener(DatabaseChangeListener l) { listenerList.add(DatabaseChangeListener.class, l); } /** Remove a DatabaseChangeListener. */ public static synchronized void removeDatabaseChangeListener(DatabaseChangeListener l) { listenerList.remove(DatabaseChangeListener.class, l); } /** * Fire DatabaseChangeEvent to DatabaseChangeListeners. * @param e DatabaseChangeEvent. */ public static void fireDatabaseChangeEvent(DatabaseChangeEvent e) { Object[] listeners; synchronized (User.class) { listeners = listenerList.getListenerList(); } // Process the listeners last to first, notifying those that are interested in this event for (int i = listeners.length-2; i>=0; i-=2) { if (listeners[i] == DatabaseChangeListener.class) ((DatabaseChangeListener)listeners[i+1]).databaseChanged(e); } } private static class DatabaseChangeRun implements Runnable { private Snapshot newSnapshot; private boolean undoRedo; private DatabaseChangeRun(Snapshot newSnapshot, boolean undoRedo) { this.newSnapshot = newSnapshot; this.undoRedo = undoRedo; } public void run() { DatabaseChangeEvent event = new DatabaseChangeEvent(currentSnapshot, newSnapshot); for(Iterator<Listener> it = Tool.getListeners(); it.hasNext(); ) { Listener listener = it.next(); listener.endBatch(currentSnapshot, newSnapshot, undoRedo); } currentSnapshot = newSnapshot; fireDatabaseChangeEvent(event); } } private int lastId = 0; private ArrayList<SavedHighlights> savedHighlights = new ArrayList<SavedHighlights>(); private static class SavedHighlights { /** id of this saved state */ private final int id; /** EditWindow_ of highlights */ private final EditWindow_ wnd; /** list of saved Highlights */ private final List<Highlight2> savedHighlights; /** saved Highlight offset */ private final Point2D savedHighlightsOffset; private SavedHighlights(int id, EditWindow_ wnd) { this.id = id; this.wnd = wnd; savedHighlights = wnd.saveHighlightList(); savedHighlightsOffset = wnd.getHighlightOffset(); } private void restore() { wnd.restoreHighlightList(savedHighlights); wnd.setHighlightOffset((int)savedHighlightsOffset.getX(), (int)savedHighlightsOffset.getY()); wnd.finishedHighlighting(); } } /** * Class to display a Splash Screen at the start of the program. */ private static class SplashWindow extends JFrame { public SplashWindow(Mode mode) { super(); setUndecorated(true); setTitle("Electric Splash"); setIconImage(TopLevel.getFrameIcon().getImage()); JPanel whole = new JPanel(); whole.setBorder(BorderFactory.createLineBorder(new Color(0, 170, 0), 5)); whole.setLayout(new BorderLayout()); ImageIcon splashImage = Resources.getResource(TopLevel.class, "SplashImage.gif"); JLabel l = new JLabel(splashImage); whole.add(l, BorderLayout.CENTER); JLabel v = new JLabel("Version " + Version.getVersion(), JLabel.CENTER); whole.add(v, BorderLayout.SOUTH); Font font = new Font(User.getDefaultFont(), Font.BOLD, 24); v.setFont(font); v.setForeground(Color.BLACK); v.setBackground(Color.WHITE); getContentPane().add(whole, BorderLayout.SOUTH); pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension labelSize = getPreferredSize(); setLocation(screenSize.width/2 - (labelSize.width/2), screenSize.height/2 - (labelSize.height/2));// addWindowListener(new WindowsEvents(this)); setVisible(true); toFront(); paint(getGraphics()); } }// /**// * This class handles deactivation of the splash screen and forces it back to the top.// */// private static class WindowsEvents implements WindowListener// {// SplashWindow sw;//// WindowsEvents(SplashWindow sw)// {// super();// this.sw = sw;// }//// public void windowActivated(WindowEvent e) {}// public void windowClosed(WindowEvent e) {}// public void windowClosing(WindowEvent e) {}// public void windowDeiconified(WindowEvent e) {}// public void windowIconified(WindowEvent e) {}// public void windowOpened(WindowEvent e) {}//// public void windowDeactivated(WindowEvent e)// {// sw.toFront();// }// } /** * Places a custom event processor on the event queue in order to * catch all exceptions generated by event processing. */ private static class EventProcessor extends EventQueue { private final String CLASS_NAME = getClass().getName(); private int dispatchDepth = 0; private EventProcessor() { Toolkit kit = Toolkit.getDefaultToolkit(); kit.getSystemEventQueue().push(this); }// public void postEvent(AWTEvent theEvent) {// logger.entering(CLASS_NAME, "postEvent", theEvent);// super.postEvent(theEvent);// logger.exiting(CLASS_NAME, "postEvent");// }// // public AWTEvent getNextEvent() throws InterruptedException {// logger.entering(CLASS_NAME, "getNextEvent");// AWTEvent event = super.getNextEvent();// logger.exiting(CLASS_NAME, "getNextEvent", event);// return event;// }// // public synchronized AWTEvent peekEvent() {// logger.entering(CLASS_NAME, "peekEvent");// AWTEvent event = super.peekEvent();// logger.exiting(CLASS_NAME, "peekEvent", event);// return event;// }//// public synchronized AWTEvent peekEvent(int id) {// logger.entering(CLASS_NAME, "peekEvent", id);// AWTEvent event = super.peekEvent(id);// logger.exiting(CLASS_NAME, "peekEvent", event);// return event;// } protected void dispatchEvent(AWTEvent e) {// logger.entering(CLASS_NAME, "dispatchEvent", e);// if (dispatchDepth == 0)// database.lock(false); dispatchDepth++; try { super.dispatchEvent(e); } catch(Throwable ex) { ex.printStackTrace(System.err); ActivityLogger.logException(ex); if (ex instanceof Error) { logger.throwing(CLASS_NAME, "dispatchEvent", ex); throw (Error)ex; }// } finally {// dispatchDepth--;// if (dispatchDepth == 0)// database.unlock(); }// logger.exiting(CLASS_NAME, "dispatchEvent"); } }// private static void runThreadStatusTimer() {// int delay = 1000*60*10; // milliseconds// Timer timer = new Timer(delay, new ThreadStatusTask());// timer.start();// }//// private static class ThreadStatusTask implements ActionListener {// public void actionPerformed(ActionEvent e) {// Thread t = Thread.currentThread();// ThreadGroup group = t.getThreadGroup();// // get the top level group// while (group.getParent() != null)// group = group.getParent();// Thread [] threads = new Thread[200];// int numThreads = group.enumerate(threads, true);// StringBuffer buf = new StringBuffer();// for (int i=0; i<numThreads; i++) {// buf.append("Thread["+i+"] "+threads[i]+": alive: "+threads[i].isAlive()+", interrupted: "+threads[i].isInterrupted()+"\n");// }// ActivityLogger.logThreadMessage(buf.toString());// }// } /** * Method to start the display of a progress dialog. * @param msg the message to show in the progress dialog. * @param filePath the file being read (null if not reading a file). */ public void startProgressDialog(String msg, String filePath) { stopProgressDialog(); try{ String message; if (filePath == null) message = msg + "..."; else message = "Reading " + msg + " " + filePath + "..."; progress = new Progress(message); } catch (Exception e) { e.printStackTrace(); } progress.setProgress(0); } /** * Method to stop the progress bar */ public void stopProgressDialog() { if (progress != null) { progress.close(); progress = null; } } /** * Method to update the progress bar * @param pct the percentage done (from 0 to 100). */ public void setProgressValue(long pct) { // progress is null if it is in quiet mode if (progress != null) { progress.setProgress((int)pct); } } /** * Method to set a text message in the progress dialog. * @param message the new progress message. */ public void setProgressNote(String message) { // progress is null if it is in quiet mode if (progress != null) progress.setNote(message); } /** * Method to get text message in the progress dialog. * @return text message in the progress dialog. */ public String getProgressNote() { if (progress == null) return ""; return progress.getNote(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -