Beispiel #1
0
 static {
   Icon icon = GnomeUtil.getIcon("info", 12, true);
   if (icon == null) {
     icon = Finder.getIcon("images/general/info.png");
   }
   ICON = icon;
 }
  @Override
  public String getTitle() {
    Calendar cal = (Calendar) this.cal.clone();
    String[] params = new String[2];

    int offset = cal.get(Calendar.YEAR) % 1000;
    cal.add(Calendar.YEAR, -offset);
    params[0] = format(mFormat[0], cal);

    cal.add(Calendar.YEAR, 999);
    params[1] = format(mFormat[1], cal);

    return Finder.getString("date.format.millennium.title", (Object[]) params);
  }
  @Override
  public String toString(Calendar cal) {
    cal = (Calendar) cal.clone();
    String[] params = new String[2];

    int offset = cal.get(Calendar.YEAR) % 100;
    cal.add(Calendar.YEAR, -offset);
    params[0] = format(eFormat[0], cal);

    cal.add(Calendar.YEAR, 99);
    params[1] = format(eFormat[1], cal);

    return Finder.getString("date.format.millennium.element", (Object[]) params);
  }
  private JPanel createForm() {
    JCheckBox enabledCheckBox = new JCheckBox(Finder.getString("vhost.ssl.edit.enable"));

    new CheckBoxPropertySynchronizer(enabledProperty, enabledCheckBox);
    ChangeIndicator enabledChange = new ChangeIndicator();
    enabledProperty.addChangeListener(enabledChange);

    JLabel iPLabel = new JLabel(Finder.getString("vhost.ssl.edit.ip"));
    JTextField iPField = GUIUtil.createTextField();
    new TextComponentPropertySynchronizer<String, JTextComponent>(ipProperty, iPField);
    ChangeIndicator iPChange = new ChangeIndicator();
    ipProperty.addChangeListener(iPChange);

    JLabel portLabel = new JLabel(Finder.getString("vhost.ssl.edit.port"));

    SpinnerNumberModel portModel = new SpinnerNumberModel(0, 0, Short.MAX_VALUE, 1);
    JSpinner portSpinner = new JSpinner(portModel);

    JComponent editor = portSpinner.getEditor();
    if (editor instanceof JSpinner.DefaultEditor) {
      JTextField field = ((JSpinner.DefaultEditor) editor).getTextField();
      field.setColumns(5);
      field.setHorizontalAlignment(JTextField.RIGHT);
    }

    new SpinnerNumberModelPropertySynchronizer(portProperty, portModel, false);
    portProperty.save();

    ChangeIndicator portChange = new ChangeIndicator();
    portProperty.addChangeListener(portChange);

    JLabel certLabel = new JLabel(Finder.getString("vhost.ssl.edit.certificate"));

    BrowsableFilePanel certPanel = new BrowsableFilePanel();
    certPanel.setOpaque(false);
    fileChoosers.add(certPanel.getFileChooser());

    new TextComponentPropertySynchronizer<String, JTextComponent>(
        certProperty, certPanel.getField());
    ChangeIndicator certChange = new ChangeIndicator();
    certProperty.addChangeListener(certChange);

    JLabel keyLabel = new JLabel(Finder.getString("vhost.ssl.edit.key"));

    BrowsableFilePanel keyPanel = new BrowsableFilePanel();
    keyPanel.setOpaque(false);
    fileChoosers.add(keyPanel.getFileChooser());

    new TextComponentPropertySynchronizer<String, JTextComponent>(keyProperty, keyPanel.getField());
    ChangeIndicator keyChange = new ChangeIndicator();
    keyProperty.addChangeListener(keyChange);

    JPanel formPanel = new JPanel();
    formPanel.setOpaque(false);

    Form form = new Form(formPanel, VerticalAnchor.TOP);

    int hGap = GUIUtil.getHalfGap();
    int sGap = 3 * hGap;
    int indent = GUIUtil.getTextXOffset(enabledCheckBox);

    ColumnLayoutConstraint c = new ColumnLayoutConstraint(HorizontalAnchor.FILL, hGap);

    RowLayoutConstraint r = new RowLayoutConstraint(VerticalAnchor.CENTER, hGap);

    HasAnchors a = new SimpleHasAnchors(HorizontalAnchor.LEFT, VerticalAnchor.CENTER);

    form.addRow(HorizontalAnchor.LEFT, c);
    form.add(enabledCheckBox, r);
    form.add(enabledChange, r);

    form.addTable(2, hGap, hGap, HorizontalAnchor.LEFT, c.setGap(sGap));
    form.add(iPLabel, a);
    form.add(getRow(hGap, iPField, iPChange), a);
    form.add(portLabel, a);
    form.add(getRow(hGap, portSpinner, portChange), a);
    form.add(certLabel, a);
    form.add(getRow(hGap, certPanel, certChange), a);
    form.add(keyLabel, a);
    form.add(getRow(hGap, keyPanel, keyChange), a);

    return formPanel;
  }
@SuppressWarnings({"serial"})
public class MillenniumTableModel extends CalendarTableModel {
  //
  // Static data
  //

  private static DateFormat[] mFormat = {
    new SimpleDateFormat(Finder.getString("date.format.millennium.title.0")),
    new SimpleDateFormat(Finder.getString("date.format.millennium.title.1")),
  };

  private static DateFormat[] eFormat = {
    new SimpleDateFormat(Finder.getString("date.format.millennium.element.0")),
    new SimpleDateFormat(Finder.getString("date.format.millennium.element.1")),
  };

  //
  // Constructors
  //

  public MillenniumTableModel(Calendar cal) {
    super(cal);
  }

  public MillenniumTableModel() {
    this(null);
  }

  //
  // CalendarTableModel methods
  //

  @Override
  public int compare(Calendar cal, Calendar cal2) {
    if (cal.get(Calendar.YEAR) / 100 == cal2.get(Calendar.YEAR) / 100) {
      return 0;
    }
    return cal.compareTo(cal2);
  }

  @Override
  protected Calendar[][] createData() {
    Calendar[][] centuries = new Calendar[3][4];
    int offset = cal.get(Calendar.YEAR) % 1000 + 100;

    for (int r = 0; r < centuries.length; r++) {
      Calendar[] row = centuries[r];
      for (int c = 0; c < row.length; c++) {
        row[c] = (Calendar) cal.clone();
        row[c].add(Calendar.YEAR, 100 * (r * row.length + c) - offset);
      }
    }

    return centuries;
  }

  @Override
  public long getMillis(int intervals) {
    Calendar cal = getCalendar();
    long before = cal.getTimeInMillis();

    cal = (Calendar) cal.clone();
    cal.add(Calendar.YEAR, 1000 * intervals);
    long after = cal.getTimeInMillis();

    return after - before;
  }

  @Override
  public String getTitle() {
    Calendar cal = (Calendar) this.cal.clone();
    String[] params = new String[2];

    int offset = cal.get(Calendar.YEAR) % 1000;
    cal.add(Calendar.YEAR, -offset);
    params[0] = format(mFormat[0], cal);

    cal.add(Calendar.YEAR, 999);
    params[1] = format(mFormat[1], cal);

    return Finder.getString("date.format.millennium.title", (Object[]) params);
  }

  @Override
  public boolean isInMainRange(Calendar cal) {
    return this.cal.get(Calendar.YEAR) / 1000 == cal.get(Calendar.YEAR) / 1000;
  }

  @Override
  public String toString(Calendar cal) {
    cal = (Calendar) cal.clone();
    String[] params = new String[2];

    int offset = cal.get(Calendar.YEAR) % 100;
    cal.add(Calendar.YEAR, -offset);
    params[0] = format(eFormat[0], cal);

    cal.add(Calendar.YEAR, 99);
    params[1] = format(eFormat[1], cal);

    return Finder.getString("date.format.millennium.element", (Object[]) params);
  }
}
public class CustomCoreSchemeEditControl
    extends SettingsControl<CoreAdmPanelDescriptor, CustomCoreSchemeEditPanel> {

  //
  // Static data
  //

  public static final String ID = "custom";
  public static final String NAME = Finder.getString("settings.scheme.custom.title");

  //
  // Instance data
  //

  private MutableProperty<CoreConfig> configProperty;

  //
  // Constructors
  //

  public CustomCoreSchemeEditControl(
      CoreAdmPanelDescriptor descriptor, MutableProperty<CoreConfig> configProperty) {

    super(ID, NAME, descriptor);
    this.configProperty = configProperty;
  }

  //
  // Control methods
  //

  @Override
  public String getHelpMapID() {
    return "coreadm-custom";
  }

  @Override
  protected void save()
      throws ActionAbortedException, ActionFailedException, ActionUnauthorizedException {

    CoreConfig value = getComponent().getConfig();
    CoreAdmPanelDescriptor descriptor = getPanelDescriptor();

    try {
      value.write(descriptor.getService());
    } catch (ScfException e) {
      SmfUtil.throwActionException(e);
    } catch (SecurityException e) {
      throw new ActionUnauthorizedException(e);
    }

    configProperty.setValue(getComponent().getConfig());
    if (configProperty.isChanged()) {
      configProperty.save();
    }
    super.save();

    descriptor.setCoreConfig(value);
  }

  //
  // SwingControl methods
  //

  @Override
  protected void configComponent(CustomCoreSchemeEditPanel panel) {
    super.configComponent(panel);
    addDefaultCancelAction(false);
    addDefaultOkayAction(false);
    addDefaultHelpAction();
  }

  @Override
  protected CustomCoreSchemeEditPanel createComponent() {
    return new CustomCoreSchemeEditPanel();
  }

  @Override
  protected void initComponent() {
    getComponent().init(configProperty.getSavedValue(), configProperty.getValue());
  }
}