Beispiel #1
0
 private static Method getBaselineMethod(JComponent component) {
   if (COMPONENT_BASELINE_METHOD != null) {
     return COMPONENT_BASELINE_METHOD;
   }
   Class klass = component.getClass();
   while (klass != null) {
     if (BASELINE_MAP.containsKey(klass)) {
       Method method = (Method) BASELINE_MAP.get(klass);
       return method;
     }
     klass = klass.getSuperclass();
   }
   klass = component.getClass();
   Method[] methods = klass.getMethods();
   for (int i = methods.length - 1; i >= 0; i--) {
     Method method = methods[i];
     if ("getBaseline".equals(method.getName())) {
       Class[] params = method.getParameterTypes();
       if (params.length == 2 && params[0] == int.class && params[1] == int.class) {
         BASELINE_MAP.put(klass, method);
         return method;
       }
     }
   }
   BASELINE_MAP.put(klass, null);
   return null;
 }
  /**
   * Creates an <code>ComponentUI</code> implementation for the specified component. In other words
   * create the look and feel specific delegate object for <code>target</code>. This is done in two
   * steps:
   *
   * <ul>
   *   <li>Look up the name of the <code>ComponentUI</code> implementation class under the value
   *       returned by <code>target.getUIClassID()</code>.
   *   <li>Use the implementation classes static <code>createUI()</code> method to construct a look
   *       and feel delegate.
   * </ul>
   *
   * @param target the <code>JComponent</code> which needs a UI
   * @return the <code>ComponentUI</code> object
   */
  public ComponentUI getUI(JComponent target) {

    Object cl = get("ClassLoader");
    ClassLoader uiClassLoader =
        (cl != null) ? (ClassLoader) cl : target.getClass().getClassLoader();
    Class<? extends ComponentUI> uiClass = getUIClass(target.getUIClassID(), uiClassLoader);
    Object uiObject = null;

    if (uiClass == null) {
      getUIError("no ComponentUI class for: " + target);
    } else {
      try {
        Method m = (Method) get(uiClass);
        if (m == null) {
          m = uiClass.getMethod("createUI", new Class[] {JComponent.class});
          put(uiClass, m);
        }
        uiObject = MethodUtil.invoke(m, null, new Object[] {target});
      } catch (NoSuchMethodException e) {
        getUIError("static createUI() method not found in " + uiClass);
      } catch (Exception e) {
        getUIError("createUI() failed for " + target + " " + e);
      }
    }

    return (ComponentUI) uiObject;
  }
Beispiel #3
0
  /**
   * Create the given ViewManager
   *
   * @param viewDescriptor Identifies the VM
   * @param properties Property string to pass
   * @return The new one
   */
  public ViewManager createViewManager(ViewDescriptor viewDescriptor, String properties) {
    synchronized (viewManagers) {
      try {
        ViewManager viewManager = null;
        if (viewDescriptor == null) {
          viewDescriptor = new ViewDescriptor();
        }
        if (viewDescriptor.getClassNames().size() > 0) {
          Class viewManagerClass = Misc.findClass((String) viewDescriptor.getClassNames().get(0));
          Constructor ctor =
              Misc.findConstructor(
                  viewManagerClass,
                  new Class[] {IntegratedDataViewer.class, ViewDescriptor.class, String.class});

          if (ctor == null) {
            throw new IllegalArgumentException(
                "cannot create ViewManager:" + viewManagerClass.getName());
          }

          viewManager =
              (ViewManager) ctor.newInstance(new Object[] {getIdv(), viewDescriptor, properties});
        } else {
          viewManager = new MapViewManager(getIdv(), viewDescriptor, properties);
        }

        addViewManager(viewManager);
        return viewManager;
      } catch (Throwable e) {
        logException("In getViewManager", e);
        return null;
      }
    }
  }
 /**
  * Find the class for the projection
  *
  * @param proj projection
  * @return corresponding ProjectionClass (or null if not found)
  */
 private ProjectionClass findProjectionClass(Projection proj) {
   Class want = proj.getClass();
   ComboBoxModel projClassList = projClassCB.getModel();
   for (int i = 0; i < projClassList.getSize(); i++) {
     ProjectionClass pc = (ProjectionClass) projClassList.getElementAt(i);
     if (want.equals(pc.projClass)) {
       return pc;
     }
   }
   return null;
 }
Beispiel #5
0
 private static boolean isWindows(LookAndFeel laf) {
   if (laf.getID() == "Windows") {
     return true;
   }
   if (!checkedForWindows) {
     try {
       WINDOWS_CLASS = Class.forName("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
     } catch (ClassNotFoundException e) {
     }
     checkedForWindows = true;
   }
   return (WINDOWS_CLASS != null && WINDOWS_CLASS.isInstance(laf));
 }
Beispiel #6
0
  private Object getResource(String key) {

    URL url = null;
    String name = key;

    if (name != null) {

      try {
        Class c = Class.forName("content.AdvancedPanel");
        url = c.getResource(name);
      } catch (ClassNotFoundException cnfe) {
        System.err.println("Unable to find Main class");
      }
      return url;
    } else return null;
  }
 /**
  * Return a String representation of the object
  *
  * @return a String representation of the object
  */
 public String toString() {
   return paramType.getName()
       + " "
       + name
       + " "
       + ((reader == null) ? "-" : "R")
       + ((writer == null) ? "-" : "W");
 }
 /**
  * Make the default projections from the internal list of classes.
  *
  * @return list of default projections
  */
 public static List makeDefaultProjections() {
   List defaults = new ArrayList();
   List classNames = getDefaultProjections();
   for (int i = 0; i < classNames.size(); i++) {
     String className = (String) classNames.get(i);
     try {
       Class projClass = Misc.findClass(className);
       ProjectionImpl pi = (ProjectionImpl) projClass.newInstance();
       pi.setName("Default " + pi.getProjectionTypeLabel());
       defaults.add(pi);
     } catch (Exception ee) {
       System.err.println("Error creating default projection: " + className);
       ee.printStackTrace();
     }
   }
   return defaults;
 }
Beispiel #9
0
 private static boolean isXP() {
   if (!checkedForClassic) {
     try {
       CLASSIC_WINDOWS =
           Class.forName("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
     } catch (ClassNotFoundException e) {
     }
     checkedForClassic = true;
   }
   if (CLASSIC_WINDOWS != null && CLASSIC_WINDOWS.isInstance(UIManager.getLookAndFeel())) {
     return false;
   }
   Toolkit toolkit = Toolkit.getDefaultToolkit();
   Boolean themeActive = (Boolean) toolkit.getDesktopProperty("win.xpstyle.themeActive");
   if (themeActive == null) {
     themeActive = Boolean.FALSE;
   }
   return themeActive.booleanValue();
 }
Beispiel #10
0
 /**
  * Get all of the view managers of the given class
  *
  * @param c ViewManager class
  * @return List of ViewManagers
  */
 public List getViewManagers(Class c) {
   List result = new ArrayList();
   List vms = getViewManagers();
   for (int i = 0; i < vms.size(); i++) {
     ViewManager vm = (ViewManager) vms.get(i);
     if (c.isAssignableFrom(vm.getClass())) {
       result.add(vm);
     }
   }
   return result;
 }
 /**
  * Create the default projection for the default class
  *
  * @return a default projection
  */
 private ProjectionImpl makeDefaultProjection() {
   // the default constructor
   try {
     Constructor c = projClass.getConstructor(VOIDCLASSARG);
     return (ProjectionImpl) c.newInstance(VOIDOBJECTARG);
   } catch (Exception ee) {
     System.err.println(
         "ProjectionManager makeDefaultProjection failed to construct class " + projClass);
     System.err.println("   " + ee);
     return null;
   }
 }
 /**
  * Accepts only cookies that can provide <code>Toolbar</code>.
  *
  * @param cookie an <code>InstanceCookie</code> to test
  * @return true if the cookie can provide accepted instances
  */
 protected InstanceCookie acceptCookie(InstanceCookie cookie)
     throws java.io.IOException, ClassNotFoundException {
   Class c = cookie.instanceClass();
   if (Toolbar.class.isAssignableFrom(c)) {
     return cookie;
   }
   if (Presenter.Toolbar.class.isAssignableFrom(c)) {
     return cookie;
   }
   if (separatorClass.isAssignableFrom(c)) {
     return cookie;
   }
   return null;
 }
Beispiel #13
0
 private static Method getBRBIMethod(Component component) {
   Class klass = component.getClass();
   while (klass != null) {
     if (BRB_I_MAP.containsKey(klass)) {
       Method method = (Method) BRB_I_MAP.get(klass);
       return method;
     }
     klass = klass.getSuperclass();
   }
   klass = component.getClass();
   Method[] methods = klass.getMethods();
   for (int i = methods.length - 1; i >= 0; i--) {
     Method method = methods[i];
     if ("getBaselineResizeBehaviorInt".equals(method.getName())) {
       Class[] params = method.getParameterTypes();
       if (params.length == 0) {
         BRB_I_MAP.put(klass, method);
         return method;
       }
     }
   }
   BRB_I_MAP.put(klass, null);
   return null;
 }
  private void copyFile() throws Exception {
    // Load the JDBC driver
    Class.forName(((String) jcboDriver.getSelectedItem()).trim());
    System.out.println("Driver loaded");

    // Establish a connection
    Connection conn =
        DriverManager.getConnection(
            ((String) jcboURL.getSelectedItem()).trim(),
            jtfUsername.getText().trim(),
            String.valueOf(jtfPassword.getPassword()).trim());
    System.out.println("Database connected");

    // Read each line from the text file and insert it to the table
    insertRows(conn);
  }
  // event handling
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnok) {
      PreparedStatement pstm;
      ResultSet rs;
      String sql;
      // if no entries has been made and hit ok button throw an error
      // you can do this step using try clause as well
      if ((tf1.getText().equals("") && (tf2.getText().equals("")))) {
        lblmsg.setText("Enter your details ");
        lblmsg.setForeground(Color.magenta);
      } else {

        try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection connect = DriverManager.getConnection("jdbc:odbc:student_base");
          System.out.println("Connected to the database");
          pstm = connect.prepareStatement("insert into student_base values(?,?)");
          pstm.setString(1, tf1.getText());
          pstm.setString(2, tf2.getText());
          // execute method to execute the query
          pstm.executeUpdate();
          lblmsg.setText("Details have been added to database");

          // closing the prepared statement  and connection object
          pstm.close();
          connect.close();
        } catch (SQLException sqe) {
          System.out.println("SQl error");
        } catch (ClassNotFoundException cnf) {
          System.out.println("Class not found error");
        }
      }
    }
    // upon clickin button addnew , your textfield will be empty to enternext record
    if (e.getSource() == btnaddnew) {
      tf1.setText("");
      tf2.setText("");
    }

    if (e.getSource() == btnexit) {
      System.exit(1);
    }
  }
Beispiel #16
0
 static {
   Method componentBaselineMethod = null;
   Method componentBRBMethod = null;
   Method componentBRBIMethod = null;
   Object brbCenterOffset = null;
   Object brbConstantAscent = null;
   Object brbConstantDescent = null;
   Object brbOther = null;
   try {
     componentBaselineMethod =
         Component.class.getMethod("getBaseline", new Class[] {int.class, int.class});
     componentBRBMethod = Component.class.getMethod("getBaselineResizeBehavior", new Class[] {});
     Class brbClass = Class.forName("java.awt.Component$BaselineResizeBehavior");
     brbCenterOffset = getFieldValue(brbClass, "CENTER_OFFSET");
     brbConstantAscent = getFieldValue(brbClass, "CONSTANT_ASCENT");
     brbConstantDescent = getFieldValue(brbClass, "CONSTANT_DESCENT");
     brbOther = getFieldValue(brbClass, "OTHER");
   } catch (NoSuchMethodException nsme) {
   } catch (ClassNotFoundException cnfe) {
   } catch (NoSuchFieldException nsfe) {
   } catch (IllegalAccessException iae) {
   }
   if (componentBaselineMethod == null
       || componentBRBMethod == null
       || brbCenterOffset == null
       || brbConstantDescent == null
       || brbConstantAscent == null
       || brbOther == null) {
     componentBaselineMethod = componentBRBMethod = null;
     brbCenterOffset = brbConstantAscent = brbConstantDescent = brbOther = null;
   }
   COMPONENT_BASELINE_METHOD = componentBaselineMethod;
   COMPONENT_BRB_METHOD = componentBRBMethod;
   ENUM_BRB_CENTER_OFFSET = brbCenterOffset;
   ENUM_BRB_CONSTANT_ASCENT = brbConstantAscent;
   ENUM_BRB_CONSTANT_DESCENT = brbConstantDescent;
   ENUM_BRB_OTHER = brbOther;
 }
Beispiel #17
0
  public QSAdminGUI(QSAdminMain qsadminMain, JFrame parentFrame) {
    this.parentFrame = parentFrame;
    Container cp = this;
    qsadminMain.setGUI(this);
    cp.setLayout(new BorderLayout(5, 5));
    headerPanel = new HeaderPanel(qsadminMain, parentFrame);
    mainCommandPanel = new MainCommandPanel(qsadminMain);
    cmdConsole = new CmdConsole(qsadminMain);
    propertiePanel = new PropertiePanel(qsadminMain);

    if (headerPanel == null
        || mainCommandPanel == null
        || cmdConsole == null
        || propertiePanel == null) {
      throw new RuntimeException("Loading of one of gui component failed.");
    }

    headerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    cp.add(headerPanel, BorderLayout.NORTH);
    JScrollPane propertieScrollPane = new JScrollPane(propertiePanel);
    // JScrollPane commandScrollPane = new JScrollPane(mainCommandPanel);
    JSplitPane splitPane =
        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, mainCommandPanel, cmdConsole);
    splitPane.setOneTouchExpandable(false);
    splitPane.setDividerLocation(250);
    // splitPane.setDividerLocation(0.70);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.addTab("Main", ball, splitPane, "Main Commands");
    tabbedPane.addTab("Get/Set", ball, propertieScrollPane, "Properties Panel");

    QSAdminPluginConfig qsAdminPluginConfig = null;
    PluginPanel pluginPanel = null;
    // -- start of loadPlugins
    try {
      File xmlFile = null;
      ClassLoader classLoader = null;
      Class mainClass = null;

      File file = new File(pluginDir);
      File dirs[] = null;

      if (file.canRead()) dirs = file.listFiles(new DirFileList());

      for (int i = 0; dirs != null && i < dirs.length; i++) {
        xmlFile = new File(dirs[i].getAbsolutePath() + File.separator + "plugin.xml");
        if (xmlFile.canRead()) {
          qsAdminPluginConfig = PluginConfigReader.read(xmlFile);
          if (qsAdminPluginConfig.getActive().equals("yes")
              && qsAdminPluginConfig.getType().equals("javax.swing.JPanel")) {
            classLoader = ClassUtil.getClassLoaderFromJars(dirs[i].getAbsolutePath());
            mainClass = classLoader.loadClass(qsAdminPluginConfig.getMainClass());
            logger.fine("Got PluginMainClass " + mainClass);
            pluginPanel = (PluginPanel) mainClass.newInstance();
            if (JPanel.class.isInstance(pluginPanel) == true) {
              logger.info("Loading plugin : " + qsAdminPluginConfig.getName());
              pluginPanelMap.put("" + (2 + i), pluginPanel);
              plugins.add(pluginPanel);
              tabbedPane.addTab(
                  qsAdminPluginConfig.getName(),
                  ball,
                  (JPanel) pluginPanel,
                  qsAdminPluginConfig.getDesc());
              pluginPanel.setQSAdminMain(qsadminMain);
              pluginPanel.init();
            }
          } else {
            logger.info(
                "Plugin "
                    + dirs[i]
                    + " is disabled so skipping "
                    + qsAdminPluginConfig.getActive()
                    + ":"
                    + qsAdminPluginConfig.getType());
          }
        } else {
          logger.info("No plugin configuration found in " + xmlFile + " so skipping");
        }
      }
    } catch (Exception e) {
      logger.warning("Error loading plugin : " + e);
      logger.fine("StackTrace:\n" + MyString.getStackTrace(e));
    }
    // -- end of loadPlugins

    tabbedPane.addChangeListener(
        new ChangeListener() {
          int selected = -1;
          int oldSelected = -1;

          public void stateChanged(ChangeEvent e) {
            // if plugin
            selected = tabbedPane.getSelectedIndex();
            if (selected >= 2) {
              ((PluginPanel) pluginPanelMap.get("" + selected)).activated();
            }
            if (oldSelected >= 2) {
              ((PluginPanel) pluginPanelMap.get("" + oldSelected)).deactivated();
            }
            oldSelected = selected;
          }
        });

    // tabbedPane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
    cp.add(tabbedPane, BorderLayout.CENTER);

    buildMenu();
  }
Beispiel #18
0
  public WhatsNew(AbstractProjectViewer pv, boolean onlyShowCurrentVersion)
      throws GeneralException {

    super(pv);

    String wn = Environment.getProperty(Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME);

    if (wn == null) {

      wn = "0";
    }

    // Get the current whats new version (i.e. old).
    Version lastWhatsNewVersion = new Version(wn);

    boolean betasAllowed =
        Environment.getUserProperties()
            .getPropertyAsBoolean(Constants.OPTIN_TO_BETA_VERSIONS_PROPERTY_NAME);

    try {

      String whatsNew = Environment.getResourceFileAsString(Constants.WHATS_NEW_FILE);

      // Load up all the whats new for greater versions.
      Element root = JDOMUtils.getStringAsElement(whatsNew);

      java.util.List verEls = JDOMUtils.getChildElements(root, XMLConstants.version, false);

      // Assume they are in the right order
      // TODO: Enforce the order and/or sort.
      for (int i = 0; i < verEls.size(); i++) {

        Element vEl = (Element) verEls.get(i);

        String id = JDOMUtils.getAttributeValue(vEl, XMLConstants.id, true);

        Version v = new Version(id);
        /*
                      if ((v.isBeta ())
                          &&
                          (!betasAllowed)
                         )
                      {

                          // Ignore, the user isn't interested in betas.
                          continue;

                      }
        */
        if ((lastWhatsNewVersion.isNewer(v))
            || ((onlyShowCurrentVersion) && (v.isSame(Environment.getQuollWriterVersion())))) {

          String c = WhatsNewComponentProvider.class.getName();

          int ind = c.lastIndexOf(".");

          if (ind > 0) {

            c = c.substring(0, ind);
          }

          WhatsNewComponentProvider compProv = null;

          String cl = JDOMUtils.getAttributeValue(vEl, XMLConstants.clazz, false);

          if (!cl.equals("")) {

            Class clz = null;

            try {

              clz = Class.forName(cl);

              if (WhatsNewComponentProvider.class.isAssignableFrom(clz)) {

                compProv = (WhatsNewComponentProvider) clz.newInstance();
              }

            } catch (Exception e) {

            }
          }

          // This is a version we are interested in.
          java.util.List itemEls =
              JDOMUtils.getChildElements(vEl, WhatsNewItem.XMLConstants.root, true);

          java.util.List<WhatsNewItem> its = new ArrayList();

          for (int j = 0; j < itemEls.size(); j++) {

            Element itEl = (Element) itemEls.get(j);

            WhatsNewItem it = new WhatsNewItem(itEl, compProv, pv);

            if (it.onlyIfCurrentVersion) {

              if (!Environment.getQuollWriterVersion().isSame(v)) {

                continue;
              }
            }

            if ((it.description == null) && (it.component == null)) {

              Environment.logMessage(
                  "Whats new item has no description or component, referenced by: "
                      + JDOMUtils.getPath(itEl));

              continue;
            }

            its.add(it);
          }

          if (its.size() > 0) {

            this.items.put(v, its);
          }
        }
      }

    } catch (Exception e) {

      throw new GeneralException("Unable to init whats new", e);
    }
  }
Beispiel #19
0
 private static Object getFieldValue(Class type, String name)
     throws IllegalAccessException, NoSuchFieldException {
   return type.getField(name).get(null);
 }
    /**
     * Create a new ProjectionClass from the class
     *
     * @param pc projection class
     * @throws ClassNotFoundException couldn't find the class
     * @throws IntrospectionException problem with introspection
     */
    ProjectionClass(Class pc) throws ClassNotFoundException, IntrospectionException {
      projClass = pc;

      // eliminate common properties with "stop class" for getBeanInfo()
      Class stopClass;
      try {
        stopClass = Misc.findClass("ucar.unidata.geoloc.ProjectionImpl");
      } catch (Exception ee) {
        System.err.println("constructParamInput failed ");
        stopClass = null;
      }

      // analyze current projection class as a bean; may throw IntrospectionException
      BeanInfo info = java.beans.Introspector.getBeanInfo(projClass, stopClass);

      // find read/write methods
      PropertyDescriptor[] props = info.getPropertyDescriptors();
      if (debugBeans) {
        System.out.print("Bean Properties for class " + projClass);
        if ((props == null) || (props.length == 0)) {
          System.out.println("none");
          return;
        }
        System.out.println("");
      }
      for (int i = 0; i < props.length; i++) {
        PropertyDescriptor pd = props[i];
        Method reader = pd.getReadMethod();
        Method writer = pd.getWriteMethod();
        // only interesetd in read/write properties
        if ((reader == null) || (writer == null)) {
          continue;
        }
        // A hack to exclude some attributes
        if (pd.getName().equals("name") || pd.getName().equals("defaultMapArea")) {
          continue;
        }
        ProjectionParam p = new ProjectionParam(pd.getName(), reader, writer, pd.getPropertyType());
        paramList.add(p);

        if (debugBeans) {
          System.out.println("  -->" + p);
        }
      }

      // get an instance of this class so we can call toClassName()
      Projection project;
      if (null == (project = makeDefaultProjection())) {
        name = "none";
        return;
      }

      // invoke the toClassName method
      try {
        Method m = projClass.getMethod("getProjectionTypeLabel", VOIDCLASSARG);
        name = (String) m.invoke(project, VOIDOBJECTARG);
      } catch (NoSuchMethodException ee) {
        System.err.println(
            "ProjectionManager: class "
                + projClass
                + " does not have method getProjectionTypeLabel()");
        throw new ClassNotFoundException();
      } catch (SecurityException ee) {
        System.err.println(
            "ProjectionManager: class "
                + projClass
                + " got SecurityException on getProjectionTypeLabel()"
                + ee);
        throw new ClassNotFoundException();
      } catch (Exception ee) {
        System.err.println(
            "ProjectionManager: class "
                + projClass
                + " Exception when invoking getProjectionTypeLabel()"
                + ee);
        throw new ClassNotFoundException();
      }
    }