Browse Source

Minor tidying in TextFrame.

Fixes issue CLIENT-22

Change-Id: I65691a9409158974bbc7d83b0c8d0aafdc42fd2c
Reviewed-on: http://gerrit.dmdirc.com/1548
Automatic-Compile: Greg Holmes <greg@dmdirc.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.5
Greg Holmes 13 years ago
parent
commit
75c58ac94e
1 changed files with 78 additions and 75 deletions
  1. 78
    75
      src/com/dmdirc/addons/ui_swing/components/frames/TextFrame.java

+ 78
- 75
src/com/dmdirc/addons/ui_swing/components/frames/TextFrame.java View File

77
 import java.nio.charset.IllegalCharsetNameException;
77
 import java.nio.charset.IllegalCharsetNameException;
78
 import java.nio.charset.UnsupportedCharsetException;
78
 import java.nio.charset.UnsupportedCharsetException;
79
 import java.util.concurrent.atomic.AtomicBoolean;
79
 import java.util.concurrent.atomic.AtomicBoolean;
80
+import java.util.logging.Level;
80
 
81
 
81
 import javax.swing.BorderFactory;
82
 import javax.swing.BorderFactory;
82
 import javax.swing.JComponent;
83
 import javax.swing.JComponent;
179
         addInternalFrameListener(this);
180
         addInternalFrameListener(this);
180
         getTextPane().addTextPaneListener(this);
181
         getTextPane().addTextPaneListener(this);
181
 
182
 
182
-        getTextPane().setBackground(config.getOptionColour("ui",
183
-                "backgroundcolour"));
184
-        getTextPane().setForeground(config.getOptionColour("ui",
185
-                "foregroundcolour"));
186
-
187
         config.addChangeListener("ui", "foregroundcolour", this);
183
         config.addChangeListener("ui", "foregroundcolour", this);
188
         config.addChangeListener("ui", "backgroundcolour", this);
184
         config.addChangeListener("ui", "backgroundcolour", this);
189
         config.addChangeListener("ui", "frameBufferSize", this);
185
         config.addChangeListener("ui", "frameBufferSize", this);
186
+        updateColours();
190
 
187
 
191
         addPropertyChangeListener("maximum", this);
188
         addPropertyChangeListener("maximum", this);
192
 
189
 
273
     /** {@inheritDoc} */
270
     /** {@inheritDoc} */
274
     @Override
271
     @Override
275
     public void open() {
272
     public void open() {
276
-        final boolean pref = frameParent.getConfigManager().getOptionBool("ui",
277
-                "maximisewindows");
273
+        final boolean pref = frameParent.getConfigManager()
274
+                .getOptionBool("ui", "maximisewindows");
278
         UIUtilities.invokeLater(new Runnable() {
275
         UIUtilities.invokeLater(new Runnable() {
279
 
276
 
280
             @Override
277
             @Override
283
                     TextFrame.super.setVisible(true);
280
                     TextFrame.super.setVisible(true);
284
                 }
281
                 }
285
                 try {
282
                 try {
286
-                    if ((pref || controller.getMainFrame().getMaximised()) && !isMaximum()) {
283
+                    if ((pref || controller.getMainFrame().getMaximised())
284
+                            && !isMaximum()) {
287
                         setMaximum(true);
285
                         setMaximum(true);
288
                     }
286
                     }
289
                 } catch (PropertyVetoException ex) {
287
                 } catch (PropertyVetoException ex) {
562
      */
560
      */
563
     @Override
561
     @Override
564
     public final void propertyChange(final PropertyChangeEvent event) {
562
     public final void propertyChange(final PropertyChangeEvent event) {
565
-        LOGGER.finer("Property change: name: " + event.getPropertyName()
566
-                + " value: " + event.getOldValue() + "->"
567
-                + event.getNewValue());
563
+        LOGGER.log(Level.FINER, "Property change: name: {0}  value: {1} -> {3}"
564
+                , new Object[]{event.getPropertyName(), event.getOldValue(),
565
+                event.getNewValue()});
568
         if ("UI".equals(event.getPropertyName())) {
566
         if ("UI".equals(event.getPropertyName())) {
569
             if (isMaximum()) {
567
             if (isMaximum()) {
570
                 hideTitlebar();
568
                 hideTitlebar();
613
                 } else {
611
                 } else {
614
                     try {
612
                     try {
615
                         c = getClass().getClassLoader().loadClass(componentUI);
613
                         c = getClass().getClassLoader().loadClass(componentUI);
616
-                        constructor =
617
-                                c.getConstructor(new Class[]{
614
+                        constructor = c.getConstructor(new Class[]{
618
                                     javax.swing.JInternalFrame.class});
615
                                     javax.swing.JInternalFrame.class});
619
-                        temp =
620
-                                constructor.newInstance(new Object[]{
616
+                        temp = constructor.newInstance(new Object[]{
621
                                     TextFrame.this});
617
                                     TextFrame.this});
622
                     } catch (ClassNotFoundException ex) {
618
                     } catch (ClassNotFoundException ex) {
623
                         Logger.appError(ErrorLevel.MEDIUM,
619
                         Logger.appError(ErrorLevel.MEDIUM,
624
-                                "Unable to readd titlebar",
625
-                                ex);
620
+                                "Unable to readd titlebar", ex);
626
                     } catch (NoSuchMethodException ex) {
621
                     } catch (NoSuchMethodException ex) {
627
                         Logger.appError(ErrorLevel.MEDIUM,
622
                         Logger.appError(ErrorLevel.MEDIUM,
628
-                                "Unable to readd titlebar",
629
-                                ex);
623
+                                "Unable to readd titlebar", ex);
630
                     } catch (InstantiationException ex) {
624
                     } catch (InstantiationException ex) {
631
                         Logger.appError(ErrorLevel.MEDIUM,
625
                         Logger.appError(ErrorLevel.MEDIUM,
632
-                                "Unable to readd titlebar",
633
-                                ex);
626
+                                "Unable to readd titlebar", ex);
634
                     } catch (IllegalAccessException ex) {
627
                     } catch (IllegalAccessException ex) {
635
                         Logger.appError(ErrorLevel.MEDIUM,
628
                         Logger.appError(ErrorLevel.MEDIUM,
636
-                                "Unable to readd titlebar",
637
-                                ex);
629
+                                "Unable to readd titlebar", ex);
638
                     } catch (InvocationTargetException ex) {
630
                     } catch (InvocationTargetException ex) {
639
                         Logger.appError(ErrorLevel.MEDIUM,
631
                         Logger.appError(ErrorLevel.MEDIUM,
640
-                                "Unable to readd titlebar",
641
-                                ex);
632
+                                "Unable to readd titlebar", ex);
642
                     }
633
                     }
643
 
634
 
644
                 }
635
                 }
728
      */
719
      */
729
     @Override
720
     @Override
730
     public void internalFrameActivated(final InternalFrameEvent event) {
721
     public void internalFrameActivated(final InternalFrameEvent event) {
731
-        LOGGER.finer(getName() + ": internalFrameActivated()");
722
+        LOGGER.log(Level.FINER, "{0} : internalFrameActivated()",
723
+                new Object[] {getName()});
732
 
724
 
733
         if (maximiseRestoreInProgress.get()) {
725
         if (maximiseRestoreInProgress.get()) {
734
             return;
726
             return;
738
             /** {@inheritDoc} */
730
             /** {@inheritDoc} */
739
             @Override
731
             @Override
740
             protected Object doInBackground() {
732
             protected Object doInBackground() {
741
-                LOGGER.finer(getName()
742
-                        + ": internalFrameActivated(): doInBackground");
733
+                LOGGER.log(Level.FINER,
734
+                        "{0} : internalFrameActivated(): doInBackground",
735
+                        new Object[]{getName()});
743
                 frameParent.windowActivated();
736
                 frameParent.windowActivated();
744
                 return null;
737
                 return null;
745
             }
738
             }
816
 
809
 
817
     /** {@inheritDoc} */
810
     /** {@inheritDoc} */
818
     @Override
811
     @Override
819
-    public void mouseClicked(final ClickTypeValue clicktype,
812
+    public void mouseClicked(final ClickTypeValue clickType,
820
             final MouseEventType eventType, final MouseEvent event) {
813
             final MouseEventType eventType, final MouseEvent event) {
821
         if (event.isPopupTrigger()) {
814
         if (event.isPopupTrigger()) {
822
-            showPopupMenuInternal(clicktype, event.getPoint());
815
+            showPopupMenuInternal(clickType, event.getPoint());
823
         }
816
         }
824
         if (eventType == MouseEventType.CLICK
817
         if (eventType == MouseEventType.CLICK
825
                 && event.getButton() == MouseEvent.BUTTON1) {
818
                 && event.getButton() == MouseEvent.BUTTON1) {
826
-            switch (clicktype.getType()) {
827
-                case CHANNEL:
828
-                    if (frameParent.getServer() != null && ActionManager.
829
-                            processEvent(CoreActionType.LINK_CHANNEL_CLICKED,
830
-                            null, this, clicktype.getValue())) {
831
-                        frameParent.getServer().join(
832
-                                new ChannelJoinRequest(clicktype.getValue()));
833
-                    }
834
-                    break;
835
-                case HYPERLINK:
836
-                    if (ActionManager.processEvent(
837
-                            CoreActionType.LINK_URL_CLICKED, null, this,
838
-                            clicktype.getValue())) {
839
-                        controller.getURLHandler().launchApp(clicktype.getValue());
840
-                    }
841
-                    break;
842
-                case NICKNAME:
843
-                    if (frameParent.getServer() != null && ActionManager.
844
-                            processEvent(CoreActionType.LINK_NICKNAME_CLICKED,
845
-                            null, this, clicktype.getValue())) {
846
-                        getContainer().getServer().getQuery(clicktype
847
-                                .getValue()).activateFrame();
848
-                    }
849
-                    break;
850
-                default:
851
-                    break;
852
-            }
819
+            handleLinkClick(clickType);
820
+        }
821
+    }
853
 
822
 
823
+    /**
824
+     * Handles clicking of a link in a textpane.
825
+     *
826
+     * @param clickType Details of link clicked
827
+     */
828
+    private void handleLinkClick(final ClickTypeValue clickType) {
829
+        switch (clickType.getType()) {
830
+            case CHANNEL:
831
+                if (frameParent.getServer() != null && ActionManager.
832
+                        processEvent(CoreActionType.LINK_CHANNEL_CLICKED,
833
+                        null, this, clickType.getValue())) {
834
+                    frameParent.getServer().join(
835
+                            new ChannelJoinRequest(clickType.getValue()));
836
+                }
837
+                break;
838
+            case HYPERLINK:
839
+                if (ActionManager.processEvent(
840
+                        CoreActionType.LINK_URL_CLICKED, null, this,
841
+                        clickType.getValue())) {
842
+                    controller.getURLHandler().launchApp(clickType.getValue());
843
+                }
844
+                break;
845
+            case NICKNAME:
846
+                if (frameParent.getServer() != null && ActionManager
847
+                        .processEvent(CoreActionType.LINK_NICKNAME_CLICKED,
848
+                        null, this, clickType.getValue())) {
849
+                    getContainer().getServer().getQuery(clickType.getValue())
850
+                            .activateFrame();
851
+                }
852
+                break;
853
+            default:
854
+                break;
854
         }
855
         }
855
     }
856
     }
856
 
857
 
857
     /**
858
     /**
858
-     * What popup type should be used for popup menus for nicknames
859
+     * What popup type should be used for popup menus for nicknames.
859
      *
860
      *
860
      * @return Appropriate popuptype for this frame
861
      * @return Appropriate popuptype for this frame
861
      */
862
      */
862
     public abstract PopupType getNicknamePopupType();
863
     public abstract PopupType getNicknamePopupType();
863
 
864
 
864
     /**
865
     /**
865
-     * What popup type should be used for popup menus for channels
866
+     * What popup type should be used for popup menus for channels.
866
      *
867
      *
867
      * @return Appropriate popuptype for this frame
868
      * @return Appropriate popuptype for this frame
868
      */
869
      */
869
     public abstract PopupType getChannelPopupType();
870
     public abstract PopupType getChannelPopupType();
870
 
871
 
871
     /**
872
     /**
872
-     * What popup type should be used for popup menus for hyperlinks
873
+     * What popup type should be used for popup menus for hyperlinks.
873
      *
874
      *
874
      * @return Appropriate popuptype for this frame
875
      * @return Appropriate popuptype for this frame
875
      */
876
      */
876
     public abstract PopupType getHyperlinkPopupType();
877
     public abstract PopupType getHyperlinkPopupType();
877
 
878
 
878
     /**
879
     /**
879
-     * What popup type should be used for popup menus for normal clicks
880
+     * What popup type should be used for popup menus for normal clicks.
880
      *
881
      *
881
      * @return Appropriate popuptype for this frame
882
      * @return Appropriate popuptype for this frame
882
      */
883
      */
894
      *
895
      *
895
      * @param type ClickType Click type
896
      * @param type ClickType Click type
896
      * @param point Point Point of the click
897
      * @param point Point Point of the click
897
-     * @param argument Word under the click
898
      */
898
      */
899
     private void showPopupMenuInternal(final ClickTypeValue type,
899
     private void showPopupMenuInternal(final ClickTypeValue type,
900
             final Point point) {
900
             final Point point) {
954
     }
954
     }
955
 
955
 
956
     /**
956
     /**
957
-     * Builds a popup menu of a specified type
957
+     * Builds a popup menu of a specified type.
958
      *
958
      *
959
      * @param type type of menu to build
959
      * @param type type of menu to build
960
      * @param arguments Arguments for the command
960
      * @param arguments Arguments for the command
1013
 
1013
 
1014
     /** {@inheritDoc} */
1014
     /** {@inheritDoc} */
1015
     @Override
1015
     @Override
1016
-    public void configChanged(final String domain,
1017
-            final String key) {
1018
-        if (getConfigManager() == null) {
1016
+    public void configChanged(final String domain, final String key) {
1017
+        if (getConfigManager() == null || getTextPane() == null) {
1019
             return;
1018
             return;
1020
         }
1019
         }
1021
 
1020
 
1022
-        if ("ui".equals(domain)) {
1023
-            if ("foregroundcolour".equals(key) && getTextPane() != null) {
1024
-                getTextPane().setForeground(getConfigManager().
1025
-                        getOptionColour("ui", "foregroundcolour"));
1026
-            } else if ("backgroundcolour".equals(key) && getTextPane()
1027
-                    != null) {
1028
-                getTextPane().setBackground(getConfigManager().
1029
-                        getOptionColour("ui", "backgroundcolour"));
1030
-            }
1021
+        if ("ui".equals(domain) && ("foregroundcolour".equals(key)
1022
+                || "backgroundcolour".equals(key))) {
1023
+            updateColours();
1031
         }
1024
         }
1032
     }
1025
     }
1033
 
1026
 
1072
     public SwingController getController() {
1065
     public SwingController getController() {
1073
         return controller;
1066
         return controller;
1074
     }
1067
     }
1068
+
1069
+    /**
1070
+     * Updates colour settings from their config values.
1071
+     */
1072
+    private void updateColours() {
1073
+        getTextPane().setForeground(getConfigManager().
1074
+                        getOptionColour("ui", "foregroundcolour"));
1075
+        getTextPane().setBackground(getConfigManager().
1076
+                        getOptionColour("ui", "backgroundcolour"));
1077
+    }
1075
 }
1078
 }

Loading…
Cancel
Save