⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 desktop.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (c) 2003, KNOPFLERFISH project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above copyright *   notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above *   copyright notice, this list of conditions and the following *   disclaimer in the documentation and/or other materials *   provided with the distribution. * * - Neither the name of the KNOPFLERFISH project nor the names of its *   contributors may be used to endorse or promote products derived *   from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */package org.knopflerfish.bundle.desktop.swing;import org.osgi.framework.*;import org.osgi.service.packageadmin.*;import org.osgi.service.startlevel.*;import org.osgi.util.tracker.*;import javax.swing.table.*;import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;import java.awt.datatransfer.*;import java.awt.dnd.*;import java.util.Enumeration;import java.util.Vector;import java.util.Dictionary;import java.util.Map;import java.util.Properties;import java.util.Set;import java.util.TreeMap;import java.util.TreeSet;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.io.*;import java.net.URL;import java.util.jar.*;import java.util.zip.*;import org.knopflerfish.bundle.desktop.swing.console.*;import org.knopflerfish.service.desktop.*;import org.knopflerfish.bundle.log.window.impl.*;import org.knopflerfish.util.*;import javax.swing.plaf.ComponentUI;/** * The big one. This class displays the main desktop frame, menues, console * and listens for all registered * <tt>SwingBundleDisplayer</tt> services. These are used to create * JComponents, which are attached to the main panels. */public class Desktop  implements    BundleListener,    FrameworkListener,    DropTargetListener,    BundleSelectionListener{  JFrame           frame;  Container        contentPane;  boolean alive = false;  JCardPane          bundlePanel;  JTabbedPane        detailPanel;  JTabbedPane        consolePanel;  ImageIcon          updateIcon;  ImageIcon          startIcon;  ImageIcon          emptyIcon;  ImageIcon          stopIcon;  ImageIcon          uninstallIcon;  ImageIcon          installIcon;  ImageIcon          magPlusIcon;  ImageIcon          magMinusIcon;  ImageIcon          magFitIcon;  ImageIcon          mag1to1Icon;  ImageIcon          reloadIcon;  ImageIcon          arrowUpIcon;  ImageIcon          arrowDownIcon;  ImageIcon          arrowUp2Icon;  ImageIcon          arrowDown2Icon;  ImageIcon          viewIcon;  ImageIcon          openIcon;  ImageIcon          openURLIcon;  ImageIcon          saveIcon;  ImageIcon          prevIcon;  ImageIcon          nextIcon;  ImageIcon          connectIcon;  ImageIcon          connectIconLarge;  ImageIcon          tipIcon;  ImageIcon          floatIcon;  JToolBar           toolBar;  StatusBar          statusBar;  JMenuBar           menuBar;  JMenuItem          menuRemote;  JButton            buttonRemote;  public JCheckBoxMenuItem  logCheckBox = null;  BundleSelectionModel bundleSelModel = new DefaultBundleSelectionModel();  ListSelectionModel bundleSelection;  ConsoleSwing       consoleSwing;  JSplitPane          splitPane;  JSplitPane          splitPaneHoriz;  //  BundleInfoDisplayer displayHTML;  LFManager lfManager;  LookAndFeelMenu lfMenu;  ServiceTracker dispTracker;  ServiceTracker slTracker;  ServiceTracker pkgTracker;  JButton viewSelection;  static Point     frameLocation = null;  static Dimension frameSize     = null;  public Desktop() {  }  Map displayMap = new HashMap();  Map detailMap  = new HashMap();  public void start() {    slTracker =      new ServiceTracker(Activator.getTargetBC(), StartLevel.class.getName(), null);    slTracker.open();    pkgTracker =      new ServiceTracker(Activator.getTargetBC(), PackageAdmin.class.getName(), null);    pkgTracker.open();    emptyIcon     = new ImageIcon(getClass().getResource("/empty.gif"));    startIcon     = new ImageIcon(getClass().getResource("/player_play.png"));    stopIcon      = new ImageIcon(getClass().getResource("/player_stop.png"));    uninstallIcon = new ImageIcon(getClass().getResource("/player_eject.png"));    installIcon = new ImageIcon(getClass().getResource("/player_install.png"));    updateIcon    = new ImageIcon(getClass().getResource("/update.png"));    viewIcon      = new ImageIcon(getClass().getResource("/view_select.png"));    magPlusIcon    = new ImageIcon(getClass().getResource("/viewmag+.png"));    magMinusIcon   = new ImageIcon(getClass().getResource("/viewmag-.png"));    magFitIcon     = new ImageIcon(getClass().getResource("/viewmagfit.png"));    mag1to1Icon    = new ImageIcon(getClass().getResource("/viewmag1.png"));    reloadIcon     = new ImageIcon(getClass().getResource("/reload_green.png"));    arrowUpIcon    = new ImageIcon(getClass().getResource("/1uparrow.png"));    arrowUp2Icon   = new ImageIcon(getClass().getResource("/2uparrow.png"));    arrowDownIcon  = new ImageIcon(getClass().getResource("/1downarrow.png"));    arrowDown2Icon = new ImageIcon(getClass().getResource("/2downarrow.png"));    openIcon     = new ImageIcon(getClass().getResource("/open.png"));    openURLIcon  = new ImageIcon(getClass().getResource("/bundle_small.png"));    saveIcon     = new ImageIcon(getClass().getResource("/save.png"));    connectIcon  = new ImageIcon(getClass().getResource("/connect.png"));    connectIconLarge  = new ImageIcon(getClass().getResource("/connect48x48.png"));    prevIcon  = new ImageIcon(getClass().getResource("/player_prev.png"));    nextIcon  = new ImageIcon(getClass().getResource("/player_next.png"));    tipIcon     = new ImageIcon(getClass().getResource("/idea.png"));    floatIcon   = new ImageIcon(getClass().getResource("/float.png"));    lfManager = new LFManager();    lfManager.init();    consoleSwing = new ConsoleSwing(Activator.getTargetBC());    consoleSwing.start();    toolBar       = makeToolBar();    statusBar     = new StatusBar("");    String rName = Activator.remoteHost;    Map    props = Activator.getSystemProperties();    String spid  = (String)props.get("org.osgi.provisioning.spid");    if(spid == null) {      spid = "";    }    frame       = new JFrame(Strings.fmt("frame_title", rName, spid));    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);    frame.addWindowListener(new WindowAdapter() {        public void windowClosing(WindowEvent e) {          stopFramework();        }      });    contentPane = frame.getContentPane();    contentPane.setLayout(new BorderLayout());    contentPane.setSize(new Dimension(600, 400));    bundlePanel = new JCardPane();    bundlePanel.setPreferredSize(new Dimension(450, 300));    toolBar       = makeToolBar();    detailPanel   = new JTabbedPane();    detailPanel.setPreferredSize(new Dimension(350, 300));    detailPanel.setTabPlacement(JTabbedPane.BOTTOM);    detailPanel.setBorder(null);    //    displayHTML = new BundleInfoDisplayerHTML(this);    contentPane.add(toolBar,      BorderLayout.NORTH);    contentPane.add(statusBar,    BorderLayout.SOUTH);    splitPaneHoriz = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,                                    bundlePanel,                                    detailPanel);    splitPaneHoriz.setDividerLocation(bundlePanel.getPreferredSize().width);    splitPaneHoriz.setOneTouchExpandable(false);    JFloatable consoleWrapper =      new JFloatable(consoleSwing.getJComponent(), "Console");    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,                               splitPaneHoriz,                               consoleWrapper);    splitPane.setDividerLocation(300);    splitPane.setOneTouchExpandable(false);    contentPane.add(splitPane,  BorderLayout.CENTER);    DropTarget dt =      new DropTarget(contentPane,                     DnDConstants.ACTION_COPY_OR_MOVE, // actions                     this,                     true);    alive = true;    Bundle[]  bl = Activator.getTargetBC().getBundles();    for(int i = 0; i  < bl.length; i++) {      bundleChanged(new BundleEvent(BundleEvent.INSTALLED, bl[i]));    }    if(frameLocation != null) {      frame.setLocation(frameLocation);    }    if(frameSize != null) {      frame.setSize(frameSize);    }    frame.setJMenuBar(menuBar = makeMenuBar());    setRemote(Activator.remoteTracker.getService() != null);    setIcon(frame, "/fish");    frame.pack();    frame.show();    frame.toFront();    String dispFilter1 =      "(&" +      "(" + Constants.OBJECTCLASS + "=" +      SwingBundleDisplayer.class.getName() +      ")" +      "(" + SwingBundleDisplayer.PROP_ISDETAIL + "=false" + ")" +      ")";    String dispFilter =      "(" + Constants.OBJECTCLASS + "=" +      SwingBundleDisplayer.class.getName() +      ")";    try {      dispTracker =        new ServiceTracker(Activator.getBC(),                           Activator.getBC().createFilter(dispFilter),                           null)        {          public Object addingService(ServiceReference sr) {            SwingBundleDisplayer disp =              (SwingBundleDisplayer)super.addingService(sr);            Icon   icon = disp.getSmallIcon();            String  name =              Util.getStringProp(sr,                                 SwingBundleDisplayer.PROP_NAME,                                 disp.getClass().getName());            String  desc =              Util.getStringProp(sr,                                 SwingBundleDisplayer.PROP_DESCRIPTION,                                 "");            boolean bDetail    =              Util.getBooleanProp(sr,                                  SwingBundleDisplayer.PROP_ISDETAIL,                                  false);            JComponent comp = disp.createJComponent();            JFloatable wrapper = new JFloatable(comp, name);            // floating windows shouldn't be closed when            // the tabbed pane swaps components            wrapper.setAutoClose(false);            disp.setBundleSelectionModel(bundleSelModel);            if(bDetail) {              detailMap.put(sr, disp);              //              JPanel wrapper2 = new JPanel(new BorderLayout());              //              wrapper2.add(wrapper, BorderLayout.CENTER);              detailPanel.addTab(name, icon, wrapper, desc);            } else {              displayMap.put(sr, disp);              bundlePanel.addTab(name, wrapper);              makeViewPopupMenu();              viewMenu = makeViewMenu(viewMenu);            }            return disp;          }          public void removedService(ServiceReference sr, Object service) {            SwingBundleDisplayer disp = (SwingBundleDisplayer)service;            String  name =              Util.getStringProp(sr,                                 SwingBundleDisplayer.PROP_NAME,                                 disp.getClass().getName());            boolean bDetail    =              Util.getBooleanProp(sr,                                  SwingBundleDisplayer.PROP_ISDETAIL,                                  false);            if(bDetail) {              Component comp = null;              for(int i = 0; i < detailPanel.getTabCount(); i++) {                if(detailPanel.getTitleAt(i).equals(name)) {                  comp = detailPanel.getComponentAt(i);                }              }              if(comp != null) {                // Make sure floating windows are closed                if(comp instanceof JFloatable) {                  ((JFloatable)comp).setAutoClose(true);                  ((JFloatable)comp).doUnfloat();                }                detailPanel.remove(comp);              }              detailMap.remove(sr);            } else {              displayMap.remove(sr);              bundlePanel.removeTab(name);              makeViewPopupMenu();              viewMenu = makeViewMenu(viewMenu);            }            super.removedService(sr, service);          }        };

⌨️ 快捷键说明

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